Skip to content

Commit 423d39d

Browse files
yiliu1765joergroedel
authored andcommitted
iommu/vt-d: Add present bit check in pasid entry setup helpers
The helper functions should not modify the pasid entries which are still in use. Add a check against present bit. Signed-off-by: Liu Yi L <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 8123b0b commit 423d39d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/iommu/intel/pasid.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
534534
devtlb_invalidation_with_pasid(iommu, dev, pasid);
535535
}
536536

537+
/*
538+
* This function flushes cache for a newly setup pasid table entry.
539+
* Caller of it should not modify the in-use pasid table entries.
540+
*/
537541
static void pasid_flush_caches(struct intel_iommu *iommu,
538542
struct pasid_entry *pte,
539543
u32 pasid, u16 did)
@@ -585,6 +589,10 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,
585589
if (WARN_ON(!pte))
586590
return -EINVAL;
587591

592+
/* Caller must ensure PASID entry is not in use. */
593+
if (pasid_pte_is_present(pte))
594+
return -EBUSY;
595+
588596
pasid_clear_entry(pte);
589597

590598
/* Setup the first level page table pointer: */
@@ -684,6 +692,10 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,
684692
return -ENODEV;
685693
}
686694

695+
/* Caller must ensure PASID entry is not in use. */
696+
if (pasid_pte_is_present(pte))
697+
return -EBUSY;
698+
687699
pasid_clear_entry(pte);
688700
pasid_set_domain_id(pte, did);
689701
pasid_set_slptr(pte, pgd_val);
@@ -723,6 +735,10 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
723735
return -ENODEV;
724736
}
725737

738+
/* Caller must ensure PASID entry is not in use. */
739+
if (pasid_pte_is_present(pte))
740+
return -EBUSY;
741+
726742
pasid_clear_entry(pte);
727743
pasid_set_domain_id(pte, did);
728744
pasid_set_address_width(pte, iommu->agaw);

0 commit comments

Comments
 (0)