mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor
       [not found] <20260903121217.23F751F000E9@smtp.kernel.org>
@ 2026-09-07 16:17 ` Nikola Prica
  2026-09-08  8:47   ` Christian König
  2026-09-14 13:41   ` Gerd Bayer
  0 siblings, 2 replies; 9+ messages in thread
From: Nikola Prica @ 2026-09-07 16:17 UTC (permalink / raw)
  To: bhelgaas
  Cc: linux-pci, linux-kernel, jerry.jiang, haijun.chang, andy.zhang,
	christian.koenig, jim.chow, matthew.mcclure, Nikola Prica

From: Nikola Prica <nikola.prica@amd.com>

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@amd.com>
---
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)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor
  2026-09-07 16:17 ` [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor Nikola Prica
@ 2026-09-08  8:47   ` Christian König
  2026-09-11 14:09     ` Prica, Nikola
  2026-09-14 13:41   ` Gerd Bayer
  1 sibling, 1 reply; 9+ messages in thread
From: Christian König @ 2026-09-08  8:47 UTC (permalink / raw)
  To: Nikola Prica, bhelgaas
  Cc: linux-pci, linux-kernel, jerry.jiang, haijun.chang, andy.zhang,
	jim.chow, matthew.mcclure, Nikola Prica, Deucher, Alexander

On 9/7/26 18:17, Nikola Prica wrote:
> From: Nikola Prica <nikola.prica@amd.com>
> 
> 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@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

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)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor
  2026-09-08  8:47   ` Christian König
@ 2026-09-11 14:09     ` Prica, Nikola
  0 siblings, 0 replies; 9+ messages in thread
From: Prica, Nikola @ 2026-09-11 14:09 UTC (permalink / raw)
  To: Christian König, Nikola Prica, bhelgaas
  Cc: linux-pci, linux-kernel, jerry.jiang, haijun.chang, andy.zhang,
	jim.chow, matthew.mcclure, Deucher, Alexander

Hi Bjorn, any thoughs on this? Do you need more information?

Thanks,
Nikola

On 9/8/2026 10:47 AM, Christian König wrote:
> On 9/7/26 18:17, Nikola Prica wrote:
>> From: Nikola Prica <nikola.prica@amd.com>
>>
>> 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@amd.com>
> 
> Reviewed-by: Christian König <christian.koenig@amd.com>
> 
> 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)
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor
  2026-09-07 16:17 ` [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor Nikola Prica
  2026-09-08  8:47   ` Christian König
@ 2026-09-14 13:41   ` Gerd Bayer
  2026-09-14 13:54     ` Christian König
  1 sibling, 1 reply; 9+ messages in thread
From: Gerd Bayer @ 2026-09-14 13:41 UTC (permalink / raw)
  To: Nikola Prica, bhelgaas, Niklas Schnelle, Alexander Schmidt
  Cc: linux-pci, linux-kernel, jerry.jiang, haijun.chang, andy.zhang,
	christian.koenig, jim.chow, matthew.mcclure, Nikola Prica

On Mon, 2026-09-07 at 18:17 +0200, Nikola Prica wrote:
> From: Nikola Prica <nikola.prica@amd.com>
> 
> 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@amd.com>

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

> ---
> 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@linux.ibm.com>
Tested-by: Gerd Bayer <gbayer@linux.ibm.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor
  2026-09-14 13:41   ` Gerd Bayer
@ 2026-09-14 13:54     ` Christian König
  2026-09-18  9:07       ` Prica, Nikola
  0 siblings, 1 reply; 9+ messages in thread
From: Christian König @ 2026-09-14 13:54 UTC (permalink / raw)
  To: Gerd Bayer, Nikola Prica, bhelgaas, Niklas Schnelle, Alexander Schmidt
  Cc: linux-pci, linux-kernel, jerry.jiang, haijun.chang, andy.zhang,
	jim.chow, matthew.mcclure, Nikola Prica

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@amd.com>
>>
>> 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@amd.com>
> 
> 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@linux.ibm.com>
> Tested-by: Gerd Bayer <gbayer@linux.ibm.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor
  2026-09-14 13:54     ` Christian König
@ 2026-09-18  9:07       ` Prica, Nikola
  2026-09-18  9:28         ` [PATCH v3] " Nikola Prica
  0 siblings, 1 reply; 9+ messages in thread
From: Prica, Nikola @ 2026-09-18  9:07 UTC (permalink / raw)
  To: Christian König, Gerd Bayer, Nikola Prica, bhelgaas,
	Niklas Schnelle, Alexander Schmidt
  Cc: linux-pci, linux-kernel, jerry.jiang, haijun.chang, andy.zhang,
	jim.chow, matthew.mcclure

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@amd.com>
>>>
>>> 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@amd.com>
>>
>> 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@linux.ibm.com>
>> Tested-by: Gerd Bayer <gbayer@linux.ibm.com>
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3] PCI: Accept AtomicOps already enabled by the hypervisor
  2026-09-18  9:07       ` Prica, Nikola
@ 2026-09-18  9:28         ` Nikola Prica
  2026-09-18 12:07           ` Christian König
  0 siblings, 1 reply; 9+ messages in thread
From: Nikola Prica @ 2026-09-18  9:28 UTC (permalink / raw)
  To: bhelgaas
  Cc: linux-pci, linux-kernel, stable, jerry.jiang, haijun.chang,
	andy.zhang, christian.koenig, jim.chow, matthew.mcclure, gbayer,
	Nikola Prica

From: Nikola Prica <nikola.prica@amd.com>

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.

Fixes: 1ae8c4ce1570 ("PCI: Enable AtomicOps only if Root Port supports them")
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com>
Tested-by: Gerd Bayer <gbayer@linux.ibm.com>
Signed-off-by: Nikola Prica <nikola.prica@amd.com>

---
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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] PCI: Accept AtomicOps already enabled by the hypervisor
  2026-09-18  9:28         ` [PATCH v3] " Nikola Prica
@ 2026-09-18 12:07           ` Christian König
  2026-09-18 17:07             ` Bjorn Helgaas
  0 siblings, 1 reply; 9+ messages in thread
From: Christian König @ 2026-09-18 12:07 UTC (permalink / raw)
  To: Nikola Prica, bhelgaas, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, stable, jerry.jiang, haijun.chang,
	andy.zhang, jim.chow, matthew.mcclure, gbayer, Nikola Prica

On 9/18/26 11:28, Nikola Prica wrote:
> From: Nikola Prica <nikola.prica@amd.com>
> 
> 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.
> 
> Fixes: 1ae8c4ce1570 ("PCI: Enable AtomicOps only if Root Port supports them")
> Reviewed-by: Christian König <christian.koenig@amd.com>
> Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com>
> Tested-by: Gerd Bayer <gbayer@linux.ibm.com>
> Signed-off-by: Nikola Prica <nikola.prica@amd.com>

CC: stable@vger.kernel.org # 7.1+

Bjorn do you want to pick that up? Alternative I can push it through drm-misc-fixes.

Initially I thought that this is a new feature, but it turned out to be an regression and we need to get it fixed ASAP.

Thanks,
Christian.

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] PCI: Accept AtomicOps already enabled by the hypervisor
  2026-09-18 12:07           ` Christian König
@ 2026-09-18 17:07             ` Bjorn Helgaas
  0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Helgaas @ 2026-09-18 17:07 UTC (permalink / raw)
  To: Christian König
  Cc: Nikola Prica, bhelgaas, linux-pci, linux-kernel, stable,
	jerry.jiang, haijun.chang, andy.zhang, jim.chow, matthew.mcclure,
	gbayer, Nikola Prica

On Fri, Sep 18, 2026 at 02:07:46PM +0200, Christian König wrote:
> On 9/18/26 11:28, Nikola Prica wrote:
> > From: Nikola Prica <nikola.prica@amd.com>
> > 
> > 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.
> > 
> > Fixes: 1ae8c4ce1570 ("PCI: Enable AtomicOps only if Root Port supports them")
> > Reviewed-by: Christian König <christian.koenig@amd.com>
> > Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com>
> > Tested-by: Gerd Bayer <gbayer@linux.ibm.com>
> > Signed-off-by: Nikola Prica <nikola.prica@amd.com>
> 
> CC: stable@vger.kernel.org # 7.1+
> 
> Bjorn do you want to pick that up? Alternative I can push it through
> drm-misc-fixes.
> 
> Initially I thought that this is a new feature, but it turned out to
> be an regression and we need to get it fixed ASAP.

Let me just talk through this to make sure I understand it:

Prior to 1ae8c4ce1570, pci_enable_atomic_ops_to_root() enabled
PCI_EXP_DEVCTL2_ATOMIC_REQ unless a switch port didn't support
AtomicOp routing, a switch upstream port blocked AtomicOp egress, or a
Root Port didn't support the requested sizes.

1ae8c4ce1570 added the requirement that the Root Port be visible,
which fixed an s390 case where pci_enable_atomic_ops_to_root() enabled
AtomicOps when the Root Port did not support them but was not visible
to the kernel.

IIUC the regression is on systems where the Root Port is not visible
but *does* support AtomicOps.  Prior to 1ae8c4ce1570, we would have
enabled AtomicOps in the endpoint and returned success.  After
1ae8c4ce1570, we return -EINVAL because we can't see the Root Port to
verify its support, so the driver thinks it can't use AtomicOps.

This patch fixes the regression by assuming that if we can't see the
Root Port but the endpoint already has AtomicOps enabled, the
hypervisor or host kernel that *can* see the Root Port has already
verified its AtomicOps support, so all we have to do is return success
so the driver can use them.

I'm happy to merge this for v7.3, and I think we should add something
like this to the commit log to make it clear that it's a regression
worthy of a post-merge window fix:

  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.

Is there any problem report for the regression?  I don't see anything
at https://linux-regtracking.leemhuis.info/regzbot/mainline/, so my
guess is no.

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-09-18 17:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20260903121217.23F751F000E9@smtp.kernel.org>
2026-09-07 16:17 ` [PATCH v2] PCI: Accept AtomicOps already enabled by the hypervisor Nikola Prica
2026-09-08  8:47   ` Christian König
2026-09-11 14:09     ` Prica, Nikola
2026-09-14 13:41   ` Gerd Bayer
2026-09-14 13:54     ` Christian König
2026-09-18  9:07       ` Prica, Nikola
2026-09-18  9:28         ` [PATCH v3] " Nikola Prica
2026-09-18 12:07           ` Christian König
2026-09-18 17:07             ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®