VirtualBox

Ignore:
Timestamp:
Mar 13, 2014 10:54:47 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92799
Message:

vboxpci: current code never calls unmap method, so we end up leaking
mappings and keeping resources busy. To hack around this, map
resources only once and return existing mapping on repeated requests,
free them at once in vboxPciOsDevDeinit().

This makes it possible for the host driver to take back control of the
device after VM terminates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxPci/linux/VBoxPci-linux.c

    r49137 r50779  
    652652    if (pPciDev)
    653653    {
     654        int iRegion;
     655        for (iRegion = 0; iRegion < 7; ++iRegion)
     656        {
     657            if (pIns->aRegionR0Mapping[iRegion])
     658            {
     659                iounmap(pIns->aRegionR0Mapping[iRegion]);
     660                pIns->aRegionR0Mapping[iRegion] = 0;
     661                pci_release_region(pPciDev, iRegion);
     662            }
     663        }
     664
    654665        vboxPciOsDevUnregisterWithIommu(pIns);
    655666
     
    738749{
    739750    struct pci_dev  *pPciDev = pIns->pPciDev;
    740     struct resource *pRegion;
    741751    RTR0PTR          result = 0;
     752    int              error;
    742753
    743754    printk(KERN_DEBUG "linux vboxPciOsDevMapRegion: reg=%d start=%llx size=%lld\n", iRegion, RegionStart, u64RegionSize);
    744755
    745756    if (!pPciDev)
    746         return 0;
     757        return VERR_INVALID_PARAMETER;
    747758
    748759    if (iRegion < 0 || iRegion > 6)
     
    752763    }
    753764
    754     pRegion = request_mem_region(RegionStart, u64RegionSize, "vboxpci");
    755     if (!pRegion)
    756     {
    757         /** @todo: need to make sure if thise error indeed can be ignored. */
    758         printk(KERN_DEBUG "request_mem_region() failed, don't care\n");
    759     }
     765    if (pci_resource_flags(pPciDev, iRegion) & IORESOURCE_IO)
     766        return VERR_INVALID_PARAMETER;
     767
     768    if (RegionStart != pci_resource_start(pPciDev, iRegion))
     769        return VERR_INVALID_PARAMETER;
     770
     771    if (u64RegionSize != pci_resource_len(pPciDev, iRegion))
     772        return VERR_INVALID_PARAMETER;
     773
     774    /*
     775     * XXX: Current code never calls unmap.  To avoid leaking mappings
     776     * only request and map resources once.
     777     */
     778    if (pIns->aRegionR0Mapping[iRegion])
     779    {
     780        *pRegionBase = pIns->aRegionR0Mapping[iRegion];
     781        return VINF_SUCCESS;
     782    }
     783
     784
     785    error = pci_request_region(pPciDev, iRegion, "vboxpci");
     786    if (error)
     787        return VERR_RESOURCE_BUSY;
    760788
    761789    /* For now no caching, try to optimize later. */
    762     result = ioremap_nocache(RegionStart, u64RegionSize);
     790    result = ioremap_nocache(pci_resource_start(pPciDev, iRegion),
     791                             pci_resource_len(pPciDev, iRegion));
    763792
    764793    if (!result)
    765794    {
    766795        printk(KERN_DEBUG "cannot ioremap_nocache\n");
    767         if (pRegion)
    768             release_mem_region(RegionStart, u64RegionSize);
    769         return 0;
    770     }
    771 
    772     *pRegionBase = result;
    773 
    774     return 0;
     796        pci_release_region(pPciDev, iRegion);
     797        return VERR_MAP_FAILED;
     798    }
     799
     800    *pRegionBase = pIns->aRegionR0Mapping[iRegion] = result;
     801
     802    return VINF_SUCCESS;
    775803}
    776804
     
    781809                             RTR0PTR        RegionBase)
    782810{
    783 
    784     iounmap(RegionBase);
    785     release_mem_region(RegionStart, u64RegionSize);
    786 
    787     return VINF_SUCCESS;
     811    /* XXX: Current code never calls unmap. */
     812    return VERR_NOT_IMPLEMENTED;
    788813}
    789814
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette