Skip to content

Commit 288d08e

Browse files
yiliu1765joergroedel
authored andcommitted
iommu/vt-d: Handle non-page aligned address
Address information for device TLB invalidation comes from userspace when device is directly assigned to a guest with vIOMMU support. VT-d requires page aligned address. This patch checks and enforce address to be page aligned, otherwise reserved bits can be set in the invalidation descriptor. Unrecoverable fault will be reported due to non-zero value in the reserved bits. Fixes: 61a06a1 ("iommu/vt-d: Support flushing more translation cache types") Signed-off-by: Liu Yi L <[email protected]> Signed-off-by: Jacob Pan <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Eric Auger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent e7e6946 commit 288d08e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

drivers/iommu/intel/dmar.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,9 +1456,26 @@ void qi_flush_dev_iotlb_pasid(struct intel_iommu *iommu, u16 sid, u16 pfsid,
14561456
* Max Invs Pending (MIP) is set to 0 for now until we have DIT in
14571457
* ECAP.
14581458
*/
1459-
desc.qw1 |= addr & ~mask;
1460-
if (size_order)
1459+
if (addr & GENMASK_ULL(size_order + VTD_PAGE_SHIFT, 0))
1460+
pr_warn_ratelimited("Invalidate non-aligned address %llx, order %d\n",
1461+
addr, size_order);
1462+
1463+
/* Take page address */
1464+
desc.qw1 = QI_DEV_EIOTLB_ADDR(addr);
1465+
1466+
if (size_order) {
1467+
/*
1468+
* Existing 0s in address below size_order may be the least
1469+
* significant bit, we must set them to 1s to avoid having
1470+
* smaller size than desired.
1471+
*/
1472+
desc.qw1 |= GENMASK_ULL(size_order + VTD_PAGE_SHIFT - 1,
1473+
VTD_PAGE_SHIFT);
1474+
/* Clear size_order bit to indicate size */
1475+
desc.qw1 &= ~mask;
1476+
/* Set the S bit to indicate flushing more than 1 page */
14611477
desc.qw1 |= QI_DEV_EIOTLB_SIZE;
1478+
}
14621479

14631480
qi_submit_sync(iommu, &desc, 1, 0);
14641481
}

0 commit comments

Comments
 (0)