From mboxrd@z Thu Jan 1 00:00:00 1970 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 CA974E7718B for ; Mon, 23 Dec 2024 14:17:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CB706B00B2; Mon, 23 Dec 2024 09:17:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 47A806B00B3; Mon, 23 Dec 2024 09:17:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 341886B00B4; Mon, 23 Dec 2024 09:17:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 173B46B00B2 for ; Mon, 23 Dec 2024 09:17:34 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 795A980E1E for ; Mon, 23 Dec 2024 14:17:33 +0000 (UTC) X-FDA: 82926425022.19.96AFFF3 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 458A61A001B for ; Mon, 23 Dec 2024 14:16:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of yangerkun@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yangerkun@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734963434; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tkJC8JWUfK0DRQl6sixPSBVZrdOzBouUb2EUjdcGY+U=; b=KLDkx1PanEwVjPKchHEASElv5Obo+bBOV+MGcbQTxBa6lrp0/ZXezPSYtkCSbywhEPLxpj 2yXJ7my5sx7ARbYAW0CpBf8/gwoayHbQvGyvwk1JXld2SVXqhL+r8MzRT4LUHfrYUGVgRE LWKBqsDTk39Ielaid/PifRgeJjviNdk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of yangerkun@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yangerkun@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734963434; a=rsa-sha256; cv=none; b=hAHWrlCoDv+2wyNkTVU0zzm1czUjwYg7fvobjy3vLkged46uvhov+uRNmNg9a3hF0NWios BTHiYXH6KUNi3iaVT0JQX7ItGpsK7W8M5dyJARIHNvc/H4ZcJme8fNJVPMY0Cd36tcqz2l XaHWJivOWbc1O5VIjeH5n2aOI82YrVo= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4YH0TD6ypcz4f3lg7 for ; Mon, 23 Dec 2024 22:17:04 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id B05CB1A018C for ; Mon, 23 Dec 2024 22:17:25 +0800 (CST) Received: from [10.174.177.210] (unknown [10.174.177.210]) by APP4 (Coremail) with SMTP id gCh0CgDnwob0cGlnHfuuFQ--.13616S3; Mon, 23 Dec 2024 22:17:25 +0800 (CST) Message-ID: Date: Mon, 23 Dec 2024 22:17:24 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v6 3/5] Revert "libfs: fix infinite directory reads for offset dir" To: cel@kernel.org, Hugh Dickins , Christian Brauner , Al Viro Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, yukuai3@huawei.com, Chuck Lever References: <20241220153314.5237-1-cel@kernel.org> <20241220153314.5237-4-cel@kernel.org> From: yangerkun In-Reply-To: <20241220153314.5237-4-cel@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:gCh0CgDnwob0cGlnHfuuFQ--.13616S3 X-Coremail-Antispam: 1UD129KBjvJXoW3Xr1kKw4Utw1rWF15Jr1DWrg_yoW7XF13pF ZxG3W3Kr4fX34jkF4vvF4DZr1F93Z3KF4UWr1ru345Ar9Iq398Kas2yr1qka4UJrZ5Cr1S qF45Kr13Zw4DCrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvjb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2xFo4CEbIxvr21lc7CjxVAaw2AF wI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43 MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWU JVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUot CzDUUUU X-CM-SenderInfo: 51dqwvhunx0q5kxd4v5lfo033gof0z/ X-Rspamd-Queue-Id: 458A61A001B X-Stat-Signature: kxapz5w5s5gio5obwb7ksiuhgg5dapox X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734963410-25776 X-HE-Meta: U2FsdGVkX18anuL8+bbksjDZgZkozxujyy8NdN2FAb2+z7UJiiYAc0xW3k1v1APOcCawh5FEzV95VduESMSBu/dgiCreSuwwpOX7qHuauk/4HU/fBzzbsLp5X0I8jVaW0br6XhoFZ1Ww6vQsbT0TybAGl2QHnFre9OqoSMYEfQRm981Aud+akOu65IdUKT90K8CHMk/ANGazAlQ+MHrks9amlGZ9bhajdftiC1a6mUKkOeT6pUuOeriHCM7+cxph5B7UUR4QHocHZ0STwzXNBSR8/iYVYzrsuxApgByJpbtyw3xHh0poyski9KS8zEX1P4ZKidD3RWv/E7pgSlWdGLrv03l80pz/K1Fo4N9x1ZmPb49REtu1iScwSXu/2fJXsnG8W54QstiHEu60flnvJ8XQX/PhnAbKuf1bmJ5s688lF5+4bhrvCighf1h8xqnMhyoKbsLsu3FqKjfH6S1/HdjS9IaggSirsDvaqVEoxvQw5YLV4tAGTscj41iMG6z3rQ1AckITuUfExAtetzz3ajjCY1twLdxJouvTnZH0gdvcAVS7sZuGw0V/ZgOPC9qhu82IfeCHYd6/FzDF6BuO11vXgWGwzm6SDukjSxOSRfw1Axz+Rbgz9RAqddoyKIJUHvi/vEINzkF7XgPZEcabUwHHAjIsnCuzzBSbCqyzooprMKqW6DBSsV6rsxsFmwLqBHxuAs+HERLnGuo2zj+R+IjV9LN/K4abI/3RqaD7JbrnoLEGJjiLiLucDGbiINOBNnaZWSuq0uwLOLi9GXu69eu6e0l6Q8s0ftHYmZb8YHuXtuNssdfj28jHPBzrx1qi4HRIBDNVRYgQMD6Zkaux9vB1mZZeEx6g8AZFId6P3RIexNQJXVdW4w/+2X4cvNvv+2VV7Zg3/iVLRkZypxJWZyep2KjeDt5uWNVyFtIlZAxK1TwUGxVpKtOSuYrnxHxvV66fYhE3sRPy/bD/4wR miXjHL1q kh0Q+EMKfpseUDGwk+RaLoJw4g0LgWef3cHWj30cS+9t81kPD+EqtbkfEGAN612bC6CPrCRBYhxLjyprA3JFi4wWksubEYeUSiNp/cvh2wXdTfKa9UcbiQAGER6XeWh1oqI3aXIsuGa38rz3ut/DaQlhX+l9m3bCLQl2neNvALiAu4lAzRJjmI9sGKw8s5aOfRG5uDRKFd/hqOCKfNeDBS7n3kQ== 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: LGTM Reviewed-by: Yang Erkun 在 2024/12/20 23:33, cel@kernel.org 写道: > From: Chuck Lever > > The current directory offset allocator (based on mtree_alloc_cyclic) > stores the next offset value to return in octx->next_offset. This > mechanism typically returns values that increase monotonically over > time. Eventually, though, the newly allocated offset value wraps > back to a low number (say, 2) which is smaller than other already- > allocated offset values. > > Yu Kuai reports that, after commit 64a7ce76fb90 > ("libfs: fix infinite directory reads for offset dir"), if a > directory's offset allocator wraps, existing entries are no longer > visible via readdir/getdents because offset_readdir() stops listing > entries once an entry's offset is larger than octx->next_offset. > These entries vanish persistently -- they can be looked up, but will > never again appear in readdir(3) output. > > The reason for this is that the commit treats directory offsets as > monotonically increasing integer values rather than opaque cookies, > and introduces this comparison: > > if (dentry2offset(dentry) >= last_index) { > > On 64-bit platforms, the directory offset value upper bound is > 2^63 - 1. Directory offsets will monotonically increase for millions > of years without wrapping. > > On 32-bit platforms, however, LONG_MAX is 2^31 - 1. The allocator > can wrap after only a few weeks (at worst). > > Revert commit 64a7ce76fb90 ("libfs: fix infinite directory reads for > offset dir") to prepare for a fix that can work properly on 32-bit > systems and might apply to recent LTS kernels where shmem employs > the simple_offset mechanism. > > Reported-by: Yu Kuai > 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 8380d9314ebd..8c9364a0174c 100644 > --- a/fs/libfs.c > +++ b/fs/libfs.c > @@ -422,14 +422,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 > @@ -443,9 +435,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; > @@ -459,8 +448,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); > } > > @@ -491,7 +479,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; > @@ -499,21 +487,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; > } > > /** > @@ -540,19 +524,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,