Re: [PATCH RFC 1/2] i3c: master: Drain IBI slot pool before freeing

From: Frank Li

Date: Wed Dec 02 2026 - 15:14:17 EST


On Wed, Dec 02, 2026 at 02:25:01AM +0000, Sam Agazaryan wrote:

Remove RFC

> When DAA re-adds a device that is already known, as on a Hot-Join after
> a target reset, __i3c_master_add_i3c_dev_locked() clears
> olddev->ibi->enabled before calling i3c_dev_free_ibi_locked(). That
> skips the wait for pending IBIs, so the controller frees its IBI pool
> while slot work is still queued or running on dev->ibi->wq. The handler
> then recycles its slot through the controller, whose per-device IBI
> data is already gone:
>
> Internal error: Oops: 0000000096000004 [#1] SMP
> Workqueue: 10-20a0168000f i3c_master_handle_ibi
> pc : hci_dma_recycle_ibi_slot+0x1c/0x38
> lr : i3c_hci_recycle_ibi_slot+0x2c/0x40
> Call trace:
> hci_dma_recycle_ibi_slot+0x1c/0x38 (P)
> i3c_hci_recycle_ibi_slot+0x2c/0x40
> i3c_master_handle_ibi+0x78/0xe0
> process_one_work+0x154/0x3b0
> worker_thread+0x28c/0x3a0
>
> Make the pool safe to free with slots in flight. Each slot now records
> its pool, and i3c_master_queue_ibi() records the IBI info and device the
> handler needs, so i3c_master_handle_ibi() no longer uses slot->dev and
> returns the slot straight to its pool. i3c_generic_ibi_free_pool() stops
> handing out slots and cancels work that has not started. If IBIs were
> ever queued, it frees the pool from a work item on the same ordered
> workqueue, which runs after any handler still in progress.
>
> This assumes every slot passed to i3c_master_queue_ibi() comes from a
> generic IBI pool, which is true for all in-tree drivers.
>
> Fixes: 9fd00df05e81 ("i3c: master: handle IBIs in order they came")
> Fixes: 36faa04ce3d9 ("i3c: master: Remove i3c_dev_disable_ibi_locked(olddev) on device hotjoin")
> Signed-off-by: Sam Agazaryan <samagazaryan@xxxxxxxxxx>
> ---
> drivers/i3c/master.c | 149 +++++++++++++++++++++++++++++++++----------
> 1 file changed, 116 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 01e05bad8661..75c44c45bd08 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -3619,6 +3619,26 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
> /* Approximate time for IBI handler to run */
> #define I3C_WAKEUP_PROCESSING_TIME_MS 100
>
> +struct i3c_generic_ibi_slot {
> + struct list_head node;
> + struct i3c_ibi_slot base;
> + struct i3c_generic_ibi_pool *pool;
> + struct i3c_device_ibi_info *ibi;
> + struct i3c_device *i3cdev;
> +};
> +
> +struct i3c_generic_ibi_pool {
> + spinlock_t lock;
> + unsigned int num_slots;
> + bool stopping;
> + struct workqueue_struct *wq;
> + struct work_struct free_work;
> + void *payload_buf;
> + struct list_head free_slots;
> + struct list_head pending;
> + struct i3c_generic_ibi_slot slots[] __counted_by(num_slots);
> +};
> +

Use prepare patch move i3c_generic_ibi_pool to here

> /**
> * i3c_master_queue_ibi() - Queue an IBI
> * @dev: the device this IBI is coming from
> @@ -3629,14 +3649,32 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
> */
> void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot)
> {
> - if (!dev->ibi || !slot)
> + struct i3c_generic_ibi_slot *gslot;
> + struct i3c_generic_ibi_pool *pool;
> + unsigned long flags;
> +
> + if (!slot)
> return;
>
> + gslot = container_of(slot, struct i3c_generic_ibi_slot, base);
> + pool = gslot->pool;
> +
> + spin_lock_irqsave(&pool->lock, flags);

Usu auto cleanup guard()

Frank