From patchwork Mon Jul 4 15:42:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12905535 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A786C433EF for ; Mon, 4 Jul 2022 15:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4pBHwwGROL+xG5BwSu45ntdnmH68CcKGQrJnrOchLb8=; b=Mn3701jXV328t9 I7ns1452L1SsHs0Y03BeoMjANXAw39YwDmEmeszy6NFBH1DRbv7FgS3rkdg/8qdnGg+MDfoD7Ac/H 3EPKrCSjklp4LPhgpJl3XhylvQQs0ov8s75hPkMksl9rpRnfdL/ulgaH7iT8YT/i9ZNABxdUJuhlA hdO0BhUxlj2kA3oyBkExXsXzJf4mdiXVTiqotlW1qUQpALgMEGp4h0daSGCBicz3hXeXn5nCoqfdK ptQ1qt5gxDv7G2aWza5OndGg74O7E+XVZ56RRmG8B2Cg4edHKigz+kW2MrBl7OmHCV4/2RHsrqrdb 7aWlKA9Ukg1aved3J3tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8OFV-009mPC-Pt; Mon, 04 Jul 2022 15:44:33 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8OE1-009lla-Cm for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 15:43:03 +0000 Received: by mail-wr1-x42c.google.com with SMTP id q9so14020924wrd.8 for ; Mon, 04 Jul 2022 08:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=46SlzW74GIiHvhVWuQrLRhWnlm69Aurjg5UhCuYh8/k=; b=tJ2R8cV0GXu4lJJxtQOskBniE5SCBOJmzYLF6g+YoBM/ND2oaDYMEI12eU1iSR9CB4 kvtjlQ03jzaTxrEoYN5/aNfDr9XavyViWb20b4VFUAS1XHWfqzfjyD3z4r1SOkuUNaRa bUOxuErvNKBqRfHNwhbnwp/3s6uOUsjcdmyHa0gEXTAKzsdvaP4kl1mQGd23V9us2mVH EuT1SuhwPAymWdXQk6BOZS0MMf9sNso2+l5EI3Z2JSeaGtNQguYinMWTXHrrB61ExiTv qh89lVbfcWz3YjCTsfxfOmEB52+iQwYUyRvDWrFUXJAv3tszFTd7YeARbSapGoQsKudK /LBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=46SlzW74GIiHvhVWuQrLRhWnlm69Aurjg5UhCuYh8/k=; b=HDB5G3rwvrGtvUD0HXgsMXfsG1OYYVNSohb6zdBwBFJDW3hAmRvELB6uVGvN++OSL4 pIbhdhEHw9Ksste9UZXZGTFmm7eRxdjrTu0dWKmGY4V/9DEUaqsWZ4gSxygx1A8G2zJy cZCDkyNka572Z3oOHWffl3cOvPfyjinHfmYv7Yii08Wlp83LMo4bYdC3JgNlBGFVKA7G +u1zhzz0R+O2hQkUX/RHOoxthIeauQqAMrTE3sTrqqRNFzzsEWpV1N8Ms2LKf/WI+UdL IpvJQ+ksy9qgxYXl+bL1Tnr0Mhm3ki7G2XT6PYm/uF8RCkyuG9slSwjRkiCEIz8QqQ8W Qr3Q== X-Gm-Message-State: AJIora9/j7VxirHcXaHJwriSsnsypR63Ccp6vZxl3wpHkL1OOIBvGmgr ksv6buuAkgTngAK/ncn5OD7mwyDq57c6bw== X-Google-Smtp-Source: AGRyM1s/hggudqgbsLZO5A9418cfpoWQrC3JDVJB1TU5WdQcG/6N+DuyzVdbMA7ftjSlm+QVDzET6g== X-Received: by 2002:adf:d1c2:0:b0:21b:e465:1e36 with SMTP id b2-20020adfd1c2000000b0021be4651e36mr28864769wrd.271.1656949377791; Mon, 04 Jul 2022 08:42:57 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:a9e8:9fdd:fa2d:1c72]) by smtp.gmail.com with ESMTPSA id j6-20020adfff86000000b0021d6b851ca1sm2763749wrr.111.2022.07.04.08.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 08:42:57 -0700 (PDT) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, leo.yan@linaro.org, acme@kernel.org, james.clark@arm.com, Mike Leach , Joel Becker , Christoph Hellwig Subject: [PATCH v4 7/7] configfs: Fix LOCKDEP nesting issues with fragment semaphores Date: Mon, 4 Jul 2022 16:42:49 +0100 Message-Id: <20220704154249.11501-8-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704154249.11501-1-mike.leach@linaro.org> References: <20220704154249.11501-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_084301_481581_B821802B X-CRM114-Status: GOOD ( 22.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org CoreSight uses configfs to represent the user interface to programmed configurations, which can be loaded and unloaded dynamically via configfs. These add and remove configurations using register/unregister group calls. It has been found that if CONFIG_LOCKDEP is enabled, then it appears to be confused by the nesting inherent in the fragment semaphores used by groups and the underlying subsystem. This patch sets up a mechanism to use separate classes for the fragment semaphores, in a similar way to that already in place to fix nesting issues with the i_mutexes. Cc: Joel Becker Cc: Christoph Hellwig Signed-off-by: Mike Leach --- fs/configfs/configfs_internal.h | 3 +++ fs/configfs/dir.c | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h index c0395363eab9..736c74ec4b7a 100644 --- a/fs/configfs/configfs_internal.h +++ b/fs/configfs/configfs_internal.h @@ -22,6 +22,9 @@ struct configfs_fragment { atomic_t frag_count; struct rw_semaphore frag_sem; bool frag_dead; +#ifdef CONFIG_LOCKDEP + int frag_depth; +#endif }; void put_fragment(struct configfs_fragment *); diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index d1f9d2632202..6ecd8961afc3 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -133,6 +133,41 @@ configfs_adjust_dir_dirent_depth_after_populate(struct configfs_dirent *sd) sd->s_depth = -1; } +/* fragment semaphore needs some lockdep handling */ +static struct lock_class_key default_frag_class[MAX_LOCK_DEPTH]; + +/* + * Set the lockdep depth for a new fragment based on the parent frag depth. + * Called from register_subsystem() with NULL parent group to set root subsystem + * depth which defaults to 0 in a new fragment, and from register_group() with the + * parent group to set a new group fragment based on the parent fragment depth. + * + * Prevents lockdep getting upset on the unregister_group() call if it cannot + * understand the hierarchy of fragments. + */ +static void configfs_adjust_frag_depth(struct configfs_fragment *frag, + struct config_group *parent_group) +{ + struct configfs_dirent *parent_dirent; + + if (parent_group) { + // find parent frag + parent_dirent = parent_group->cg_item.ci_dentry->d_fsdata; + frag->frag_depth = parent_dirent->s_frag->frag_depth + 1; + } + + if (frag->frag_depth < ARRAY_SIZE(default_frag_class)) { + lockdep_set_class(&frag->frag_sem, + &default_frag_class[frag->frag_depth]); + } else { + /* + * In practice the maximum level of locking depth is + * already reached. Just inform about possible reasons. + */ + pr_info("Too many levels of fragments for the locking correctness validator.\n"); + } +} + #else /* CONFIG_LOCKDEP */ static void configfs_init_dirent_depth(struct configfs_dirent *sd) @@ -154,6 +189,11 @@ configfs_adjust_dir_dirent_depth_after_populate(struct configfs_dirent *sd) { } +static void configfs_adjust_frag_depth(struct configfs_fragment *frag, + struct config_group *parent_group) +{ +} + #endif /* CONFIG_LOCKDEP */ static struct configfs_fragment *new_fragment(void) @@ -165,6 +205,9 @@ static struct configfs_fragment *new_fragment(void) atomic_set(&p->frag_count, 1); init_rwsem(&p->frag_sem); p->frag_dead = false; +#ifdef CONFIG_LOCKDEP + p->frag_depth = 0; +#endif } return p; } @@ -1742,6 +1785,7 @@ int configfs_register_group(struct config_group *parent_group, parent = parent_group->cg_item.ci_dentry; inode_lock_nested(d_inode(parent), I_MUTEX_PARENT); + configfs_adjust_frag_depth(frag, parent_group); ret = create_default_group(parent_group, group, frag); if (ret) goto err_out; @@ -1872,6 +1916,7 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys) mutex_unlock(&configfs_subsystem_mutex); inode_lock_nested(d_inode(root), I_MUTEX_PARENT); + configfs_adjust_frag_depth(frag, NULL); err = -ENOMEM; dentry = d_alloc_name(root, group->cg_item.ci_name);