All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pranjal Shrivastava <praan@google.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Nicolin Chen <nicolinc@nvidia.com>,
	iommu@lists.linux.dev, Will Deacon <will@kernel.org>,
	Joerg Roedel <joro@8bytes.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Mostafa Saleh <smostafa@google.com>,
	Samiullah Khawaja <skhawaja@google.com>,
	Daniel Mentz <danielmentz@google.com>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	David Matlack <dmatlack@google.com>
Subject: Re: [PATCH rc v2] iommu/arm-smmu-v3: Fix inconsistent ATS state tracking
Date: Tue, 5 May 2026 22:32:40 +0000	[thread overview]
Message-ID: <afpwCIjQXwfImPXm@google.com> (raw)
In-Reply-To: <afpdm5lfIeWptxOh@google.com>

On Tue, May 05, 2026 at 09:14:03PM +0000, Pranjal Shrivastava wrote:
> On Tue, May 05, 2026 at 01:11:26PM -0300, Jason Gunthorpe wrote:
> > On Mon, May 04, 2026 at 07:33:07PM +0000, Pranjal Shrivastava wrote:
> > 
> > > > > The issue was exposed under heavy load when running a VFIO-based DMA map
> > > > > stress test: iova_stress [1]
> > > > 
> > > > I wonder what's the real reason for pci_enable_ats() to fail:
> > > > 
> > > 
> > > Yes, It's the dev->is_virtfn case (the one you suspect below)
> > 
> > Oh.... This is a much larger problem then
> > 
> > The VF should not fail to enable ATS, that is a meaningful bug, I'm
> > not sure why are are just discovering this?
> > 
> > It looks like the PF unconditionally calls pci_prepare_ats() during
> > arm_smmu_probe_device(), so how does this happen:
> > 
> > > >         if (dev->is_virtfn) {
> > > >                 pdev = pci_physfn(dev);
> > > >                 if (pdev->ats_stu != ps)
> > > >                         return -EINVAL;		// maybe this one?
> > 
> > ??
> > 
> > So, I think the right error handling for a case that shouldn't happen is
> > to fail the attachment not to try to continue it broken?
> > 
> 
> Hmm.. you mean we should fail the VF attach if it's PF's ATS isn't
> enabled?
> 
> I agree prepare_ats is called regardless on every device and we return
> early without setting the STU if (dev->is_virtfn) but the catch is we
> never check for pci_prepare_ats's return value in probe_device :/
> (The PF might be untrusted or non ATS capable).
> 
> Here's the EXACT failing case:
> 
> 1. arm_smmu_probe_device(PF) -> we call pci_prepare_ats & ignore retval
> 2. The PF attaches to Identity domain (pci_enable_ats skipped, no logs)
> 3. We create VFs and try to assign them (new group -> unmanaged domain)
> 4. We try to enable ATS in attach_commit, fail and see the failure log
> 5. arm-smmu-v3 driver tracks the state as "ATS enabled" for VF
> 6. We try to disable ATS which was never enabled and hit the WARN
> 
> The catch is in step 1, pci_prepare_ats(PF) returned -EINVAL as either
> the ATS capability didn't exist OR the device was untrusted but the
> driver let it slide (ignored the retval in probe_device).
> I'll debug further to see which one is it (because in that case
> arm_smmu_ats_supported should've failed too).
> 

I added some logs to check the reason of failure.
To make the matter worse, I believe I spotted this due to a broken HW.
(Although, we can face something similar with untrusted etc. in the mix)

The PF shows no ATS Cap:

[    0.575749] PCI host bridge to bus 000X:00
[    0.575773] pci 000X:00:00.0: set_pcie_untrusted: no parent bridge, removable=0, external_facing=0
[    0.575774] pci 000X:00:00.0: [abab:cdcd] type 00 class 0x060000 conventional PCI endpoint
[    0.575786] pci 000X:00:00.0: pci_ats_supported: NO ATS CAPABILITY FOUND (ats_cap=0)
[    0.575787] pci 000X:00:00.0: pci_ats_supported: NO ATS CAPABILITY FOUND (ats_cap=0)
[    0.575819] pci 000X:00:01.0: set_pcie_untrusted: no parent bridge, removable=0, external_facing=0
[    0.575821] pci 000X:00:01.0: [abab:cdcd] type 01 class 0x060400 PCIe Root Port
[    2.591975] pci 000X:00:00.0: pci_ats_supported: NO ATS CAPABILITY FOUND (ats_cap=0)
[    2.591979] pci 000X:00:00.0: pci_prepare_ats: ps=12, is_virtfn=0, ats_cap=0x0
[    2.591980] pci 000X:00:00.0: pci_ats_supported: NO ATS CAPABILITY FOUND (ats_cap=0)
[    2.591981] pci 000X:00:00.0: pci_prepare_ats failed: not supported
[    2.592001] pci 000X:00:00.0: Adding to iommu group 19
[    2.592007] pci 000X:00:01.0: pci_ats_supported: NO ATS CAPABILITY FOUND (ats_cap=0)
[    2.592009] pci 000X:00:01.0: pci_prepare_ats: ps=12, is_virtfn=0, ats_cap=0x0

Whereas the VF presents ATS cap:

[   16.803702] pci 000X:02:00.0: [abab:cdcd] type 00 class 0x020000 PCIe Endpoint
[   16.803869] pci 000X:02:00.0: pci_prepare_ats: ps=12, is_virtfn=1, ats_cap=0x1e4
[   16.803871] pci 000X:02:00.0: pci_prepare_ats: device is VF, returning success
[   16.803927] pci 000X:02:00.0: Adding to iommu group <redacted>
[   16.803941] pci 000X:02:00.0: arm_smmu_ats_supported: dev is PCI, ats_cap=0x1e4, untrusted=0, pci_ats_supported=1
[   16.803949] pci 000X:02:00.0: Calling pci_enable_ats(STU 12)
[   16.803950] pci 000X:02:00.0: pci_enable_ats: ps=12, is_virtfn=1, ats_cap=0x1e4
[   16.803951] pci 000X:02:00.0: pci_enable_ats: checking PF (000X:01:00.0) -> ats_cap=0x0, ats_enabled=0, ats_stu=0
[   16.803952] pci 000X:02:00.0: pci_enable_ats failed: STU mismatch (PF STU = 0 vs VF STU = 12)
[   16.803954] pci 000X:02:00.0: Failed to enable ATS (STU 12) error -22
[   16.804168] pci 000X:02:00.0: disabling ATS

which means pci_ats_supported returns true for such broken HW. Ideally,
it should return false for VF if the PF doesn't support ATS!

Currently, we don't *really* enable ATS but I believe pci_ats_supported
should fail in such cases.

Thanks,
Praan

  reply	other threads:[~2026-05-05 22:32 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04 16:38 [PATCH rc v2] iommu/arm-smmu-v3: Fix inconsistent ATS state tracking Pranjal Shrivastava
2026-05-04 18:01 ` Nicolin Chen
2026-05-04 19:33   ` Pranjal Shrivastava
2026-05-04 20:03     ` Pranjal Shrivastava
2026-05-04 20:23     ` Nicolin Chen
2026-05-04 20:29       ` Pranjal Shrivastava
2026-05-04 20:51         ` Nicolin Chen
2026-05-04 20:40       ` Pranjal Shrivastava
2026-05-04 20:54         ` Nicolin Chen
2026-05-05 16:11     ` Jason Gunthorpe
2026-05-05 20:21       ` Nicolin Chen
2026-05-05 21:23         ` Pranjal Shrivastava
2026-05-05 21:44           ` Nicolin Chen
2026-05-05 22:06             ` Pranjal Shrivastava
2026-05-06 20:44         ` Samiullah Khawaja
2026-05-05 21:14       ` Pranjal Shrivastava
2026-05-05 22:32         ` Pranjal Shrivastava [this message]
2026-05-06  9:46           ` Jason Gunthorpe
2026-05-06 20:19             ` Pranjal Shrivastava
2026-05-06 22:03               ` Pranjal Shrivastava
2026-05-06 21:57             ` Pranjal Shrivastava
2026-05-06 22:04               ` Pranjal Shrivastava
2026-05-09 17:14                 ` Jason Gunthorpe
2026-05-11 12:07                   ` Pranjal Shrivastava
2026-05-11 14:16                     ` Jason Gunthorpe
2026-05-11 16:07                       ` Pranjal Shrivastava
2026-05-11 16:30                         ` David Matlack
2026-05-11 16:57                           ` Pranjal Shrivastava
2026-05-11 17:03                         ` Jason Gunthorpe
2026-05-06 22:20               ` Samiullah Khawaja
2026-05-07 20:12                 ` Pranjal Shrivastava

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afpwCIjQXwfImPXm@google.com \
    --to=praan@google.com \
    --cc=danielmentz@google.com \
    --cc=dmatlack@google.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=nicolinc@nvidia.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=robin.murphy@arm.com \
    --cc=skhawaja@google.com \
    --cc=smostafa@google.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.