Re: [PATCH v2] PCI: endpoint: pci-epf-test: Fix sleeping function being called from atomic context
From: Niklas Cassel
Date: Thu Oct 09 2025 - 05:37:49 EST
On Tue, Sep 30, 2025 at 08:08:09AM +0530, Bhanu Seshu Kumar Valluri wrote:
> 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.
>
> [ 474.686193] BUG: sleeping function called from invalid context at kernel/locking/mutex.c:271
> [ 474.710934] Call trace:
> [ 474.710995] __might_resched+0x130/0x158
> [ 474.711011] __might_sleep+0x70/0x88
> [ 474.711023] mutex_lock+0x2c/0x80
> [ 474.711036] pci_epc_get_msi+0x78/0xd8
> [ 474.711052] pci_epf_test_raise_irq.isra.0+0x74/0x138
> [ 474.711063] 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@xxxxxxxxx>
> ---
All other calls to pci_epf_test_raise_irq() is done from the workqueue.
While we could change pci_epf_test_doorbell_handler() to queue some work on
the workqueue (and let that work call pci_epf_test_raise_irq()), converting
pci_epf_test_doorbell_handler() to be a threaded IRQ handler seems like the
less invasive change, thus:
Reviewed-by: Niklas Cassel <cassel@xxxxxxxxxx>