From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796178311; b=3fh8Mr0KprqjI4S261leOXNHsaB/Tk+ukO1WOWYqpEmi6TB+5e3Pv8RX5nd8EiXds9rt YQJcMqrqBiJv49NIhCuzPi4O27in7BdkCME5eXWAENwhrSE0Sul4xATyBzeYSnRUHA1jX FXIAidJy1lv4ZVN50c+jWtGRp3/S2oLQM1bdP2Z7IAZsS0fF16hGAjbcU7btTIFJZXNVK n9M7yw7SIxxKSaDT/usXL0XcNrQWjRRPcu4v9GGoxUHeuAGovX8bNMHqmcrfx1sfiJFSj 68dSgIe0b4ASg7n0YFcUbLrnmgobRsQ3txhQb0MAhe9ZLGJxZld0S37ErTSbwdEo7dg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796178311; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=jXAtIdKWRWifFz5CZd5Lwca0KJFLSLOLyAaaBzpPhLU=; b=ksOzP2WqVnsGqTOiXplE+VnFiIMOf2fYUKScCw3kNMKnAOCkYDSxo0drZ2dTps6WP851 +V99rN3Sp04El9wvf7NSWU+kZ+uGTd5wlgGRGe2kbY+nrnGZ3cydynS8FOJpjvij8txGH s9RsmSRQQKy3xWnu4qUc3VFnIuudhG/r9cQ+Fz2d9KWD6ajEfIU2e6UGYzkCmn8drisVv htnY8O1tQ15oygIu2oKVJwxu/zFiEhN6Kb6jkKWa0HxRZ3URaD22ZQ/H2yqfYDEWCa7s3 p3iMaoKxe6Eg5as5Yel1ayMInbF2wv/GrA0N50ANP6nB8tXxqiCQ90tBAnwOkLVHIuA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--samagazaryan.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=nLaNnrB4; arc=none smtp.remote-ip=74.125.82.72 Received: from mail-dl1-f72.google.com (mail-dl1-f72.google.com [74.125.82.72]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34871606A31A for ; Wed, 2 Dec 2026 02:25:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 34871606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--samagazaryan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=nLaNnrB4 Received: by mail-dl1-f72.google.com with SMTP id a92af1059eb24-1b53bfc9534so5676993c88.0 for ; Tue, 01 Dec 2026 18:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796178310; x=1796783110; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=jXAtIdKWRWifFz5CZd5Lwca0KJFLSLOLyAaaBzpPhLU=; b=nLaNnrB4CWu15SNt1A8ngXOKQdLIptfcBsF2uBm8pNEHGci6xCSw2q7ZCDi57mHVCE 72pEXe6dZgePFxui/xaseNBi+yw/sad9lNq4GV002bazMwFTx5NixN37V1+0QG7umNEx myt1hNxhWvb8oIn2zNCSgLEIu1T/OfvuNuXUXFgMgHe4xPFImglD6P+j7TRcc9QEYWJZ coq8rRSv88KzEVVBMcGVZzbQL4rS7Wu7bNDl2vaFaYoLDmLDGNvvywfQs08InsAp/CoI Y/2E9UYJzbl6ihIawR53HKRKxjsIX2ZC9vODjXDCAzsK3GRdUhCuuZ6BSmjTwfY13i/K QuUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796178310; x=1796783110; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jXAtIdKWRWifFz5CZd5Lwca0KJFLSLOLyAaaBzpPhLU=; b=heAxYkoyQh97/VlBH0uPhxbtJSkzug0k3Yj/2nw+kAtstWf6U99vkU3sVMqWFWJCHL TLDM2ETfChpqmrdEzfbz04djWGVWULugi/OfO9YJbGOPkW5XCNOcyasZSY9CavVIBxWm vB98C1zrX7l97dAczgS2CMHXXE6SuEl0f4DJcmtYfF+2bSXTWIyrv3VWpyOEPHjbSCzj 5R2Zv8gpzOqoavWjLj+VxKfmSGqBaEdp4VH/2rfhvrcffiBaHsb97YizXWNeLOGoabs5 Htb5qZ5m4qvMhObirqQbXOgbCgkP17mo1Od9rbLw33nr4qhh1lRIl/41+ultIZOf2372 3kOg== X-Forwarded-Encrypted: i=1; AL+hErFvoNYjkBs6EjdmRIQYa+0RWtFfZxScsWKX3CRE+2MuJ2P1hHO+cn68IBrA3+54tq7X451hYq+tbbq0VMo=@vger.kernel.org X-Gm-Message-State: APuU4Z8M1Vbubpg8Bj56fgkcROwt7fR/TdOKYf8Z2zkenWvyWx2wnwif 2/ppU4+g/tMx8IQw8HC4gi7HYA8H0fGO6M6200iz7xQ3cjiA0Iyp6L06KqX1fks7kS3+NP0yaVM 9pA2YX7IsAzX5z1l/O2M+cCQ5dWk/uA== X-Received: from dleb8-n1.prod.google.com ([2002:a05:701b:4248:10b0:1a4:c892:b166]) (user=samagazaryan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1503:b0:190:da74:2c89 with SMTP id a92af1059eb24-1b5c3039cf3mr2551301c88.21.1796178309832; Tue, 01 Dec 2026 18:25:09 -0800 (PST) Date: Wed, 2 Dec 2026 02:25:00 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202022502.3661797-1-samagazaryan@google.com> Subject: [PATCH RFC 0/2] i3c: master: Fix IBI teardown when DAA re-adds a device From: Sam Agazaryan To: Alexandre Belloni , linux-i3c@lists.infradead.org Cc: Frank Li , Adrian Hunter , Zbigniew Lukwinski , Ravindra Yashvant Shinde , linux-kernel@vger.kernel.org, Sam Agazaryan Content-Type: text/plain; charset="UTF-8" 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