Skip to contentSkip to conversation

PCI/portdrv: Add necessary delay for disabling hotplug events

PATCH Superseded Feng Tang 4 participants 19 messages Feb 4, 2025 – Feb 12, 2025 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Feng Tang

author
#0 lore raw

PATCH 1/2 PCI/portdrv: Add necessary delay for disabling hotplug events

According to PCIe 6.1 spec, section 6.7.3.2, software need to wait at least 1 second for the command-complete event, before resending the cmd or sending a new cmd.

Currently get_port_device_capability() sends slot control cmd to disable PCIe hotplug interrupts without waiting for its completion and there was real problem reported for the lack of waiting.

Add the necessary wait to comply with PCIe spec. The waiting logic refers existing pcie_poll_cmd().

---
 drivers/pci/pci.h          |  2 ++
 drivers/pci/pcie/portdrv.c | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)
drivers/pci/pci.h +2 -0
index 01e51db8d285..c1e234d1b81d 100644
@@ -759,12 +759,14 @@ static inline void pcie_ecrc_get_policy(char *str) { }
 #ifdef CONFIG_PCIEPORTBUS
 void pcie_reset_lbms_count(struct pci_dev *port);
 int pcie_lbms_count(struct pci_dev *port, unsigned long *val);
+void pcie_disable_hp_interrupts_early(struct pci_dev *dev);
 #else
 static inline void pcie_reset_lbms_count(struct pci_dev *port) {}
 static inline int pcie_lbms_count(struct pci_dev *port, unsigned long *val)
 {
 	return -EOPNOTSUPP;
 }
+static inline void pcie_disable_hp_interrupts_early(struct pci_dev *dev) {}
 #endif
 
 struct pci_dev_reset_methods {
drivers/pci/pcie/portdrv.c +31 -2
index 02e73099bad0..16010973bfe2 100644
@@ -18,6 +18,7 @@
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/aer.h>
+#include <linux/delay.h>
 
 #include "../pci.h"
 #include "portdrv.h"
@@ -205,6 +206,35 @@ static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
 	return 0;
 }
 
+static int pcie_wait_sltctl_cmd_raw(struct pci_dev *pdev)
+{
+	u16 slot_status;
+	/* 1000 ms, according toPCIe spec 6.1, section 6.7.3.2 */
+	int timeout = 1000;
+
+	do {
+		pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
+		if (slot_status & PCI_EXP_SLTSTA_CC) {
+			pcie_capability_write_word(pdev, PCI_EXP_SLTSTA,
+						   PCI_EXP_SLTSTA_CC);
+			return 0;
+		}
+		msleep(10);
+		timeout -= 10;
+	} while (timeout);
+
+	/* Timeout */
+	return  -1;
+}
+
+void pcie_disable_hp_interrupts_early(struct pci_dev *dev)
+{
+	pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
+		  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
+	if (pcie_wait_sltctl_cmd_raw(dev))
+		pci_info(dev, "Timeout on disabling hot-plug interrupts\n");
+}
+
 /**
  * get_port_device_capability - discover capabilities of a PCI Express port
  * @dev: PCI Express port to examine
@@ -230,8 +260,7 @@ static int get_port_device_capability(struct pci_dev *dev)
 		 * Disable hot-plug interrupts in case they have been enabled
 		 * by the BIOS and the hot-plug service driver is not loaded.
 		 */
-		pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
-			  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
+		pcie_disable_hp_interrupts_early(dev);
 	}
 
 #ifdef CONFIG_PCIEAER
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/2 PCI: Disable PCIE hotplug interrupts early when msi is disabled

There was a irq storm bug when testing "pci=nomsi" case, and the root cause is: 'nomsi' will disable MSI and let devices and root ports use legacy INTX inerrupt, and likely make several devices/ports share one interrupt. In the failure case, BIOS doesn't disable the PCIE hotplug interrupts, and actually asserts the command-complete interrupt. As MSI is disabled, ACPI initialization code will not enumerate root port's PCIE hotplug capability, and pciehp service driver wont' be enabled for the root port to handle that interrupt, later on when it is shared and enabled by other device driver like NVME or NIC, the "nobody care irq storm" happens.

So disable the pcie hotplug CCIE/HPIE interrupt in early boot phase when MSI is not enbaled.

---
 drivers/pci/probe.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pci/probe.c +9 -0
index b6536ed599c3..10d72156da9a 100644
@@ -1664,6 +1664,15 @@ void set_pcie_hotplug_bridge(struct pci_dev *pdev)
 	pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, &reg32);
 	if (reg32 & PCI_EXP_SLTCAP_HPC)
 		pdev->is_hotplug_bridge = 1;
+
+	/*
+	 * When MSI is disabled, root port will use legacy INTX, and likely
+	 * share INTX interrupt line with other devices like NIC/NVME. There
+	 * was real world issue that the CCIE IRQ is asserted afer boot, but
+	 * will not be handled well and cause IRQ storm. So disable it early.
+	 */
+	if (!pci_msi_enabled())
+		pcie_disable_hp_interrupts_early(pdev);
 }
 
 static void set_pcie_thunderbolt(struct pci_dev *dev)
