From: Christian Schoenebeck <linux_oss@crudebyte.com>
To: Eric Van Hensbergen <ericvh@gmail.com>,
Latchesar Ionkov <lucho@ionkov.net>,
Dominique Martinet <asmadeus@codewreck.org>,
Tyler Hicks <tyhicks@linux.microsoft.com>
Cc: Jianyong Wu <jianyong.wu@arm.com>,
v9fs-developer@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/5] 9p: Fix refcounting during full path walks for fid lookups
Date: Mon, 30 May 2022 19:14:43 +0200 [thread overview]
Message-ID: <43525959.9j6oIFhYhY@silver> (raw)
In-Reply-To: <20220527000003.355812-2-tyhicks@linux.microsoft.com>
On Freitag, 27. Mai 2022 01:59:59 CEST Tyler Hicks wrote:
> Decrement the refcount of the parent dentry's fid after walking
> each path component during a full path walk for a lookup. Failure to do
> so can lead to fids that are not clunked until the filesystem is
> unmounted, as indicated by this warning:
>
> 9pnet: found fid 3 not clunked
That explains why I saw so many fids not being clunked with recent Linux
kernel versions while doing some 9p protocol debugging with QEMU recently.
> The improper refcounting after walking resulted in open(2) returning
> -EIO on any directories underneath the mount point when using the virtio
> transport. When using the fd transport, there's no apparent issue until
> the filesytem is unmounted and the warning above is emitted to the logs.
Actually I never saw that open() = -EIO error. Do you have a reproducer?
> In some cases, the user may not yet be attached to the filesystem and a
> new root fid, associated with the user, is created and attached to the
> root dentry before the full path walk is performed. Increment the new
> root fid's refcount to two in that situation so that it can be safely
> decremented to one after it is used for the walk operation. The new fid
> will still be attached to the root dentry when
> v9fs_fid_lookup_with_uid() returns so a final refcount of one is
> correct/expected.
>
> Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tyler Hicks <tyhicks@linux.microsoft.com>
> ---
> fs/9p/fid.c | 17 +++++------------
> 1 file changed, 5 insertions(+), 12 deletions(-)
>
> diff --git a/fs/9p/fid.c b/fs/9p/fid.c
> index 79df61fe0e59..5a469b79c1ee 100644
> --- a/fs/9p/fid.c
> +++ b/fs/9p/fid.c
> @@ -152,7 +152,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct
> dentry *dentry, const unsigned char **wnames, *uname;
> int i, n, l, clone, access;
> struct v9fs_session_info *v9ses;
> - struct p9_fid *fid, *old_fid = NULL;
> + struct p9_fid *fid, *old_fid;
>
> v9ses = v9fs_dentry2v9ses(dentry);
> access = v9ses->flags & V9FS_ACCESS_MASK;
> @@ -194,13 +194,12 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct
> dentry *dentry, if (IS_ERR(fid))
> return fid;
>
> + refcount_inc(&fid->count);
> v9fs_fid_add(dentry->d_sb->s_root, fid);
> }
> /* If we are root ourself just return that */
> - if (dentry->d_sb->s_root == dentry) {
> - refcount_inc(&fid->count);
> + if (dentry->d_sb->s_root == dentry)
> return fid;
> - }
Hmm, wouldn't it then be possible that the root fid is returned with refcount
being 2 here?
> /*
> * Do a multipath walk with attached root.
> * When walking parent we need to make sure we
> @@ -212,6 +211,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct
> dentry *dentry, fid = ERR_PTR(n);
> goto err_out;
> }
> + old_fid = fid;
> clone = 1;
> i = 0;
> while (i < n) {
> @@ -221,15 +221,8 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct
> dentry *dentry, * walk to ensure none of the patch component change
> */
> fid = p9_client_walk(fid, l, &wnames[i], clone);
> + p9_client_clunk(old_fid);
> if (IS_ERR(fid)) {
> - if (old_fid) {
> - /*
> - * If we fail, clunk fid which are
mapping
> - * to path component and not the last
component
> - * of the path.
> - */
> - p9_client_clunk(old_fid);
> - }
> kfree(wnames);
> goto err_out;
> }
So this is the actual fix mentioned in the commit log. Makes sense.
Nitpicking: Wouldn't it be a bit cleaner to set old_fid solely within the
while loop and just before overwriting fid? And as we now have bumped to
-std=C11, probably making old_fid a local variable within loop scope only?
Best regards,
Christian Schoenebeck
next prev parent reply other threads:[~2022-05-30 17:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-26 23:59 [PATCH v2 0/5] 9p: Fix refcounting and improve readability in lookup Tyler Hicks
2022-05-26 23:59 ` [PATCH v2 1/5] 9p: Fix refcounting during full path walks for fid lookups Tyler Hicks
2022-05-30 17:14 ` Christian Schoenebeck [this message]
2022-05-31 14:28 ` Tyler Hicks
2022-06-01 14:28 ` Christian Schoenebeck
2022-06-07 3:41 ` Tyler Hicks
2022-06-09 12:44 ` Christian Schoenebeck
2022-06-11 12:46 ` Dominique Martinet
2022-06-11 23:17 ` Dominique Martinet
2022-06-13 19:38 ` Tyler Hicks
2022-05-27 0:00 ` [PATCH v2 2/5] 9p: Track the root fid with its own variable during lookups Tyler Hicks
2022-05-27 0:00 ` [PATCH v2 3/5] 9p: Make the path walk logic more clear about when cloning is required Tyler Hicks
2022-05-27 0:00 ` [PATCH v2 4/5] 9p: Remove unnecessary variable for old fids while walking from d_parent Tyler Hicks
2022-05-27 0:00 ` [PATCH v2 5/5] 9p: Fix minor typo in code comment Tyler Hicks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43525959.9j6oIFhYhY@silver \
--to=linux_oss@crudebyte.com \
--cc=asmadeus@codewreck.org \
--cc=ericvh@gmail.com \
--cc=jianyong.wu@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lucho@ionkov.net \
--cc=tyhicks@linux.microsoft.com \
--cc=v9fs-developer@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox