[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/4] VT-d: round IOTLB flush ranges up to an aligned power of two



Page-selective invalidation takes only aligned power-of-two ranges, so
iommu_flush_iotlb() flushes any other range as the whole domain. A
later patch flushes one range per group of grant unmaps, which rarely
has that shape.

Round the range up to the smallest aligned power of two covering it.
Orders the IOMMU doesn't support still get a domain-selective flush,
and device TLB invalidations use the same range.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@xxxxxxxxx>

---
Changes in v2:
- New patch, taking the rounding out of the grant unmap batch (Teddy).
---
 xen/drivers/passthrough/vtd/iommu.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/xen/drivers/passthrough/vtd/iommu.c 
b/xen/drivers/passthrough/vtd/iommu.c
index b41a1d41c8..faf8255f26 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -742,6 +742,10 @@ static int __must_check cf_check iommu_flush_iotlb(struct 
domain *d, dfn_t dfn,
     {
         ASSERT(page_count && !dfn_eq(dfn, INVALID_DFN));
         ASSERT(flush_flags);
+
+        /* PSI takes only aligned powers of two: cover the range with one. */
+        page_count = 1UL << flsl(dfn_x(dfn) ^ (dfn_x(dfn) + page_count - 1));
+        dfn = _dfn(dfn_x(dfn) & ~(page_count - 1));
     }
 
     /*
-- 
2.47.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.