From patchwork Mon Nov 11 00:52:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13870101 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 AA771D12D5F for ; Mon, 11 Nov 2024 00:53:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B6BC6B0082; Sun, 10 Nov 2024 19:53:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 28E106B0083; Sun, 10 Nov 2024 19:53:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 107F26B0088; Sun, 10 Nov 2024 19:53:09 -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 EA4686B0082 for ; Sun, 10 Nov 2024 19:53:08 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9E8DC4160F for ; Mon, 11 Nov 2024 00:53:08 +0000 (UTC) X-FDA: 82771988922.12.3D153AA Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf30.hostedemail.com (Postfix) with ESMTP id E05BA80010 for ; Mon, 11 Nov 2024 00:51:51 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AUp9e8+0; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of cel@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731286300; 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=X302ZFW4KINxz4atSW2PZU6LnfpzBp/noFGMl3ltNWw=; b=r+Rlj/SKk6k9Qe/fbbS4eQSMsFBF03Gp/0i1kFTItV5zKwB/7XMVcqCGo2gejjOR0Tk8D8 i298sr30/cBjvVgvpdgu0ieSInAKrP2Ouwm7A7kphZtDv7emWjBcHDyiQ3CRp6yFK6caaH /g98ybsIRPqJbmmczz6N9sBfVKW7hb8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AUp9e8+0; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of cel@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731286300; a=rsa-sha256; cv=none; b=a9lJHOAI3WJ65BnWsX5roFVzIYnD4GAJHLqGPXC06YpQa9SkkD1bhmv+kq1zpFXCbMIZCq vPGkvVMiuvAP8/2Gl9QEshFuXt0yb551v24JsUxHYs8+93KVwdWptVuhXPkvx5exAEa2dA ZVqQ8XsWizSnC3eC8T9HC3b1L9fD2WA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id DF9C0A4136B; Mon, 11 Nov 2024 00:51:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F118C4CED7; Mon, 11 Nov 2024 00:53:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731286386; bh=MS0L+/cj/qetOL2B467nUPcahNS75vbYcTKvMHCfQKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AUp9e8+0TpoPzUlfgwTw5E6GgnI/ZpYgc1q76uXOC/+G/BieWoMPdjZEB9lyIDrgW QXnLpnLmlQr9H3pU3uuH6bLkqEMMVOzHhdcMtSSAL9OpMLf+1hUWeWgQj8DDTUrsi4 HPlMJt1byI0ysarlcYcYt43gIZmtHoAEgpzJNUNIjlag6m8EPrbqQPCcjGC4n4l4w2 acEdEsqQ12dH+mxNQZwEssa6U3KD3BDs3TcnGaplZbXr6RuqnTPuBDN0JgoZRBikUj McYBLgOQhdkImalQc+aABZ2RlO+V6EjfcIX2x8OD/WW8qej8jqF0AvLODayl32j4Dz IQXG8dMnfIgqA== From: cel@kernel.org To: Cc: yukuai1@huaweicloud.com, harry.wentland@amd.com, sunpeng.li@amd.com, Rodrigo.Siqueira@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, viro@zeniv.linux.org.uk, brauner@kernel.org, Liam.Howlett@oracle.com, akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, gregkh@linuxfoundation.org, sashal@kernel.org, srinivasan.shanmugam@amd.com, chiahsuan.chung@amd.com, mingo@kernel.org, mgorman@techsingularity.net, yukuai3@huawei.com, chengming.zhou@linux.dev, zhangpeng.00@bytedance.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, , linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, yi.zhang@huawei.com, yangerkun@huawei.com, Chuck Lever , Jan Kara Subject: [RFC PATCH 1/6 6.6] libfs: Define a minimum directory offset Date: Sun, 10 Nov 2024 19:52:37 -0500 Message-ID: <20241111005242.34654-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111005242.34654-1-cel@kernel.org> References: <20241111005242.34654-1-cel@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E05BA80010 X-Stat-Signature: nh4udifjnzbtbsqcg6pfgsxxsi9zodc5 X-HE-Tag: 1731286311-108152 X-HE-Meta: U2FsdGVkX19ha936cZjtDA+4/hnxzYfsRPKKd2qY64chPi24xR0ZGkDhF1r7Dh+NbyVOTRpxzuWmuAae6qgfos/1UFAJX5ti5pXnkEgoKyBP7j0R/MlDtx/6ZI3O3aRA6uXlc9SO8S2oS+ttmuMNjDKRo8agrkwuDc4b88fnqQp9GhgDLXDs4wgIg+KNhbA6eMTnQh51gEO7nBbAcJIZFR1twZRIc5KJA+TYiqyHUVoEMeEZNOSeC5ctfFCWBnX30idmOlbzzDHY9gjIGOKstisaMdzr0iDmtVW3fmbTeyFe7MtHKLC9gnb5aQ1y/8PuQkL0tNInTvg2JYC/IKqnmAz10WnaJNlGIW37NAlRvImUNhRP7zpkDZMOSmox5LX/ophld9nUjcPpLaR8B8AZa+rrnpk63FmOPNXV2RGlsM7PdDAmry73icj/Ztbe1NAx6rlAuuPJXFMb5CNw9l739Y/T4jSlFqCcKe209YVsy8RHN4yL4HsgNmS7nO4Oql8VpTAcHVgHULhupTwgGuMzkMxekQtlpqW+CdQ7UR98h1rDZ9pgrJEY31SV3lHiSeVTklvosO57eyv4Hhnohi02nTC5jydvORQnnmHPpg6gsIrtW0Co5um3Y4CtZdxtKKLrscShJNV57j42SWEuyXQAuq7gV3vVuMYN6SNU5SHfxZKE3CTQ4E7YUN8iah9aQwsjEENQ1Sc+fe1HZw8V1DHeb3KN3ED29MHwSyKa7IXlF9EAHDM0X/5hmro62DVS1ZNUnEtB0VSajq/6a+/1TYB7PNNHB+EmM3JX0691wVbjUPdLMCf9GYXrHCWowFKfTgEMR2b8+0eETABoQMXNGz4OMK/zddAny4s9G732NWhvvItjLkhw3zvimB9oDVlrAwmEllUjCUcrFLGDEasv3z6A/4q7EkhbZwkc12J2TfYltd/gZsErmksKJqYZ5Mkp+bHArcGbIO2J50qyYhuqDqq OMMbrspz 7W6epoCVg9YgB0Orh7csqG0fC3f09/tz3OsoCOpy3m/HPVObPXYHebQHuGcAenVQP5mmTAetXHJxMnEH6hvwwh773Suu0uyloMPZ6csSq73GcmzwgDfa5rjKJ1V4DqT50SMN6oz/pptONXMOsuNKERSRgx2LZcFO7BPOGSeLyBH2djM5OYd3NopLOC8fRphMwvm2xo+i14Gc3cPeKtgtyG+5hW22G1JyCw3fqX8Hdx4uXNNpaZl3QO+Ji4b9l0FXQ0LHvfSOH8EDInodFK0R1VwHnTg== 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 [ Upstream commit 7beea725a8ca412c6190090ce7c3a13b169592a1 ] This value is used in several places, so make it a symbolic constant. Reviewed-by: Jan Kara Signed-off-by: Chuck Lever Link: https://lore.kernel.org/r/170820142741.6328.12428356024575347885.stgit@91.116.238.104.host.secureserver.net Signed-off-by: Christian Brauner Stable-dep-of: ecba88a3b32d ("libfs: Add simple_offset_empty()") Signed-off-by: Chuck Lever --- fs/libfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index dc0f7519045f..4a2205afcc88 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -239,6 +239,11 @@ const struct inode_operations simple_dir_inode_operations = { }; EXPORT_SYMBOL(simple_dir_inode_operations); +/* 0 is '.', 1 is '..', so always start with offset 2 or more */ +enum { + DIR_OFFSET_MIN = 2, +}; + static void offset_set(struct dentry *dentry, u32 offset) { dentry->d_fsdata = (void *)((uintptr_t)(offset)); @@ -260,9 +265,7 @@ void simple_offset_init(struct offset_ctx *octx) { xa_init_flags(&octx->xa, XA_FLAGS_ALLOC1); lockdep_set_class(&octx->xa.xa_lock, &simple_offset_xa_lock); - - /* 0 is '.', 1 is '..', so always start with offset 2 */ - octx->next_offset = 2; + octx->next_offset = DIR_OFFSET_MIN; } /** @@ -275,7 +278,7 @@ void simple_offset_init(struct offset_ctx *octx) */ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) { - static const struct xa_limit limit = XA_LIMIT(2, U32_MAX); + static const struct xa_limit limit = XA_LIMIT(DIR_OFFSET_MIN, U32_MAX); u32 offset; int ret; @@ -480,7 +483,7 @@ static int offset_readdir(struct file *file, struct dir_context *ctx) return 0; /* In this case, ->private_data is protected by f_pos_lock */ - if (ctx->pos == 2) + if (ctx->pos == DIR_OFFSET_MIN) file->private_data = NULL; else if (file->private_data == ERR_PTR(-ENOENT)) return 0; From patchwork Mon Nov 11 00:52:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13870102 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 A18D6D12D5C for ; Mon, 11 Nov 2024 00:53:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17EBB6B0089; Sun, 10 Nov 2024 19:53:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12E6A6B008A; Sun, 10 Nov 2024 19:53:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F12EA6B008C; Sun, 10 Nov 2024 19:53:12 -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 D20EC6B0089 for ; Sun, 10 Nov 2024 19:53:12 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9821D1215D7 for ; Mon, 11 Nov 2024 00:53:12 +0000 (UTC) X-FDA: 82771989510.11.2BC5EDE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id 3AC0A140007 for ; Mon, 11 Nov 2024 00:52:43 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lrf5VPIU; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731286216; a=rsa-sha256; cv=none; b=LXLoQDO27sOSecQ1FaERIs1lC3oOjsMH9vHVEv9J5VJSOkQQALNBbtr3xfD2Gm9XWafddc 8SGo/xt5TJLv1PnCGRb6LznI8xbDdyiuWsDqxeG4oZLfvJsmiA8chKSKgIIrxtlH4MMH4L xjld0UsPMV2PSvAyHej+kH7A2UGUnK8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lrf5VPIU; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731286216; 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=rtXzJ+fV4vyb9qvnzLh43ryjIhUuQz7njmNubhr4nPg=; b=rJ56eare/5QQJ0018rCmLaf0L8a+y4K28wfDMcb5/P+iyszrozXC9K/QtB2s4s0UdJZ9nE 4G7qdUPZNAFNaLuNDsINIWXFz6aDefx4C5ez4bOMXlzxJOHmhGnMyxfEBsx7MJwQOXnzWW NOseDkcg/7EAq5jpaqc73Xu5hYVw0B8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 195BC5C54AC; Mon, 11 Nov 2024 00:52:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DB9AC4CED6; Mon, 11 Nov 2024 00:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731286389; bh=Z1QVcRNEajq+vvtRp+aYnLkCErRyzdCuKYY5Gom358E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lrf5VPIUItWcKVtrlMjZyA9tq+5oyRSxI+GpQOE4It5Fkefwo9OvtC99jBNEAmCVO /jB3FJ1h0OrzKq6rZO3CvgotIAATbQ1c7zaXUesKHVANqRnZE9aExWhcKF+HJdRfqq MNH2HDC3jfuxXoHT70TnTXw+m5EgHdVIBRTGI7dExUKfhaJ05nDo6wczsw8sN1zN14 TUhUQr6YbDOedUUN5JyHBYo9kG/GVPCJxeamWdtcbATWWySK/aYoAEpy4N2wB0dL0k OXj7FNKqa1bAF+RgA2Jbro7kxneUAYLDi/Yrho3dK67Th8fBM5ZuogzGch/WAvDoeC vlrZ/CgdO2Wjw== From: cel@kernel.org To: Cc: yukuai1@huaweicloud.com, harry.wentland@amd.com, sunpeng.li@amd.com, Rodrigo.Siqueira@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, viro@zeniv.linux.org.uk, brauner@kernel.org, Liam.Howlett@oracle.com, akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, gregkh@linuxfoundation.org, sashal@kernel.org, srinivasan.shanmugam@amd.com, chiahsuan.chung@amd.com, mingo@kernel.org, mgorman@techsingularity.net, yukuai3@huawei.com, chengming.zhou@linux.dev, zhangpeng.00@bytedance.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, , linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, yi.zhang@huawei.com, yangerkun@huawei.com, Chuck Lever , Jan Kara Subject: [RFC PATCH 2/6 6.6] libfs: Add simple_offset_empty() Date: Sun, 10 Nov 2024 19:52:38 -0500 Message-ID: <20241111005242.34654-3-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111005242.34654-1-cel@kernel.org> References: <20241111005242.34654-1-cel@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 6piiuj468frd93mmy9q15fcctsqtekoq X-Rspamd-Queue-Id: 3AC0A140007 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731286363-229510 X-HE-Meta: U2FsdGVkX1/hz3StQWXYWNIys5UzBGFAXtYKvQQ3NUTfQ873OChHTevIKmjNq8XSx1MFdmNW9/evU7dBaLb+JEOARI1FMKY8GQ1S3BdyBNwZ/6L4R4lHdQFHjI/sEzirvqHW8QTm/rqegUcBXeC3tCLxZg2Fb3G/5Gu6Xr4bbtrvPUK6pw8L2yrkq2ZcMJAiPwRmWtdOwUU4ir1Q4j/MO7fuMIjg/jgXUN3Lq5f/BCjhfoGQ+K+Y4/9UVj5+4EgtDBxIJsdqu6tBHbR2k+Nfya/BnR6ON3lkRgk9wTnGrqPIWIMHL1KNL+kCy704i13h1ASB/my//0gfoQzvV6rH+E+0yn1WBk2Vc51Yr/Q1eaqXnxfmq0wnfCzBHge/mD85bbPNELkZAaUd5Ne+cZmluGd1yeeu4pPrlT2B0CBxdfMpi+usjxu3OZtj/JUiI3rviVJhSZHJExWtwypHempaKpeDgPZ7ZtCGHBffr9HqxcMstcsSrKPY3GHTM1pn8wW/AmSvN0iVRUT33f2MuVvzMxy9/nwF1SzmrEJ5WmKFxKGXKf+yIbVAP/Xw4bBCFeiWH7JxWQetBrHtEwyuOC/2/LXYrwnuxQ243iRjK0kPvXlyL0aP7mEeMzI5gPwWmHhvKuKBOpf2TgHNH2lqOvpU/qEswdZRDs6c3J/R6ro+1Q9fk3vPrOIOw/2QM2bVjKK4E0ZMk9QDTljQagYChJa6a4Ur3K+o6Eey1LpIQWOcyzfvXW3AwJw6x0wHGasGTO+0LRQ3xs00eqi5zpS+AKZo8Al0z5tTOtXvI6SX2gOko9Oz11N7zdrypwtp6RIP4AKFM7z4Rm5SbOMj2p6jck3IQf66+6F6fuMzbvjVxy2uWIRBTRiCHVqzWBHfmGOAsjgcoFyaosxnQyc359B4WxkfdBxDl/boGmrBGKgh9hH7j6fcHeKL1nDticCll+gddopjwF8NH7FOsme5WTSYQe1 o14uY1zD jgyZvA+WiE0EntYWMfptK4GXG0XtHcHFqCZ5FEuaoRPt1LXkzDF5NDSue+F87PNeB56erQhoa6uFXf9rZ5fiP3XErT2IWSApKfCet85MQSy4Z2R/6iRDUvaVaFt0xYppc/E6XzZWr0kVMXFhW6DpgC1zLytfpY2ttyfHH7UCk4Q4ltZUUj2c1Z/EPNk4n+YvLyrkjES6JukpAHERzy6KfYSJmchndG6bB8jgCvpo74eE2Ntz3ECUWxQXB33YlkC6bzhNl70Bji2g2i0Z/3FwfMCpoxAz4XsjDfQk9zNZHxr/9XqQj5BSsEOVuBgl99zvRWugFYOgkdmnSP9Q= 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 [ Upstream commit ecba88a3b32d733d41e27973e25b2bc580f64281 ] For simple filesystems that use directory offset mapping, rely strictly on the directory offset map to tell when a directory has no children. After this patch is applied, the emptiness test holds only the RCU read lock when the directory being tested has no children. In addition, this adds another layer of confirmation that simple_offset_add/remove() are working as expected. Reviewed-by: Jan Kara Signed-off-by: Chuck Lever Link: https://lore.kernel.org/r/170820143463.6328.7872919188371286951.stgit@91.116.238.104.host.secureserver.net Signed-off-by: Christian Brauner Stable-dep-of: 5a1a25be995e ("libfs: Add simple_offset_rename() API") Signed-off-by: Chuck Lever --- fs/libfs.c | 32 ++++++++++++++++++++++++++++++++ include/linux/fs.h | 1 + mm/shmem.c | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 4a2205afcc88..66b428f3fc41 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -312,6 +312,38 @@ void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry) offset_set(dentry, 0); } +/** + * simple_offset_empty - Check if a dentry can be unlinked + * @dentry: dentry to be tested + * + * Returns 0 if @dentry is a non-empty directory; otherwise returns 1. + */ +int simple_offset_empty(struct dentry *dentry) +{ + struct inode *inode = d_inode(dentry); + struct offset_ctx *octx; + struct dentry *child; + unsigned long index; + int ret = 1; + + if (!inode || !S_ISDIR(inode->i_mode)) + return ret; + + index = DIR_OFFSET_MIN; + octx = inode->i_op->get_offset_ctx(inode); + xa_for_each(&octx->xa, index, child) { + spin_lock(&child->d_lock); + if (simple_positive(child)) { + spin_unlock(&child->d_lock); + ret = 0; + break; + } + spin_unlock(&child->d_lock); + } + + return ret; +} + /** * simple_offset_rename_exchange - exchange rename with directory offsets * @old_dir: parent of dentry being moved diff --git a/include/linux/fs.h b/include/linux/fs.h index 6c3d86532e3f..5104405ce3e6 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3197,6 +3197,7 @@ struct offset_ctx { void simple_offset_init(struct offset_ctx *octx); int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry); void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry); +int simple_offset_empty(struct dentry *dentry); int simple_offset_rename_exchange(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, diff --git a/mm/shmem.c b/mm/shmem.c index 5d076022da24..e0d014eaaf73 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3373,7 +3373,7 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry) static int shmem_rmdir(struct inode *dir, struct dentry *dentry) { - if (!simple_empty(dentry)) + if (!simple_offset_empty(dentry)) return -ENOTEMPTY; drop_nlink(d_inode(dentry)); @@ -3430,7 +3430,7 @@ static int shmem_rename2(struct mnt_idmap *idmap, return simple_offset_rename_exchange(old_dir, old_dentry, new_dir, new_dentry); - if (!simple_empty(new_dentry)) + if (!simple_offset_empty(new_dentry)) return -ENOTEMPTY; if (flags & RENAME_WHITEOUT) { From patchwork Mon Nov 11 00:52:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13870103 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 44691D12D5C for ; Mon, 11 Nov 2024 00:53:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91FDD6B008A; Sun, 10 Nov 2024 19:53:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A9BF6B008C; Sun, 10 Nov 2024 19:53:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 747FE6B0092; Sun, 10 Nov 2024 19:53:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 580016B008A for ; Sun, 10 Nov 2024 19:53:15 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C40831C74C0 for ; Mon, 11 Nov 2024 00:53:14 +0000 (UTC) X-FDA: 82771989132.22.BE45569 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id 60A7EA000B for ; Mon, 11 Nov 2024 00:52:44 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LntlDsRP; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731286265; a=rsa-sha256; cv=none; b=MxICdAqnA/ODjEPoPC5u3rqY+YjfR+XW+QIgTHHgZwHmeF7GCJwhXjZkPJ1nOnrn9MTUDt D0uHdFuH7zFdLpJYUvT5kcAsyh79SsUQjMEADK/qDMZRzLvXJ2bgPQSIy9LNF8wRV2L306 nw4DGWq7i7xX0N+kDbcwBSHvGWhyEk8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LntlDsRP; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731286265; 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=G7qMnJXlMqB7qZE88pzAQRUnDuB0HpujX7yANaFKMZ8=; b=7l2aeUNug0Vmdum+Qe88hBQQy/q3OdPN5uX996qXuIjmC62zf0SW2H0VJwWF0Fn0ZFL5rU CV02fD9CdBJsVfXkwHP3Rf7/EsYZidTbjd9FIGvQBPECvzf+uW085D/xHrLrTKNwcGIiQY nDFnnDQJB88OjW3vLo+Lj4zu29QylC4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D06775C5557; Mon, 11 Nov 2024 00:52:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4692DC4CEDE; Mon, 11 Nov 2024 00:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731286392; bh=Vg2de2ueiLqplD9ZUkL2WjK6PFXZnIvvP0PrhnulG7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LntlDsRPAJVpLflvo1J+MXbwR9kHtrH49Fl7QV0sUfTujzgZAVo2GYq05/qBcrED2 P5+FBtYtnXmvVoS67me6BmpKITcP96pPQOruzlaNuNYbgLNcdLbK8+uQoJk2yU52fe 3DPfqjPHYI5YACZNC9kwdfTOKkl50NK+YlzDP8pnBPZhCBFyXCgc92DjRrFVmAPVFl P9D1yn//N2jB4mFzzusmaQPzfUhK6ZC0Uw8/KeJcqJd2o2bQ/ukM4eVg7Or+Ek0SLF Ns9L2mmyGiq8vMHRYfUN8SiJfeLdspLvac8GWEATs2hz6s/fh3Jn/WBOYm5zRNJEGe iLRbh88kvIh8Q== From: cel@kernel.org To: Cc: yukuai1@huaweicloud.com, harry.wentland@amd.com, sunpeng.li@amd.com, Rodrigo.Siqueira@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, viro@zeniv.linux.org.uk, brauner@kernel.org, Liam.Howlett@oracle.com, akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, gregkh@linuxfoundation.org, sashal@kernel.org, srinivasan.shanmugam@amd.com, chiahsuan.chung@amd.com, mingo@kernel.org, mgorman@techsingularity.net, yukuai3@huawei.com, chengming.zhou@linux.dev, zhangpeng.00@bytedance.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, , linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, yi.zhang@huawei.com, yangerkun@huawei.com, Chuck Lever Subject: [RFC PATCH 3/6 6.6] libfs: Fix simple_offset_rename_exchange() Date: Sun, 10 Nov 2024 19:52:39 -0500 Message-ID: <20241111005242.34654-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111005242.34654-1-cel@kernel.org> References: <20241111005242.34654-1-cel@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 60A7EA000B X-Stat-Signature: sbioc8yen4bp77kinf6a5cznjyuezr8i X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731286364-733532 X-HE-Meta: U2FsdGVkX18UScKRjiurfycA3QfcqphN43Zfc91eNwREnHNFo912eskjBdqYvpCDijwg+jskfpjWUi9SVMCx+gNmn817dxMwv2f+/otQmsf9XhuHlFj62RDe1Hf1PZ/wiqErJq+jNdeZCy6J6O26OC7MslfiDBMQvx6sLdSz0F3ZZPFZlTfxSoeG11Ij/5HFbi3IsKGKEoqE/VKDeGBQNaqVjQYIjhVPfzFAAsTGtxO4vxIBn4Nu3e0gkkaYUGemFiireYvB0W3O/X3dHm/dim7Vkz6njSmoseT1yEMPO+lsz7GjuyIRx02UteWUtyyJRV2eSWx8nPHxiwv+jwAGNxPLpctwD3XCNKamEq3SX1+IYeYSkADiEQx/Y1tmrcgbBk1jlRb2D0tm1IOkpKCBtn4caVJk2f6OeBBDmMoroDQMatvl3kI2rmrBCavIKl9TCqyKUULW7qb57affS6adsDa9h+gvl7VpuCHJP6ZIhXNfO8tFEeR+y5GHrxIGAFEr33nyFRi0VyM3Yi9bM/UYVl6Xq0/P/CtCLIMUbxpUyZqvcSpwdyN0Lsuds9KgJiHqHTPUrgHQDQWEy97L/t//rTtexeW+X/Ntj+XIJ2AY4XWoWzPXLx0s6WO8NfXDpt4rtKtRUPM5vObft5Ub1lE6Gi+CQ971f7u50yebYIFqstT02twhDo5wJJDa4SeBWL+1wsKKfUUf//EEgFl08WkAAAu6Y9YR9R6wc7lMSLH8QtrtJ80mKT/74oaGlvXuU+a7Z9LKm7MBvjc/YyMCPeQmK4VLMeXJ78jlRMMeGQz8F09TTXGBMhVLntPRwuRXBoCaO70jeetmVhJYDgToTlWsdqzPaJE4kcCvmzBhk4ZSaAZkDTai3G3xV0AnQCWR0YTp2wbX/4Yf/QsXMS1QbISrxrjjZg5TVU9m1sGu7u28pjiDwPkxbOEh/vT7JBU6JtpGWw3wHuskTfqaOwCoYAX h56m1zk5 mqJ7TX6C26gZtImY35HVCjpGA55MQGC3kzqn1/xUkudr+/9PiMPMaxrbbNkweW0hvK+NOEvqIa8yIxylwVZSY61JsDGRjvTNDb0dAKF/+upsH19XN+ZvPUXlEcZu0O7pXR0ikrCfkn29JYi+YBGffK4X74WjBorfMa6Z8UU3VWo+zhghnRG1qn1n9WCUutkx9oopoHMg6IptYiRFQrBsWgx1x9zHXyDkwFIQHHhHZ+mvQmZlsBTZnB/PkatHJQ14JExdbpIblKo7TvfEEEo2XcpUhjxp55yuN7pSbDyuc7qTmjSsLooUZ0aT39g== 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 [ Upstream commit 23cdd0eed3f1fff3af323092b0b88945a7950d8e ] User space expects the replacement (old) directory entry to have the same directory offset after the rename. Suggested-by: Christian Brauner Fixes: a2e459555c5f ("shmem: stable directory offsets") Signed-off-by: Chuck Lever Link: https://lore.kernel.org/r/20240415152057.4605-2-cel@kernel.org Signed-off-by: Christian Brauner [ cel: adjusted to apply to origin/linux-6.6.y ] Signed-off-by: Chuck Lever --- fs/libfs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 66b428f3fc41..9fec0113a83f 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -294,6 +294,18 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) return 0; } +static int simple_offset_replace(struct offset_ctx *octx, struct dentry *dentry, + u32 offset) +{ + void *ret; + + ret = xa_store(&octx->xa, offset, dentry, GFP_KERNEL); + if (xa_is_err(ret)) + return xa_err(ret); + offset_set(dentry, offset); + return 0; +} + /** * simple_offset_remove - Remove an entry to a directory's offset map * @octx: directory offset ctx to be updated @@ -351,6 +363,9 @@ int simple_offset_empty(struct dentry *dentry) * @new_dir: destination parent * @new_dentry: destination dentry * + * This API preserves the directory offset values. Caller provides + * appropriate serialization. + * * Returns zero on success. Otherwise a negative errno is returned and the * rename is rolled back. */ @@ -368,11 +383,11 @@ int simple_offset_rename_exchange(struct inode *old_dir, simple_offset_remove(old_ctx, old_dentry); simple_offset_remove(new_ctx, new_dentry); - ret = simple_offset_add(new_ctx, old_dentry); + ret = simple_offset_replace(new_ctx, old_dentry, new_index); if (ret) goto out_restore; - ret = simple_offset_add(old_ctx, new_dentry); + ret = simple_offset_replace(old_ctx, new_dentry, old_index); if (ret) { simple_offset_remove(new_ctx, old_dentry); goto out_restore; @@ -387,10 +402,8 @@ int simple_offset_rename_exchange(struct inode *old_dir, return 0; out_restore: - offset_set(old_dentry, old_index); - xa_store(&old_ctx->xa, old_index, old_dentry, GFP_KERNEL); - offset_set(new_dentry, new_index); - xa_store(&new_ctx->xa, new_index, new_dentry, GFP_KERNEL); + (void)simple_offset_replace(old_ctx, old_dentry, old_index); + (void)simple_offset_replace(new_ctx, new_dentry, new_index); return ret; } From patchwork Mon Nov 11 00:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13870104 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 9D381D12D5E for ; Mon, 11 Nov 2024 00:53:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21A9B6B0093; Sun, 10 Nov 2024 19:53:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CB236B0095; Sun, 10 Nov 2024 19:53:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 094536B0096; Sun, 10 Nov 2024 19:53:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D50FE6B0093 for ; Sun, 10 Nov 2024 19:53:17 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 93C3F141570 for ; Mon, 11 Nov 2024 00:53:17 +0000 (UTC) X-FDA: 82771988922.06.047FB2D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 4364A40011 for ; Mon, 11 Nov 2024 00:52:25 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=k543p4gD; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731286334; a=rsa-sha256; cv=none; b=pdCVbI3OZeStbjaZylqnySkJavhLcs2Xcj+cHf/2RRU4mOROMoWF66j2IR5SS4gWz8CB7i G5BAGgb3H2C9gK/J08B70NCuO9J5418yInnMjbzYWLKEuRjlBygqVyRFMDCoh5Ug5hAXhI 4RbxRnLhNxKNOuIj6gyf8QOE1oBWOys= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=k543p4gD; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731286334; 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=XWmvozTdER7+V3ReRar0B4FYLyqi7haHvU5MN0JybOA=; b=BsfiHMwiFVtez0t1395REjlIKnDF5BxjaywXfO/cOJdDXTYMiAsb1tuiecw9hwRViRUloI m8TUkZCTk73jmSFJqSpg5kCAyPguJp7i8wmlFTFWjedRZK/OqhTxURTRj7rpwmRL/azdr4 lxzFvameeRgU6XXMq62zkPACRUdvJc8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AE6085C559E; Mon, 11 Nov 2024 00:52:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40C69C4CECF; Mon, 11 Nov 2024 00:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731286395; bh=cheGtrVFrxMD7UddlqYcWxRXeXiTalHU/TXmpLwYnLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k543p4gDIbH3NkLzJj34S7bHS+uDbygpE9kcK4a1Xs0xXeZFpl2+fmEcRbCDJjgPI pyeK/2NKMa0aXKDhYbuVz3JAdY2c8fikvdu2u41e+3O4y8p/P9PWNiEJySxlBUQtLR z46MtAPrxrvHJ0j79ygGb1jmpzBjXRcKUJ5ij0VAIdyoUEKI4ix6HsSnY8b08x3ddY 3FZ3A6Pl4ZlKJYwSLsQZdeeu7HJikjHV0uhXQYpoWLJGq2xJBzPQUbp+dqiqt7owQ4 kTp65YdpznYFFeUoSAIAWP/dH5jBTMuTH6VGjxyKEhBKkA0emLcsBvajMX5qYhWJJr bzSDRjvAtsXQg== From: cel@kernel.org To: Cc: yukuai1@huaweicloud.com, harry.wentland@amd.com, sunpeng.li@amd.com, Rodrigo.Siqueira@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, viro@zeniv.linux.org.uk, brauner@kernel.org, Liam.Howlett@oracle.com, akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, gregkh@linuxfoundation.org, sashal@kernel.org, srinivasan.shanmugam@amd.com, chiahsuan.chung@amd.com, mingo@kernel.org, mgorman@techsingularity.net, yukuai3@huawei.com, chengming.zhou@linux.dev, zhangpeng.00@bytedance.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, , linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, yi.zhang@huawei.com, yangerkun@huawei.com, Chuck Lever Subject: [RFC PATCH 4/6 6.6] libfs: Add simple_offset_rename() API Date: Sun, 10 Nov 2024 19:52:40 -0500 Message-ID: <20241111005242.34654-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111005242.34654-1-cel@kernel.org> References: <20241111005242.34654-1-cel@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 4364A40011 X-Rspamd-Server: rspam11 X-Stat-Signature: ds3cpfmga6bfjendwqr9u9m8k784cyuu X-HE-Tag: 1731286345-729877 X-HE-Meta: U2FsdGVkX19znGbGyfhkXOoslM4dqDmjFX+LWpRAt6fDpftwonPS+YYQaM3dr7gex/oj8W6pxSxTANO9cpdpLCVc8v4Mfpw/FsyEF5pFuPANYq9GpVGf5ZpkXqsCuscdKxWT70sZxQPa6nRWBXNmO/wnGkooUCFWqtjPuklAMglNDT0zlVc+Nz6xqykfKqh1AlMCoSDukJq3+vqGA4IAgMQLtrt4TDkszW/dcRFY0Nl5ExCqaWIzge50bTXLD1+D2U7BX0Lob2J47yvFIq6OIEyP+ioAh1ykQeLYu9eVbjrDa7DFWldtCE2XZwj1pOtMo/UuEm7l1SQatBYFoDYSz/nuDLz48bwC1D0SWqWkwxIsnsOTePMcKulbYpO2EugLHNf9Jog1q90uDO35QIKCWMC410K6rt7Tc5liwc7YFmeiKUyl2TfHBrOTqRsTJt/YH2MiuYtZePgKQfTDS/XsPomrlBxzmOjz06+3+CH52rXQO40GZZ5D00hA1AOkDJSbb2PJdoQdhdCnRgMN1VLEpOqKgkynx4sOB/1Fv7yH3ji4GIW6zxMsTtYJ9rsXKT2pMDZ8ZOWknsvH0Ygr2FNsuPf5M9xcmJ2dRY824+7GNIWBBiNxPujW3Z5Gv02ZKVl0q86WyQx/fCG2+eXiSgOwK70bozTdU8SSnl723Zh24rbQyFnqqfXuNt81ZdDVzXjDn6StGPAfPK59HYxbMdEaH7frY6Z5wwIHGWkeYZsNEJuuVB1KXawq9+f0z1OP9D9VfOpvDKlkjtO974xna53yHuHxe0o2jCMpKLQ4l/hR0cNBRCoTES119nQV+HC3k7oMcwjgWk6rh/waHNKYzQv0iBh4BVzJNLkLKSAngu3nLAYsGviyKffhqp/F6ohobnP9QNgqehzY162LYzDJ01+PP6spyCYaEO9ixKCrS5Tb0H9Cw2O7GJ09lSMG7Cozbt1O6zV3FMbr9c3OzGM+Xhz q8FV0tDr 13g8MYvzqongCX/uyLu1GTDEcgzbW/QxiMmu9ZM+BI92kIkxd1xllBIyOs44InnsWfZNcPospWh0meodYuvYMNvdUy/y4XifiFwh0bjzkrrxBrCi3PLrZhnbIjRF6dqms1e4JwLzMpXX2JoaOZJyY1Sp3y3Dc6x+vttHRdZp2twpf3ai3fzJBHd48FYDj3yAXJah79uxRZGEppGMRzvI4g2fmUHog4om1o4NWt7t5ZMsivL9ShIv2ULtDzagpQyhgUpulwdaVMX6/Qx6uNLRx/piBkbzqbIRnvlfKHtTyS02FiGt2mUySifFUqw== 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 [ Upstream commit 5a1a25be995e1014abd01600479915683e356f5c ] I'm about to fix a tmpfs rename bug that requires the use of internal simple_offset helpers that are not available in mm/shmem.c Signed-off-by: Chuck Lever Link: https://lore.kernel.org/r/20240415152057.4605-3-cel@kernel.org Signed-off-by: Christian Brauner Stable-dep-of: ad191eb6d694 ("shmem: Fix shmem_rename2()") Signed-off-by: Chuck Lever --- fs/libfs.c | 21 +++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/shmem.c | 3 +-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 9fec0113a83f..b2dcb15d993a 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -356,6 +356,27 @@ int simple_offset_empty(struct dentry *dentry) return ret; } +/** + * simple_offset_rename - handle directory offsets for rename + * @old_dir: parent directory of source entry + * @old_dentry: dentry of source entry + * @new_dir: parent_directory of destination entry + * @new_dentry: dentry of destination + * + * Caller provides appropriate serialization. + * + * Returns zero on success, a negative errno value on failure. + */ +int simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry) +{ + struct offset_ctx *old_ctx = old_dir->i_op->get_offset_ctx(old_dir); + struct offset_ctx *new_ctx = new_dir->i_op->get_offset_ctx(new_dir); + + simple_offset_remove(old_ctx, old_dentry); + return simple_offset_add(new_ctx, old_dentry); +} + /** * simple_offset_rename_exchange - exchange rename with directory offsets * @old_dir: parent of dentry being moved diff --git a/include/linux/fs.h b/include/linux/fs.h index 5104405ce3e6..e4d139fcaad0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3198,6 +3198,8 @@ void simple_offset_init(struct offset_ctx *octx); int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry); void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry); int simple_offset_empty(struct dentry *dentry); +int simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry); int simple_offset_rename_exchange(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, diff --git a/mm/shmem.c b/mm/shmem.c index e0d014eaaf73..8e8998152a0f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3439,8 +3439,7 @@ static int shmem_rename2(struct mnt_idmap *idmap, return error; } - simple_offset_remove(shmem_get_offset_ctx(old_dir), old_dentry); - error = simple_offset_add(shmem_get_offset_ctx(new_dir), old_dentry); + error = simple_offset_rename(old_dir, old_dentry, new_dir, new_dentry); if (error) return error; From patchwork Mon Nov 11 00:52:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13870105 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 3FBFFD12D5C for ; Mon, 11 Nov 2024 00:53:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDEA96B0096; Sun, 10 Nov 2024 19:53:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B42256B0098; Sun, 10 Nov 2024 19:53:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 994806B0099; Sun, 10 Nov 2024 19:53:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 78D146B0096 for ; Sun, 10 Nov 2024 19:53:21 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0051F4160F for ; Mon, 11 Nov 2024 00:53:21 +0000 (UTC) X-FDA: 82771989426.24.9CF30F0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id B7F681C0010 for ; Mon, 11 Nov 2024 00:53:01 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aMIYzEMN; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731286225; 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=iGU/kFBZllJTKWG3r8FweNF45RNtpFgrUWWP1Gmir4s=; b=uQfUNolnRzu6grzrIIf3+MGqhtg7zXPuxl7lie5HcTTo4nZxtq9vWVvqVeGPTwK0BSOX2m VEHVbNaGeyPLnHtTnp7S4imWD6OIlSZpjUKHDykqApJsj0XV3S6l7XOa6ZpVcsg4SeYA2o JhOtsOhXYNt2mi0tNrxsZVd/7exhbYs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aMIYzEMN; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731286225; a=rsa-sha256; cv=none; b=jL2xk08/+TGd0z/ojaTlsD4w6N6o5NvE5Oz53ma9VGMtq6bqXkw0kQfXbqcF0HCxdxhss7 bHQMAnb8rR2yOmMEyXflYL1wfWE+t3WNH4sMgvBEtszxuw3msMZWfMyNABd1kqBn+uZqzq 09ygTuEa51jtQW6yXzbbFl/n7enI8uk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 20DA45C548D; Mon, 11 Nov 2024 00:52:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35F69C4CEDA; Mon, 11 Nov 2024 00:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731286398; bh=Eq6hm/AurEpUBcGjs15qnEqlTE8OCuozLkUE85txKaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aMIYzEMNY9q4iFf2JUztZP3Jyhw3wEtFmFm9g1gY0/ekzc6Sm1//MNk70I+7KwldA 7/eY37HChonjEeA2109emE/Syd1tdoK4X3vzsxDHeVEc7SN338hQcoXLla/Hz2eq2l 8J5TzUVJosjhO11krG92weLktbMPDx+YF3N0M8SlyDq4JCNWlTP4fWqe1VB8ewQXt+ 4QJ0G6CXfvWQBdx+b9eYPSJJ6z/cXyMoRkxcuD3xg3AtkuFrpLKBfyHFGJBClHw5hV ge+cgqwUijpgvDIodDRso5iDS72XZie2UXIw8VTekxd3mGzAhY21s6Q+AUj2vc3IQB J8PSNpMRiiqyQ== From: cel@kernel.org To: Cc: yukuai1@huaweicloud.com, harry.wentland@amd.com, sunpeng.li@amd.com, Rodrigo.Siqueira@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, viro@zeniv.linux.org.uk, brauner@kernel.org, Liam.Howlett@oracle.com, akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, gregkh@linuxfoundation.org, sashal@kernel.org, srinivasan.shanmugam@amd.com, chiahsuan.chung@amd.com, mingo@kernel.org, mgorman@techsingularity.net, yukuai3@huawei.com, chengming.zhou@linux.dev, zhangpeng.00@bytedance.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, , linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, yi.zhang@huawei.com, yangerkun@huawei.com, Chuck Lever Subject: [RFC PATCH 5/6 6.6] shmem: Fix shmem_rename2() Date: Sun, 10 Nov 2024 19:52:41 -0500 Message-ID: <20241111005242.34654-6-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111005242.34654-1-cel@kernel.org> References: <20241111005242.34654-1-cel@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B7F681C0010 X-Stat-Signature: hb8s33sp1gurkq5moaiik4ihaca4ybkz X-Rspam-User: X-HE-Tag: 1731286381-590346 X-HE-Meta: U2FsdGVkX1/0zG1n4e0S6WlbuLHnsrelBOvDSNOOfdVOeGUbP3k+Jyt/erXTDvWfdXD0lJ/7S81avfEMiIvio++cS9Q1BHLqoalXNG2/L54FbPbFUqoeGggi4WMm6avCaTE/8c62P8rTqJmV6RYmTL+O67S7KsKGMZRh8RJubyAc5o/65hXsfgbtgVTcmZNmXizG6PqtLO4AHBFFVU8uAfN1FhzS+KcvFRZHD2EVrYeDU/en6qykHO1Qg3NIvBRH9fzoYriDqxYEGrxTOjEFp0HdTd954CemHqdX7BTc2VmQnlpJlJvq/wLfPf5cQk7Rc0IjwV6D4OCBWw1oi+d6FRjT68yiiy2zIAje3BAHwaDisPSesQcHpe9dV3SPzop06LCKQwc4C+nZ8QHV5KfsY2420yWl2SiF8sPA08385kzzqbLEW9IUxrx2pIi19Lvc/UxAP4RbgqDO2tJz/Nvv44nqTtFEqdohitRgnhEVVwa3qW+Uw5kSfNyrTo5/++xhWlHOlHm4o4qoXDAs70THL5hMqKI2UEHsj4zvQE+02PwTcF50sUBaSNp2MYbwo5/lPxWyyoYrAeb/szNhCZNktTDfv1OtXdq2qY7/spsjycINHxjFPxjOd80f2k9QyR2++otMrkVeL9A0QFg1KRgcXDwxe91/wiMSnUk7NIHCVw/K/HyX9MGU9EMPVidvB9rFFT5GfdmLBJ10p0dOIviC2xcbZkm4jKBXLh9mk5baYrQIjbvv6XUMUG4W9RPcCGn2YEf/42hl3mWBxKEKxK3YMTUbf3gXCYMLA99pRBvu10RCJNABTYRPoScsaa7dODn6eMRysErhstq3Ow6mh3icZ49Zcs2MxwMM1Jzve3EuB5EnYo7KEjDVzH+z/LwWuZx++hrr1J+Fko3Sy4/FVMfsyVmbMvzaoElQRZn4NmTL2EPjDcIGkXsomj1KfhveEN178UPfo035zZ9gwkHcPpy k1Imp0Jl FL5go/vPzzju7VlOpvFdL8P+X6JOe8xnDUzBhuyqkvm33deHM5O7j6fCnQRLVEHWBjPXkEfoOxLLhEk7G1m+RZpLyp1NTs27USSJbx/1CHMufWdKiLUel91VtBWTtObYdMMPrmQig2IzlEthxra9eS882tm0R3dsEzJATh0Q8P3+vnP+r75djxjC4wsJBDi+qnDNlDujWzEPWZMc49rP8zU4NxeYVlIEEqjjFXHVbVhhQPMHcMSxi835fQVSOu0AaoW1b0Q2JwvsX2CdMJdO3kkMYveje5o3ekNP7l4Vvte9Lh2Yjns9+dF1uMfINlvUaMjwgOSFXx8nZc1gwYC0rHu0belLk84Z1lqnrww7g8MV5WbA= 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 [ Upstream commit ad191eb6d6942bb835a0b20b647f7c53c1d99ca4 ] When renaming onto an existing directory entry, user space expects the replacement entry to have the same directory offset as the original one. Link: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15966 Fixes: a2e459555c5f ("shmem: stable directory offsets") Signed-off-by: Chuck Lever Link: https://lore.kernel.org/r/20240415152057.4605-4-cel@kernel.org Signed-off-by: Christian Brauner Signed-off-by: Chuck Lever --- fs/libfs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index b2dcb15d993a..a87005c89534 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -365,6 +365,9 @@ int simple_offset_empty(struct dentry *dentry) * * Caller provides appropriate serialization. * + * User space expects the directory offset value of the replaced + * (new) directory entry to be unchanged after a rename. + * * Returns zero on success, a negative errno value on failure. */ int simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry, @@ -372,8 +375,14 @@ int simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry, { struct offset_ctx *old_ctx = old_dir->i_op->get_offset_ctx(old_dir); struct offset_ctx *new_ctx = new_dir->i_op->get_offset_ctx(new_dir); + long new_offset = dentry2offset(new_dentry); simple_offset_remove(old_ctx, old_dentry); + + if (new_offset) { + offset_set(new_dentry, 0); + return simple_offset_replace(new_ctx, old_dentry, new_offset); + } return simple_offset_add(new_ctx, old_dentry); } From patchwork Mon Nov 11 00:52:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13870106 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 B8633D12D5E for ; Mon, 11 Nov 2024 00:53:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F0246B0098; Sun, 10 Nov 2024 19:53:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 37A606B0099; Sun, 10 Nov 2024 19:53:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F3456B009A; Sun, 10 Nov 2024 19:53:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id F24ED6B0098 for ; Sun, 10 Nov 2024 19:53:23 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9C2DC1A140A for ; Mon, 11 Nov 2024 00:53:23 +0000 (UTC) X-FDA: 82771989510.30.855E934 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id AC3BF100003 for ; Mon, 11 Nov 2024 00:52:06 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SS71cagn; spf=pass (imf05.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 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=1731286348; 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=FGLo83jrDngw/CAuOddHFvlwBshrpzVUuM0qMcpgloY=; b=5/VD+T6/9J6a1sTkTUj0mM/9XrmYQm64LvjPgtXUhPL/RSpv9qcBkNpRch6iBgJDbm7OzJ QlL1BY1aq/nnPUoHPv8Q8ZSyacMg+DZViNORB9+/z9epagdM1DxQqUba/JOgJ29rsZ4JxR lDMERMpblqgVtoVmmG8FX3b9LpLr2OM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731286348; a=rsa-sha256; cv=none; b=PoHsJlsW/Y5zq/izpbtu/MXbx3Wz3toE3jAV17hjLHqSEmknQQYcSimOhsccMAjkKKXqoI ClY0u03jWnKy6wrCIH5cUyF1Q9LqxgZsvmFdAs59Gp0Zof4Od4GjGorKntS+/bz8fO92rK yW0Hby42Y8zAZjY1qMJq46G5nLfaAtw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SS71cagn; spf=pass (imf05.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 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 dfw.source.kernel.org (Postfix) with ESMTP id C155F5C54D1; Mon, 11 Nov 2024 00:52:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 381A7C4CEDF; Mon, 11 Nov 2024 00:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731286400; bh=FdkkHjJkV4S0+kVcTYwQw7JAo4gJep4aQ3vPEJrklpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SS71cagn0Y7k0khmPTRSNE2WIHD+UznGHwyeGjN6di6DA1sirkflrguuVTZfxJuMc /G9xzd1SKB6D9RdV9mg/kKdTh3Fb8Uw0YfA3G5UjeH1P9ZO52x1CzgadU77Vyy7HgZ FnPM9QJ6/Fd2xvc9b3aTmANUab2ekRv5H7VCSTVNS+VumwqsVLVOWs39LyhE+bh+4h e1ygJE+h9xbhHDwrinkdWVXPXG1QA19rUN38dxI6I8sqZEE74fYpYwrkIBq7TR74w7 Rn6PjpDnyEgXK2ddOoeB3QHYdnXmUkLTtda17feUFfBEaG5aHTbfsQgcZVzOpWvud7 +nuLxfO5dEEMg== From: cel@kernel.org To: Cc: yukuai1@huaweicloud.com, harry.wentland@amd.com, sunpeng.li@amd.com, Rodrigo.Siqueira@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, viro@zeniv.linux.org.uk, brauner@kernel.org, Liam.Howlett@oracle.com, akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, gregkh@linuxfoundation.org, sashal@kernel.org, srinivasan.shanmugam@amd.com, chiahsuan.chung@amd.com, mingo@kernel.org, mgorman@techsingularity.net, yukuai3@huawei.com, chengming.zhou@linux.dev, zhangpeng.00@bytedance.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, , linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, yi.zhang@huawei.com, yangerkun@huawei.com, Chuck Lever Subject: [RFC PATCH 6/6 6.6] libfs: fix infinite directory reads for offset dir Date: Sun, 10 Nov 2024 19:52:42 -0500 Message-ID: <20241111005242.34654-7-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111005242.34654-1-cel@kernel.org> References: <20241111005242.34654-1-cel@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 93uyx1a815b16ysru57o7fmmppgocyd9 X-Rspam-User: X-Rspamd-Queue-Id: AC3BF100003 X-Rspamd-Server: rspam02 X-HE-Tag: 1731286326-614355 X-HE-Meta: U2FsdGVkX1+uDmIOZGFgffazdgto0Lkvx4sJhv+IvSb0AFTsRQs8bT6gk7O49SCQ0n3SHYWywqe7Xtd0tmQ6ZGOrZzfvU38B1PIGT2NZ6WpXjXGo1mqSlt20WovUHem6DUloUBqCXSuN7QQFu09okPmSR9PVW8of3uKugdnYdFehN9/9GqfF/df5KzykZxyT4c6YAWxlbAYXWkqLQe3PFFA0K9WliP9WObVI25mGmhYaapoEohgQhZ3FzwxWAnpoJ6PTPVzGJ+etk0IUvns30OR69mCwOIHBeFFiWbb9giNBl1nxmNKdaOeV9R2lyn37f+JD7nz4mpN8+apPTdkurtk9HSbQAnfOa33YepI5ZENBVpiabwJDPmTKImKcHYiHv5+UY27+9T3RYZgNfhkoBGaQVkJUdwfA4oLvUeIoTbdBgBeb9fKanZFFsAH1HV+M3O2Q8FvIrtjs41FnGeBZ95CD5VT/zKssfCF1SYfBIN4YMzalQIxzRAqzmss3rj/DvPygjBgvxflIjXyjJy0IMcChUcLM5vFMQHl+S9c0gjhQv27HPdYkF7LUjS3qtrnIvJ4vg0Aj/muLcyQWQIvyvC0Rc+UOgYW1fsTFQed1p4p+OM7MMSEFeYwwKNrgoOQfvBwc7YAh+j0ISBiU8Gx4ZzO74VLgVV9vhxywBiggncoz4G7msJL5cwCCYIuDNA7BKT+WaL8dSHBMe8zTJro/oZD4Bgq6a0hsrRPPX/RbEsSDDLbxQ8/n/cKhSylhvbjw45SCDMagTGMv/zITdDuTF0Kuhy+RhPyYX59A8/WULj+iWrLn/bGLzHRWMMvNwH7qF7H1/M1Cjmyt9UFnC8tUNGhcw+Dz3wlOPwknBjOtjhZn6LiWixpeuayGOa1PDIqJWm0EJwJO2ANaFTj99FArwnRnYdUH7k0RRYip0GOPBj7yO9ev+HlDmJE1/TdS88eHQ9fdt1wyFp8xYU6d4Oq 6Hbj6vl6 gYuhBw2cvUQDorH91Uh1kg+yWDkk041BfKSpvmCstVO4QSJs2vUtOZnDaGq+74Cf/5aquMPvDfnT+Vtr49CFPew8kkBOr4w4haDy6Hb7PiR4hmVMPSRPKEbSDyDToWWUKIxA28zxl1ZKaGR+N1V0rt5IaJZvBM5+B1yOCdy2Saq/wml+f8tfNo7iAqarKk05ktwUaiSaBjXV3ZcsrbZmNcs/6sx62HYJfSuZ19Ygg1KlEHRkSv2Zmv3VsN7n2go2CoQbj/vby+iyMQVj6/1W46BgafmWf0Hjwlf8x0iLkWc7HJUk= 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: yangerkun [ Upstream commit 64a7ce76fb901bf9f9c36cf5d681328fc0fd4b5a ] After we switch tmpfs dir operations from simple_dir_operations to simple_offset_dir_operations, every rename happened will fill new dentry to dest dir's maple tree(&SHMEM_I(inode)->dir_offsets->mt) with a free key starting with octx->newx_offset, and then set newx_offset equals to free key + 1. This will lead to infinite readdir combine with rename happened at the same time, which fail generic/736 in xfstests(detail show as below). 1. create 5000 files(1 2 3...) under one dir 2. call readdir(man 3 readdir) once, and get one entry 3. rename(entry, "TEMPFILE"), then rename("TEMPFILE", entry) 4. loop 2~3, until readdir return nothing or we loop too many times(tmpfs break test with the second condition) We choose the same logic what commit 9b378f6ad48cf ("btrfs: fix infinite directory reads") to fix it, record the last_index when we open dir, and do not emit the entry which index >= last_index. The file->private_data now used in offset dir can use directly to do this, and we also update the last_index when we llseek the dir file. Fixes: a2e459555c5f ("shmem: stable directory offsets") Signed-off-by: yangerkun Link: https://lore.kernel.org/r/20240731043835.1828697-1-yangerkun@huawei.com Reviewed-by: Chuck Lever [brauner: only update last_index after seek when offset is zero like Jan suggested] Signed-off-by: Christian Brauner Link: https://nvd.nist.gov/vuln/detail/CVE-2024-46701 [ cel: adjusted to apply to origin/linux-6.6.y ] Signed-off-by: Chuck Lever --- fs/libfs.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index a87005c89534..b59ff0dfea1f 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -449,6 +449,14 @@ void simple_offset_destroy(struct offset_ctx *octx) xa_destroy(&octx->xa); } +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 @@ -462,6 +470,9 @@ void simple_offset_destroy(struct offset_ctx *octx) */ 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; @@ -475,8 +486,9 @@ 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 */ - file->private_data = NULL; - return vfs_setpos(file, offset, U32_MAX); + if (!offset) + file->private_data = (void *)ctx->next_offset; + return vfs_setpos(file, offset, LONG_MAX); } static struct dentry *offset_find_next(struct xa_state *xas) @@ -505,7 +517,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) +static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx, long last_index) { struct offset_ctx *so_ctx = inode->i_op->get_offset_ctx(inode); XA_STATE(xas, &so_ctx->xa, ctx->pos); @@ -514,17 +526,21 @@ static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) while (true) { dentry = offset_find_next(&xas); if (!dentry) - return ERR_PTR(-ENOENT); + return; + + if (dentry2offset(dentry) >= last_index) { + dput(dentry); + return; + } if (!offset_dir_emit(ctx, dentry)) { dput(dentry); - break; + return; } dput(dentry); ctx->pos = xas.xa_index + 1; } - return NULL; } /** @@ -551,22 +567,19 @@ static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) 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; - /* 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); + offset_iterate_dir(d_inode(dir), ctx, last_index); 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,