From patchwork Thu Jan 30 08:59:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 13954355 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 4B304C0218A for ; Thu, 30 Jan 2025 08:59:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAAF128026E; Thu, 30 Jan 2025 03:59:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C3BE62800D0; Thu, 30 Jan 2025 03:59:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B224028026E; Thu, 30 Jan 2025 03:59:45 -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 901AB2800D0 for ; Thu, 30 Jan 2025 03:59:45 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 47BD31C5BF9 for ; Thu, 30 Jan 2025 08:59:45 +0000 (UTC) X-FDA: 83063520330.01.9A4DAA9 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id E547E18000F for ; Thu, 30 Jan 2025 08:59:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=J7V7M+eU; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf16.hostedemail.com: domain of gregkh@linuxfoundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738227583; a=rsa-sha256; cv=none; b=rb/3NlqEbE/aJZscd4QSrdFAXM0+/hFpANezPKOFIXGrCnW+qwUX+TSwb5czBFAQznE3tI 2kF0BxazaSLdFV/fbo1hbmxGYDNQexqTwAr1wG7YlezDHiexVqKkxMLhwIKkvw3//yGjmA nDl6UWQjxdG7+udKiToZjrY2NUjoY8Y= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=J7V7M+eU; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf16.hostedemail.com: domain of gregkh@linuxfoundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738227583; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to:references:dkim-signature; bh=7dzJ8v1sb73/d9dKO6Ynz1VKaKeX32njOVq4M4T+tKc=; b=Y0Vg01NRLCCVXhg35Pe0NFl8vdlRakLdRCHr0fHRTpchcwbdnOF1QHpciciJ25bwpKuXTA F6ybkUz4Yn3rQNmuNpuK//3Iys5rfLSD5jiaxFwc7vPWUmLDfsz6audMUF2oA4PpjCbYnC 8kwfQy8bYAqzIjNhX15yDkLLba7+cA4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 958F1A40F8C; Thu, 30 Jan 2025 08:57:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97EDFC4CED3; Thu, 30 Jan 2025 08:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1738227583; bh=Z/LKTK06Z2RzqnLIk8wTdPoMVPLvwy/8sx7cV9ZMGaM=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=J7V7M+eUR9voIc8OwPotHBcLfjWI2rhvQ3a8iJpxShElioHlxTJXZXdFphlJrgKS6 +KEIjoc41+P1SCrMtn9U+u6LyBE23vDv2GkU9vzWiFYPVnM7pQWjSd7vPGtBbE4AbO ZR52D4hamtL+aiZu3qhdwUVzEtb3l4AOX2wLI9gs= Subject: Patch "libfs: Re-arrange locking in offset_iterate_dir()" has been added to the 6.6-stable tree To: Liam.Howlett@Oracle.com,akpm@linux-foundation.org,brauner@kernel.org,cel@kernel.org,chuck.lever@oracle.com,gregkh@linuxfoundation.org,hughd@google.com,jack@suse.cz,linux-mm@kvack.org,sashal@kernel.org,viro@zeniv.linux.org.uk,yangerkun@huawei.com,yukuai3@huawei.com Cc: From: Date: Thu, 30 Jan 2025 09:59:30 +0100 In-Reply-To: <20250124191946.22308-2-cel@kernel.org Message-Id: <20250130085942.97EDFC4CED3@smtp.kernel.org> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E547E18000F X-Stat-Signature: 5mipe316iicsem7t33zrewfxn5rw6joi X-Rspam-User: X-HE-Tag: 1738227583-579784 X-HE-Meta: U2FsdGVkX19ovjtJq0BCR5MOD9iMEFBNrBMQN1BcJ4gyV8NRkVLdt9AMaXCeEVUjQXkc7+xuQdJJDVviZATPpFlyb/QNI74+zd7lIdcmNVQnBk4HOIxKf0PSii6mSb9t1MIP9vMw5rrCxucFmVKv6b3vF0FBaWVoma5Wcyt3NUl6gN4zYozKAyReXxayMqURX9ciEuG07Wkfv2f0cJtyAn5PROqZeR/G7lEvQkr9pHtpXlVyqg6QehLz+mfSaF+onBNnvSow6Z/6nssSw+3KfjI5S1ehaZvgQT1SCTCFVzgL9sSrg6hC+PWcty1qSWISGAnEoRqxoV2wjdmcpeoQxkSuA0xOTsE8ORK4N4g7+6jxULu5yxB9/giPZOHTfa246o7wIE7VxPorAccP/qcpnHTsaOeKX6Sa2fyGLth2Sh975AXljzu6mTltmLhEK49tgCcyHGyripQv36c44kAPsPIC3DdEub/m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b0FMisNmzGX93IMjGmOjsAzdu58dIgKWKD34764vch3dioaSc9M5A== 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: 170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> Message-ID: <2025013030-navigator-unzip-fad7@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit X-stable: commit X-Patchwork-Hint: ignore This is a note to let you know that I've just added the patch titled libfs: Re-arrange locking in offset_iterate_dir() to the 6.6-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: libfs-re-arrange-locking-in-offset_iterate_dir.patch and it can be found in the queue-6.6 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. From stable+bounces-110401-greg=kroah.com@vger.kernel.org Fri Jan 24 20:20:29 2025 From: cel@kernel.org Date: Fri, 24 Jan 2025 14:19:36 -0500 Subject: libfs: Re-arrange locking in offset_iterate_dir() To: Hugh Dickins , Andrew Morten , Christian Brauner , Al Viro , Greg Kroah-Hartman , Sasha Levin Cc: , , , yukuai3@huawei.com, yangerkun@huawei.com, Chuck Lever , "Liam R. Howlett" , Jan Kara Message-ID: <20250124191946.22308-2-cel@kernel.org> From: Chuck Lever [ Upstream commit 3f6d810665dfde0d33785420618ceb03fba0619d ] Liam and Matthew say that once the RCU read lock is released, xa_state is not safe to re-use for the next xas_find() call. But the RCU read lock must be released on each loop iteration so that dput(), which might_sleep(), can be called safely. Thus we are forced to walk the offset tree with fresh state for each directory entry. xa_find() can do this for us, though it might be a little less efficient than maintaining xa_state locally. We believe that in the current code base, inode->i_rwsem provides protection for the xa_state maintained in offset_iterate_dir(). However, there is no guarantee that will continue to be the case in the future. Since offset_iterate_dir() doesn't build xa_state locally any more, there's no longer a strong need for offset_find_next(). Clean up by rolling these two helpers together. Suggested-by: Liam R. Howlett Message-ID: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> Signed-off-by: Chuck Lever Link: https://lore.kernel.org/r/170820142021.6328.15047865406275957018.stgit@91.116.238.104.host.secureserver.net Reviewed-by: Jan Kara Signed-off-by: Christian Brauner Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- fs/libfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) Patches currently in stable-queue which might be from cel@kernel.org are queue-6.6/libfs-replace-simple_offset-end-of-directory-detection.patch queue-6.6/libfs-re-arrange-locking-in-offset_iterate_dir.patch queue-6.6/libfs-add-simple_offset_empty.patch queue-6.6/shmem-fix-shmem_rename2.patch queue-6.6/revert-libfs-add-simple_offset_empty.patch queue-6.6/libfs-use-d_children-list-to-iterate-simple_offset-directories.patch queue-6.6/libfs-define-a-minimum-directory-offset.patch queue-6.6/libfs-return-enospc-when-the-directory-offset-range-is-exhausted.patch queue-6.6/libfs-fix-simple_offset_rename_exchange.patch queue-6.6/libfs-add-simple_offset_rename-api.patch --- a/fs/libfs.c +++ b/fs/libfs.c @@ -401,12 +401,13 @@ static loff_t offset_dir_llseek(struct f return vfs_setpos(file, offset, U32_MAX); } -static struct dentry *offset_find_next(struct xa_state *xas) +static struct dentry *offset_find_next(struct offset_ctx *octx, loff_t offset) { struct dentry *child, *found = NULL; + XA_STATE(xas, &octx->xa, offset); rcu_read_lock(); - child = xas_next_entry(xas, U32_MAX); + child = xas_next_entry(&xas, U32_MAX); if (!child) goto out; spin_lock(&child->d_lock); @@ -429,12 +430,11 @@ static bool offset_dir_emit(struct dir_c static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) { - struct offset_ctx *so_ctx = inode->i_op->get_offset_ctx(inode); - XA_STATE(xas, &so_ctx->xa, ctx->pos); + struct offset_ctx *octx = inode->i_op->get_offset_ctx(inode); struct dentry *dentry; while (true) { - dentry = offset_find_next(&xas); + dentry = offset_find_next(octx, ctx->pos); if (!dentry) return ERR_PTR(-ENOENT); @@ -443,8 +443,8 @@ static void *offset_iterate_dir(struct i break; } + ctx->pos = dentry2offset(dentry) + 1; dput(dentry); - ctx->pos = xas.xa_index + 1; } return NULL; }