From patchwork Fri Feb 2 12:18:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 195844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp387791dyc; Fri, 2 Feb 2024 04:23:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IE56dh63PJjFEYVElKSLeUVH5+Zf7HD8BdvalcUGJDOA3AyHkJJG0h50iNpKftS2WVGWEM2 X-Received: by 2002:a05:6830:1516:b0:6e1:115b:fdb5 with SMTP id k22-20020a056830151600b006e1115bfdb5mr7869412otp.19.1706876629671; Fri, 02 Feb 2024 04:23:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706876629; cv=pass; d=google.com; s=arc-20160816; b=S2Lo83C9PUybYBAtT/CZ7yv+o+8tzCXVhY5fIlSMos2nPwbB0hnSAly6bheOgbSaNw oD8iP1tmkmbzio7tPPKyhrrJuSJpLVTmX7GWnDjxqEXPF29JdY0K4udM/0DsPDhrQPgK cEhoLIiK7uRjk/Ztr0EnGFSKA5kyBijMa3xxpU/jmTvp5NXHj63JSRtESsO+0dqMaFgZ Curx2UplzuR+8d5MyR31e6CN9dERWtMI+wf8fYFyDX0jOPyb8PMo+n8+6/AanLg+9iIO OeuJw3lva8Bj12y3cVzlw4TF3sZgqEO19gRbxT/pCQ02MbELDLmcNrqHJpBE62sCT3SU w5KQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=rkdXSzqHURME3hhbkeglkIxGqapmxg5vzQSBc1TtGds=; fh=e0L63A0nsRh64FVdteqeeVyxTFYeDFve2OBQeJko1mc=; b=LoSqNYVtI/BdqWJoKd8UeQX2+pCOhQc4Yhl8KNKXKRJkzb/5V4RiflRoQriktsgeRy eEtFUqNT5rG0psK8VcFmZwkDwK1l4Ul/FIMNgavx6gkjKltiJN3AoF9N1Vom7Bv+6Eea gJlbYf+mrLvCQJVPAnA1ExiXpkuGmN59riFs0SQYrfv81zvQn7xP/yRr2lBZpkccwbnf ZcxfQfQVKCL3hZb0pmQ19o2kGiAx5TZAy+pAExHzocIxpd8bkBP0Cw3RpKY2K02iVDZl Bbs60EMXGqGVvRhymIHCitgtCo+ua6JNCSg/tr9C5josVJ8uTI1/MIJjQteQzexf7e3u jYmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AoZV5JNv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49824-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49824-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUadP3NPZWAwrMIwszJnR/ZcaiOZnMKUtBwE8k99135LQ+G4p77B9eYghJd+xr8+epzvJ4z0RjMWePGU6Ge4fLIW6S0ZQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w11-20020a63474b000000b005d8c175f17fsi1485329pgk.405.2024.02.02.04.23.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 04:23:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49824-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AoZV5JNv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49824-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49824-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 52B8528BECE for ; Fri, 2 Feb 2024 12:19:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 507D61420C4; Fri, 2 Feb 2024 12:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AoZV5JNv" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 550F414076C; Fri, 2 Feb 2024 12:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706876302; cv=none; b=puxDza5FWsxvOWletooWE9YMncnk1vS3Vow11lfhwa+jZr+WK6v1GLiRS0we1ahNMcMW2L6v83M/CccW4MlensUkufQjGJ2Y2N9V26H9Nzi9FhflfD4qBSkRSjCGfnMeOYZgDuO92364X1FS+lvnqlJ4kbCccrBhgFVrOaYb7QU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706876302; c=relaxed/simple; bh=cDD6zWE+hIAQdurFS+rSICTH3h1uOHnIQoJ80Fb5RoU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V67XxXrdhOUzjM6Nh7uPFmirMGl8KoynGVPexnGs7Vrl/tul+JUXnQtsiQFV2ranqt/BuOXI1PgSmbYtMYUW4uhwz0XgWf00PB4fTEUcuHDLe7R3kjQ3n8ejJSmXRWafxpItVphd2L0g6Ju5OALN3JTBRJw4WmppKUA9sS7bZAY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AoZV5JNv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id EA050C433F1; Fri, 2 Feb 2024 12:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706876302; bh=cDD6zWE+hIAQdurFS+rSICTH3h1uOHnIQoJ80Fb5RoU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AoZV5JNv3oQO7IebuQ+al5XeD5XyLhj9FV4qgqVMmvTc2AHrq8seQEQec6+vns13S OrpsotHKZ8p6k3UUVmjMRo0L1vf9jImRW5GKfWBVLWQqeVnREKuq5NUqqPPGRWBuUC 6gAk26wDcIBcK1RJKZ9SgkZN/DDQDEr8nosZSfDiYjZ/sMIjSXWriLB2eFyV540KOD OAYg/toV4ky+RxvYujwYSPD1cW0ktLyVirTOqE1Y7fPjLySH3qT90i7qs33HsVV01i eOU0dq2xTSNKEpMorLGyzPfWh/xkPxTS6eQkwNrkYgepL1hK5GeTbz0B1Zf6D9xhQp HqvAhUU9KW2NA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC173C48291; Fri, 2 Feb 2024 12:18:21 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Feb 2024 13:18:16 +0100 Subject: [PATCH 1/2] driver: core: add dedicated workqueue for devlink removal Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240202-fix-device-links-overlays-v1-1-f9fd1404c8e2@analog.com> References: <20240202-fix-device-links-overlays-v1-0-f9fd1404c8e2@analog.com> In-Reply-To: <20240202-fix-device-links-overlays-v1-0-f9fd1404c8e2@analog.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand , Rob Herring , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Len Brown Cc: linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706876300; l=3622; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=ByQW6bRhqckZ/DlDF0eHD/SVHr3IYmtWZF3VkOkvgCw=; b=WICzQqU/L3gsEQRCsjjuaAvWQHaT7MtrCBmtTUWoXIlARhre7lov5EEkAoHQ++K02ag0qs27w lA2lR3S4/yjDPZnECukErBUw0XqUC3wNoIIEI7o9or9qJo1hbLkniV6 X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789789869038921485 X-GMAIL-MSGID: 1789789869038921485 From: Nuno Sa Let's use a dedicated queue for devlinks since releasing a link happens asynchronously but some code paths, like DT overlays, have some expectations regarding the of_node when being removed (the refcount must be 1). Given how devlinks are released that cannot be assured. Hence, add a dedicated queue so that it's easy to sync against devlinks removal. While at it, make sure to explicitly include . Signed-off-by: Nuno Sa --- drivers/base/core.c | 33 +++++++++++++++++++++++++++++---- include/linux/fwnode.h | 1 + 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 14d46af40f9a..06e7766b5227 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -31,6 +31,7 @@ #include #include #include /* for dma_default_coherent */ +#include #include "base.h" #include "physical_location.h" @@ -44,6 +45,7 @@ static bool fw_devlink_is_permissive(void); static void __fw_devlink_link_to_consumers(struct device *dev); static bool fw_devlink_drv_reg_done; static bool fw_devlink_best_effort; +static struct workqueue_struct *devlink_release_queue __ro_after_init; /** * __fwnode_link_add - Create a link between two fwnode_handles. @@ -235,6 +237,11 @@ static void __fw_devlink_pickup_dangling_consumers(struct fwnode_handle *fwnode, __fw_devlink_pickup_dangling_consumers(child, new_sup); } +void fwnode_links_flush_queue(void) +{ + flush_workqueue(devlink_release_queue); +} + static DEFINE_MUTEX(device_links_lock); DEFINE_STATIC_SRCU(device_links_srcu); @@ -531,9 +538,10 @@ static void devlink_dev_release(struct device *dev) * It may take a while to complete this work because of the SRCU * synchronization in device_link_release_fn() and if the consumer or * supplier devices get deleted when it runs, so put it into the "long" - * workqueue. + * devlink workqueue. + * */ - queue_work(system_long_wq, &link->rm_work); + queue_work(devlink_release_queue, &link->rm_work); } static struct class devlink_class = { @@ -636,10 +644,27 @@ static int __init devlink_class_init(void) return ret; ret = class_interface_register(&devlink_class_intf); - if (ret) + if (ret) { + class_unregister(&devlink_class); + return ret; + } + + /* + * Using a dedicated queue for devlinks since releasing a link happens + * asynchronously but some code paths, like DT overlays, have some + * expectations regarding the of_node when being removed (the refcount + * must be 1). Given how devlinks are released that cannot be assured. + * Hence, add a dedicated queue so that it's easy to sync against + * devlinks removal. + */ + devlink_release_queue = alloc_workqueue("devlink_release", 0, 0); + if (!devlink_release_queue) { + class_interface_unregister(&devlink_class_intf); class_unregister(&devlink_class); + return -ENODEV; + } - return ret; + return 0; } postcore_initcall(devlink_class_init); diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 2a72f55d26eb..017b170e9903 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -213,5 +213,6 @@ extern bool fw_devlink_is_strict(void); int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup); void fwnode_links_purge(struct fwnode_handle *fwnode); void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode); +void fwnode_links_flush_queue(void); #endif From patchwork Fri Feb 2 12:18:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 195842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp385228dyc; Fri, 2 Feb 2024 04:19:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IENqG9/mTuzNbr6892THzGypNLqyu7ygPQnJqeAwofIPkRaTXJ4nVVENwR/N84cQQtNWg0Y X-Received: by 2002:a05:620a:3889:b0:783:55c2:f0fc with SMTP id qp9-20020a05620a388900b0078355c2f0fcmr4931956qkn.56.1706876345888; Fri, 02 Feb 2024 04:19:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706876345; cv=pass; d=google.com; s=arc-20160816; b=T2vbVA5j2eisuhF8Rh7GeqGID6dRxUrxO4oMZfdWYPOVx+w6L03LA2M3mv4vLYi55H AXDxv5cuvfG14/r4B7owkW++8Z6X4IpG9/NnDbncUCwBnItFzJOUPfzQ/PJbxcWg202A SqA0WpsM1Jgsh7Aw9lgEogWrOArg8a6DaeOpo4aqJOJp/GZVvmOe5EDCCIs1Md/epzN/ JbX8mLvmKRsv/FZmb7fHyYmtCDYDtAVWWmIP+VLhQQwO5RPd4lUIE5pmq3ZupWBDZ5zT RAK8r499YSvOSmYbUYRy5JoeUaZDihqtfi+irxScWo9NhpOmr0TZqN52CGJkgQclqSlW 9Jqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=LWC70hBwcYvNIErAJlvTGYTySej5b8z/SPLw2+iq0eQ=; fh=JNoCSBaUSqrph5MwRr1fFVeaKj+BiOjO5OGjfdL2RVI=; b=o4ATHNu/4IOq2uXMWsvYP8OzuiwQeAT/h6soJ3hANo20+NvtQqQIjdggWKVmMBOVAE 2S1OBd/ZCTiyJgaZdXBuOGKQ5xvyIotYm219tDcHkm5AbS2J40xRRMzdToGCtiKobVPH 86EJVj5R0ZJ1bWfQUJa8uLGun8gttrHcfno05WAL4/v9C11wqJycKEguHOrFxQssSn4h glrkBnNwmbc17SLrJ3vKli5itne2/7MyRcYH5ucBvrtZhvcZzT9yaYG6+me4sxoJOaNJ 5vH5NFQic0E6wNfBQpopqxs8CER28JEUcbvZCFP9v6yP10FatDBPF8HYpZgNMMQnYHvq SsmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XS91VSIV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49823-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXZ5vPLKJh2/pfRCK4aSVQ3g7AHfT7LhDh7VJWZGIP0G5cFQXYjDWfo54y5FIXE/lwZLq8dL3LqB/u6F6FYfGly4gDs4A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g6-20020a05620a218600b007840ac8b62asi1827946qka.577.2024.02.02.04.19.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 04:19:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49823-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XS91VSIV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49823-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AA8C11C26BAD for ; Fri, 2 Feb 2024 12:19:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 179841420BC; Fri, 2 Feb 2024 12:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XS91VSIV" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 550BC140764; Fri, 2 Feb 2024 12:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706876302; cv=none; b=GEWkAn/ijUwfmfQeKl3ZP01nUIq7U96qToITqv+PiiAnHd0DiOXB2hXB9BglQ1HXorkayKVtYG12sfr/9InVjSE/6xvF4c4X8F+2lTGxjqMUOKRyKitId3V+zdUznUqxeqUhBfHuHPfJV6ohAQ9nbV4YK6FBVdT6n7XqHkUTkFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706876302; c=relaxed/simple; bh=76bLnTFW8hOss6IF1pWTx33Eugtw/u1ls0YA9hmCWJA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RaBj+9p5EhKXqYkWGDnfEaYTD/2+l3/BYtI1FZifJdXaJj1J1YYcKibATilsSWg/VHcr9xWsp0Kz7ltXxfMZTFVMSUbrdj5Yo9hEu5ecYHJlM/hkWqLfF4532Mw3XbpF9/ki9+bt98rXyOerQQ7RXtx4f5Ty+wg7D5PgLQ+NQKs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XS91VSIV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id F3AF3C433B1; Fri, 2 Feb 2024 12:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706876302; bh=76bLnTFW8hOss6IF1pWTx33Eugtw/u1ls0YA9hmCWJA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XS91VSIVxeAq9Ho4N5W/CiepsN+55y/voO+51FzBqNFFbP9eddOWk7W6ktq2lZ+5+ Pp0SCqzYLiPKNdI7j8wf4UTAgc+S/J77Bf0hDS8RQUZIKOiGV42lZ/TSG/z3izPhiw uadBuCu+CYz0jxWTcNNaLyHahwT4fQIIZoa13E89CF0alxGxlDm9OnM8UNq7f9Rjek h9ijT1J7Plz98HwyqNFlcPgrk0NsBdGoyW7P+0lQVSU9Xd6UN/QjgprS0ogBFwSiIF B27mAYOf3/XH8EuxXnITW/F37jIQXjp2wa0gl7QQYfVGUG1/J2+hazmBU/m34qfYQr SilZ8SUdPBhVQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D61A8C47DB3; Fri, 2 Feb 2024 12:18:21 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Feb 2024 13:18:17 +0100 Subject: [PATCH 2/2] of: dynamic: flush devlinks workqueue before destroying the changeset Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240202-fix-device-links-overlays-v1-2-f9fd1404c8e2@analog.com> References: <20240202-fix-device-links-overlays-v1-0-f9fd1404c8e2@analog.com> In-Reply-To: <20240202-fix-device-links-overlays-v1-0-f9fd1404c8e2@analog.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand , Rob Herring , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Len Brown Cc: linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706876300; l=1506; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=YDuksPxVzpgUXsXtMiptrKAHNtqa9E4wT61h67KKExU=; b=ZZzDh6w2p09vAdpaA/tKnsT3Ui0/BIBnmAmI6LdOVcWud7O6pG7mMOAa9At/XeR3mGQi7zAsu 0e7xJAbQW2cCDWx1T2sT1C8IFd2yKgLf/WrOHH3wwaavzpt33PL6veD X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789789571245466309 X-GMAIL-MSGID: 1789789571245466309 From: Nuno Sa Device links will drop their supplier + consumer refcounts asynchronously. That means that the refcount of the of_node attached to these devices will also be dropped asynchronously and so we cannot guarantee the DT overlay assumption that the of_node refcount must be 1 in __of_changeset_entry_destroy(). Given the above, call the new fwnode_links_flush_queue() helper to flush the devlink workqueue so we can be sure that all links are dropped before doing the proper checks. Signed-off-by: Nuno Sa --- drivers/of/dynamic.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 3bf27052832f..b7153c72c9c9 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "of_private.h" @@ -518,6 +519,13 @@ EXPORT_SYMBOL(of_changeset_create_node); static void __of_changeset_entry_destroy(struct of_changeset_entry *ce) { + /* + * device links drop their device references (and hence their of_node + * references) asynchronously on a dedicated workqueue. Hence we need + * to flush it to make sure everything is done before doing the below + * checks. + */ + fwnode_links_flush_queue(); if (ce->action == OF_RECONFIG_ATTACH_NODE && of_node_check_flag(ce->np, OF_OVERLAY)) { if (kref_read(&ce->np->kobj.kref) > 1) {