All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/2] i3c: master: Fix IBI teardown when DAA re-adds a device
@ 2026-12-02  2:25 ` Sam Agazaryan
  0 siblings, 0 replies; 8+ messages in thread
From: Sam Agazaryan @ 2026-12-02  2:25 UTC (permalink / raw)
  To: Alexandre Belloni, linux-i3c
  Cc: Frank Li, Adrian Hunter, Zbigniew Lukwinski,
	Ravindra Yashvant Shinde, linux-kernel, Sam Agazaryan

When DAA re-adds a device that is already on the bus, as on a Hot-Join
after a target reset, __i3c_master_add_i3c_dev_locked() frees the old
descriptor's IBI resources with the bus maintenance lock held. On an
AST2700 BMC with MCTP over I3C this caused two bugs.

The controller frees its IBI slot pool while IBI work is still queued or
running, and the handler then recycles its slot through the controller,
which has already freed that device's IBI data. Patch 1 makes the pool
safe to free with slots in flight.

destroy_workqueue() on the old IBI workqueue waits for a handler that is
blocked on the bus lock DAA holds. Patch 2 moves the workqueue to the
new descriptor instead of destroying it.

Two points I would like feedback on.

Patch 1 returns slots straight to their pool instead of through
->recycle_ibi_slot(), so the core now assumes every slot passed to
i3c_master_queue_ibi() comes from a generic IBI pool. That holds for
all in-tree drivers. If you would rather the core own the pool, or
->recycle_ibi_slot() go away, I can rework it.

Patch 2 hands the old descriptor's IBI state to the new one. IBIs
queued for the old descriptor that have not started are dropped, and
a handler that is already running finishes against the new one.
Deferring the old teardown until DAA drops the lock looked harder,
since the controller has to release its per-device IBI resources
before the old descriptor is detached inside DAA.

Both failures first showed up in host reset loops, in fewer than 1 in 10
resets. The series was tested on a 6.18-based kernel with equivalent
changes. That kernel has a sysfs attribute that runs RSTDAA and DAA on a
bus, which userspace uses after a host reset. I looped it on the bus
with the host CPU's MCTP endpoint, with 100 to 200 MCTP packets per
second, each announced by an IBI, and a test-only 5 ms sleep at the
start of i3c_master_handle_ibi() so a handler is still running when DAA
re-adds the device. Without the sleep, 30 rescans on the unpatched
kernel did not hit the race.

Without the series, the first or second rescan hit the WARN in
i3c_generic_ibi_free_pool() and then the NULL dereference shown in
patch 1. With patch 1 alone, the second rescan deadlocked as shown in
patch 2. With both patches, 250 rescans on two buses with 0, 5 and
20 ms delays ran clean, and MCTP recovered after every one.

On the unpatched kernel, lockdep also flags the problem on the first
rescan, with no test sleep: a possible circular locking dependency at
destroy_workqueue() in the DAA path, through the MCTP IBI handler and
the bus lock.

On this base the series is build-tested for arm64 with all I3C drivers
enabled.

Sam Agazaryan (2):
  i3c: master: Drain IBI slot pool before freeing
  i3c: master: Preserve IBI workqueue across DAA

 drivers/i3c/master.c       | 188 +++++++++++++++++++++++++++++--------
 include/linux/i3c/master.h |   2 +
 2 files changed, 150 insertions(+), 40 deletions(-)


base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-02  2:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  2:25 [PATCH RFC 0/2] i3c: master: Fix IBI teardown when DAA re-adds a device Sam Agazaryan
2026-12-02  2:25 ` Sam Agazaryan
2026-12-02  2:25 ` [PATCH RFC 1/2] i3c: master: Drain IBI slot pool before freeing Sam Agazaryan
2026-12-02  2:25   ` Sam Agazaryan
2026-12-02  2:44   ` sashiko-bot
2026-12-02  2:25 ` [PATCH RFC 2/2] i3c: master: Preserve IBI workqueue across DAA Sam Agazaryan
2026-12-02  2:25   ` Sam Agazaryan
2026-12-02  2:48   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.