Skip to content

Commit 1dca8ae

Browse files
ahunter6alexandrebelloni
authored andcommitted
i3c: mipi-i3c-hci: Fix race in DMA ring dequeue
The HCI DMA dequeue path (hci_dma_dequeue_xfer()) may be invoked for multiple transfers that timeout around the same time. However, the function is not serialized and can race with itself. When a timeout occurs, hci_dma_dequeue_xfer() stops the ring, processes incomplete transfers, and then restarts the ring. If another timeout triggers a parallel call into the same function, the two instances may interfere with each other - stopping or restarting the ring at unexpected times. Add a mutex so that hci_dma_dequeue_xfer() is serialized with respect to itself. Fixes: 9ad9a52 ("i3c/master: introduce the mipi-i3c-hci driver") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260306072451.11131-7-adrian.hunter@intel.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 4decbbc commit 1dca8ae

3 files changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/i3c/master/mipi-i3c-hci/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ static int i3c_hci_probe(struct platform_device *pdev)
927927
return -ENOMEM;
928928

929929
spin_lock_init(&hci->lock);
930+
mutex_init(&hci->control_mutex);
930931

931932
/*
932933
* Multi-bus instances share the same MMIO address range, but not

drivers/i3c/master/mipi-i3c-hci/dma.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci,
547547
unsigned int i;
548548
bool did_unqueue = false;
549549

550+
guard(mutex)(&hci->control_mutex);
551+
550552
/* stop the ring */
551553
rh_reg_write(RING_CONTROL, RING_CTRL_ABORT);
552554
if (wait_for_completion_timeout(&rh->op_done, HZ) == 0) {

drivers/i3c/master/mipi-i3c-hci/hci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct i3c_hci {
5151
void *io_data;
5252
const struct hci_cmd_ops *cmd;
5353
spinlock_t lock;
54+
struct mutex control_mutex;
5455
atomic_t next_cmd_tid;
5556
bool irq_inactive;
5657
u32 caps;

0 commit comments

Comments
 (0)