Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796453761; b=OFm7qY8mbQ7+QKGC2uwul+mawH9NnLVcaq9DSFqiYhwWx5OCNZ56MmEWPWjgHya+0l7F osMCT+3cLUGvop7FIYEGvhDxUdGk6sqRpZ9RdaTzML3hUf16LqZWR8GjA3SwDVwpevq0Q 68kdkKd+JmlnzP/ZiqYwLmvi3C5L1O6AK0mxNoehZGE8/iDscI99Ds/BlVb6H/L+VjErs GvGiZNQK81vMvg/EyIyu5mJLag2ap9uwTYu1TwuYFKejENR+YHoDLf4mD8CziEynGRYD7 HnuCBjgHuFEiPCZ/YB/0XaARpiHHM2nI70UY10oOKKeVyXkLRubBa1t0E563dDn4e5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796453761; 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=m7NrKX1zHYktimo+apD19Q32F4W+HITNVHjcOYeZrk0=; b=tDsY43a2oLuXxpeX0Ksz5jl9jcMVEoFHBWSveNO83/rTKXPvYgTCbic7tZMBv/iajMpP hc/vDvenbsJ+Cl1U7KRSgICx3EgvdaaboUbJfs8xph2+WDDGuBwFOTtr9kIO4oOgWygGb tBY79s+mbzWx2VHDFfXCqFvMzeplYRQGTF+RRPIiCQWd2FFRO8gmTQutnIIKpnP5gVTgi 7jf2rvEkQF3kIDHGVp4a8BBZYBVItY7CWex6V1GVjB57oampvrgz7mSIve9dipThIzycG mbYGsS0IgundcZBWpOXWMbCcY0Tk8CvLzWn9gtGfRqg/cCH2+1jIsG+G1uMIEK8BW6g== 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=SoSJ+s+g; arc=none smtp.remote-ip=74.125.82.200 Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) (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 6CE76606A33A for ; Sat, 5 Dec 2026 06:56:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CE76606A33A 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=SoSJ+s+g Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-3846d5f54c1so2162986eec.1 for ; Fri, 04 Dec 2026 22:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796453760; x=1797058560; 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=m7NrKX1zHYktimo+apD19Q32F4W+HITNVHjcOYeZrk0=; b=SoSJ+s+gtna23SJJorsIgMVOnCBtkxmc9IJ8/UIAZjLuyFcDqTsKR/ZFTWN6bU2Jom TvAMU2rbIKdAp685z6TOzTK3AF90JmMxXc51jox/Hm6AVws8W6aSogCvc4WJgPDfbExj 0NRm9VUUm51Y9XC7pLXbeVJzoY9MfukPex4SWzhAUOCifnbE4sPVH12Qg+OuAYnbY8Vv Wp9wgnHZFJiQmmsNvJkB6GsF+tNpxycRVBovw7FGnuZFob4n8sE99WaFXWO0UECfhdnc upDLLLuV9aS4an4aACp6wmuTbO0ZNSYzp5bDkIFD9xSK48fWusG0JoL4MyN4XjyxX6bB Bnpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796453760; x=1797058560; 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=m7NrKX1zHYktimo+apD19Q32F4W+HITNVHjcOYeZrk0=; b=hujsD+jbV4DV36ZQ2fiN8h3ek5Yj5FNjDPwzh1wxIbEfXkNbPMGIB9GRhTI87jtzoc KOSTg+5PpFtGS+JLvYimjDMjhhVi9aVBTYv7hbEIjDahfNkBq+b89+lBcZnoUc6OZ3ov 7dTtoZkOYdTbWvrMs2u8cRHyfX/RJLELe5QeY8xG/ZcpvNs6ReCa84OYm7fSOgD3qL3S z9FlTFJcWXeIA0V5sttdu0H34qHImss2M2SGF/54mRTwagtyZGV4cpSVLY4uKS+76UFT ydp0on7nvZXgEHAx2mGb2Rg1inm8TUfmSEMzneZqrpDsO4Me7r5w26jw+poVS2nZL7Pp v6ZQ== X-Forwarded-Encrypted: i=1; AL+hErFXPybvAscWIOcqw22PuUdxA/ZN8OxtDzE0WNyJFVcT4wy05syvh/LlVaTAXUuJwaETiqvvQNRWEMMlJAY=@vger.kernel.org X-Gm-Message-State: AB4q+uGprx17eWiViHI7Jo4VplMY1t91wV/TPZDXjNQDIFbyyHwympEl YwYhMBgXmSiWq5/wSLxTI4M05WzzpfEmO1RrRnDq+wbbcY6iewtDZUDshidIwZtMnhNXjIL6bCf PRY8FUbz5+aIXWQVSNbIkr/ettliK2Q== X-Received: from dybmt11.prod.google.com ([2002:a05:7300:d58b:b0:378:1191:3e95]) (user=samagazaryan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:d214:b0:387:422c:fe14 with SMTP id 5a478bee46e88-387521e34b4mr4012973eec.40.1796453760231; Fri, 04 Dec 2026 22:56:00 -0800 (PST) Date: Sat, 5 Dec 2026 06:55:52 +0000 In-Reply-To: <20261205065552.2594113-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: <20261205065552.2594113-1-samagazaryan@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261205065552.2594113-5-samagazaryan@google.com> Subject: [PATCH v2 4/4] i3c: master: Preserve IBI workqueue across DAA From: Sam Agazaryan To: Alexandre Belloni , linux-i3c@lists.infradead.org Cc: Frank Li , Adrian Hunter , Miquel Raynal , Jeremy Kerr , Joel Stanley , Zbigniew Lukwinski , Ravindra Yashvant Shinde , Bart Van Assche , 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, keep the IBI info on it anyway, marked as having no controller resources. A handler may still be running on its workqueue, and keeping it there means i3c_device_free_ibi() still waits for that handler when the driver unbinds. Enabling IBIs on such a device fails with -ENODEV, and disabling or freeing them skips the controller. 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 --- Notes: Changes in v2: - If requesting controller IBI resources for the new descriptor fails, keep the IBI info on it, marked as having no controller resources, instead of destroying its workqueue from a system workqueue. Driver teardown then still waits for a running handler (Sashiko). - Drop the destroy_work member this made unnecessary. drivers/i3c/master.c | 52 ++++++++++++++++++++++++++++++-------- include/linux/i3c/master.h | 5 ++++ 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index e52254f65145..58112c0dd5fd 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2768,6 +2768,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 = { }; @@ -2810,10 +2811,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) { @@ -2829,9 +2829,21 @@ 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); + if (olddev->ibi->has_controller_resources) { + i3c_dev_free_ibi_controller_locked(olddev); + olddev->ibi->has_controller_resources = false; + } + old_ibi = olddev->ibi; + olddev->ibi = NULL; } mutex_unlock(&olddev->ibi_lock); @@ -2885,9 +2897,16 @@ 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); + /* + * Keep the IBI info on newdev even if the controller request + * fails. A handler may still be running on its workqueue, and + * the driver's i3c_device_free_ibi() must wait for it. + */ + newdev->ibi = old_ibi; + ret = i3c_dev_request_ibi_controller_locked(newdev, &ibireq); + newdev->ibi->has_controller_resources = !ret; if (ret) { dev_err(&master->dev, "Failed to request IBI on device %d-%llx", @@ -4291,9 +4310,14 @@ int i3c_dev_disable_ibi_locked(struct i3c_dev_desc *dev) { int ret; - ret = i3c_dev_disable_ibi_controller_locked(dev); - if (ret) - return ret; + if (!dev->ibi) + return -EINVAL; + + if (dev->ibi->has_controller_resources) { + ret = i3c_dev_disable_ibi_controller_locked(dev); + if (ret) + return ret; + } reinit_completion(&dev->ibi->all_ibis_handled); if (atomic_read(&dev->ibi->pending_ibis)) @@ -4349,6 +4373,9 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev) { int ret; + if (dev->ibi && !dev->ibi->has_controller_resources) + return -ENODEV; + ret = i3c_dev_enable_ibi_controller_locked(dev); if (!ret) dev->ibi->enabled = true; @@ -4440,6 +4467,8 @@ int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev, destroy_workqueue(ibi->wq); kfree(ibi); dev->ibi = NULL; + } else { + ibi->has_controller_resources = true; } return ret; @@ -4497,7 +4526,8 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev) dev_err(&master->dev, "Failed to disable IBI before freeing\n"); } - i3c_dev_free_ibi_controller_locked(dev); + if (dev->ibi->has_controller_resources) + i3c_dev_free_ibi_controller_locked(dev); if (dev->ibi->wq) { destroy_workqueue(dev->ibi->wq); diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index f0b8fe89a3cc..fb1384149d63 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -136,6 +136,10 @@ struct i3c_ibi_slot { * rejected by the master * @num_slots: number of IBI slots reserved for this device * @enabled: reflect the IBI status + * @has_controller_resources: the controller holds IBI resources for this + * device, set up by its ->request_ibi() hook. Only + * false after DAA re-added the device and the + * controller failed to set them up again * @wq: workqueue used to execute IBI handlers. * @handler: IBI handler specified at i3c_device_request_ibi() call time. This * handler will be called from the controller workqueue, and as such @@ -159,6 +163,7 @@ struct i3c_device_ibi_info { unsigned int max_payload_len; unsigned int num_slots; unsigned int enabled; + bool has_controller_resources; struct workqueue_struct *wq; void (*handler)(struct i3c_device *dev, const struct i3c_ibi_payload *payload); -- 2.56.1.915.g69d5ec7298-goog