vhost-user for input & GPU
Subsystems (2)
v4 cover vhost-user for input & GPU
Hi,
vhost-user allows to drive a virtio device in a seperate process. After vhost-user-net, we have seen vhost-user-{scsi,blk,crypto} added more recently.
This series, initially proposed 2 years ago
(https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01905.html)
contributes with vhost-user-input and vhost-user-gpu.
Additionally, to factor out common code and ease the usage, a vhost-user-backend is introduced as an intermediary object between the backend and the qemu device.
You may start a vhost-user-gpu with virgl rendering in a separate process like this:
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vug
You may also specify the backend command and the arguments as part of vhost-user-backend qemu arguments. For example, to start a vhost-user-input backend on input device /dev/input/event19:
-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event19" -device virtio-input-host-pci,vhost-user=vuid
The vhost-user-gpu backend requires virgl from git.
The libvirt support is on-going work:
https://github.com/elmarco/libvirt/commits/vhost-user-gpu
The GPU benchmarks are encouraging, giving up to x5 performance on Unigine Heaven 4.0.
Feedback welcome,
v4:
- move qemu_write_pidfile() in util, improve it a bit
- add --pid and --fd arguments to vhost-user to help with libvirt support
- various bug fixes for synchronization, and tearing down
v3: deal with most comments from rfcv2 and various improvements
- "vhost-user-backend: allow to specify binary to execute" as seperate patch, not for inclusion since Daniel as concerned about parsing shell strings with glib
- use dmabuf to share 2d rendering result (with intel gem only atm)
- document the vhost-user-gpu protocol
- make vhost-user-gpu-pci and vhost-user-vga seperate devices (instead of adding vhost-user support to existing devices)
- allow to specify virgl rendering, and rendernode
- let's promote out of RFC status :)
RFCv2: (addressing some of Gerd comments digged in the archives)
- rebased, clean ups, various small fixes, update commit messages
- teach the vhost-user-backend to take a chardev
- add vhost-user-input-pci, instead of adding vhost code to virtio-input-host-pci
Marc-André Lureau (29):
chardev: avoid crash if no associated address
chardev: remove qemu_chr_fe_read_all() counter
chardev: unref if underlying chardev has no parent
dmabuf: add y0_top, pass it to spice
vhost-user: simplify vhost_user_init/vhost_user_cleanup
libvhost-user: exit by default on VHOST_USER_NONE
vhost-user: wrap some read/write with retry handling Add vhost-user-backend
qio: add qio_channel_command_new_spawn_with_pre_exec()
HACK: vhost-user-backend: allow to specify binary to execute
vhost-user: split vhost_user_read()
vhost-user: add vhost_user_input_get_config()
libvhost-user: export vug_source_new()
contrib: add vhost-user-input
Add vhost-user-input-pci
vhost-user: add vhost_user_gpu_set_socket()
vhost-user: add vhost_user_gpu_get_num_capsets()
virtio: add virtio-gpu bswap helpers header
util: promote qemu_egl_rendernode_open() to libqemuutil
util: add qemu_write_pidfile()
util: use fcntl() for qemu_write_pidfile() locking
contrib: add vhost-user-gpu
virtio-gpu: remove unused qdev
virtio-gpu: remove unused config_size
virtio-gpu: block both 2d and 3d rendering
virtio-gpu: remove useless 'waiting' field
virtio-gpu: split virtio-gpu, introduce virtio-gpu-base
virtio-gpu: split virtio-gpu-pci & virtio-vga hw/display: add vhost-user-vga & gpu-pci
contrib/libvhost-user/libvhost-user-glib.h | 3 + contrib/libvhost-user/libvhost-user.h | 3 + contrib/vhost-user-gpu/drm.h | 63 ++ contrib/vhost-user-gpu/virgl.h | 25 + contrib/vhost-user-gpu/vugpu.h | 168 +++ hw/display/virtio-vga.h | 22 + hw/virtio/virtio-pci.h | 27 +- include/hw/virtio/vhost-backend.h | 6 + include/hw/virtio/vhost-user-blk.h | 2 +- include/hw/virtio/vhost-user-scsi.h | 2 +- include/hw/virtio/vhost-user.h | 2 +- include/hw/virtio/virtio-gpu-bswap.h | 61 + include/hw/virtio/virtio-gpu.h | 90 +- include/hw/virtio/virtio-input.h | 14 + include/io/channel-command.h | 18 + include/qemu/drm.h | 6 + include/qemu/osdep.h | 3 +- include/sysemu/vhost-user-backend.h | 60 + include/ui/console.h | 1 + backends/cryptodev-vhost-user.c | 18 +- backends/vhost-user.c | 320 ++++++ chardev/char-fe.c | 13 +- chardev/char-socket.c | 8 +- contrib/libvhost-user/libvhost-user-glib.c | 15 +- contrib/libvhost-user/libvhost-user.c | 3 +- contrib/vhost-user-gpu/drm.c | 190 ++++ contrib/vhost-user-gpu/main.c | 1164 ++++++++++++++++++++ contrib/vhost-user-gpu/virgl.c | 579 ++++++++++ contrib/vhost-user-input/main.c | 379 +++++++ hw/block/vhost-user-blk.c | 22 +- hw/display/vhost-user-gpu-pci.c | 51 + hw/display/vhost-user-gpu.c | 524 +++++++++ hw/display/vhost-user-vga.c | 52 + hw/display/virtio-gpu-3d.c | 70 +- hw/display/virtio-gpu-base.c | 292 +++++ hw/display/virtio-gpu-pci.c | 39 +- hw/display/virtio-gpu.c | 368 ++----- hw/display/virtio-vga.c | 127 ++- hw/input/vhost-user-input.c | 110 ++ hw/scsi/vhost-user-scsi.c | 20 +- hw/virtio/vhost-stub.c | 4 +- hw/virtio/vhost-user.c | 143 ++- hw/virtio/virtio-pci.c | 20 + io/channel-command.c | 33 +- net/vhost-user.c | 13 +- os-posix.c | 24 - os-win32.c | 25 - qga/main.c | 54 +- scsi/qemu-pr-helper.c | 40 +- ui/egl-helpers.c | 51 +- ui/spice-display.c | 3 +- util/drm.c | 66 ++ util/oslib-posix.c | 39 + util/oslib-win32.c | 27 + vl.c | 8 +- MAINTAINERS | 15 +- Makefile | 6 + Makefile.objs | 2 + backends/Makefile.objs | 3 +- configure | 35 + contrib/vhost-user-gpu/Makefile.objs | 10 + contrib/vhost-user-input/Makefile.objs | 1 + docs/interop/vhost-user-gpu.rst | 236 ++++ docs/interop/vhost-user.txt | 24 + hw/display/Makefile.objs | 5 +- hw/input/Makefile.objs | 1 + qemu-options.hx | 24 + util/Makefile.objs | 1 + 68 files changed, 5130 insertions(+), 723 deletions(-) create mode 100644 contrib/vhost-user-gpu/drm.h create mode 100644 contrib/vhost-user-gpu/virgl.h create mode 100644 contrib/vhost-user-gpu/vugpu.h create mode 100644 hw/display/virtio-vga.h create mode 100644 include/hw/virtio/virtio-gpu-bswap.h create mode 100644 include/qemu/drm.h create mode 100644 include/sysemu/vhost-user-backend.h create mode 100644 backends/vhost-user.c create mode 100644 contrib/vhost-user-gpu/drm.c create mode 100644 contrib/vhost-user-gpu/main.c create mode 100644 contrib/vhost-user-gpu/virgl.c create mode 100644 contrib/vhost-user-input/main.c create mode 100644 hw/display/vhost-user-gpu-pci.c create mode 100644 hw/display/vhost-user-gpu.c create mode 100644 hw/display/vhost-user-vga.c create mode 100644 hw/display/virtio-gpu-base.c create mode 100644 hw/input/vhost-user-input.c create mode 100644 util/drm.c create mode 100644 contrib/vhost-user-gpu/Makefile.objs create mode 100644 contrib/vhost-user-input/Makefile.objs create mode 100644 docs/interop/vhost-user-gpu.rst
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 1/29 chardev: avoid crash if no associated address
A socket chardev may not have associated address (when adding client fd manually for example). But on disconnect, updating socket filename expects an address and may lead to this crash:
Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
0x0000555555d8c70c in SocketAddress_to_str (prefix=0x555556043062 "disconnected:", addr=0x0, is_listen=false, is_telnet=false) at /home/elmarco/src/qq/chardev/char-socket.c:388
388 switch (addr->type) {
(gdb) bt
#0 0x0000555555d8c70c in SocketAddress_to_str (prefix=0x555556043062 "disconnected:", addr=0x0, is_listen=false, is_telnet=false) at /home/elmarco/src/qq/chardev/char-socket.c:388 #1 0x0000555555d8c8aa in update_disconnected_filename (s=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:419 #2 0x0000555555d8c959 in tcp_chr_disconnect (chr=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:438 #3 0x0000555555d8cba1 in tcp_chr_hup (channel=0x555556b75690, cond=G_IO_HUP, opaque=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:482 #4 0x0000555555da596e in qio_channel_fd_source_dispatch (source=0x555556bb68b0, callback=0x555555d8cb58 <tcp_chr_hup>, user_data=0x555556b1ed00) at /home/elmarco/src/qq/io/channel-watch.c:84
Replace filename with a generic "disconnected:socket" in this case.
--- chardev/char-socket.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
chardev/char-socket.c +6 -2
@@ -419,8 +419,12 @@ static void update_disconnected_filename(SocketChardev *s)Chardev *chr =CHARDEV (s);g_free (chr->filename); - chr->filename =SocketAddress_to_str ("disconnected:" , s->addr, - s->is_listen, s->is_telnet); +if (s->addr) { + chr->filename =SocketAddress_to_str ("disconnected:" , s->addr, + s->is_listen, s->is_telnet); + }else { + chr->filename =g_strdup ("disconnected:socket" ); + } }/* NB may be called even if tcp_chr_connect has not been
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 2/29 chardev: remove qemu_chr_fe_read_all() counter
In reply to Marc-André LureauThere is no obvious reason to have a loop counter. This limits from reading several megabytes large buffers in one go, since socket read/write usually have a limit.
--- chardev/char-fe.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
chardev/char-fe.c +1 -5
@@ -56,7 +56,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len)int qemu_chr_fe_read_all (CharBackend *be,uint8_t *buf,int len) {Chardev *s = be->chr; -int offset =0 , counter =10 ; +int offset =0 ;int res;if (!s || !CHARDEV_GET_CLASS (s)->chr_sync_read) {
@@ -88,10 +88,6 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) } offset += res; - -if (!counter--) { -break ; - } }if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 02/29] chardev: remove qemu_chr_fe_read_all() counter
Quoted 3 lines · Marc-André Lureau
There is no obvious reason to have a loop counter. This limits from reading several megabytes large buffers in one go, since socket read/write usually have a limit.
The counter was there since this method's introduction in 7b0bfdf52d694c9a3a96505aa42ce3f8d63acd35, and no obvious indication of its purpose in that commit.
I can imagine maybe it was a misguided attempt to prevent QEMU blocking forever if no data was pending, but it does not in fact achieve that.
Quoted 5 lines
Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>--- chardev/char-fe.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 3/29 chardev: unref if underlying chardev has no parent
In reply to Marc-André LureauIt's possible to write code creating a chardev backend that is not registered. When it is not user-created, it makes sense to keep it hidden. Let the associated frontend destroy it also in this case.
--- chardev/char-fe.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
chardev/char-fe.c +6 -1
@@ -235,7 +235,12 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del) d->backends[b->tag] =NULL ; }if (del) { -object_unparent (OBJECT (b->chr)); +Object *obj =OBJECT (b->chr); +if (obj->parent) { +object_unparent (obj); + }else { +object_unref (obj); + } } b->chr =NULL ; }
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 03/29] chardev: unref if underlying chardev has no parent
Quoted 8 lines · Marc-André Lureau
It's possible to write code creating a chardev backend that is not registered. When it is not user-created, it makes sense to keep it hidden. Let the associated frontend destroy it also in this case.
Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char-fe.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 4/29 dmabuf: add y0_top, pass it to spice
In reply to Marc-André LureauSome scanouts during boot are top-down without it.
y0_top is set from VHOST_USER_GPU_DMABUF_SCANOUT code path in the last patch of this series.
In current QEMU code base, only vfio/display uses dmabuf API. But the VFIO query interface doesn't provide or need that detail so far.
--- include/ui/console.h | 1 + ui/spice-display.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
include/ui/console.h +1 -0
@@ -186,6 +186,7 @@ struct QemuDmaBuf {uint32_t stride;uint32_t fourcc;uint32_t texture; +bool y0_top; }; typedef struct DisplayChangeListenerOps {
ui/spice-display.c +2 -1
@@ -1048,7 +1048,8 @@ static void qemu_spice_gl_update(DisplayChangeListener *dcl,/* note: spice server will close the fd, so hand over a dup */ spice_qxl_gl_scanout (&ssd->qxl,dup (dmabuf->fd), dmabuf->width, dmabuf->height, - dmabuf->stride, dmabuf->fourcc, false); + dmabuf->stride, dmabuf->fourcc, + dmabuf->y0_top); }qemu_spice_gl_monitor_config (ssd,0 ,0 , dmabuf->width, dmabuf->height); ssd->guest_dmabuf_refresh = false;
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 04/29] dmabuf: add y0_top, pass it to spice
Quoted 7 lines · Marc-André Lureau
Some scanouts during boot are top-down without it.
y0_topis set fromVHOST_USER_GPU_DMABUF_SCANOUTcode path in the last patch of this series.In current QEMU code base, only vfio/display uses dmabuf API. But the VFIO query interface doesn't provide or need that detail so far.
Cherry-picked into ui queue.
cheers,
Gerd
PATCH v4 5/29 vhost-user: simplify vhost_user_init/vhost_user_cleanup
In reply to Marc-André LureauTake a VhostUserState* that can be pre-allocated, and initialize it with the associated chardev.
--- include/hw/virtio/vhost-user-blk.h | 2 +- include/hw/virtio/vhost-user-scsi.h | 2 +- include/hw/virtio/vhost-user.h | 2 +- backends/cryptodev-vhost-user.c | 18 ++++-------------- hw/block/vhost-user-blk.c | 22 ++++------------------ hw/scsi/vhost-user-scsi.c | 20 ++++---------------- hw/virtio/vhost-stub.c | 4 ++-- hw/virtio/vhost-user.c | 16 ++++++++++++---- net/vhost-user.c | 13 ++++--------- 9 files changed, 33 insertions(+), 66 deletions(-)
include/hw/virtio/vhost-user-blk.h +1 -1
@@ -36,7 +36,7 @@ typedef struct VHostUserBlk {uint32_t queue_size;uint32_t config_wce;struct vhost_dev dev; - VhostUserState *vhost_user; + VhostUserState vhost_user; } VHostUserBlk;#endif
include/hw/virtio/vhost-user-scsi.h +1 -1
@@ -31,7 +31,7 @@typedef struct VHostUserSCSI {VHostSCSICommon parent_obj;uint64_t host_features; -VhostUserState *vhost_user; +VhostUserState vhost_user; }VHostUserSCSI ;#endif /* VHOST_USER_SCSI_H */
include/hw/virtio/vhost-user.h +1 -1
@@ -22,7 +22,7 @@ typedef struct VhostUserState { VhostUserHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostUserState; -VhostUserState *vhost_user_init (void ); +bool vhost_user_init (VhostUserState *user,CharBackend *chr,Error **errp);void vhost_user_cleanup (VhostUserState *user);#endif
backends/cryptodev-vhost-user.c +4 -14
@@ -47,7 +47,7 @@ typedef struct CryptoDevBackendVhostUser { CryptoDevBackend parent_obj; - VhostUserState *vhost_user; + VhostUserState vhost_user; CharBackend chr; char *chr_name; bool opened;
@@ -104,7 +104,7 @@ cryptodev_vhost_user_start(int queues,continue ; } - options.opaque = s->vhost_user; + options.opaque = &s->vhost_user; options.backend_type =VHOST_BACKEND_TYPE_USER ; options.cc = b->conf.peers.ccs[i]; s->vhost_crypto[i] =cryptodev_vhost_init (&options);
@@ -187,7 +187,6 @@ static void cryptodev_vhost_user_init(size_t i;Error *local_err =NULL ;Chardev *chr; -VhostUserState *user;CryptoDevBackendClient *cc;CryptoDevBackendVhostUser *s =CRYPTODEV_BACKEND_VHOST_USER (backend);
@@ -218,15 +217,10 @@ static void cryptodev_vhost_user_init( } } - user =vhost_user_init (); -if (!user) { -error_setg (errp,"Failed to init vhost_user" ); +if (!vhost_user_init (&s->vhost_user, &s->chr, errp)) {return ; } - user->chr = &s->chr; - s->vhost_user = user; -qemu_chr_fe_set_handlers (&s->chr,NULL ,NULL , cryptodev_vhost_user_event,NULL , s,NULL , true);
@@ -312,11 +306,7 @@ static void cryptodev_vhost_user_cleanup( } } -if (s->vhost_user) { -vhost_user_cleanup (s->vhost_user); -g_free (s->vhost_user); - s->vhost_user =NULL ; - } +vhost_user_cleanup (&s->vhost_user); } static void cryptodev_vhost_user_set_chardev(Object *obj,
hw/block/vhost-user-blk.c +4 -18
@@ -224,7 +224,6 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) {VirtIODevice *vdev =VIRTIO_DEVICE (dev);VHostUserBlk *s =VHOST_USER_BLK (vdev); -VhostUserState *user;int i, ret;if (!s->chardev.chr) {
@@ -242,15 +241,10 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)return ; } - user =vhost_user_init (); -if (!user) { -error_setg (errp,"vhost-user-blk: failed to init vhost_user" ); +if (!vhost_user_init (&s->vhost_user, &s->chardev, errp)) {return ; } - user->chr = &s->chardev; - s->vhost_user = user; -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK ,sizeof (struct virtio_blk_config ));
@@ -266,7 +260,7 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)vhost_dev_set_config_notifier (&s->dev, &blk_ops); - ret =vhost_dev_init (&s->dev, s->vhost_user,VHOST_BACKEND_TYPE_USER ,0 ); + ret =vhost_dev_init (&s->dev, &s->vhost_user,VHOST_BACKEND_TYPE_USER ,0 );if (ret <0 ) {error_setg (errp,"vhost-user-blk: vhost initialization failed: %s" ,strerror (-ret));
@@ -291,10 +285,7 @@ vhost_err: virtio_err:g_free (s->dev.vqs);virtio_cleanup (vdev); - -vhost_user_cleanup (user); -g_free (user); - s->vhost_user =NULL ; +vhost_user_cleanup (&s->vhost_user); }static void vhost_user_blk_device_unrealize (DeviceState *dev,Error **errp)
@@ -306,12 +297,7 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)vhost_dev_cleanup (&s->dev);g_free (s->dev.vqs);virtio_cleanup (vdev); - -if (s->vhost_user) { -vhost_user_cleanup (s->vhost_user); -g_free (s->vhost_user); - s->vhost_user =NULL ; - } +vhost_user_cleanup (&s->vhost_user); }static void vhost_user_blk_instance_init (Object *obj)
hw/scsi/vhost-user-scsi.c +4 -16
@@ -69,7 +69,6 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (dev);VHostUserSCSI *s =VHOST_USER_SCSI (dev);VHostSCSICommon *vsc =VHOST_SCSI_COMMON (s); -VhostUserState *user;Error *err =NULL ;int ret;
@@ -86,30 +85,24 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)return ; } - user =vhost_user_init (); -if (!user) { -error_setg (errp,"vhost-user-scsi: failed to init vhost_user" ); +if (!vhost_user_init (&s->vhost_user, &vs->conf.chardev, errp)) {return ; } - user->chr = &vs->conf.chardev; vsc->dev.nvqs =2 + vs->conf.num_queues; vsc->dev.vqs = g_new(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vq_index =0 ; vsc->dev.backend_features =0 ; - ret =vhost_dev_init (&vsc->dev, user, + ret =vhost_dev_init (&vsc->dev, &s->vhost_user,VHOST_BACKEND_TYPE_USER ,0 );if (ret <0 ) {error_setg (errp,"vhost-user-scsi: vhost initialization failed: %s" ,strerror (-ret)); -vhost_user_cleanup (user); -g_free (user); +vhost_user_cleanup (&s->vhost_user);return ; } - s->vhost_user = user; -/* Channel and lun both are 0 for bootable vhost-user-scsi disk */ vsc->channel =0 ; vsc->lun =0 ;
@@ -129,12 +122,7 @@ static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp)g_free (vsc->dev.vqs);virtio_scsi_common_unrealize (dev, errp); - -if (s->vhost_user) { -vhost_user_cleanup (s->vhost_user); -g_free (s->vhost_user); - s->vhost_user =NULL ; - } +vhost_user_cleanup (&s->vhost_user); } static uint64_t vhost_user_scsi_get_features(VirtIODevice *vdev,
hw/virtio/vhost-stub.c +2 -2
@@ -7,9 +7,9 @@ bool vhost_has_free_slot(void)return true; } -VhostUserState *vhost_user_init (void ) +bool vhost_user_init (VhostUserState *user,CharBackend *chr,Error **errp) { -return NULL ; +return false; }void vhost_user_cleanup (VhostUserState *user)
hw/virtio/vhost-user.c +12 -4
@@ -1743,17 +1743,24 @@ static bool vhost_user_mem_section_filter(struct vhost_dev *dev,return result; } -VhostUserState *vhost_user_init (void ) +bool vhost_user_init (VhostUserState *user,CharBackend *chr,Error **errp) { - VhostUserState *user = g_new0(struct VhostUserState, 1); - -return user; +if (user->chr) { +error_setg (errp,"Cannot initialize vhost-user state" ); +return false; + } + user->chr = chr; +return true; }void vhost_user_cleanup (VhostUserState *user) {int i; +if (!user->chr) { +return ; + } +for (i =0 ; i <VIRTIO_QUEUE_MAX ; i++) {if (user->notifier[i].addr) {object_unparent (OBJECT (&user->notifier[i].mr));
@@ -1761,6 +1768,7 @@ void vhost_user_cleanup(VhostUserState *user) user->notifier[i].addr =NULL ; } } + user->chr =NULL ; }const VhostOps user_ops = {
net/vhost-user.c +4 -9
@@ -291,19 +291,14 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, {Error *err =NULL ;NetClientState *nc, *nc0 =NULL ; -VhostUserState *user =NULL ;NetVhostUserState *s =NULL ; +VhostUserState *user;int i;assert (name);assert (queues >0 ); - user =vhost_user_init (); -if (!user) { -error_report ("failed to init vhost_user" ); - goto err; - } - + user = g_new0(struct VhostUserState, 1);for (i =0 ; i < queues; i++) { nc =qemu_new_net_client (&net_vhost_user_info, peer, device, name); snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
@@ -312,11 +307,11 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,if (!nc0) { nc0 = nc; s =DO_UPCAST (NetVhostUserState, nc, nc); -if (!qemu_chr_fe_init (&s->chr, chr, &err)) { +if (!qemu_chr_fe_init (&s->chr, chr, &err) || + !vhost_user_init (user, &s->chr, &err)) {error_report_err (err); goto err; } - user->chr = &s->chr; } s =DO_UPCAST (NetVhostUserState, nc, nc); s->vhost_user = user;
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 6/29 libvhost-user: exit by default on VHOST_USER_NONE
In reply to Marc-André LureauSince commit 2566378d6d13bf4d28c7770bdbda5f7682594bbe, libvhost-user no longer panics on disconnect (rc == 0), and instead silently ignores an invalid VHOST_USER_NONE message.
Without extra work from the API user, this will simply busy-loop on HUP events. The obvious thing to do is to exit(0) instead, while additional or different work can be done by overriding iface->process_msg().
--- contrib/libvhost-user/libvhost-user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +2 -1
@@ -1285,7 +1285,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg)case VHOST_USER_SET_CONFIG :return vu_set_config (dev, vmsg);case VHOST_USER_NONE : -break ; +/* if you need processing before exit, override iface->process_msg */ +exit (0 );case VHOST_USER_POSTCOPY_ADVISE :return vu_set_postcopy_advise (dev, vmsg);case VHOST_USER_POSTCOPY_LISTEN :
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 06/29] libvhost-user: exit by default on VHOST_USER_NONE
Quoted 9 lines
Since commit
2566378d6d13bf4d28c7770bdbda5f7682594bbe, libvhost-user no longer panics on disconnect (rc == 0), and instead silently ignores an invalidVHOST_USER_NONEmessage.Without extra work from the API user, this will simply busy-loop on HUP events. The obvious thing to do is to exit(0) instead, while additional or different work can be done by overriding
iface->process_msg().
Quoted 4 lines
Signed-off-by Marc-André Lureau <[email protected]>--- contrib/libvhost-user/libvhost-user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH v4 7/29 vhost-user: wrap some read/write with retry handling
In reply to Marc-André Lureau--- hw/virtio/vhost-user.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
hw/virtio/vhost-user.c +12 -3
@@ -975,7 +975,10 @@ static void slave_read(void *opaque) iov.iov_base = &hdr; iov.iov_len =VHOST_USER_HDR_SIZE ; - size =recvmsg (u->slave_fd, &msgh,0 ); +do { + size =recvmsg (u->slave_fd, &msgh,0 ); + }while (size <0 && (errno ==EINTR || errno ==EAGAIN )); +if (size !=VHOST_USER_HDR_SIZE ) {error_report ("Failed to read from slave." ); goto err;
@@ -1004,7 +1007,10 @@ static void slave_read(void *opaque) }/* Read payload */ - size =read (u->slave_fd, &payload, hdr.size); +do { + size =read (u->slave_fd, &payload, hdr.size); + }while (size <0 && (errno ==EINTR || errno ==EAGAIN )); +if (size != hdr.size) {error_report ("Failed to read payload from slave." ); goto err;
@@ -1052,7 +1058,10 @@ static void slave_read(void *opaque) iovec[1 ].iov_base = &payload; iovec[1 ].iov_len = hdr.size; - size =writev (u->slave_fd, iovec,ARRAY_SIZE (iovec)); +do { + size =writev (u->slave_fd, iovec,ARRAY_SIZE (iovec)); + }while (size <0 && (errno ==EINTR || errno ==EAGAIN )); +if (size !=VHOST_USER_HDR_SIZE + hdr.size) {error_report ("Failed to send msg reply to slave." ); goto err;
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 8/29 Add vhost-user-backend
In reply to Marc-André LureauCreate a vhost-user-backend object that holds a connection to a vhost-user backend and can be referenced from virtio devices that support it. See later patches for input & gpu usage.
A chardev can be specified to communicate with the vhost-user backend,
ex: -chardev socket,id=char0,path=/tmp/foo.sock -object vhost-user-backend,id=vuid,chardev=char0.
--- include/sysemu/vhost-user-backend.h | 60 +++++++ backends/vhost-user.c | 244 ++++++++++++++++++++++++++++ vl.c | 3 +- MAINTAINERS | 2 + backends/Makefile.objs | 3 +- qemu-options.hx | 20 +++ 6 files changed, 330 insertions(+), 2 deletions(-) create mode 100644 include/sysemu/vhost-user-backend.h create mode 100644 backends/vhost-user.c
include/sysemu/vhost-user-backend.h new file +60 -0
@@ -0,0 +1,60 @@ +/* +* QEMU vhost-user backend +* +* Copyright (C) 2018 Red Hat Inc +* +* Authors: +* Marc-André Lureau <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef QEMU_VHOST_USER_BACKEND_H +#define QEMU_VHOST_USER_BACKEND_H + +#include "qom/object.h" +#include "exec/memory.h" +#include "qemu/option.h" +#include "qemu/bitmap.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.h" +#include "io/channel.h" + +#define TYPE_VHOST_USER_BACKEND "vhost-user-backend" +#define VHOST_USER_BACKEND (obj) \ + OBJECT_CHECK(VhostUserBackend, (obj), TYPE_VHOST_USER_BACKEND) +#define VHOST_USER_BACKEND_GET_CLASS (obj) \ + OBJECT_GET_CLASS(VhostUserBackendClass, (obj), TYPE_VHOST_USER_BACKEND) +#define VHOST_USER_BACKEND_CLASS (klass) \ + OBJECT_CLASS_CHECK(VhostUserBackendClass, (klass), TYPE_VHOST_USER_BACKEND) + +typedef struct VhostUserBackend VhostUserBackend ; +typedef struct VhostUserBackendClass VhostUserBackendClass ; + +struct VhostUserBackendClass { +ObjectClass parent_class; +}; + +struct VhostUserBackend { +/* private */ +Object parent; + +char *cmd; +char *chr_name; + +CharBackend chr; +VhostUserState vhost_user; +struct vhost_dev dev; +QIOChannel *child; +VirtIODevice *vdev; +bool started; +bool completed; +}; + +int vhost_user_backend_dev_init (VhostUserBackend *b,VirtIODevice *vdev, +unsigned nvqs,Error **errp); +void vhost_user_backend_start (VhostUserBackend *b); +void vhost_user_backend_stop (VhostUserBackend *b); + +#endif
backends/vhost-user.c new file +244 -0
244 lines not on this page · raw message
vl.c +2 -1
@@ -2737,7 +2737,8 @@ static bool object_create_initial(const char *type) }#if defined(CONFIG_VHOST_USER ) && defined(CONFIG_LINUX ) -if (g_str_equal (type,"cryptodev-vhost-user" )) { +if (g_str_equal (type,"cryptodev-vhost-user" ) || +g_str_equal (type,"vhost-user-backend" )) {return false; }#endif
MAINTAINERS +2 -0
@@ -1189,6 +1189,8 @@ M: Michael S. Tsirkin <[email protected]> S: Supported F: hw/*/*vhost* F: docs/interop/vhost-user.txt +F: backends/vhost-user.c +F: include/sysemu/vhost-user-backend.h virtio M: Michael S. Tsirkin <[email protected]>
backends/Makefile.objs +2 -1
@@ -12,7 +12,8 @@ common-obj-y += cryptodev-builtin.o ifeq ($(CONFIG_VIRTIO),y) common-obj-y += cryptodev-vhost.o common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX)) += \ - cryptodev-vhost-user.o + cryptodev-vhost-user.o \ + vhost-user.o endif common-obj-$(CONFIG_LINUX) += hostmem-memfd.o
qemu-options.hx +20 -0
@@ -4292,6 +4292,26 @@ secondary: If you want to know the detail of above command line, you can read the colo-compare git log. +@item -object vhost-user-backend,id=id=@var{id},chardev=@var{chardevid} + +Create a vhost-user-backend object that holds a connection to a +vhost-user backend and can be referenced from virtio/vhost-user +devices that support it. + +The @var{id} parameter is a unique ID that will be used to reference +this vhost-user backend from the @option{vhost-user} device. The +@var{chardev} parameter is the unique ID of a character device backend +that provides the connection to the vhost-user slave process. (Since 3.0) + +@example + + # qemu-system-x86_64 \ + [...] \ + -object vhost-user-backend,id=vuid,chardev=char0 \ + -device vhost-user-input-pci,vhost-user=vuid + [...] +@end example + @item -object cryptodev-backend-builtin,id=@var{id}[,queues=@var{queues}] Creates a cryptodev backend which executes crypto opreation from
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 9/29 qio: add qio_channel_command_new_spawn_with_pre_exec()
In reply to Marc-André LureauAdd a new function to let caller do some tuning thanks to a callback before exec().
--- include/io/channel-command.h | 18 ++++++++++++++++++ io/channel-command.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 7 deletions(-)
include/io/channel-command.h +18 -0
@@ -71,6 +71,24 @@ qio_channel_command_new_pid(int writefd,int readfd, pid_t pid); +/** +* qio_channel_command_new_spawn_with_pre_exec: +* @argv: the NULL terminated list of command arguments +* @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR +* @errp: pointer to a NULL-initialized error object +* +* Create a channel for performing I/O with the +* command to be spawned with arguments @argv. +* +* Returns: the command channel object, or NULL on error +*/ +QIOChannelCommand * +qio_channel_command_new_spawn_with_pre_exec (const char *const argv[], +int flags, +void (*pre_exec_cb)(void *), +void *data, +Error **errp); +/** * qio_channel_command_new_spawn: * @argv: the NULL terminated list of command arguments
io/channel-command.c +26 -7
@@ -46,9 +46,12 @@ qio_channel_command_new_pid(int writefd,#ifndef WIN32 QIOChannelCommand * -qio_channel_command_new_spawn (const char *const argv[], -int flags, -Error **errp) +qio_channel_command_new_spawn_with_pre_exec (const char *const argv[], +int flags, +void (*pre_exec_cb)(void *), +void *data, +Error **errp) + {pid_t pid =-1 ;int stdinfd[2 ] = {-1 ,-1 };
@@ -104,6 +107,10 @@ qio_channel_command_new_spawn(const char *const argv[],close (devnull); } +if (pre_exec_cb) { +pre_exec_cb (data); + } +execv (argv[0 ], (char *const *)argv);_exit (1 ); }
@@ -139,12 +146,13 @@ qio_channel_command_new_spawn(const char *const argv[], }return NULL ; } -#else /* WIN32 */ QIOChannelCommand * -qio_channel_command_new_spawn (const char *const argv[], -int flags, -Error **errp) +qio_channel_command_new_spawn_with_pre_exec (const char *const argv[], +int flags, +void (*pre_exec_cb)(void *), +void *data, +Error **errp) {error_setg_errno (errp,ENOSYS ,"Command spawn not supported on this platform" );
@@ -152,6 +160,17 @@ qio_channel_command_new_spawn(const char *const argv[], }#endif /* WIN32 */ + +QIOChannelCommand * +qio_channel_command_new_spawn (const char *const argv[], +int flags, +Error **errp) +{ +return qio_channel_command_new_spawn_with_pre_exec (argv, flags, +NULL ,NULL , errp); +} + +#ifndef WIN32 static int qio_channel_command_abort (QIOChannelCommand *ioc,Error **errp)
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 09/29] qio: add qio_channel_command_new_spawn_with_pre_exec()
Quoted 14 lines · Marc-André Lureau
Add a new function to let caller do some tuning thanks to a callback before
exec().Signed-off-by Marc-André Lureau <[email protected]>--- include/io/channel-command.h | 18 ++++++++++++++++++ io/channel-command.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 7 deletions(-)include/io/channel-command.h +0
-0
include/io/channel-command.h qio_channel_command_new_pid(int writefd, · line 78
Quoted 8 lines
include/io/channel-command.h +5
-0@@ -71,6 +71,24 @@ qio_channel_command_new_pid(int writefd,int readfd, pid_t pid); +/** +* qio_channel_command_new_spawn_with_pre_exec: +* @argv: the NULL terminated list of command arguments +* @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR +* @errp: pointer to a NULL-initialized error object
Missing the new args
include/io/channel-command.h qio_channel_command_new_pid(int writefd, · line 90
Quoted 12 lines
include/io/channel-command.h +12
-0+* +* Create a channel for performing I/O with the +* command to be spawned with arguments @argv. +* +* Returns: the command channel object, or NULL on error +*/ +QIOChannelCommand * +qio_channel_command_new_spawn_with_pre_exec (const char *const argv[], +int flags, +void (*pre_exec_cb)(void *), +void *data, +Error **errp);
I have a slight preference for using a typedef for the callback signature, and providing API docs explaining the contract.
eg the callback should call _exit() if something happens that it can't handle
Quoted 75 lines
include/io/channel-command.h +1
-0+/** * qio_channel_command_new_spawn: * @argv: the NULL terminated list of command arguments io/channel-command.c +26
-7@@ -46,9 +46,12 @@ qio_channel_command_new_pid(int writefd,#ifndef WIN32 QIOChannelCommand * -qio_channel_command_new_spawn (const char *const argv[], -int flags, -Error **errp) +qio_channel_command_new_spawn_with_pre_exec (const char *const argv[], +int flags, +void (*pre_exec_cb)(void *), +void *data, +Error **errp) + {pid_t pid =-1 ;int stdinfd[2 ] = {-1 ,-1 };@@ -104,6 +107,10 @@ qio_channel_command_new_spawn(const char *const argv[],close (devnull); } +if (pre_exec_cb) { +pre_exec_cb (data); + } +execv (argv[0 ], (char *const *)argv);_exit (1 ); }@@ -139,12 +146,13 @@ qio_channel_command_new_spawn(const char *const argv[], }return NULL ; } -#else /* WIN32 */ QIOChannelCommand * -qio_channel_command_new_spawn (const char *const argv[], -int flags, -Error **errp) +qio_channel_command_new_spawn_with_pre_exec (const char *const argv[], +int flags, +void (*pre_exec_cb)(void *), +void *data, +Error **errp) {error_setg_errno (errp,ENOSYS ,"Command spawn not supported on this platform" );@@ -152,6 +160,17 @@ qio_channel_command_new_spawn(const char *const argv[], }#endif /* WIN32 */ + +QIOChannelCommand * +qio_channel_command_new_spawn (const char *const argv[], +int flags, +Error **errp) +{ +return qio_channel_command_new_spawn_with_pre_exec (argv, flags, +NULL ,NULL , errp); +} + +#ifndef WIN32 static int qio_channel_command_abort (QIOChannelCommand *ioc,Error **errp)Signature · 1 line
2.18.0.129.ge3331758f1
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 10/29 HACK: vhost-user-backend: allow to specify binary to execute
In reply to Marc-André LureauAn executable with its arguments may be given as 'cmd' property, ex:
-object vhost-user-backend,id=vui,cmd="./vhost-user-input /dev/input..". The executable is then spawn and, by convention, the vhost-user socket is passed as fd=3. It may be considered a security breach to allow creating processes that may execute arbitrary executables, so this may be restricted to some known executables (via signature etc) or directory.
To make the patch more acceptable, the command argument would have to be passed via an array (probably via -object json: syntax), instead of using g_shell_parse_argv().
--- backends/vhost-user.c | 96 ++++++++++++++++++++++++++++++++++++++----- qemu-options.hx | 12 ++++-- 2 files changed, 94 insertions(+), 14 deletions(-)
backends/vhost-user.c +86 -10
@@ -136,31 +136,105 @@ vhost_user_backend_stop(VhostUserBackend *b) b->started = false; } +static void +pre_exec_cb (void *data) +{ +int *sv = data; +int maxfd =sysconf (_SC_OPEN_MAX); +int fd; + +dup2 (sv[1 ],3 ); +for (fd =4 ; fd < maxfd; fd++) { +close (fd); + } +} +static void vhost_user_backend_complete (UserCreatable *uc,Error **errp) {VhostUserBackend *b =VHOST_USER_BACKEND (uc);Chardev *chr; +char **argv =NULL ; -if (!b->chr_name) { -error_setg (errp,"You must specificy 'chardev'." ); +if (!!b->chr_name + !!b->cmd !=1 ) { +error_setg (errp,"You may specificy only one of 'chardev' or 'cmd'." );return ; } - chr =qemu_chr_find (b->chr_name); -if (chr ==NULL ) { -error_set (errp,ERROR_CLASS_DEVICE_NOT_FOUND , -"Chardev '%s' not found" , b->chr_name); -return ; - } +if (b->chr_name) { + chr =qemu_chr_find (b->chr_name); +if (chr ==NULL ) { +error_set (errp,ERROR_CLASS_DEVICE_NOT_FOUND , +"Chardev '%s' not found" , b->chr_name); +return ; + } -if (!qemu_chr_fe_init (&b->chr, chr, errp)) { -return ; +if (!qemu_chr_fe_init (&b->chr, chr, errp)) { +return ; + } + }else { +QIOChannelCommand *child; +GError *err; +int sv[2 ]; + +if (!g_shell_parse_argv (b->cmd,NULL , &argv, &err)) { +error_setg (errp,"Fail to parse command: %s" , err->message); +g_error_free (err); +return ; + } + +if (socketpair (PF_UNIX ,SOCK_STREAM ,0 , sv) ==-1 ) { +error_setg_errno (errp, errno,"socketpair() failed" ); + goto end; + } + + chr =CHARDEV (object_new (TYPE_CHARDEV_SOCKET )); +if (!chr ||qemu_chr_add_client (chr, sv[0 ]) ==-1 ) { +error_setg (errp,"Failed to make socket chardev" ); +object_unref (OBJECT (chr)); + goto end; + } + +if (!qemu_chr_fe_init (&b->chr, chr, errp)) { + goto end; + } + + child =qio_channel_command_new_spawn_with_pre_exec ( + (const char *const *)argv,O_RDONLY |O_WRONLY , + pre_exec_cb, sv, errp); +if (!child) { + goto end; + } + b->child =QIO_CHANNEL (child); + +close (sv[1 ]); } b->completed = true;/* could vhost_dev_init() happen here, so early vhost-user message * can be exchanged */ +end: +g_strfreev (argv); +} + +static char *get_cmd (Object *obj,Error **errp) +{ +VhostUserBackend *b =VHOST_USER_BACKEND (obj); + +return g_strdup (b->cmd); +} + +static void set_cmd (Object *obj,const char *str,Error **errp) +{ +VhostUserBackend *b =VHOST_USER_BACKEND (obj); + +if (b->child) { +error_setg (errp,"cannot change property value" ); +return ; + } + +g_free (b->cmd); + b->cmd =g_strdup (str); }static void set_chardev (Object *obj,const char *value,Error **errp)
@@ -189,6 +263,7 @@ static char *get_chardev(Object *obj, Error **errp)static void vhost_user_backend_init (Object *obj) { +object_property_add_str (obj,"cmd" , get_cmd, set_cmd,NULL );object_property_add_str (obj,"chardev" , get_chardev, set_chardev,NULL ); }
@@ -197,6 +272,7 @@ static void vhost_user_backend_finalize(Object *obj)VhostUserBackend *b =VHOST_USER_BACKEND (obj);g_free (b->dev.vqs); +g_free (b->cmd);g_free (b->chr_name);vhost_user_cleanup (&b->vhost_user);
qemu-options.hx +8 -4
@@ -4292,16 +4292,20 @@ secondary: If you want to know the detail of above command line, you can read the colo-compare git log. -@item -object vhost-user-backend,id=id=@var{id},chardev=@var{chardevid} +@item -object vhost-user-backend,id=id=@var{id}[,chardev=@var{chardevid},cmd=@var{cmd}] Create a vhost-user-backend object that holds a connection to a vhost-user backend and can be referenced from virtio/vhost-user devices that support it. The @var{id} parameter is a unique ID that will be used to reference -this vhost-user backend from the @option{vhost-user} device. The -@var{chardev} parameter is the unique ID of a character device backend -that provides the connection to the vhost-user slave process. (Since 3.0) +this vhost-user backend from the @option{vhost-user} device. + +You must specify either @var{chardev} or @var{cmd}. The @var{chardev} +parameter is the unique ID of a character device backend that provides +the connection to the vhost-user slave process. The @var{cmd} +parameter will simplify handling of the backend, by running the given +command and establishing the connection. (Since 3.1) @example
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 10/29] HACK: vhost-user-backend: allow to specify binary to execute
Quoted 7 lines · Marc-André Lureau
An executable with its arguments may be given as 'cmd' property, ex:
-object vhost-user-backend,id=vui,cmd="./vhost-user-input/dev/input..". The executable is then spawn and, by convention, the vhost-user socket is passed as fd=3. It may be considered a security breach to allow creating processes that may execute arbitrary executables, so this may be restricted to some known executables (via signature etc) or directory.
NB, Libvirt runs all QEMU instances with a seccomp policy that forbids any use of execve(), so libvirt won't use 'cmd' at all.
Quoted 3 lines
To make the patch more acceptable, the command argument would have to be passed via an array (probably via -object json: syntax), instead of using
g_shell_parse_argv().
I still think we should not allow args to be specified at all. Declare a stable API contract for this script where QEMU defines what argv and env will be provided, in the same way we do for TAP ifup scripts. Then on the CLI we'd only need a binary path.
Quoted 6 lines
backends/vhost-user.c +0
-0@@ -136,31 +136,105 @@ vhost_user_backend_stop(VhostUserBackend *b) b->started = false;
backends/vhost-user.c vhost_user_backend_stop(VhostUserBackend *b) · line 146
Quoted 10 lines
backends/vhost-user.c +8
-0} +static void +pre_exec_cb (void *data) +{ +int *sv = data; +int maxfd =sysconf (_SC_OPEN_MAX); +int fd; + +dup2 (sv[1 ],3 );
error checking...
backends/vhost-user.c vhost_user_backend_stop(VhostUserBackend *b) · line 148
Quoted 2 lines
backends/vhost-user.c +2
-0+for (fd =4 ; fd < maxfd; fd++) { +close (fd);
This shouldn't fail, but to be robust we should check errors anyway.
Quoted 20 lines
backends/vhost-user.c +3
-0+ } +} +qemu-options.hx +1
-1@@ -4292,16 +4292,20 @@ secondary: If you want to know the detail of above command line, you can read the colo-compare git log. -@item -object vhost-user-backend,id=id=@var{id},chardev=@var{chardevid} +@item -object vhost-user-backend,id=id=@var{id}[,chardev=@var{chardevid},cmd=@var{cmd}] Create a vhost-user-backend object that holds a connection to a vhost-user backend and can be referenced from virtio/vhost-user devices that support it. The @var{id} parameter is a unique ID that will be used to reference
qemu-options.hx secondary: · line 4308
Quoted 10 lines
qemu-options.hx +7
-3-this vhost-user backend from the @option{vhost-user} device. The -@var{chardev} parameter is the unique ID of a character device backend -that provides the connection to the vhost-user slave process. (Since 3.0) +this vhost-user backend from the @option{vhost-user} device. + +You must specify either @var{chardev} or @var{cmd}. The @var{chardev} +parameter is the unique ID of a character device backend that provides +the connection to the vhost-user slave process. The @var{cmd} +parameter will simplify handling of the backend, by running the given +command and establishing the connection. (Since 3.1)
Should note that 'cmd' is not usable with seccomp policy that blocks execve.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 11/29 vhost-user: split vhost_user_read()
In reply to Marc-André LureauSplit vhost_user_read(), so only header can be read with vhost_user_read_header().
--- hw/virtio/vhost-user.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
hw/virtio/vhost-user.c +19 -8
@@ -210,7 +210,7 @@ static bool ioeventfd_enabled(void)return kvm_enabled () &&kvm_eventfds_enabled (); } -static int vhost_user_read (struct vhost_dev *dev,VhostUserMsg *msg) +static int vhost_user_read_header (struct vhost_dev *dev,VhostUserMsg *msg) {struct vhost_user *u = dev->opaque;CharBackend *chr = u->user->chr;
@@ -221,7 +221,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)if (r != size) {error_report ("Failed to read msg header. Read %d instead of %d." " Original request %d." , r, size, msg->hdr.request); - goto fail; +return -1 ; }/* validate received flags */
@@ -229,7 +229,21 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)error_report ("Failed to read msg header." " Flags 0x%x instead of 0x%x." , msg->hdr.flags,VHOST_USER_REPLY_MASK |VHOST_USER_VERSION ); - goto fail; +return -1 ; + } + +return 0 ; +} + +static int vhost_user_read (struct vhost_dev *dev,VhostUserMsg *msg) +{ +struct vhost_user *u = dev->opaque; +CharBackend *chr = u->user->chr; +uint8_t *p = (uint8_t *) msg; +int r, size; + +if (vhost_user_read_header (dev, msg) <0 ) { +return -1 ; }/* validate message size is sane */
@@ -237,7 +251,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)error_report ("Failed to read msg header." " Size %d exceeds the maximum %zu." , msg->hdr.size,VHOST_USER_PAYLOAD_SIZE ); - goto fail; +return -1 ; }if (msg->hdr.size) {
@@ -247,14 +261,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)if (r != size) {error_report ("Failed to read msg payload." " Read %d instead of %d." , r, msg->hdr.size); - goto fail; +return -1 ; } }return 0 ; - -fail: -return -1 ; } static int process_message_reply(struct vhost_dev *dev,
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 11/29] vhost-user: split vhost_user_read()
Quoted 7 lines · Marc-André Lureau
Split
vhost_user_read(), so only header can be read withvhost_user_read_header().Signed-off-by Marc-André Lureau <[email protected]>--- hw/virtio/vhost-user.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 12/29 vhost-user: add vhost_user_input_get_config()
In reply to Marc-André LureauAsk vhost user input backend the list of virtio_input_config.
--- contrib/libvhost-user/libvhost-user.h | 1 + include/hw/virtio/vhost-backend.h | 4 ++ hw/virtio/vhost-user.c | 59 +++++++++++++++++++++++++++ docs/interop/vhost-user.txt | 7 ++++ 4 files changed, 71 insertions(+)
contrib/libvhost-user/libvhost-user.h +1 -0
@@ -91,6 +91,7 @@ typedef enum VhostUserRequest {VHOST_USER_POSTCOPY_ADVISE =28 ,VHOST_USER_POSTCOPY_LISTEN =29 ,VHOST_USER_POSTCOPY_END =30 , +VHOST_USER_INPUT_GET_CONFIG =31 , VHOST_USER_MAX } VhostUserRequest;
include/hw/virtio/vhost-backend.h +4 -0
@@ -12,6 +12,7 @@#define VHOST_BACKEND_H #include "exec/memory.h" +#include "standard-headers/linux/virtio_input.h" typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE = 0,
@@ -160,4 +161,7 @@ int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev,int vhost_backend_handle_iotlb_msg (struct vhost_dev *dev,struct vhost_iotlb_msg *imsg); +int vhost_user_input_get_config (struct vhost_dev *dev, +struct virtio_input_config **config); +#endif /* VHOST_BACKEND_H */
hw/virtio/vhost-user.c +59 -0
71 lines not on this page · raw message
docs/interop/vhost-user.txt +7 -0
@@ -761,6 +761,13 @@ Master message types was previously sent. The value returned is an error indication; 0 is success. + * VHOST_USER_INPUT_GET_CONFIG + Id: 31 + Master payload: N/A + Slave payload: (struct virtio_input_config)* + + Ask vhost user input backend the list of virtio_input_config. + Slave message types -------------------
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 13/29 libvhost-user: export vug_source_new()
In reply to Marc-André LureauSimplify the creation of FD sources for other users.
--- contrib/libvhost-user/libvhost-user-glib.h | 3 +++ contrib/libvhost-user/libvhost-user-glib.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
contrib/libvhost-user/libvhost-user-glib.h +3 -0
@@ -29,4 +29,7 @@ void vug_init(VugDev *dev, int socket, vu_panic_cb panic, const VuDevIface *iface);void vug_deinit (VugDev *dev); +GSource *vug_source_new (VugDev *dev,int fd,GIOCondition cond, +vu_watch_cb vu_cb,gpointer data); +#endif /* LIBVHOST_USER_GLIB_H */
contrib/libvhost-user/libvhost-user-glib.c +11 -4
@@ -69,8 +69,8 @@ static GSourceFuncs vug_src_funcs = { };static GSource * -vug_source_new (VuDev *dev,int fd,GIOCondition cond, -vu_watch_cb vu_cb,gpointer data) +_vug_source_new (VuDev *dev,int fd,GIOCondition cond, +vu_watch_cb vu_cb,gpointer data) {GSource *gsrc;VugSrc *src;
@@ -95,6 +95,13 @@ vug_source_new(VuDev *dev, int fd, GIOCondition cond,return gsrc; } +GSource * +vug_source_new (VugDev *dev,int fd,GIOCondition cond, +vu_watch_cb vu_cb,gpointer data) +{ +return _vug_source_new (&dev->parent, fd, cond, vu_cb, data); +} +static void set_watch (VuDev *vu_dev,int fd,int vu_evt,vu_watch_cb cb,void *pvt) {
@@ -106,7 +113,7 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt, vu_watch_cb cb, void *pvt)g_assert (cb); dev =container_of (vu_dev, VugDev, parent); - src =vug_source_new (vu_dev, fd, vu_evt, cb, pvt); + src =_vug_source_new (vu_dev, fd, vu_evt, cb, pvt);g_hash_table_replace (dev->fdmap,GINT_TO_POINTER (fd), src); }
@@ -141,7 +148,7 @@ vug_init(VugDev *dev, int socket, dev->fdmap =g_hash_table_new_full (NULL ,NULL ,NULL , (GDestroyNotify ) g_source_destroy); - dev->src =vug_source_new (&dev->parent, socket,G_IO_IN , vug_watch,NULL ); + dev->src =_vug_source_new (&dev->parent, socket,G_IO_IN , vug_watch,NULL ); }void
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 14/29 contrib: add vhost-user-input
In reply to Marc-André LureauAdd a vhost-user input backend, based on virtio-input-host device. It takes an evdev path as argument, and can be associated with a vhost-user-backend object, ex:
-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event0"
--- contrib/vhost-user-input/main.c | 379 +++++++++++++++++++++++++ MAINTAINERS | 1 + Makefile | 3 + Makefile.objs | 1 + configure | 3 + contrib/vhost-user-input/Makefile.objs | 1 + 6 files changed, 388 insertions(+) create mode 100644 contrib/vhost-user-input/main.c create mode 100644 contrib/vhost-user-input/Makefile.objs
contrib/vhost-user-input/main.c new file +379 -0
@@ -0,0 +1,379 @@ +/* +* This work is licensed under the terms of the GNU GPL, version 2 or +* (at your option) any later version. See the COPYING file in the +* top-level directory. +*/ + +#include "qemu/osdep.h" + +#include <glib.h> +#include <linux/input.h> + +#include "qemu/iov.h" +#include "qemu/bswap.h" +#include "contrib/libvhost-user/libvhost-user.h" +#include "contrib/libvhost-user/libvhost-user-glib.h" +#include "standard-headers/linux/virtio_input.h" +#include "qapi/error.h" + +typedef struct virtio_input_event virtio_input_event ; +typedef struct virtio_input_config virtio_input_config ; + +typedef struct VuInput { +VugDev dev; +GSource *evsrc; +int evdevfd; +GArray *config; +virtio_input_event *queue; +uint32_t qindex, qsize; +}VuInput ; + +static void vi_input_send (VuInput *vi,struct virtio_input_event *event) +{ +VuDev *dev = &vi->dev.parent; +VuVirtq *vq =vu_get_queue (dev,0 ); +VuVirtqElement *elem; +unsigned have, need; +int i, len; + +/* queue up events ... */ +if (vi->qindex == vi->qsize) { + vi->qsize++; + vi->queue =realloc (vi->queue, vi->qsize * +sizeof (virtio_input_event)); + } + vi->queue[vi->qindex++] = *event; + +/* ... until we see a report sync ... */ +if (event->type !=htole16 (EV_SYN ) || + event->code !=htole16 (SYN_REPORT )) { +return ; + } + +/* ... then check available space ... */ + need =sizeof (virtio_input_event) * vi->qindex; +vu_queue_get_avail_bytes (dev, vq, &have,NULL , need,0 ); +if (have < need) { + vi->qindex =0 ; +g_warning ("ENOSPC in vq, dropping events" ); +return ; + } + +/* ... and finally pass them to the guest */ +for (i =0 ; i < vi->qindex; i++) { + elem =vu_queue_pop (dev, vq,sizeof (VuVirtqElement)); +if (!elem) { +/* should not happen, we've checked for space beforehand */ +g_warning ("%s: Huh? No vq elem available ...\n" , __func__); +return ; + } + len =iov_from_buf (elem->in_sg, elem->in_num, +0 , vi->queue + i,sizeof (virtio_input_event)); +vu_queue_push (dev, vq, elem, len); +g_free (elem); + } +vu_queue_notify (&vi->dev.parent, vq); + vi->qindex =0 ; +} + +static void +vi_evdev_watch (VuDev *dev,int condition,void *data) +{ +VuInput *vi = data; +int fd = vi->evdevfd; + +g_debug ("Got evdev condition %x" , condition); + +struct virtio_input_event virtio; +struct input_event evdev; +int rc; + +for (;;) { + rc =read (fd, &evdev,sizeof (evdev)); +if (rc !=sizeof (evdev)) { +break ; + } + +g_debug ("input %d %d %d" , evdev.type, evdev.code, evdev.value); + + virtio.type =htole16 (evdev.type); + virtio.code =htole16 (evdev.code); + virtio.value =htole32 (evdev.value); +vi_input_send (vi, &virtio); + } +} + + +static void vi_handle_status (VuInput *vi,virtio_input_event *event) +{ +struct input_event evdev; +int rc; + +if (gettimeofday (&evdev.time,NULL )) { +perror ("vi_handle_status: gettimeofday" ); +return ; + } + + evdev.type =le16toh (event->type); + evdev.code =le16toh (event->code); + evdev.value =le32toh (event->value); + + rc =write (vi->evdevfd, &evdev,sizeof (evdev)); +if (rc ==-1 ) { +perror ("vi_host_handle_status: write" ); + } +} + +static void vi_handle_sts (VuDev *dev,int qidx) +{ +VuInput *vi =container_of (dev, VuInput, dev.parent); +VuVirtq *vq =vu_get_queue (dev, qidx); +virtio_input_event event; +VuVirtqElement *elem; +int len; + +g_debug ("%s" ,G_STRFUNC ); + +for (;;) { + elem =vu_queue_pop (dev, vq,sizeof (VuVirtqElement)); +if (!elem) { +break ; + } + +memset (&event,0 ,sizeof (event)); + len =iov_to_buf (elem->out_sg, elem->out_num, +0 , &event,sizeof (event)); +vi_handle_status (vi, &event); +vu_queue_push (dev, vq, elem, len); +g_free (elem); + } + +vu_queue_notify (&vi->dev.parent, vq); +} + +static void +vi_panic (VuDev *dev,const char *msg) +{ +g_critical ("%s\n" , msg); +exit (1 ); +} + +static void +vi_queue_set_started (VuDev *dev,int qidx,bool started) +{ +VuInput *vi =container_of (dev, VuInput, dev.parent); +VuVirtq *vq =vu_get_queue (dev, qidx); + +g_debug ("queue started %d:%d" , qidx, started); + +if (qidx ==0 ) { +if (started && !vi->evsrc) { + vi->evsrc =vug_source_new (&vi->dev, vi->evdevfd, +G_IO_IN , vi_evdev_watch, vi); + }else if (!started) { +g_source_destroy (vi->evsrc); + vi->evsrc =NULL ; + } + }else { +vu_set_queue_handler (dev, vq, started ? vi_handle_sts :NULL ); + } +} + +static int +vi_process_msg (VuDev *dev,VhostUserMsg *vmsg,int *do_reply) +{ +VuInput *vi =container_of (dev, VuInput, dev.parent); + +switch (vmsg->request) { +case VHOST_USER_INPUT_GET_CONFIG : + vmsg->size = vi->config->len *sizeof (virtio_input_config); + vmsg->data =g_memdup (vi->config->data, vmsg->size); + *do_reply = true; +return 1 ; +default : +return 0 ; + } +} + +static const VuDevIface vuiface = { + .queue_set_started = vi_queue_set_started, + .process_msg = vi_process_msg, +}; + +static void +vi_bits_config (VuInput *vi,int type,int count) +{ +virtio_input_config bits; +int rc, i, size =0 ; + +memset (&bits,0 ,sizeof (bits)); + rc =ioctl (vi->evdevfd,EVIOCGBIT (type, count /8 ), bits.u.bitmap); +if (rc <0 ) { +return ; + } + +for (i =0 ; i < count /8 ; i++) { +if (bits.u.bitmap[i]) { + size = i +1 ; + } + } +if (size ==0 ) { +return ; + } + + bits.select =VIRTIO_INPUT_CFG_EV_BITS ; + bits.subsel = type; + bits.size = size; +g_array_append_val (vi->config, bits); +} + +static int unix_sock_new (char *path) +{ +int sock; +struct sockaddr_un un; +size_t len; + + sock =socket (AF_UNIX ,SOCK_STREAM ,0 ); +if (sock <=0 ) { +perror ("socket" ); +return -1 ; + } + + un.sun_family =AF_UNIX ; +snprintf (un.sun_path,sizeof (un.sun_path),"%s" , path); + len =sizeof (un.sun_family) +strlen (un.sun_path); + +unlink (path); +if (bind (sock, (struct sockaddr *)&un, len) <0 ) { +perror ("bind" ); + goto fail; + } + +if (listen (sock,1 ) <0 ) { +perror ("listen" ); + goto fail; + } + +return sock; + +fail: +close (sock); + +return -1 ; +} + +static char **opt_fname; +static int opt_fdnum =3 ; +static char *opt_socket_path; +static gboolean opt_nograb; +static char *opt_pid_path; + +static GOptionEntry entries[] = { + {"no-grab" ,'n' ,0 ,G_OPTION_ARG_NONE , &opt_nograb, +"Don't grab device" ,NULL }, + {"pid" ,'p' ,0 ,G_OPTION_ARG_FILENAME , &opt_pid_path, +"PID path" ,"PATH" }, + {"fd" ,'f' ,0 ,G_OPTION_ARG_INT , &opt_fdnum, +"Use inherited fd socket" ,"FDNUM" }, + {"socket-path" ,'s' ,0 ,G_OPTION_ARG_FILENAME , &opt_socket_path, +"Use UNIX socket path" ,"PATH" }, + {G_OPTION_REMAINING ,'\0' ,0 ,G_OPTION_ARG_FILENAME_ARRAY , &opt_fname, +"EVDEV filename" ,"..." }, + {NULL , } +}; + +int +main (int argc,char *argv[]) +{ +GMainLoop *loop =NULL ; +VuInput vi = {0 , }; +int rc, ver, fd; +virtio_input_config id; +struct input_id ids; +GError *error =NULL ; +GOptionContext *context; +Error *err =NULL ; + + context =g_option_context_new ("EVDEV - vhost-user-input sample" ); +g_option_context_add_main_entries (context, entries,NULL ); +if (!g_option_context_parse (context, &argc, &argv, &error)) { +g_printerr ("Option parsing failed: %s\n" , error->message); +exit (EXIT_FAILURE ); + } +if (!opt_fname || !opt_fname[0 ] || opt_fname[1 ]) { +g_printerr ("Please specify a single EVDEV filename\n" ); +exit (EXIT_FAILURE ); + } + +if (opt_pid_path && !qemu_write_pidfile (opt_pid_path, &err)) { +g_printerr ("%s\n" ,error_get_pretty (err)); +error_free (err); +exit (EXIT_FAILURE ); + } + + vi.evdevfd =open (opt_fname[0 ],O_RDWR ); +if (vi.evdevfd <0 ) { +g_printerr ("Failed to open evdev: %s\n" ,g_strerror (errno)); +exit (EXIT_FAILURE ); + } + + rc =ioctl (vi.evdevfd,EVIOCGVERSION , &ver); +if (rc <0 ) { +g_printerr ("%s: is not an evdev device\n" , argv[1 ]); +exit (EXIT_FAILURE ); + } + +if (!opt_nograb) { + rc =ioctl (vi.evdevfd,EVIOCGRAB ,1 ); +if (rc <0 ) { +g_printerr ("Failed to grab device\n" ); +exit (EXIT_FAILURE ); + } + } + + vi.config =g_array_new (false, false,sizeof (virtio_input_config)); +memset (&id,0 ,sizeof (id)); +ioctl (vi.evdevfd,EVIOCGNAME (sizeof (id.u.string) -1 ), id.u.string); + id.select =VIRTIO_INPUT_CFG_ID_NAME ; + id.size =strlen (id.u.string); +g_array_append_val (vi.config, id); + +if (ioctl (vi.evdevfd,EVIOCGID , &ids) ==0 ) { +memset (&id,0 ,sizeof (id)); + id.select =VIRTIO_INPUT_CFG_ID_DEVIDS ; + id.size =sizeof (struct virtio_input_devids ); + id.u.ids.bustype =cpu_to_le16 (ids.bustype); + id.u.ids.vendor =cpu_to_le16 (ids.vendor); + id.u.ids.product =cpu_to_le16 (ids.product); + id.u.ids.version =cpu_to_le16 (ids.version); +g_array_append_val (vi.config, id); + } + +vi_bits_config (&vi,EV_KEY ,KEY_CNT ); +vi_bits_config (&vi,EV_REL ,REL_CNT ); +vi_bits_config (&vi,EV_ABS ,ABS_CNT ); +vi_bits_config (&vi,EV_MSC ,MSC_CNT ); +vi_bits_config (&vi,EV_SW ,SW_CNT ); +g_debug ("config length: %u" , vi.config->len); + +if (opt_socket_path) { +int lsock =unix_sock_new (opt_socket_path); + fd =accept (lsock,NULL ,NULL ); +close (lsock); + }else { + fd = opt_fdnum; + } +if (fd ==-1 ) { +g_printerr ("Invalid socket" ); +exit (EXIT_FAILURE ); + } +vug_init (&vi.dev, fd, vi_panic, &vuiface); + + loop =g_main_loop_new (NULL , FALSE); +g_main_loop_run (loop); +g_main_loop_unref (loop); + +vug_deinit (&vi.dev); + +return 0 ; +}
MAINTAINERS +1 -0
@@ -1233,6 +1233,7 @@ M: Gerd Hoffmann <[email protected]> S: Maintained F: hw/input/virtio-input*.c F: include/hw/virtio/virtio-input.h +F: contrib/vhost-user-input/* virtio-serial M: Amit Shah <[email protected]>
Makefile +3 -0
@@ -419,6 +419,7 @@ dummy := $(call unnest-vars,, \ libvhost-user-obj-y \ vhost-user-scsi-obj-y \ vhost-user-blk-obj-y \ + vhost-user-input-obj-y \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \
@@ -717,6 +718,8 @@ vhost-user-scsi$(EXESUF): $(vhost-user-scsi-obj-y) libvhost-user.a $(call LINK, $^) vhost-user-blk$(EXESUF): $(vhost-user-blk-obj-y) libvhost-user.a $(call LINK, $^) +vhost-user-input$(EXESUF): $(vhost-user-input-obj-y) libvhost-user.a libqemuutil.a + $(call LINK, $^) module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak $(call quiet-command,$(PYTHON) $< $@ \
Makefile.objs +1 -0
@@ -193,6 +193,7 @@ vhost-user-scsi.o-cflags := $(LIBISCSI_CFLAGS) vhost-user-scsi.o-libs := $(LIBISCSI_LIBS) vhost-user-scsi-obj-y = contrib/vhost-user-scsi/ vhost-user-blk-obj-y = contrib/vhost-user-blk/ +vhost-user-input-obj-y = contrib/vhost-user-input/ ###################################################################### trace-events-subdirs =
configure +3 -0
@@ -5634,6 +5634,9 @@ if test "$want_tools" = "yes" ; then if [ "$ivshmem" = "yes" ]; then tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools" fi + if [ "$linux" = "yes" ] ; then + tools="vhost-user-input\$(EXESUF) $tools" + fi fi if test "$softmmu" = yes ; then if test "$linux" = yes; then
contrib/vhost-user-input/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +vhost-user-input-obj-y = main.o
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 15/29 Add vhost-user-input-pci
In reply to Marc-André LureauAdd a new virtio-input device, which connects to a vhost-user backend. Usage:
-object vhost-user-backend,id=vuid \
-device vhost-user-input-pci,vhost-user=vuid
--- hw/virtio/virtio-pci.h | 10 +++ include/hw/virtio/virtio-input.h | 14 ++++ hw/input/vhost-user-input.c | 110 +++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.c | 20 ++++++ MAINTAINERS | 1 + hw/input/Makefile.objs | 1 + 6 files changed, 156 insertions(+) create mode 100644 hw/input/vhost-user-input.c
hw/virtio/virtio-pci.h +10 -0
@@ -54,6 +54,7 @@ typedef struct VirtIORngPCI VirtIORngPCI;typedef struct VirtIOInputPCI VirtIOInputPCI ;typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI ;typedef struct VirtIOInputHostPCI VirtIOInputHostPCI ; +typedef struct VHostUserInputPCI VHostUserInputPCI ;typedef struct VirtIOGPUPCI VirtIOGPUPCI ;typedef struct VHostVSockPCI VHostVSockPCI ;typedef struct VirtIOCryptoPCI VirtIOCryptoPCI ;
@@ -376,6 +377,15 @@ struct VirtIOInputHostPCI {#endif +#define TYPE_VHOST_USER_INPUT_PCI "vhost-user-input-pci" +#define VHOST_USER_INPUT_PCI (obj) \ + OBJECT_CHECK(VHostUserInputPCI, (obj), TYPE_VHOST_USER_INPUT_PCI) + +struct VHostUserInputPCI { +VirtIOPCIProxy parent_obj; +VHostUserInput vhi; +}; +/* * virtio-gpu-pci: This extends VirtioPCIProxy. */
include/hw/virtio/virtio-input.h +14 -0
@@ -2,6 +2,7 @@#define QEMU_VIRTIO_INPUT_H #include "ui/input.h" +#include "sysemu/vhost-user-backend.h" /* ----------------------------------------------------------------- */ /* virtio input protocol */
@@ -42,11 +43,18 @@ typedef struct virtio_input_event virtio_input_event;#define VIRTIO_INPUT_HOST_GET_PARENT_CLASS (obj) \ OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST) +#define TYPE_VHOST_USER_INPUT "vhost-user-input" +#define VHOST_USER_INPUT (obj) \ + OBJECT_CHECK(VHostUserInput, (obj), TYPE_VHOST_USER_INPUT) +#define VHOST_USER_INPUT_GET_PARENT_CLASS (obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_VHOST_USER_INPUT) +typedef struct VirtIOInput VirtIOInput ;typedef struct VirtIOInputClass VirtIOInputClass ;typedef struct VirtIOInputConfig VirtIOInputConfig ;typedef struct VirtIOInputHID VirtIOInputHID ;typedef struct VirtIOInputHost VirtIOInputHost ; +typedef struct VHostUserInput VHostUserInput ;struct VirtIOInputConfig {virtio_input_config config;
@@ -98,6 +106,12 @@ struct VirtIOInputHost {int fd; }; +struct VHostUserInput { +VirtIOInput parent_obj; + +VhostUserBackend *vhost; +}; +void virtio_input_send (VirtIOInput *vinput,virtio_input_event *event);void virtio_input_init_config (VirtIOInput *vinput,virtio_input_config *config);
hw/input/vhost-user-input.c new file +110 -0
110 lines not on this page · raw message
hw/virtio/virtio-pci.c +20 -0
@@ -2645,6 +2645,25 @@ static const TypeInfo virtio_host_pci_info = { };#endif +static void vhost_input_pci_initfn (Object *obj) +{ +VHostUserInputPCI *dev =VHOST_USER_INPUT_PCI (obj); + +virtio_instance_init_common (obj, &dev->vhi,sizeof (dev->vhi), +TYPE_VHOST_USER_INPUT ); + +object_property_add_alias (obj,"vhost-user" , +OBJECT (&dev->vhi),"vhost-user" , + &error_abort); +} + +static const TypeInfo vhost_input_pci_info = { + .name =TYPE_VHOST_USER_INPUT_PCI , + .parent =TYPE_VIRTIO_INPUT_PCI , + .instance_size =sizeof (VHostUserInputPCI), + .instance_init = vhost_input_pci_initfn, +}; +/* virtio-pci-bus */ static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
@@ -2701,6 +2720,7 @@ static void virtio_pci_register_types(void)#ifdef CONFIG_LINUX type_register_static (&virtio_host_pci_info);#endif +type_register_static (&vhost_input_pci_info);type_register_static (&virtio_pci_bus_info);type_register_static (&virtio_pci_info);#ifdef CONFIG_VIRTFS
MAINTAINERS +1 -0
@@ -1231,6 +1231,7 @@ L: [email protected] virtio-input M: Gerd Hoffmann <[email protected]> S: Maintained +F: hw/input/vhost-user-input.c F: hw/input/virtio-input*.c F: include/hw/virtio/virtio-input.h F: contrib/vhost-user-input/*
hw/input/Makefile.objs +1 -0
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input.o common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-hid.o ifeq ($(CONFIG_LINUX),y) common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-host.o +common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_VIRTIO_INPUT)) += vhost-user-input.o endif obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 16/29 vhost-user: add vhost_user_gpu_set_socket()
In reply to Marc-André LureauAdd a new vhost-user message to give a unix socket to a vhost-user backend for GPU display updates.
Back when I started that work, I added a new GPU channel because the vhost-user protocol wasn't bidirectional. Since then, there is a vhost-user-slave channel for the slave to send requests to the master. We could extend it with GPU messages. However, the GPU protocol is quite orthogonal to vhost-user, thus I chose to have a new dedicated channel.
See vhost-user-gpu.rst for the protocol details.
--- contrib/libvhost-user/libvhost-user.h | 1 + include/hw/virtio/vhost-backend.h | 1 + hw/virtio/vhost-user.c | 11 ++ MAINTAINERS | 6 + docs/interop/vhost-user-gpu.rst | 236 ++++++++++++++++++++++++++ docs/interop/vhost-user.txt | 9 + 6 files changed, 264 insertions(+) create mode 100644 docs/interop/vhost-user-gpu.rst
contrib/libvhost-user/libvhost-user.h +1 -0
@@ -92,6 +92,7 @@ typedef enum VhostUserRequest {VHOST_USER_POSTCOPY_LISTEN =29 ,VHOST_USER_POSTCOPY_END =30 ,VHOST_USER_INPUT_GET_CONFIG =31 , +VHOST_USER_GPU_SET_SOCKET =32 , VHOST_USER_MAX } VhostUserRequest;
include/hw/virtio/vhost-backend.h +1 -0
@@ -163,5 +163,6 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev,int vhost_user_input_get_config (struct vhost_dev *dev,struct virtio_input_config **config); +int vhost_user_gpu_set_socket (struct vhost_dev *dev,int fd);#endif /* VHOST_BACKEND_H */
hw/virtio/vhost-user.c +11 -0
@@ -90,6 +90,7 @@ typedef enum VhostUserRequest {VHOST_USER_POSTCOPY_LISTEN =29 ,VHOST_USER_POSTCOPY_END =30 ,VHOST_USER_INPUT_GET_CONFIG =31 , +VHOST_USER_GPU_SET_SOCKET =32 , VHOST_USER_MAX } VhostUserRequest;
@@ -397,6 +398,16 @@ err:return -1 ; } +int vhost_user_gpu_set_socket (struct vhost_dev *dev,int fd) +{ +VhostUserMsg msg = { + .hdr.request =VHOST_USER_GPU_SET_SOCKET , + .hdr.flags =VHOST_USER_VERSION , + }; + +return vhost_user_write (dev, &msg, &fd,1 ); +} +static int vhost_user_set_log_base (struct vhost_dev *dev,uint64_t base,struct vhost_log *log) {
MAINTAINERS +6 -0
@@ -1371,6 +1371,12 @@ F: hw/display/virtio-gpu* F: hw/display/virtio-vga.c F: include/hw/virtio/virtio-gpu.h +vhost-user-gpu +M: Marc-André Lureau <[email protected]> +M: Gerd Hoffmann <[email protected]> +S: Maintained +F: docs/interop/vhost-user-gpu.rst + Cirrus VGA M: Gerd Hoffmann <[email protected]> S: Odd Fixes
docs/interop/vhost-user-gpu.rst new file +236 -0
236 lines not on this page · raw message
docs/interop/vhost-user.txt +9 -0
@@ -768,6 +768,15 @@ Master message types Ask vhost user input backend the list of virtio_input_config. + * VHOST_USER_GPU_SET_SOCKET + Id: 32 + Master payload: N/A + Slave payload: N/A + + Sets the GPU protocol socket file descriptor, which is passed as + ancillary data. The GPU protocol is used to inform the master of + rendering state and updates. See vhost-user-gpu.rst for details. + Slave message types -------------------
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 17/29 vhost-user: add vhost_user_gpu_get_num_capsets()
In reply to Marc-André LureauSee vhost-user.txt protocol documentation for details.
--- contrib/libvhost-user/libvhost-user.h | 1 + include/hw/virtio/vhost-backend.h | 1 + hw/virtio/vhost-user.c | 15 +++++++++++++++ docs/interop/vhost-user.txt | 8 ++++++++ 4 files changed, 25 insertions(+)
contrib/libvhost-user/libvhost-user.h +1 -0
@@ -93,6 +93,7 @@ typedef enum VhostUserRequest {VHOST_USER_POSTCOPY_END =30 ,VHOST_USER_INPUT_GET_CONFIG =31 ,VHOST_USER_GPU_SET_SOCKET =32 , +VHOST_USER_GPU_GET_NUM_CAPSETS =33 , VHOST_USER_MAX } VhostUserRequest;
include/hw/virtio/vhost-backend.h +1 -0
@@ -164,5 +164,6 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev,int vhost_user_input_get_config (struct vhost_dev *dev,struct virtio_input_config **config);int vhost_user_gpu_set_socket (struct vhost_dev *dev,int fd); +int vhost_user_gpu_get_num_capsets (struct vhost_dev *dev,uint32_t *num);#endif /* VHOST_BACKEND_H */
hw/virtio/vhost-user.c +15 -0
@@ -91,6 +91,7 @@ typedef enum VhostUserRequest {VHOST_USER_POSTCOPY_END =30 ,VHOST_USER_INPUT_GET_CONFIG =31 ,VHOST_USER_GPU_SET_SOCKET =32 , +VHOST_USER_GPU_GET_NUM_CAPSETS =33 , VHOST_USER_MAX } VhostUserRequest;
@@ -922,6 +923,20 @@ static int vhost_user_get_u64(struct vhost_dev *dev, int request, uint64_t *u64)return 0 ; } +int vhost_user_gpu_get_num_capsets (struct vhost_dev *dev,uint32_t *num) +{ +uint64_t u64; + +if (vhost_user_get_u64 (dev,VHOST_USER_GPU_GET_NUM_CAPSETS , &u64) <0 ) { +return -1 ; + } +if (u64 >INT32_MAX ) { +return -1 ; + } + *num = u64; +return 0 ; +} +static int vhost_user_get_features (struct vhost_dev *dev,uint64_t *features) {return vhost_user_get_u64 (dev,VHOST_USER_GET_FEATURES , features);
docs/interop/vhost-user.txt +8 -0
@@ -777,6 +777,14 @@ Master message types ancillary data. The GPU protocol is used to inform the master of rendering state and updates. See vhost-user-gpu.rst for details. + * VHOST_USER_GPU_GET_NUM_CAPSETS + Id: 33 + Master payload: N/A + Slave payload: u64 + + Get the virtio-gpu 'num_capsets' config value. For non-virgl + rendering, the value can be 0. + Slave message types -------------------
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 18/29 virtio: add virtio-gpu bswap helpers header
In reply to Marc-André LureauThe helper functions are useful to build the vhost-user-gpu backend.
--- include/hw/virtio/virtio-gpu-bswap.h | 61 ++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 43 +------------------- 2 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 include/hw/virtio/virtio-gpu-bswap.h
include/hw/virtio/virtio-gpu-bswap.h new file +61 -0
@@ -0,0 +1,61 @@ +/* +* Virtio GPU Device +* +* Copyright Red Hat, Inc. 2013-2014 +* +* Authors: +* Dave Airlie <[email protected]> +* Gerd Hoffmann <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_VIRTIO_GPU_BSWAP_H +#define HW_VIRTIO_GPU_BSWAP_H + +#include "qemu/bswap.h" + +static inline void +virtio_gpu_ctrl_hdr_bswap (struct virtio_gpu_ctrl_hdr *hdr) +{ +le32_to_cpus (&hdr->type); +le32_to_cpus (&hdr->flags); +le64_to_cpus (&hdr->fence_id); +le32_to_cpus (&hdr->ctx_id); +le32_to_cpus (&hdr->padding); +} + +static inline void +virtio_gpu_bswap_32 (void *ptr,size_t size) +{ +#ifdef HOST_WORDS_BIGENDIAN + +size_t i; +struct virtio_gpu_ctrl_hdr *hdr = (struct virtio_gpu_ctrl_hdr *) ptr; + +virtio_gpu_ctrl_hdr_bswap (hdr); + + i =sizeof (struct virtio_gpu_ctrl_hdr ); +while (i < size) { +le32_to_cpus ((uint32_t *)(ptr + i)); + i = i +sizeof (uint32_t ); + } + +#endif +} + +static inline void +virtio_gpu_t2d_bswap (struct virtio_gpu_transfer_to_host_2d *t2d) +{ +virtio_gpu_ctrl_hdr_bswap (&t2d->hdr); +le32_to_cpus (&t2d->r.x); +le32_to_cpus (&t2d->r.y); +le32_to_cpus (&t2d->r.width); +le32_to_cpus (&t2d->r.height); +le64_to_cpus (&t2d->offset); +le32_to_cpus (&t2d->resource_id); +le32_to_cpus (&t2d->padding); +} + +#endif
hw/display/virtio-gpu.c +1 -42
55 lines not on this page · raw message
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 19/29 util: promote qemu_egl_rendernode_open() to libqemuutil
In reply to Marc-André Lureauvhost-user-gpu will share the same code to open a DRM node.
--- include/qemu/drm.h | 6 +++++ ui/egl-helpers.c | 51 ++--------------------------------- util/drm.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + util/Makefile.objs | 1 + 5 files changed, 76 insertions(+), 49 deletions(-) create mode 100644 include/qemu/drm.h create mode 100644 util/drm.c
include/qemu/drm.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef QEMU_DRM_H_ +#define QEMU_DRM_H_ + +int qemu_drm_rendernode_open (const char *rendernode); + +#endif
ui/egl-helpers.c +2 -49
68 lines not on this page · raw message
util/drm.c new file +66 -0
66 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -1565,6 +1565,7 @@ S: Odd Fixes F: ui/ F: include/ui/ F: qapi/ui.json +F: util/drm.c Cocoa graphics M: Peter Maydell <[email protected]>
util/Makefile.objs +1 -0
@@ -49,3 +49,4 @@ util-obj-y += stats64.o util-obj-y += systemd.o util-obj-y += iova-tree.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o +util-obj-$(CONFIG_LINUX) += drm.o
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 20/29 util: add qemu_write_pidfile()
In reply to Marc-André LureauThere are variants of qemu_create_pidfile() in qemu-pr-helper and qemu-ga. Let's have a common implementation in libqemuutil.
The code is based from pr-helper write_pidfile(), but allows the caller to deal with error reporting and behaviour.
--- include/qemu/osdep.h | 3 ++- os-posix.c | 24 ------------------- os-win32.c | 25 -------------------- qga/main.c | 54 ++++++++----------------------------------- scsi/qemu-pr-helper.c | 40 ++++---------------------------- util/oslib-posix.c | 33 ++++++++++++++++++++++++++ util/oslib-win32.c | 27 ++++++++++++++++++++++ vl.c | 4 ++-- 8 files changed, 79 insertions(+), 131 deletions(-)
include/qemu/osdep.h +2 -1
@@ -448,7 +448,8 @@ bool qemu_has_ofd_lock(void);#define FMT_pid "%d"#endif -int qemu_create_pidfile (const char *filename); +bool qemu_write_pidfile (const char *pidfile,Error **errp); +int qemu_get_thread_id (void );#ifndef CONFIG_IOVEC
os-posix.c +0 -24
@@ -352,30 +352,6 @@ void os_set_line_buffering(void)setvbuf (stdout,NULL , _IOLBF,0 ); } -int qemu_create_pidfile (const char *filename) -{ -char buffer[128 ]; -int len; -int fd; - - fd =qemu_open (filename,O_RDWR |O_CREAT ,0600 ); -if (fd ==-1 ) { -return -1 ; - } -if (lockf (fd,F_TLOCK ,0 ) ==-1 ) { -close (fd); -return -1 ; - } - len =snprintf (buffer,sizeof (buffer), FMT_pid"\n" ,getpid ()); -if (write (fd, buffer, len) != len) { -close (fd); -return -1 ; - } - -/* keep pidfile open & locked forever */ -return 0 ; -} -bool is_daemonized (void ) {return daemonize;
os-win32.c +0 -25
@@ -97,28 +97,3 @@ int os_parse_cmd_args(int index, const char *optarg) {return -1 ; } - -int qemu_create_pidfile (const char *filename) -{ -char buffer[128 ]; -int len; -HANDLE file; -OVERLAPPED overlap; -BOOL ret; -memset (&overlap,0 ,sizeof (overlap)); - - file =CreateFile (filename,GENERIC_WRITE ,FILE_SHARE_READ ,NULL , -OPEN_ALWAYS ,FILE_ATTRIBUTE_NORMAL ,NULL ); - -if (file ==INVALID_HANDLE_VALUE ) { -return -1 ; - } - len =snprintf (buffer,sizeof (buffer),"%d\n" ,getpid ()); - ret =WriteFile (file, (LPCVOID )buffer, (DWORD )len, -NULL , &overlap); -CloseHandle (file); -if (ret ==0 ) { -return -1 ; - } -return 0 ; -}
qga/main.c +10 -44
72 lines not on this page · raw message
scsi/qemu-pr-helper.c +5 -35
@@ -117,39 +117,6 @@ QEMU_COPYRIGHT "\n" , name); } -static void write_pidfile (void ) -{ -int pidfd; -char pidstr[32 ]; - - pidfd =qemu_open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR ); -if (pidfd ==-1 ) { -error_report ("Cannot open pid file, %s" ,strerror (errno)); -exit (EXIT_FAILURE ); - } - -if (lockf (pidfd,F_TLOCK ,0 )) { -error_report ("Cannot lock pid file, %s" ,strerror (errno)); - goto fail; - } -if (ftruncate (pidfd,0 )) { -error_report ("Failed to truncate pid file" ); - goto fail; - } - -snprintf (pidstr,sizeof (pidstr),"%d\n" ,getpid ()); -if (write (pidfd, pidstr,strlen (pidstr)) !=strlen (pidstr)) { -error_report ("Failed to write pid file" ); - goto fail; - } -return ; - -fail: -unlink (pidfile); -close (pidfd); -exit (EXIT_FAILURE ); -} -/* SG_IO support */ typedef struct PRHelperSGIOData {
@@ -1076,8 +1043,11 @@ int main(int argc, char **argv) } } -if (daemonize || pidfile_specified) -write_pidfile (); +if ((daemonize || pidfile_specified) && + !qemu_write_pidfile (pidfile, &local_err)) { +error_report_err (local_err); +exit (EXIT_FAILURE ); + }#ifdef CONFIG_LIBCAP if (drop_privileges () <0 ) {
util/oslib-posix.c +33 -0
@@ -88,6 +88,39 @@ int qemu_daemon(int nochdir, int noclose)return daemon (nochdir, noclose); } +bool qemu_write_pidfile (const char *pidfile,Error **errp) +{ +int pidfd; +char pidstr[32 ]; + + pidfd =qemu_open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR ); +if (pidfd ==-1 ) { +error_setg_errno (errp, errno,"Cannot open pid file" ); +return false; + } + +if (lockf (pidfd,F_TLOCK ,0 )) { +error_setg_errno (errp, errno,"Cannot lock pid file" ); + goto fail; + } +if (ftruncate (pidfd,0 )) { +error_setg_errno (errp, errno,"Failed to truncate pid file" ); + goto fail; + } + +snprintf (pidstr,sizeof (pidstr),"%d\n" ,getpid ()); +if (write (pidfd, pidstr,strlen (pidstr)) !=strlen (pidstr)) { +error_setg (errp,"Failed to write pid file" ); + goto fail; + } +return true; + +fail: +unlink (pidfile); +close (pidfd); +return false; +} +void *qemu_oom_check (void *ptr) {if (ptr ==NULL ) {
util/oslib-win32.c +27 -0
@@ -767,3 +767,30 @@ ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags, }return ret; } + +bool qemu_write_pidfile (const char *filename,Error **errp) +{ +char buffer[128 ]; +int len; +HANDLE file; +OVERLAPPED overlap; +BOOL ret; +memset (&overlap,0 ,sizeof (overlap)); + + file =CreateFile (filename,GENERIC_WRITE ,FILE_SHARE_READ ,NULL , +OPEN_ALWAYS ,FILE_ATTRIBUTE_NORMAL ,NULL ); + +if (file ==INVALID_HANDLE_VALUE ) { +error_setg (errp,"Failed to create PID file" ); +return false; + } + len =snprintf (buffer,sizeof (buffer),"%d\n" ,getpid ()); + ret =WriteFile (file, (LPCVOID )buffer, (DWORD )len, +NULL , &overlap); +CloseHandle (file); +if (ret ==0 ) { +error_setg (errp,"Failed to write PID file" ); +return false; + } +return true; +}
vl.c +2 -2
@@ -3993,8 +3993,8 @@ int main(int argc, char **argv, char **envp)os_daemonize ();rcu_disable_atfork (); -if (pid_file &&qemu_create_pidfile (pid_file) !=0 ) { -error_report ("could not acquire pid file: %s" ,strerror (errno)); +if (pid_file && !qemu_write_pidfile (pid_file, &err)) { +error_reportf_err (err,"cannot create PID file: " );exit (1 ); }
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 20/29] util: add qemu_write_pidfile()
Quoted 47 lines · Marc-André Lureau
There are variants of
qemu_create_pidfile()in qemu-pr-helper and qemu-ga. Let's have a common implementation in libqemuutil.The code is based from pr-helper
write_pidfile(), but allows the caller to deal with error reporting and behaviour.Signed-off-by Marc-André Lureau <[email protected]>--- include/qemu/osdep.h | 3 ++- os-posix.c | 24 ------------------- os-win32.c | 25 -------------------- qga/main.c | 54 ++++++++----------------------------------- scsi/qemu-pr-helper.c | 40 ++++---------------------------- util/oslib-posix.c | 33 ++++++++++++++++++++++++++ util/oslib-win32.c | 27 ++++++++++++++++++++++ vl.c | 4 ++-- 8 files changed, 79 insertions(+), 131 deletions(-)util/oslib-posix.c +19
-0@@ -88,6 +88,39 @@ int qemu_daemon(int nochdir, int noclose)return daemon (nochdir, noclose); } +bool qemu_write_pidfile (const char *pidfile,Error **errp) +{ +int pidfd; +char pidstr[32 ]; + + pidfd =qemu_open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR ); +if (pidfd ==-1 ) { +error_setg_errno (errp, errno,"Cannot open pid file" ); +return false; + } + +if (lockf (pidfd,F_TLOCK ,0 )) { +error_setg_errno (errp, errno,"Cannot lock pid file" ); + goto fail; + } +if (ftruncate (pidfd,0 )) { +error_setg_errno (errp, errno,"Failed to truncate pid file" ); + goto fail; + }
util/oslib-posix.c int qemu_daemon(int nochdir, int noclose) · line 119
Quoted 10 lines
util/oslib-posix.c +10
-0+ +snprintf (pidstr,sizeof (pidstr),"%d\n" ,getpid ()); +if (write (pidfd, pidstr,strlen (pidstr)) !=strlen (pidstr)) { +error_setg (errp,"Failed to write pid file" ); + goto fail; + } +return true; + +fail: +unlink (pidfile);
Danger, Will Robinson !
We can get to this fail: label if we were unable to lockf() the pidfile. ie someone else owns the pidfile, and we've now unlinked the pidfile they own.
util/oslib-posix.c int qemu_daemon(int nochdir, int noclose) · line 126
Quoted 7 lines
util/oslib-posix.c +4
-0+close (pidfd); +return false; +} +void *qemu_oom_check (void *ptr) {if (ptr ==NULL ) {
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v4 20/29] util: add qemu_write_pidfile()
Hi
Quoted 62 lines · Daniel P. Berrangé
Quoted 47 lines · Marc-André Lureau
There are variants of
qemu_create_pidfile()in qemu-pr-helper and qemu-ga. Let's have a common implementation in libqemuutil.The code is based from pr-helper
write_pidfile(), but allows the caller to deal with error reporting and behaviour.Signed-off-by Marc-André Lureau <[email protected]>--- include/qemu/osdep.h | 3 ++- os-posix.c | 24 ------------------- os-win32.c | 25 -------------------- qga/main.c | 54 ++++++++----------------------------------- scsi/qemu-pr-helper.c | 40 ++++---------------------------- util/oslib-posix.c | 33 ++++++++++++++++++++++++++ util/oslib-win32.c | 27 ++++++++++++++++++++++ vl.c | 4 ++-- 8 files changed, 79 insertions(+), 131 deletions(-)util/oslib-posix.c +19
-0@@ -88,6 +88,39 @@ int qemu_daemon(int nochdir, int noclose)return daemon (nochdir, noclose); } +bool qemu_write_pidfile (const char *pidfile,Error **errp) +{ +int pidfd; +char pidstr[32 ]; + + pidfd =qemu_open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR ); +if (pidfd ==-1 ) { +error_setg_errno (errp, errno,"Cannot open pid file" ); +return false; + } + +if (lockf (pidfd,F_TLOCK ,0 )) { +error_setg_errno (errp, errno,"Cannot lock pid file" ); + goto fail; + } +if (ftruncate (pidfd,0 )) { +error_setg_errno (errp, errno,"Failed to truncate pid file" ); + goto fail; + }util/oslib-posix.c int qemu_daemon(int nochdir, int noclose) · line 119
Quoted 10 lines
util/oslib-posix.c +10
-0+ +snprintf (pidstr,sizeof (pidstr),"%d\n" ,getpid ()); +if (write (pidfd, pidstr,strlen (pidstr)) !=strlen (pidstr)) { +error_setg (errp,"Failed to write pid file" ); + goto fail; + } +return true; + +fail: +unlink (pidfile);Danger, Will Robinson !
Quoted 3 lines
We can get to this fail: label if we were unable to
lockf()the pidfile. ie someone else owns the pidfile, and we've now unlinked the pidfile they own.
The code was based on qemu-pr-helper, so the problem exists there.
So we better follow ga_open_pidfile() version here, and close the fd, return an error. ok
Quoted 18 lines
util/oslib-posix.c int qemu_daemon(int nochdir, int noclose) · line 126
Quoted 9 lines
util/oslib-posix.c +4
-0+close (pidfd); +return false; +} +void *qemu_oom_check (void *ptr) {if (ptr ==NULL ) {Regards,
Daniel
--|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH v4 20/29] util: add qemu_write_pidfile()
In reply to Marc-André LureauQuoted 38 lines · Marc-André Lureau
There are variants of
qemu_create_pidfile()in qemu-pr-helper and qemu-ga. Let's have a common implementation in libqemuutil.The code is based from pr-helper
write_pidfile(), but allows the caller to deal with error reporting and behaviour.Signed-off-by Marc-André Lureau <[email protected]>util/oslib-posix.c +22
-0@@ -88,6 +88,39 @@ int qemu_daemon(int nochdir, int noclose)return daemon (nochdir, noclose); } +bool qemu_write_pidfile (const char *pidfile,Error **errp) +{ +int pidfd; +char pidstr[32 ]; + + pidfd =qemu_open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR ); +if (pidfd ==-1 ) { +error_setg_errno (errp, errno,"Cannot open pid file" ); +return false; + } + +if (lockf (pidfd,F_TLOCK ,0 )) { +error_setg_errno (errp, errno,"Cannot lock pid file" ); + goto fail; + } +if (ftruncate (pidfd,0 )) { +error_setg_errno (errp, errno,"Failed to truncate pid file" ); + goto fail; + } + +snprintf (pidstr,sizeof (pidstr),"%d\n" ,getpid ()); +if (write (pidfd, pidstr,strlen (pidstr)) !=strlen (pidstr)) {
util/oslib-posix.c int qemu_daemon(int nochdir, int noclose) · line 122
Quoted 10 lines
util/oslib-posix.c +10
-0+error_setg (errp,"Failed to write pid file" ); + goto fail; + } +return true; + +fail: +unlink (pidfile); +close (pidfd); +return false; +}
Thinking about this again, I think it is not robust enough.
QEMU will leave the pidfile existing on disk when it exits which initially made me think it avoids the deletion race. The app managing QEMU, however, may well delete the pidfile after it has seen QEMU exit, and even if the app locks the pidfile before deleting it, there is still a race.
eg consider the following sequence
QEMU 1 libvirtd QEMU 2
1. lock(pidfile)
2. exit()
3. open(pidfile)
4. lock(pidfile)
5. open(pidfile)
6. unlink(pidfile)
7. close(pidfile)
8. lock(pidfile)
IOW, at step 8 the new QEMU has successfully acquired the lock, but the pidfile no longer exists on disk because it was deleted after the original QEMU exited.
While we could just say no external app should ever delete the pidfile, I don't think that is satisfactory as people don't read docs, and admins don't like stale pidfiles being left around on disk.
To make this robust, I think we might want to copy libvirt's approach to pidfile acquisition which runs in a loop and checks that the file on disk /after/ acquiring the lock matches the file that was locked. Then we could in fact safely let QEMU delete its own pidfiles on clean exit.
while (1) {
struct stat a, b;
if ((fd = open(path, O_WRONLY|O_CREAT, 0644)) < 0) {
return -1;
}
if (fstat(fd, &b) < 0) {
close(fd);
return -1;
}
if (lockf(fd, F_TLOCK, 0) < 0) {
close(fd);
return -1;
}
/* Now make sure the pidfile we locked is the same
* one that now exists on the filesystem
*/
if (stat(path, &a) < 0) {
close(fd);
/* Someone else must be racing with us, so try again */
continue;
}
if (a.st_ino == b.st_ino)
break;
close(fd);
/* Someone else must be racing with us, so try again */
}
if (ftruncate(fd, 0)) {
close(fd);
return -1;
}
snprintf(pidstr, sizeof(pidstr), "%d\n", getpid());
if (write(fd, pidstr, strlen(pidstr)) != strlen(pidstr)) {
close(fd);
return -1;
}
return fd;Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 21/29 util: use fcntl() for qemu_write_pidfile() locking
In reply to Marc-André LureauAccording to Daniel Berrange, fcntl() locks have better portable semantics than lockf().
Use an exclusive lock on the first byte with fcntl().
--- util/oslib-posix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
util/oslib-posix.c +7 -1
@@ -92,6 +92,11 @@ bool qemu_write_pidfile(const char *pidfile, Error **errp) {int pidfd;char pidstr[32 ]; +struct flock lock = { + .l_type =F_WRLCK , + .l_whence =SEEK_SET , + .l_len =1 , + }; pidfd =qemu_open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR );if (pidfd ==-1 ) {
@@ -99,10 +104,11 @@ bool qemu_write_pidfile(const char *pidfile, Error **errp)return false; } -if (lockf (pidfd,F_TLOCK ,0 )) { +if (fcntl (pidfd,F_SETLK , &lock)) {error_setg_errno (errp, errno,"Cannot lock pid file" ); goto fail; } +if (ftruncate (pidfd,0 )) {error_setg_errno (errp, errno,"Failed to truncate pid file" ); goto fail;
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 21/29] util: use fcntl() for qemu_write_pidfile() locking
Quoted 2 lines · Marc-André Lureau
According to Daniel Berrange,
fcntl()locks have better portable semantics thanlockf().
Specifically I was referring to this from 'man lockf':
On Linux, lockf() is just an interface on top of fcntl(2) locking. Many other systems implement lockf() in this way, but note that POSIX.1 leaves the relationship between lockf() and fcntl(2) locks unspecified. A portable application should probably avoid mixing calls to these interfaces.
IOW, if its just a shim around fcntl() on many systems, it is clearer if we just use fcntl() directly, as we then know how fcntl() locks will behave if they're on a network filesystem like NFS.
Quoted 12 lines
Use an exclusive lock on the first byte with
fcntl().Signed-off-by Marc-André Lureau <[email protected]>--- util/oslib-posix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)util/oslib-posix.c +0
-0
util/oslib-posix.c bool qemu_write_pidfile(const char *pidfile, Error **errp) · line 99
Quoted 8 lines
util/oslib-posix.c +5
-0@@ -92,6 +92,11 @@ bool qemu_write_pidfile(const char *pidfile, Error **errp) {int pidfd;char pidstr[32 ]; +struct flock lock = { + .l_type =F_WRLCK , + .l_whence =SEEK_SET , + .l_len =1 , + };
For the same semantics as lockf we should use len == 0 (ie infinity)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v4 21/29] util: use fcntl() for qemu_write_pidfile() locking
Hi
Quoted 24 lines · Daniel P. Berrangé
Quoted 2 lines · Marc-André Lureau
According to Daniel Berrange,
fcntl()locks have better portable semantics thanlockf().Specifically I was referring to this from 'man lockf':
On Linux,
lockf()is just an interface on top of fcntl(2) locking. Many other systems implementlockf()in this way, but note that POSIX.1 leaves the relationship betweenlockf()and fcntl(2) locks unspecified. A portable application should probably avoid mixing calls to these interfaces.IOW, if its just a shim around
fcntl()on many systems, it is clearer if we just usefcntl()directly, as we then know howfcntl()locks will behave if they're on a network filesystem like NFS.Quoted 7 lines
Use an exclusive lock on the first byte with
fcntl().Signed-off-by Marc-André Lureau <[email protected]>--- util/oslib-posix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 16 lines
util/oslib-posix.c bool qemu_write_pidfile(const char *pidfile, Error **errp) · line 99
Quoted 13 lines
util/oslib-posix.c +5
-0@@ -92,6 +92,11 @@ bool qemu_write_pidfile(const char *pidfile, Error **errp) {int pidfd;char pidstr[32 ]; +struct flock lock = { + .l_type =F_WRLCK , + .l_whence =SEEK_SET , + .l_len =1 , + };For the same semantics as lockf we should use len == 0 (ie infinity)
ok
Quoted 8 lines
Regards,
Daniel
--|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH v4 21/29] util: use fcntl() for qemu_write_pidfile() locking
In reply to Daniel P. BerrangéHi
Quoted 24 lines · Daniel P. Berrangé
Quoted 2 lines · Marc-André Lureau
According to Daniel Berrange,
fcntl()locks have better portable semantics thanlockf().Specifically I was referring to this from 'man lockf':
On Linux,
lockf()is just an interface on top of fcntl(2) locking. Many other systems implementlockf()in this way, but note that POSIX.1 leaves the relationship betweenlockf()and fcntl(2) locks unspecified. A portable application should probably avoid mixing calls to these interfaces.IOW, if its just a shim around
fcntl()on many systems, it is clearer if we just usefcntl()directly, as we then know howfcntl()locks will behave if they're on a network filesystem like NFS.Quoted 7 lines
Use an exclusive lock on the first byte with
fcntl().Signed-off-by Marc-André Lureau <[email protected]>--- util/oslib-posix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 15 lines
util/oslib-posix.c bool qemu_write_pidfile(const char *pidfile, Error **errp) · line 99
Quoted 13 lines
util/oslib-posix.c +5
-0@@ -92,6 +92,11 @@ bool qemu_write_pidfile(const char *pidfile, Error **errp) {int pidfd;char pidstr[32 ]; +struct flock lock = { + .l_type =F_WRLCK , + .l_whence =SEEK_SET , + .l_len =1 , + };For the same semantics as lockf we should use len == 0 (ie infinity)
I went to look at how libvirt implements it. Interestingly, it uses start=0, len=1, and you added it in:
Re: [Qemu-devel] [PATCH v4 21/29] util: use fcntl() for qemu_write_pidfile() locking
Quoted 43 lines · Marc-André Lureau
Hi
Quoted 24 lines · Daniel P. Berrangé
Quoted 2 lines · Marc-André Lureau
According to Daniel Berrange,
fcntl()locks have better portable semantics thanlockf().Specifically I was referring to this from 'man lockf':
On Linux,
lockf()is just an interface on top of fcntl(2) locking. Many other systems implementlockf()in this way, but note that POSIX.1 leaves the relationship betweenlockf()and fcntl(2) locks unspecified. A portable application should probably avoid mixing calls to these interfaces.IOW, if its just a shim around
fcntl()on many systems, it is clearer if we just usefcntl()directly, as we then know howfcntl()locks will behave if they're on a network filesystem like NFS.Quoted 7 lines
Use an exclusive lock on the first byte with
fcntl().Signed-off-by Marc-André Lureau <[email protected]>--- util/oslib-posix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)Quoted 15 lines
util/oslib-posix.c bool qemu_write_pidfile(const char *pidfile, Error **errp) · line 99
Quoted 13 lines
util/oslib-posix.c +5
-0@@ -92,6 +92,11 @@ bool qemu_write_pidfile(const char *pidfile, Error **errp) {int pidfd;char pidstr[32 ]; +struct flock lock = { + .l_type =F_WRLCK , + .l_whence =SEEK_SET , + .l_len =1 , + };For the same semantics as lockf we should use len == 0 (ie infinity)
Quoted 2 lines
I went to look at how libvirt implements it. Interestingly, it uses start=0, len=1, and you added it in:
libvirt never used lockf though. Both are valid, I was just saying that to be identical to what lockf did, it would use len == 0.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 22/29 contrib: add vhost-user-gpu
In reply to Marc-André LureauAdd a vhost-user gpu backend example, based on virtio-gpu/3d device. It is to be associated with a vhost-user-backend object, ex:
-object vhost-user-backend,id=vug,cmd="vhost-user-gpu"
TODO:
- add/check multi-head support
- crash & resume handling
- accelerated rendering/display to avoid the many round trips
--- contrib/vhost-user-gpu/drm.h | 63 ++ contrib/vhost-user-gpu/virgl.h | 25 + contrib/vhost-user-gpu/vugpu.h | 168 ++++ contrib/vhost-user-gpu/drm.c | 190 +++++ contrib/vhost-user-gpu/main.c | 1164 ++++++++++++++++++++++++++ contrib/vhost-user-gpu/virgl.c | 579 +++++++++++++ MAINTAINERS | 2 + Makefile | 3 + Makefile.objs | 1 + configure | 32 + contrib/vhost-user-gpu/Makefile.objs | 10 + 11 files changed, 2237 insertions(+) create mode 100644 contrib/vhost-user-gpu/drm.h create mode 100644 contrib/vhost-user-gpu/virgl.h create mode 100644 contrib/vhost-user-gpu/vugpu.h create mode 100644 contrib/vhost-user-gpu/drm.c create mode 100644 contrib/vhost-user-gpu/main.c create mode 100644 contrib/vhost-user-gpu/virgl.c create mode 100644 contrib/vhost-user-gpu/Makefile.objs
contrib/vhost-user-gpu/drm.h new file +63 -0
@@ -0,0 +1,63 @@ +/* +* Virtio vhost-user GPU Device +* +* DRM helpers +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef VHOST_USER_GPU_DRM_H +#define VHOST_USER_GPU_DRM_H + +#include "qemu/osdep.h" + +#ifdef CONFIG_LIBDRM_INTEL +#include <i915_drm.h> +#include <intel_bufmgr.h> +#endif + +struct drm_buffer ; + +struct drm_device { +bool inited; +int fd; +char *name; +#ifdef CONFIG_LIBDRM_INTEL +drm_intel_bufmgr *bufmgr; +#endif + +bool (*alloc_bo)(struct drm_buffer *buf); +void (*free_bo)(struct drm_buffer *buf); +bool (*export_bo_to_prime)(struct drm_buffer *buf,int *fd); +bool (*map_bo)(struct drm_buffer *buf); +void (*unmap_bo)(struct drm_buffer *buf); +void (*device_destroy)(struct drm_device *dev); +}; + +struct drm_buffer { +struct drm_device *dev; + +#ifdef CONFIG_LIBDRM_INTEL +drm_intel_bo *intel_bo; +#endif /* HAVE_LIBDRM_INTEL */ + +uint32_t gem_handle; +int dmabuf_fd; +uint8_t *mmap; + +int width; +int height; +int bpp; +unsigned long stride; +int format; +}; + +bool drm_device_init (struct drm_device *dev,int fd); +void drm_device_destroy (struct drm_device *dev); + +bool drm_buffer_create (struct drm_buffer *buffer,struct drm_device *dev, +int width,int height); +bool drm_buffer_get_dmabuf_fd (struct drm_buffer *buffer,int *fd); +void drm_buffer_destroy (struct drm_buffer *buffer); + +#endif
contrib/vhost-user-gpu/virgl.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Virtio vhost-user GPU Device +* +* Copyright Red Hat, Inc. 2013-2018 +* +* Authors: +* Dave Airlie <[email protected]> +* Gerd Hoffmann <[email protected]> +* Marc-André Lureau <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef VUGPU_VIRGL_H_ +#define VUGPU_VIRGL_H_ + +#include "vugpu.h" + +bool vg_virgl_init (VuGpu *g); +uint32_t vg_virgl_get_num_capsets (void ); +void vg_virgl_process_cmd (VuGpu *vg,struct virtio_gpu_ctrl_command *cmd); +void vg_virgl_update_cursor_data (VuGpu *g,uint32_t resource_id, +gpointer data); + +#endif
contrib/vhost-user-gpu/vugpu.h new file +168 -0
168 lines not on this page · raw message
contrib/vhost-user-gpu/drm.c new file +190 -0
190 lines not on this page · raw message
contrib/vhost-user-gpu/main.c new file +1164 -0
1,164 lines not on this page · raw message
contrib/vhost-user-gpu/virgl.c new file +579 -0
579 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -1376,6 +1376,8 @@ M: Marc-André Lureau <[email protected]> M: Gerd Hoffmann <[email protected]> S: Maintained F: docs/interop/vhost-user-gpu.rst +F: contrib/vhost-user-gpu +F: hw/display/vhost-user-* Cirrus VGA M: Gerd Hoffmann <[email protected]>
Makefile +3 -0
@@ -420,6 +420,7 @@ dummy := $(call unnest-vars,, \ vhost-user-scsi-obj-y \ vhost-user-blk-obj-y \ vhost-user-input-obj-y \ + vhost-user-gpu-obj-y \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \
@@ -720,6 +721,8 @@ vhost-user-blk$(EXESUF): $(vhost-user-blk-obj-y) libvhost-user.a $(call LINK, $^) vhost-user-input$(EXESUF): $(vhost-user-input-obj-y) libvhost-user.a libqemuutil.a $(call LINK, $^) +vhost-user-gpu$(EXESUF): $(vhost-user-gpu-obj-y) $(libvhost-user-obj-y) libqemuutil.a libqemustub.a + $(call LINK, $^) module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak $(call quiet-command,$(PYTHON) $< $@ \
Makefile.objs +1 -0
@@ -194,6 +194,7 @@ vhost-user-scsi.o-libs := $(LIBISCSI_LIBS) vhost-user-scsi-obj-y = contrib/vhost-user-scsi/ vhost-user-blk-obj-y = contrib/vhost-user-blk/ vhost-user-input-obj-y = contrib/vhost-user-input/ +vhost-user-gpu-obj-y = contrib/vhost-user-gpu/ ###################################################################### trace-events-subdirs =
configure +32 -0
@@ -3882,6 +3882,20 @@ libs_softmmu="$libs_softmmu $fdt_libs" ########################################## # opengl probe (for sdl2, gtk, milkymist-tmu2) +libdrm="no" +if $pkg_config libdrm; then + libdrm_cflags="$($pkg_config --cflags libdrm)" + libdrm_libs="$($pkg_config --libs libdrm)" + libdrm="yes" +fi + +libdrm_intel="no" +if $pkg_config libdrm_intel; then + libdrm_intel_cflags="$($pkg_config --cflags libdrm_intel)" + libdrm_intel_libs="$($pkg_config --libs libdrm_intel)" + libdrm_intel="yes" +fi + if test "$opengl" != "no" ; then opengl_pkgs="epoxy gbm" if $pkg_config $opengl_pkgs; then
@@ -5637,6 +5651,9 @@ if test "$want_tools" = "yes" ; then if [ "$linux" = "yes" ] ; then tools="vhost-user-input\$(EXESUF) $tools" fi + if [ "$linux" = "yes" -a "$virglrenderer" = "yes" -a "$libdrm" = "yes" ] ; then + tools="vhost-user-gpu\$(EXESUF) $tools" + fi fi if test "$softmmu" = yes ; then if test "$linux" = yes; then
@@ -6507,6 +6524,18 @@ if test "$opengl" = "yes" ; then fi fi +if test "$libdrm" = "yes" ; then + echo "CONFIG_LIBDRM=y" >> $config_host_mak + echo "LIBDRM_LIBS=$libdrm_libs" >> $config_host_mak + echo "LIBDRM_CFLAGS=$libdrm_cflags" >> $config_host_mak +fi + +if test "$libdrm_intel" = "yes" ; then + echo "CONFIG_LIBDRM_INTEL=y" >> $config_host_mak + echo "LIBDRM_INTEL_LIBS=$libdrm_intel_libs" >> $config_host_mak + echo "LIBDRM_INTEL_CFLAGS=$libdrm_intel_cflags" >> $config_host_mak +fi + if test "$malloc_trim" = "yes" ; then echo "CONFIG_MALLOC_TRIM=y" >> $config_host_mak fi
@@ -7331,6 +7360,9 @@ echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak done # for target in $targets +echo "PIXMAN_CFLAGS=$pixman_cflags" >> $config_host_mak +echo "PIXMAN_LIBS=$pixman_libs" >> $config_host_mak + if test -n "$enabled_cross_compilers"; then echo echo "NOTE: cross-compilers enabled: $enabled_cross_compilers"
contrib/vhost-user-gpu/Makefile.objs new file +10 -0
@@ -0,0 +1,10 @@ +vhost-user-gpu-obj-y = main.o virgl.o drm.o + +main.o-cflags := $(PIXMAN_CFLAGS) +main.o-libs := $(PIXMAN_LIBS) + +virgl.o-cflags := $(VIRGL_CFLAGS) +virgl.o-libs := $(VIRGL_LIBS) + +drm.o-cflags := $(LIBDRM_CFLAGS) $(LIBDRM_INTEL_CFLAGS) +drm.o-libs := $(LIBDRM_LIBS) $(LIBDRM_INTEL_LIBS)
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 23/29 virtio-gpu: remove unused qdev
In reply to Marc-André Lureau--- include/hw/virtio/virtio-gpu.h | 1 - hw/display/virtio-gpu.c | 1 - 2 files changed, 2 deletions(-)
include/hw/virtio/virtio-gpu.h +0 -1
@@ -97,7 +97,6 @@ typedef struct VirtIOGPU {int enable;int config_size; -DeviceState *qdev; QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist; QTAILQ_HEAD(, virtio_gpu_ctrl_command) cmdq;
hw/display/virtio-gpu.c +0 -1
@@ -1219,7 +1219,6 @@ static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)QTAILQ_INIT (&g->fenceq); g->enabled_output_bitmask =1 ; - g->qdev = qdev;for (i =0 ; i < g->conf.max_outputs; i++) { g->scanout[i].con =
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 24/29 virtio-gpu: remove unused config_size
In reply to Marc-André Lureau--- include/hw/virtio/virtio-gpu.h | 2 -- hw/display/virtio-gpu.c | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-)
include/hw/virtio/virtio-gpu.h +0 -2
@@ -96,8 +96,6 @@ typedef struct VirtIOGPU {int enable; -int config_size; - QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist; QTAILQ_HEAD(, virtio_gpu_ctrl_command) cmdq; QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
hw/display/virtio-gpu.c +1 -2
@@ -1189,10 +1189,9 @@ static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp) } } - g->config_size =sizeof (struct virtio_gpu_config ); g->virtio_config.num_scanouts =cpu_to_le32 (g->conf.max_outputs);virtio_init (VIRTIO_DEVICE (g),"virtio-gpu" ,VIRTIO_ID_GPU , - g->config_size); +sizeof (struct virtio_gpu_config )); g->req_state[0 ].width = g->conf.xres; g->req_state[0 ].height = g->conf.yres;
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 25/29 virtio-gpu: block both 2d and 3d rendering
In reply to Marc-André LureauNow that 2d commands are translated to 3d rendering, qemu must stop sending 3d updates (from 2d) to Spice as well.
--- include/hw/virtio/virtio-gpu.h | 1 - hw/display/virtio-gpu-3d.c | 21 --------------------- hw/display/virtio-gpu.c | 25 ++++++++++++++++++++++--- 3 files changed, 22 insertions(+), 25 deletions(-)
include/hw/virtio/virtio-gpu.h +0 -1
@@ -166,7 +166,6 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd);void virtio_gpu_virgl_fence_poll (VirtIOGPU *g);void virtio_gpu_virgl_reset (VirtIOGPU *g); -void virtio_gpu_gl_block (void *opaque,bool block);int virtio_gpu_virgl_init (VirtIOGPU *g);int virtio_gpu_virgl_get_num_capsets (VirtIOGPU *g);#endif
hw/display/virtio-gpu-3d.c +0 -21
@@ -404,11 +404,6 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, {VIRTIO_GPU_FILL_CMD (cmd->cmd_hdr); - cmd->waiting = g->renderer_blocked; -if (cmd->waiting) { -return ; - } -virgl_renderer_force_ctx_0 ();switch (cmd->cmd_hdr.type) {case VIRTIO_GPU_CMD_CTX_CREATE :
@@ -604,22 +599,6 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g) } } -void virtio_gpu_gl_block (void *opaque,bool block) -{ -VirtIOGPU *g = opaque; - -if (block) { - g->renderer_blocked++; - }else { - g->renderer_blocked--; - } -assert (g->renderer_blocked >=0 ); - -if (g->renderer_blocked ==0 ) { -virtio_gpu_process_cmdq (g); - } -} -int virtio_gpu_virgl_init (VirtIOGPU *g) {int ret;
hw/display/virtio-gpu.c +22 -3
@@ -840,12 +840,15 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)while (!QTAILQ_EMPTY (&g->cmdq)) { cmd =QTAILQ_FIRST (&g->cmdq); -/* process command */ -VIRGL (g, virtio_gpu_virgl_process_cmd, virtio_gpu_simple_process_cmd, - g, cmd); + cmd->waiting = g->renderer_blocked;if (cmd->waiting) {break ; } + +/* process command */ +VIRGL (g, virtio_gpu_virgl_process_cmd, virtio_gpu_simple_process_cmd, + g, cmd); +QTAILQ_REMOVE (&g->cmdq, cmd, next);if (virtio_gpu_stats_enabled (g->conf)) { g->stats.requests++;
@@ -981,6 +984,22 @@ static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)return 0 ; } +static void virtio_gpu_gl_block (void *opaque,bool block) +{ +VirtIOGPU *g = opaque; + +if (block) { + g->renderer_blocked++; + }else { + g->renderer_blocked--; + } +assert (g->renderer_blocked >=0 ); + +if (g->renderer_blocked ==0 ) { +virtio_gpu_process_cmdq (g); + } +} +const GraphicHwOps virtio_gpu_ops = { .invalidate = virtio_gpu_invalidate_display, .gfx_update = virtio_gpu_update_display,
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 26/29 virtio-gpu: remove useless 'waiting' field
In reply to Marc-André LureauLet's check renderer_blocked instead directly.
--- include/hw/virtio/virtio-gpu.h | 1 - hw/display/virtio-gpu.c | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-)
include/hw/virtio/virtio-gpu.h +0 -1
@@ -81,7 +81,6 @@ struct virtio_gpu_ctrl_command {VirtQueue *vq;struct virtio_gpu_ctrl_hdr cmd_hdr;uint32_t error; -bool waiting;bool finished;QTAILQ_ENTRY (virtio_gpu_ctrl_command) next; };
hw/display/virtio-gpu.c +1 -3
@@ -840,8 +840,7 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)while (!QTAILQ_EMPTY (&g->cmdq)) { cmd =QTAILQ_FIRST (&g->cmdq); - cmd->waiting = g->renderer_blocked; -if (cmd->waiting) { +if (g->renderer_blocked) {break ; }
@@ -890,7 +889,6 @@ static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) cmd->vq = vq; cmd->error =0 ; cmd->finished = false; - cmd->waiting = false;QTAILQ_INSERT_TAIL (&g->cmdq, cmd, next); cmd =virtqueue_pop (vq,sizeof (struct virtio_gpu_ctrl_command )); }
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 27/29 virtio-gpu: split virtio-gpu, introduce virtio-gpu-base
In reply to Marc-André LureauAdd a base class that is common to virtio-gpu and vhost-user-gpu devices.
The VirtIOGPUBase base class provides common functionalities necessary for both virtio-gpu and vhost-user-gpu:
- common configuration (max-outputs, initial resolution, flags)
- virtio device initialization, including queue setup
- device pre-conditions checks (iommu)
- migration blocker
- virtio device callbacks
- hooking up to qemu display subsystem
- a few common helper functions to reset the device, retrieve display informations
- a class callback to unblock the rendering (for GL updates)
What is left to the virtio-gpu subdevice to take care of, in short, are all the virtio queues handling, command processing and migration.
--- include/hw/virtio/virtio-gpu.h | 72 +++++-- hw/display/virtio-gpu-3d.c | 49 ++--- hw/display/virtio-gpu-base.c | 292 +++++++++++++++++++++++++++++ hw/display/virtio-gpu-pci.c | 2 +- hw/display/virtio-gpu.c | 332 ++++++--------------------------- hw/display/virtio-vga.c | 15 +- hw/display/Makefile.objs | 2 +- 7 files changed, 447 insertions(+), 317 deletions(-) create mode 100644 hw/display/virtio-gpu-base.c
include/hw/virtio/virtio-gpu.h +55 -17
@@ -22,6 +22,14 @@#include "standard-headers/linux/virtio_gpu.h" +#define TYPE_VIRTIO_GPU_BASE "virtio-gpu-base" +#define VIRTIO_GPU_BASE (obj) \ + OBJECT_CHECK(VirtIOGPUBase, (obj), TYPE_VIRTIO_GPU_BASE) +#define VIRTIO_GPU_BASE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(VirtIOGPUBaseClass, obj, TYPE_VIRTIO_GPU_BASE) +#define VIRTIO_GPU_BASE_CLASS (klass) \ + OBJECT_CLASS_CHECK(VirtIOGPUBaseClass, klass, TYPE_VIRTIO_GPU_BASE) +#define TYPE_VIRTIO_GPU "virtio-gpu-device"#define VIRTIO_GPU (obj) \ OBJECT_CHECK(VirtIOGPU, (obj), TYPE_VIRTIO_GPU)
@@ -58,7 +66,7 @@ struct virtio_gpu_requested_state {int x, y; }; -enum virtio_gpu_conf_flags { +enum virtio_gpu_base_conf_flags {VIRTIO_GPU_FLAG_VIRGL_ENABLED =1 ,VIRTIO_GPU_FLAG_STATS_ENABLED , };
@@ -68,8 +76,7 @@ enum virtio_gpu_conf_flags {#define virtio_gpu_stats_enabled (_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_STATS_ENABLED)) -struct virtio_gpu_conf { -uint64_t max_hostmem; +struct virtio_gpu_base_conf {uint32_t max_outputs;uint32_t flags;uint32_t xres;
@@ -85,31 +92,53 @@ struct virtio_gpu_ctrl_command {QTAILQ_ENTRY (virtio_gpu_ctrl_command) next; }; -typedef struct VirtIOGPU { +typedef struct VirtIOGPUBase {VirtIODevice parent_obj; - QEMUBH *ctrl_bh; - QEMUBH *cursor_bh; +Error *migration_blocker; + +struct virtio_gpu_base_conf conf; +struct virtio_gpu_config virtio_config; + +bool use_virgl_renderer; +int renderer_blocked; +int enable; + +struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS ]; + +int enabled_output_bitmask; +struct virtio_gpu_requested_state req_state[VIRTIO_GPU_MAX_SCANOUTS ]; +}VirtIOGPUBase ; + +typedef struct VirtIOGPUBaseClass { +VirtioDeviceClass parent; + +void (*gl_unblock)(VirtIOGPUBase *g); +}VirtIOGPUBaseClass ; + +#define VIRTIO_GPU_BASE_PROPERTIES (_state, _conf) \ + DEFINE_PROP_UINT32("max_outputs", _state, _conf.max_outputs, 1), \ + DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1024), \ + DEFINE_PROP_UINT32("yres", _state, _conf.yres, 768) + +typedef struct VirtIOGPU { + VirtIOGPUBase parent_obj; + + uint64_t conf_max_hostmem; + VirtQueue *ctrl_vq; VirtQueue *cursor_vq; - int enable; + QEMUBH *ctrl_bh; + QEMUBH *cursor_bh; QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist; QTAILQ_HEAD(, virtio_gpu_ctrl_command) cmdq; QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq; - struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS]; - struct virtio_gpu_requested_state req_state[VIRTIO_GPU_MAX_SCANOUTS]; - - struct virtio_gpu_conf conf; uint64_t hostmem; - int enabled_output_bitmask; - struct virtio_gpu_config virtio_config; - bool use_virgl_renderer; bool renderer_inited; - int renderer_blocked; QEMUTimer *fence_poll; QEMUTimer *print_stats;
@@ -120,8 +149,6 @@ typedef struct VirtIOGPU {uint32_t req_3d;uint32_t bytes_3d; } stats; - -Error *migration_blocker; } VirtIOGPU;extern const GraphicHwOps virtio_gpu_ops;
@@ -144,6 +171,16 @@ extern const GraphicHwOps virtio_gpu_ops; } \ }while (0 ) +/* virtio-gpu-base.c */ +bool virtio_gpu_base_device_realize(DeviceState *qdev, + int num_capsets, + VirtIOHandleOutput ctrl_cb, + VirtIOHandleOutput cursor_cb, + Error **errp); +void virtio_gpu_base_reset (VirtIOGPUBase *g); +void virtio_gpu_base_fill_display_info (VirtIOGPUBase *g, +struct virtio_gpu_resp_display_info *dpy_info); +/* virtio-gpu.c */ void virtio_gpu_ctrl_response(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd,
@@ -167,4 +204,5 @@ void virtio_gpu_virgl_fence_poll(VirtIOGPU *g);void virtio_gpu_virgl_reset (VirtIOGPU *g);int virtio_gpu_virgl_init (VirtIOGPU *g);int virtio_gpu_virgl_get_num_capsets (VirtIOGPU *g); +#endif
hw/display/virtio-gpu-3d.c +26 -23
131 lines not on this page · raw message
hw/display/virtio-gpu-base.c new file +292 -0
292 lines not on this page · raw message
hw/display/virtio-gpu-pci.c +1 -1
@@ -27,7 +27,7 @@ static Property virtio_gpu_pci_properties[] = {static void virtio_gpu_pci_realize (VirtIOPCIProxy *vpci_dev,Error **errp) {VirtIOGPUPCI *vgpu =VIRTIO_GPU_PCI (vpci_dev); -VirtIOGPU *g = &vgpu->vdev; +VirtIOGPUBase *g =VIRTIO_GPU_BASE (&vgpu->vdev);DeviceState *vdev =DEVICE (&vgpu->vdev);int i;Error *local_error =NULL ;
hw/display/virtio-gpu.c +62 -270
559 lines not on this page · raw message
hw/display/virtio-vga.c +10 -5
@@ -22,8 +22,9 @@ typedef struct VirtIOVGA {static void virtio_vga_invalidate_display (void *opaque) {VirtIOVGA *vvga = opaque; +VirtIOGPUBase *g =VIRTIO_GPU_BASE (&vvga->vdev); -if (vvga->vdev.enable) { +if (g->enable) { virtio_gpu_ops.invalidate (&vvga->vdev); }else { vvga->vga.hw_ops->invalidate (&vvga->vga);
@@ -33,8 +34,9 @@ static void virtio_vga_invalidate_display(void *opaque)static void virtio_vga_update_display (void *opaque) {VirtIOVGA *vvga = opaque; +VirtIOGPUBase *g =VIRTIO_GPU_BASE (&vvga->vdev); -if (vvga->vdev.enable) { +if (g->enable) { virtio_gpu_ops.gfx_update (&vvga->vdev); }else { vvga->vga.hw_ops->gfx_update (&vvga->vga);
@@ -44,8 +46,9 @@ static void virtio_vga_update_display(void *opaque)static void virtio_vga_text_update (void *opaque,console_ch_t *chardata) {VirtIOVGA *vvga = opaque; +VirtIOGPUBase *g =VIRTIO_GPU_BASE (&vvga->vdev); -if (vvga->vdev.enable) { +if (g->enable) {if (virtio_gpu_ops.text_update) { virtio_gpu_ops.text_update (&vvga->vdev, chardata); }
@@ -98,7 +101,7 @@ static const VMStateDescription vmstate_virtio_vga = {static void virtio_vga_realize (VirtIOPCIProxy *vpci_dev,Error **errp) {VirtIOVGA *vvga =VIRTIO_VGA (vpci_dev); -VirtIOGPU *g = &vvga->vdev; +VirtIOGPUBase *g =VIRTIO_GPU_BASE (&vvga->vdev);VGACommonState *vga = &vvga->vga;Error *err =NULL ;uint32_t offset;
@@ -168,7 +171,9 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static void virtio_vga_reset (DeviceState *dev) {VirtIOVGA *vvga =VIRTIO_VGA (dev); - vvga->vdev.enable =0 ; +VirtIOGPUBase *g =VIRTIO_GPU_BASE (&vvga->vdev); + + g->enable =0 ;vga_dirty_log_start (&vvga->vga); }
hw/display/Makefile.objs +1 -1
@@ -39,7 +39,7 @@ obj-$(CONFIG_VGA) += vga.o common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o -obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu.o virtio-gpu-3d.o +obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-base.o virtio-gpu.o virtio-gpu-3d.o obj-$(call land,$(CONFIG_VIRTIO_GPU),$(CONFIG_VIRTIO_PCI)) += virtio-gpu-pci.o obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o virtio-gpu.o-cflags := $(VIRGL_CFLAGS)
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 28/29 virtio-gpu: split virtio-gpu-pci & virtio-vga
In reply to Marc-André LureauAdd base classes that are common to vhost-user-gpu-pci and vhost-user-vga.
--- hw/display/virtio-vga.h | 22 +++++++ hw/virtio/virtio-pci.h | 16 ++--- hw/display/virtio-gpu-pci.c | 39 +++++++++--- hw/display/virtio-vga.c | 122 +++++++++++++++++++----------------- MAINTAINERS | 2 +- 5 files changed, 126 insertions(+), 75 deletions(-) create mode 100644 hw/display/virtio-vga.h
hw/display/virtio-vga.h new file +22 -0
@@ -0,0 +1,22 @@ +#ifndef VIRTIO_VGA_H_ +#define VIRTIO_VGA_H_ + +#include "hw/virtio/virtio-pci.h" +#include "vga_int.h" + +/* +* virtio-vga-base: This extends VirtioPCIProxy. +*/ +#define TYPE_VIRTIO_VGA_BASE "virtio-vga-base" +#define VIRTIO_VGA_BASE (obj) \ + OBJECT_CHECK(VirtIOVGABase, (obj), TYPE_VIRTIO_VGA_BASE) + +typedef struct VirtIOVGABase { +VirtIOPCIProxy parent_obj; + +VirtIOGPUBase *vgpu; +VGACommonState vga; +MemoryRegion vga_mrs[3 ]; +}VirtIOVGABase ; + +#endif /* VIRTIO_VGA_H_ */
hw/virtio/virtio-pci.h +9 -7
@@ -386,17 +386,19 @@ struct VHostUserInputPCI {VHostUserInput vhi; }; +/* -* virtio-gpu-pci: This extends VirtioPCIProxy. +* virtio-gpu-pci-base: This extends VirtioPCIProxy. */ -#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci" -#define VIRTIO_GPU_PCI (obj) \ - OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI) +#define TYPE_VIRTIO_GPU_PCI_BASE "virtio-gpu-pci-base" +#define VIRTIO_GPU_PCI_BASE (obj) \ + OBJECT_CHECK(VirtIOGPUPCIBase, (obj), TYPE_VIRTIO_GPU_PCI_BASE) -struct VirtIOGPUPCI { +typedef struct VirtIOGPUPCIBase {VirtIOPCIProxy parent_obj; -VirtIOGPU vdev; -}; + +VirtIOGPUBase *vgpu; +}VirtIOGPUPCIBase ;#ifdef CONFIG_VHOST_VSOCK /*
hw/display/virtio-gpu-pci.c +29 -10
@@ -19,16 +19,16 @@#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-gpu.h" -static Property virtio_gpu_pci_properties[] = { +static Property virtio_gpu_pci_base_properties[] = {DEFINE_VIRTIO_GPU_PCI_PROPERTIES (VirtIOPCIProxy),DEFINE_PROP_END_OF_LIST (), }; -static void virtio_gpu_pci_realize (VirtIOPCIProxy *vpci_dev,Error **errp) +static void virtio_gpu_pci_base_realize (VirtIOPCIProxy *vpci_dev,Error **errp) { -VirtIOGPUPCI *vgpu =VIRTIO_GPU_PCI (vpci_dev); -VirtIOGPUBase *g =VIRTIO_GPU_BASE (&vgpu->vdev); -DeviceState *vdev =DEVICE (&vgpu->vdev); +VirtIOGPUPCIBase *vgpu =VIRTIO_GPU_PCI_BASE (vpci_dev); +VirtIOGPUBase *g = vgpu->vgpu; +DeviceState *vdev =DEVICE (g);int i;Error *local_error =NULL ;
@@ -48,37 +48,56 @@ static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) } } -static void virtio_gpu_pci_class_init (ObjectClass *klass,void *data) +static void virtio_gpu_pci_base_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);VirtioPCIClass *k =VIRTIO_PCI_CLASS (klass);PCIDeviceClass *pcidev_k =PCI_DEVICE_CLASS (klass);set_bit (DEVICE_CATEGORY_DISPLAY , dc->categories); - dc->props = virtio_gpu_pci_properties; + dc->props = virtio_gpu_pci_base_properties; dc->hotpluggable = false; - k->realize = virtio_gpu_pci_realize; + k->realize = virtio_gpu_pci_base_realize; pcidev_k->class_id =PCI_CLASS_DISPLAY_OTHER ; } +static const TypeInfo virtio_gpu_pci_base_info = { + .name =TYPE_VIRTIO_GPU_PCI_BASE , + .parent =TYPE_VIRTIO_PCI , + .instance_size =sizeof (VirtIOGPUPCIBase), + .class_init = virtio_gpu_pci_base_class_init, + .abstract = true +}; + +#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci" +#define VIRTIO_GPU_PCI (obj) \ + OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI) + +struct VirtIOGPUPCI { +VirtIOGPUPCIBase parent_obj; +VirtIOGPU vdev; +}; +static void virtio_gpu_initfn (Object *obj) {VirtIOGPUPCI *dev =VIRTIO_GPU_PCI (obj);virtio_instance_init_common (obj, &dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_GPU ); +VIRTIO_GPU_PCI_BASE (obj)->vgpu =VIRTIO_GPU_BASE (&dev->vdev); }static const TypeInfo virtio_gpu_pci_info = { .name =TYPE_VIRTIO_GPU_PCI , - .parent =TYPE_VIRTIO_PCI , + .parent =TYPE_VIRTIO_GPU_PCI_BASE , .instance_size =sizeof (VirtIOGPUPCI), .instance_init = virtio_gpu_initfn, - .class_init = virtio_gpu_pci_class_init, };static void virtio_gpu_pci_register_types (void ) { +type_register_static (&virtio_gpu_pci_base_info);type_register_static (&virtio_gpu_pci_info); } +type_init (virtio_gpu_pci_register_types)
hw/display/virtio-vga.c +65 -57
233 lines not on this page · raw message
MAINTAINERS +1 -1
@@ -1368,7 +1368,7 @@ virtio-gpu M: Gerd Hoffmann <[email protected]> S: Maintained F: hw/display/virtio-gpu* -F: hw/display/virtio-vga.c +F: hw/display/virtio-vga.* F: include/hw/virtio/virtio-gpu.h vhost-user-gpu
Signature · 1 line
2.18.0.129.ge3331758f1
PATCH v4 29/29 hw/display: add vhost-user-vga & gpu-pci
In reply to Marc-André LureauAdd new virtio-gpu devices with a "vhost-user" property. Tthe associated vhost-user backend is used to handle the virtio rings and provide rendering results thanks to the vhost-user-gpu protocol.
Example usage:
-object vhost-user-backend,id=vug,cmd="./vhost-user-gpu" -device vhost-user-vga,vhost-user=vug
--- hw/virtio/virtio-pci.h | 1 + include/hw/virtio/virtio-gpu.h | 13 + hw/display/vhost-user-gpu-pci.c | 51 ++++ hw/display/vhost-user-gpu.c | 524 ++++++++++++++++++++++++++++++++ hw/display/vhost-user-vga.c | 52 ++++ vl.c | 1 + hw/display/Makefile.objs | 3 + 7 files changed, 645 insertions(+) create mode 100644 hw/display/vhost-user-gpu-pci.c create mode 100644 hw/display/vhost-user-gpu.c create mode 100644 hw/display/vhost-user-vga.c
hw/virtio/virtio-pci.h +1 -0
@@ -56,6 +56,7 @@ typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;typedef struct VirtIOInputHostPCI VirtIOInputHostPCI ;typedef struct VHostUserInputPCI VHostUserInputPCI ;typedef struct VirtIOGPUPCI VirtIOGPUPCI ; +typedef struct VhostUserGPUPCI VhostUserGPUPCI ;typedef struct VHostVSockPCI VHostVSockPCI ;typedef struct VirtIOCryptoPCI VirtIOCryptoPCI ;
include/hw/virtio/virtio-gpu.h +13 -0
@@ -19,6 +19,7 @@#include "ui/console.h" #include "hw/virtio/virtio.h" #include "qemu/log.h" +#include "sysemu/vhost-user-backend.h" #include "standard-headers/linux/virtio_gpu.h"
@@ -34,6 +35,8 @@#define VIRTIO_GPU (obj) \ OBJECT_CHECK(VirtIOGPU, (obj), TYPE_VIRTIO_GPU) +#define TYPE_VHOST_USER_GPU "vhost-user-gpu" +#define VIRTIO_ID_GPU 16struct virtio_gpu_simple_resource {
@@ -151,6 +154,16 @@ typedef struct VirtIOGPU { } stats; } VirtIOGPU; +typedef struct VhostUserGPU { +VirtIOGPUBase parent_obj; + +VhostUserBackend *vhost; +int vhost_gpu_fd;/* closed by the chardev */ +CharBackend vhost_chr; +QemuDmaBuf dmabuf[VIRTIO_GPU_MAX_SCANOUTS ]; +bool backend_blocked; +}VhostUserGPU ; +extern const GraphicHwOps virtio_gpu_ops;/* to share between PCI and VGA */
hw/display/vhost-user-gpu-pci.c new file +51 -0
51 lines not on this page · raw message
hw/display/vhost-user-gpu.c new file +524 -0
524 lines not on this page · raw message
hw/display/vhost-user-vga.c new file +52 -0
52 lines not on this page · raw message
vl.c +1 -0
@@ -237,6 +237,7 @@ static struct { { .driver = "vmware-svga", .flag = &default_vga }, { .driver = "qxl-vga", .flag = &default_vga }, { .driver = "virtio-vga", .flag = &default_vga }, + { .driver = "vhost-user-vga", .flag = &default_vga }, }; static QemuOptsList qemu_rtc_opts = {
hw/display/Makefile.objs +3 -0
@@ -40,8 +40,11 @@ obj-$(CONFIG_VGA) += vga.o common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-base.o virtio-gpu.o virtio-gpu-3d.o +obj-$(call land,$(CONFIG_VIRTIO_GPU),$(CONFIG_VHOST_USER)) += vhost-user-gpu.o obj-$(call land,$(CONFIG_VIRTIO_GPU),$(CONFIG_VIRTIO_PCI)) += virtio-gpu-pci.o +obj-$(call land,$(CONFIG_VHOST_USER),$(call land,$(CONFIG_VIRTIO_GPU),$(CONFIG_VIRTIO_PCI))) += vhost-user-gpu-pci.o obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o +obj-$(call land,$(CONFIG_VIRTIO_VGA),$(CONFIG_VHOST_USER)) += vhost-user-vga.o virtio-gpu.o-cflags := $(VIRGL_CFLAGS) virtio-gpu.o-libs += $(VIRGL_LIBS) virtio-gpu-3d.o-cflags := $(VIRGL_CFLAGS)
Signature · 1 line
2.18.0.129.ge3331758f1
Re: [Qemu-devel] [PATCH v4 29/29] hw/display: add vhost-user-vga & gpu-pci
Review
Quoted 7 lines · Marc-André Lureau
Add new virtio-gpu devices with a "vhost-user" property. Tthe associated vhost-user backend is used to handle the virtio rings and provide rendering results thanks to the vhost-user-gpu protocol.
Example usage:
(quoted diff) +0
-2-object vhost-user-backend,id=vug,cmd="./vhost-user-gpu" -device vhost-user-vga,vhost-user=vug
This is a pretty different approach from what QEMU has done for modelling in the past. We've always had separation between the frontend device and the backend provider, with a single frontend device impl being plugged into an arbitrary backend type. This though is introducing a frontend device that actually has the name of a backend which is rather bizarre and quite misleading as it on first sight looks like a new device type.
If we must introduce new device types, at very least the confusion could be reduced by calling it "virtio-vga-vhost" so it is clear its the same device type as virtio-vga, likewise 'virtio-gpu-pci-vhost'
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 33 lines · Marc-André Lureau
Hi,
vhost-user allows to drive a virtio device in a seperate process. After vhost-user-net, we have seen vhost-user-{scsi,blk,crypto} added more recently.
This series, initially proposed 2 years ago
(https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01905.html)
contributes with vhost-user-input and vhost-user-gpu.Additionally, to factor out common code and ease the usage, a vhost-user-backend is introduced as an intermediary object between the backend and the qemu device.
You may start a vhost-user-gpu with virgl rendering in a separate process like this:
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugYou may also specify the backend command and the arguments as part of vhost-user-backend qemu arguments. For example, to start a vhost-user-input backend on input device
/dev/input/event19:(quoted diff) +0
-2-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event19" -device virtio-input-host-pci,vhost-user=vuidThe vhost-user-gpu backend requires virgl from git.
Quoted 7 lines
The libvirt support is on-going work:
https://github.com/elmarco/libvirt/commits/vhost-user-gpuThe GPU benchmarks are encouraging, giving up to x5 performance on Unigine Heaven 4.0.
Feedback welcome,
ping
fwiw, there is a related series for libvirt support: "[libvirt] [RFC PATCH 00/17] Add vhost-user-gpu support"
thanks
Quoted 148 lines
v4:
- moveqemu_write_pidfile()in util, improve it a bit
- add --pid and --fd arguments to vhost-user to help with libvirt support
- various bug fixes for synchronization, and tearing downv3: deal with most comments from rfcv2 and various improvements
- "vhost-user-backend: allow to specify binary to execute" as seperate patch, not for inclusion since Daniel as concerned about parsing shell strings with glib
- use dmabuf to share 2d rendering result (with intel gem only atm)
- document the vhost-user-gpu protocol
- make vhost-user-gpu-pci and vhost-user-vga seperate devices (instead of adding vhost-user support to existing devices)
- allow to specify virgl rendering, and rendernode
- let's promote out of RFC status :)RFCv2: (addressing some of Gerd comments digged in the archives)
- rebased, clean ups, various small fixes, update commit messages
- teach the vhost-user-backend to take a chardev
- add vhost-user-input-pci, instead of adding vhost code to virtio-input-host-pciMarc-André Lureau (29):
chardev: avoid crash if no associated address
chardev: removeqemu_chr_fe_read_all()counter
chardev: unref if underlying chardev has no parent
dmabuf: addy0_top, pass it to spice
vhost-user: simplify vhost_user_init/vhost_user_cleanup
libvhost-user: exit by default onVHOST_USER_NONE
vhost-user: wrap some read/write with retry handling Add vhost-user-backend
qio: addqio_channel_command_new_spawn_with_pre_exec()
HACK: vhost-user-backend: allow to specify binary to execute
vhost-user: splitvhost_user_read()
vhost-user: addvhost_user_input_get_config()
libvhost-user: exportvug_source_new()
contrib: add vhost-user-input
Add vhost-user-input-pci
vhost-user: addvhost_user_gpu_set_socket()
vhost-user: addvhost_user_gpu_get_num_capsets()
virtio: add virtio-gpu bswap helpers header
util: promoteqemu_egl_rendernode_open()to libqemuutil
util: addqemu_write_pidfile()
util: usefcntl()forqemu_write_pidfile()locking
contrib: add vhost-user-gpu
virtio-gpu: remove unused qdev
virtio-gpu: remove unusedconfig_size
virtio-gpu: block both 2d and 3d rendering
virtio-gpu: remove useless 'waiting' field
virtio-gpu: split virtio-gpu, introduce virtio-gpu-base
virtio-gpu: split virtio-gpu-pci & virtio-vga hw/display: add vhost-user-vga & gpu-pcicontrib/libvhost-user/libvhost-user-glib.h | 3 + contrib/libvhost-user/libvhost-user.h | 3 + contrib/vhost-user-gpu/drm.h | 63 ++ contrib/vhost-user-gpu/virgl.h | 25 + contrib/vhost-user-gpu/vugpu.h | 168 +++ hw/display/virtio-vga.h | 22 + hw/virtio/virtio-pci.h | 27 +- include/hw/virtio/vhost-backend.h | 6 + include/hw/virtio/vhost-user-blk.h | 2 +- include/hw/virtio/vhost-user-scsi.h | 2 +- include/hw/virtio/vhost-user.h | 2 +- include/hw/virtio/virtio-gpu-bswap.h | 61 + include/hw/virtio/virtio-gpu.h | 90 +- include/hw/virtio/virtio-input.h | 14 + include/io/channel-command.h | 18 + include/qemu/drm.h | 6 + include/qemu/osdep.h | 3 +- include/sysemu/vhost-user-backend.h | 60 + include/ui/console.h | 1 + backends/cryptodev-vhost-user.c | 18 +- backends/vhost-user.c | 320 ++++++ chardev/char-fe.c | 13 +- chardev/char-socket.c | 8 +- contrib/libvhost-user/libvhost-user-glib.c | 15 +- contrib/libvhost-user/libvhost-user.c | 3 +- contrib/vhost-user-gpu/drm.c | 190 ++++ contrib/vhost-user-gpu/main.c | 1164 ++++++++++++++++++++ contrib/vhost-user-gpu/virgl.c | 579 ++++++++++ contrib/vhost-user-input/main.c | 379 +++++++ hw/block/vhost-user-blk.c | 22 +- hw/display/vhost-user-gpu-pci.c | 51 + hw/display/vhost-user-gpu.c | 524 +++++++++ hw/display/vhost-user-vga.c | 52 + hw/display/virtio-gpu-3d.c | 70 +- hw/display/virtio-gpu-base.c | 292 +++++ hw/display/virtio-gpu-pci.c | 39 +- hw/display/virtio-gpu.c | 368 ++----- hw/display/virtio-vga.c | 127 ++- hw/input/vhost-user-input.c | 110 ++ hw/scsi/vhost-user-scsi.c | 20 +- hw/virtio/vhost-stub.c | 4 +- hw/virtio/vhost-user.c | 143 ++- hw/virtio/virtio-pci.c | 20 + io/channel-command.c | 33 +- net/vhost-user.c | 13 +- os-posix.c | 24 - os-win32.c | 25 - qga/main.c | 54 +- scsi/qemu-pr-helper.c | 40 +- ui/egl-helpers.c | 51 +- ui/spice-display.c | 3 +- util/drm.c | 66 ++ util/oslib-posix.c | 39 + util/oslib-win32.c | 27 + vl.c | 8 +- MAINTAINERS | 15 +- Makefile | 6 + Makefile.objs | 2 + backends/Makefile.objs | 3 +- configure | 35 + contrib/vhost-user-gpu/Makefile.objs | 10 + contrib/vhost-user-input/Makefile.objs | 1 + docs/interop/vhost-user-gpu.rst | 236 ++++ docs/interop/vhost-user.txt | 24 + hw/display/Makefile.objs | 5 +- hw/input/Makefile.objs | 1 + qemu-options.hx | 24 + util/Makefile.objs | 1 + 68 files changed, 5130 insertions(+), 723 deletions(-) create mode 100644 contrib/vhost-user-gpu/drm.h create mode 100644 contrib/vhost-user-gpu/virgl.h create mode 100644 contrib/vhost-user-gpu/vugpu.h create mode 100644 hw/display/virtio-vga.h create mode 100644 include/hw/virtio/virtio-gpu-bswap.h create mode 100644 include/qemu/drm.h create mode 100644 include/sysemu/vhost-user-backend.h create mode 100644 backends/vhost-user.c create mode 100644 contrib/vhost-user-gpu/drm.c create mode 100644 contrib/vhost-user-gpu/main.c create mode 100644 contrib/vhost-user-gpu/virgl.c create mode 100644 contrib/vhost-user-input/main.c create mode 100644 hw/display/vhost-user-gpu-pci.c create mode 100644 hw/display/vhost-user-gpu.c create mode 100644 hw/display/vhost-user-vga.c create mode 100644 hw/display/virtio-gpu-base.c create mode 100644 hw/input/vhost-user-input.c create mode 100644 util/drm.c create mode 100644 contrib/vhost-user-gpu/Makefile.objs create mode 100644 contrib/vhost-user-input/Makefile.objs create mode 100644 docs/interop/vhost-user-gpu.rst--
2.18.0.129.ge3331758f1
Signature · 1 line
Marc-André Lureau
Hi,
Quoted 3 lines
Quoted 1 line
Feedback welcome,
ping
Cherry-picked two patches for the ui pull request.
What is the plan for the command line handling, specifically the patch tagged with HACK?
cheers,
Gerd
Hi
Quoted 8 lines · Gerd Hoffmann
Hi,
Quoted 3 lines
Quoted 1 line
Feedback welcome,
ping
Cherry-picked two patches for the ui pull request.
thanks
Quoted 3 lines
What is the plan for the command line handling, specifically the patch tagged with HACK?
The RFC libvirt series doesn't use it.
However, it's very convenient for qemu command line users. Daniel doesn't want g_shell_parse_argv(), but he would like the -object json:
command line form instead. I don't know what is the status about supporting that syntax.
You may skip patch 9 & 10 for review & merge. But for easy testing, I recommend to use them atm :)
thanks
--
Marc-André Lureau
Quoted 18 lines · Marc-André Lureau
Hi
Quoted 8 lines · Gerd Hoffmann
Hi,
Quoted 3 lines
Quoted 1 line
Feedback welcome,
ping
Cherry-picked two patches for the ui pull request.
thanks
Quoted 3 lines
What is the plan for the command line handling, specifically the patch tagged with HACK?
Quoted 6 lines
The RFC libvirt series doesn't use it.
However, it's very convenient for qemu command line users. Daniel doesn't want
g_shell_parse_argv(), but he would like the -object json:
command line form instead. I don't know what is the status about supporting that syntax.
IIRC the last suggestion I saw was to not allow custom ARGV at all ? ie define a standard contract that all scripts must follow, as we have done with the ifup scripts.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Hi
Quoted 31 lines · Marc-André Lureau
Hi,
vhost-user allows to drive a virtio device in a seperate process. After vhost-user-net, we have seen vhost-user-{scsi,blk,crypto} added more recently.
This series, initially proposed 2 years ago
(https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01905.html)
contributes with vhost-user-input and vhost-user-gpu.Additionally, to factor out common code and ease the usage, a vhost-user-backend is introduced as an intermediary object between the backend and the qemu device.
You may start a vhost-user-gpu with virgl rendering in a separate process like this:
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugYou may also specify the backend command and the arguments as part of vhost-user-backend qemu arguments. For example, to start a vhost-user-input backend on input device
/dev/input/event19:(quoted diff) +0
-2-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event19" -device virtio-input-host-pci,vhost-user=vuid
Quoted 8 lines
The vhost-user-gpu backend requires virgl from git.
The libvirt support is on-going work:
https://github.com/elmarco/libvirt/commits/vhost-user-gpuThe GPU benchmarks are encouraging, giving up to x5 performance on Unigine Heaven 4.0.
I rebased the series: (on top of virtio-vga: fix reset)
https://github.com/elmarco/qemu/ vhost-user-gpu
Quoted 149 lines
Feedback welcome,
v4:
- moveqemu_write_pidfile()in util, improve it a bit
- add --pid and --fd arguments to vhost-user to help with libvirt support
- various bug fixes for synchronization, and tearing downv3: deal with most comments from rfcv2 and various improvements
- "vhost-user-backend: allow to specify binary to execute" as seperate patch, not for inclusion since Daniel as concerned about parsing shell strings with glib
- use dmabuf to share 2d rendering result (with intel gem only atm)
- document the vhost-user-gpu protocol
- make vhost-user-gpu-pci and vhost-user-vga seperate devices (instead of adding vhost-user support to existing devices)
- allow to specify virgl rendering, and rendernode
- let's promote out of RFC status :)RFCv2: (addressing some of Gerd comments digged in the archives)
- rebased, clean ups, various small fixes, update commit messages
- teach the vhost-user-backend to take a chardev
- add vhost-user-input-pci, instead of adding vhost code to virtio-input-host-pciMarc-André Lureau (29):
chardev: avoid crash if no associated address
chardev: removeqemu_chr_fe_read_all()counter
chardev: unref if underlying chardev has no parent
dmabuf: addy0_top, pass it to spice
vhost-user: simplify vhost_user_init/vhost_user_cleanup
libvhost-user: exit by default onVHOST_USER_NONE
vhost-user: wrap some read/write with retry handling Add vhost-user-backend
qio: addqio_channel_command_new_spawn_with_pre_exec()
HACK: vhost-user-backend: allow to specify binary to execute
vhost-user: splitvhost_user_read()
vhost-user: addvhost_user_input_get_config()
libvhost-user: exportvug_source_new()
contrib: add vhost-user-input
Add vhost-user-input-pci
vhost-user: addvhost_user_gpu_set_socket()
vhost-user: addvhost_user_gpu_get_num_capsets()
virtio: add virtio-gpu bswap helpers header
util: promoteqemu_egl_rendernode_open()to libqemuutil
util: addqemu_write_pidfile()
util: usefcntl()forqemu_write_pidfile()locking
contrib: add vhost-user-gpu
virtio-gpu: remove unused qdev
virtio-gpu: remove unusedconfig_size
virtio-gpu: block both 2d and 3d rendering
virtio-gpu: remove useless 'waiting' field
virtio-gpu: split virtio-gpu, introduce virtio-gpu-base
virtio-gpu: split virtio-gpu-pci & virtio-vga hw/display: add vhost-user-vga & gpu-pcicontrib/libvhost-user/libvhost-user-glib.h | 3 + contrib/libvhost-user/libvhost-user.h | 3 + contrib/vhost-user-gpu/drm.h | 63 ++ contrib/vhost-user-gpu/virgl.h | 25 + contrib/vhost-user-gpu/vugpu.h | 168 +++ hw/display/virtio-vga.h | 22 + hw/virtio/virtio-pci.h | 27 +- include/hw/virtio/vhost-backend.h | 6 + include/hw/virtio/vhost-user-blk.h | 2 +- include/hw/virtio/vhost-user-scsi.h | 2 +- include/hw/virtio/vhost-user.h | 2 +- include/hw/virtio/virtio-gpu-bswap.h | 61 + include/hw/virtio/virtio-gpu.h | 90 +- include/hw/virtio/virtio-input.h | 14 + include/io/channel-command.h | 18 + include/qemu/drm.h | 6 + include/qemu/osdep.h | 3 +- include/sysemu/vhost-user-backend.h | 60 + include/ui/console.h | 1 + backends/cryptodev-vhost-user.c | 18 +- backends/vhost-user.c | 320 ++++++ chardev/char-fe.c | 13 +- chardev/char-socket.c | 8 +- contrib/libvhost-user/libvhost-user-glib.c | 15 +- contrib/libvhost-user/libvhost-user.c | 3 +- contrib/vhost-user-gpu/drm.c | 190 ++++ contrib/vhost-user-gpu/main.c | 1164 ++++++++++++++++++++ contrib/vhost-user-gpu/virgl.c | 579 ++++++++++ contrib/vhost-user-input/main.c | 379 +++++++ hw/block/vhost-user-blk.c | 22 +- hw/display/vhost-user-gpu-pci.c | 51 + hw/display/vhost-user-gpu.c | 524 +++++++++ hw/display/vhost-user-vga.c | 52 + hw/display/virtio-gpu-3d.c | 70 +- hw/display/virtio-gpu-base.c | 292 +++++ hw/display/virtio-gpu-pci.c | 39 +- hw/display/virtio-gpu.c | 368 ++----- hw/display/virtio-vga.c | 127 ++- hw/input/vhost-user-input.c | 110 ++ hw/scsi/vhost-user-scsi.c | 20 +- hw/virtio/vhost-stub.c | 4 +- hw/virtio/vhost-user.c | 143 ++- hw/virtio/virtio-pci.c | 20 + io/channel-command.c | 33 +- net/vhost-user.c | 13 +- os-posix.c | 24 - os-win32.c | 25 - qga/main.c | 54 +- scsi/qemu-pr-helper.c | 40 +- ui/egl-helpers.c | 51 +- ui/spice-display.c | 3 +- util/drm.c | 66 ++ util/oslib-posix.c | 39 + util/oslib-win32.c | 27 + vl.c | 8 +- MAINTAINERS | 15 +- Makefile | 6 + Makefile.objs | 2 + backends/Makefile.objs | 3 +- configure | 35 + contrib/vhost-user-gpu/Makefile.objs | 10 + contrib/vhost-user-input/Makefile.objs | 1 + docs/interop/vhost-user-gpu.rst | 236 ++++ docs/interop/vhost-user.txt | 24 + hw/display/Makefile.objs | 5 +- hw/input/Makefile.objs | 1 + qemu-options.hx | 24 + util/Makefile.objs | 1 + 68 files changed, 5130 insertions(+), 723 deletions(-) create mode 100644 contrib/vhost-user-gpu/drm.h create mode 100644 contrib/vhost-user-gpu/virgl.h create mode 100644 contrib/vhost-user-gpu/vugpu.h create mode 100644 hw/display/virtio-vga.h create mode 100644 include/hw/virtio/virtio-gpu-bswap.h create mode 100644 include/qemu/drm.h create mode 100644 include/sysemu/vhost-user-backend.h create mode 100644 backends/vhost-user.c create mode 100644 contrib/vhost-user-gpu/drm.c create mode 100644 contrib/vhost-user-gpu/main.c create mode 100644 contrib/vhost-user-gpu/virgl.c create mode 100644 contrib/vhost-user-input/main.c create mode 100644 hw/display/vhost-user-gpu-pci.c create mode 100644 hw/display/vhost-user-gpu.c create mode 100644 hw/display/vhost-user-vga.c create mode 100644 hw/display/virtio-gpu-base.c create mode 100644 hw/input/vhost-user-input.c create mode 100644 util/drm.c create mode 100644 contrib/vhost-user-gpu/Makefile.objs create mode 100644 contrib/vhost-user-input/Makefile.objs create mode 100644 docs/interop/vhost-user-gpu.rst--
2.18.0.129.ge3331758f1
Signature · 1 line
Marc-André Lureau
Quoted 30 lines · Marc-André Lureau
Hi,
vhost-user allows to drive a virtio device in a seperate process. After vhost-user-net, we have seen vhost-user-{scsi,blk,crypto} added more recently.
This series, initially proposed 2 years ago
(https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01905.html)
contributes with vhost-user-input and vhost-user-gpu.Additionally, to factor out common code and ease the usage, a vhost-user-backend is introduced as an intermediary object between the backend and the qemu device.
You may start a vhost-user-gpu with virgl rendering in a separate process like this:
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugYou may also specify the backend command and the arguments as part of vhost-user-backend qemu arguments. For example, to start a vhost-user-input backend on input device
/dev/input/event19:(quoted diff) +0
-2-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event19" -device virtio-input-host-pci,vhost-user=vuid
Quoted 7 lines
The vhost-user-gpu backend requires virgl from git.
The libvirt support is on-going work:
https://github.com/elmarco/libvirt/commits/vhost-user-gpuThe GPU benchmarks are encouraging, giving up to x5 performance on Unigine Heaven 4.0.
What is the main driving motivation behind this featureset ? Is it aimed at providing performance, or security, or allowing arbitrary out of tree backends, or all three ?
Although we've got a number of vhost-user backends I'm pretty concerned about the direction this is taking QEMU overall.
Managing QEMU is non-trivial for a number of reasons. We've done a lot of work to provide standardized modelling of CLI args, guest ABI stability via association with machine types, migration data stream stability, QEMU feature capabilities detection and so on.
The move to outsource backends to external binaries is discarding some or all of these items, rewinding alot of progress we've made in the managability of QEMU. Each external binary has to now reinvent the things that are already solved in QEMU, and you can be sure each impl will reinvent the concepts differently.
I can't help feeling that we are shooting ourselves in the foot here long term.
We've always rejected the idea of having loadable modules in QEMU, but as a result we've end up with outsourcing the backend entirely via the vhost-user framework, so the end result is even more opaque than if we had loadable modules, and is unable to take advantage of our standardized modelling frameworks & capabilities :-(
If we just look at performance & security, and ignore 3rd party impls for a minute, I really don't like that to gain perf + security we have to change from:
$ qemu... -device virtio-vga
To
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vug
Once we have the ability to run the backend via an external process, to gain performance & security benefits, assuming feature parity is achieved, I question why anyone would want to continue with the old in-process approach ? IOW the goal should be that the original args
$ qemu... -device virtio-vga
should "do the right thing" to launch the external process when you have upgraded to a new enough QEMU, so that everyone immediately benefits from the more secure & performant architecture.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 86 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 30 lines · Marc-André Lureau
Hi,
vhost-user allows to drive a virtio device in a seperate process. After vhost-user-net, we have seen vhost-user-{scsi,blk,crypto} added more recently.
This series, initially proposed 2 years ago
(https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01905.html)
contributes with vhost-user-input and vhost-user-gpu.Additionally, to factor out common code and ease the usage, a vhost-user-backend is introduced as an intermediary object between the backend and the qemu device.
You may start a vhost-user-gpu with virgl rendering in a separate process like this:
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugYou may also specify the backend command and the arguments as part of vhost-user-backend qemu arguments. For example, to start a vhost-user-input backend on input device
/dev/input/event19:(quoted diff) +0
-2-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event19" -device virtio-input-host-pci,vhost-user=vuidQuoted 7 lines
The vhost-user-gpu backend requires virgl from git.
The libvirt support is on-going work:
https://github.com/elmarco/libvirt/commits/vhost-user-gpuThe GPU benchmarks are encouraging, giving up to x5 performance on Unigine Heaven 4.0.
What is the main driving motivation behind this featureset ? Is it aimed at providing performance, or security, or allowing arbitrary out of tree backends, or all three ?
Although we've got a number of vhost-user backends I'm pretty concerned about the direction this is taking QEMU overall.
Managing QEMU is non-trivial for a number of reasons. We've done a lot of work to provide standardized modelling of CLI args, guest ABI stability via association with machine types, migration data stream stability, QEMU feature capabilities detection and so on.
The move to outsource backends to external binaries is discarding some or all of these items, rewinding alot of progress we've made in the managability of QEMU. Each external binary has to now reinvent the things that are already solved in QEMU, and you can be sure each impl will reinvent the concepts differently.
I can't help feeling that we are shooting ourselves in the foot here long term.
We've always rejected the idea of having loadable modules in QEMU, but as a result we've end up with outsourcing the backend entirely via the vhost-user framework, so the end result is even more opaque than if we had loadable modules, and is unable to take advantage of our standardized modelling frameworks & capabilities :-(
If we just look at performance & security, and ignore 3rd party impls for a minute, I really don't like that to gain perf + security we have to change from:
$ qemu... -device virtio-vgaTo
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugOnce we have the ability to run the backend via an external process, to gain performance & security benefits, assuming feature parity is achieved, I question why anyone would want to continue with the old in-process approach ? IOW the goal should be that the original args
Quoted 6 lines
$ qemu... -device virtio-vgashould "do the right thing" to launch the external process when you have upgraded to a new enough QEMU, so that everyone immediately benefits from the more secure & performant architecture.
But which external process should it run, under what privilieges and with sockets placed where?
While it's true it would be good to have a nice simple way, often the qemu process might not have the privs to run that external process or know where to put the sockets; that's exactly the type of thing we're happy to leave to libvirt to wire up.
Dave
Quoted 7 lines
Regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 94 lines · Dr. David Alan Gilbert
Quoted 86 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 30 lines · Marc-André Lureau
Hi,
vhost-user allows to drive a virtio device in a seperate process. After vhost-user-net, we have seen vhost-user-{scsi,blk,crypto} added more recently.
This series, initially proposed 2 years ago
(https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01905.html)
contributes with vhost-user-input and vhost-user-gpu.Additionally, to factor out common code and ease the usage, a vhost-user-backend is introduced as an intermediary object between the backend and the qemu device.
You may start a vhost-user-gpu with virgl rendering in a separate process like this:
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugYou may also specify the backend command and the arguments as part of vhost-user-backend qemu arguments. For example, to start a vhost-user-input backend on input device
/dev/input/event19:(quoted diff) +0
-2-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event19" -device virtio-input-host-pci,vhost-user=vuidQuoted 7 lines
The vhost-user-gpu backend requires virgl from git.
The libvirt support is on-going work:
https://github.com/elmarco/libvirt/commits/vhost-user-gpuThe GPU benchmarks are encouraging, giving up to x5 performance on Unigine Heaven 4.0.
What is the main driving motivation behind this featureset ? Is it aimed at providing performance, or security, or allowing arbitrary out of tree backends, or all three ?
Although we've got a number of vhost-user backends I'm pretty concerned about the direction this is taking QEMU overall.
Managing QEMU is non-trivial for a number of reasons. We've done a lot of work to provide standardized modelling of CLI args, guest ABI stability via association with machine types, migration data stream stability, QEMU feature capabilities detection and so on.
The move to outsource backends to external binaries is discarding some or all of these items, rewinding alot of progress we've made in the managability of QEMU. Each external binary has to now reinvent the things that are already solved in QEMU, and you can be sure each impl will reinvent the concepts differently.
I can't help feeling that we are shooting ourselves in the foot here long term.
We've always rejected the idea of having loadable modules in QEMU, but as a result we've end up with outsourcing the backend entirely via the vhost-user framework, so the end result is even more opaque than if we had loadable modules, and is unable to take advantage of our standardized modelling frameworks & capabilities :-(
If we just look at performance & security, and ignore 3rd party impls for a minute, I really don't like that to gain perf + security we have to change from:
$ qemu... -device virtio-vgaTo
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugOnce we have the ability to run the backend via an external process, to gain performance & security benefits, assuming feature parity is achieved, I question why anyone would want to continue with the old in-process approach ? IOW the goal should be that the original args
Quoted 6 lines
$ qemu... -device virtio-vgashould "do the right thing" to launch the external process when you have upgraded to a new enough QEMU, so that everyone immediately benefits from the more secure & performant architecture.
Quoted 6 lines
But which external process should it run, under what privilieges and with sockets placed where?
While it's true it would be good to have a nice simple way, often the qemu process might not have the privs to run that external process or know where to put the sockets; that's exactly the type of thing we're happy to leave to libvirt to wire up.
We can still do both - the simple case where QEMU just spawns a process,
$ qemu...
-device virtio-vgawhile also allowing connections to a pre-spawned process to have extra privs via:
$ qemu...
-device virtio-vga,vhost=chardevIDRegards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Hi
Quoted 36 lines · Daniel P. Berrangé
Quoted 35 lines · Marc-André Lureau
Hi,
vhost-user allows to drive a virtio device in a seperate process. After vhost-user-net, we have seen vhost-user-{scsi,blk,crypto} added more recently.
This series, initially proposed 2 years ago
(https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01905.html)
contributes with vhost-user-input and vhost-user-gpu.Additionally, to factor out common code and ease the usage, a vhost-user-backend is introduced as an intermediary object between the backend and the qemu device.
You may start a vhost-user-gpu with virgl rendering in a separate process like this:
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugYou may also specify the backend command and the arguments as part of vhost-user-backend qemu arguments. For example, to start a vhost-user-input backend on input device
/dev/input/event19:(quoted diff) +0
-2-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event19" -device virtio-input-host-pci,vhost-user=vuidThe vhost-user-gpu backend requires virgl from git.
The libvirt support is on-going work:
https://github.com/elmarco/libvirt/commits/vhost-user-gpu
Quoted 6 lines
Quoted 2 lines
The GPU benchmarks are encouraging, giving up to x5 performance on Unigine Heaven 4.0.
What is the main driving motivation behind this featureset ? Is it aimed at providing performance, or security, or allowing arbitrary out of tree backends, or all three ?
Mainly security/stability & performance. Allowing arbitrary out of tree backends is a bonus for me, I don't care much if we don't allow it.
Quoted 8 lines
Although we've got a number of vhost-user backends I'm pretty concerned about the direction this is taking QEMU overall.
Managing QEMU is non-trivial for a number of reasons. We've done a lot of work to provide standardized modelling of CLI args, guest ABI stability via association with machine types, migration data stream stability, QEMU feature capabilities detection and so on.
Quoted 8 lines
The move to outsource backends to external binaries is discarding some or all of these items, rewinding alot of progress we've made in the managability of QEMU. Each external binary has to now reinvent the things that are already solved in QEMU, and you can be sure each impl will reinvent the concepts differently.
I can't help feeling that we are shooting ourselves in the foot here long term.
I have a bit of the same feeling. For ex, I was a bit reluctant having the TPM emulator as an external process (new protocol, external binaries, with various management work, "opaque" migration). But in the end, the integration with libvirt makes thing quite easy for the user. So I changed a bit my mind, and I think this is one task that libvirt can be really good at.
Quoted 6 lines
We've always rejected the idea of having loadable modules in QEMU, but as a result we've end up with outsourcing the backend entirely via the vhost-user framework, so the end result is even more opaque than if we had loadable modules, and is unable to take advantage of our standardized modelling frameworks & capabilities :-(
I agree, that's one of the reason I put together libvhostuser in the first place. If qemu ships its own backend, there is no reason we don't share modelling & code etc.
For ex, I hope more vhost-users will use the -object vhost-user-backend to do basic connection and virtio setup. (in the series, -gpu and -input, I didn't really investigate -crypto, -net, -blk etc)
Quoted 7 lines
If we just look at performance & security, and ignore 3rd party impls for a minute, I really don't like that to gain perf + security we have to change from:
$ qemu... -device virtio-vga
Quoted 8 lines
To
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vug
That's a bit incovenient for qemu command line users. But who runs qemu this way but some developers? (others have higher-level scripts / tools or libvirt)
Quoted 11 lines
Once we have the ability to run the backend via an external process, to gain performance & security benefits, assuming feature parity is achieved, I question why anyone would want to continue with the old in-process approach ? IOW the goal should be that the original args
$ qemu... -device virtio-vgashould "do the right thing" to launch the external process when you have upgraded to a new enough QEMU, so that everyone immediately benefits from the more secure & performant architecture.
That's not incompatible with having the lengthy version. But this comes with some downside atm, since migration is not implemented for ex (for 2d, virgl doesn't have migration).
And seccomp spawn rule disable forking.
And libvirt will probably want to manage the external process for security/resource/tweaking reasons.
thanks for the feedback!
Hi
Quoted 125 lines · Marc-André Lureau
Hi
Quoted 36 lines · Daniel P. Berrangé
Quoted 35 lines · Marc-André Lureau
Hi,
vhost-user allows to drive a virtio device in a seperate process. After vhost-user-net, we have seen vhost-user-{scsi,blk,crypto} added more recently.
This series, initially proposed 2 years ago
(https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01905.html)
contributes with vhost-user-input and vhost-user-gpu.Additionally, to factor out common code and ease the usage, a vhost-user-backend is introduced as an intermediary object between the backend and the qemu device.
You may start a vhost-user-gpu with virgl rendering in a separate process like this:
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugYou may also specify the backend command and the arguments as part of vhost-user-backend qemu arguments. For example, to start a vhost-user-input backend on input device
/dev/input/event19:(quoted diff) +0
-2-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event19" -device virtio-input-host-pci,vhost-user=vuidThe vhost-user-gpu backend requires virgl from git.
The libvirt support is on-going work:
https://github.com/elmarco/libvirt/commits/vhost-user-gpuQuoted 6 lines
Quoted 2 lines
The GPU benchmarks are encouraging, giving up to x5 performance on Unigine Heaven 4.0.
What is the main driving motivation behind this featureset ? Is it aimed at providing performance, or security, or allowing arbitrary out of tree backends, or all three ?
Mainly
security/stability& performance. Allowing arbitrary out of tree backends is a bonus for me, I don't care much if we don't allow it.Quoted 8 lines
Although we've got a number of vhost-user backends I'm pretty concerned about the direction this is taking QEMU overall.
Managing QEMU is non-trivial for a number of reasons. We've done a lot of work to provide standardized modelling of CLI args, guest ABI stability via association with machine types, migration data stream stability, QEMU feature capabilities detection and so on.
Quoted 8 lines
The move to outsource backends to external binaries is discarding some or all of these items, rewinding alot of progress we've made in the managability of QEMU. Each external binary has to now reinvent the things that are already solved in QEMU, and you can be sure each impl will reinvent the concepts differently.
I can't help feeling that we are shooting ourselves in the foot here long term.
I have a bit of the same feeling. For ex, I was a bit reluctant having the TPM emulator as an external process (new protocol, external binaries, with various management work, "opaque" migration). But in the end, the integration with libvirt makes thing quite easy for the user. So I changed a bit my mind, and I think this is one task that libvirt can be really good at.
Quoted 6 lines
We've always rejected the idea of having loadable modules in QEMU, but as a result we've end up with outsourcing the backend entirely via the vhost-user framework, so the end result is even more opaque than if we had loadable modules, and is unable to take advantage of our standardized modelling frameworks & capabilities :-(
I agree, that's one of the reason I put together libvhostuser in the first place. If qemu ships its own backend, there is no reason we don't share modelling & code etc.
For ex, I hope more vhost-users will use the -object vhost-user-backend to do basic connection and virtio setup. (in the series, -gpu and -input, I didn't really investigate -crypto, -net, -blk etc)
Quoted 7 lines
If we just look at performance & security, and ignore 3rd party impls for a minute, I really don't like that to gain perf + security we have to change from:
$ qemu... -device virtio-vgaQuoted 8 lines
To
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugThat's a bit incovenient for qemu command line users. But who runs qemu this way but some developers? (others have higher-level scripts / tools or libvirt)
Quoted 11 lines
Once we have the ability to run the backend via an external process, to gain performance & security benefits, assuming feature parity is achieved, I question why anyone would want to continue with the old in-process approach ? IOW the goal should be that the original args
$ qemu... -device virtio-vgashould "do the right thing" to launch the external process when you have upgraded to a new enough QEMU, so that everyone immediately benefits from the more secure & performant architecture.
Quoted 8 lines
That's not incompatible with having the lengthy version. But this comes with some downside atm, since migration is not implemented for ex (for 2d, virgl doesn't have migration).
And seccomp spawn rule disable forking.
And libvirt will probably want to manage the external process for
security/resource/tweakingreasons.
I would like to make progress on this, but I feel a bit stuck. As explained earlier, libvirt will have to manage the external processes. So what we would like to see, is a stable interface for the various vhost-user backends.
I suggest the vhost-user binary (vhost-user-gpu or vhost-user-input etc), the default binary be in the system PATH, so that libvirt & co can find it. Host administrator can use update-alternative or such if they are other implementations. (other selections mechanisms can be added later)
I thinks the vhost-user backends could have the following common options handling:
- take a "--fd=FDNUM" argument, that would indicate which fd the socket has been passed on.
- OR take a "--socket-path=PATH"
- optionally? take a "--pid=PATH" argument, to write out the process PID
We probably need a way to list the capabilities of the backend.:
--dump-caps, could list known keywords, one per line? (grab, virgl, opengles, etc...)
Other options may vary based on the backend type, for ex:
- vhost-user-input EVDEV-PATH (required)
- vhost-user-gpu --render-node=PATH (optional)
I am not sure how this should be documented.
Any help appreciated!
thanks
Signature · 1 line
Marc-André Lureau
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugThat's a bit incovenient for qemu command line users. But who runs qemu this way but some developers? (others have higher-level scripts / tools or libvirt)
In practice this will *allways* run over a unix socket, right? So I'm wondering whenever it makes sense to take the chardev indirection here ...
Quoted 5 lines
I suggest the vhost-user binary (vhost-user-gpu or vhost-user-input etc), the default binary be in the system PATH, so that libvirt & co can find it. Host administrator can use update-alternative or such if they are other implementations. (other selections mechanisms can be added later)
Might make sense to place them in /usr/libexec instead.
Quoted 4 lines
I thinks the vhost-user backends could have the following common options handling:
- take a "--fd=FDNUM" argument, that would indicate which fd the socket has been passed on.
Which is what libvirt would use, right?
Quoted 1 line
- OR take a "--socket-path=PATH"
Convinient when not using libvirt, looks ok to me.
Quoted 1 line
- optionally? take a "--pid=PATH" argument, to write out the process PID
Do we need that? When libvirt forks off the process it knows the PID without pidfile, right?
Quoted 3 lines
We probably need a way to list the capabilities of the backend.:
--dump-caps, could list known keywords, one per line? (grab, virgl, opengles, etc...)
Hmm, good question.
I'd tend include more information here. Such as a description of the capability. The command line switch to enable it. Print as json, we have support in both qemu and libvirt. Something like
[ 'name' : 'vulkan',
'help' : 'enable virgl vulkan support',
'switch' : '--enable-vulkan' ]
What would libvirt like to consume here? Would it actually be able to use whatever it finds there? Or would libvirt look for specific known features only, matching them with domain xml attributes?
Quoted 2 lines
Other options may vary based on the backend type, for ex:
- vhost-user-input EVDEV-PATH (required)
I'd go for "--evdev-path=/dev/input/..." syntax even for mandatory arguments.
Quoted 3 lines
- vhost-user-gpu --render-node=PATH (optional)
I am not sure how this should be documented.
docs/specs/ ?
cheers,
Gerd
Hi
Quoted 7 lines · Gerd Hoffmann
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vug
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
That's a bit incovenient for qemu command line users. But who runs qemu this way but some developers? (others have higher-level scripts / tools or libvirt)
In practice this will *allways* run over a unix socket, right? So I'm wondering whenever it makes sense to take the chardev indirection here ...
The management layer can set things up and pass fd around, avoiding socket paths etc.
Quoted 8 lines
Quoted 6 lines
I suggest the vhost-user binary (vhost-user-gpu or vhost-user-input etc), the default binary be in the system PATH, so that libvirt & co can find it. Host administrator can use update-alternative or such if they are other implementations. (other selections mechanisms can be added later)
Might make sense to place them in
/usr/libexecinstead.
ok (slightly less convenient for command line users though)
Quoted 7 lines
Quoted 5 lines
I thinks the vhost-user backends could have the following common options handling:
- take a "--fd=FDNUM" argument, that would indicate which fd the socket has been passed on.Which is what libvirt would use, right?
yes (see the related libvirt series / branch)
Quoted 9 lines
Quoted 2 lines
- OR take a "--socket-path=PATH"
Convinient when not using libvirt, looks ok to me.
Quoted 1 line
- optionally? take a "--pid=PATH" argument, to write out the process PID
Do we need that? When libvirt forks off the process it knows the PID without pidfile, right?
Yes I am not sure it is strictly necessary (that's why I put optionally). The helper could fork itself, for various reasons.
Quoted 7 lines
Quoted 4 lines
We probably need a way to list the capabilities of the backend.:
--dump-caps, could list known keywords, one per line? (grab, virgl, opengles, etc...)Hmm, good question.
Quoted 8 lines
I'd tend include more information here. Such as a description of the capability. The command line switch to enable it. Print as json, we have support in both qemu and libvirt. Something like
[ 'name' : 'vulkan',
'help' : 'enable virgl vulkan support',
'switch' : '--enable-vulkan' ]
I wouldn't go so far as describing the command line arguments here. Or else, we will have to specify the argument type etc. Instead, I would use a list of well-known keywords, described in the specification.
"vulkan" caps would mean that --enable-vulkan (without argument) is accepted and has an expected behaviour (to handle vulkan commands / rendering etc)
I don't see a problem putting the list in a json array, but I don't see much benefit either doing it.
Quoted 3 lines
What would libvirt like to consume here? Would it actually be able to use whatever it finds there? Or would libvirt look for specific known features only, matching them with domain xml attributes?
I am not sure I understand the qestion. libvirt would deal with the binary capabilities like it deals with qemu capabilities.
It would use the best combination of options given a domain XML and the capabilities.
If the domain XML requests a feature that the backend is not able to support, it would provide a sensible error.
Unknown capabilities would be ignored.
Quoted 6 lines
Quoted 3 lines
Other options may vary based on the backend type, for ex:
- vhost-user-input EVDEV-PATH (required)I'd go for "--evdev-path=/dev/input/..." syntax even for mandatory arguments.
ok
Quoted 6 lines
Quoted 4 lines
- vhost-user-gpu --render-node=PATH (optional)
I am not sure how this should be documented.
docs/specs/ ?
ok, I suppose I can start some document and include libvir-list for discussion.
Signature · 1 line
Marc-André Lureau
Quoted 14 lines · Marc-André Lureau
Hi
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
$ ./vhost-user-gpu --virgl -s vgpu.sock & $ qemu... -chardev socket,id=chr,path=vgpu.sock -object vhost-user-backend,id=vug,chardev=chr -device vhost-user-vga,vhost-user=vugThat's a bit incovenient for qemu command line users. But who runs qemu this way but some developers? (others have higher-level scripts / tools or libvirt)
Quoted 6 lines
Quoted 3 lines
In practice this will *allways* run over a unix socket, right? So I'm wondering whenever it makes sense to take the chardev indirection here ...
The management layer can set things up and pass fd around, avoiding socket paths etc.
But that fd will be a socket too ...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
- optionally? take a "--pid=PATH" argument, to write out the process PID
Do we need that? When libvirt forks off the process it knows the PID without pidfile, right?
Yes I am not sure it is strictly necessary (that's why I put optionally). The helper could fork itself, for various reasons.
Ok, good point. But then I'd make this mandatory, and maybe name it --pidfile. Shouldn't a big burden as you probably have code for that in the vhost-user helper lib
Quoted 1 line
Unknown capabilities would be ignored.
Ok, so when libvirt ignores unknown stuff anyway a list of keywords is good enough I guess. And for humans having --help is more useful.
I'd include the protocol into the names, for robustness reasons, i.e. use "input-grab" or "gpu-vulkan".
cheers,
Gerd