Re: [PATCH v4 2/5] PCI/ATS: Validate STU for VFs in pci_prepare_ats()
From: Pranjal Shrivastava
Date: Thu May 28 2026 - 16:34:46 EST
On Mon, May 25, 2026 at 12:46:53PM -0700, Nicolin Chen wrote:
> On Mon, May 25, 2026 at 06:43:44PM +0000, Pranjal Shrivastava wrote:
> > While every PCI Function that implements ATS has an independent ATS
> > Extended Capability structure with a Read/Write Smallest Translation
> > Unit (STU) field, the kernel manages SR-IOV ATS by requiring the IOMMU
> > driver to configure the STU on the Physical Function (PF) before any
> > any Virtual Functions (VFs) are created.
> >
> > Currently, pci_prepare_ats() bails out early for VFs, assuming that the
> > PF has already been correctly prepared. However, this creates a potential
> > mismatch if a VF is subsequently prepared with a different page shift.
> >
> > Update pci_prepare_ats() to validate that the requested page shift (ps)
> > matches the STU already configured in the associated PF. This ensures
> > early detection of incompatible configurations and maintains the kernel's
> > policy of consistent STU sizing across all functions associated with a
> > given SMMU.
> >
> > Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> > Reviewed-by: Samiullah Khawaja <skhawaja@xxxxxxxxxx>
> > Signed-off-by: Pranjal Shrivastava <praan@xxxxxxxxxx>
>
> Reviewed-by: Nicolin Chen <nicolinc@xxxxxxxxxx>
>
> Nit:
>
> > @@ -73,8 +73,13 @@ int pci_prepare_ats(struct pci_dev *dev, int ps)
> > if (ps < PCI_ATS_MIN_STU)
> > return -EINVAL;
> >
> > - if (dev->is_virtfn)
> > + if (dev->is_virtfn) {
> > + struct pci_dev *pdev = pci_physfn(dev);
> > +
> > + if (pdev->ats_stu != ps)
> > + return -EINVAL;
> > return 0;
> > + }
>
> pdev doesn't seem useful. Dropping it reads better to me:
> if (pci_physfn(dev)->ats_stu != ps)
> return -EINVAL;
Ahh, I missed this nit in the v5 I just posted. I'll surely address this
in the next revision.
Thanks,
Praan