From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796178317; b=4KRQLoWjih+Q2X20hgti4vXb7RA+QQYGFxZHKNGlWu8P/Re2srYSRIcleu2iNoNaK1E2 bSNDEXljsf5s1W9ougVifik8ly6xdmwKO+8jRMnIPQ5/fpwlnJpqh++Rc9UGd6eHGGLmU 1YHrEadTL5OSlINLnwhcDG99xXQsGgi6HWNbyiQiqEfEaUPe8KC4Lc4+9q62cOTNcKRVU u81ue1m0+TuFlpKPggOmof4Y1kqVFK9xitdgri/GtB/UMCzMaxtY7zmOaItU48ciLyrBt DIk+5AgUtXCeDvH0K0AP8Sy26oc9xKe0AK/i34Zb2PyrnI4u0Tkl6iwfU3bINxkg4Hw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796178317; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=alXZ11dc47TIFhXQ/Vnhz4PtJfFufUaQYAwALNQIUNA=; b=JOv1GIpfeHfSTuYMqqrZgbWsogx7NITrqeujK3AVy/ciP01OMqsTG2agx4v/HAmEFNUJ Su5H3hnmR03dWo2bF0Kb2abkeVAes1mPMui4oFFBcEQOWGXrRVgIL645x63YVNKg6i98p rbMmpMrbhZ3qQEJagmZs3OXrOJzfMY/vgLU/g2yazpdUU/+MVZb5UWFLhpQmCPl4vi5Tg /kAvetkvghuB0pnmj8NawVBVJAkV5l0U3bLPHg1Fy9+7hJXQCo7HHVeja/NnqsS8A9T5U V10NE5i5z4NYeMZ1miYD7BOYENJfFBm4dHyrr1eg8249MzAhx5V3/nwvUb+LxN3Hx/g== 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="QNvx/QXQ"; arc=none smtp.remote-ip=74.125.82.199 Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) (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 2735B606A333 for ; Wed, 2 Dec 2026 02:25:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2735B606A333 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=QNvx/QXQ Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-3869865a304so15101111eec.0 for ; Tue, 01 Dec 2026 18:25:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796178315; x=1796783115; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=alXZ11dc47TIFhXQ/Vnhz4PtJfFufUaQYAwALNQIUNA=; b=QNvx/QXQnNUkUhUufW4jxOJlOibvwfiho0YFeG8iLMM6iUFxlCQOCs/hYaqgiNMK+0 ghkZaLQPAWp8pmhpUMnKVDdYWVhIsR03tdt6xLSJ3s0/8hKvJj96DXAoXmnDYHM3G9sU edN+8EwCqtDxwOUiaEMsytgrheI7sWxsk8TsBIilpPPwAbe/q3jODP45KwwhvZ+9Cjm0 rVE4VJBks3owsN3/bu5qGGGXwHACyGkpGS6Oj5MHUb9kB9LS7PLGAoozfRerf49oHVW2 lhXaKPcR+mV5nR3sjFYKi7RUq7rJ1RxsMUCjGyb+VxkVXKKDxCrDFZXsOoOknITJnITt Dbmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796178315; x=1796783115; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=alXZ11dc47TIFhXQ/Vnhz4PtJfFufUaQYAwALNQIUNA=; b=VICtzGU/njW9Zbw7vfQoRY+nkEIKIK/iPk9rTrgsBNdChqOiA+CrOLWynyyJXrj2bg S/RPxeGrjbec4HadPPXRHkuRS/c9r1f/27cAYTELoNN7xijvW1T91r3dhS0l/yz4q/cu Fc/ZTfEO1eGM2Wcb57H6jd64WaaL+jao/lEUhnLhNYuodu18Sc8TieUZ6yXa24gkYgxx EkfPa8vTyjdyziqv7k1j2lHTwgYRHdC6Ylx7PVNjGGp2POPEEzH3cthz7VSzHQkHVJHF zGhc6cSvYDjRkGnIj9J5MbyHP9T9m1Nvf+kDXIAM8KMyp1tRbK8/k/O7DCTkO17x3sx2 9Z9A== X-Forwarded-Encrypted: i=1; AL+hErF82leWEHrFf7IFjKZ9YtxS9PoUI06PwfZobgT10b6U+S9Pfww8CRWrLovTHmLbaip/JA3YzHS+lh1gEdw=@vger.kernel.org X-Gm-Message-State: APuU4Z/Ypo2ldGOtx3g5AyxDF2HQs9dz8YV/vKlzxpyH0qVQE0gL1A7Y gsLNKMAaBvsWnjc3iZjd+ZeX9EGZvCy9DY8t5dcbMyXwHOV33e/PVqjsvKnroeqXIcl5b9YF3xp F2IdL+nwqDPwfTHk2h9HVpllCXKRVEg== X-Received: from dybqo16.prod.google.com ([2002:a05:7301:6790:b0:386:a9a2:8073]) (user=samagazaryan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:418a:b0:381:3b6:6c3d with SMTP id 5a478bee46e88-38571417ca8mr58078697eec.35.1796178314786; Tue, 01 Dec 2026 18:25:14 -0800 (PST) Date: Wed, 2 Dec 2026 02:25:02 +0000 In-Reply-To: <20261202022502.3661797-1-samagazaryan@google.com> 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 References: <20261202022502.3661797-1-samagazaryan@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202022502.3661797-3-samagazaryan@google.com> Subject: [PATCH RFC 2/2] i3c: master: Preserve IBI workqueue across DAA 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 known, __i3c_master_add_i3c_dev_locked() runs with the bus maintenance lock held and calls i3c_dev_free_ibi_locked() on the old descriptor. That destroys its IBI workqueue, which waits for any handler still running. If that handler starts a private transfer, as mctp_i3c_ibi_handler() does, it blocks on the bus lock and the two deadlock: INFO: task i3c-hub-detecto:895 blocked for more than 120 seconds. Call trace: __flush_workqueue+0x104/0x3a8 drain_workqueue+0xb4/0x158 destroy_workqueue+0x5c/0x2c8 i3c_dev_free_ibi_locked+0x50/0x88 i3c_master_add_i3c_dev_locked+0x248/0x3b8 hci_cmd_v1_daa+0x214/0x448 i3c_hci_daa+0x1c/0x30 i3c_master_do_daa+0x58/0x130 INFO: task kworker/u16:1:141099 blocked for more than 121 seconds. Workqueue: 10-20a0168000f i3c_master_handle_ibi Call trace: rwsem_down_read_slowpath+0x21c/0x528 down_read+0x48/0xd0 i3c_bus_normaluse_lock+0x18/0x28 i3c_device_do_priv_xfers+0x7c/0xb8 mctp_i3c_ibi_handler+0x170/0x308 i3c_master_handle_ibi+0x60/0xe0 Free only the controller IBI resources of the old descriptor and move its IBI info, workqueue included, to the new one. If requesting controller IBI resources for the new descriptor fails, destroy the workqueue from a system workqueue so that never happens under the bus lock. This depends on the previous patch, since the controller now frees the old IBI pool while a handler may still be running. IBIs queued for the old descriptor that have not started are dropped, and a handler that is already running completes against the new one. 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 --- drivers/i3c/master.c | 39 +++++++++++++++++++++++++++++++------- include/linux/i3c/master.h | 2 ++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 75c44c45bd08..22fe970ce3ac 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2728,6 +2728,17 @@ i3c_master_search_i3c_dev_duplicate(struct i3c_dev_desc *refdev) return NULL; } +static void i3c_dev_free_ibi_work(struct work_struct *work) +{ + struct i3c_device_ibi_info *ibi = container_of(work, + struct i3c_device_ibi_info, + destroy_work); + + if (ibi->wq) + destroy_workqueue(ibi->wq); + kfree(ibi); +} + /** * __i3c_master_add_i3c_dev_locked() - add an I3C slave to the bus * @master: master used to send frames on the bus @@ -2743,6 +2754,7 @@ static void __i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master u8 addr, bool probe) { struct i3c_device_info info = { .dyn_addr = addr }; + struct i3c_device_ibi_info *old_ibi = NULL; struct i3c_dev_desc *newdev, *olddev; u8 old_dyn_addr = addr, expected_dyn_addr; struct i3c_ibi_setup ibireq = { }; @@ -2785,10 +2797,9 @@ static void __i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master newdev->dev->desc = newdev; /* - * We need to restore the IBI state too, so let's save the - * IBI information and try to restore them after olddev has - * been detached+released and its IBI has been stopped and - * the associated resources have been freed. + * We need to restore the IBI state too, so save the IBI + * information and move it to newdev once olddev has been + * detached and released. */ mutex_lock(&olddev->ibi_lock); if (olddev->ibi) { @@ -2804,9 +2815,18 @@ static void __i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master * a new address. This will result in NACK or timeout. * So, update the olddev->ibi->enabled flag to false * to avoid DISEC with OldAddr. + * + * Free only the controller IBI resources and hand + * olddev->ibi, workqueue included, over to newdev. + * Destroying the workqueue here would wait for any + * running IBI handler while we hold the bus + * maintenance lock, and the handler may be waiting + * for that lock. */ olddev->ibi->enabled = false; - i3c_dev_free_ibi_locked(olddev); + i3c_dev_free_ibi_controller_locked(olddev); + old_ibi = olddev->ibi; + olddev->ibi = NULL; } mutex_unlock(&olddev->ibi_lock); @@ -2860,13 +2880,17 @@ static void __i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master * should request the IBI again instead of trying to hide that from * him. */ - if (ibireq.handler) { + if (old_ibi) { mutex_lock(&newdev->ibi_lock); - ret = i3c_dev_request_ibi_locked(newdev, &ibireq); + newdev->ibi = old_ibi; + ret = i3c_dev_request_ibi_controller_locked(newdev, &ibireq); if (ret) { dev_err(&master->dev, "Failed to request IBI on device %d-%llx", master->bus.id, newdev->info.pid); + newdev->ibi = NULL; + /* destroy_workqueue() waits, so not under the bus lock */ + queue_work(system_dfl_wq, &old_ibi->destroy_work); } else if (enable_ibi) { ret = i3c_dev_enable_ibi_locked(newdev); if (ret) @@ -4354,6 +4378,7 @@ int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev, atomic_set(&ibi->pending_ibis, 0); init_completion(&ibi->all_ibis_handled); + INIT_WORK(&ibi->destroy_work, i3c_dev_free_ibi_work); ibi->handler = req->handler; ibi->max_payload_len = req->max_payload_len; ibi->num_slots = req->num_slots; diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index d58070a72a49..55f3309ca42b 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -136,6 +136,7 @@ struct i3c_ibi_slot { * @num_slots: number of IBI slots reserved for this device * @enabled: reflect the IBI status * @wq: workqueue used to execute IBI handlers. + * @destroy_work: frees @wq and this structure from a system workqueue * @handler: IBI handler specified at i3c_device_request_ibi() call time. This * handler will be called from the controller workqueue, and as such * is allowed to sleep (though it is recommended to process the IBI @@ -159,6 +160,7 @@ struct i3c_device_ibi_info { unsigned int num_slots; unsigned int enabled; struct workqueue_struct *wq; + struct work_struct destroy_work; void (*handler)(struct i3c_device *dev, const struct i3c_ibi_payload *payload); }; -- 2.56.1.911.g883d8bcb20-goog