Re: [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor
From: Christian König
Date: Tue Sep 08 2026 - 04:57:12 EST
On 9/7/26 18:17, 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.
>
> Signed-off-by: Nikola Prica <nikola.prica@xxxxxxx>
Reviewed-by: Christian König <christian.koenig@xxxxxxx>
Bjorn first of all any objections to this? It sounds save to me, only a handful of drivers actually use this function and it generally seems to be the right things to do.
Then if you agree any objections to up-streaming it through AMDs GPU branch? That would make things a bit easier for us.
Thanks,
Christian.
> ---
> Changes in 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)