From: Matthew Wilcox <willy@infradead.org>
To: Dominique Martinet <asmadeus@codewreck.org>,
David Howells <dhowells@redhat.com>,
Vlastimil Babka <vbabka@suse.cz>
Cc: Chris Arges <carges@cloudflare.com>,
David Howells <dhowells@redhat.com>,
ericvh@kernel.org, lucho@ionkov.net, linux_oss@crudebyte.com,
v9fs@lists.linux.dev, linux-kernel@vger.kernel.org,
kernel-team@cloudflare.com
Subject: Re: kernel BUG when mounting large block xfs backed by 9p (folio ref count bug)
Date: Fri, 5 Dec 2025 04:53:31 +0000 [thread overview]
Message-ID: <aTJlS_oFL_uiEoTw@casper.infradead.org> (raw)
In-Reply-To: <aSVw0M8f3vTXdQxH@codewreck.org>
On Tue, Nov 25, 2025 at 06:03:12PM +0900, Dominique Martinet wrote:
> I'm sorry but I'm not sure I see what I should do from this -- your
> patch looks to me like it should now work with this?
> Oh, it's not merged?... I don't see where the discussion stalled
> either...
>
> For context, in this case virtio needs the pages to be pinned because
> the host will write directly into it, and the API we're using is
> virtqueue_add_sgs() (drivers/virtio/virtio_ring.c) which expects a
> scatterlist, which I guess must be pages (can't say I'm very familiar
> with this particular API either, but the word `folio` doesn't show up in
> drivers/virtio)
I was hoping Dave Howells would chime in, but since he hasn't ...
The root problem is that iov_iter_get_pages_alloc() takes a reference
on the page. It thinks this will prevent the memory from being fredd
under it. That's not true with slab allocations; the slab won't get
freed back to the page allocator, but the original memory can be kfreed
and reallocated to another kmalloc. So at best this is a useless
bumping of the refcount, and at worst it'll corrupt the data of some
unsuspecting user.
So we delberately broke this usage. You can't pass slab allocated memory
to iov_iter_get_pages_alloc() any more. And then we decided to break
the "large kmalloc" case too. It's an implementation detail whether a
kmalloc comes from slab or not, and we might change things in the future
such that allocations which are currently deemed too large to come from
a slab now come from a slab instead.
I don't really have concrete advice for you what you should be doing
to fix this. We should never have allowed this to work, but I'm
insufficiently familiar with the iov_iter APIs to tell you what you
should be doing instead. Hence my hope that Dave Howells would ride
to the rescue.
But this isn't anything to do with folios, at least not directly.
It's a spinoff of the folio project.
> Since we don't know where the iov comes from, we can't have any
> expectation about it, but we can check things and try to act
> appropriately (or error out and/or somehow fallback to non-zc if there's
> a reason we can't do it).
>
> What would one need to go from an iov_iter to something this could use?
>
> out of curiosity I looked at other "big" virtqueue users (e.g. vhost
> scsi must be shuffling similar data around), but I don't quite see how
> the buffers are passed, I'd need to spend more time than I can afford immediately...
>
>
> Thanks (and sorry for pulling the whole arm when you give a hand),
> --
> Dominique
next prev parent reply other threads:[~2025-12-05 4:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-24 15:47 kernel BUG when mounting filesystem on 9p Chris Arges
2025-11-24 23:12 ` kernel BUG when mounting large block xfs backed by 9p (folio ref count bug) Dominique Martinet
2025-11-24 23:55 ` Matthew Wilcox
2025-11-25 9:03 ` Dominique Martinet
2025-12-05 4:53 ` Matthew Wilcox [this message]
2025-12-05 10:47 ` Christian Schoenebeck
2025-12-05 13:03 ` Dominique Martinet
2025-12-05 13:36 ` Christian Schoenebeck
2025-12-05 13:48 ` Dominique Martinet
2025-12-07 7:18 ` Matthew Wilcox
2025-12-07 13:49 ` Dominique Martinet
2025-12-08 17:21 ` Chris Arges
2025-12-09 9:52 ` Christian Schoenebeck
2025-11-25 15:52 ` Chris Arges
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=aTJlS_oFL_uiEoTw@casper.infradead.org \
--to=willy@infradead.org \
--cc=asmadeus@codewreck.org \
--cc=carges@cloudflare.com \
--cc=dhowells@redhat.com \
--cc=ericvh@kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=v9fs@lists.linux.dev \
--cc=vbabka@suse.cz \
/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
all inboxes | Powered by JetHome®