Linux virtualization list
 help / color / mirror / Atom feed
From: "Graf (AWS), Alexander" <graf@amazon.de>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "Jason Wang" <jasowangio@gmail.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"virtualization@lists.linux.dev" <virtualization@lists.linux.dev>,
	"nh-open-source@amazon.com" <nh-open-source@amazon.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [RFC PATCH 06/12] virtio: add a device memory buffer region allocator
Date: Mon, 10 Aug 2026 07:57:13 +0000	[thread overview]
Message-ID: <6f34275a-6320-4be1-b8e4-b96aa3289344@amazon.com> (raw)
In-Reply-To: <20260809181455-mutt-send-email-mst@kernel.org>


On 10.08.26 00:38, Michael S. Tsirkin wrote:
> On Sun, Aug 09, 2026 at 06:20:04PM +0000, Alexander Graf wrote:
>> In preparation to support VIRTIO_F_DMB, create a mechanism to allocate
>> and map memory from the Device Memory Buffer (DMB). The DMB is a shared
>> memory region a device exposes and owns. A device that negotiates the
>> feature expects its virtqueues and all the buffers we hand it to live in
>> that region, and every address we publish to it is a byte offset into
>> the region.
>>
>> Add virtio_dmb_init(), which locates the region by the shared memory id
>> the device reports and builds a page-granular allocator over it, and
>> virtio_dmb_destroy() to tear that down. Add virtio_dmb_map_ops, a struct
>> virtio_map_ops implementation that hands out allocations from that
>> allocator as region offsets: alloc() places a virtqueue area in the
>> region, map_page() copies a buffer that lives elsewhere into it and
>> copies it back on unmap. The map operations reach that allocator through
>> a new dmb member of union virtio_map.
>>
>> The shared memory id is transport specific, so add a get_dmb_shm_id()
>> callback to struct virtio_config_ops for a transport to report it. A
>> transport that does not implement it must not accept VIRTIO_F_DMB. Add
>> CONFIG_VIRTIO_DMB to enable this support. It defaults to y, and a kernel
>> that will never meet such a device can turn it off to leave the
>> allocator and its bookkeeping out.
>>
>> Link: https://lore.kernel.org/virtio-comment/20260804161202.38619-1-graf@amazon.com/
>> Assisted-by: Kiro:claude-opus-5 checkpatch sparse
>> Signed-off-by: Alexander Graf <graf@amazon.com>
>
>
>
>> ---
>>   drivers/virtio/Kconfig        |   15 +
>>   drivers/virtio/Makefile       |    3 +-
>>   drivers/virtio/virtio_dmb.c   | 1317 +++++++++++++++++++++++++++++++++
>>   drivers/virtio/virtio_dmb.h   |   28 +
>>   include/linux/virtio.h        |    3 +
>>   include/linux/virtio_config.h |    8 +
>
> Really >1000 lines to implement a virtio specific allocator?
>
> Can't we start e.g. with gen alloc and maybe xarray if you
> need some metadata?
>
>
> I guess virtio sync is annoying, it gets handle + offset is that the
> issue? We can fix them though. Or let's just not support them. There
> were there for premapped originally but now it uses page pool.
>
> Maybe I will send a patch to drop sync completely.


I started off with gen_alloc. And then over time it slowly morphed into 
what you're seeing here when I ran into issues with multi-queue 
allocations (split the buffer by VQ pair so that we don't run into lock 
contention) and zero-copy vsock transfers (by keeping DMB buffers 
statically allocated).

I agree that it's a bit much for the initial post. How about I revert 
back to the gen_alloc variant and we look at the optimizations as 
follow-up? Since everything is guest driven, we can play with them as 
much as we like in future improvements.


Alex

  reply	other threads:[~2026-08-10  7:57 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09 18:19 [RFC PATCH 00/12] virtio: support devices that own their virtqueue memory Alexander Graf
2026-08-09 18:19 ` [RFC PATCH 01/12] vdpa: correct the VIRTIO_DEVICE_F_MASK example value Alexander Graf
2026-08-09 22:42   ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 02/12] virtio_ring: validate premapped addresses through the device's map Alexander Graf
2026-08-09 22:48   ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 03/12] virtio: add the VIRTIO_F_DMB feature bit Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 04/12] virtio_pci: read the device memory buffer shared memory id Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 05/12] virtio_pci: create virtqueues with the device's mapping token Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 06/12] virtio: add a device memory buffer region allocator Alexander Graf
2026-08-09 22:06   ` Michael S. Tsirkin
2026-08-09 22:38   ` Michael S. Tsirkin
2026-08-10  7:57     ` Graf (AWS), Alexander [this message]
2026-08-10  8:07       ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 07/12] virtio: locate the device memory buffer after feature negotiation Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 08/12] virtio_pci: support VIRTIO_F_DMB Alexander Graf
2026-08-09 22:14   ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 09/12] Documentation: virtio: describe the device memory buffer Alexander Graf
2026-08-09 22:09   ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 10/12] virtio_ring: report a bounded pool's exhaustion as -ENOSPC Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 11/12] virtio: expose device memory buffer occupancy over debugfs Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 12/12] virtio: guarantee a virtqueue can publish its first descriptor chain Alexander Graf
2026-08-09 22:41   ` Michael S. Tsirkin
2026-08-09 23:15     ` Randy Dunlap
2026-08-10  6:23 ` [RFC PATCH 00/12] virtio: support devices that own their virtqueue memory Michael S. Tsirkin
2026-08-10  7:39   ` Graf (AWS), Alexander
2026-08-10  8:04     ` Michael S. Tsirkin
2026-08-10  8:25       ` Graf (AWS), Alexander
2026-08-10 19:14         ` Graf (AWS), Alexander
2026-08-10 21:42           ` Michael S. Tsirkin
2026-08-11 19:33             ` Graf (AWS), Alexander
2026-08-10 20:39 ` Stefan Hajnoczi
2026-08-11 19:39   ` Graf (AWS), Alexander

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=6f34275a-6320-4be1-b8e4-b96aa3289344@amazon.com \
    --to=graf@amazon.de \
    --cc=eperezma@redhat.com \
    --cc=jasowangio@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=nh-open-source@amazon.com \
    --cc=pbonzini@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.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