mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sam Agazaryan <samagazaryan@google.com>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	linux-i3c@lists.infradead.org
Cc: Frank Li <Frank.Li@nxp.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	 Zbigniew Lukwinski <zbigniew.lukwinski@linux.intel.com>,
	 Ravindra Yashvant Shinde <ravindra.yashvant.shinde@nxp.com>,
	linux-kernel@vger.kernel.org,
	 Sam Agazaryan <samagazaryan@google.com>
Subject: [PATCH RFC 0/2] i3c: master: Fix IBI teardown when DAA re-adds a device
Date: Wed,  2 Dec 2026 02:25:00 +0000	[thread overview]
Message-ID: <20261202022502.3661797-1-samagazaryan@google.com> (raw)

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


             reply	other threads:[~2026-12-02  2:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  2:25 Sam Agazaryan [this message]
2026-12-02  2:25 ` [PATCH RFC 1/2] i3c: master: Drain IBI slot pool before freeing Sam Agazaryan
2026-12-02  2:25 ` [PATCH RFC 2/2] i3c: master: Preserve IBI workqueue across DAA Sam Agazaryan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202022502.3661797-1-samagazaryan@google.com \
    --to=samagazaryan@google.com \
    --cc=Frank.Li@nxp.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ravindra.yashvant.shinde@nxp.com \
    --cc=zbigniew.lukwinski@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®