From patchwork Wed Nov 27 15:28:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13887145 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76D18D6ACEB for ; Wed, 27 Nov 2024 15:28:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C2826B0092; Wed, 27 Nov 2024 10:28:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 024FB6B008C; Wed, 27 Nov 2024 10:28:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF4DF6B0092; Wed, 27 Nov 2024 10:28:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AE6836B0089 for ; Wed, 27 Nov 2024 10:28:24 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4D4B91C793B for ; Wed, 27 Nov 2024 15:28:24 +0000 (UTC) X-FDA: 82832256234.03.972722D Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf11.hostedemail.com (Postfix) with ESMTP id E0AD440016 for ; Wed, 27 Nov 2024 15:28:15 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OUF1FZnE; spf=pass (imf11.hostedemail.com: domain of cel@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732721296; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=faVLgSYD5zgubge24QYkBt9ct7o8n5VsqyIvRy82wAE=; b=Z6vYsJYTQjT9fh1Y03/RvKvljETcj3BVbklkqvaQvbhHdQEAhKbXcZi1jttZba92VOkK35 bwhSiRof8s3tj3EOb+Op3+o7g2LniFtJASbuhr9q2X+clpFTZ1HUeu1AygetgJc5CQkDJa Em3G1d5pjoqFCeDjxxQeU1SU7d4Gcu4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732721296; a=rsa-sha256; cv=none; b=3DmpRbEEhVXJSOJuZi891Q9PpcUfQ7HuS4I4CDSllXs9F5SW69HUgtogGpky5TmpjkimL0 3XcKuSHwwpuKjAKsjigVk4HAbUbtznFGP+ZhlAfUz8XI2wwuyuGM5UkJNFUpG1RRh8Udcg BZryoizqi9AZfncviSi/d0bgzi5Q+pU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OUF1FZnE; spf=pass (imf11.hostedemail.com: domain of cel@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 51326A43930; Wed, 27 Nov 2024 15:26:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 417F9C4CED4; Wed, 27 Nov 2024 15:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732721302; bh=VKlx/q6S0TZnqYbdlXcPYo2H5Z6zTd8jSftplsjeB2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OUF1FZnEbEpTpG79Oe/YjbbeeVfCsXJ/5xBFkexLOTBtxQVGlfx9MOJwh3G2/j/by UYpk2NVmI1OKMIJ7nv+n3tQnlk0qayYy4skYlF6AfnIk+FcSfxCKxwyse3Z2xLthro ljQctQEOJeORXjPDZnfmr7M2dgXbM0vocnmmVjq9ZueoUhhpTxPrY+f2lgZ9nUVTiy 1Df+8URO5rh2kPGypKBxQ5BMX6PiCCd4sMyxsMgQuHFJGZwkvZjvzY8AINLKwTQs/c DhXZdZysUC89taQn6jHsQa7UAL0gArN4EXazDKH6Q2UlEvpLDn71hi2vxH8QyVXmL8 4VrymohnnAQbQ== From: cel@kernel.org To: Hugh Dickens , Christian Brauner , Al Viro Cc: , , yukuai3@huawei.com, yangerkun@huaweicloud.com, Chuck Lever Subject: [RFC PATCH v3 3/5] Revert "libfs: fix infinite directory reads for offset dir" Date: Wed, 27 Nov 2024 10:28:13 -0500 Message-ID: <20241127152815.151781-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241127152815.151781-1-cel@kernel.org> References: <20241127152815.151781-1-cel@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E0AD440016 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: un69hux5t9m1wdbtodqa97y6xm75moya X-HE-Tag: 1732721295-911506 X-HE-Meta: U2FsdGVkX1+FcQET/6NCBHkdqCcYhqCbb89I0CO7k28onTRjlxl+1CtolgMlvQsX1sXgi4V14wqNMoA2LysCcZqdsLXupeCf/boIm7QmECdp3wZoiaEH/lOAfgQ402ogcRtj06rfetr6dPFJWCYEpT4UJA1Tr2JMfzZWaw5OKRBcWmzDAMCPUSiYeiUusogR569Qm80m/H2l3Vd3r1hzSPWqJE3cfNBFNVgn6VRpxrQf1/GquZPmDbAN2pU5O04fHwtjf9o5RPJf15mGqJLagdnyfQ0bfXv4oh7PHMAArCXVGHpw5JBZJM/NogIX/Pnst/YSGoGq5/HYSNe8SCF5DHdD9rQN5vdSY7bADQorjEV1rll1GrxaCaP1XSjFy2CVc/5kbD2CeFlostnU92altyXP6dnLuL7c9o4PXtx3jEGD8WK+tR1PDNNpuZdjt59bzlP97XpavcYGUCA2PvuUng2LldyIGVVIRy4VVt4nrgJnwpSte25fKflG0tBCiNyvizT700p9RCGk+z1ka8Z+vWQEwn5q3fZrHaLHNLt4soN6TcxE6DhsTshh199vv9OjCN4iaPb1Mg3PfXVVJHe6GUP23SxUr3uK/JCkIDGSJSvhtQ1ENhnLo8XUhs7ppjxPRBLZgMurlSeJ3JXmZWy6CZ2paJe60Xz+syGobFaUxnu+pKdw3xiqhSJv7nZrDFCUkATwcyONFX/e+bqrETwR3rqvhJenB6PoWmcPf+MXUHKSDg+Dmt0sQRemdMgkltZixPAPKUjlEYNdyD5UXZXJ1dJK5kqgxClzxGUWayDhdM3HYxjWXgm9DDc0BGL2xP5wQVc0jFsOgR9CI4v84Lnb19j+fermfB2CqBUAi1Z9m0a3+UfI8U6ai8bz1pmigAuRx5pdmfSangIQ7dDF+BGdYewDsyoAnf86h6QY8gotcETT25WwKSn22RIKclZQiufkaFg+e/OEbZaxrmTnB6x 6GWA99wh MsQRV/kC3sxWRVI94LNaehJGjzd/bdbC+A0MoC/vcJxrlmHn3fmc9/fMZUTzo2tYCnnYLvsipcuP5T8uBrN8qdzqS2z+aWn5bC/8Gm05BUaarzfcRjh3YTNLzayWoAhh3wtVFJbcWqraEJDEjjY83GAiciZts/T27gqnAk1VMvUP4K/toQ/Em8ErkjKYxkzq3h+1FgqCAlJOtyiC8uozpYr/ns0Dr9zbrYMyKWTEGgdY1/8A= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Chuck Lever Using octx->next_offset to determine the newest entries works only because the offset value range is 63-bits. If an offset were to wrap, existing entries are no longer visible to readdir because offset_readdir() stops listing entries once an entry's offset is larger than octx->next_offset. This fix is effective, but it would be better not to use next_offset at all when iterating a directory. Revert this fix to prepare for replacing the current offset_readdir() mechanism. Reverting also makes it easier to apply the replacement code to v6.6. Signed-off-by: Chuck Lever --- fs/libfs.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index f686336489a3..a673427d3416 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -449,14 +449,6 @@ void simple_offset_destroy(struct offset_ctx *octx) mtree_destroy(&octx->mt); } -static int offset_dir_open(struct inode *inode, struct file *file) -{ - struct offset_ctx *ctx = inode->i_op->get_offset_ctx(inode); - - file->private_data = (void *)ctx->next_offset; - return 0; -} - /** * offset_dir_llseek - Advance the read position of a directory descriptor * @file: an open directory whose position is to be updated @@ -470,9 +462,6 @@ static int offset_dir_open(struct inode *inode, struct file *file) */ static loff_t offset_dir_llseek(struct file *file, loff_t offset, int whence) { - struct inode *inode = file->f_inode; - struct offset_ctx *ctx = inode->i_op->get_offset_ctx(inode); - switch (whence) { case SEEK_CUR: offset += file->f_pos; @@ -486,8 +475,7 @@ static loff_t offset_dir_llseek(struct file *file, loff_t offset, int whence) } /* In this case, ->private_data is protected by f_pos_lock */ - if (!offset) - file->private_data = (void *)ctx->next_offset; + file->private_data = NULL; return vfs_setpos(file, offset, LONG_MAX); } @@ -518,7 +506,7 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) inode->i_ino, fs_umode_to_dtype(inode->i_mode)); } -static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx, long last_index) +static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) { struct offset_ctx *octx = inode->i_op->get_offset_ctx(inode); struct dentry *dentry; @@ -526,21 +514,17 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx, lon while (true) { dentry = offset_find_next(octx, ctx->pos); if (!dentry) - return; - - if (dentry2offset(dentry) >= last_index) { - dput(dentry); - return; - } + return ERR_PTR(-ENOENT); if (!offset_dir_emit(ctx, dentry)) { dput(dentry); - return; + break; } ctx->pos = dentry2offset(dentry) + 1; dput(dentry); } + return NULL; } /** @@ -567,19 +551,22 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx, lon static int offset_readdir(struct file *file, struct dir_context *ctx) { struct dentry *dir = file->f_path.dentry; - long last_index = (long)file->private_data; lockdep_assert_held(&d_inode(dir)->i_rwsem); if (!dir_emit_dots(file, ctx)) return 0; - offset_iterate_dir(d_inode(dir), ctx, last_index); + /* In this case, ->private_data is protected by f_pos_lock */ + if (ctx->pos == DIR_OFFSET_MIN) + file->private_data = NULL; + else if (file->private_data == ERR_PTR(-ENOENT)) + return 0; + file->private_data = offset_iterate_dir(d_inode(dir), ctx); return 0; } const struct file_operations simple_offset_dir_operations = { - .open = offset_dir_open, .llseek = offset_dir_llseek, .iterate_shared = offset_readdir, .read = generic_read_dir,