qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] pci: ensure valid link status bits for downstream ports
@ 2024-12-03 12:19 Sebastian Ott
  2024-12-03 14:28 ` Alex Williamson
  2025-01-17  6:21 ` Michael Tokarev
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Ott @ 2024-12-03 12:19 UTC (permalink / raw)
  To: Alex Williamson, Marcel Apfelbaum, Michael S . Tsirkin
  Cc: qemu-devel, Sebastian Ott, Zhenyu Zhang

PCI hotplug for downstream endpoints on arm fails because Linux'
PCIe hotplug driver doesn't like the QEMU provided LNKSTA:

  pcieport 0000:08:01.0: pciehp: Slot(2): Card present
  pcieport 0000:08:01.0: pciehp: Slot(2): Link Up
  pcieport 0000:08:01.0: pciehp: Slot(2): Cannot train link: status 0x2000

There's 2 cases where LNKSTA isn't setup properly:
* the downstream device has no express capability
* max link width of the bridge is 0

Move the sanity checks added via 88c869198aa63
("pci: Sanity test minimum downstream LNKSTA") outside of the
branch to make sure downstream ports always have a valid LNKSTA.

Signed-off-by: Sebastian Ott <sebott@redhat.com>
Tested-by: Zhenyu Zhang <zhenyzha@redhat.com>
---
 hw/pci/pcie.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 0b455c8654..1b12db6fa2 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -1113,18 +1113,22 @@ void pcie_sync_bridge_lnk(PCIDevice *bridge_dev)
         if ((lnksta & PCI_EXP_LNKSTA_NLW) > (lnkcap & PCI_EXP_LNKCAP_MLW)) {
             lnksta &= ~PCI_EXP_LNKSTA_NLW;
             lnksta |= lnkcap & PCI_EXP_LNKCAP_MLW;
-        } else if (!(lnksta & PCI_EXP_LNKSTA_NLW)) {
-            lnksta |= QEMU_PCI_EXP_LNKSTA_NLW(QEMU_PCI_EXP_LNK_X1);
         }
 
         if ((lnksta & PCI_EXP_LNKSTA_CLS) > (lnkcap & PCI_EXP_LNKCAP_SLS)) {
             lnksta &= ~PCI_EXP_LNKSTA_CLS;
             lnksta |= lnkcap & PCI_EXP_LNKCAP_SLS;
-        } else if (!(lnksta & PCI_EXP_LNKSTA_CLS)) {
-            lnksta |= QEMU_PCI_EXP_LNKSTA_CLS(QEMU_PCI_EXP_LNK_2_5GT);
         }
     }
 
