From patchwork Sun Apr 6 20:43:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tingmao Wang X-Patchwork-Id: 14039515 Received: from flow-a4-smtp.messagingengine.com (flow-a4-smtp.messagingengine.com [103.168.172.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AFF43597A for ; Sun, 6 Apr 2025 20:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972352; cv=none; b=E6MSm01F8wbg8UEM4gAJ+LJ3QthxGOcnlQxnvKTwCCTxEQQ2RoeKygUslWTpLJjIKv8HBMVl/Ufd6xXWhEftSxiQ3A1DwtU9IqlSNlWxmgqrT3LjimWAs9cB/qxXBMBHHOFp6X9M0cdk8sv4k9s6KFUsHELnt3HSiyhATA0Alxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972352; c=relaxed/simple; bh=XLFo39BVEoAoBBqV9syYijIuPWDZsYIEBwJfJJ9SE7c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=stWECXpIO8aQEsqOzg48eqdUxOH3fsigHIHFPUInZjJrQSZbBQj4h8tA029BIit4mGds0yovZyml0t7HSohM3GNoThkbpF8DODoBtMvhlXKGfJA+DwvSoyOQyaB2X1blsezh6vslYh/Ku3NVZwpTgXtT+XW7VZxxlEH8LLkeJdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org; spf=pass smtp.mailfrom=maowtm.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b=Z6eU+TSY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=tFX5OLvk; arc=none smtp.client-ip=103.168.172.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=maowtm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b="Z6eU+TSY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="tFX5OLvk" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailflow.phl.internal (Postfix) with ESMTP id 689D0202428; Sun, 6 Apr 2025 16:45:48 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Sun, 06 Apr 2025 16:45:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maowtm.org; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1743972348; x= 1743975948; bh=QTBCQns44FbkVkYYlhRmyTJiJhR3fKsYOUyxwrjONOk=; b=Z 6eU+TSYjzvhSATxKOv4qeVP8Fp6YdlM5ZPqEaY8eD3viFzVBy2c4FX0rK2TJVB/4 PahRk80cuzQZ6QaDiMpTnQ96jOoOKy4UnxWKB+HrUljCZayFPHlHlqm7Za+FyQyE 8XpU25HTPh6zTQcucX0TUyKOV1fSFGMR68O09AyO0/uwH9TCZzjcW2TWRaYOTgVp GFgswoHMON938DmgTgyRI3OxTg0Nresc0snJHkzA3vXyMme8M1unfS85jwCWSIAX NOviCzcFEdaGgMwSk4oFLhyJSmpc0pruimhDSnPd1TfIOpZ01OTyE7GPUo3BByEs +y2SUutmf0Gg06MYUE2YA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743972348; x=1743975948; bh=Q TBCQns44FbkVkYYlhRmyTJiJhR3fKsYOUyxwrjONOk=; b=tFX5OLvkNpa63wFdf lzxXEiUsPQ0MEPkQP818VH0+J4TGfWRyW6ckhHt0qYiizUTlR8Re+uslC8N61JFy SDTIi89oREambWYknuw2C0BPWqU2P8hwUFGG5NjZl3xLSX3PDj/fVgVZfYTKGGsz LGLGf9r9ckgMFYOcoZeEphrq7xM9sMra34W7QW1TMKq4O+nf64zPh5UP25rdsD8J ykCAR5a1G9ryN8VijtbKmQFk8/tK6A1iC0aozQ++fK6IT5qaPpwwLvf4zPKXf9V3 y0iKIh5wPQ9+/URy61oA+M42rxFgGDtYuR//dSRlXZtPlI5MgYDfVdmtfOk2aVk7 3WR4A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleekvdekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepvfhinhhgmhgrohcuhggrnhhguceomhesmhgrohifthhmrdhorhhgqe enucggtffrrghtthgvrhhnpeeuuddthefhhefhvdejteevvddvteefffegteetueegueel jeefueekjeetieeuleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehmsehmrghofihtmhdrohhrghdpnhgspghrtghpthhtohepudefpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegvrhhitghvhheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheprghsmhgruggvuhhssegtohguvgifrhgvtghkrdhorhhgpdhrtghpthht oheplhhutghhohesihhonhhkohhvrdhnvghtpdhrtghpthhtoheplhhinhhugigpohhssh estghruhguvggshihtvgdrtghomhdprhgtphhtthhopehmsehmrghofihtmhdrohhrghdp rhgtphhtthhopehvlehfsheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhope hmihgtseguihhgihhkohgurdhnvghtpdhrtghpthhtohepghhnohgrtghksehgohhoghhl vgdrtghomhdprhgtphhtthhopehlihhnuhigqdhsvggtuhhrihhthidqmhhoughulhgvse hvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i580e4893:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 6 Apr 2025 16:45:42 -0400 (EDT) From: Tingmao Wang To: Eric Van Hensbergen , Dominique Martinet , Latchesar Ionkov , Christian Schoenebeck Cc: Tingmao Wang , v9fs@lists.linux.dev, =?utf-8?q?Micka=C3=AB?= =?utf-8?q?l_Sala=C3=BCn?= , =?utf-8?q?G=C3=BCnther_Noack?= , linux-security-module@vger.kernel.org, Jan Kara , Amir Goldstein , Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 1/6] fs/9p: Add ability to identify inode by path for .L Date: Sun, 6 Apr 2025 21:43:02 +0100 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: v9fs@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Creating a new file for shared code between vfs_inode.c and vfs_inode_dotl.c. Same change for non-.L will be added in a following commit. Signed-off-by: Tingmao Wang --- fs/9p/Makefile | 3 +- fs/9p/ino_path.c | 114 +++++++++++++++++++++++++++++++++++++++++ fs/9p/v9fs.h | 54 +++++++++++++------ fs/9p/vfs_inode.c | 20 ++++++-- fs/9p/vfs_inode_dotl.c | 91 +++++++++++++++++++++++++++++--- fs/9p/vfs_super.c | 10 +++- 6 files changed, 262 insertions(+), 30 deletions(-) create mode 100644 fs/9p/ino_path.c diff --git a/fs/9p/Makefile b/fs/9p/Makefile index e7800a5c7395..38c3ceb26274 100644 --- a/fs/9p/Makefile +++ b/fs/9p/Makefile @@ -11,7 +11,8 @@ obj-$(CONFIG_9P_FS) := 9p.o vfs_dentry.o \ v9fs.o \ fid.o \ - xattr.o + xattr.o \ + ino_path.o 9p-$(CONFIG_9P_FSCACHE) += cache.o 9p-$(CONFIG_9P_FS_POSIX_ACL) += acl.o diff --git a/fs/9p/ino_path.c b/fs/9p/ino_path.c new file mode 100644 index 000000000000..a4e0aef81618 --- /dev/null +++ b/fs/9p/ino_path.c @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Specific operations on the v9fs_ino_path structure. + * + * Copyright (C) 2025 by Tingmao Wang + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include + +#include +#include +#include +#include "v9fs.h" + +/* + * Must hold rename_sem due to traversing parents + */ +struct v9fs_ino_path *make_ino_path(struct dentry *dentry) +{ + struct v9fs_ino_path *path; + size_t path_components = 0; + struct dentry *curr = dentry; + ssize_t i; + + lockdep_assert_held_read(&v9fs_dentry2v9ses(dentry)->rename_sem); + + rcu_read_lock(); + + /* Don't include the root dentry */ + while (curr->d_parent != curr) { + path_components++; + curr = curr->d_parent; + } + if (WARN_ON(path_components > SSIZE_MAX)) { + rcu_read_unlock(); + return NULL; + } + + path = kmalloc(struct_size(path, names, path_components), + GFP_KERNEL); + if (!path) { + rcu_read_unlock(); + return NULL; + } + + path->nr_components = path_components; + curr = dentry; + for (i = path_components - 1; i >= 0; i--) { + take_dentry_name_snapshot(&path->names[i], curr); + curr = curr->d_parent; + } + WARN_ON(curr != curr->d_parent); + rcu_read_unlock(); + return path; +} + +void free_ino_path(struct v9fs_ino_path *path) +{ + if (path) { + for (size_t i = 0; i < path->nr_components; i++) + release_dentry_name_snapshot(&path->names[i]); + kfree(path); + } +} + +/* + * Must hold rename_sem due to traversing parents + */ +bool ino_path_compare(struct v9fs_ino_path *ino_path, + struct dentry *dentry) +{ + struct dentry *curr = dentry; + struct qstr *curr_name; + struct name_snapshot *compare; + ssize_t i; + + lockdep_assert_held_read(&v9fs_dentry2v9ses(dentry)->rename_sem); + + rcu_read_lock(); + for (i = ino_path->nr_components - 1; i >= 0; i--) { + if (curr->d_parent == curr) { + /* We're supposed to have more components to walk */ + rcu_read_unlock(); + return false; + } + curr_name = &curr->d_name; + compare = &ino_path->names[i]; + /* + * We can't use hash_len because it is salted with the parent + * dentry pointer. We could make this faster by pre-computing our + * own hashlen for compare and ino_path outside, probably. + */ + if (curr_name->len != compare->name.len) { + rcu_read_unlock(); + return false; + } + if (strncmp(curr_name->name, compare->name.name, + curr_name->len) != 0) { + rcu_read_unlock(); + return false; + } + curr = curr->d_parent; + } + rcu_read_unlock(); + if (curr != curr->d_parent) { + /* dentry is deeper than ino_path */ + return false; + } + return true; +} diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index f28bc763847a..5c85923aa2dd 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -10,6 +10,7 @@ #include #include +#include /** * enum p9_session_flags - option flags for each 9P session @@ -31,16 +32,17 @@ #define V9FS_ACL_MASK V9FS_POSIX_ACL enum p9_session_flags { - V9FS_PROTO_2000U = 0x01, - V9FS_PROTO_2000L = 0x02, - V9FS_ACCESS_SINGLE = 0x04, - V9FS_ACCESS_USER = 0x08, - V9FS_ACCESS_CLIENT = 0x10, - V9FS_POSIX_ACL = 0x20, - V9FS_NO_XATTR = 0x40, - V9FS_IGNORE_QV = 0x80, /* ignore qid.version for cache hints */ - V9FS_DIRECT_IO = 0x100, - V9FS_SYNC = 0x200 + V9FS_PROTO_2000U = 0x01, + V9FS_PROTO_2000L = 0x02, + V9FS_ACCESS_SINGLE = 0x04, + V9FS_ACCESS_USER = 0x08, + V9FS_ACCESS_CLIENT = 0x10, + V9FS_POSIX_ACL = 0x20, + V9FS_NO_XATTR = 0x40, + V9FS_IGNORE_QV = 0x80, /* ignore qid.version for cache hints */ + V9FS_DIRECT_IO = 0x100, + V9FS_SYNC = 0x200, + V9FS_INODE_IDENT_PATH = 0x400, }; /** @@ -133,11 +135,27 @@ struct v9fs_session_info { /* cache_validity flags */ #define V9FS_INO_INVALID_ATTR 0x01 +struct v9fs_ino_path { + size_t nr_components; + struct name_snapshot names[] __counted_by(nr_components); +}; + +extern struct v9fs_ino_path *make_ino_path(struct dentry *dentry); +extern void free_ino_path(struct v9fs_ino_path *path); +extern bool ino_path_compare(struct v9fs_ino_path *ino_path, + struct dentry *dentry); + struct v9fs_inode { struct netfs_inode netfs; /* Netfslib context and vfs inode */ struct p9_qid qid; unsigned int cache_validity; struct mutex v_mutex; + + /* + * Only for filesystems with inode_ident=path. Lifetime is the same as + * this inode + */ + struct v9fs_ino_path *path; }; static inline struct v9fs_inode *V9FS_I(const struct inode *inode) @@ -188,7 +206,8 @@ extern const struct inode_operations v9fs_symlink_inode_operations_dotl; extern const struct netfs_request_ops v9fs_req_ops; extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, - struct super_block *sb, int new); + struct super_block *sb, + struct dentry *dentry, int new); /* other default globals */ #define V9FS_PORT 564 @@ -217,6 +236,11 @@ static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses) return v9ses->flags & V9FS_PROTO_2000L; } +static inline int v9fs_inode_ident_path(struct v9fs_session_info *v9ses) +{ + return v9ses->flags & V9FS_INODE_IDENT_PATH; +} + /** * v9fs_get_inode_from_fid - Helper routine to populate an inode by * issuing a attribute request @@ -227,10 +251,10 @@ static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses) */ static inline struct inode * v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, - struct super_block *sb) + struct super_block *sb, struct dentry *dentry) { if (v9fs_proto_dotl(v9ses)) - return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 0); + return v9fs_inode_from_fid_dotl(v9ses, fid, sb, dentry, 0); else return v9fs_inode_from_fid(v9ses, fid, sb, 0); } @@ -245,10 +269,10 @@ v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, */ static inline struct inode * v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, - struct super_block *sb) + struct super_block *sb, struct dentry *dentry) { if (v9fs_proto_dotl(v9ses)) - return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1); + return v9fs_inode_from_fid_dotl(v9ses, fid, sb, dentry, 1); else return v9fs_inode_from_fid(v9ses, fid, sb, 1); } diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 1640765563e9..72fd72a2ff06 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -243,6 +243,7 @@ struct inode *v9fs_alloc_inode(struct super_block *sb) void v9fs_free_inode(struct inode *inode) { + free_ino_path(V9FS_I(inode)->path); kmem_cache_free(v9fs_inode_cache, V9FS_I(inode)); } @@ -607,15 +608,17 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, goto error; } /* - * instantiate inode and assign the unopened fid to the dentry + * Instantiate inode. On .L fs, pass in dentry for inodeident=path. */ - inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); + inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, + v9fs_proto_dotl(v9ses) ? dentry : NULL); if (IS_ERR(inode)) { err = PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err); goto error; } + /* Assign the unopened fid to the dentry */ v9fs_fid_add(dentry, &fid); d_instantiate(dentry, inode); } @@ -733,14 +736,21 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, name = dentry->d_name.name; fid = p9_client_walk(dfid, 1, &name, 1); p9_fid_put(dfid); + + /* + * On .L fs, pass in dentry to v9fs_get_inode_from_fid in case it is + * needed by inodeident=path + */ if (fid == ERR_PTR(-ENOENT)) inode = NULL; else if (IS_ERR(fid)) inode = ERR_CAST(fid); - else if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) - inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb); + else if (v9ses->cache & (CACHE_META | CACHE_LOOSE)) + inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb, + v9fs_proto_dotl(v9ses) ? dentry : NULL); else - inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); + inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, + v9fs_proto_dotl(v9ses) ? dentry : NULL); /* * If we had a rename on the server and a parallel lookup * for the new name, then make sure we instantiate with diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 2d025e561ba1..c1cc3553f2fb 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -52,10 +52,17 @@ static kgid_t v9fs_get_fsgid_for_create(struct inode *dir_inode) return current_fsgid(); } +struct iget_data { + struct p9_stat_dotl *st; + struct dentry *dentry; +}; + static int v9fs_test_inode_dotl(struct inode *inode, void *data) { struct v9fs_inode *v9inode = V9FS_I(inode); - struct p9_stat_dotl *st = (struct p9_stat_dotl *)data; + struct p9_stat_dotl *st = ((struct iget_data *)data)->st; + struct dentry *dentry = ((struct iget_data *)data)->dentry; + struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); /* don't match inode of different type */ if (inode_wrong_type(inode, st->st_mode)) @@ -74,22 +81,74 @@ static int v9fs_test_inode_dotl(struct inode *inode, void *data) if (v9inode->qid.path != st->qid.path) return 0; + + if (v9fs_inode_ident_path(v9ses)) { + if (!ino_path_compare(v9inode->path, dentry)) { + p9_debug(P9_DEBUG_VFS, "Refusing to reuse inode %p based on path mismatch", + inode); + return 0; + } + } return 1; } /* Always get a new inode */ static int v9fs_test_new_inode_dotl(struct inode *inode, void *data) { + struct v9fs_inode *v9inode = V9FS_I(inode); + struct p9_stat_dotl *st = ((struct iget_data *)data)->st; + struct dentry *dentry = ((struct iget_data *)data)->dentry; + struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); + + /* + * Don't reuse inode of different type, even if we have + * inodeident=path and path matches. + */ + if (inode_wrong_type(inode, st->st_mode)) + return 0; + + /* + * We're only getting here if QID2INO stays the same anyway, so + * mirroring the qid checks in v9fs_test_inode_dotl + * (but maybe that check is unnecessary anyway? at least on 64bit) + */ + + if (v9inode->qid.type != st->qid.type) + return 0; + + if (v9inode->qid.path != st->qid.path) + return 0; + + if (v9fs_inode_ident_path(v9ses) && dentry && v9inode->path) { + if (ino_path_compare(V9FS_I(inode)->path, dentry)) { + p9_debug(P9_DEBUG_VFS, + "Reusing inode %p based on path match", inode); + return 1; + } + } + return 0; } static int v9fs_set_inode_dotl(struct inode *inode, void *data) { struct v9fs_inode *v9inode = V9FS_I(inode); - struct p9_stat_dotl *st = (struct p9_stat_dotl *)data; + struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); + struct iget_data *idata = data; + struct p9_stat_dotl *st = idata->st; + struct dentry *dentry = idata->dentry; memcpy(&v9inode->qid, &st->qid, sizeof(st->qid)); inode->i_generation = st->st_gen; + if (v9fs_inode_ident_path(v9ses)) { + if (dentry) { + v9inode->path = make_ino_path(dentry); + if (!v9inode->path) + return -ENOMEM; + } else { + v9inode->path = NULL; + } + } return 0; } @@ -97,19 +156,35 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb, struct p9_qid *qid, struct p9_fid *fid, struct p9_stat_dotl *st, + struct dentry *dentry, int new) { int retval; struct inode *inode; struct v9fs_session_info *v9ses = sb->s_fs_info; int (*test)(struct inode *inode, void *data); + struct iget_data data = { + .st = st, + .dentry = dentry, + }; + if (new) test = v9fs_test_new_inode_dotl; else test = v9fs_test_inode_dotl; - inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode_dotl, st); + if (v9fs_inode_ident_path(v9ses) && dentry) { + /* + * We have to take the rename_sem lock here as iget5_locked has + * spinlock in it (inode_hash_lock) + */ + down_read(&v9ses->rename_sem); + } + inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode_dotl, &data); + if (v9fs_inode_ident_path(v9ses) && dentry) + up_read(&v9ses->rename_sem); + if (!inode) return ERR_PTR(-ENOMEM); if (!(inode->i_state & I_NEW)) @@ -142,7 +217,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb, struct inode * v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, - struct super_block *sb, int new) + struct super_block *sb, struct dentry *dentry, int new) { struct p9_stat_dotl *st; struct inode *inode = NULL; @@ -151,7 +226,7 @@ v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, if (IS_ERR(st)) return ERR_CAST(st); - inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, new); + inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, dentry, new); kfree(st); return inode; } @@ -305,7 +380,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); goto out; } - inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); + inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, dentry); if (IS_ERR(inode)) { err = PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err); @@ -400,7 +475,7 @@ static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap, } /* instantiate inode and assign the unopened fid to the dentry */ - inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); + inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, dentry); if (IS_ERR(inode)) { err = PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", @@ -838,7 +913,7 @@ v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir, err); goto error; } - inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); + inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, dentry); if (IS_ERR(inode)) { err = PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index 489db161abc9..566d9ae6255f 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c @@ -139,7 +139,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags, else sb->s_d_op = &v9fs_dentry_operations; - inode = v9fs_get_new_inode_from_fid(v9ses, fid, sb); + inode = v9fs_get_new_inode_from_fid(v9ses, fid, sb, NULL); if (IS_ERR(inode)) { retval = PTR_ERR(inode); goto release_sb; @@ -151,6 +151,14 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags, goto release_sb; } sb->s_root = root; + + if (v9fs_inode_ident_path(v9ses)) { + /* Probably not necessary, just to satisfy lockdep_assert */ + down_read(&v9ses->rename_sem); + V9FS_I(inode)->path = make_ino_path(root); + up_read(&v9ses->rename_sem); + } + retval = v9fs_get_acl(inode, fid); if (retval) goto release_sb; From patchwork Sun Apr 6 20:43:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tingmao Wang X-Patchwork-Id: 14039516 Received: from flow-a4-smtp.messagingengine.com (flow-a4-smtp.messagingengine.com [103.168.172.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CB272E62A8 for ; Sun, 6 Apr 2025 20:45:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972357; cv=none; b=hWxlWVTnT/X9DEpSKLgo09xP2zfk8Bnfzd7V3Wu/hFUs/0I7/7Vkvn1hIUXkHihcgHFSXIhc2iZavf1+G3ovmKw7+2hDLs40rT+96Dakdf63ZQiFHsz4m7ac275Q21Oaxm+Hdn88yPx2YOmsIuzUtZygNy7DxRRI1i3DkYn9qLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972357; c=relaxed/simple; bh=3uJ5EzHzUXFc4cgnh3jo3P1fzJjtE38PfIqi7/I4yy0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MN/yj5GjRWhhCQUKgHO7rtV8GDTOVtNb7YEREmJUkbz08T8A2+sJZULmyNEDZ3Dqrvo1CZEFb4MdXsZ3nItrse4fY2iX83PCpMOnLQCIS0fOx1uc9i2jEx+tEnpzM6xytMW/af1kw3W1Nn4L3Nh+5ydxaJm9PboS+jML5CHvyC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org; spf=pass smtp.mailfrom=maowtm.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b=vmMCpyh9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uYiPJhxo; arc=none smtp.client-ip=103.168.172.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=maowtm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b="vmMCpyh9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uYiPJhxo" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailflow.phl.internal (Postfix) with ESMTP id B3640202428; Sun, 6 Apr 2025 16:45:54 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Sun, 06 Apr 2025 16:45:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maowtm.org; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1743972354; x= 1743975954; bh=7NkZxrLaz0tdouf7OofZ+jWLjRfRdYXGiNFcjQujXBs=; b=v mMCpyh95t0+6wtiLKuPDjpIWj61Yw5bOsrQ9RCh5997xnHjdtYBWZwA0ppDwpAMj crT6LptjN9pPJ1yaufvOSj71Yp8yCF067q9whifbCzYoSXdfOJZYFbaaP9Ar0hK4 xfXW7BHcNmv5mJ6rr+3MkUWtL+091nosTpZjV4XALddojLbLv3iudJu/WUzXva/P RNXZSmjZeJEEdC4fw3Ohn8Nhld07zg+Kqf7iDO4P6oIp9zQxKkESsIVrLosiDAV0 6m49wVWVF7Yh9RtkAdKbZ1m7mNeDnjg6k7Jxk9KK17LwDfCOHC29dUBlJ38n4gLt 9Eb47eY2HMy559bg2jOJA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743972354; x=1743975954; bh=7 NkZxrLaz0tdouf7OofZ+jWLjRfRdYXGiNFcjQujXBs=; b=uYiPJhxoWeZ4n8rRA VmuGTrz7zbr76pAimneNW3Zub2OQILGcpcyP/PSpfcwswhFgI3a+HguKVrU2Wq+q mtIoNa/sJk+6qouWKLOUDxyEHXJqrFe7oFHYveNFHNMkw8mdP8krN4yqaC5p80ih tTZf2MtQkmeM28CbnL1pKG65+8yrjUfp+/1+47u6mEEbtyFQIwxqFVEEgBNAkZsn ztN+NcE+4LkxiQLKu0L8bj39AU/k2GInb6FI/p33t+bYvVyOTT0CV8kcYofRy8PA jNEbs4+dfNflz4KowIP+MPBnuHOxzcjUE+6UJDzRVWgYQMtjW62uBTiH0bHytTb1 dBqIw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleekvdekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepvfhinhhgmhgrohcuhggrnhhguceomhesmhgrohifthhmrdhorhhgqe enucggtffrrghtthgvrhhnpeeuuddthefhhefhvdejteevvddvteefffegteetueegueel jeefueekjeetieeuleenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrih hlfhhrohhmpehmsehmrghofihtmhdrohhrghdpnhgspghrtghpthhtohepudefpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegvrhhitghvhheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheprghsmhgruggvuhhssegtohguvgifrhgvtghkrdhorhhgpdhrtghpthht oheplhhutghhohesihhonhhkohhvrdhnvghtpdhrtghpthhtoheplhhinhhugigpohhssh estghruhguvggshihtvgdrtghomhdprhgtphhtthhopehmsehmrghofihtmhdrohhrghdp rhgtphhtthhopehvlehfsheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhope hmihgtseguihhgihhkohgurdhnvghtpdhrtghpthhtohepghhnohgrtghksehgohhoghhl vgdrtghomhdprhgtphhtthhopehlihhnuhigqdhsvggtuhhrihhthidqmhhoughulhgvse hvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i580e4893:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 6 Apr 2025 16:45:48 -0400 (EDT) From: Tingmao Wang To: Eric Van Hensbergen , Dominique Martinet , Latchesar Ionkov , Christian Schoenebeck Cc: Tingmao Wang , v9fs@lists.linux.dev, =?utf-8?q?Micka=C3=AB?= =?utf-8?q?l_Sala=C3=BCn?= , =?utf-8?q?G=C3=BCnther_Noack?= , linux-security-module@vger.kernel.org, Jan Kara , Amir Goldstein , Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 2/6] fs/9p: add default option for path-based inodes Date: Sun, 6 Apr 2025 21:43:03 +0100 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: v9fs@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add an extra option to control the inode identification behaviour, and make path-based default. The reasoning for this default is that the current 9pfs already does not re-use inodes even for same qid.path, but because of the dcache, a file kept open by a process (by e.g. open, or having the directory as CWD) means that other processes will re-use that inode. If we identify inode by path by default, this behaviour is consistent regardless of whether files are kept open or not. In a future version, if we can negotiate with the server and be sure that it won't give us duplicate qid.path, the default for those cases can be qid-based (possibly re-merging commit 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")...?) Signed-off-by: Tingmao Wang --- fs/9p/v9fs.c | 33 ++++++++++++++++++++++++++++++++- fs/9p/v9fs.h | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index 77e9c4387c1d..487532295a98 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c @@ -36,7 +36,7 @@ enum { /* Options that take integer arguments */ Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid, /* String options */ - Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag, + Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag, Opt_inodeident, /* Options that take no arguments */ Opt_nodevmap, Opt_noxattr, Opt_directio, Opt_ignoreqv, /* Access options */ @@ -63,6 +63,7 @@ static const match_table_t tokens = { {Opt_access, "access=%s"}, {Opt_posixacl, "posixacl"}, {Opt_locktimeout, "locktimeout=%u"}, + {Opt_inodeident, "inodeident=%s"}, {Opt_err, NULL} }; @@ -149,6 +150,15 @@ int v9fs_show_options(struct seq_file *m, struct dentry *root) if (v9ses->flags & V9FS_NO_XATTR) seq_puts(m, ",noxattr"); + switch (v9ses->flags & V9FS_INODE_IDENT_MASK) { + case 0: + seq_puts(m, ",inodeident=none"); + break; + case V9FS_INODE_IDENT_PATH: + seq_puts(m, ",inodeident=path"); + break; + } + return p9_show_client_options(m, v9ses->clnt); } @@ -369,6 +379,25 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) v9ses->session_lock_timeout = (long)option * HZ; break; + case Opt_inodeident: + s = match_strdup(&args[0]); + if (!s) { + ret = -ENOMEM; + p9_debug(P9_DEBUG_ERROR, + "problem allocating copy of inodeident arg\n"); + goto free_and_return; + } + if (strcmp(s, "none") == 0) { + v9ses->flags &= ~V9FS_INODE_IDENT_MASK; + } else if (strcmp(s, "path") == 0) { + v9ses->flags |= V9FS_INODE_IDENT_PATH; + } else { + ret = -EINVAL; + p9_debug(P9_DEBUG_ERROR, "Unknown inodeident argument %s\n", s); + } + kfree(s); + break; + default: continue; } @@ -423,6 +452,8 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, v9ses->flags |= V9FS_PROTO_2000U; } + v9ses->flags |= V9FS_INODE_IDENT_PATH; + rc = v9fs_parse_options(v9ses, data); if (rc < 0) goto err_clnt; diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index 5c85923aa2dd..b4874fdd925e 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -31,6 +31,8 @@ #define V9FS_ACCESS_MASK V9FS_ACCESS_ANY #define V9FS_ACL_MASK V9FS_POSIX_ACL +#define V9FS_INODE_IDENT_MASK (V9FS_INODE_IDENT_PATH) + enum p9_session_flags { V9FS_PROTO_2000U = 0x01, V9FS_PROTO_2000L = 0x02, From patchwork Sun Apr 6 20:43:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tingmao Wang X-Patchwork-Id: 14039517 Received: from flow-a4-smtp.messagingengine.com (flow-a4-smtp.messagingengine.com [103.168.172.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA5562E62A8 for ; Sun, 6 Apr 2025 20:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972359; cv=none; b=PS9p7MXD5p6TWhKwpZLsB3FBgBCfeYgQtHlVDQdPTntd5xrwJe3XYHFJRMOex2s8ekwxX2TXHseWbQNBcZY5Z3LtW/Y1UBuslnhqtUXBnrN9iIt+zqWpf6mF11u/myv8L8V2kyTK22ZRKZnqSDRAt/JikZTFFR836zJzzX321Fk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972359; c=relaxed/simple; bh=7HGn0jib/kmR9d10MZQU3iiQIPjUSsHH+0CH7Imt00Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j3z2fV93CIHV0PRxu202yg8qi+5NmSB/dQNJ1qh0lgX2AcDp/ACBNTbg9Kxzg5WiBo62o+N9ZJxk9GMHYnK4/7Bk0iSDVvfDeo97A81faNgJx+8rtJjEQBMKuqlInUipGHJB1vL9fRFi5OnKmxNrTXRouFcvqDB7fAZEja58yXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org; spf=pass smtp.mailfrom=maowtm.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b=roZE7PJJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MG94ThnM; arc=none smtp.client-ip=103.168.172.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=maowtm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b="roZE7PJJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MG94ThnM" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailflow.phl.internal (Postfix) with ESMTP id 00937202430; Sun, 6 Apr 2025 16:45:57 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sun, 06 Apr 2025 16:45:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maowtm.org; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1743972356; x= 1743975956; bh=6go0t2my0vJ/oS1uBp4E6KCMY7Xbt6JkyoRL1HMo1Jw=; b=r oZE7PJJH6lR9H5rn+oSWMgKLkOC4CUE0pjhKTwdig/I02ZD4QJp9sUgZXhKDVFol qOQSF1Qja0befWOScKpSQJsKuw4TAzcuDEx42jWNIJyUvejqeKZHPItt1kAvcvXK G/ARVfPhXb0Kdae9nw7M4ZHt0AQSoMjH5qaMVj+jaxsbZmLz+55NE5l9+6AySni4 5ZAfNy4n+DFYA137z4hG79e2VLwaAb1mIFaiWq63cilqofFueZIAoNVK32Wtli5w /Npk9bgWksMf6+jjTAzocbE19/4Ts/rCSjJPiXrhpKs117d5rMD9ZxJZr9f9+fAe fknLVGlNbWgIdgOn3RR/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743972356; x=1743975956; bh=6 go0t2my0vJ/oS1uBp4E6KCMY7Xbt6JkyoRL1HMo1Jw=; b=MG94ThnMog4g/OtQ6 NMlnKKAQ0tiTuWwYic1mxv+J2tLU3UIU+ggDPNmbytmH9YMjUEGHRkv5CN5dyso2 SAT9MAK1BAqwcwim4/xvlwoZsWAaT354fJUgFP7y0TqcL7HBGk8z+ZEj2YfjhEq4 i8ZOSzlBCaWvypUM/kMkzcoO0ssxMQQyFUwPOaLCK8KPSi0aOn9mvW8PZzncHCJM XrPMjMRF7UTthwlERNK2Xb1iKQtbo8+S/q7OzEaXn4Q6kz8c19Dwq/Hqn7J1Qqk/ YDzL+NIp9bqHp2z/MwyLTb0Bq2f5aJ+aJi+tJbvbUrmak32cuNE7HspBZgD8UFvU 9NjZg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleekvdekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepvfhinhhgmhgrohcuhggrnhhguceomhesmhgrohifthhmrdhorhhgqe enucggtffrrghtthgvrhhnpeeuuddthefhhefhvdejteevvddvteefffegteetueegueel jeefueekjeetieeuleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehmsehmrghofihtmhdrohhrghdpnhgspghrtghpthhtohepudefpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegvrhhitghvhheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheprghsmhgruggvuhhssegtohguvgifrhgvtghkrdhorhhgpdhrtghpthht oheplhhutghhohesihhonhhkohhvrdhnvghtpdhrtghpthhtoheplhhinhhugigpohhssh estghruhguvggshihtvgdrtghomhdprhgtphhtthhopehmsehmrghofihtmhdrohhrghdp rhgtphhtthhopehvlehfsheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhope hmihgtseguihhgihhkohgurdhnvghtpdhrtghpthhtohepghhnohgrtghksehgohhoghhl vgdrtghomhdprhgtphhtthhopehlihhnuhigqdhsvggtuhhrihhthidqmhhoughulhgvse hvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i580e4893:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 6 Apr 2025 16:45:54 -0400 (EDT) From: Tingmao Wang To: Eric Van Hensbergen , Dominique Martinet , Latchesar Ionkov , Christian Schoenebeck Cc: Tingmao Wang , v9fs@lists.linux.dev, =?utf-8?q?Micka=C3=AB?= =?utf-8?q?l_Sala=C3=BCn?= , =?utf-8?q?G=C3=BCnther_Noack?= , linux-security-module@vger.kernel.org, Jan Kara , Amir Goldstein , Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 3/6] fs/9p: Hide inodeident=path from show_options as it is the default Date: Sun, 6 Apr 2025 21:43:04 +0100 Message-ID: <611ecb66e65699bce6696076e1c2e5933adb88c3.1743971855.git.m@maowtm.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: v9fs@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 I think it makes sense either way, not sure whether we should do this or not, but including this patch anyway. Signed-off-by: Tingmao Wang --- fs/9p/v9fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index 487532295a98..0070d1179021 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c @@ -155,7 +155,7 @@ int v9fs_show_options(struct seq_file *m, struct dentry *root) seq_puts(m, ",inodeident=none"); break; case V9FS_INODE_IDENT_PATH: - seq_puts(m, ",inodeident=path"); + /* default */ break; } From patchwork Sun Apr 6 20:43:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tingmao Wang X-Patchwork-Id: 14039518 Received: from flow-a4-smtp.messagingengine.com (flow-a4-smtp.messagingengine.com [103.168.172.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64E501624F7 for ; Sun, 6 Apr 2025 20:46:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972362; cv=none; b=QSNW1RXP7eL3ztmOnnFIU/qaI2X5UBAi1+izLXPJ7XLQFog3M0TDSvo6fQnp1m5QL04AQnPwuZiZ7LzmMgfcga7cROe2sucVqeHCoVemVNdIhtOPZppTmidlZjA35Eau3AvnE645E86etSbdO8+8tbvXS7DRQd/o32l/6z4OlF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972362; c=relaxed/simple; bh=0hchm3FeyjJjJO2HG5wfFrBkeFUETDnwqD5n55ge7xg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a4UWOoF7oAeOT4k5hr6Utl4x2Qp8m2rUpyr+R2vAp2fKhBXGufE7x8D/Gz3v61b3V8/wdoNN0Rmcy0GYRVAbAucCI1XZeT7Kb5bCw4N1bdHWRiusLOp3JuC1+B6XoJ6izr73vtI9kKG7FVBNYJg0LNJoP1dlwoI4Ddc9H8Cv++A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org; spf=pass smtp.mailfrom=maowtm.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b=RP7QWYON; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=A3brkeqZ; arc=none smtp.client-ip=103.168.172.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=maowtm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b="RP7QWYON"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="A3brkeqZ" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailflow.phl.internal (Postfix) with ESMTP id 7D0DB202428; Sun, 6 Apr 2025 16:45:59 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Sun, 06 Apr 2025 16:45:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maowtm.org; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1743972359; x= 1743975959; bh=POOHptp+/dVW3vm3gf8nE0D5rIirz3UAl7VbL7lUWo0=; b=R P7QWYONARZeHV3oUUpUNC9Lekb3TXY6Iy8nY+ueZT76ixRXcIamrQye0i96D8AWT tJyV9FLSas7RX6ciALTJm9Znqc+uCUErGTq8ChY4WLHaQqV02c06UKciulh6I+Rp rHTpe3TIREbZyWgz4xEtyqw6BGiofTN6aq4OSm0av8RBj4bbA/1nVJVw/PfATsyw vtKOszmmf3MQTATd4W971No56ujK6+f24kfytitanbEj8Zg47svg2pAbVM/iS3O4 WO8mJdVq0ma8ZwKZAIN9/fkx9p1tOWBiGIp059p63oJiwvqPGuusZCNb2gycnzP6 e0VfTk3WBv4SLRc1jq+5Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743972359; x=1743975959; bh=P OOHptp+/dVW3vm3gf8nE0D5rIirz3UAl7VbL7lUWo0=; b=A3brkeqZ7Hg1+NL3q GVCRN82m0/J8ux+/pT5TgINvOscQUHJBxGjunty6Lr629PBSFhn3l7n+LqwWNtvB kadNcnjDBtVtbZfjH4gGQc90qDU7+65I7vp0xM0YPXm5tRKTSt/2QOh+Kpel+1g2 l3j8JWsRjSKPWR83eBwx0GrQjtIdVSFQGRc5FvMWe84DLLevxswhTSV032aJ2tcT F6a0y/9BEBGYNDsf3IymgYab4smYdF9TW5/XXQBDBv+idN4+O8p9C/qzYVENNGPM TyVjF2j7RizmkeAHBksJCwyeLWRf4WOwdzgZylq39K1UE9ZeO1IhkZdJNgrdajB9 B/4gg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleekvdejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepvfhinhhgmhgrohcuhggrnhhguceomhesmhgrohifthhmrdhorhhgqe enucggtffrrghtthgvrhhnpeeuuddthefhhefhvdejteevvddvteefffegteetueegueel jeefueekjeetieeuleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehmsehmrghofihtmhdrohhrghdpnhgspghrtghpthhtohepudefpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegvrhhitghvhheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheprghsmhgruggvuhhssegtohguvgifrhgvtghkrdhorhhgpdhrtghpthht oheplhhutghhohesihhonhhkohhvrdhnvghtpdhrtghpthhtoheplhhinhhugigpohhssh estghruhguvggshihtvgdrtghomhdprhgtphhtthhopehmsehmrghofihtmhdrohhrghdp rhgtphhtthhopehvlehfsheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhope hmihgtseguihhgihhkohgurdhnvghtpdhrtghpthhtohepghhnohgrtghksehgohhoghhl vgdrtghomhdprhgtphhtthhopehlihhnuhigqdhsvggtuhhrihhthidqmhhoughulhgvse hvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i580e4893:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 6 Apr 2025 16:45:57 -0400 (EDT) From: Tingmao Wang To: Eric Van Hensbergen , Dominique Martinet , Latchesar Ionkov , Christian Schoenebeck Cc: Tingmao Wang , v9fs@lists.linux.dev, =?utf-8?q?Micka=C3=AB?= =?utf-8?q?l_Sala=C3=BCn?= , =?utf-8?q?G=C3=BCnther_Noack?= , linux-security-module@vger.kernel.org, Jan Kara , Amir Goldstein , Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 4/6] fs/9p: Add ability to identify inode by path for non-.L Date: Sun, 6 Apr 2025 21:43:05 +0100 Message-ID: <90f6c4c492821407bf0659e5fd16e94db8bf5143.1743971855.git.m@maowtm.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: v9fs@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This replicates the earlier .L patch for non-.L, and removing some previously inserted conditionals in shared code. Signed-off-by: Tingmao Wang --- fs/9p/v9fs.h | 7 +-- fs/9p/vfs_inode.c | 112 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 96 insertions(+), 23 deletions(-) diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index b4874fdd925e..3199d516dc8a 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -201,7 +201,8 @@ extern int v9fs_vfs_rename(struct mnt_idmap *idmap, unsigned int flags); extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, - struct super_block *sb, int new); + struct super_block *sb, + struct dentry *dentry, int new); extern const struct inode_operations v9fs_dir_inode_operations_dotl; extern const struct inode_operations v9fs_file_inode_operations_dotl; extern const struct inode_operations v9fs_symlink_inode_operations_dotl; @@ -258,7 +259,7 @@ v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, if (v9fs_proto_dotl(v9ses)) return v9fs_inode_from_fid_dotl(v9ses, fid, sb, dentry, 0); else - return v9fs_inode_from_fid(v9ses, fid, sb, 0); + return v9fs_inode_from_fid(v9ses, fid, sb, dentry, 0); } /** @@ -276,7 +277,7 @@ v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, if (v9fs_proto_dotl(v9ses)) return v9fs_inode_from_fid_dotl(v9ses, fid, sb, dentry, 1); else - return v9fs_inode_from_fid(v9ses, fid, sb, 1); + return v9fs_inode_from_fid(v9ses, fid, sb, dentry, 1); } #endif diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 72fd72a2ff06..1137a5960ac2 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -363,12 +363,18 @@ void v9fs_evict_inode(struct inode *inode) clear_inode(inode); } +struct iget_data { + struct p9_wstat *st; + struct dentry *dentry; +}; + static int v9fs_test_inode(struct inode *inode, void *data) { int umode; dev_t rdev; struct v9fs_inode *v9inode = V9FS_I(inode); - struct p9_wstat *st = (struct p9_wstat *)data; + struct p9_wstat *st = ((struct iget_data *)data)->st; + struct dentry *dentry = ((struct iget_data *)data)->dentry; struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); umode = p9mode2unixmode(v9ses, st, &rdev); @@ -386,26 +392,81 @@ static int v9fs_test_inode(struct inode *inode, void *data) if (v9inode->qid.path != st->qid.path) return 0; + + if (v9fs_inode_ident_path(v9ses)) { + if (!ino_path_compare(v9inode->path, dentry)) { + p9_debug(P9_DEBUG_VFS, "Refusing to reuse inode %p based on path mismatch", + inode); + return 0; + } + } + return 1; } static int v9fs_test_new_inode(struct inode *inode, void *data) { + int umode; + dev_t rdev; + struct v9fs_inode *v9inode = V9FS_I(inode); + struct p9_wstat *st = ((struct iget_data *)data)->st; + struct dentry *dentry = ((struct iget_data *)data)->dentry; + struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); + + umode = p9mode2unixmode(v9ses, st, &rdev); + /* + * Don't reuse inode of different type, even if we have + * inodeident=path and path matches. + */ + if (inode_wrong_type(inode, umode)) + return 0; + + /* + * We're only getting here if QID2INO stays the same anyway, so + * mirroring the qid checks in v9fs_test_inode + * (but maybe that check is unnecessary anyway? at least on 64bit) + */ + + if (v9inode->qid.path != st->qid.path) + return 0; + + if (v9inode->qid.type != st->qid.type) + return 0; + + if (v9fs_inode_ident_path(v9ses) && dentry && v9inode->path) { + if (ino_path_compare(V9FS_I(inode)->path, dentry)) { + p9_debug(P9_DEBUG_VFS, "Refusing to reuse inode %p based on path mismatch", + inode); + return 1; + } + } + return 0; } -static int v9fs_set_inode(struct inode *inode, void *data) +static int v9fs_set_inode(struct inode *inode, void *data) { struct v9fs_inode *v9inode = V9FS_I(inode); - struct p9_wstat *st = (struct p9_wstat *)data; + struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); + struct iget_data *idata = data; + struct p9_wstat *st = idata->st; + struct dentry *dentry = idata->dentry; memcpy(&v9inode->qid, &st->qid, sizeof(st->qid)); + if (v9fs_inode_ident_path(v9ses)) { + if (dentry) { + v9inode->path = make_ino_path(dentry); + if (!v9inode->path) + return -ENOMEM; + } else { + v9inode->path = NULL; + } + } return 0; } -static struct inode *v9fs_qid_iget(struct super_block *sb, - struct p9_qid *qid, - struct p9_wstat *st, +static struct inode *v9fs_qid_iget(struct super_block *sb, struct p9_qid *qid, + struct p9_wstat *st, struct dentry *dentry, int new) { dev_t rdev; @@ -414,13 +475,27 @@ static struct inode *v9fs_qid_iget(struct super_block *sb, struct inode *inode; struct v9fs_session_info *v9ses = sb->s_fs_info; int (*test)(struct inode *inode, void *data); + struct iget_data data = { + .st = st, + .dentry = dentry, + }; if (new) test = v9fs_test_new_inode; else test = v9fs_test_inode; - inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode, st); + if (v9fs_inode_ident_path(v9ses) && dentry) { + /* + * We have to take the rename_sem lock here as iget5_locked has + * spinlock in it (inode_hash_lock) + */ + down_read(&v9ses->rename_sem); + } + inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode, &data); + if (v9fs_inode_ident_path(v9ses) && dentry) + up_read(&v9ses->rename_sem); + if (!inode) return ERR_PTR(-ENOMEM); if (!(inode->i_state & I_NEW)) @@ -447,9 +522,9 @@ static struct inode *v9fs_qid_iget(struct super_block *sb, } -struct inode * -v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, - struct super_block *sb, int new) +struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses, + struct p9_fid *fid, struct super_block *sb, + struct dentry *dentry, int new) { struct p9_wstat *st; struct inode *inode = NULL; @@ -458,7 +533,7 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, if (IS_ERR(st)) return ERR_CAST(st); - inode = v9fs_qid_iget(sb, &st->qid, st, new); + inode = v9fs_qid_iget(sb, &st->qid, st, dentry, new); p9stat_free(st); kfree(st); return inode; @@ -608,10 +683,9 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, goto error; } /* - * Instantiate inode. On .L fs, pass in dentry for inodeident=path. + * Instantiate inode. Pass in dentry for inodeident=path. */ - inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, - v9fs_proto_dotl(v9ses) ? dentry : NULL); + inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, dentry); if (IS_ERR(inode)) { err = PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, @@ -738,19 +812,17 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, p9_fid_put(dfid); /* - * On .L fs, pass in dentry to v9fs_get_inode_from_fid in case it is - * needed by inodeident=path + * Pass in dentry to v9fs_get_inode_from_fid in case it is needed by + * inodeident=path */ if (fid == ERR_PTR(-ENOENT)) inode = NULL; else if (IS_ERR(fid)) inode = ERR_CAST(fid); else if (v9ses->cache & (CACHE_META | CACHE_LOOSE)) - inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb, - v9fs_proto_dotl(v9ses) ? dentry : NULL); + inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb, dentry); else - inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, - v9fs_proto_dotl(v9ses) ? dentry : NULL); + inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb, dentry); /* * If we had a rename on the server and a parallel lookup * for the new name, then make sure we instantiate with From patchwork Sun Apr 6 20:43:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tingmao Wang X-Patchwork-Id: 14039519 Received: from flow-a4-smtp.messagingengine.com (flow-a4-smtp.messagingengine.com [103.168.172.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD36E1B0F19 for ; Sun, 6 Apr 2025 20:46:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972364; cv=none; b=afOFMurtx8sPV5oQJ3TzRz7gKqFIwtz5aaGXH9zPHH96oY25ccoN1UGbA5NfaWWy5LBI/5Oy8zPx7y+EWtdOJyGPJBExcKsEIqyXMJ+rU4LwXY2flezMEtBqpq+yIEiKVUC0w59Pg6kiPQV9Nza2yCxSzZspFPTmDIO5khJI8Pg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972364; c=relaxed/simple; bh=hR94pmqglUX1HDCAhc0UZm/zg++tvdt+zW5ZJZPAMr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JYxXKGQ0XHiRPNoKylObGb/NO8dN7Hgp0FIYqM1yOvVTM3RCVwZT40yEBgJjp1r1rDb7N0SVC9CwFXoHO+4fUHOq3dX5fCKMNdovqWCHbpy26PonK8KXBn9kh6JbL6ekz/pvjGtzibhgDOnwHhGw2u5b78opCa9IqPGd7UC3MyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org; spf=pass smtp.mailfrom=maowtm.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b=bRgQ2tQp; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=T0tDGW2z; arc=none smtp.client-ip=103.168.172.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=maowtm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b="bRgQ2tQp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="T0tDGW2z" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailflow.phl.internal (Postfix) with ESMTP id D78F6202430; Sun, 6 Apr 2025 16:46:01 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Sun, 06 Apr 2025 16:46:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maowtm.org; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1743972361; x= 1743975961; bh=90xMjucamVsewCSQDP8SkIIi9Yg3hTLJZtFtNjvjA/o=; b=b RgQ2tQpB5siKPyAeJ82ADpl/dRdmJ7HVy1HwuqWjUhWvxs8GqT6Onhv0Ho6F1v1g neyVSl7zpUmYTkvwPPGdrF5mWLgn3WvbJ0kuqBoXQfMjkMiP8TDFke+W4GEarfzW 9cdM5uZ7qv+oZtE8niooffj4qn2Xsq5pvB5GDVrrSggjUxQGalSk/wqqbasFrSUr SOCjph6i2mYBev0OPe7UEMEkeZ2MS7BLP2b7z3wLaBCRwrKR/Ux5d2e5rdvoViKD 7TL4a+iDcnEAYeiRk9PToSzAgb7FGEq/xj2io4+iKeOx7pjwPFOFnYQctFV6TYlo 5hPCrjoDsdXFznLLa97lg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743972361; x=1743975961; bh=9 0xMjucamVsewCSQDP8SkIIi9Yg3hTLJZtFtNjvjA/o=; b=T0tDGW2zHORFDFzbR hhmwqdaE9h6uaQqBiq6YVm8jHPsZlysXwp23GL5BEPrp+Ba7nq3DUZdyZKRvPeFe e1vvsBwOLUuCs5ml6u9bKBqaD9Iu/OS3u/KzIMsi9hdR4XOGEQdUUGBwrqT0Q5Ku Jq/5fk8x2hkkX2dDtOTSy27qHNH1N3QkytJVzdZovoc6dtdQ71Uc0p096tzVgEl0 WzZ93O1ZfgdSHl04so/wcKl6cj+vAeAl/VX+vUX24bilEcO3QlA1O5PJiZNIozgQ Diq4Nylvy3A+yfsFxby/ERs8BCeIKqFih/J5SAnHD7yBgXvvq4a3/qMhB5CdLODY A34uQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleekvdejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepvfhinhhgmhgrohcuhggrnhhguceomhesmhgrohifthhmrdhorhhgqe enucggtffrrghtthgvrhhnpeeuuddthefhhefhvdejteevvddvteefffegteetueegueel jeefueekjeetieeuleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehmsehmrghofihtmhdrohhrghdpnhgspghrtghpthhtohepudefpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegvrhhitghvhheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheprghsmhgruggvuhhssegtohguvgifrhgvtghkrdhorhhgpdhrtghpthht oheplhhutghhohesihhonhhkohhvrdhnvghtpdhrtghpthhtoheplhhinhhugigpohhssh estghruhguvggshihtvgdrtghomhdprhgtphhtthhopehmsehmrghofihtmhdrohhrghdp rhgtphhtthhopehvlehfsheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhope hmihgtseguihhgihhkohgurdhnvghtpdhrtghpthhtohepghhnohgrtghksehgohhoghhl vgdrtghomhdprhgtphhtthhopehlihhnuhigqdhsvggtuhhrihhthidqmhhoughulhgvse hvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i580e4893:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 6 Apr 2025 16:45:59 -0400 (EDT) From: Tingmao Wang To: Eric Van Hensbergen , Dominique Martinet , Latchesar Ionkov , Christian Schoenebeck Cc: Tingmao Wang , v9fs@lists.linux.dev, =?utf-8?q?Micka=C3=AB?= =?utf-8?q?l_Sala=C3=BCn?= , =?utf-8?q?G=C3=BCnther_Noack?= , linux-security-module@vger.kernel.org, Jan Kara , Amir Goldstein , Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 5/6] fs/9p: .L: Refresh stale inodes on reuse Date: Sun, 6 Apr 2025 21:43:06 +0100 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: v9fs@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Only for uncached mode for now. We will need to revisit this for cached mode once we sort out reusing an old inode with changed qid.version. Note that v9fs_test(_new)?_inode_dotl already makes sure we don't reuse inodes of the wrong type or different qid. Signed-off-by: Tingmao Wang --- fs/9p/vfs_inode_dotl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index c1cc3553f2fb..20434a25cb22 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -187,8 +187,23 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb, if (!inode) return ERR_PTR(-ENOMEM); - if (!(inode->i_state & I_NEW)) + if (!(inode->i_state & I_NEW)) { + /* + * If we're returning an existing inode, we might as well refresh + * it with the metadata we just got. Refreshing the i_size also + * prevents read errors. + * + * We only do this for uncached mode, since in cached move, any + * change on the inode will bump qid.version, which will result in + * us getting a new inode in the first place. If we got an old + * inode, let's not touch it for now. + */ + if (new) { + v9fs_stat2inode_dotl(st, inode, + (v9ses->cache & CACHE_LOOSE) ? V9FS_STAT2INODE_KEEP_ISIZE : 0); + } return inode; + } /* * initialize the inode with the stat info * FIXME!! we may need support for stale inodes From patchwork Sun Apr 6 20:43:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tingmao Wang X-Patchwork-Id: 14039520 Received: from flow-a4-smtp.messagingengine.com (flow-a4-smtp.messagingengine.com [103.168.172.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7FDC186E20 for ; Sun, 6 Apr 2025 20:46:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972366; cv=none; b=hB6aKVjtjSEeEC3+ZSjdBB2CgFhphFyFQMoQ0zhFesvu9r8sUIUuhToOR9DkB3nkdZWWn+UH6IP0WXYFeNDrPIy61dAG1xIDR5YGq+okHEje9MlRZ+o0aq0IP9tkn0Dt68JvByxKfyKzHrofzU0IpPxgnZS42sfrkMs22D4IKbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743972366; c=relaxed/simple; bh=WBJTNTYjycyxp1ti192OEN39iD9bsjfkFPcfWB+pqBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CvciJDcd/rzGVjsYHapiBARDzCTDjJvi/jM4HJG8TxEf6nfaIvC13J8gtCPxLJu/khu5CoALYySRYM5383a/B5kYpV13gOILb+9m8KdvxtJrcQD935zGZEBQzrn+ef2gdtMMdFoyVd8HmBQeykUwQn1RV7RZSM+Fe/CoMgzHN0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org; spf=pass smtp.mailfrom=maowtm.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b=KTCzxLKz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lUJP7ILA; arc=none smtp.client-ip=103.168.172.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=maowtm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=maowtm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=maowtm.org header.i=@maowtm.org header.b="KTCzxLKz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lUJP7ILA" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailflow.phl.internal (Postfix) with ESMTP id EBAC1202428; Sun, 6 Apr 2025 16:46:03 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Sun, 06 Apr 2025 16:46:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maowtm.org; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1743972363; x= 1743975963; bh=ygHy4tWC00SI2EYsxDY2Q33xgQ0DwhcTe1RbaWpNvdI=; b=K TCzxLKznBd0TKZD8GtPqhv7yuPovdwLeDrBhtgLK4X0JB8hO/sZ7PpnYEShqvOMi UWUfCyF626POe4hK0h+D7FAKqu76g6ZNZRzdUXERu3Z733RNcV3XlM1WgYoVk4YE thcE+81LnUaUechPPZ61/OiGBdT9D/rM+ScTFSk2qR6tNUZc7WqZ91xdhkWjEwld yGT+77BrGaEHeGxAfBg/72pOv0wHMK3Uvx5MYMOukcyjNV8k7DuXHea2sT1h2GjL 6tX7HC4xUJP/xdLQ1zRCYDXlYPIW5bO4Zn6lgBV94N96gxm8AlIzOVUcBL4CNsQ1 sNmZzl71jvZgeYo9hBFag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743972363; x=1743975963; bh=y gHy4tWC00SI2EYsxDY2Q33xgQ0DwhcTe1RbaWpNvdI=; b=lUJP7ILAF/EgPoXAO Znqn6os9HnSdDtmGt+y7Mq91rFGaSSjkh4VCMCv/NnVuxSyVYxG6LDPJblO/mWNN 5kZiXovBeGq23LynvFEdlullEyZnXRwj1M1eXDZ6F8KvkurB9sju1rwLR1pVftdC ZDM44lRgtTVbZGA/ewxAFupiZza5G9z+Sv4pqsl1tp13ljojHuDyswdD0/qW4U8j m+3Zuc26roWnG2WHIlZQdkmJz2rkYWRmA9NI67oqie8yf9OMpYjJ+uNh0kuetu4Y 4tCu9SoQbriTgsgQ7zjioAiHcLz3v8q14ZtrCgSUjC43ICJLKofCSRS4ldlLXMpI +TAdA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleekvdejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepvfhinhhgmhgrohcuhggrnhhguceomhesmhgrohifthhmrdhorhhgqe enucggtffrrghtthgvrhhnpeeuuddthefhhefhvdejteevvddvteefffegteetueegueel jeefueekjeetieeuleenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrih hlfhhrohhmpehmsehmrghofihtmhdrohhrghdpnhgspghrtghpthhtohepudefpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegvrhhitghvhheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheprghsmhgruggvuhhssegtohguvgifrhgvtghkrdhorhhgpdhrtghpthht oheplhhutghhohesihhonhhkohhvrdhnvghtpdhrtghpthhtoheplhhinhhugigpohhssh estghruhguvggshihtvgdrtghomhdprhgtphhtthhopehmsehmrghofihtmhdrohhrghdp rhgtphhtthhopehvlehfsheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhope hmihgtseguihhgihhkohgurdhnvghtpdhrtghpthhtohepghhnohgrtghksehgohhoghhl vgdrtghomhdprhgtphhtthhopehlihhnuhigqdhsvggtuhhrihhthidqmhhoughulhgvse hvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i580e4893:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 6 Apr 2025 16:46:02 -0400 (EDT) From: Tingmao Wang To: Eric Van Hensbergen , Dominique Martinet , Latchesar Ionkov , Christian Schoenebeck Cc: Tingmao Wang , v9fs@lists.linux.dev, =?utf-8?q?Micka=C3=AB?= =?utf-8?q?l_Sala=C3=BCn?= , =?utf-8?q?G=C3=BCnther_Noack?= , linux-security-module@vger.kernel.org, Jan Kara , Amir Goldstein , Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 6/6] fs/9p: non-.L: Refresh stale inodes on reuse Date: Sun, 6 Apr 2025 21:43:07 +0100 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: v9fs@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This replicates the previous .L commit for non-.L Signed-off-by: Tingmao Wang --- fs/9p/vfs_inode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 1137a5960ac2..3f087b0bf1bf 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -498,8 +498,14 @@ static struct inode *v9fs_qid_iget(struct super_block *sb, struct p9_qid *qid, if (!inode) return ERR_PTR(-ENOMEM); - if (!(inode->i_state & I_NEW)) + if (!(inode->i_state & I_NEW)) { + /* See explanation in v9fs_qid_iget_dotl */ + if (new) { + v9fs_stat2inode(st, inode, sb, + (v9ses->cache & CACHE_LOOSE) ? V9FS_STAT2INODE_KEEP_ISIZE : 0); + } return inode; + } /* * initialize the inode with the stat info * FIXME!! we may need support for stale inodes