From: Christian Schoenebeck <linux_oss@crudebyte.com>
To: asmadeus@codewreck.org
Cc: David Kahurani <k.kahurani@gmail.com>,
davem@davemloft.net, ericvh@gmail.com, kuba@kernel.org,
linux-kernel@vger.kernel.org, lucho@ionkov.net,
netdev@vger.kernel.org, v9fs-developer@lists.sourceforge.net,
David Howells <dhowells@redhat.com>, Greg Kurz <groug@kaod.org>
Subject: Re: 9p fs-cache tests/benchmark (was: 9p fscache Duplicate cookie detected)
Date: Fri, 01 Apr 2022 16:19:20 +0200 [thread overview]
Message-ID: <1866935.Y7JIjT2MHT@silver> (raw)
In-Reply-To: <YkTP/Talsy3KQBbf@codewreck.org>
On Mittwoch, 30. März 2022 23:47:41 CEST asmadeus@codewreck.org wrote:
> Thanks Christian!
>
> Christian Schoenebeck wrote on Wed, Mar 30, 2022 at 02:21:16PM +0200:
[...]
> > > Christian Schoenebeck wrote on Sat, Mar 26, 2022 at 01:36:31PM +0100:
> > > hm, fscache code shouldn't be used for cache=mmap, I'm surprised you can
> > > hit this...
> >
> > I assume that you mean that 9p driver does not explicitly ask for fs-cache
> > being used for mmap. I see that 9p uses the kernel's generalized mmap
> > implementation:
> >
> > https://github.com/torvalds/linux/blob/d888c83fcec75194a8a48ccd283953bdba7
> > b2550/fs/9p/vfs_file.c#L481
> >
> > I haven't dived further into this, but the kernel has to use some kind of
> > filesystem cache anyway to provide the mmap functionality, so I guess it
> > makes sense that I got those warning messages from the FS-Cache
> > subsystem?
> It uses the generic mmap which has vfs caching, but definitely not
> fs-cache.
> fs-cache adds more hooks for cachefilesd (writing file contents to disk
> for bigger cache) and things like that cache=loose/mmap shouldn't be
> caring about. cache=loose actually just disables some key parts so I'm
> not surprised it shares bugs with the new code, but cache=mmap is really
> independant and I need to trace where these come from...
From looking at the sources, the call stack for emitting "FS-Cache: Duplicate
cookie detected" error messages with 9p "cache=mmap" option seems to be:
1. v9fs_vfs_lookup [fs/9p/vfs_inode.c, 788]:
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
2. v9fs_get_new_inode_from_fid [fs/9p/v9fs.h, 228]:
return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1);
3. v9fs_inode_from_fid_dotl [fs/9p/vfs_inode_dotl.c, 157]:
inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, new);
4. v9fs_qid_iget_dotl [fs/9p/vfs_inode_dotl.c, 133]:
v9fs_cache_inode_get_cookie(inode);
^--- Called independent of function argument "new"'s value here
https://github.com/torvalds/linux/blob/e8b767f5e04097aaedcd6e06e2270f9fe5282696/fs/9p/vfs_inode_dotl.c#L133
5. v9fs_cache_inode_get_cookie [fs/9p/cache.c, 68]:
v9inode->fscache =
fscache_acquire_cookie(v9fs_session_cache(v9ses),
0,
&path, sizeof(path),
&version, sizeof(version),
i_size_read(&v9inode->vfs_inode));
6. fscache_acquire_cookie [include/linux/fscache.h, 251]:
return __fscache_acquire_cookie(volume, advice,
index_key, index_key_len,
aux_data, aux_data_len,
object_size);
7. __fscache_acquire_cookie [fs/fscache/cookie.c, 472]:
if (!fscache_hash_cookie(cookie)) {
fscache_see_cookie(cookie, fscache_cookie_discard);
fscache_free_cookie(cookie);
return NULL;
}
8. fscache_hash_cookie [fs/fscache/cookie.c, 430]:
pr_err("Duplicate cookie detected\n");
> > With QEMU >= 5.2 you should see the following QEMU warning with your
> > reproducer:
> >
> > "
> > qemu-system-x86_64: warning: 9p: Multiple devices detected in same VirtFS
> > export, which might lead to file ID collisions and severe misbehaviours on
> > guest! You should either use a separate export for each device shared from
> > host or use virtfs option 'multidevs=remap'!
> > "
>
> oh, I wasn't aware of the new option. Good job there!
>
> It's the easiest way to reproduce but there are also harder to fix
> collisions, file systems only guarantee unicity for (fsid,inode
> number,version) which is usually bigger than 128 bits (although version
> is often 0), but version isn't exposed to userspace easily...
> What we'd want for unicity is handle from e.g. name_to_handle_at but
> that'd add overhead, wouldn't fit in qid path and not all fs are capable
> of providing one... The 9p protocol just doesn't want bigger handles
> than qid path.
No bigger qid.path on 9p protocol level in future? Why?
> And, err, looking at the qemu code
>
> qidp->version = stbuf->st_mtime ^ (stbuf->st_size << 8);
>
> so the qid is treated as "data version",
> but on kernel side we've treated it as inode version (i_version, see
> include/linux/iversion.h)
>
> (v9fs_test_inode_dotl checks the version is the same when comparing two
> inodes) so it will incorrectly identify two identical inodes as
> different.
> That will cause problems...
> Since you'll be faster than me could you try keeping it at 0 there?
I tried with your suggested change on QEMU side:
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index a6d6b3f835..5d9be87758 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -981,7 +981,7 @@ static int stat_to_qid(V9fsPDU *pdu, const struct stat *stbuf, V9fsQID *qidp)
memcpy(&qidp->path, &stbuf->st_ino, size);
}
- qidp->version = stbuf->st_mtime ^ (stbuf->st_size << 8);
+ qidp->version = 0;
qidp->type = 0;
if (S_ISDIR(stbuf->st_mode)) {
qidp->type |= P9_QID_TYPE_DIR;
Unfortunately it did not make any difference for these 2 Linux kernel fs-cache
issues at least; still same errors, and same suboptimal performance.
Best regards,
Christian Schoenebeck
next prev parent reply other threads:[~2022-04-01 14:19 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAAZOf26g-L2nSV-Siw6mwWQv1nv6on8c0fWqB4bKmX73QAFzow@mail.gmail.com>
2022-03-26 11:46 ` [syzbot] WARNING in p9_client_destroy David Kahurani
2022-03-26 11:48 ` Christian Schoenebeck
2022-03-26 12:24 ` asmadeus
2022-03-26 12:36 ` Christian Schoenebeck
2022-03-26 13:35 ` 9p fscache Duplicate cookie detected (Was: [syzbot] WARNING in p9_client_destroy) asmadeus
2022-03-30 12:21 ` 9p fs-cache tests/benchmark (was: 9p fscache Duplicate cookie detected) Christian Schoenebeck
2022-03-30 21:47 ` asmadeus
2022-04-01 14:19 ` Christian Schoenebeck [this message]
2022-04-01 23:11 ` asmadeus
2022-04-02 12:43 ` Christian Schoenebeck
2022-04-11 8:10 ` David Howells
2022-04-11 7:59 ` David Howells
2022-04-09 11:16 ` Christian Schoenebeck
2022-04-10 16:18 ` Christian Schoenebeck
2022-04-10 22:54 ` asmadeus
2022-04-11 13:41 ` Christian Schoenebeck
2022-04-12 22:38 ` asmadeus
2022-04-14 12:44 ` Christian Schoenebeck
2022-04-17 12:56 ` asmadeus
2022-04-17 13:52 ` Christian Schoenebeck
2022-04-17 21:22 ` asmadeus
2022-04-17 22:17 ` 9p EBADF with cache enabled (Was: 9p fs-cache tests/benchmark (was: 9p fscache Duplicate cookie detected)) asmadeus
2022-04-21 10:36 ` David Howells
2022-04-21 11:36 ` Christian Schoenebeck
2022-04-22 13:13 ` asmadeus
2022-04-25 14:10 ` David Howells
2022-04-26 15:38 ` Christian Schoenebeck
2022-05-03 10:21 ` asmadeus
2022-05-04 18:33 ` Christian Schoenebeck
2022-05-04 21:48 ` asmadeus
2022-05-06 19:14 ` Christian Schoenebeck
2022-06-03 16:46 ` Christian Schoenebeck
2022-06-12 10:02 ` asmadeus
2022-06-14 3:38 ` [PATCH] 9p: fix EBADF errors in cached mode Dominique Martinet
2022-06-14 3:41 ` Dominique Martinet
2022-06-14 12:10 ` Christian Schoenebeck
2022-06-14 12:45 ` Dominique Martinet
2022-06-14 14:11 ` Christian Schoenebeck
2022-06-16 13:35 ` Christian Schoenebeck
2022-06-16 13:51 ` Dominique Martinet
2022-06-16 14:11 ` Dominique Martinet
2022-06-16 20:14 ` Christian Schoenebeck
2022-06-16 20:53 ` Dominique Martinet
2022-06-16 21:10 ` [PATCH v3] " Dominique Martinet
2022-06-20 12:47 ` Christian Schoenebeck
2022-06-20 20:34 ` Dominique Martinet
2022-06-21 12:13 ` Christian Schoenebeck
2022-06-16 13:52 ` [PATCH v2] " Dominique Martinet
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=1866935.Y7JIjT2MHT@silver \
--to=linux_oss@crudebyte.com \
--cc=asmadeus@codewreck.org \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=ericvh@gmail.com \
--cc=groug@kaod.org \
--cc=k.kahurani@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lucho@ionkov.net \
--cc=netdev@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.