Linux-PCI Archive mirror
 help / color / mirror / Atom feed
From: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
To: "Manivannan Sadhasivam" <mani@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Niklas Cassel" <cassel@kernel.org>,
	"Frank Li" <Frank.Li@nxp.com>,
	"Damien Le Moal" <dlemoal@kernel.org>,
	"Mohamed Khalfella" <khalfella@gmail.com>,
	"Christian Bruel" <christian.bruel@foss.st.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	khalid@kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
	bhanuseshukumar@gmail.com
Subject: [PATCH v3] PCI: endpoint: pci-epf-test: Fix sleeping function being called from atomic context
Date: Tue, 14 Oct 2025 08:11:09 +0530	[thread overview]
Message-ID: <20251014024109.42287-1-bhanuseshukumar@gmail.com> (raw)

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")
Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
---
 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/20250930023809.7931-1-bhanuseshukumar@gmail.com/

 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/20250917161817.15776-1-bhanuseshukumar@gmail.com/

 drivers/pci/endpoint/functions/pci-epf-test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 31617772a..b05e8db57 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -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


             reply	other threads:[~2025-10-14  2:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14  2:41 Bhanu Seshu Kumar Valluri [this message]
2025-10-16 16:50 ` [PATCH v3] PCI: endpoint: pci-epf-test: Fix sleeping function being called from atomic context Frank Li
2025-10-26 15:53 ` Manivannan Sadhasivam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251014024109.42287-1-bhanuseshukumar@gmail.com \
    --to=bhanuseshukumar@gmail.com \
    --cc=Frank.Li@nxp.com \
    --cc=bhelgaas@google.com \
    --cc=cassel@kernel.org \
    --cc=christian.bruel@foss.st.com \
    --cc=david.hunter.linux@gmail.com \
    --cc=dlemoal@kernel.org \
    --cc=khalfella@gmail.com \
    --cc=khalid@kernel.org \
    --cc=kishon@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).