From: Jason Gunthorpe <jgg@nvidia.com>
To: "Tian, Kevin" <kevin.tian@intel.com>
Cc: Lu Baolu <baolu.lu@linux.intel.com>,
Bjorn Helgaas <bhelgaas@google.com>,
David Woodhouse <dwmw2@infradead.org>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
Joerg Roedel <joro@8bytes.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Will Deacon <will@kernel.org>,
"patches@lists.linux.dev" <patches@lists.linux.dev>
Subject: Re: [PATCH] iommu: Allow ATS to work on VFs when the PF uses IDENTITY
Date: Fri, 9 Aug 2024 10:28:45 -0300 [thread overview]
Message-ID: <20240809132845.GG8378@nvidia.com> (raw)
In-Reply-To: <BN9PR11MB52762296EEA7F307A48591518CBA2@BN9PR11MB5276.namprd11.prod.outlook.com>
On Fri, Aug 09, 2024 at 02:36:14AM +0000, Tian, Kevin wrote:
> > From: Jason Gunthorpe <jgg@nvidia.com>
> > Sent: Thursday, August 8, 2024 2:19 AM
> >
> > PCI ATS has a global Smallest Translation Unit field that is located in
> > the PF but shared by all of the VFs.
> >
> > The expectation is that the STU will be set to the root port's global STU
> > capability which is driven by the IO page table configuration of the iommu
> > HW. Today it becomes set when the iommu driver first enables ATS.
> >
> > Thus, to enable ATS on the VF, the PF must have already had the correct
> > STU programmed, even if ATS is off on the PF.
> >
> > Unfortunately the PF only programs the STU when the PF enables ATS. The
> > iommu drivers tend to leave ATS disabled when IDENTITY translation is
> > being used.
>
> Is there more context on this?
How do you mean?
> Looking at intel-iommu driver ATS is disabled for IDENETITY when
> the iommu is in legacy mode:
>
> dmar_domain_attach_device()
> {
> ...
> if (sm_supported(info->iommu) || !domain_type_is_si(info->domain))
> iommu_enable_pci_caps(info);
> ...
> }
>
> But this follows what VT-d spec says (section 9.3):
>
> TT: Translate Type
> 10b: Untranslated requests are processed as pass-through. The SSPTPTR
> field is ignored by hardware. Translated and Translation Requests are
> blocked.
Yes, HW like this is exactly the problem, it ends up not enabling ATS
on the PF and then we don't have the STU programmed so the VF is
effectively disabled too.
Ideally iommus would continue to work with translated requests when
ATS is enabled. Not supporting this configuration creates a nasty
problem for devices that are using PASID.
The PASID may require ATS to be enabled (ie SVA), but the RID may be
IDENTITY for performance. The poor device has no idea it is not
allowed to use ATS on the RID side :(
> > +/**
> > + * pci_prepare_ats - Setup the PS for ATS
> > + * @dev: the PCI device
> > + * @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.
> > + *
> > + * Returns 0 on success, or negative on failure.
> > + */
> > +int pci_prepare_ats(struct pci_dev *dev, int ps)
> > +{
> > + u16 ctrl;
> > +
> > + if (!pci_ats_supported(dev))
> > + return -EINVAL;
> > +
> > + if (WARN_ON(dev->ats_enabled))
> > + return -EBUSY;
> > +
> > + if (ps < PCI_ATS_MIN_STU)
> > + return -EINVAL;
> > +
> > + if (dev->is_virtfn)
> > + return 0;
>
> missed a check that 'ps' matches pf's ats_stu.
Deliberate, that check is done when enabling ats:
> > +
> > + dev->ats_stu = ps;
> > + ctrl = PCI_ATS_CTRL_STU(dev->ats_stu - PCI_ATS_MIN_STU);
> > + pci_write_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, ctrl);
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(pci_prepare_ats);
> > +
>
> Then there is no need to keep the 'ps' parameter in pci_enable_ats().
Which is why I left it here.
Jason
next prev parent reply other threads:[~2024-08-09 13:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-07 18:19 [PATCH] iommu: Allow ATS to work on VFs when the PF uses IDENTITY Jason Gunthorpe
2024-08-09 2:36 ` Tian, Kevin
2024-08-09 13:28 ` Jason Gunthorpe [this message]
2024-08-12 0:09 ` Tian, Kevin
2024-08-12 9:03 ` Yi Liu
2024-08-12 11:35 ` Jason Gunthorpe
2024-08-13 3:00 ` Yi Liu
2024-08-09 19:10 ` Bjorn Helgaas
2024-08-12 2:20 ` Baolu Lu
2024-08-13 3:11 ` Yi Liu
2024-08-13 12:30 ` Jason Gunthorpe
2024-08-13 23:21 ` Yi Liu
2024-08-13 8:52 ` Joerg Roedel
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=20240809132845.GG8378@nvidia.com \
--to=jgg@nvidia.com \
--cc=baolu.lu@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).