Signature · 1 line
2.43.5
#2 lore raw

Re: [PATCH 2/2] PCI: Disable PCIE hotplug interrupts early when msi is disabled

Quoted 11 lines · Feng Tang

There was a irq storm bug when testing "pci=nomsi" case, and the root cause is: 'nomsi' will disable MSI and let devices and root ports use legacy INTX inerrupt, and likely make several devices/ports share one interrupt. In the failure case, BIOS doesn't disable the PCIE hotplug interrupts, and actually asserts the command-complete interrupt. As MSI is disabled, ACPI initialization code will not enumerate root port's PCIE hotplug capability, and pciehp service driver wont' be enabled for the root port to handle that interrupt, later on when it is shared and enabled by other device driver like NVME or NIC, the "nobody care irq storm" happens.

Quoted 2 lines

So disable the pcie hotplug CCIE/HPIE interrupt in early boot phase when MSI is not enbaled.

So I think this issue should go away if disabling the interrupt by portdrv is no longer conditional on

  (pcie_ports_native || host->native_pcie_hotplug)

like I've just proposed here:

https://lore.kernel.org/r/[email protected]/

... in which case this patch won't be necessary. Can you confirm that?

You can split the change I've proposed into two patches if you like.

Thanks,

Lukas

author
#3 lore raw

Re: [PATCH 2/2] PCI: Disable PCIE hotplug interrupts early when msi is disabled

Quoted 18 lines · Lukas Wunner
Quoted 11 lines · Feng Tang

There was a irq storm bug when testing "pci=nomsi" case, and the root cause is: 'nomsi' will disable MSI and let devices and root ports use legacy INTX inerrupt, and likely make several devices/ports share one interrupt. In the failure case, BIOS doesn't disable the PCIE hotplug interrupts, and actually asserts the command-complete interrupt. As MSI is disabled, ACPI initialization code will not enumerate root port's PCIE hotplug capability, and pciehp service driver wont' be enabled for the root port to handle that interrupt, later on when it is shared and enabled by other device driver like NVME or NIC, the "nobody care irq storm" happens.

Quoted 2 lines

So disable the pcie hotplug CCIE/HPIE interrupt in early boot phase when MSI is not enbaled.

So I think this issue should go away if disabling the interrupt by portdrv is no longer conditional on

Quoted 7 lines
  (pcie_ports_native || host->native_pcie_hotplug)

like I've just proposed here:

https://lore.kernel.org/r/[email protected]/

... in which case this patch won't be necessary. Can you confirm that?

Thanks for the suggestion! I will try to get the platform for test, and report back.

As for the change,

	 +		if (!IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE))
	 +			pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
	 +				  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);

The CONFIG_HOTPLUG_PCI_PCIE is always enabled on our platform and many distros, I guess the check needs to be removed, which sees the 1 second waiting again, and need the waiting logic in 1/2 patch?

Thanks,
Feng

Quoted 6 lines

You can split the change I've proposed into two patches if you like.

Thanks,

Lukas

author
#4 lore raw

Re: [PATCH 2/2] PCI: Disable PCIE hotplug interrupts early when msi is disabled

Quoted 21 lines · Feng Tang
Quoted 20 lines · Lukas Wunner
Quoted 11 lines · Feng Tang

There was a irq storm bug when testing "pci=nomsi" case, and the root cause is: 'nomsi' will disable MSI and let devices and root ports use legacy INTX inerrupt, and likely make several devices/ports share one interrupt. In the failure case, BIOS doesn't disable the PCIE hotplug interrupts, and actually asserts the command-complete interrupt. As MSI is disabled, ACPI initialization code will not enumerate root port's PCIE hotplug capability, and pciehp service driver wont' be enabled for the root port to handle that interrupt, later on when it is shared and enabled by other device driver like NVME or NIC, the "nobody care irq storm" happens.

Quoted 2 lines

So disable the pcie hotplug CCIE/HPIE interrupt in early boot phase when MSI is not enbaled.

So I think this issue should go away if disabling the interrupt by portdrv is no longer conditional on

  (pcie_ports_native || host->native_pcie_hotplug)
Quoted 8 lines
Quoted 5 lines

like I've just proposed here:

https://lore.kernel.org/r/[email protected]/

... in which case this patch won't be necessary. Can you confirm that?

Thanks for the suggestion! I will try to get the platform for test, and report back.

I haven't got the platform, but I recalled something, that disabling HP interrupts inside get_port_device_capability()/portdrv_probe() got called after the nvme_probe(), so it may still cause the irq storm due to:

* pcie root port's hotplug interrupt asserted
* the interrupt is shared with NVME and other device
* those device drivers enable the interrupt line early before portdrv's probe()

That's why we tried to put the disabling early in PCI initialization code.

Thanks,
Feng

Quoted 11 lines

As for the change,

	 +		if (!IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE))
	 +			pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
	 +				  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);

