Re: [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor

From: Prica, Nikola

Date: Fri Sep 18 2026 - 05:27:32 EST


Hi Christian, Gerd,

Yes, this fixes a recent regression that we recognized with 6.8.0-135-generic kernel release. And it is the commit that Gerd referenced. I'll add Fixes tag.

Thanks for your attention and help!

Regards,
Nikola

On 9/14/2026 3:54 PM, Christian König wrote:
On 9/14/26 15:41, Gerd Bayer wrote:

On Mon, 2026-09-07 at 18:17 +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.

Hi Nikola,

your patch got me interested, since it touches those parts of
pci_enable_atomic_ops_to_root() that commit 1ae8c4ce1570 ("PCI: Enable
AtomicOps only if Root Port supports them") has modified.

I like your solution for putting the hypervisor in control of the
enablement of Atomic Ops on root-less PCI functions and did test your
change on s390/Connect-X, successfully.

Signed-off-by: Nikola Prica <nikola.prica@xxxxxxx>

If that commit of mine regressed your use-cases, you might even want to
add a Fixes: tag?

Oh, that's an interesting point. I wasn't aware that the root complex check was added so recently.

So indeed question @Nikola did that worked out of the box before kernel 7.1? If yes then that would be a regression.

Regards,
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)

At any rate, feel free to add my

Reviewed-by: Gerd Bayer <gbayer@xxxxxxxxxxxxx>
Tested-by: Gerd Bayer <gbayer@xxxxxxxxxxxxx>