| Message ID | 20261001233338.918408-2-praan@google.com |
|---|---|
| State | New |
| Headers | show |
| Series | PCI/ATS: Mandate checking pci_ats_supported() before pci_prepare_ats() | expand |
> 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(). > > Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> > Suggested-by: Baolu Lu <baolu.lu@linux.intel.com> > Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> > Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> > Signed-off-by: Pranjal Shrivastava <praan@google.com> Sashiko has reviewed this patch and found no issues. It looks great!
diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index 9cb23780093d..f1434f86ac40 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -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))