The CONFIG_HOTPLUG_PCI_PCIE is always enabled on our platform and many distros, I guess the check needs to be removed, which sees the 1 second waiting again, and need the waiting logic in 1/2 patch?

Thanks,
Feng

#5 lore raw

Re: [PATCH 2/2] PCI: Disable PCIE hotplug interrupts early when msi is disabled

In reply to Feng Tang
Quoted 10 lines · Feng Tang

There was a irq storm bug when testing "pci=nomsi" case, and the root cause is: 'nomsi' will disable MSI and let devices and root ports use legacy INTX inerrupt, and likely make several devices/ports share one interrupt. In the failure case, BIOS doesn't disable the PCIE hotplug interrupts, and actually asserts the command-complete interrupt. As MSI is disabled, ACPI initialization code will not enumerate root port's PCIE hotplug capability, and pciehp service driver wont' be enabled for the root port to handle that interrupt, later on when it is shared and enabled by other device driver like NVME or NIC, the "nobody care irq storm" happens.

Is there a section in the PCI Firmware Spec which says ACPI doesn't enumerate the hotplug capability if MSI is disabled?

If so, it should be referenced in the commit message.

If not, I'm wondering if it's safe to fiddle with the Slot Control register given the platform hasn't granted OSPM control of it.

Of course if this is spec-defined behavior in the nomsi case, we could make the write to the Slot Control register conditional on that. But if this turns out to be platform-specific behavior, we can't deal with it in generic PCI code but only in a quirk.

Thanks,

Lukas

author
#6 lore raw

Re: [PATCH 2/2] PCI: Disable PCIE hotplug interrupts early when msi is disabled

Hi Lukas,

Quoted 12 lines · Lukas Wunner
Quoted 10 lines · Feng Tang

There was a irq storm bug when testing "pci=nomsi" case, and the root cause is: 'nomsi' will disable MSI and let devices and root ports use legacy INTX inerrupt, and likely make several devices/ports share one interrupt. In the failure case, BIOS doesn't disable the PCIE hotplug interrupts, and actually asserts the command-complete interrupt. As MSI is disabled, ACPI initialization code will not enumerate root port's PCIE hotplug capability, and pciehp service driver wont' be enabled for the root port to handle that interrupt, later on when it is shared and enabled by other device driver like NVME or NIC, the "nobody care irq storm" happens.

Quoted 2 lines

Is there a section in the PCI Firmware Spec which says ACPI doesn't enumerate the hotplug capability if MSI is disabled?

No, I didn't get it from spec, but found the logic by code reading during debugging the irq storm issue. The related code is about:

#define ACPI_PCIE_REQ_SUPPORT (OSC_PCI_EXT_CONFIG_SUPPORT \
				| OSC_PCI_ASPM_SUPPORT \
				| OSC_PCI_CLOCK_PM_SUPPORT \
				| OSC_PCI_MSI_SUPPORT)

acpi_pci_root_add

	negotiate_os_control
		calculate_support
			if (pci_msi_enabled())
				support |= OSC_PCI_MSI_SUPPORT;
		decode_osc_support
		os_control_query_checks
			if ((support & ACPI_PCIE_REQ_SUPPORT) != ACPI_PCIE_REQ_SUPPORT)
				return false
		acpi_pci_osc_control_set

And later in get_port_device_capability(), the pciehp service bit won't be set, and driver is not loaded.

Thanks,
Feng

Quoted 13 lines

If so, it should be referenced in the commit message.

If not, I'm wondering if it's safe to fiddle with the Slot Control register given the platform hasn't granted OSPM control of it.

Of course if this is spec-defined behavior in the nomsi case, we could make the write to the Slot Control register conditional on that. But if this turns out to be platform-specific behavior, we can't deal with it in generic PCI code but only in a quirk.

Thanks,

Lukas

#7 lore raw

Re: [PATCH 2/2] PCI: Disable PCIE hotplug interrupts early when msi is disabled

[to += Rafael, start of thread is here:
https://lore.kernel.org/all/[email protected]/
]

Hi Rafael,

Quoted 16 lines · Feng Tang
Quoted 12 lines · Lukas Wunner
Quoted 10 lines · Feng Tang

There was a irq storm bug when testing "pci=nomsi" case, and the root cause is: 'nomsi' will disable MSI and let devices and root ports use legacy INTX inerrupt, and likely make several devices/ports share one interrupt. In the failure case, BIOS doesn't disable the PCIE hotplug interrupts, and actually asserts the command-complete interrupt. As MSI is disabled, ACPI initialization code will not enumerate root port's PCIE hotplug capability, and pciehp service driver wont' be enabled for the root port to handle that interrupt, later on when it is shared and enabled by other device driver like NVME or NIC, the "nobody care irq storm" happens.

Quoted 2 lines

Is there a section in the PCI Firmware Spec which says ACPI doesn't enumerate the hotplug capability if MSI is disabled?

Quoted 7 lines

No, I didn't get it from spec, but found the logic by code reading during debugging the irq storm issue. The related code is about:

