Skip to contentSkip to conversation

PCI/ATS: Mandate checking pci_ats_supported() before pci_prepare_ats()

PATCH New Pranjal Shrivastava 2 participants 3 messages Oct 1 – Oct 2 PCI

lore
Share & tools
lore
#0 lore raw

v4 cover PCI/ATS: Mandate checking pci_ats_supported() before pci_prepare_ats()

Hi Bjorn,

This single-patch submission represents the final core enforcement for the PCIe ATS robustness hardening effort.

This work was split into two parallel driver-specific consolidation series:
1. Intel & ARM [1]
2. AMD [2]

All the prerequisite driver refactors from both series have now been merged into the IOMMU tree by Joerg, with the latest merge commit [3].

As the driver-side safety checks are now fully in place, Joerg requested [4] that this final, PCI core patch be submitted through the PCIe tree. Hence, I'm sending this as a standalone patch rebased on the pci tree (for-next branch).

Thanks,
Praan

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/iommu/linux.git/commit/?id=622384f54a8415f28bf7cf11cda95ab125488ca1
[4] https://lore.kernel.org/all/[email protected]/

Pranjal Shrivastava (1):
PCI/ATS: Mandate checking pci_ats_supported() before pci_prepare_ats()

 drivers/pci/ats.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#1 lore raw

PATCH v4 1/1 PCI/ATS: Mandate checking pci_ats_supported() before pci_prepare_ats()

Currently, pci_prepare_ats() internally calls pci_ats_supported() and returns -EINVAL if the device does not support ATS. While this provides a silent safety check, it conflates support detection with configuration.

Update pci_prepare_ats() to wrap the internal pci_ats_supported check in a WARN_ON(). This mandates all callers to call pci_prepare_ats() only if the function supports ATS.

Update the function documentation to mention that callers must verify ATS support (via pci_ats_supported()) before calling pci_prepare_ats().

---
 drivers/pci/ats.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/ats.c +4 -2
index 9cb23780093d..f1434f86ac40 100644
@@ -56,7 +56,9 @@ EXPORT_SYMBOL_GPL(pci_ats_supported);
  * @ps: the IOMMU page shift
  *
  * This must be done by the IOMMU driver on the PF before any VFs are created to
- * ensure that the VF can have ATS enabled.
+ * ensure that the VF can have ATS enabled. Callers must verify that ATS is
+ * supported by the device (e.g. via pci_ats_supported()) before calling this
+ * function.
  *
  * Returns 0 on success, or negative on failure.
  */
@@ -64,7 +66,7 @@ int pci_prepare_ats(struct pci_dev *dev, int ps)
 {
 	u16 ctrl;
 
-	if (!pci_ats_supported(dev))
+	if (WARN_ON(!pci_ats_supported(dev)))
 		return -EINVAL;
 
 	if (WARN_ON(dev->ats_enabled))
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#2 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

Currently, pci_prepare_ats() internally calls pci_ats_supported() and returns -EINVAL if the device does not support ATS. While this provides a silent safety check, it conflates support detection with configuration.

Update pci_prepare_ats() to wrap the internal pci_ats_supported check in a WARN_ON(). This mandates all callers to call pci_prepare_ats() only if the function supports ATS.

Quoted 8 lines

Update the function documentation to mention that callers must verify ATS support (via pci_ats_supported()) before calling pci_prepare_ats().

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1