From: David Laight <david.laight.linux@gmail.com>
To: Dominique Martinet <asmadeus@codewreck.org>
Cc: Pierre Barre <pierre@barre.sh>,
Eric Van Hensbergen <ericvh@kernel.org>,
Latchesar Ionkov <lucho@ionkov.net>,
Christian Schoenebeck <linux_oss@crudebyte.com>,
v9fs@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] 9p: use kvzalloc for readdir buffer
Date: Thu, 16 Apr 2026 10:18:12 +0100 [thread overview]
Message-ID: <20260416101812.59e857d3@pumpkin> (raw)
In-Reply-To: <aeBJ5pT0WtMp-LO5@codewreck.org>
On Thu, 16 Apr 2026 11:31:02 +0900
Dominique Martinet <asmadeus@codewreck.org> wrote:
> David Laight wrote on Wed, Apr 15, 2026 at 11:36:25AM +0100:
> > > Perhaps what you describe can explain what I was seeing there:
> > > https://lore.kernel.org/v9fs/496d10b9-40fe-4f81-8014-37497c37ff63@app.fastmail.com/
> > (After seeking, getdents() returns stale cached entries instead of fetching from the new position.)
> >
> > Absolutely.
> > But the fix probably isn't trivial.
> > The offset that you need for the seek isn't directly related to the number
> > of bytes copied to the user buffer - which is what I suspect ftell() (or
> > whatever gets used) returns.
> > I think there is some mechanism for arbitrary directory offsets; but IIRC that
> > requires the code put the 'file system offset for the next directory entry'
> > somewhere in the directory entry.
> > Such an offset would have to be one the remote system would understand.
> >
> > A partial 'non-fix' would be to reject seeks to other than offset 0.
>
>
> Thank you both for working on this and reviewing -- this is all
> historical code that hasn't seen much love.
>
>
> 9p Treaddir sends an offset on each call, so I think it'd be fine to
> invalidate buffer/remember whatever the client set in a custom llseek
> function and send this to the server on readdir call, but I honestly
> didn't give this any more thought than the past 2 mintes (I'm totally
> swamped and can't keep up/didn't even notice the bug report this
> december, sorry :/)
The problem is you need to get the correct offsets for the various calls.
So the directory entry sent to the user needs the correct offset the
server would use for the (next) directory entry.
If the latter aren't byte offsets into the buffer it probably impossible.
I have a vague recollection of some fs encoding 'directory block number'
and 'offset in directory block' into the 'file offset' for directory fd.
> I think some filesystems only allow seeks to 0 already? So given there
> is a precendent this might be fine, but I don't see the harm in allowing
> custom offsets: the server needs to be able to deal with junk offsets in
> read requests anyway, so it's not a problem for me if userspace can set
> something invalid and get itself stuck on EINVAL or whatever.
>
>
> As for locking the vfs takes the file's f_lock for seek, but there
> doesn't seem to be anything in the readdir path that would do that, so I
> guess it probably would blow up with parallel readdirs on the same fd,
> and could use improving...
There might be something, file->offset needs protecting for readdir()
the same as for read() (but not pread()).
At least once (for some filesystem on some unix variant) readdir() would
have been pretty much the same as read().
David
>
prev parent reply other threads:[~2026-04-16 9:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 5:45 [PATCH] 9p: use kvzalloc for readdir buffer Pierre Barre
2026-04-15 9:01 ` David Laight
2026-04-15 9:27 ` Pierre Barre
2026-04-15 10:36 ` David Laight
2026-04-16 2:31 ` Dominique Martinet
2026-04-16 9:18 ` David Laight [this message]
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=20260416101812.59e857d3@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=asmadeus@codewreck.org \
--cc=ericvh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=pierre@barre.sh \
--cc=v9fs@lists.linux.dev \
/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