#define ACPI_PCIE_REQ_SUPPORT (OSC_PCI_EXT_CONFIG_SUPPORT \
				| OSC_PCI_ASPM_SUPPORT \
				| OSC_PCI_CLOCK_PM_SUPPORT \
				| OSC_PCI_MSI_SUPPORT)

Commit 415e12b23792 ("PCI/ACPI: Request _OSC control once for each root bridge (v3)") contains a change which doesn't seem to be explained in the commit message:

If the user passes "pci=nomsi" on the command line, Linux doesn't request hotplug control (or any other control) from the platform. So ACPI always remains responsible for hotplug in the "pci=nomsi" case.

The commit sought to fix a cpu hog issue:

https://bugzilla.kernel.org/show_bug.cgi?id=29722

It's unclear to me if that bug was fixed by requesting _OSC only once, as the commit message suggests, or if the addition of OSC_MSI_SUPPORT to ACPI_PCIE_REQ_SUPPORT fixed the issue.

Since the latter is not mentioned in the commit message, it seems plausible to assume that the OSC_MSI_SUPPORT change was unintentional.

In any case it doesn't seem to make sense to not request any control in the "pci=nomsi" case.

It's also worth noting that the behavior is different on Apple machines as they use a fixed _OSC set even for "pci=nomsi".

I'm wondering if OSC_PCI_MSI_SUPPORT should simply be removed from ACPI_PCIE_REQ_SUPPORT, but I'm worried that it may cause reappearance of the cpu hog issue.

Thoughts?

Thanks,

Lukas

author
#8 lore raw

Re: [PATCH 2/2] PCI: Disable PCIE hotplug interrupts early when msi is disabled

Quoted 55 lines · Lukas Wunner

[to += Rafael, start of thread is here:
https://lore.kernel.org/all/[email protected]/
]

Hi Rafael,

Quoted 16 lines · Feng Tang
Quoted 12 lines · Lukas Wunner
Quoted 10 lines · Feng Tang

There was a irq storm bug when testing "pci=nomsi" case, and the root cause is: 'nomsi' will disable MSI and let devices and root ports use legacy INTX inerrupt, and likely make several devices/ports share one interrupt. In the failure case, BIOS doesn't disable the PCIE hotplug interrupts, and actually asserts the command-complete interrupt. As MSI is disabled, ACPI initialization code will not enumerate root port's PCIE hotplug capability, and pciehp service driver wont' be enabled for the root port to handle that interrupt, later on when it is shared and enabled by other device driver like NVME or NIC, the "nobody care irq storm" happens.

Quoted 2 lines

Is there a section in the PCI Firmware Spec which says ACPI doesn't enumerate the hotplug capability if MSI is disabled?

Quoted 7 lines

No, I didn't get it from spec, but found the logic by code reading during debugging the irq storm issue. The related code is about:

#define ACPI_PCIE_REQ_SUPPORT (OSC_PCI_EXT_CONFIG_SUPPORT \
				| OSC_PCI_ASPM_SUPPORT \
				| OSC_PCI_CLOCK_PM_SUPPORT \
				| OSC_PCI_MSI_SUPPORT)

Commit 415e12b23792 ("PCI/ACPI: Request _OSC control once for each root bridge (v3)") contains a change which doesn't seem to be explained in the commit message:

If the user passes "pci=nomsi" on the command line, Linux doesn't request hotplug control (or any other control) from the platform. So ACPI always remains responsible for hotplug in the "pci=nomsi" case.

The commit sought to fix a cpu hog issue:

https://bugzilla.kernel.org/show_bug.cgi?id=29722

It's unclear to me if that bug was fixed by requesting _OSC only once, as the commit message suggests, or if the addition of OSC_MSI_SUPPORT to ACPI_PCIE_REQ_SUPPORT fixed the issue.

Since the latter is not mentioned in the commit message, it seems plausible to assume that the OSC_MSI_SUPPORT change was unintentional.

In any case it doesn't seem to make sense to not request any control in the "pci=nomsi" case.

Quoted 6 lines

It's also worth noting that the behavior is different on Apple machines as they use a fixed _OSC set even for "pci=nomsi".

I'm wondering if OSC_PCI_MSI_SUPPORT should simply be removed from ACPI_PCIE_REQ_SUPPORT, but I'm worried that it may cause reappearance of the cpu hog issue.

Hi Lukas,

I tried to remove OSC_PCI_MSI_SUPPORT from ACPI_PCIE_REQ_SUPPORT, but after negotiate_os_control(), the 'PCIeHotplug' control is still disabled in the control capability after ACPI query_osc, run_osc routines (I haven't figured out why yet), thus the pciehp severvice driver can't be loader.

Thanks,
Feng

Quoted 5 lines

Thoughts?

Thanks,

Lukas

#9 lore raw
In reply to Feng Tang
Quoted 10 lines · Feng Tang

According to PCIe 6.1 spec, section 6.7.3.2, software need to wait at least 1 second for the command-complete event, before resending the cmd or sending a new cmd.

Currently get_port_device_capability() sends slot control cmd to disable PCIe hotplug interrupts without waiting for its completion and there was real problem reported for the lack of waiting.

Add the necessary wait to comply with PCIe spec. The waiting logic refers existing pcie_poll_cmd().

[...]

drivers/pci/pcie/portdrv.c static int get_port_device_capability(struct pci_dev *dev) · line 264

Quoted 10 lines
drivers/pci/pcie/portdrv.c +1 -2
@@ -230,8 +260,7 @@ static int get_port_device_capability(struct pci_dev *dev)
 		 * Disable hot-plug interrupts in case they have been enabled
 		 * by the BIOS and the hot-plug service driver is not loaded.
 		 */
-		pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
-			  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
+		pcie_disable_hp_interrupts_early(dev);
 	}

