Skip to content

Commit

Permalink
iommu/vt-d: Add present bit check in pasid entry setup helpers
Browse files Browse the repository at this point in the history
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 <yi.l.liu@intel.com>
Link: https://lore.kernel.org/r/20210817042425.1784279-1-yi.l.liu@intel.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20210818134852.1847070-10-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Liu Yi L authored and Joerg Roedel committed Aug 19, 2021
1 parent 8123b0b commit 423d39d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/iommu/intel/pasid.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
devtlb_invalidation_with_pasid(iommu, dev, pasid);
}

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

/* Caller must ensure PASID entry is not in use. */
if (pasid_pte_is_present(pte))
return -EBUSY;

pasid_clear_entry(pte);

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

/* Caller must ensure PASID entry is not in use. */
if (pasid_pte_is_present(pte))
return -EBUSY;

pasid_clear_entry(pte);
pasid_set_domain_id(pte, did);
pasid_set_slptr(pte, pgd_val);
Expand Down Expand Up @@ -723,6 +735,10 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
return -ENODEV;
}

/* Caller must ensure PASID entry is not in use. */
if (pasid_pte_is_present(pte))
return -EBUSY;

pasid_clear_entry(pte);
pasid_set_domain_id(pte, did);
pasid_set_address_width(pte, iommu->agaw);
Expand Down

0 comments on commit 423d39d

Please sign in to comment.