]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Mar 2026 15:15:32 +0000 (16:15 +0100)
commit 1dca8aee80eea76d2aae21265de5dd64f6ba0f09 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: 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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
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 3debc5f1327d08c257b2047cbb1528bdff10adb3..c529c527d7224adad57978d7dc89f32a194988de 100644 (file)
@@ -632,6 +632,7 @@ static int i3c_hci_init(struct i3c_hci *hci)
                return ret;
 
        spin_lock_init(&hci->lock);
+       mutex_init(&hci->control_mutex);
 
        /*
         * Now let's reset the hardware.
index 1ed9d053c62feb8a34b4c0b21d7d1ce6011aad86..032753a2bd680b315166565315dcb091ec6c750e 100644 (file)
@@ -486,6 +486,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 5656d43a100956739a5f30027694531f41ecb06d..32c8aecde9f76f2cbf0d2646d9b287d48e66d521 100644 (file)
@@ -46,6 +46,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;
        u32 caps;
        unsigned int quirks;