The language of the code comment is a bit confusing in that it says the hot-plug driver may not be "loaded". This sounds like it could be modular. But it can't. It's always built-in.

So I think what is really meant here is that the driver may be *disabled* in the config, i.e. CONFIG_HOTPLUG_PCI_PCIE=n.

Now if CONFIG_HOTPLUG_PCI_PCIE=n, you don't need to observe the Command Completed delay because the hotplug driver won't touch the Slot Control register afterwards. It's not compiled in.

On the other hand if CONFIG_HOTPLUG_PCI_PCIE=y, you don't need to disable the CCIE and HPIE interrupt because the hotplug driver will handle them.

So I think the proper solution here is to make the write to the Slot Control register conditional on CONFIG_HOTPLUG_PCI_PCIE, like this:

	if (dev->is_hotplug_bridge &&
	    (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT ||

- pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) &&
- (pcie_ports_native || host->native_pcie_hotplug)) {
- services |= PCIE_PORT_SERVICE_HP;
+ pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM)) {
+ if (pcie_ports_native || host->native_pcie_hotplug)
+ services |= PCIE_PORT_SERVICE_HP;

		/*
		 * Disable hot-plug interrupts in case they have been enabled
		 * by the BIOS and the hot-plug service driver is not loaded.
		 */

- pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
- PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
+ if (!IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE))
+ pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,

+				  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
	}

The above patch also makes sure the interrupts are quiesced if the platform didn't grant hotplug control to OSPM.

Thanks,

Lukas

author
#10 lore raw

Hi Lukas,

Thanks for your review and suggestions!

Quoted 12 lines · Lukas Wunner
Quoted 10 lines · Feng Tang

According to PCIe 6.1 spec, section 6.7.3.2, software need to wait at least 1 second for the command-complete event, before resending the cmd or sending a new cmd.

Currently get_port_device_capability() sends slot control cmd to disable PCIe hotplug interrupts without waiting for its completion and there was real problem reported for the lack of waiting.

Add the necessary wait to comply with PCIe spec. The waiting logic refers existing pcie_poll_cmd().

[...]

Quoted 14 lines

drivers/pci/pcie/portdrv.c static int get_port_device_capability(struct pci_dev *dev) · line 264

Quoted 10 lines
drivers/pci/pcie/portdrv.c +1 -2
@@ -230,8 +260,7 @@ static int get_port_device_capability(struct pci_dev *dev)
 		 * Disable hot-plug interrupts in case they have been enabled
 		 * by the BIOS and the hot-plug service driver is not loaded.
 		 */
-		pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
-			  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
+		pcie_disable_hp_interrupts_early(dev);
 	}

The language of the code comment is a bit confusing in that it says the hot-plug driver may not be "loaded". This sounds like it could be modular. But it can't. It's always built-in.

I'm not sure what problem this piece of code try to avoid, maybe something simliar to the irq storm isseu as mentioned in the 2/2 patch? The code comments could be about the small time window between this point and the loading of pciehp driver, which will request_irq and enable hotplug interrupt again.

Quoted 28 lines

So I think what is really meant here is that the driver may be *disabled* in the config, i.e. CONFIG_HOTPLUG_PCI_PCIE=n.

Now if CONFIG_HOTPLUG_PCI_PCIE=n, you don't need to observe the Command Completed delay because the hotplug driver won't touch the Slot Control register afterwards. It's not compiled in.

On the other hand if CONFIG_HOTPLUG_PCI_PCIE=y, you don't need to disable the CCIE and HPIE interrupt because the hotplug driver will handle them.

So I think the proper solution here is to make the write to the Slot Control register conditional on CONFIG_HOTPLUG_PCI_PCIE, like this:

	if (dev->is_hotplug_bridge &&
	    (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT ||
(quoted diff) +3 -3
-	     pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) &&
-	    (pcie_ports_native || host->native_pcie_hotplug)) {
-		services |= PCIE_PORT_SERVICE_HP;
+	     pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM)) {
+		if (pcie_ports_native || host->native_pcie_hotplug)
+			services |= PCIE_PORT_SERVICE_HP;
		/*
		 * Disable hot-plug interrupts in case they have been enabled
		 * by the BIOS and the hot-plug service driver is not loaded.
		 */

Review

Quoted 5 lines
(quoted diff) +3 -2
-		pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
-			  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
+		if (!IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE))
+			pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
+				  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);

