Re: [PATCH v4] PCI: Accept AtomicOps already enabled by the hypervisor
From: Bjorn Helgaas
Date: Thu Oct 01 2026 - 13:16:26 EST
On Mon, Sep 21, 2026 at 01:19:03PM +0200, Nikola Prica wrote:
> From: Nikola Prica <nikola.prica@xxxxxxx>
>
> pci_enable_atomic_ops_to_root() currently fails when no Root Port is
> visible. That is common in passthrough guests (ESXi, Hyper-V): the
> endpoint is assigned to the VM, but the guest topology has no Root
> Port above it.
>
> In those setups the hypervisor may already have enabled AtomicOp
> Requester Enable on the device. If PCI_EXP_DEVCTL2_ATOMIC_REQ is set,
> treat AtomicOps as already enabled and return success instead of
> failing the Root Port walk.
>
> After 1ae8c4ce1570 ("PCI: Enable AtomicOps only if Root Port
> supports them"), pci_enable_atomic_ops_to_root() always fails if the
> Root Port is not visible. On systems where the Root Port is not
> visible but *does* support AtomicOps, this is a regression: prior to
> 1ae8c4ce1570, it enabled AtomicOps in the endpoint and returned
> success.
>
> Fixes: 1ae8c4ce1570 ("PCI: Enable AtomicOps only if Root Port supports them")
> Reviewed-by: Christian König <christian.koenig@xxxxxxx>
> Reviewed-by: Gerd Bayer <gbayer@xxxxxxxxxxxxx>
> Tested-by: Gerd Bayer <gbayer@xxxxxxxxxxxxx>
> Signed-off-by: Nikola Prica <nikola.prica@xxxxxxx>
Applied to pci/for-linus for v7.3, thank you!
I tweaked the last paragraph to be more explicit about the regression
behavior (as I understand it):
After 1ae8c4ce1570 ("PCI: Enable AtomicOps only if Root Port
supports them"), pci_enable_atomic_ops_to_root() always returns
failure if the Root Port is not visible, so drivers don't use
atomics when they could.
> ---
> v4: Updates commit log to make regression point clear
> v3: Add Fixes tag
> v2: Be more strict and only apply logic in headless device case.
> ---
> drivers/pci/pci.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index b2879a6be5f8..62729ade496f 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -3769,8 +3769,18 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
> }
>
> root = pcie_find_root_port(dev);
> - if (!root)
> + if (!root) {
> + /*
> + * A hypervisor may expose a headless topology with no
> + * visible root port. If it has already set AtomicOp
> + * Requester Enable, there is nothing more to do.
> + */
> + pcie_capability_read_dword(dev, PCI_EXP_DEVCTL2, &ctl2);
> + if (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_REQ)
> + return 0;
> +
> return -EINVAL;
> + }
>
> pcie_capability_read_dword(root, PCI_EXP_DEVCAP2, &cap);
> if ((cap & cap_mask) != cap_mask)
> --
> 2.34.1
>