Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp579409rwb; Thu, 27 Jul 2023 18:16:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlGBZH/BTwuZIq7JsXeIp4hO+yZPrfh+GPYUveg53u79aK7xegExpaBcmaR8jFm/+usXNQc4 X-Received: by 2002:a05:6a21:998f:b0:133:31a5:51e7 with SMTP id ve15-20020a056a21998f00b0013331a551e7mr407980pzb.15.1690506996490; Thu, 27 Jul 2023 18:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690506996; cv=none; d=google.com; s=arc-20160816; b=tun8Z3MBUlMnIEWfdzkL6w8bgcsMCFMPvN9bE+0eYIQ1Rks1yYFVN+AuByHMvcR7AR sJi/SQkVjz5sZoRZ0nDB87B3JgP5ZEdAO6og5qz6bckHGcWrQG91nMiuGa3QT7gxJypr BWHNSikP00BN74vFQCS49+ZU2sbOk27SwKPF0fxZ/Hz2zy8q58HmECYEQ6xkV3ZqUKRr TK/3AO52lcuX8LLsCmvEGt3BwpGxk2rAmzQmfxPKn7nimLSK1dpD0+PUlX0Tlb3j43Ac T/C9b7e5vFfrbXm8kv04M0a+grT1Ldbzlr5Zlq6Azr5uVKf166lrkNDnkZIkXzwnzPu1 AV/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:feedback-id:dkim-signature:dkim-signature; bh=B9vNmwATli/9YytihPIv5vkCD7D8T9gClaI0PewxNUQ=; fh=T6I/UV8tlehzaN2toXM1pm+n9x3Ami3GO8a9faTA2N4=; b=N8JR3dl0jBIqusnGlBMCGZjyX94QaBfEZaXknUvVw8HQ47Md2yXFXIjLOboE6ZvnFO t1ZycUU/nOSfWuuvYwW4Ju6s1ZGWS1BqH8Ly945ek/mZmNeM1wZLNvCVI184BYrMjFoP MYwIrLxaeIGv5UgUEgTKjsldejkNOBK/NJrpIl9TV1auzoWbIPGRfq0J3S1qADSOEd+s 0lJdCD/SS7yZ2oqhUxc+re6aUW8SXKg6hBiXgj5u+t8c4KtVL8dducBVg3qhkaO69YLc 8bN2UfAggoA0qI2ATu8halDyxrGAqwR8eSecM5vFQH9PaAyzRUx3gTvF6IPKPPNadhfq Lqtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@themaw.net header.s=fm2 header.b=XBaViwcd; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Qx7Rzow6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i127-20020a639d85000000b00557447d5721si1981512pgd.768.2023.07.27.18.16.24; Thu, 27 Jul 2023 18:16:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@themaw.net header.s=fm2 header.b=XBaViwcd; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Qx7Rzow6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232064AbjG1ARL (ORCPT + 99 others); Thu, 27 Jul 2023 20:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230182AbjG1ARI (ORCPT ); Thu, 27 Jul 2023 20:17:08 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A14702685; Thu, 27 Jul 2023 17:17:02 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 16AEA5C018A; Thu, 27 Jul 2023 20:17:02 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 27 Jul 2023 20:17:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=themaw.net; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1690503422; x=1690589822; bh=B9vNmwATli/9YytihPIv5vkCD7D8T9gClaI 0PewxNUQ=; b=XBaViwcdJeDS3sg6zo2VPk2SK6SLw6wWFQrY7wbduhfDbssyD2m /WCt1fLFQcbQABhuZIBgqqqT2TvOfakTPPkyOAmWrLnVs/XZaXTqzxlJcVWCjOKN B16wGl3bfaNV6rNOjcvZ7sPV2H2982B6r3pxQ6kX1cnUz9yGcpUoXqbs/cXWcLPD xsS4IZkRcSsNsU39f+AXuCtyuQJ77qPPdsFQihY2DKA20dzmohu5OHMY2LlN/tBm zUG4qit2as01U2aNdcEtJSHnNgX3kM1vi+cJyVMU4MtPYu/bjsRXFbIKSSTgkqrc umqI42b9jrAUeEnfOA5Mo/f/Ze+yicwIWFQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1690503422; x=1690589822; bh=B9vNmwATli/9YytihPIv5vkCD7D8T9gClaI 0PewxNUQ=; b=Qx7Rzow6uR7McQ7/H8Jhf7Ic5WpZvfNhSk7YJa4lCy9EG9g8olb rNEYxuPtuB7w5kEc1Iaq4Iz3Jk0pLw7JOv014uRTI2R2b2rj0FeXFjBBti8AiJ05 SxZgq2Jh2fmMbFUGt3VxK/3cm4D+DKktW2FBbW3fIywkTMdl/5tt0SW0ysJvspo/ 8pOukq6vc4h3LwBVJFXpXTcA8WQ81ugcu0JIMp5/JlD62bX8KQzawcpNFV4DpQZi jnC0Ide8VOy7dU+8TF9leSKeQySXxyPTLnI19pjq79rVCYQRvHKIKyfmsfU+fVDQ 9SYzMDY6Jk3/GqimabqhQt07ag33mxn0KEw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrieehgdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuhffvvehfjggtgfesthekredttdefjeenucfhrhhomhepkfgrnhcu mfgvnhhtuceorhgrvhgvnhesthhhvghmrgifrdhnvghtqeenucggtffrrghtthgvrhhnpe eiveelkefgtdegudefudeftdelteejtedvheeuleevvdeluefhuddtieegveelkeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrrghvvghnse hthhgvmhgrfidrnhgvth X-ME-Proxy: Feedback-ID: i31e841b0:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 27 Jul 2023 20:16:55 -0400 (EDT) Message-ID: <70d667af-661b-6f62-aa29-a3b8610feda6@themaw.net> Date: Fri, 28 Jul 2023 08:16:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH 1/2] kernfs: dont take i_lock on inode attr read Content-Language: en-US From: Ian Kent To: Imran Khan , Anders Roxell Cc: Arnd Bergmann , Tejun Heo , Greg Kroah-Hartman , Minchan Kim , Eric Sandeen , Alexander Viro , Rick Lindsley , David Howells , Miklos Szeredi , Carlos Maiolino , linux-fsdevel , Kernel Mailing List , elver@google.com References: <166606025456.13363.3829702374064563472.stgit@donald.themaw.net> <166606036215.13363.1288735296954908554.stgit@donald.themaw.net> <20221221133428.GE69385@mutt> <7815c8da-7d5f-c2c5-9dfd-7a77ac37c7f7@themaw.net> <9e35cf66-79ef-1f13-dc6b-b013c73a9fc6@themaw.net> <20230718190009.GC411@mutt> <76fcd1fe-b5f5-dd6b-c74d-30c2300f3963@themaw.net> <15eddad0-e73b-2686-b5ba-eaacc57b8947@themaw.net> <3505769d-9e7a-e76d-3aa7-286d689345b6@oracle.com> <996e11bf-5f22-3ab7-2951-92109649195d@themaw.net> In-Reply-To: <996e11bf-5f22-3ab7-2951-92109649195d@themaw.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/7/23 08:00, Ian Kent wrote: > On 27/7/23 12:30, Imran Khan wrote: >> Hello Ian, >> Sorry for late reply. I was about to reply this week. >> >> On 27/7/2023 10:38 am, Ian Kent wrote: >>> On 20/7/23 10:03, Ian Kent wrote: >>>> On Wed, 2023-07-19 at 12:23 +0800, Ian Kent wrote: >> [...] >>>> I do see a problem with recent changes. >>>> >>>> I'll send this off to Greg after I've done some testing (primarily >>>> just >>>> compile and function). >>>> >>>> Here's a patch which describes what I found. >>>> >>>> Comments are, of course, welcome, ;) >>> Anders I was hoping you would check if/what lockdep trace >>> >>> you get with this patch. >>> >>> >>> Imran, I was hoping you would comment on my change as it >>> >>> relates to the kernfs_iattr_rwsem changes. >>> >>> >>> Ian >>> >>>> kernfs: fix missing kernfs_iattr_rwsem locking >>>> >>>> From: Ian Kent >>>> >>>> When the kernfs_iattr_rwsem was introduced a case was missed. >>>> >>>> The update of the kernfs directory node child count was also protected >>>> by the kernfs_rwsem and needs to be included in the change so that the >>>> child count (and so the inode n_link attribute) does not change while >>>> holding the rwsem for read. >>>> >> kernfs direcytory node's child count changes in >> kernfs_(un)link_sibling and >> these are getting invoked while adding (kernfs_add_one), >> removing(__kernfs_remove) or moving (kernfs_rename_ns)a node. Each of >> these >> operations proceed under kernfs_rwsem and I see each invocation of >> kernfs_link/unlink_sibling during the above mentioned operations is >> happening >> under kernfs_rwsem. >> So the child count should still be protected by kernfs_rwsem and we >> should not >> need to acquire kernfs_iattr_rwsem in kernfs_link/unlink_sibling. > > Yes, that's exactly what I intended (assuming you mean write lock in > those cases) > > when I did it so now I wonder what I saw that lead to my patch, I'll > need to look > > again ... Ahh, I see why I thought this ... It's the hunk: @@ -285,10 +285,10 @@ int kernfs_iop_permission(struct mnt_idmap *idmap,         kn = inode->i_private;         root = kernfs_root(kn); -       down_read(&root->kernfs_rwsem); +       down_read(&root->kernfs_iattr_rwsem);         kernfs_refresh_inode(kn, inode);         ret = generic_permission(&nop_mnt_idmap, inode, mask); -       up_read(&root->kernfs_rwsem); +       up_read(&root->kernfs_iattr_rwsem);         return ret;  } which takes away the kernfs_rwsem and introduces the possibility of the change. It may be more instructive to add back taking the read lock of kernfs_rwsem in .permission() than altering the sibling link and unlink functions, I mean I even caught myself on it. Ian > > >> >> Kindly let me know your thoughts. I would still like to see new >> lockdep traces >> with this change. > > Indeed, I hope Anders can find time to get the trace. > > > Ian > >> >> Thanks, >> Imran >> >>>> Fixes: 9caf696142 (kernfs: Introduce separate rwsem to protect inode >>>> attributes) >>>> >>>> Signed-off-by: Ian Kent >>>> Cc: Anders Roxell >>>> Cc: Imran Khan >>>> Cc: Arnd Bergmann >>>> Cc: Minchan Kim >>>> Cc: Eric Sandeen >>>> --- >>>>    fs/kernfs/dir.c |    4 ++++ >>>>    1 file changed, 4 insertions(+) >>>> >>>> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c >>>> index 45b6919903e6..6e84bb69602e 100644 >>>> --- a/fs/kernfs/dir.c >>>> +++ b/fs/kernfs/dir.c >>>> @@ -383,9 +383,11 @@ static int kernfs_link_sibling(struct kernfs_node >>>> *kn) >>>>        rb_insert_color(&kn->rb, &kn->parent->dir.children); >>>>          /* successfully added, account subdir number */ >>>> + down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); >>>>        if (kernfs_type(kn) == KERNFS_DIR) >>>>            kn->parent->dir.subdirs++; >>>>        kernfs_inc_rev(kn->parent); >>>> +    up_write(&kernfs_root(kn)->kernfs_iattr_rwsem); >>>>          return 0; >>>>    } >>>> @@ -408,9 +410,11 @@ static bool kernfs_unlink_sibling(struct >>>> kernfs_node *kn) >>>>        if (RB_EMPTY_NODE(&kn->rb)) >>>>            return false; >>>>    + down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); >>>>        if (kernfs_type(kn) == KERNFS_DIR) >>>>            kn->parent->dir.subdirs--; >>>>        kernfs_inc_rev(kn->parent); >>>> +    up_write(&kernfs_root(kn)->kernfs_iattr_rwsem); >>>>          rb_erase(&kn->rb, &kn->parent->dir.children); >>>>        RB_CLEAR_NODE(&kn->rb); >>>>