Yes, this could sovlve the original issue.

The problem I heard from BIOS developer is, they didn't expect to receive 2 link control commands at almost the same time, which doesn't comply to pcie spec, and normaly the handling of one command will take some time, though not as long as 1 second.

Thanks,
Feng

Quoted 6 lines

The above patch also makes sure the interrupts are quiesced if the platform didn't grant hotplug control to OSPM.

Thanks,

Lukas

#11 lore raw
In reply to Feng Tang

…

Quoted 2 lines

Add the necessary wait to comply with PCIe spec. The waiting logic refers existing pcie_poll_cmd().

* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?

* Will cover letters be usually helpful for such patch series?

* You would probably like to avoid a typo in an email address.

Regards,
Markus

author Reviewed-by Hidetoshi Seto
#12 lore raw

Hi Markus,

Thanks for the review and reminding!

Quoted 5 lines · Markus Elfring

…

Quoted 2 lines

Add the necessary wait to comply with PCIe spec. The waiting logic refers existing pcie_poll_cmd().

* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?

The code went through some refactor, and the related commit should be:

commit 2bd50dd800b52245294cfceb56be62020cdc7515
Author: Rafael J. Wysocki <[email protected]>
Date: Sat Aug 21 01:57:39 2010 +0200

PCI: PCIe: Disable PCIe port services during port initialization

In principle PCIe port services may be enabled by the BIOS, so it's better to disable them during port initialization to avoid spurious events from being generated.

Add Rafael to cc.

Quoted 1 line

* Will cover letters be usually helpful for such patch series?

Initially I planned to send the 2 patches seprately as they handle different issues, but as 2/2 will reuse the helper function added by 1/2, I put them together.

Quoted 1 line

* You would probably like to avoid a typo in an email address.

Could you be more specific? I got the mail addresses from get_maintainers.pl. thanks!

- Feng

#13 lore raw
Quoted 1 line

Could you be more specific? I got the mail addresses from get_maintainers.pl.

Would you like to take another look at information also according to Jonathan Cameron (for example in your patch recipient list)?

Regards,
Markus

author
#14 lore raw
Quoted 3 lines · Markus Elfring
Quoted 1 line

Could you be more specific? I got the mail addresses from get_maintainers.pl.

Would you like to take another look at information also according to Jonathan Cameron (for example in your patch recipient list)?

I see, thanks!

- Feng

Quoted 2 lines

Regards,
Markus

#15 lore raw
In reply to Feng Tang
Quoted 7 lines · Feng Tang

According to PCIe 6.1 spec, section 6.7.3.2, software need to wait at least 1 second for the command-complete event, before resending the cmd or sending a new cmd.

Currently get_port_device_capability() sends slot control cmd to disable PCIe hotplug interrupts without waiting for its completion and there was real problem reported for the lack of waiting.

Can you include the error log associated with this issue? What is the actual issue you are seeing and in which hardware?

Quoted 55 lines

Add the necessary wait to comply with PCIe spec. The waiting logic refers existing pcie_poll_cmd().

---
  drivers/pci/pci.h          |  2 ++
  drivers/pci/pcie/portdrv.c | 33 +++++++++++++++++++++++++++++++--
  2 files changed, 33 insertions(+), 2 deletions(-)
drivers/pci/pci.h +2 -0
index 01e51db8d285..c1e234d1b81d 100644
@@ -759,12 +759,14 @@ static inline void pcie_ecrc_get_policy(char *str) { }
  #ifdef CONFIG_PCIEPORTBUS
  void pcie_reset_lbms_count(struct pci_dev *port);
  int pcie_lbms_count(struct pci_dev *port, unsigned long *val);
+void pcie_disable_hp_interrupts_early(struct pci_dev *dev);
  #else
  static inline void pcie_reset_lbms_count(struct pci_dev *port) {}
  static inline int pcie_lbms_count(struct pci_dev *port, unsigned long *val)
  {
  	return -EOPNOTSUPP;
  }
+static inline void pcie_disable_hp_interrupts_early(struct pci_dev *dev) {}
  #endif
 
  struct pci_dev_reset_methods {
drivers/pci/pcie/portdrv.c +11 -0
index 02e73099bad0..16010973bfe2 100644
@@ -18,6 +18,7 @@
  #include <linux/string.h>
  #include <linux/slab.h>
  #include <linux/aer.h>
+#include <linux/delay.h>
 
  #include "../pci.h"
  #include "portdrv.h"
@@ -205,6 +206,35 @@ static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
  	return 0;
  }
 
+static int pcie_wait_sltctl_cmd_raw(struct pci_dev *pdev)
+{
+	u16 slot_status;
+	/* 1000 ms, according toPCIe spec 6.1, section 6.7.3.2 */
+	int timeout = 1000;
+
+	do {
+		pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
+		if (slot_status & PCI_EXP_SLTSTA_CC) {
+			pcie_capability_write_word(pdev, PCI_EXP_SLTSTA,

drivers/pci/pcie/portdrv.c static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask) · line 228

Quoted 10 lines
drivers/pci/pcie/portdrv.c +10 -0
+						   PCI_EXP_SLTSTA_CC);
+			return 0;
+		}
+		msleep(10);
+		timeout -= 10;
+	} while (timeout);
+
+	/* Timeout */
+	return  -1;
+}

