Skip to contentSkip to conversation

PCI: endpoint: pci-epf-test: Fix sleeping function being called from atomic context

PATCH Applied Bhanu Seshu Kumar Valluri 3 participants 3 messages Oct 14, 2025 – Oct 26, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 PCI: endpoint: pci-epf-test: Fix sleeping function being called from atomic context

When Root Complex (RC) triggers a Doorbell MSI interrupt to Endpoint (EP) it triggers a warning in the EP. pci_endpoint kselftest target is compiled and used to run the Doorbell test in RC.

BUG: sleeping function called from invalid context at kernel/locking/mutex.c:271
Call trace:
 __might_resched+0x130/0x158
 __might_sleep+0x70/0x88
 mutex_lock+0x2c/0x80
 pci_epc_get_msi+0x78/0xd8
 pci_epf_test_raise_irq.isra.0+0x74/0x138
 pci_epf_test_doorbell_handler+0x34/0x50

The BUG arises because the EP's pci_epf_test_doorbell_handler() is making an indirect call to pci_epc_get_msi(), which uses mutex inside, from interrupt context.

To fix the issue convert hard IRQ handler to a threaded IRQ handler to allow it to call functions that can sleep during bottom half execution. Register threaded IRQ handler with IRQF_ONESHOT to keep interrupt line disabled until the threaded IRQ handler completes execution.

Fixes eff0c286aa91 ("PCI: endpoint: pci-epf-test: Add doorbell test support")

---
Note : The patch is compiled and tested on TI am642 board.

Change log
V2->V3:
Addressed Bjorn Helgass review points in v2
- Rebase to pci/main (v6.18-rc1)
- Add a space before each "("
- Remove the timestamps because they're unnecessary distraction
- Add "()" after function names in commit log
- s/irq/IRQ/
- Rewrap the commit log to fit in 75 columns
- Rewrap the code below to fit in 78 columns because most of the
rest of the file does
Link to V2: https://lore.kernel.org/all/[email protected]/

V1->V2:
Trimmed Call trace to include only essential calls.
Used 12 digit commit ID in fixes tag.
Steps to reproduce the bug are removed from commit log.
Link to V1: https://lore.kernel.org/all/[email protected]/

 drivers/pci/endpoint/functions/pci-epf-test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/endpoint/functions/pci-epf-test.c +3 -2
index 31617772a..b05e8db57 100644
@@ -730,8 +730,9 @@ static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test,
 	if (bar < BAR_0)
 		goto err_doorbell_cleanup;
 
-	ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0,
-			  "pci-ep-test-doorbell", epf_test);
+	ret = request_threaded_irq(epf->db_msg[0].virq, NULL,
+				   pci_epf_test_doorbell_handler, IRQF_ONESHOT,
+				   "pci-ep-test-doorbell", epf_test);
 	if (ret) {
 		dev_err(&epf->dev,
 			"Failed to request doorbell IRQ: %d\n",
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 17 lines · Bhanu Seshu Kumar Valluri

When Root Complex (RC) triggers a Doorbell MSI interrupt to Endpoint (EP) it triggers a warning in the EP. pci_endpoint kselftest target is compiled and used to run the Doorbell test in RC.

BUG: sleeping function called from invalid context at kernel/locking/mutex.c:271
Call trace:
 __might_resched+0x130/0x158
 __might_sleep+0x70/0x88
 mutex_lock+0x2c/0x80
 pci_epc_get_msi+0x78/0xd8
 pci_epf_test_raise_irq.isra.0+0x74/0x138
 pci_epf_test_doorbell_handler+0x34/0x50

The BUG arises because the EP's pci_epf_test_doorbell_handler() is making an indirect call to pci_epc_get_msi(), which uses mutex inside, from interrupt context.

Quoted 8 lines

To fix the issue convert hard IRQ handler to a threaded IRQ handler to allow it to call functions that can sleep during bottom half execution. Register threaded IRQ handler with IRQF_ONESHOT to keep interrupt line disabled until the threaded IRQ handler completes execution.

Fixes eff0c286aa91 ("PCI: endpoint: pci-epf-test: Add doorbell test support")
Quoted 44 lines

---
Note : The patch is compiled and tested on TI am642 board.

Change log
V2->V3:
Addressed Bjorn Helgass review points in v2
- Rebase to pci/main (v6.18-rc1)
- Add a space before each "("
- Remove the timestamps because they're unnecessary distraction
- Add "()" after function names in commit log
- s/irq/IRQ/
- Rewrap the commit log to fit in 75 columns
- Rewrap the code below to fit in 78 columns because most of the
rest of the file does
Link to V2: https://lore.kernel.org/all/[email protected]/

V1->V2:
Trimmed Call trace to include only essential calls.
Used 12 digit commit ID in fixes tag.
Steps to reproduce the bug are removed from commit log.
Link to V1: https://lore.kernel.org/all/[email protected]/

 drivers/pci/endpoint/functions/pci-epf-test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/endpoint/functions/pci-epf-test.c +3 -3
index 31617772a..b05e8db57 100644
@@ -730,8 +730,9 @@ static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test,
 	if (bar < BAR_0)
 		goto err_doorbell_cleanup;
 
-	ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0,
-			  "pci-ep-test-doorbell", epf_test);
+	ret = request_threaded_irq(epf->db_msg[0].virq, NULL,
+				   pci_epf_test_doorbell_handler, IRQF_ONESHOT,
+				   "pci-ep-test-doorbell", epf_test);
 	if (ret) {
 		dev_err(&epf->dev,
 			"Failed to request doorbell IRQ: %d\n",
--

2.34.1

maintainer Applied
#2 lore raw
In reply to Bhanu Seshu Kumar Valluri
Quoted 13 lines · Bhanu Seshu Kumar Valluri

When Root Complex (RC) triggers a Doorbell MSI interrupt to Endpoint (EP) it triggers a warning in the EP. pci_endpoint kselftest target is compiled and used to run the Doorbell test in RC.

BUG: sleeping function called from invalid context at kernel/locking/mutex.c:271
Call trace:
 __might_resched+0x130/0x158
 __might_sleep+0x70/0x88
 mutex_lock+0x2c/0x80
 pci_epc_get_msi+0x78/0xd8
 pci_epf_test_raise_irq.isra.0+0x74/0x138
 pci_epf_test_doorbell_handler+0x34/0x50
Quoted 1 line

[...]

Applied, thanks!

[1/1] PCI: endpoint: pci-epf-test: Fix sleeping function being called from atomic context

      commit: 25423cda145f9ed6ee4a72d9f2603ac2a4685e74

Best regards,

Signature · 1 line
Manivannan Sadhasivam <[email protected]>