From: Jason Gunthorpe <jgg@ziepe.ca>
To: Vasant Hegde <vasant.hegde@amd.com>
Cc: iommu@lists.linux.dev, joro@8bytes.org,
suravee.suthikulpanit@amd.com, wei.huang2@amd.com,
jsnitsel@redhat.com
Subject: Re: [PATCH v6 08/15] iommu/amd: Enable PCI features based on attached domain capability
Date: Tue, 5 Mar 2024 12:01:08 -0400 [thread overview]
Message-ID: <20240305160108.GJ9225@ziepe.ca> (raw)
In-Reply-To: <87abadb2-aa08-3a79-e1a2-4031b2c7e791@amd.com>
On Tue, Mar 05, 2024 at 08:40:08PM +0530, Vasant Hegde wrote:
> Jason,
>
>
> On 3/5/2024 6:02 AM, Jason Gunthorpe wrote:
> > On Fri, Feb 09, 2024 at 11:29:23AM +0000, Vasant Hegde wrote:
> >> Commit eda8c2860ab ("iommu/amd: Enable device ATS/PASID/PRI capabilities
> >> independently") changed the way it enables device capability while
> >> attaching devices. I missed to account the attached domain capability.
> >> Meaning if domain is not capable of handling PASID/PRI (ex: paging
> >> domain with v1 page table) then enabling device feature is not required.
> >>
> >> This patch enables PASID/PRI only if domain is capable of handling SVA.
> >> Also move pci feature enablement to do_attach() function so that we make
> >> SVA capability in one place. Finally make PRI enable/disable functions as
> >> static functions.
> >
> >> @@ -2036,6 +2038,7 @@ static int do_attach(struct iommu_dev_data *dev_data,
> >> struct protection_domain *domain)
> >> {
> >> struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
> >> + struct pci_dev *pdev;
> >> int ret = 0;
> >>
> >> /* Update data structures */
> >> @@ -2050,10 +2053,16 @@ static int do_attach(struct iommu_dev_data *dev_data,
> >> domain->dev_iommu[iommu->index] += 1;
> >> domain->dev_cnt += 1;
> >>
> >> + pdev = dev_is_pci(dev_data->dev) ? to_pci_dev(dev_data->dev) : NULL;
> >> if (pdom_is_sva_capable(domain)) {
> >> ret = init_gcr3_table(dev_data, domain);
> >> if (ret)
> >> return ret;
> >> +
> >> + if (pdev)
> >> + pdev_enable_caps(pdev);
> >
> > But here we are turning PRI on for an IDENTITY domain and for a v2
> > domain that doesn't have a PRI handler. This is not technically what
> > we want to see, the PRI capability at the device should only be turned
> > on when a PRI handler is available in the SW side. Otherwise PRI
> > should be off and non-present ATS responses should fail in the device.
>
> We are setting up handler right after enabling capability for both IDENTIFY and
> v2 domain as both can support SVA mode.
It is enabling PRI when the device can enable PRI but before any
driver has actually asked for any PRI features. It is technically too
early.
It should be enabled when a SVA domain is first attached.
Like we don't want the HW to generate PRI faults from a VM
deliberately banging on non-translated page table memory. This is a
pure DOS attack on the hypervisor kernel and should be prevented by
having PRI turned off.
> > Also, PASID enablement looks like the wrong spot too, it should be
> > done in the probe_device() callback and stay enabled. The bit is set
> > if the IOMMU HW can decode the PASID TLP. Ie don't enable it on old
> > IOMMU HW that can't understand PASID.
>
> Our V1 page table is not compatible with PASID. Hence currently its done in
> attach_device path.
What does "compatible" mean exactly?
The PASID cap on the device is only about the IOMMU HW ability to
properly *parse* PASID, it can fail every PASID tagged TLP and it
would still be fine to turn it on at the device always.
v1 is clearly not able to route PASID to different translations, but
as long as a v1 DTE fails every single PASID tagged TLP you can always
turn PASID on at the source just fine.
It would be a very weird design if v2 HW makes the DTE in v1 mode just
discards the PASID and translates everything with the v1 table. I'd
also wonder if the identity/blocked cases are similarly weird?
IOW, I would expect to see probe_device check if the HW supports V2,
if it does it knows the HW can parse the PASID in the TLP and will
abort PASID's without translations (ie v1 DTEs). Then you turn on
PASID support always. If the HW supports only v1 then assume it
doesn't know how to parse the PASID and will ignore it and fold all
PASID requests into the RID. Leave PASID always off.
Jason
next prev parent reply other threads:[~2024-03-05 16:01 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 11:29 [PATCH v6 00/15] iommu/amd: SVA Support (Part 4) - SVA and IOPF Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 01/15] iommu/amd: Rename amd_iommu_v2_supported() as amd_iommu_pasid_supported() Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 02/15] iommu/amd: Introduce per device DTE update function Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 03/15] iommu/amd: Add support for enabling/disabling IOMMU features Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 04/15] iommu/amd: Move PPR-related functions into ppr.c Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 05/15] iommu/amd: Fix PPR interrupt processing logic Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 06/15] iommu/amd: Introduce iommu_dev_data.max_pasids Vasant Hegde
2024-03-04 23:46 ` Jason Gunthorpe
2024-02-09 11:29 ` [PATCH v6 07/15] iommu/amd: Setup GCR3 table in advance if domain is SVA capable Vasant Hegde
2024-03-05 0:11 ` Jason Gunthorpe
2024-03-11 11:20 ` Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 08/15] iommu/amd: Enable PCI features based on attached domain capability Vasant Hegde
2024-03-05 0:32 ` Jason Gunthorpe
2024-03-05 15:10 ` Vasant Hegde
2024-03-05 16:01 ` Jason Gunthorpe [this message]
2024-03-11 10:02 ` Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 09/15] iommu/amd: Define per-IOMMU iopf_queue Vasant Hegde
2024-03-05 0:33 ` Jason Gunthorpe
2024-02-09 11:29 ` [PATCH v6 10/15] iommu/amd: Add support for page response Vasant Hegde
2024-03-05 0:35 ` Jason Gunthorpe
2024-02-09 11:29 ` [PATCH v6 11/15] iommu/amd: Add IO page fault notifier handler Vasant Hegde
2024-03-05 0:40 ` Jason Gunthorpe
2024-03-11 11:00 ` Vasant Hegde
2024-03-19 17:54 ` Jason Gunthorpe
2024-02-09 11:29 ` [PATCH v6 12/15] iommu/amd: Add support for enable/disable IOPF Vasant Hegde
2024-03-05 0:42 ` Jason Gunthorpe
2024-03-05 15:21 ` Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 13/15] iommu/amd: Initial SVA support for AMD IOMMU Vasant Hegde
2024-03-05 0:50 ` Jason Gunthorpe
2024-03-11 11:11 ` Vasant Hegde
2024-03-19 17:56 ` Jason Gunthorpe
2024-03-27 6:15 ` Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 14/15] iommu: Add ops->domain_alloc_sva() Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 15/15] iommu/amd: Add SVA domain support Vasant Hegde
2024-03-05 0:52 ` [PATCH v6 00/15] iommu/amd: SVA Support (Part 4) - SVA and IOPF Jason Gunthorpe
2024-03-05 14:59 ` Vasant Hegde
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=20240305160108.GJ9225@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=jsnitsel@redhat.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=vasant.hegde@amd.com \
--cc=wei.huang2@amd.com \
/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