May be this logic can be simplified using readl_poll_timeout()?

Quoted 22 lines
drivers/pci/pcie/portdrv.c +10 -2
+
+void pcie_disable_hp_interrupts_early(struct pci_dev *dev)
+{
+	pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
+		  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
+	if (pcie_wait_sltctl_cmd_raw(dev))
+		pci_info(dev, "Timeout on disabling hot-plug interrupts\n");
+}
+
  /**
   * get_port_device_capability - discover capabilities of a PCI Express port
   * @dev: PCI Express port to examine
@@ -230,8 +260,7 @@ static int get_port_device_capability(struct pci_dev *dev)
  		 * Disable hot-plug interrupts in case they have been enabled
  		 * by the BIOS and the hot-plug service driver is not loaded.
  		 */
-		pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
-			  PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
+		pcie_disable_hp_interrupts_early(dev);
  	}
 
  #ifdef CONFIG_PCIEAER
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
author
#16 lore raw

Hi Sathyanarayanan,

Quoted 6 lines · Sathyanarayanan Kuppuswamy
Quoted 4 lines · Feng Tang

According to PCIe 6.1 spec, section 6.7.3.2, software need to wait at least 1 second for the command-complete event, before resending the cmd or sending a new cmd.

Quoted 6 lines
Quoted 3 lines

Currently get_port_device_capability() sends slot control cmd to disable PCIe hotplug interrupts without waiting for its completion and there was real problem reported for the lack of waiting.

Can you include the error log associated with this issue? What is the actual issue you are seeing and in which hardware?

For this one, we don't have specific log, as it was raised by firmware developer, as in https://lore.kernel.org/lkml/[email protected]/

When handling PCI hotplug problem, they hit issue and found their state machine corrupted , and back traced to OS. They didn't expect to receive 2 link control commands at almost the same time, which doesn't comply to pcie spec, and normally the handling of one command will take some time in BIOS, though not as long as 1 second. The HW is an ARM server.

I will try to add these info to commit log in next version.

Quoted 57 lines
Quoted 57 lines

Add the necessary wait to comply with PCIe spec. The waiting logic refers existing pcie_poll_cmd().

---
  drivers/pci/pci.h          |  2 ++
  drivers/pci/pcie/portdrv.c | 33 +++++++++++++++++++++++++++++++--
  2 files changed, 33 insertions(+), 2 deletions(-)
drivers/pci/pci.h +2 -0
index 01e51db8d285..c1e234d1b81d 100644
@@ -759,12 +759,14 @@ static inline void pcie_ecrc_get_policy(char *str) { }
  #ifdef CONFIG_PCIEPORTBUS
  void pcie_reset_lbms_count(struct pci_dev *port);
  int pcie_lbms_count(struct pci_dev *port, unsigned long *val);
+void pcie_disable_hp_interrupts_early(struct pci_dev *dev);
  #else
  static inline void pcie_reset_lbms_count(struct pci_dev *port) {}
  static inline int pcie_lbms_count(struct pci_dev *port, unsigned long *val)
  {
  	return -EOPNOTSUPP;
  }
+static inline void pcie_disable_hp_interrupts_early(struct pci_dev *dev) {}
  #endif
  struct pci_dev_reset_methods {
drivers/pci/pcie/portdrv.c +15 -0
index 02e73099bad0..16010973bfe2 100644
@@ -18,6 +18,7 @@
  #include <linux/string.h>
  #include <linux/slab.h>
  #include <linux/aer.h>
+#include <linux/delay.h>
  #include "../pci.h"
  #include "portdrv.h"
@@ -205,6 +206,35 @@ static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
  	return 0;
  }
+static int pcie_wait_sltctl_cmd_raw(struct pci_dev *pdev)
+{
+	u16 slot_status;
+	/* 1000 ms, according toPCIe spec 6.1, section 6.7.3.2 */
+	int timeout = 1000;
+
+	do {
+		pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
+		if (slot_status & PCI_EXP_SLTSTA_CC) {
+			pcie_capability_write_word(pdev, PCI_EXP_SLTSTA,
+						   PCI_EXP_SLTSTA_CC);
+			return 0;
+		}
+		msleep(10);
Quoted 8 lines

drivers/pci/pcie/portdrv.c static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask) · line 228

Quoted 6 lines
drivers/pci/pcie/portdrv.c +6 -0
+		timeout -= 10;
+	} while (timeout);
+
+	/* Timeout */
+	return  -1;
+}

May be this logic can be simplified using readl_poll_timeout()?

Seems this is what exactly I needed :) Many thanks for the suggestion!

- Feng

#17 lore raw
Quoted 11 lines · Feng Tang

Hi Sathyanarayanan,

