]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
i3c: mipi-i3c-hci: Fix race in DMA ring dequeue
authorAdrian Hunter <adrian.hunter@intel.com>
Fri, 6 Mar 2026 07:24:43 +0000 (09:24 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Wed, 11 Mar 2026 21:10:01 +0000 (22:10 +0100)
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: 9ad9a52cce282 ("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>
drivers/i3c/master/mipi-i3c-hci/core.c
drivers/i3c/master/mipi-i3c-hci/dma.c
drivers/i3c/master/mipi-i3c-hci/hci.h

index faf5eae2409fffb4cbf0855a95cf63ae6697aaf9..061e84a5c412882a41df9f87dd3fa88d5eef48f7 100644 (file)
@@ -927,6 +927,7 @@ static int i3c_hci_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        spin_lock_init(&hci->lock);
+       mutex_init(&hci->control_mutex);
 
        /*
         * Multi-bus instances share the same MMIO address range, but not
index 74b255ad6d0f96418ca4e276a50739bb7bb8bf9d..f7d411e5e11fbeae290f204bcc22eea828896ff3 100644 (file)
@@ -547,6 +547,8 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci,
        unsigned int i;
        bool did_unqueue = false;
 
+       guard(mutex)(&hci->control_mutex);
+
        /* stop the ring */
        rh_reg_write(RING_CONTROL, RING_CTRL_ABORT);
        if (wait_for_completion_timeout(&rh->op_done, HZ) == 0) {
index f1dd502c071f509bd1da7f0814375d74cf4f857a..9c63d80f7fc447a5f7ccbba1a6d81b2e6c443e3f 100644 (file)
@@ -51,6 +51,7 @@ struct i3c_hci {
        void *io_data;
        const struct hci_cmd_ops *cmd;
        spinlock_t lock;
+       struct mutex control_mutex;
        atomic_t next_cmd_tid;
        bool irq_inactive;
        u32 caps;