Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp2753416rwe; Sun, 16 Apr 2023 04:55:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bkiJ5uDMWhIxDFwABWBK6zc3CXGgLv1M7uB6xCGpJczBErwEJXEngIRpBa+1OlkrDb/LJU X-Received: by 2002:a05:6a00:1402:b0:62d:e966:ffcb with SMTP id l2-20020a056a00140200b0062de966ffcbmr17286538pfu.0.1681646107385; Sun, 16 Apr 2023 04:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681646107; cv=none; d=google.com; s=arc-20160816; b=ACYjKW42X28W4jp5OzsIAeXUu0k2B6kE7aDBLF9exsaF7UwGlXo2Oxr9mTuKNmn5z/ JZLSZnT/g+0JkRUYuGtFsi5at63NE2kWJzAa1C4lKsEdKQcoIY9OhCHs1hOGzMbUBE69 NA/nMv/GqPQRA4fy+azJOazz4tpLIYOx1esruz3MvVJpji7Cob4iC9C1/GUvDV7Cma/8 BbuvwJ/4BfRT5PNkxjvkUmSx2jvFX7VoEWvWJoI99PLMXk+P7bmAfUz1U62RDYJxhgab GnJmbb5DPftOCKs05aEVV2SMx4UwZL77GgAo2POonYQbkT5junC0OpJQt5k6uP00AlIv yQNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=pg/RyKF4/F51xF4q6FaB17wU9tkFpzINx5VyKZ9D9TI=; b=G4HPpVN+ZO6dDbgmvQi5/5CBM7McVePVmoEyDeL5gpMXn1rYkJfmDJ0Vdy/QKvoQIk CFQ+voSCz4yOE+9HFpSRrFof94jlHCPtfuzmDbbzezc0p9ji3DMR6VtMakYfDDu93dLa v0EJ8C01puaUA4FdFbCzUiD+W2+uiRfg5dtIAL4RcB1nQ6xIholH8ShcnSqOXs8uao8s Q/cP4SRhnGpywVOM0ArN2r24YB/tILZkCWuVUqEjwR3ttahTYJml1YkyDuPKYz9VnIkm 1WL6bdHT/oFL1S93wJpyEXH0EMkC8hlIdnmYIe2Wc29lehqYvWUBR2bHouZ3+JAwCgyL BFyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i9BiZCcz; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 144-20020a621896000000b00633d39d7b09si8943712pfy.390.2023.04.16.04.54.40; Sun, 16 Apr 2023 04:55:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@kernel.org header.s=k20201202 header.b=i9BiZCcz; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbjDPLvq (ORCPT + 99 others); Sun, 16 Apr 2023 07:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjDPLvq (ORCPT ); Sun, 16 Apr 2023 07:51:46 -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 3688E1FC7; Sun, 16 Apr 2023 04:51:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BEB7E60CA3; Sun, 16 Apr 2023 11:51:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80BCAC433EF; Sun, 16 Apr 2023 11:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681645904; bh=mNnJMm7iNNu8gLDmVbiscd/RfBID9+WEncb2zmYzGjg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=i9BiZCczvdmzyJkPfIDcpveGRoQRdSamjC6e+aWe8N52ntLjgBmV6mUkeRZaEL0tQ 4VtSSh8Jydovl2VTlCX4xOYGmBzNoYP7KJVHxTMdlOaUHF6qDX3rRdlBjtTm0UaHbf LEbJfkjDsib609aHb9X3lJD997gUwaP9q0xNHUzS14O1cpAttawvLPowPhVFVQ4K6d K5sOGyl5XKpxJRJcrKcf3I27NBQ6y/tY3ONEfZscNsQQd7ShUoNnqY5TDsc6xMCN1Q FWoyQjWLhjrfPLymbQuUhrcAMxKm8bTomSo1QO+UFjKcNO5y2hcDHG4xaFI2N9Bokg 3nFxVBIdq2hOQ== Message-ID: <7246a80ae33244a4553bbc0ca9e771ce8143d97b.camel@kernel.org> Subject: Re: [PATCH] nfsd: don't use GFP_KERNEL from nfsd_getxattr()/nfsd_listxattr() From: Jeff Layton To: Tetsuo Handa , Chuck Lever III Cc: Frank van der Linden , Linux NFS Mailing List , Frank van der Linden , linux-fsdevel Date: Sun, 16 Apr 2023 07:51:41 -0400 In-Reply-To: References: <72bf692e-bb6b-c1f2-d1ba-3205ab649b43@I-love.SAKURA.ne.jp> <4BC7955B-40E4-4A43-B2D1-2E9302E84337@oracle.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-nfs@vger.kernel.org On Sun, 2023-04-16 at 08:21 +0900, Tetsuo Handa wrote: > On 2023/04/16 3:40, Jeff Layton wrote: > > On Sun, 2023-04-16 at 02:11 +0900, Tetsuo Handa wrote: > > > On 2023/04/16 1:13, Chuck Lever III wrote: > > > > > On Apr 15, 2023, at 7:07 AM, Tetsuo Handa wrote: > > > > >=20 > > > > > Since GFP_KERNEL is GFP_NOFS | __GFP_FS, usage like GFP_KERNEL | = GFP_NOFS > > > > > does not make sense. Drop __GFP_FS flag in order to avoid deadloc= k. > > > >=20 > > > > The server side threads run in process context. GFP_KERNEL > > > > is safe to use here -- as Jeff said, this code is not in > > > > the server's reclaim path. Plenty of other call sites in > > > > the NFS server code use GFP_KERNEL. > > >=20 > > > GFP_KERNEL memory allocation calls filesystem's shrinker functions > > > because of __GFP_FS flag. My understanding is > > >=20 > > > Whether this code is in memory reclaim path or not is irrelevant. > > > Whether memory reclaim path might hold lock or not is relevant. > > >=20 > > > . Therefore, question is, does nfsd hold i_rwsem during memory reclai= m path? > > >=20 > >=20 > > No. At the time of these allocations, the i_rwsem is not held. >=20 > Excuse me? nfsd_getxattr()/nfsd_listxattr() _are_ holding i_rwsem > via inode_lock_shared(inode) before kvmalloc(GFP_KERNEL | GFP_NOFS) alloc= ation. > That's why >=20 > /* > * We're holding i_rwsem - use GFP_NOFS. > */ >=20 > is explicitly there in nfsd_listxattr() side. >=20 > If memory reclaim path (directly or indirectly via locking dependency) in= volves > inode_lock_shared(inode)/inode_lock(inode), it is not safe to use __GFP_F= S flag. >=20 (cc'ing Frank V. who wrote this code and -fsdevel) I stand corrected! You're absolutely right that it's taking the i_rwsem for read there. That seems pretty weird, actually. I don't believe we need to hold the inode_lock to call vfs_getxattr or vfs_listxattr, and certainly nothing else under there requires it. Frank, was there some reason you decided you needed the inode_lock there? It looks like under the hood, the xattr code requires you to take it for write in setxattr and removexattr, but you don't need it at all in getxattr or listxattr. Go figure. If there's no reason to keep it there, then in addition to removing GFP_NOFS there I think we probably ought to just remove the inode_lock from nfsd_getxattr and nfsd_listxattr altogether. Longer term, I wonder what the inode_lock is protecting in setxattr and removexattr operations, given that get and list don't require them? These are always delegated to the filesystem driver -- there is no generic xattr implementation. Maybe we ought to do a lock pushdown on those operations at some point? I'd bet that most of the setxattr/removexattr operations do their own locking and don't require the i_rwsem at all. --=20 Jeff Layton