All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wendy Liang <wendy.liang@amd.com>
To: <qemu-devel@nongnu.org>
Cc: "Wendy Liang" <wendy.liang@amd.com>,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Lizhi Hou" <lizhi.hou@amd.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Max Zhen" <max.zhen@amd.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>
Subject: [RFC PATCH 0/2] Introduce virtio-accel device for NPU virtualization
Date: Tue, 1 Dec 2026 23:44:53 -0800	[thread overview]
Message-ID: <cover.1796196350.git.wendy.liang@amd.com> (raw)

This patch series adds a DRM-based accelerator virtio-accel-pci device,
which allows a guest to access host NPU resources through the DRM interface.
It also adds host-memory blob mapping support for the virtio-accel device.

We are trying to support NPU virtualization in QEMU. We have a DRM accelerator
driver drivers/accel/amdxdna in upstream Linux kernel for NPU. We checked the
existing virtio-gpu and virglrenderer. We also use native context and resource
blob ideas because they are similar to our use case.  They enable kernel
operations (ioctls) across the guest and host. There is no API translation
required. We can mirror host DRM ioctls with CCMDs in the guest, and the host
replays them. This lets guests use what host driver supports. With the CCMD
shim layer in the guest, we can use the same application stack on both guest
and host. Guest pages are passed as iovecs to the host, or host buffers are
mapped into a PCI BAR which avoids extra copies.

We needed to support different types for virtio-gpu devices such as graphics
GPU and compute NPUs within the same guest. Virtio implementation allows us to
share the same NPU across guests, but we also want to select which drm accel
device nodes to use for a guest as we can have multiple accel devices on the
host.
e.g.
from qemu command line, we can specify:
`-device virtio-accel-pci,accel-node=accel1`
in the guest Linux, the NPU will be presented as
`/dev/dri/card<>`, `/dev/dri/renderD<>`.
The guest shim layer uses the virtio-gpu kernel driver, no new driver is required.

virglrenderer keeps a single static struct global_state with one cookie and one
callback table. After the first virgl_renderer_init() call in a qemu process,
a second call with a different cookie returns -EBUSY. So there is only one
virglrenderer-backed device per QEMU process. QEMU doesn't implement
virglrenderer's get_drm_fd callback; even if it did, drm_renderer_create()
opens the first render node with a matching driver name for every context, ignoring
that fd. There is no way to choose the host device. Also, virtio-accel needs no
OpenGL, epoxy or EGL, while virtio-gpu-gl requires opengl. And thus, we created
libvxdna (https://github.com/amd/xdna-driver/tree/main/src/vxdna)
to support multiple virtio-accel devices in the same guest and multiple DRM accel
devices on the host. libvxdna is a userspace library that provides implementation
of the vaccel_<> APIs defined in:
https://github.com/amd/xdna-driver/blob/main/src/vxdna/include/vaccel.h
which is called by the virtio-accel device in QEMU.
This library accesses the host NPU device to execute the CCMDs specified by the
xdna-driver shim layer (https://github.com/amd/xdna-driver/tree/main/src/shim/virtio)
in the guest.

Sending this RFC patch series for feedback on this approach.

Usage of this patch series:
1. On an AMD NPU enabled host, follow the instructions in
   https://github.com/amd/xdna-driver/blob/main/README.md
   to build and install the AMD NPU driver and libvxdna library.
2. Build QEMU with this patch series applied, with the `--enable-drm-accel` option.
3. Build Linux kernel with CONFIG_DRM_VIRTIO_GPU enabled.
4. Create guest linux image with xdna-driver package and xrt package installed.
5. Run qemu with the following command line option to use guest memory:
    -object memory-backend-memfd,id=mem0,size=16G,share=on \
    -machine q35,memory-backend=mem0,accel=kvm \
    -device virtio-accel-pci,accel-node=accel0
   to use host memory:
    -machine q35,accel=kvm -m 16G \
    -device virtio-accel-pci,accel-node=accel0,hostmem=8G
6. In the guest linux, launch `xrt-smi examine` and `xrt-smi validate` to check
   NPU status.

Wendy Liang (2):
  hw/display/virtio-accel: add DRM-based accelerator device
  hw/display/virtio-accel: add host-memory blob mapping

 MAINTAINERS                    |   7 +
 hw/display/meson.build         |  15 +
 hw/display/trace-events        |   9 +
 hw/display/virtio-accel-pci.c  |  52 +++
 hw/display/virtio-accel.c      | 732 +++++++++++++++++++++++++++++++++
 hw/display/virtio-gpu-base.c   |   3 +-
 hw/display/virtio-gpu.c        |   1 +
 include/hw/virtio/virtio-gpu.h |  30 ++
 meson.build                    |   7 +
 meson_options.txt              |   2 +
 scripts/meson-buildoptions.sh  |   3 +
 11 files changed, 860 insertions(+), 1 deletion(-)
 create mode 100644 hw/display/virtio-accel-pci.c
 create mode 100644 hw/display/virtio-accel.c


base-commit: fae886567b48c672977acde6b775dd7e2d2121c1
-- 
2.53.0



             reply	other threads:[~2026-12-02 12:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  7:44 Wendy Liang [this message]
2026-12-02  7:44 ` [RFC PATCH 1/2] hw/display/virtio-accel: add DRM-based accelerator device Wendy Liang
2026-12-02  7:44 ` [RFC PATCH 2/2] hw/display/virtio-accel: add host-memory blob mapping Wendy Liang

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=cover.1796196350.git.wendy.liang@amd.com \
    --to=wendy.liang@amd.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=lizhi.hou@amd.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=max.zhen@amd.com \
    --cc=mst@redhat.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pbonzini@redhat.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.