From: Christian Schoenebeck <linux_oss@crudebyte.com>
To: Christoph Hellwig <hch@infradead.org>,
Dominique Martinet <asmadeus@codewreck.org>
Cc: Eric Van Hensbergen <ericvh@kernel.org>,
Latchesar Ionkov <lucho@ionkov.net>,
v9fs@lists.linux.dev, linux-kernel@vger.kernel.org,
David Howells <dhowells@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
linux-fsdevel@vger.kernel.org,
Chris Arges <carges@cloudflare.com>
Subject: Re: [PATCH] 9p/virtio: restrict page pinning to user_backed_iter() iovec
Date: Mon, 15 Dec 2025 12:16:07 +0100 [thread overview]
Message-ID: <3918430.kQq0lBPeGt@weasel> (raw)
In-Reply-To: <aT-59HURCGPDUJnZ@codewreck.org>
On Monday, 15 December 2025 08:34:12 CET Dominique Martinet wrote:
> Thanks for having a look
>
> Christoph Hellwig wrote on Sun, Dec 14, 2025 at 09:55:12PM -0800:
> > > Ok, I don't understand why the current code locks everything down and
> > > wants to use a single scatterlist shared for the whole channel (and
> > > capped to 128 pages?), it should only need to lock around the
> > > virtqueue_add_sg() call, I'll need to play with that some more.
> >
> > What do you mean with "lock down"?
>
> Just the odd (to me) use of the chan->lock around basically all of
> p9_virtio_request() and most of p9_virtio_zc_request() -- I'm not pretty
> sure this was just the author trying to avoid an allocation by recycling
> the chan->sg array around though, so ignore this.
The lock protects the channel wide, shared scatterlist while the scatterlist
is filled from the linear buffers by pack_sg_list(). Then virtqueue_add_sgs()
pushes scatterlist's segments as virtio descriptors into the virtio FIFOs.
From this point it safe to unlock as the scatterlist is no longer needed.
And yes, the assumption probably was that handling the scatterlist as a
temporary was more expensive due to allocation.
> > > Looking at other virtio drivers I could probably use a sg_table and
> > > have extract_iter_to_sg() do all the work for us...
> >
> > Looking at the code I'm actually really confused. Both because I
> > actually though we were talking about the 9fs direct I/O code, but
> > that has actually been removed / converted to netfs a long time ago.
> >
> > But even more so what the net/9p code is actually doing.. How do
> > we even end up with user addresses here at all?
>
> FWIW I tried logging and saw ITER_BVEC, ITER_KVEC and ITER_FOLIOQ --
> O_DIRECT writes are seen as BVEC so I guess it's not as direct as I
> expected them to be -- that code could very well be leftovers from
> the switch to iov_iter back in 2015...
>
> (I'm actually not sure why Christian suggested checking for is_iovec()
> in https://lkml.kernel.org/r/2245723.irdbgypaU6@weasel -- then I
> generalized it to user_backed_iter() and it just worked because checking
> for that moved out bvec and folioq from iov_iter_get_pages_alloc2()
> to... something that obviously should not work in my opinion but
> apparently was enough to not trigger this particular BUG.)
Sorry, I should have explained why I suggested that change: My understanding
of the p9_get_mapped_pages() code was that the original author intended to go
down the iov_iter_get_pages_alloc2() path only for user space memory
exclusively and that he assumed that his preceding !iov_iter_is_kvec(data)
check would guard this appropriately. But apparently there are several other
iterator types that are kernel memory as well. So I thought switching the
check to is_iovec() would be better as these are user space memory, however I
missed that there is also ITER_UBUF with user space memory, which you realized
fortunately by suggesting user_backed_iter() check instead.
/Christian
next prev parent reply other threads:[~2025-12-15 11:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 21:04 [PATCH] 9p/virtio: restrict page pinning to user_backed_iter() iovec Dominique Martinet via B4 Relay
2025-12-10 4:21 ` Matthew Wilcox
2025-12-10 6:04 ` Christoph Hellwig
2025-12-10 7:38 ` asmadeus
2025-12-10 8:32 ` Christoph Hellwig
2025-12-13 13:28 ` asmadeus
2025-12-15 5:55 ` Christoph Hellwig
2025-12-15 7:34 ` Dominique Martinet
2025-12-15 11:16 ` Christian Schoenebeck [this message]
2025-12-15 14:37 ` Christoph Hellwig
2025-12-19 12:03 ` David Howells
2025-12-19 12:00 ` David Howells
2025-12-19 11:26 ` David Howells
2025-12-10 13:33 ` Christian Schoenebeck
2025-12-17 13:41 ` Christian Schoenebeck
2025-12-17 21:49 ` asmadeus
2025-12-18 14:21 ` asmadeus
2025-12-18 15:14 ` Christian Schoenebeck
2025-12-18 23:14 ` asmadeus
2025-12-19 4:09 ` 9p read corruption of mmaped content (Was: [PATCH] 9p/virtio: restrict page pinning to user_backed_iter() iovec) Dominique Martinet
2025-12-19 11:53 ` Dominique Martinet
2025-12-19 13:46 ` Dominique Martinet
2025-12-19 14:01 ` David Howells
2025-12-19 12:06 ` [PATCH] 9p/virtio: restrict page pinning to user_backed_iter() iovec David Howells
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=3918430.kQq0lBPeGt@weasel \
--to=linux_oss@crudebyte.com \
--cc=asmadeus@codewreck.org \
--cc=carges@cloudflare.com \
--cc=dhowells@redhat.com \
--cc=ericvh@kernel.org \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lucho@ionkov.net \
--cc=v9fs@lists.linux.dev \
--cc=willy@infradead.org \
/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