dmaengine: idxd: Fix deadlock on interrupt handle revocation
Subsystems (2)
PATCH v2 1/1 dmaengine: idxd: Fix deadlock on interrupt handle revocation
idxd_misc_thread() handles the misc MSI-X vector and completes device commands when IDXD_INTC_CMD is set. On an IDXD_INTC_INT_HANDLE_REVOKED interrupt, it allocates a work item with GFP_ATOMIC. If that allocation fails, it calls idxd_wqs_quiesce() inline. This takes wq_lock for each enabled kernel work queue and can block behind a command submitter holding that lock while waiting for cmd_done. The misc thread cannot complete the command while blocked on the lock, resulting in a deadlock.
This potential deadlock was found by our experimental static analysis tool, which analyzes lock usage and completion-based synchronization.
Embed the work item in struct idxd_device and queue it asynchronously, removing the allocation and its synchronous quiesce fallback.
Revokes received while the work is pending are coalesced; the queued work refreshes all valid interrupt handles. A revoke received while the work is running can queue another execution to refresh handles that have already been processed. Reusing the same work item on the same workqueue also serialises revoke handling.
Initialize the work once in idxd_setup_internals(), since interrupt setup runs again during FLR recovery. During interrupt cleanup, block new revoke enqueues and synchronize the misc IRQ before cancelling the work. This accounts for IRQ handlers that have already passed the stop check. Cancel the work before releasing the misc IRQ so that the IRQ handler remains available for command completions while waiting for a running work item to finish.
---
Changes in v2:
- Initialize the embedded work once, rather than on each interrupt setup.
- Stop new enqueues and synchronize the misc IRQ before cancelling work.
- Cancel revoke work before freeing the misc IRQ.
v1: https://lore.kernel.org/r/[email protected]
drivers/dma/idxd/idxd.h | 3 +++ drivers/dma/idxd/init.c | 10 ++++++++++ drivers/dma/idxd/irq.c | 28 +++++----------------------- 3 files changed, 18 insertions(+), 23 deletions(-)
drivers/dma/idxd/idxd.h +3 -0
@@ -366,6 +366,8 @@ struct idxd_device {struct idxd_dma_dev *idxd_dma;struct workqueue_struct *wq;struct work_struct work; +struct work_struct int_handle_revoke_work; +bool int_handle_revoke_stop;struct idxd_pmu *idxd_pmu;
@@ -762,6 +764,7 @@ int idxd_load_iaa_device_defaults(struct idxd_device *idxd);/* device interrupt control */ irqreturn_t idxd_misc_thread (int vec,void *data); +void idxd_int_handle_revoke (struct work_struct *work);irqreturn_t idxd_wq_thread (int irq,void *data);void idxd_mask_error_interrupts (struct idxd_device *idxd);void idxd_unmask_error_interrupts (struct idxd_device *idxd);
drivers/dma/idxd/init.c +10 -0
@@ -153,8 +153,16 @@ static void idxd_cleanup_interrupts(struct idxd_device *idxd) ie =idxd_get_ie (idxd,0 );idxd_mask_error_interrupts (idxd); + +/* Drain IRQ enqueues before cancelling work, keeping command IRQs live. */ +WRITE_ONCE (idxd->int_handle_revoke_stop, true); +synchronize_irq (ie->vector); +cancel_work_sync (&idxd->int_handle_revoke_work); +free_irq (ie->vector, ie);pci_free_irq_vectors (pdev); + +WRITE_ONCE (idxd->int_handle_revoke_stop, false); }static void idxd_clean_wqs (struct idxd_device *idxd)
@@ -433,6 +441,8 @@ static int idxd_setup_internals(struct idxd_device *idxd)int rc;init_waitqueue_head (&idxd->cmd_waitq); +/* Once per device: idxd_setup_interrupts() runs again after FLR */ +INIT_WORK (&idxd->int_handle_revoke_work, idxd_int_handle_revoke); rc =idxd_setup_wqs (idxd);if (rc <0 )
drivers/dma/idxd/irq.c +5 -23
@@ -24,11 +24,6 @@ struct idxd_resubmit {struct idxd_desc *desc; }; -struct idxd_int_handle_revoke { -struct work_struct work; -struct idxd_device *idxd; -}; -static void idxd_device_reinit (struct work_struct *work) { struct idxd_device *idxd = container_of(work, struct idxd_device, work);
@@ -127,17 +122,15 @@ static void idxd_abort_invalid_int_handle_descs(struct idxd_irq_entry *ie) } } -static void idxd_int_handle_revoke (struct work_struct *work) +void idxd_int_handle_revoke (struct work_struct *work) { -struct idxd_int_handle_revoke *revoke = - container_of(work, struct idxd_int_handle_revoke, work); -struct idxd_device *idxd = revoke->idxd; +struct idxd_device *idxd = + container_of(work, struct idxd_device, int_handle_revoke_work);struct pci_dev *pdev = idxd->pdev;struct device *dev = &pdev->dev;int i, new_handle, rc;if (!idxd->request_int_handles) { -kfree (revoke);dev_warn (dev,"Unexpected int handle refresh interrupt.\n" );return ; }
@@ -216,7 +209,6 @@ static void idxd_int_handle_revoke(struct work_struct *work)udelay (100 );idxd_int_handle_revoke_drain (ie); } -kfree (revoke); }static void idxd_evl_fault_work (struct work_struct *work)
@@ -504,20 +496,10 @@ irqreturn_t idxd_misc_thread(int vec, void *data) }if (cause &IDXD_INTC_INT_HANDLE_REVOKED ) { -struct idxd_int_handle_revoke *revoke; - val |=IDXD_INTC_INT_HANDLE_REVOKED ; - revoke =kzalloc_obj (*revoke,GFP_ATOMIC ); -if (revoke) { - revoke->idxd = idxd; -INIT_WORK (&revoke->work, idxd_int_handle_revoke); -queue_work (idxd->wq, &revoke->work); - - }else { -dev_err (dev,"Failed to allocate work for int handle revoke\n" ); -idxd_wqs_quiesce (idxd); - } +if (!READ_ONCE (idxd->int_handle_revoke_stop)) +queue_work (idxd->wq, &idxd->int_handle_revoke_work); }if (cause &IDXD_INTC_CMD ) {
Signature · 1 line
2.34.1