Quoted 8 lines · Sathyanarayanan Kuppuswamy
Quoted 7 lines · Feng Tang

According to PCIe 6.1 spec, section 6.7.3.2, software need to wait at least 1 second for the command-complete event, before resending the cmd or sending a new cmd.

Currently get_port_device_capability() sends slot control cmd to disable PCIe hotplug interrupts without waiting for its completion and there was real problem reported for the lack of waiting.

Quoted 8 lines
Quoted 2 lines

Can you include the error log associated with this issue? What is the actual issue you are seeing and in which hardware?

For this one, we don't have specific log, as it was raised by firmware developer, as in https://lore.kernel.org/lkml/[email protected]/

When handling PCI hotplug problem, they hit issue and found their state machine corrupted , and back traced to OS. They didn't expect to receive 2 link control commands at almost the same time, which doesn't comply to

Which 2 commands from OS? Did you identify both commands?

Quoted 4 lines

pcie spec, and normally the handling of one command will take some time in BIOS, though not as long as 1 second. The HW is an ARM server.

I will try to add these info to commit log in next version.

Ok. Please include it.

Quoted 66 lines
Quoted 55 lines
Quoted 55 lines

Add the necessary wait to comply with PCIe spec. The waiting logic refers existing pcie_poll_cmd().

---
   drivers/pci/pci.h          |  2 ++
   drivers/pci/pcie/portdrv.c | 33 +++++++++++++++++++++++++++++++--
   2 files changed, 33 insertions(+), 2 deletions(-)
drivers/pci/pci.h +2 -0
index 01e51db8d285..c1e234d1b81d 100644
@@ -759,12 +759,14 @@ static inline void pcie_ecrc_get_policy(char *str) { }
   #ifdef CONFIG_PCIEPORTBUS
   void pcie_reset_lbms_count(struct pci_dev *port);
   int pcie_lbms_count(struct pci_dev *port, unsigned long *val);
+void pcie_disable_hp_interrupts_early(struct pci_dev *dev);
   #else
   static inline void pcie_reset_lbms_count(struct pci_dev *port) {}
   static inline int pcie_lbms_count(struct pci_dev *port, unsigned long *val)
   {
   	return -EOPNOTSUPP;
   }
+static inline void pcie_disable_hp_interrupts_early(struct pci_dev *dev) {}
   #endif
   struct pci_dev_reset_methods {
drivers/pci/pcie/portdrv.c +14 -0
index 02e73099bad0..16010973bfe2 100644
@@ -18,6 +18,7 @@
   #include <linux/string.h>
   #include <linux/slab.h>
   #include <linux/aer.h>
+#include <linux/delay.h>
   #include "../pci.h"
   #include "portdrv.h"
@@ -205,6 +206,35 @@ static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
   	return 0;
   }
+static int pcie_wait_sltctl_cmd_raw(struct pci_dev *pdev)
+{
+	u16 slot_status;
+	/* 1000 ms, according toPCIe spec 6.1, section 6.7.3.2 */
+	int timeout = 1000;
+
+	do {
+		pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
+		if (slot_status & PCI_EXP_SLTSTA_CC) {
+			pcie_capability_write_word(pdev, PCI_EXP_SLTSTA,
+						   PCI_EXP_SLTSTA_CC);
+			return 0;
+		}
Quoted 8 lines

drivers/pci/pcie/portdrv.c static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask) · line 228

Quoted 7 lines
drivers/pci/pcie/portdrv.c +7 -0
+		msleep(10);
+		timeout -= 10;
+	} while (timeout);
+
+	/* Timeout */
+	return  -1;
+}

May be this logic can be simplified using readl_poll_timeout()?

Seems this is what exactly I needed :) Many thanks for the suggestion!

- Feng

Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
author
#18 lore raw
Quoted 15 lines · Sathyanarayanan Kuppuswamy
Quoted 13 lines · Feng Tang

Hi Sathyanarayanan,

Quoted 10 lines · Sathyanarayanan Kuppuswamy
Quoted 7 lines · Feng Tang

According to PCIe 6.1 spec, section 6.7.3.2, software need to wait at least 1 second for the command-complete event, before resending the cmd or sending a new cmd.

Currently get_port_device_capability() sends slot control cmd to disable PCIe hotplug interrupts without waiting for its completion and there was real problem reported for the lack of waiting.

Can you include the error log associated with this issue? What is the actual issue you are seeing and in which hardware?

Quoted 8 lines
Quoted 6 lines

For this one, we don't have specific log, as it was raised by firmware developer, as in https://lore.kernel.org/lkml/[email protected]/

When handling PCI hotplug problem, they hit issue and found their state machine corrupted , and back traced to OS. They didn't expect to receive 2 link control commands at almost the same time, which doesn't comply to

Which 2 commands from OS? Did you identify both commands?

Firmware developer saw 2 programming to PCIE Slot Control register of one root port, first is writing 0x5ca, the second is writing 0x15f8.

IIUC, the first one is to disable CCIE/HPIE here from get_port_device_capability()

Thanks,
Feng