Skip to content

Commit c062db0

Browse files
LuBaoluwilldeacon
authored andcommitted
iommu/vt-d: Update domain geometry in iommu_ops.at(de)tach_dev
The iommu-dma constrains IOVA allocation based on the domain geometry that the driver reports. Update domain geometry everytime a domain is attached to or detached from a device. Signed-off-by: Lu Baolu <[email protected]> Tested-by: Logan Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 65f746e commit c062db0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
#define MAX_AGAW_WIDTH 64
6868
#define MAX_AGAW_PFN_WIDTH (MAX_AGAW_WIDTH - VTD_PAGE_SHIFT)
6969

70-
#define __DOMAIN_MAX_PFN(gaw) ((((uint64_t)1) << (gaw-VTD_PAGE_SHIFT)) - 1)
71-
#define __DOMAIN_MAX_ADDR(gaw) ((((uint64_t)1) << gaw) - 1)
70+
#define __DOMAIN_MAX_PFN(gaw) ((((uint64_t)1) << ((gaw) - VTD_PAGE_SHIFT)) - 1)
71+
#define __DOMAIN_MAX_ADDR(gaw) ((((uint64_t)1) << (gaw)) - 1)
7272

7373
/* We limit DOMAIN_MAX_PFN to fit in an unsigned long, and DOMAIN_MAX_ADDR
7474
to match. That way, we can use 'unsigned long' for PFNs with impunity. */
@@ -739,6 +739,18 @@ static void domain_update_iommu_cap(struct dmar_domain *domain)
739739
*/
740740
if (domain->nid == NUMA_NO_NODE)
741741
domain->nid = domain_update_device_node(domain);
742+
743+
/*
744+
* First-level translation restricts the input-address to a
745+
* canonical address (i.e., address bits 63:N have the same
746+
* value as address bit [N-1], where N is 48-bits with 4-level
747+
* paging and 57-bits with 5-level paging). Hence, skip bit
748+
* [N-1].
749+
*/
750+
if (domain_use_first_level(domain))
751+
domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw - 1);
752+
else
753+
domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw);
742754
}
743755

744756
struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus,

0 commit comments

Comments
 (0)