intel_iommu,dmar: reserve mmio of IOMMU registers
PATCH 1/1 intel_iommu,dmar: reserve mmio of IOMMU registers
Intel-iommu initialization doesn't currently reserve the memory used for the IOMMU registers. This can allow the pci resource allocator to assign a device BAR to the same address as the IOMMU registers. This can cause some not so nice side affects when the driver ioremap's that region.
--- drivers/iommu/dmar.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-)
drivers/iommu/dmar.c +16 -2
@@ -599,10 +599,16 @@ int alloc_iommu(struct dmar_drhd_unit *drhd) iommu->seq_id = iommu_allocated++;sprintf (iommu->name,"dmar%d" , iommu->seq_id); + map_size =VTD_PAGE_SIZE ; +if (!request_mem_region (drhd->reg_base_addr, map_size, iommu->name)) { +printk (KERN_ERR "IOMMU: can't reserve memory\n" ); + goto error; + } + iommu->reg =ioremap (drhd->reg_base_addr,VTD_PAGE_SIZE );if (!iommu->reg) {printk (KERN_ERR "IOMMU: can't map the region\n" ); - goto error; + goto err_release; } iommu->cap =dmar_readq (iommu->reg +DMAR_CAP_REG ); iommu->ecap =dmar_readq (iommu->reg +DMAR_ECAP_REG );
@@ -637,10 +643,16 @@ int alloc_iommu(struct dmar_drhd_unit *drhd) map_size =VTD_PAGE_ALIGN (map_size);if (map_size >VTD_PAGE_SIZE ) {iounmap (iommu->reg); +release_mem_region (drhd->reg_base_addr,VTD_PAGE_SIZE ); +if (!request_mem_region (drhd->reg_base_addr, map_size, + iommu->name)) { +printk (KERN_ERR "IOMMU: can't reserve memory\n" ); + goto error; + } iommu->reg =ioremap (drhd->reg_base_addr, map_size);if (!iommu->reg) {printk (KERN_ERR "IOMMU: can't map the region\n" ); - goto error; + goto err_release; } }
@@ -659,6 +671,8 @@ int alloc_iommu(struct dmar_drhd_unit *drhd) err_unmap:iounmap (iommu->reg); + err_release: +release_mem_region (drhd->reg_base_addr,VTD_PAGE_SIZE ); error:kfree (iommu);return -1 ;
Signature · 1 line
1.7.1
A message that is not in the archive (sent off-list or not yet received): 1331250676-55926-1-git-send-email-ddutile-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
self-nak.
Found an iounmap() with a missing release_mem_region(); will post V2 shortly.
Quoted 60 lines · Donald Dutile
Intel-iommu initialization doesn't currently reserve the memory used for the IOMMU registers. This can allow the pci resource allocator to assign a device BAR to the same address as the IOMMU registers. This can cause some not so nice side affects when the driver ioremap's that region.
Signed-off-by Donald Dutile<[email protected]>--- drivers/iommu/dmar.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-)drivers/iommu/dmar.c +16
-2@@ -599,10 +599,16 @@ int alloc_iommu(struct dmar_drhd_unit *drhd) iommu->seq_id = iommu_allocated++;sprintf (iommu->name,"dmar%d" , iommu->seq_id); + map_size =VTD_PAGE_SIZE ; +if (!request_mem_region (drhd->reg_base_addr, map_size, iommu->name)) { +printk (KERN_ERR "IOMMU: can't reserve memory\n" ); + goto error; + } + iommu->reg =ioremap (drhd->reg_base_addr,VTD_PAGE_SIZE );if (!iommu->reg) {printk (KERN_ERR "IOMMU: can't map the region\n" ); - goto error; + goto err_release; } iommu->cap =dmar_readq (iommu->reg +DMAR_CAP_REG ); iommu->ecap =dmar_readq (iommu->reg +DMAR_ECAP_REG );@@ -637,10 +643,16 @@ int alloc_iommu(struct dmar_drhd_unit *drhd) map_size =VTD_PAGE_ALIGN (map_size);if (map_size>VTD_PAGE_SIZE ) {iounmap (iommu->reg); +release_mem_region (drhd->reg_base_addr,VTD_PAGE_SIZE ); +if (!request_mem_region (drhd->reg_base_addr, map_size, + iommu->name)) { +printk (KERN_ERR "IOMMU: can't reserve memory\n" ); + goto error; + } iommu->reg =ioremap (drhd->reg_base_addr, map_size);if (!iommu->reg) {printk (KERN_ERR "IOMMU: can't map the region\n" ); - goto error; + goto err_release; } }@@ -659,6 +671,8 @@ int alloc_iommu(struct dmar_drhd_unit *drhd) err_unmap:iounmap (iommu->reg); + err_release: +release_mem_region (drhd->reg_base_addr,VTD_PAGE_SIZE ); error:kfree (iommu);return -1 ;