Skip to content

Commit 4faa1e9

Browse files
ahunter6gregkh
authored andcommitted
i3c: mipi-i3c-hci: Fix race in DMA ring dequeue
commit 1dca8ae upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 18c662b commit 4faa1e9

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
@@ -632,6 +632,7 @@ static int i3c_hci_init(struct i3c_hci *hci)
632632
return ret;
633633

634634
spin_lock_init(&hci->lock);
635+
mutex_init(&hci->control_mutex);
635636

636637
/*
637638
* Now let's reset the hardware.

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

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

489+
guard(mutex)(&hci->control_mutex);
490+
489491
/* stop the ring */
490492
rh_reg_write(RING_CONTROL, RING_CTRL_ABORT);
491493
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
@@ -46,6 +46,7 @@ struct i3c_hci {
4646
void *io_data;
4747
const struct hci_cmd_ops *cmd;
4848
spinlock_t lock;
49+
struct mutex control_mutex;
4950
atomic_t next_cmd_tid;
5051
u32 caps;
5152
unsigned int quirks;

0 commit comments

Comments
 (0)