From: Bjorn Helgaas <helgaas@kernel.org>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
linux-pci@vger.kernel.org, Robin Murphy <robin.murphy@arm.com>,
Will Deacon <will@kernel.org>,
Alex Williamson <alex.williamson@redhat.com>,
Lu Baolu <baolu.lu@linux.intel.com>,
Donald Dutile <ddutile@redhat.com>,
galshalom@nvidia.com, Joerg Roedel <jroedel@suse.de>,
Kevin Tian <kevin.tian@intel.com>,
kvm@vger.kernel.org, maorg@nvidia.com, patches@lists.linux.dev,
tdave@nvidia.com, Tony Zhu <tony.zhu@intel.com>
Subject: Re: [PATCH v3 03/11] iommu: Compute iommu_groups properly for PCIe switches
Date: Tue, 9 Sep 2025 15:27:02 -0500 [thread overview]
Message-ID: <20250909202702.GA1504205@bhelgaas> (raw)
In-Reply-To: <3-v3-8827cc7fc4e0+23f-pcie_switch_groups_jgg@nvidia.com>
On Fri, Sep 05, 2025 at 03:06:18PM -0300, Jason Gunthorpe wrote:
> The current algorithm does not work if ACS is turned off, and it is not
> clear how this has been missed for so long. I think it has been avoided
> because the kernel command line options to target specific devices and
> disable ACS are rarely used.
>
> For discussion lets consider a simple topology like the below:
s/lets consider/consider/ (or "let's")
>
> -- DSP 02:00.0 -> End Point A
> Root 00:00.0 -> USP 01:00.0 --|
> -- DSP 02:03.0 -> End Point B
>
> If ACS is fully activated we expect 00:00.0, 01:00.0, 02:00.0, 02:03.0, A,
> B to all have unique single device groups.
>
> If both DSPs have ACS off then we expect 00:00.0 and 01:00.0 to have
> unique single device groups while 02:00.0, 02:03.0, A, B are part of one
> multi-device group.
>
> If the DSPs have asymmetric ACS, with one fully isolating and one
> non-isolating we also expect the above multi-device group result.
>
> Instead the current algorithm always creates unique single device groups
> for this topology. It happens because the pci_device_group(DSP)
> immediately moves to the USP and computes pci_acs_path_enabled(USP) ==
> true and decides the DSP can get a unique group. The pci_device_group(A)
> immediately moves to the DSP, sees pci_acs_path_enabled(DSP) == false and
> then takes the DSPs group.
s/takes the DSPs group/takes the DSP's group/ (I guess?)
> For root-ports a PCIe topology like:
s/root-ports/Root Ports/ (also various "root port" and "root complex"
spellings below that are typically capitalized in drivers/pci/)
> -- Dev 01:00.0
> Root 00:00.00 --- Root Port 00:01.0 --|
> | -- Dev 01:00.1
> |- Dev 00:17.0
>
> Previously would group [00:01.0, 01:00.0, 01:00.1] together if there is no
> ACS capability in the root port.
>
> While ACS on root ports is underspecified in the spec, it should still
> function as an egress control and limit access to either the MMIO of the
> root port itself, or perhaps some other devices upstream of the root
> complex - 00:17.0 perhaps in this example.
Does ACS have some kind of MMIO-specific restriction? Oh, I guess
this must be the "Memory Target Access Control" piece? (Added by the
upcoming patch 08/11).
> Historically the grouping in Linux has assumed the root port routes all
> traffic into the TA/IOMMU and never bypasses the TA to go to other
> functions in the root complex. Following the new understanding that ACS is
> required for internal loopback also treat root ports with no ACS
> capability as lacking internal loopback as well.
>
> The current algorithm has several issues:
>
> 1) It implicitly depends on ordering. Since the existing group discovery
> only goes in the upstream direction discovering a downstream device
> before its upstream will cause the wrong creation of narrower groups.
>
> 2) It assumes that if the path from the end point to the root is entirely
> ACS isolated then that end point is isolated. This misses cross-traffic
> in the asymmetric ACS case.
>
> 3) When evaluating a non-isolated DSP it does not check peer DSPs for an
> already established group unless the multi-function feature does it.
>
> 4) It does not understand the aliasing rule for PCIe to PCI bridges
> where the alias is to the subordinate bus. The bridge's RID on the
> primary bus is not aliased. This causes the PCIe to PCI bridge to be
> wrongly joined to the group with the downstream devices.
>
> As grouping is a security property for VFIO creating incorrectly narrowed
> groups is a security problem for the system.
I.e., we treated devices as being isolated from P2PDMA when they
actually were not isolated, right? More isolation => smaller
(narrower) IOMMU groups?
> Revise the design to solve these problems.
>
> Explicitly require ordering, or return EPROBE_DEFER if things are out of
> order. This avoids silent errors that created smaller groups and solves
> problem #1.
If it's easy to state, would be nice to say what ordering is required.
The issue mentioned above was "discovering a downstream device before
its upstream", so I guess you want to discover upstream devices before
downstream? Obviously PCI enumeration already works that way, so
IOMMU group discovery must be a little different.
> Work on busses, not devices. Isolation is a property of the bus, and the
> first non-isolated bus should form a group containing all devices
> downstream of that bus. If all busses on the path to an end device are
> isolated then the end device has a chance to make a single-device group.
>
> Use pci_bus_isolation() to compute the bus's isolation status based on the
> ACS flags and technology. pci_bus_isolation() touches a lot of PCI
> internals to get the information in the right format.
>
> Add a new flag in the iommu_group to record that the group contains a
> non-isolated bus. Any downstream pci_device_group() will see
> bus->self->iommu_group is non-isolated and unconditionally join it. This
> makes the first non-isolation apply to all downstream devices and solves
> problem #2
>
> The bus's non-isolated iommu_group will be stored in either the DSP of
> PCIe switch or the bus->self upstream device, depending on the situation.
> When storing in the DSP all the DSPs are checked first for a pre-existing
> non-isolated iommu_group. When stored in the upstream the flag forces it
> to all downstreams. This solves problem #3.
>
> Put the handling of end-device aliases and MFD into pci_get_alias_group()
> and only call it in cases where we have a fully isolated path. Otherwise
> every downstream device on the bus is going to be joined to the group of
> bus->self.
>
> Finally, replace the initial pci_for_each_dma_alias() with a combination
> of:
>
> - Directly checking pci_real_dma_dev() and enforcing ordering.
> The group should contain both pdev and pci_real_dma_dev(pdev) which is
> only possible if pdev is ordered after real_dma_dev. This solves a case
> of #1.
>
> - Indirectly relying on pci_bus_isolation() to report legacy PCI busses
> as non-isolated, with the enum including the distinction of the PCIe to
> PCI bridge being isolated from the downstream. This solves problem #4.
>
> It is very likely this is going to expand iommu_group membership in
> existing systems. After all that is the security bug that is being
> fixed. Expanding the iommu_groups risks problems for users using VFIO.
>
> The intention is to have a more accurate reflection of the security
> properties in the system and should be seen as a security fix. However
> people who have ACS disabled may now need to enable it. As such users may
> have had good reason for ACS to be disabled I strongly recommend that
> backporting of this also include the new config_acs option so that such
> users can potentially minimally enable ACS only where needed.
Minor nits below.
> +/* Return a group if the upstream hierarchy has isolation restrictions. */
> +static struct iommu_group *pci_hierarchy_group(struct pci_dev *pdev)
> +{
> + /*
> + * SRIOV functions may reside on a virtual bus, jump directly to the PFs
> + * bus in all cases.
> + */
> + struct pci_bus *bus = pci_physfn(pdev)->bus;
> + struct iommu_group *group;
> +
> + /* Nothing upstream of this */
> + if (pci_is_root_bus(bus))
> + return NULL;
> +
> + /*
> + * !self is only for SRIOV virtual busses which should have been
> + * excluded by pci_physfn()
> + */
> + if (WARN_ON(!bus->self))
> + return ERR_PTR(-EINVAL);
> +
> + group = iommu_group_get(&bus->self->dev);
> + if (!group) {
> + /*
> + * If the upstream bridge needs the same group as pdev then
> + * there is no way for it's pci_device_group() to discover it.
s/it's/its/
> + dev_err(&pdev->dev,
> + "PCI device is probing out of order, upstream bridge device of %s is not probed yet\n",
> + pci_name(bus->self));
> + return ERR_PTR(-EPROBE_DEFER);
> + }
> + if (group->bus_data & BUS_DATA_PCI_NON_ISOLATED)
> + return group;
> + iommu_group_put(group);
> + return NULL;
> +}
> +
> +/*
> + * For legacy PCI we have two main considerations when forming groups:
> + *
> + * 1) In PCI we can loose the RID inside the fabric, or some devices will use
> + * the wrong RID. The PCI core calls this aliasing, but from an IOMMU
> + * perspective it means that a PCI device may have multiple RIDs and a
> + * single RID may represent many PCI devices. This effectively means all the
> + * aliases must share a translation, thus group, because the IOMMU cannot
> + * tell devices apart.
s/loose/lose/
> + * 2) PCI permits a bus segment to claim an address even if the transaction
> + * originates from an end point not the CPU. When it happens it is called
> + * peer to peer. Claiming a transaction in the middle of the bus hierarchy
> + * bypasses the IOMMU translation. The IOMMU subsystem rules require these
> + * devices to be placed in the same group because they lack isolation from
> + * each other. In PCI Express the ACS system can be used to inhibit this and
> + * force transactions to go to the IOMMU.
> + *
> + * From a PCI perspective any given PCI bus is either isolating or
> + * non-isolating. Isolating means downstream originated transactions always
> + * progress toward the CPU and do not go to other devices on the bus
> + * segment, while non-isolating means downstream originated transactions can
> + * progress back downstream through another device on the bus segment.
> + *
> + * Beyond buses a multi-function device or bridge can also allow
> + * transactions to loop back internally from one function to another.
s/PCI Express/PCIe/ to match other usage?
Elsewhere in this series you use "busses". "Buses" is more common in
both drivers/pci and drivers/iommu.
> + *
> + * Once a PCI bus becomes non isolating the entire downstream hierarchy of
> + * that bus becomes a single group.
s/non isolating/non-isolating/ to match usage above
next prev parent reply other threads:[~2025-09-09 20:27 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 18:06 [PATCH v3 00/11] Fix incorrect iommu_groups with PCIe ACS Jason Gunthorpe
2025-09-05 18:06 ` [PATCH v3 01/11] PCI: Move REQ_ACS_FLAGS into pci_regs.h as PCI_ACS_ISOLATED Jason Gunthorpe
2025-09-09 4:08 ` Donald Dutile
2025-09-05 18:06 ` [PATCH v3 02/11] PCI: Add pci_bus_isolated() Jason Gunthorpe
2025-09-09 4:09 ` Donald Dutile
2025-09-09 19:54 ` Bjorn Helgaas
2025-09-09 21:21 ` Jason Gunthorpe
2025-09-05 18:06 ` [PATCH v3 03/11] iommu: Compute iommu_groups properly for PCIe switches Jason Gunthorpe
2025-09-09 4:14 ` Donald Dutile
2025-09-09 12:18 ` Jason Gunthorpe
2025-09-09 19:33 ` Donald Dutile
2025-09-09 20:27 ` Bjorn Helgaas [this message]
2025-09-09 21:21 ` Jason Gunthorpe
2025-09-05 18:06 ` [PATCH v3 04/11] iommu: Organize iommu_group by member size Jason Gunthorpe
2025-09-09 4:16 ` Donald Dutile
2025-09-05 18:06 ` [PATCH v3 05/11] PCI: Add pci_reachable_set() Jason Gunthorpe
2025-09-09 21:03 ` Bjorn Helgaas
2025-09-10 16:13 ` Jason Gunthorpe
2025-09-11 19:56 ` Donald Dutile
2025-09-15 13:38 ` Jason Gunthorpe
2025-09-15 14:32 ` Donald Dutile
2025-09-05 18:06 ` [PATCH v3 06/11] iommu: Compute iommu_groups properly for PCIe MFDs Jason Gunthorpe
2025-09-09 4:57 ` Donald Dutile
2025-09-09 13:31 ` Jason Gunthorpe
2025-09-09 19:55 ` Donald Dutile
2025-09-09 21:24 ` Bjorn Helgaas
2025-09-09 23:20 ` Jason Gunthorpe
2025-09-10 1:59 ` Donald Dutile
2025-09-10 17:43 ` Jason Gunthorpe
2025-09-05 18:06 ` [PATCH v3 07/11] iommu: Validate that pci_for_each_dma_alias() matches the groups Jason Gunthorpe
2025-09-09 5:00 ` Donald Dutile
2025-09-09 15:35 ` Jason Gunthorpe
2025-09-09 19:58 ` Donald Dutile
2025-09-05 18:06 ` [PATCH v3 08/11] PCI: Add the ACS Enhanced Capability definitions Jason Gunthorpe
2025-09-09 5:01 ` Donald Dutile
2025-09-05 18:06 ` [PATCH v3 09/11] PCI: Enable ACS Enhanced bits for enable_acs and config_acs Jason Gunthorpe
2025-09-09 5:01 ` Donald Dutile
2025-09-05 18:06 ` [PATCH v3 10/11] PCI: Check ACS DSP/USP redirect bits in pci_enable_pasid() Jason Gunthorpe
2025-09-09 5:02 ` Donald Dutile
2025-09-09 21:43 ` Bjorn Helgaas
2025-09-10 17:34 ` Jason Gunthorpe
2025-09-11 19:50 ` Donald Dutile
2026-01-20 18:08 ` Keith Busch
2025-09-05 18:06 ` [PATCH v3 11/11] PCI: Check ACS Extended flags for pci_bus_isolated() Jason Gunthorpe
2025-09-09 5:04 ` Donald Dutile
2025-09-15 9:41 ` [PATCH v3 00/11] Fix incorrect iommu_groups with PCIe ACS Cédric Le Goater
2025-09-22 22:39 ` Alex Williamson
2025-09-23 1:44 ` Donald Dutile
2025-09-23 2:06 ` Alex Williamson
2025-09-23 2:42 ` Donald Dutile
2025-09-23 22:23 ` Alex Williamson
2025-09-30 15:23 ` Donald Dutile
2025-09-30 16:21 ` Jason Gunthorpe
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=20250909202702.GA1504205@bhelgaas \
--to=helgaas@kernel.org \
--cc=alex.williamson@redhat.com \
--cc=baolu.lu@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=ddutile@redhat.com \
--cc=galshalom@nvidia.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=jroedel@suse.de \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=maorg@nvidia.com \
--cc=patches@lists.linux.dev \
--cc=robin.murphy@arm.com \
--cc=tdave@nvidia.com \
--cc=tony.zhu@intel.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