Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1931022rdb; Sun, 19 Nov 2023 17:17:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbAuCajYAEO1Z7gQTFgQLPMQ8Y1OsSojSWQavS4OuxkhGygChLKx5AASjbun60aHRVnjNX X-Received: by 2002:a05:6a21:99a7:b0:14c:a2e1:65ec with SMTP id ve39-20020a056a2199a700b0014ca2e165ecmr8782193pzb.38.1700443043523; Sun, 19 Nov 2023 17:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700443043; cv=none; d=google.com; s=arc-20160816; b=vVdk/0D4Yp7ZmETtTqxu4Y551dKQ1cIe16c5b0NgiRLD4y74gjRbpanbjwEXQ2MvNN XLfqpZYRfeQXWwuH22ytkrdDTY6iyeIzvxYqEld9ia5EXrGJnMGBZjcsL8joiS5N7jcN mfayNP+V6sz0o8HFKznlPwoJ/lSjJCMw9PuGWNswD1YPOPz2Kef1gP5GWpcpFup+iiDS bz4WaPjeMWj6m4leKAZoNjF3k2y48GBsNiwZUPYdt0Ex/x/8JQH2kQjZJrLVyDh+11tw rzJgZB2wzoBWucWa+dNl9/cMPg7ghFaw//yEvPZBjD/P6TRwde4sO7oPXiM27O+zE+b4 jeVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject:dkim-signature; bh=q8T74YS2fosSZM53BMM71uHQjJOWdd7TU4jyqJllH1c=; fh=VFBVf2jGaHsKktvG7m2OX4TYoG+YmCm7M7xSJQ+49IE=; b=Nqb8WvlypJHevWE7s8y/gjUCYkFKgtK6JYeSeDHup7EVdr9lMWUWfJ4YSfY6CjmNt/ e/vacz6TrO8QCsa7jPsuZPBFjCE4UQry78NSOZJE+jIy+oHm6vqmNyk9l8zLBJYc6JGl b69aXtk/yVLNAlTlAQzrx5aBX42Z+UxmyMw4O2pS7DNVq2xATYZKBAfNMHYocSzQuEEn bn1kPPz9y0fcVqPW1pz6uHBOp2Zp1AZWYk8DiaM35/NJY2KYHKRCPEh0lsQ90pfXDCIO KW3rq/v9VfOR6HIbmH2MWEkDWbNPKJsHRVdAky9jPuP7HG0zAUt2pQDucOIEOWBnFYtB QP7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="s5ScbHa/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id gp1-20020a17090adf0100b002803e634e13si9551684pjb.151.2023.11.19.17.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 17:17:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="s5ScbHa/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C72E0806141E; Sun, 19 Nov 2023 17:17:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229569AbjKTBRT (ORCPT + 99 others); Sun, 19 Nov 2023 20:17:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjKTBRT (ORCPT ); Sun, 19 Nov 2023 20:17:19 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1DD107 for ; Sun, 19 Nov 2023 17:17:16 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21396C433C8; Mon, 20 Nov 2023 01:17:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700443032; bh=Nx49sN8FqQm27Tfby83rI2t+pYBeM74/Q4HQ6/nyn0o=; h=Subject:From:To:Cc:Date:From; b=s5ScbHa/Et7CcQRAww0Q+HXQADfDKvcax08FRY0G5K/0SZ6M4R111G5IEvo/jTr1g YMarLn5zJE1FlSO9f+7Rrrzmrfd30rBiNVYw5646mJzfCUJTG5Nv5Cn9WxdgXVm6in YI/+lZlEN5Anx0xO7C2v0ejMZeKYnYfGbk5wH6yTyYMtJ2ZV7ksLim05v+v7NsgLey qDpLN8XFiPBNrxj1QooL8CoZYEKFM+Rfg1+asW0X4S40FOT8+Gxzd4zIN05Zo+nD01 o27Zec3rG+T6oy39zD+Xn+G6BVNmMPxnzepvm9l18swUDjtJRhrqVS4d1z8BBLMV8C YUv2kFtSJsNSg== Subject: [PATCH v1] NFSD: Document lack of f_pos_lock in nfsd_readdir() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: viro@zeniv.linux.org.uk Date: Sun, 19 Nov 2023 20:17:11 -0500 Message-ID: <170044303100.5164.767231155248883501.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 19 Nov 2023 17:17:19 -0800 (PST) From: Chuck Lever Al Viro notes that normal system calls hold f_pos_lock when calling ->iterate_shared and ->llseek; however nfsd_readdir() does not take that mutex when calling these methods. It should be safe however because the struct file acquired by nfsd_readdir() is not visible to other threads. Signed-off-by: Chuck Lever --- fs/nfsd/vfs.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index fbbea7498f02..87a5953c6bf0 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -2109,9 +2109,23 @@ static __be32 nfsd_buffered_readdir(struct file *file, struct svc_fh *fhp, return cdp->err; } -/* - * Read entries from a directory. - * The NFSv3/4 verifier we ignore for now. +/** + * nfsd_readdir - Read entries from a directory + * @rqstp: RPC transaction context + * @fhp: NFS file handle of directory to be read + * @offsetp: OUT: seek offset of final entry that was read + * @cdp: OUT: an eof error value + * @func: entry filler actor + * + * This implementation ignores the NFSv3/4 verifier cookie. + * + * NB: normal system calls hold file->f_pos_lock when calling + * ->iterate_shared and ->llseek, but nfsd_readdir() does not. + * Because the struct file acquired here is not visible to other + * threads, it's internal state does not need mutex protection. + * + * Returns nfs_ok on success, otherwise an nfsstat code is + * returned. */ __be32 nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp,