From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Gavin Shan" <gshan@redhat.com>,
"Pavel Hrdina" <phrdina@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
qemu-devel@nongnu.org, qemu-arm@nongnu.org, jugraham@redhat.com,
shan.gavin@gmail.com, "Alex Williamson" <alex@shazbot.org>,
"David Hildenbrand" <david@kernel.org>
Subject: Re: [PATCH RFCv1] virtio: Inherit max bounce buffer size from bus parent if possible
Date: Wed, 10 Jun 2026 17:44:58 -0400 [thread overview]
Message-ID: <20260610174052-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <ainWw13-_TfX_vln@x1.local>
On Wed, Jun 10, 2026 at 05:27:31PM -0400, Peter Xu wrote:
> On Wed, Jun 10, 2026 at 05:03:59PM -0400, Michael S. Tsirkin wrote:
> > On Wed, Jun 10, 2026 at 03:10:46PM -0400, Peter Xu wrote:
> > > On Wed, Jun 10, 2026 at 12:19:39PM -0400, Michael S. Tsirkin wrote:
> > > > On Wed, Jun 10, 2026 at 05:11:40PM +0100, Peter Maydell wrote:
> > > > > On Wed, 10 Jun 2026 at 16:37, Peter Xu <peterx@redhat.com> wrote:
> > > > > >
> > > > > > On Wed, Jun 10, 2026 at 10:06:24AM -0400, Michael S. Tsirkin wrote:
> > > > > > > This is the change that broke it I think?
> > > > > > >
> > > > > > >
> > > > > > > commit 4a2e242bbb306ef5c16ce9e7bb2da3bd8a4eb098
> > > > > > > Author: Alex Williamson <alex@shazbot.org>
> > > > > > > Date: Mon Oct 31 09:53:03 2016 -0600
> > > > > > >
> > > > > > > memory: Don't use memcpy for ram_device regions
> > > > > > >
> > > > > > >
> > > > > > > Maybe Alex has an opinion on what to do.
> > > > > >
> > > > > > I can offer one idea here..
> > > > > >
> > > > > > IIUC the major issue was vector ops but the mr ops might be too heavy, then
> > > > > > another way to fix it is in memory API instead of using memcpy()/memmove(),
> > > > > > we always use a helper (say, memmove_no_vector()) to do the split and
> > > > > > properly aligned IOs as what ram_device_mem_ops does right now, this should
> > > > > > only applies to ram_device.
> > > > >
> > > > > If the underlying memory needs to be accessed only with specific
> > > > > alignment/size, as the 4a2e242bbb30 commit message suggests, then
> > > > > we cannot expose it via address_space_map(), so we must have
> > > > > a bounce-buffer.
> > >
> > > I get the point; this is technically a concern, but IMHO it's still
> > > slightly different, and I expect it non-issue in reality.
> > >
> > > Essentially we can have two ways to iteract with the pci bar:
> > >
> > > 1) via vCPU / CPU access
> > > 2) via DMA targets
> > >
> > > Alex can correct me, but IIUC that problem was when the CPU accesses the
> > > mapped region with memcpy(), rather than making that bar to be DMA target.
> > > Hence, use case 1) only. So my current understanding is the proposal
> > > shouldn't (hopefully..) regress that realtek problem because use case 1) is
> > > properly covered.
> > >
> > > I always think it is very bogus to have any register-like MMIO regions to
> > > be passed over, maybe it's a bug already? It's because I don't know any
> > > way to guarantee DMA performs in a way that will be compatible with a pci
> > > bar that is register-based and will not have any side effect. Say, if some
> > > pci bar (real register-backed) must be accessed in 4B and aligned, how
> > > would a DMA request guarantee that?
> > >
> > > >From that perspective, IMHO it's a guest (driver or app, I'm not sure..)
> > > bug to make such region to be DMA target in the first place. The outcome
> > > of such setup should be undefined. It'll be the same after applying the
> > > proposal I raised, that QEMU will have undefined behavior for such pci bars
> > > to be used as DMA targets.
> > >
> > > Thanks,
> >
> > Sorry, wasting gibabytes and GB/s of main
> > RAM and PCI BW just to shuffle data back out the PCI bus
> > is out of the question.
> >
> > You don't have to like it)
>
> I'm not sure if my previous comment wasn't clear, but just to make sure it
> is..
>
> The proposal was exactly about making ram_device to be directly accessible
> by default. That is, make memory_region_supports_direct_access() return
> true for ram_device like before, however when doing direct access from
> QEMU, QEMU should use memmove_no_vector() version instead of memcpy().
>
> We leave DMA maps like virtio-blk to be directly accessible without
> auditing device emulations using memcpy() or not: then QEMU faces the same
> risk to bare metal where MMIO regions used for DMA buffers, then it's
> undefined behavior.
>
> In case of GPU bar mapping, it should then work like RAM for virtio-blk.
>
> Thanks,
Ah, I get it. not sure we need memmove_no_vector even, we can keep
the bounce buffer thing if we want.
> >
> > > >
> > > > Right. And virtio currently isn't friendly to the bounce buffer.
> > > > We can fix that but I worry about the perf impact.
> > > >
> > > > > The address_space_map() function says
> > > > > "here's a host pointer to memory, do what you like to it", and
> > > > > the caller is entitled to memcpy to/from it or otherwise
> > > > > access it with any C operations, which are not guaranteed to
> > > > > respect any kind of alignment or similar restrictions.
> > > > >
> > > > > My guess from commit 4a2e242bbb30 is that that applied an
> > > > > overly broad "don't do direct access" hammer to all
> > > > > vfio assigned devices, and that there needs to be some
> > > > > concept of "this vfio assigned device's region is OK for
> > > > > direct access" vs "this other one is not", such that if
> > > > > this GH100 card's BAR guarantees it can be treated entirely
> > > > > as RAM then we can have memory_region_supports_direct_access()
> > > > > return true for it.
> > > > >
> > > > > thanks
> > > > > -- PMM
> > > >
> > >
> > > --
> > > Peter Xu
> >
> >
>
> --
> Peter Xu
next prev parent reply other threads:[~2026-06-10 21:46 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 0:18 [PATCH RFCv1] virtio: Inherit max bounce buffer size from bus parent if possible Gavin Shan
2026-06-08 8:55 ` Daniel P. Berrangé
2026-06-08 11:11 ` Gavin Shan
2026-06-08 11:38 ` Daniel P. Berrangé
2026-06-09 2:08 ` Gavin Shan
2026-06-09 16:25 ` Peter Xu
2026-06-10 0:32 ` Gavin Shan
2026-06-10 9:54 ` Pavel Hrdina
2026-06-10 10:55 ` Gavin Shan
2026-06-10 12:12 ` Michael S. Tsirkin
2026-06-10 12:19 ` Gavin Shan
2026-06-10 12:27 ` Michael S. Tsirkin
2026-06-10 13:00 ` Gavin Shan
2026-06-10 13:54 ` Gavin Shan
2026-06-10 14:06 ` Michael S. Tsirkin
2026-06-10 15:36 ` Peter Xu
2026-06-10 16:11 ` Peter Maydell
2026-06-10 16:19 ` Michael S. Tsirkin
2026-06-10 19:10 ` Peter Xu
2026-06-10 21:03 ` Michael S. Tsirkin
2026-06-10 21:27 ` Peter Xu
2026-06-10 21:44 ` Michael S. Tsirkin [this message]
2026-06-10 16:18 ` Michael S. Tsirkin
2026-06-11 4:33 ` Gavin Shan
2026-06-11 5:31 ` Michael S. Tsirkin
2026-06-11 6:28 ` Gavin Shan
2026-06-11 6:34 ` Michael S. Tsirkin
2026-06-11 12:33 ` Gavin Shan
2026-06-11 12:48 ` Peter Maydell
2026-06-11 14:10 ` Michael S. Tsirkin
2026-06-11 14:55 ` Peter Maydell
2026-06-11 15:05 ` Michael S. Tsirkin
2026-06-11 15:25 ` Michael S. Tsirkin
2026-06-11 15:29 ` Peter Maydell
2026-06-11 15:57 ` Michael S. Tsirkin
2026-06-11 16:16 ` Peter Maydell
2026-06-11 16:42 ` Michael S. Tsirkin
2026-06-11 16:53 ` Peter Maydell
2026-06-11 17:02 ` Michael S. Tsirkin
2026-06-11 18:20 ` Peter Xu
2026-06-11 20:52 ` Michael S. Tsirkin
2026-06-11 21:20 ` Peter Xu
2026-06-11 21:59 ` Michael S. Tsirkin
2026-06-12 19:44 ` Alex Williamson
2026-06-12 21:24 ` Peter Xu
2026-06-14 16:10 ` Michael S. Tsirkin
2026-06-11 21:15 ` Michael S. Tsirkin
2026-06-11 16:13 ` Michael S. Tsirkin
2026-06-12 4:25 ` Gavin Shan
2026-06-12 8:43 ` Michael S. Tsirkin
2026-06-12 10:25 ` Gavin Shan
2026-06-11 6:51 ` Michael S. Tsirkin
2026-06-10 12:23 ` Pavel Hrdina
2026-06-10 14:04 ` Gavin Shan
2026-06-10 14:08 ` Michael S. Tsirkin
2026-06-10 9:49 ` Michael S. Tsirkin
2026-06-10 18:30 ` Stefan Hajnoczi
2026-06-10 21:00 ` Michael S. Tsirkin
2026-06-11 14:20 ` Stefan Hajnoczi
2026-06-11 14:45 ` Michael S. Tsirkin
2026-06-11 15:04 ` Peter Maydell
2026-06-11 15:09 ` Michael S. Tsirkin
2026-06-11 18:37 ` Stefan Hajnoczi
2026-06-11 20:54 ` Michael S. Tsirkin
2026-06-15 15:54 ` Stefan Hajnoczi
2026-06-15 19:59 ` Michael S. Tsirkin
2026-06-11 1:19 ` Gavin Shan
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=20260610174052-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=alex@shazbot.org \
--cc=berrange@redhat.com \
--cc=david@kernel.org \
--cc=gshan@redhat.com \
--cc=jugraham@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=phrdina@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=shan.gavin@gmail.com \
/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