+    if (!(lnksta & PCI_EXP_LNKSTA_NLW)) {
+        lnksta |= QEMU_PCI_EXP_LNKSTA_NLW(QEMU_PCI_EXP_LNK_X1);
+    }
+
+    if (!(lnksta & PCI_EXP_LNKSTA_CLS)) {
+        lnksta |= QEMU_PCI_EXP_LNKSTA_CLS(QEMU_PCI_EXP_LNK_2_5GT);
+    }
+
     pci_word_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA,
                                  PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW);
     pci_word_test_and_set_mask(exp_cap + PCI_EXP_LNKSTA, lnksta &
-- 
2.42.0



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

* Re: [PATCH v2] pci: ensure valid link status bits for downstream ports
  2024-12-03 12:19 [PATCH v2] pci: ensure valid link status bits for downstream ports Sebastian Ott
@ 2024-12-03 14:28 ` Alex Williamson
  2024-12-17 15:52   ` Sebastian Ott
  2025-01-07 16:48   ` Sebastian Ott
  2025-01-17  6:21 ` Michael Tokarev
  1 sibling, 2 replies; 5+ messages in thread
From: Alex Williamson @ 2024-12-03 14:28 UTC (permalink / raw)
  To: Sebastian Ott
  Cc: Marcel Apfelbaum, Michael S . Tsirkin, qemu-devel, Zhenyu Zhang

On Tue,  3 Dec 2024 13:19:28 +0100
Sebastian Ott <sebott@redhat.com> wrote:

> PCI hotplug for downstream endpoints on arm fails because Linux'
> PCIe hotplug driver doesn't like the QEMU provided LNKSTA:
> 
>   pcieport 0000:08:01.0: pciehp: Slot(2): Card present
>   pcieport 0000:08:01.0: pciehp: Slot(2): Link Up
>   pcieport 0000:08:01.0: pciehp: Slot(2): Cannot train link: status 0x2000
> 
> There's 2 cases where LNKSTA isn't setup properly:
> * the downstream device has no express capability
> * max link width of the bridge is 0
> 
> Move the sanity checks added via 88c869198aa63
> ("pci: Sanity test minimum downstream LNKSTA") outside of the
> branch to make sure downstream ports always have a valid LNKSTA.
> 
> Signed-off-by: Sebastian Ott <sebott@redhat.com>
> Tested-by: Zhenyu Zhang <zhenyzha@redhat.com>
> ---
>  hw/pci/pcie.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

Reviewed-by: Alex Williamson <alex.williamson@redhat.com>


> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index 0b455c8654..1b12db6fa2 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -1113,18 +1113,22 @@ void pcie_sync_bridge_lnk(PCIDevice *bridge_dev)
>          if ((lnksta & PCI_EXP_LNKSTA_NLW) > (lnkcap & PCI_EXP_LNKCAP_MLW)) {
>              lnksta &= ~PCI_EXP_LNKSTA_NLW;
>              lnksta |= lnkcap & PCI_EXP_LNKCAP_MLW;
> -        } else if (!(lnksta & PCI_EXP_LNKSTA_NLW)) {
> -            lnksta |= QEMU_PCI_EXP_LNKSTA_NLW(QEMU_PCI_EXP_LNK_X1);
>          }
>  
>          if ((lnksta & PCI_EXP_LNKSTA_CLS) > (lnkcap & PCI_EXP_LNKCAP_SLS)) {
>              lnksta &= ~PCI_EXP_LNKSTA_CLS;
>              lnksta |= lnkcap & PCI_EXP_LNKCAP_SLS;
> -        } else if (!(lnksta & PCI_EXP_LNKSTA_CLS)) {
> -            lnksta |= QEMU_PCI_EXP_LNKSTA_CLS(QEMU_PCI_EXP_LNK_2_5GT);
>          }
>      }
>  
> +    if (!(lnksta & PCI_EXP_LNKSTA_NLW)) {
> +        lnksta |= QEMU_PCI_EXP_LNKSTA_NLW(QEMU_PCI_EXP_LNK_X1);
> +    }
> +
> +    if (!(lnksta & PCI_EXP_LNKSTA_CLS)) {
> +        lnksta |= QEMU_PCI_EXP_LNKSTA_CLS(QEMU_PCI_EXP_LNK_2_5GT);
> +    }
> +
>      pci_word_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA,
>                                   PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW);
>      pci_word_test_and_set_mask(exp_cap + PCI_EXP_LNKSTA, lnksta &



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

* Re: [PATCH v2] pci: ensure valid link status bits for downstream ports
  2024-12-03 14:28 ` Alex Williamson
@ 2024-12-17 15:52   ` Sebastian Ott
  2025-01-07 16:48   ` Sebastian Ott
  1 sibling, 0 replies; 5+ messages in thread
From: Sebastian Ott @ 2024-12-17 15:52 UTC (permalink / raw)
  To: Marcel Apfelbaum, Michael S . Tsirkin
  Cc: Alex Williamson, qemu-devel, Zhenyu Zhang

Hi,

On Tue, 3 Dec 2024, Alex Williamson wrote:
> On Tue,  3 Dec 2024 13:19:28 +0100
> Sebastian Ott <sebott@redhat.com> wrote:
>
>> PCI hotplug for downstream endpoints on arm fails because Linux'
>> PCIe hotplug driver doesn't like the QEMU provided LNKSTA:
>>
>>   pcieport 0000:08:01.0: pciehp: Slot(2): Card present
>>   pcieport 0000:08:01.0: pciehp: Slot(2): Link Up
>>   pcieport 0000:08:01.0: pciehp: Slot(2): Cannot train link: status 0x2000
>>
>> There's 2 cases where LNKSTA isn't setup properly:
>> * the downstream device has no express capability
>> * max link width of the bridge is 0
>>
>> Move the sanity checks added via 88c869198aa63
>> ("pci: Sanity test minimum downstream LNKSTA") outside of the
>> branch to make sure downstream ports always have a valid LNKSTA.
>>
>> Signed-off-by: Sebastian Ott <sebott@redhat.com>
>> Tested-by: Zhenyu Zhang <zhenyzha@redhat.com>
>> ---
>>  hw/pci/pcie.c | 12 ++++++++----
>>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> Reviewed-by: Alex Williamson <alex.williamson@redhat.com>

Can someone pick this up for the next qemu release?

Thanks,
Sebastian



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

* Re: [PATCH v2] pci: ensure valid link status bits for downstream ports
  2024-12-03 14:28 ` Alex Williamson
  2024-12-17 15:52   ` Sebastian Ott
@ 2025-01-07 16:48   ` Sebastian Ott
  1 sibling, 0 replies; 5+ messages in thread
From: Sebastian Ott @ 2025-01-07 16:48 UTC (permalink / raw)
  To: Marcel Apfelbaum, Michael S . Tsirkin
  Cc: Alex Williamson, qemu-devel, Zhenyu Zhang

Hello Michael, Marcel,

On Tue, 3 Dec 2024, Alex Williamson wrote:

> On Tue,  3 Dec 2024 13:19:28 +0100
> Sebastian Ott <sebott@redhat.com> wrote:
>
>> PCI hotplug for downstream endpoints on arm fails because Linux'
>> PCIe hotplug driver doesn't like the QEMU provided LNKSTA:
>>
>>   pcieport 0000:08:01.0: pciehp: Slot(2): Card present
>>   pcieport 0000:08:01.0: pciehp: Slot(2): Link Up
>>   pcieport 0000:08:01.0: pciehp: Slot(2): Cannot train link: status 0x2000
>>
>> There's 2 cases where LNKSTA isn't setup properly:
>> * the downstream device has no express capability
>> * max link width of the bridge is 0
>>
>> Move the sanity checks added via 88c869198aa63
>> ("pci: Sanity test minimum downstream LNKSTA") outside of the
>> branch to make sure downstream ports always have a valid LNKSTA.
>>
>> Signed-off-by: Sebastian Ott <sebott@redhat.com>
>> Tested-by: Zhenyu Zhang <zhenyzha@redhat.com>
>> ---
>>  hw/pci/pcie.c | 12 ++++++++----
>>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> Reviewed-by: Alex Williamson <alex.williamson@redhat.com>

Can you pick this up for the next qemu release, please? It fixes PCI
hotplug for downstream endpoints on arm.

Thanks,
Sebastian



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

* Re: [PATCH v2] pci: ensure valid link status bits for downstream ports
  2024-12-03 12:19 [PATCH v2] pci: ensure valid link status bits for downstream ports Sebastian Ott
  2024-12-03 14:28 ` Alex Williamson
@ 2025-01-17  6:21 ` Michael Tokarev
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Tokarev @ 2025-01-17  6:21 UTC (permalink / raw)
  To: Sebastian Ott, Alex Williamson, Marcel Apfelbaum,
	Michael S . Tsirkin
  Cc: qemu-devel, Zhenyu Zhang, qemu-stable

03.12.2024 15:19, Sebastian Ott wrote:
> PCI hotplug for downstream endpoints on arm fails because Linux'
> PCIe hotplug driver doesn't like the QEMU provided LNKSTA:
> 
>    pcieport 0000:08:01.0: pciehp: Slot(2): Card present
>    pcieport 0000:08:01.0: pciehp: Slot(2): Link Up
>    pcieport 0000:08:01.0: pciehp: Slot(2): Cannot train link: status 0x2000
> 
> There's 2 cases where LNKSTA isn't setup properly:
> * the downstream device has no express capability
> * max link width of the bridge is 0
> 
> Move the sanity checks added via 88c869198aa63
> ("pci: Sanity test minimum downstream LNKSTA") outside of the
> branch to make sure downstream ports always have a valid LNKSTA.

This seems to be a qemu-stable material.  Please let me know it it
is not.

Thanks,

/mjt

> Signed-off-by: Sebastian Ott <sebott@redhat.com>
> Tested-by: Zhenyu Zhang <zhenyzha@redhat.com>
> ---
>   hw/pci/pcie.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index 0b455c8654..1b12db6fa2 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -1113,18 +1113,22 @@ void pcie_sync_bridge_lnk(PCIDevice *bridge_dev)
>           if ((lnksta & PCI_EXP_LNKSTA_NLW) > (lnkcap & PCI_EXP_LNKCAP_MLW)) {
>               lnksta &= ~PCI_EXP_LNKSTA_NLW;
>               lnksta |= lnkcap & PCI_EXP_LNKCAP_MLW;
> -        } else if (!(lnksta & PCI_EXP_LNKSTA_NLW)) {
> -            lnksta |= QEMU_PCI_EXP_LNKSTA_NLW(QEMU_PCI_EXP_LNK_X1);
>           }
>   
>           if ((lnksta & PCI_EXP_LNKSTA_CLS) > (lnkcap & PCI_EXP_LNKCAP_SLS)) {
>               lnksta &= ~PCI_EXP_LNKSTA_CLS;
>               lnksta |= lnkcap & PCI_EXP_LNKCAP_SLS;
> -        } else if (!(lnksta & PCI_EXP_LNKSTA_CLS)) {
> -            lnksta |= QEMU_PCI_EXP_LNKSTA_CLS(QEMU_PCI_EXP_LNK_2_5GT);
>           }
>       }
>   
> +    if (!(lnksta & PCI_EXP_LNKSTA_NLW)) {
> +        lnksta |= QEMU_PCI_EXP_LNKSTA_NLW(QEMU_PCI_EXP_LNK_X1);
> +    }
> +
> +    if (!(lnksta & PCI_EXP_LNKSTA_CLS)) {
> +        lnksta |= QEMU_PCI_EXP_LNKSTA_CLS(QEMU_PCI_EXP_LNK_2_5GT);
> +    }
> +
>       pci_word_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA,
>                                    PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW);
>       pci_word_test_and_set_mask(exp_cap + PCI_EXP_LNKSTA, lnksta &



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

end of thread, other threads:[~2025-01-17  6:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-03 12:19 [PATCH v2] pci: ensure valid link status bits for downstream ports Sebastian Ott
2024-12-03 14:28 ` Alex Williamson
2024-12-17 15:52   ` Sebastian Ott
2025-01-07 16:48   ` Sebastian Ott
2025-01-17  6:21 ` Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).