From patchwork Fri Aug 4 22:41:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 710689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8D43C04A6A for ; Fri, 4 Aug 2023 22:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbjHDWmT (ORCPT ); Fri, 4 Aug 2023 18:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjHDWmQ (ORCPT ); Fri, 4 Aug 2023 18:42:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F240246B3; Fri, 4 Aug 2023 15:42:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 702066215E; Fri, 4 Aug 2023 22:42:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23B32C433C7; Fri, 4 Aug 2023 22:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691188934; bh=J7O07IUOpjRY/io4/uOgLa6WjHDFcDRrzq7DlljLaM8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rEXhsZ8CpbWlBk1Y+51kSPKl1125KzQA0JfelmLnQpCvkXJ2YvofyzkQOXDbFOQSc Q5+Vhiajid8eqfrBBwGnhfRcLmlb1cJF9YdBYxuAmeI6iwBX8iyMn98j1j3cJsgy/1 v8GTCHMmQh0woqCMEZkrsiLW29nrzxMOGzA0hxYtuFn1SjsMKXoeaz+53/knX2/ExT jN5TArDyxMyDMStrKNf7ESiBNHJOj+io47y0/MgiqwLG8tankN6D8Gd+camNyI4lZC tQOswJrU6jpLTmwuRF7dfgm2Ygg56YsYTdQcLyhWiuSmx9nEZEAVQfrC41BsMmPq3t fA7SgCXsEsrRA== Received: (nullmailer pid 2346977 invoked by uid 1000); Fri, 04 Aug 2023 22:42:09 -0000 From: Rob Herring Date: Fri, 04 Aug 2023 16:41:52 -0600 Subject: [PATCH v2 2/6] of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock MIME-Version: 1.0 Message-Id: <20230801-dt-changeset-fixes-v2-2-c2b701579dee@kernel.org> References: <20230801-dt-changeset-fixes-v2-0-c2b701579dee@kernel.org> In-Reply-To: <20230801-dt-changeset-fixes-v2-0-c2b701579dee@kernel.org> To: Frank Rowand , "Enrico Weigelt, metux IT consult" , "Rafael J. Wysocki" , Sakari Ailus , Petr Mladek , Andy Shevchenko , Geert Uytterhoeven Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.13-dev Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org While originally it was fine to format strings using "%pOF" while holding devtree_lock, this now causes a deadlock. Lockdep reports: of_get_parent from of_fwnode_get_parent+0x18/0x24 ^^^^^^^^^^^^^ of_fwnode_get_parent from fwnode_count_parents+0xc/0x28 fwnode_count_parents from fwnode_full_name_string+0x18/0xac fwnode_full_name_string from device_node_string+0x1a0/0x404 device_node_string from pointer+0x3c0/0x534 pointer from vsnprintf+0x248/0x36c vsnprintf from vprintk_store+0x130/0x3b4 Fix this by moving the printing in __of_changeset_entry_apply() outside the lock. As the only difference in the the multiple prints is the action name, use the existing "action_names" to refactor the prints into a single print. Fixes: a92eb7621b9fb2c2 ("lib/vsprintf: Make use of fwnode API to obtain node names and separators") Reported-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- v5 (v2 in this series): - Move majority of refactoring to separate patch and minimize the fix to just moving the print out of the locked section. v4: - Add missing 'static' reported by 0-day v3: - Re-implement Geert's fix to move the prints rather than move the spinlock v1 and v2 from Geert simply moved the devtree_lock into each case statement: https://lore.kernel.org/all/c593d8389352c574b5be69d4ca4810da13326a50.1690533838.git.geert+renesas@glider.be/ --- drivers/of/dynamic.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index e311d406b170..2f0eb0053773 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -63,15 +63,13 @@ int of_reconfig_notifier_unregister(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister); -#ifdef DEBUG -const char *action_names[] = { +static const char *action_names[] = { [OF_RECONFIG_ATTACH_NODE] = "ATTACH_NODE", [OF_RECONFIG_DETACH_NODE] = "DETACH_NODE", [OF_RECONFIG_ADD_PROPERTY] = "ADD_PROPERTY", [OF_RECONFIG_REMOVE_PROPERTY] = "REMOVE_PROPERTY", [OF_RECONFIG_UPDATE_PROPERTY] = "UPDATE_PROPERTY", }; -#endif int of_reconfig_notify(unsigned long action, struct of_reconfig_data *p) { @@ -620,21 +618,9 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) } ret = __of_add_property(ce->np, ce->prop); - if (ret) { - pr_err("changeset: add_property failed @%pOF/%s\n", - ce->np, - ce->prop->name); - break; - } break; case OF_RECONFIG_REMOVE_PROPERTY: ret = __of_remove_property(ce->np, ce->prop); - if (ret) { - pr_err("changeset: remove_property failed @%pOF/%s\n", - ce->np, - ce->prop->name); - break; - } break; case OF_RECONFIG_UPDATE_PROPERTY: @@ -648,20 +634,17 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) } ret = __of_update_property(ce->np, ce->prop, &old_prop); - if (ret) { - pr_err("changeset: update_property failed @%pOF/%s\n", - ce->np, - ce->prop->name); - break; - } break; default: ret = -EINVAL; } raw_spin_unlock_irqrestore(&devtree_lock, flags); - if (ret) + if (ret) { + pr_err("changeset: apply failed: cset<%p> %-15s %pOF:%s\n", + ce, action_names[ce->action], ce->np, ce->prop->name); return ret; + } switch (ce->action) { case OF_RECONFIG_ATTACH_NODE: