vhost-user backends for gpu & input virtio devices
cover vhost-user backends for gpu & input virtio devices
From: Marc-André Lureau <[email protected]>
Hi,
vhost-user allows to drive a virtio device in a seperate process. So far, it has been mainly used with virtio-net. It can work with other devices such as input and gpu, as shown in this series.
Some of the benefits of using vhost-user are:
- parallelism, since the backend is running in a different process
- flexibility, since backends may be implemented by various parties
- some process isolation (virgl is fairly recent project and a lot of security issues have been found, opengl isn't super safe either and it may run on closed-source and large gl libraries), although having a limited access to guest memory could be safer.
You can run the vhost-user-gpu backend with spice only (since importing dmabuf requires an egl context, it's not easy to do it with sdl/gtk ui), it provides the basic cursor/2d/3d rendering, but lacks some features (such as resize):
-object vhost-user-backend,id=vug,cmd="./vhost-user-gpu" -device virtio-vga,virgl=true,vhost-user=vug
-spice disable-ticketing,gl=on,unix,addr=/tmp/spice.soc
As for vhost-user-input, it takes an input device path:
-object vhost-user-backend,id=vuid,cmd="vhost-user-input /dev/input/event0" -device virtio-input-host-pci,vhost-user=vuid
This is based on top of libvhost-user series sent earlier on ML. For convenience, the branch is also available on github:
https://github.com/elmarco/qemu/ vhost-user-gpu
Comments welcome!
Marc-André Lureau (14):
Add qemu_chr_open_socket()
Add vhost-user-backend
vhost-user: split vhost_user_read()
vhost-user: add vhost_user_input_get_config()
Add vhost-user backend to virtio-input-host
contrib: add vhost-user-input
misc: rename virtio-gpu.h header guard
vhost: make sure call fd has been received
qemu-char: use READ_RETRIES
qemu-char: block during sync read
console: add dpy_gl_scanout2()
contrib: add vhost-user-gpu
vhost-user: add vhost_user_gpu_set_socket()
Add virtio-gpu vhost-user backend
Makefile | 6 + Makefile.objs | 2 + backends/Makefile.objs | 2 + backends/vhost-user.c | 262 +++++++++ configure | 5 + contrib/libvhost-user/libvhost-user.h | 1 + contrib/vhost-user-gpu/Makefile.objs | 7 + contrib/vhost-user-gpu/main.c | 1012 ++++++++++++++++++++++++++++++++ contrib/vhost-user-gpu/virgl.c | 545 +++++++++++++++++ contrib/vhost-user-gpu/virgl.h | 24 + contrib/vhost-user-gpu/vugpu.h | 155 +++++ contrib/vhost-user-input/Makefile.objs | 1 + contrib/vhost-user-input/main.c | 369 ++++++++++++ docs/specs/vhost-user.txt | 9 + hw/display/Makefile.objs | 2 +- hw/display/vhost-gpu.c | 264 +++++++++ hw/display/virtio-gpu-pci.c | 6 + hw/display/virtio-gpu.c | 75 ++- hw/display/virtio-vga.c | 5 + hw/input/virtio-input-host.c | 67 ++- hw/input/virtio-input.c | 4 + hw/virtio/vhost-user.c | 97 ++- hw/virtio/vhost.c | 5 + hw/virtio/virtio-pci.c | 5 + include/hw/virtio/vhost-backend.h | 5 + include/hw/virtio/virtio-gpu.h | 11 +- include/hw/virtio/virtio-input.h | 2 + include/sysemu/char.h | 2 + include/sysemu/vhost-user-backend.h | 65 ++ include/ui/console.h | 10 + qemu-char.c | 43 +- ui/console.c | 12 + ui/spice-display.c | 19 + 33 files changed, 3073 insertions(+), 26 deletions(-) create mode 100644 backends/vhost-user.c create mode 100644 contrib/vhost-user-gpu/Makefile.objs 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/virgl.h create mode 100644 contrib/vhost-user-gpu/vugpu.h create mode 100644 contrib/vhost-user-input/Makefile.objs create mode 100644 contrib/vhost-user-input/main.c create mode 100644 hw/display/vhost-gpu.c create mode 100644 include/sysemu/vhost-user-backend.h
Signature · 1 line
2.7.4
RFC 1/14 Add qemu_chr_open_socket()
From: Marc-André Lureau <[email protected]>
Create a CharDriver from an existing socket fd. Is there a better way to do that?
--- include/sysemu/char.h | 2 ++ qemu-char.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-)
include/sysemu/char.h +2 -0
@@ -106,6 +106,8 @@ struct CharDriverState {*/ CharDriverState *qemu_chr_alloc (ChardevCommon *backend,Error **errp); +CharDriverState *qemu_chr_open_socket (int fd,Error **errp); +/** * @qemu_chr_new_from_opts: *
qemu-char.c +36 -1
@@ -96,6 +96,10 @@static char *SocketAddress_to_str (const char *prefix,SocketAddress *addr,bool is_listen,bool is_telnet) { +if (!addr) { +return g_strdup (prefix); + } +switch (addr->type) {case SOCKET_ADDRESS_KIND_INET : return g_strdup_printf("%s%s:%s:%s%s", prefix,
@@ -166,7 +170,7 @@ CharDriverState *qemu_chr_alloc(ChardevCommon *backend, Error **errp)CharDriverState *chr =g_malloc0 (sizeof (CharDriverState));qemu_mutex_init (&chr->chr_write_lock); -if (backend->has_logfile) { +if (backend && backend->has_logfile) {int flags =O_WRONLY |O_CREAT ;if (backend->has_logappend && backend->logappend) {
@@ -4466,6 +4470,37 @@ static CharDriverState *qmp_chardev_open_socket(const char *id,return NULL ; } +CharDriverState *qemu_chr_open_socket (int fd,Error **errp) +{ +CharDriverState *chr; +TCPCharDriver *s; + + chr =qemu_chr_alloc (NULL , errp); +if (!chr) { +return NULL ; + } + +qemu_set_nonblock (fd); + + s =g_new0 (TCPCharDriver,1 ); + chr->opaque = s; + chr->chr_write = tcp_chr_write; + chr->chr_sync_read = tcp_chr_sync_read; + chr->chr_close = tcp_chr_close; + chr->get_msgfds = tcp_get_msgfds; + chr->set_msgfds = tcp_set_msgfds; + chr->chr_add_watch = tcp_chr_add_watch; + chr->chr_update_read_handler = tcp_chr_update_read_handler; + +if (tcp_chr_add_client (chr, fd) <-1 ) { +free (s); +qemu_chr_free_common (chr); +return NULL ; + } + +return chr; +} + static CharDriverState *qmp_chardev_open_udp(const char *id, ChardevBackend *backend, ChardevReturn *ret,
Signature · 1 line
2.7.4
RFC 2/14 Add vhost-user-backend
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Create a vhost-user-backend object that holds a connection to a vhost-user backend and can be referenced from virtio devices that support it.
Currently, you may specify the executable to spawn directly from command line, ex: -object vhost-user-backend,id=vui,cmd="./vhost-user-input /dev/input.."
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 or directoy. If not acceptable, the object may just take use a socket chardev instead (like vhost-user-net today).
--- backends/Makefile.objs | 2 + backends/vhost-user.c | 262 ++++++++++++++++++++++++++++++++++++ include/sysemu/vhost-user-backend.h | 65 +++++++++ 3 files changed, 329 insertions(+) create mode 100644 backends/vhost-user.c create mode 100644 include/sysemu/vhost-user-backend.h
backends/Makefile.objs +2 -0
@@ -9,3 +9,5 @@ common-obj-$(CONFIG_TPM) += tpm.o common-obj-y += hostmem.o hostmem-ram.o common-obj-$(CONFIG_LINUX) += hostmem-file.o + +common-obj-y += vhost-user.o
backends/vhost-user.c new file +262 -0
262 lines not on this page · raw message
include/sysemu/vhost-user-backend.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC 3/14 vhost-user: split vhost_user_read()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Split vhost_user_read(), so only header can be read with vhost_user_read_header().
--- hw/virtio/vhost-user.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
hw/virtio/vhost-user.c +19 -9
@@ -112,7 +112,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) {CharDriverState *chr = dev->opaque;uint8_t *p = (uint8_t *) msg;
@@ -122,7 +122,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->request); - goto fail; +return -1 ; }/* validate received flags */
@@ -130,7 +130,20 @@ 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->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) +{ +CharDriverState *chr = dev->opaque; +uint8_t *p = (uint8_t *) msg; +int r, size; + +if (vhost_user_read_header (dev, msg) <0 ) { +return -1 ; }/* validate message size is sane */
@@ -138,7 +151,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->size,VHOST_USER_PAYLOAD_SIZE ); - goto fail; +return -1 ; }if (msg->size) {
@@ -148,14 +161,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->size); - goto fail; +return -1 ; } }return 0 ; - -fail: -return -1 ; }static bool vhost_user_one_time_request (VhostUserRequest request)
@@ -458,7 +468,7 @@ static int vhost_user_get_u64(struct vhost_dev *dev, int request, uint64_t *u64)vhost_user_write (dev, &msg,NULL ,0 );if (vhost_user_read (dev, &msg) <0 ) { -return 0 ; +return -1 ; }if (msg.request != request) {
Signature · 1 line
2.7.4
RFC 4/14 vhost-user: add vhost_user_input_get_config()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- docs/specs/vhost-user.txt | 9 ++++++ hw/virtio/vhost-user.c | 58 +++++++++++++++++++++++++++++++++++++++ include/hw/virtio/vhost-backend.h | 4 +++ 3 files changed, 71 insertions(+)
docs/specs/vhost-user.txt +9 -0
@@ -464,3 +464,12 @@ Message types is present in VHOST_USER_GET_PROTOCOL_FEATURES. The first 6 bytes of the payload contain the mac address of the guest to allow the vhost user backend to construct and broadcast the fake RARP. + + * VHOST_USER_INPUT_GET_CONFIG + + Id: 20 + Equivalent ioctl: N/A + Master payload: N/A + Slave payload: (struct virtio_input_config)* + + Ask vhost user input backend the list of virtio_input_config.
hw/virtio/vhost-user.c +58 -0
70 lines not on this page · raw message
include/hw/virtio/vhost-backend.h +4 -0
@@ -11,6 +11,7 @@ #ifndef VHOST_BACKEND_H_ #define VHOST_BACKEND_H_ +#include "standard-headers/linux/virtio_input.h" typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE = 0,
@@ -107,4 +108,7 @@ extern const VhostOps user_ops;int vhost_set_backend_type (struct vhost_dev *dev,VhostBackendType backend_type); +int vhost_user_input_get_config (struct vhost_dev *dev, +struct virtio_input_config **config); +#endif /* VHOST_BACKEND_H_ */
Signature · 1 line
2.7.4
RFC 5/14 Add vhost-user backend to virtio-input-host
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Learn to use a vhost-user as a virtio-input backend. Usage:
-object vhost-user-backend,id=vuid -device virtio-input-host-pci,vhost-user=vuid
--- hw/input/virtio-input-host.c | 67 ++++++++++++++++++++++++++++++++++------ hw/input/virtio-input.c | 4 +++ hw/virtio/virtio-pci.c | 5 +++ include/hw/virtio/virtio-input.h | 2 ++ 4 files changed, 69 insertions(+), 9 deletions(-)
hw/input/virtio-input-host.c +58 -9
@@ -95,20 +95,14 @@ static void virtio_input_abs_config(VirtIOInputHost *vih, int axis)virtio_input_add_config (VIRTIO_INPUT (vih), &config); } -static void virtio_input_host_realize (DeviceState *dev,Error **errp) +static void virtio_input_evdev_init (VirtIOInputHost *vih,Error **errp) { -VirtIOInputHost *vih =VIRTIO_INPUT_HOST (dev); -VirtIOInput *vinput =VIRTIO_INPUT (dev); +VirtIOInput *vinput =VIRTIO_INPUT (vih);virtio_input_config id, *abs;struct input_id ids;int rc, ver, i, axis;uint8_t byte; -if (!vih->evdev) { -error_setg (errp,"evdev property is required" ); -return ; - } - vih->fd =open (vih->evdev,O_RDWR );if (vih->fd <0 ) {error_setg_file_open (errp, errno, vih->evdev);
@@ -175,7 +169,34 @@ static void virtio_input_host_realize(DeviceState *dev, Error **errp) err_close:close (vih->fd); vih->fd =-1 ; -return ; +} + +static void virtio_input_host_realize (DeviceState *dev,Error **errp) +{ +VirtIOInputHost *vih =VIRTIO_INPUT_HOST (dev); +VirtIOInput *vinput =VIRTIO_INPUT (vih); + +if (!!vih->evdev + !!vinput->vhost !=1 ) { +error_setg (errp,"'evdev' or 'vhost-user' property is required" ); +return ; + } + +if (vih->evdev) { +virtio_input_evdev_init (vih, errp); + }else { +virtio_input_config *config; +int i, ret; + + ret =vhost_user_input_get_config (&vinput->vhost->dev, &config); +if (ret <0 ) { +error_setg (errp,"failed to get input config" ); +return ; + } +for (i =0 ; i < ret; i++) { +virtio_input_add_config (vinput, &config[i]); + } +g_free (config); + } }static void virtio_input_host_unrealize (DeviceState *dev,Error **errp)
@@ -210,6 +231,15 @@ static void virtio_input_host_handle_status(VirtIOInput *vinput, } } +static void virtio_input_host_change_active (VirtIOInput *vinput) +{ +if (vinput->active) { +vhost_user_backend_start (vinput->vhost); + }else { +vhost_user_backend_stop (vinput->vhost); + } +} +static const VMStateDescription vmstate_virtio_input_host = { .name ="virtio-input-host" , .unmigratable =1 ,
@@ -230,6 +260,19 @@ static void virtio_input_host_class_init(ObjectClass *klass, void *data) vic->realize = virtio_input_host_realize; vic->unrealize = virtio_input_host_unrealize; vic->handle_status = virtio_input_host_handle_status; + vic->change_active = virtio_input_host_change_active; +} + +static void virtio_input_host_user_is_busy (Object *obj,const char *name, +Object *val,Error **errp) +{ +VirtIOInput *vinput =VIRTIO_INPUT (obj); + +if (vinput->vhost) { +error_setg (errp,"can't use already busy vhost-user" ); + }else { +qdev_prop_allow_set_link_before_realize (obj, name, val, errp); + } }static void virtio_input_host_init (Object *obj)
@@ -237,6 +280,12 @@ static void virtio_input_host_init(Object *obj)VirtIOInput *vinput =VIRTIO_INPUT (obj);virtio_input_init_config (vinput, virtio_input_host_config); + +object_property_add_link (obj,"vhost-user" ,TYPE_VHOST_USER_BACKEND , + (Object **)&vinput->vhost, + virtio_input_host_user_is_busy, +OBJ_PROP_LINK_UNREF_ON_RELEASE , + &error_abort); }static const TypeInfo virtio_input_host_info = {
hw/input/virtio-input.c +4 -0
@@ -280,6 +280,10 @@ static void virtio_input_device_realize(DeviceState *dev, Error **errp) vinput->evt =virtio_add_queue (vdev,64 , virtio_input_handle_evt); vinput->sts =virtio_add_queue (vdev,64 , virtio_input_handle_sts); +if (vinput->vhost) { +vhost_user_backend_dev_init (vinput->vhost, vdev,2 , errp); + } +register_savevm (dev,"virtio-input" ,-1 ,VIRTIO_INPUT_VM_VERSION , virtio_input_save, virtio_input_load, vinput); }
hw/virtio/virtio-pci.c +5 -0
@@ -2454,6 +2454,11 @@ static void virtio_host_initfn(Object *obj)virtio_instance_init_common (obj, &dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_INPUT_HOST ); + +/* could eventually be included in qdev_alias_all_properties? */ +object_property_add_alias (obj,"vhost-user" , +OBJECT (&dev->vdev),"vhost-user" , + &error_abort); }static const TypeInfo virtio_host_pci_info = {
include/hw/virtio/virtio-input.h +2 -0
@@ -2,6 +2,7 @@#define _QEMU_VIRTIO_INPUT_H#include "ui/input.h" +#include "sysemu/vhost-user-backend.h" /* ----------------------------------------------------------------- */ /* virtio input protocol */
@@ -66,6 +67,7 @@ struct VirtIOInput {uint32_t qindex, qsize;bool active; +VhostUserBackend *vhost; };struct VirtIOInputClass {
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC 05/14] Add vhost-user backend to virtio-input-host
Quoted 5 lines · On Sa, 2016-06-04 at 23:33 +0200, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Learn to use a vhost-user as a virtio-input backend. Usage:
-object vhost-user-backend,id=vuid -device virtio-input-host-pci,vhost-user=vuid
IMO this should be a separate device, named "virtio-input-vhost" or "virtio-input-user". There isn't really any common code between this and virtio-input-host.
cheers,
Gerd
RFC 6/14 contrib: add vhost-user-input
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add a vhost-user input backend example, 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"
--- Makefile | 3 + Makefile.objs | 1 + configure | 1 + contrib/vhost-user-input/Makefile.objs | 1 + contrib/vhost-user-input/main.c | 369 +++++++++++++++++++++++++++++++++ 5 files changed, 375 insertions(+) create mode 100644 contrib/vhost-user-input/Makefile.objs create mode 100644 contrib/vhost-user-input/main.c
Makefile +3 -0
@@ -152,6 +152,7 @@ dummy := $(call unnest-vars,, \ ivshmem-client-obj-y \ ivshmem-server-obj-y \ libvhost-user-obj-y \ + vhost-user-input-obj-y \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \
@@ -332,6 +333,8 @@ ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) libqemuutil.a libqemustub.a $(call LINK, $^) ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) libqemuutil.a libqemustub.a $(call LINK, $^) +vhost-user-input$(EXESUF): $(vhost-user-input-obj-y) $(libvhost-user-obj-y) libqemuutil.a libqemustub.a + $(call LINK, $^) clean: # avoid old build problems by removing potentially incorrect old files
Makefile.objs +1 -0
@@ -116,3 +116,4 @@ qga-vss-dll-obj-y = qga/ ivshmem-client-obj-y = contrib/ivshmem-client/ ivshmem-server-obj-y = contrib/ivshmem-server/ libvhost-user-obj-y = contrib/libvhost-user/ +vhost-user-input-obj-y = contrib/vhost-user-input/
configure +1 -0
@@ -4602,6 +4602,7 @@ if test "$want_tools" = "yes" ; then if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then tools="qemu-nbd\$(EXESUF) $tools" tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools" + tools="vhost-user-input\$(EXESUF) $tools" fi fi if test "$softmmu" = yes ; then
contrib/vhost-user-input/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +vhost-user-input-obj-y = main.o
contrib/vhost-user-input/main.c new file +369 -0
369 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC 7/14 misc: rename virtio-gpu.h header guard
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- include/hw/virtio/virtio-gpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/hw/virtio/virtio-gpu.h +2 -2
@@ -11,8 +11,8 @@* See the COPYING file in the top-level directory. */ -#ifndef _QEMU_VIRTIO_VGA_H -#define _QEMU_VIRTIO_VGA_H +#ifndef _QEMU_VIRTIO_GPU_H +#define _QEMU_VIRTIO_GPU_H#include "qemu/queue.h" #include "ui/qemu-pixman.h"
Signature · 1 line
2.7.4
RFC 8/14 vhost: make sure call fd has been received
In reply to [email protected]From: Marc-André Lureau <[email protected]>
vhost switches between masked notifier and guest notifier when unmasking. virtio_pci_vq_vector_unmask() checks if there was pending notification, but at the time it is checked, vhost-user backend doesn't guarantee that the switch happened yet, so it may lose some events.
To solve this vhost-user race, I introduced an extra "sync" call (waiting for a reply). One may want to make all/many vhost-user replies mandatories by adding a new capability instead.
--- hw/virtio/vhost.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/virtio/vhost.c +5 -0
@@ -1181,6 +1181,7 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,struct VirtQueue *vvq =virtio_get_queue (vdev, n);int r, index = n - hdev->vq_index;struct vhost_vring_file file; +uint64_t features;if (mask) {assert (vdev->use_guest_notifier_mask);
@@ -1192,6 +1193,10 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, file.index = hdev->vhost_ops->vhost_get_vq_index (hdev, n); r = hdev->vhost_ops->vhost_set_vring_call (hdev, &file);assert (r >=0 ); + +/* silly sync call to make sure the call fd has been received */ + r = hdev->vhost_ops->vhost_get_features (hdev, &features); +assert (r >=0 ); } uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits,
Signature · 1 line
2.7.4
RFC 9/14 qemu-char: use READ_RETRIES
In reply to [email protected]From: Marc-André Lureau <[email protected]>
The define was introduced with qemu_chr_fe_read_all() in 7b0bfdf52d, however never used.
--- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qemu-char.c +2 -2
@@ -325,13 +325,13 @@ int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len)int qemu_chr_fe_read_all (CharDriverState *s,uint8_t *buf,int len) { -int offset =0 , counter =10 ; +int offset =0 , counter =READ_RETRIES ;int res;if (!s->chr_sync_read) {return 0 ; } - +if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) {return replay_char_read_all_load (buf); }
Signature · 1 line
2.7.4
RFC 10/14 qemu-char: block during sync read
In reply to [email protected]From: Marc-André Lureau <[email protected]>
A sync read should block until data is available, instead of retrying. Change the channel to blocking during read.
--- qemu-char.c | 2 ++ 1 file changed, 2 insertions(+)
qemu-char.c +2 -0
@@ -2911,7 +2911,9 @@ static int tcp_chr_sync_read(CharDriverState *chr, const uint8_t *buf, int len)return 0 ; } +qio_channel_set_blocking (s->ioc, true,NULL ); size =tcp_chr_recv (chr, (void *) buf, len); +qio_channel_set_blocking (s->ioc, false,NULL );if (size ==0 ) {/* connection closed */ tcp_chr_disconnect (chr);
Signature · 1 line
2.7.4
RFC 11/14 console: add dpy_gl_scanout2()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add a new scanout callback that doesn't require any gl context in qemu (importing a dmabuf fd would require qemu egl&gl contexts, and would be unnecessary when using spice anyway)
--- include/ui/console.h | 10 ++++++++++ ui/console.c | 12 ++++++++++++ ui/spice-display.c | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+)
include/ui/console.h +10 -0
@@ -218,6 +218,11 @@ typedef struct DisplayChangeListenerOps {void (*dpy_gl_scanout)(DisplayChangeListener *dcl,uint32_t backing_id,bool backing_y_0_top,uint32_t x,uint32_t y,uint32_t w,uint32_t h); +void (*dpy_gl_scanout2)(DisplayChangeListener *dcl, +int fd,bool backing_y_0_top, +uint32_t x,uint32_t y,uint32_t w,uint32_t h, +uint32_t fd_w,uint32_t fd_h,uint32_t fd_stride, +int fd_fourcc);void (*dpy_gl_update)(DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h);
@@ -286,6 +291,11 @@ bool dpy_gfx_check_format(QemuConsole *con,void dpy_gl_scanout (QemuConsole *con,uint32_t backing_id,bool backing_y_0_top,uint32_t x,uint32_t y,uint32_t w,uint32_t h); +void dpy_gl_scanout2 (QemuConsole *con, +int fd,bool backing_y_0_top, +uint32_t x,uint32_t y,uint32_t w,uint32_t h, +uint32_t fd_w,uint32_t fd_h,uint32_t fd_stride, +int fd_fourcc);void dpy_gl_update (QemuConsole *con,uint32_t x,uint32_t y,uint32_t w,uint32_t h);
ui/console.c +12 -0
@@ -1712,6 +1712,18 @@ void dpy_gl_scanout(QemuConsole *con, x, y, width, height); } +void dpy_gl_scanout2 (QemuConsole *con, +int fd,bool backing_y_0_top, +uint32_t x,uint32_t y,uint32_t w,uint32_t h, +uint32_t fd_w,uint32_t fd_h,uint32_t fd_stride, +int fd_fourcc) +{ +assert (con->gl); + con->gl->ops->dpy_gl_scanout2 (con->gl, fd, backing_y_0_top, + x, y, w, h, fd_w, fd_h, fd_stride, + fd_fourcc); +} +void dpy_gl_update (QemuConsole *con,uint32_t x,uint32_t y,uint32_t w,uint32_t h) {
ui/spice-display.c +19 -0
@@ -888,6 +888,24 @@ static void qemu_spice_gl_scanout(DisplayChangeListener *dcl,qemu_spice_gl_monitor_config (ssd, x, y, w, h); } +static void +qemu_spice_gl_scanout2 (DisplayChangeListener *dcl, +int fd,bool y_0_top, +uint32_t x,uint32_t y,uint32_t w,uint32_t h, +uint32_t fd_w,uint32_t fd_h,uint32_t fd_stride, +int fd_fourcc) +{ +SimpleSpiceDisplay *ssd =container_of (dcl, SimpleSpiceDisplay, dcl); + +/* note: spice server will close the fd */ +spice_qxl_gl_scanout (&ssd->qxl, fd, + fd_w, + fd_h, + fd_stride, fd_fourcc, y_0_top); + +qemu_spice_gl_monitor_config (ssd, x, y, w, h); +} +static void qemu_spice_gl_update (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h) {
@@ -915,6 +933,7 @@ static const DisplayChangeListenerOps display_listener_gl_ops = { .dpy_gl_ctx_get_current = qemu_egl_get_current_context, .dpy_gl_scanout = qemu_spice_gl_scanout, + .dpy_gl_scanout2 = qemu_spice_gl_scanout2, .dpy_gl_update = qemu_spice_gl_update, };
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC 11/14] console: add dpy_gl_scanout2()
Hi,
include/ui/console.h typedef struct DisplayChangeListenerOps { · line 225
Quoted 9 lines
include/ui/console.h +5
-0@@ -218,6 +218,11 @@ typedef struct DisplayChangeListenerOps {void (*dpy_gl_scanout)(DisplayChangeListener *dcl,uint32_t backing_id,bool backing_y_0_top,uint32_t x,uint32_t y,uint32_t w,uint32_t h); +void (*dpy_gl_scanout2)(DisplayChangeListener *dcl, +int fd,bool backing_y_0_top, +uint32_t x,uint32_t y,uint32_t w,uint32_t h, +uint32_t fd_w,uint32_t fd_h,uint32_t fd_stride, +int fd_fourcc);
Interface looks sane. I'd like to see a more descriptive name than just "2" though. Maybe "dpy_gl_scanout_dmabuf"? And while being at it rename the other one to "dpy_gl_scanout_texture"?
Also: please put the spice update into a separate patch.
Adding gtk (or sdl2, or both) support would be nice, to see whenever the interface works if qemu needs to import the dma-buf for display.
cheers,
Gerd
Re: [Qemu-devel] [RFC 11/14] console: add dpy_gl_scanout2()
Hi
----- Original Message -----
Quoted 18 lines
Hi,
Review typedef struct DisplayChangeListenerOps { · line 228
Quoted 12 lines
(quoted diff) +5
-0@@ -218,6 +218,11 @@ typedef struct DisplayChangeListenerOps { void (*dpy_gl_scanout)(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, uint32_t x, uint32_t y, uint32_t w, uint32_t h); + void (*dpy_gl_scanout2)(DisplayChangeListener *dcl, + int fd, bool backing_y_0_top, + uint32_t x, uint32_t y, uint32_t w, uint32_t h, + uint32_t fd_w, uint32_t fd_h, uint32_t fd_stride, + int fd_fourcc);Interface looks sane. I'd like to see a more descriptive name than just "2" though. Maybe "
dpy_gl_scanout_dmabuf"? And while being at it rename the other one to "dpy_gl_scanout_texture"?
sounds good
Quoted 2 lines
Also: please put the spice update into a separate patch.
ok
Quoted 3 lines
Adding gtk (or sdl2, or both) support would be nice, to see whenever the interface works if qemu needs to import the dma-buf for display.
As I explained in cover, it's not easily doable since gtk/sdl2 use glx, and can't import dmabuf (it needs egl). I could make it work with gtk/egl (but not gtkglarea, sigh, so many UIs and subtle issues)
Re: [Qemu-devel] [RFC 11/14] console: add dpy_gl_scanout2()
Hi,
Quoted 6 lines
Quoted 2 lines
Adding gtk (or sdl2, or both) support would be nice, to see whenever the interface works if qemu needs to import the dma-buf for display.
As I explained in cover, it's not easily doable since gtk/sdl2 use glx, and can't import dmabuf (it needs egl). I could make it work with gtk/egl (but not gtkglarea, sigh, so many UIs and subtle issues)
Ah, ok. Was reading a bit too fast it seems, didn't notice the subtile egl vs. glx thing.
cheers,
Gerd
RFC 12/14 contrib: add vhost-user-gpu
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add 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"
--- Makefile | 3 + Makefile.objs | 1 + configure | 4 + contrib/vhost-user-gpu/Makefile.objs | 7 + contrib/vhost-user-gpu/main.c | 1012 ++++++++++++++++++++++++++++++++++ contrib/vhost-user-gpu/virgl.c | 545 ++++++++++++++++++ contrib/vhost-user-gpu/virgl.h | 24 + contrib/vhost-user-gpu/vugpu.h | 155 ++++++ 8 files changed, 1751 insertions(+) create mode 100644 contrib/vhost-user-gpu/Makefile.objs 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/virgl.h create mode 100644 contrib/vhost-user-gpu/vugpu.h
Makefile +3 -0
@@ -153,6 +153,7 @@ dummy := $(call unnest-vars,, \ ivshmem-server-obj-y \ libvhost-user-obj-y \ vhost-user-input-obj-y \ + vhost-user-gpu-obj-y \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \
@@ -335,6 +336,8 @@ ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) libqemuutil.a libqemustub.a $(call LINK, $^) vhost-user-input$(EXESUF): $(vhost-user-input-obj-y) $(libvhost-user-obj-y) libqemuutil.a libqemustub.a $(call LINK, $^) +vhost-user-gpu$(EXESUF): $(vhost-user-gpu-obj-y) $(libvhost-user-obj-y) libqemuutil.a libqemustub.a + $(call LINK, $^) clean: # avoid old build problems by removing potentially incorrect old files
Makefile.objs +1 -0
@@ -117,3 +117,4 @@ ivshmem-client-obj-y = contrib/ivshmem-client/ ivshmem-server-obj-y = contrib/ivshmem-server/ libvhost-user-obj-y = contrib/libvhost-user/ vhost-user-input-obj-y = contrib/vhost-user-input/ +vhost-user-gpu-obj-y = contrib/vhost-user-gpu/
configure +4 -0
@@ -4603,6 +4603,7 @@ if test "$want_tools" = "yes" ; then tools="qemu-nbd\$(EXESUF) $tools" tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools" tools="vhost-user-input\$(EXESUF) $tools" + tools="vhost-user-gpu\$(EXESUF) $tools" fi fi if test "$softmmu" = yes ; then
@@ -5924,6 +5925,9 @@ if [ "$pixman" = "internal" ]; then echo "config-host.h: subdir-pixman" >> $config_host_mak fi +echo "PIXMAN_CFLAGS=$pixman_cflags" >> $config_host_mak +echo "PIXMAN_LIBS=$pixman_libs" >> $config_host_mak + if [ "$dtc_internal" = "yes" ]; then echo "config-host.h: subdir-dtc" >> $config_host_mak fi
contrib/vhost-user-gpu/Makefile.objs new file +7 -0
@@ -0,0 +1,7 @@ +vhost-user-gpu-obj-y = main.o virgl.o + +main.o-cflags := $(PIXMAN_CFLAGS) +main.o-libs := $(PIXMAN_LIBS) + +virgl.o-cflags := $(VIRGL_CFLAGS) +virgl.o-libs := $(VIRGL_LIBS)
contrib/vhost-user-gpu/main.c new file +1012 -0
1,012 lines not on this page · raw message
contrib/vhost-user-gpu/virgl.c new file +545 -0
545 lines not on this page · raw message
contrib/vhost-user-gpu/virgl.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Virtio vhost-user GPU Device +* +* Copyright Red Hat, Inc. 2013-2016 +* +* 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" + +int vg_virgl_init (VuGpu *g); +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 +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC 13/14 vhost-user: add vhost_user_gpu_set_socket()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add a new vhost-user message to give a unix socket for gpu updates to a vhost-user backend.
--- contrib/libvhost-user/libvhost-user.h | 1 + hw/virtio/vhost-user.c | 11 +++++++++++ include/hw/virtio/vhost-backend.h | 1 + 3 files changed, 13 insertions(+)
contrib/libvhost-user/libvhost-user.h +1 -0
@@ -61,6 +61,7 @@ typedef enum VhostUserRequest {VHOST_USER_SET_VRING_ENABLE =18 ,VHOST_USER_SEND_RARP =19 ,VHOST_USER_INPUT_GET_CONFIG =20 , +VHOST_USER_GPU_SET_SOCKET =21 , VHOST_USER_MAX } VhostUserRequest;
hw/virtio/vhost-user.c +11 -0
@@ -59,6 +59,7 @@ typedef enum VhostUserRequest {VHOST_USER_SET_VRING_ENABLE =18 ,VHOST_USER_SEND_RARP =19 ,VHOST_USER_INPUT_GET_CONFIG =20 , +VHOST_USER_GPU_SET_SOCKET =21 , VHOST_USER_MAX } VhostUserRequest;
@@ -263,6 +264,16 @@ err:return -1 ; } +int vhost_user_gpu_set_socket (struct vhost_dev *dev,int fd) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GPU_SET_SOCKET , + .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) {
include/hw/virtio/vhost-backend.h +1 -0
@@ -110,5 +110,6 @@ int vhost_set_backend_type(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_ */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC 13/14] vhost-user: add vhost_user_gpu_set_socket()
Quoted 4 lines · On Sa, 2016-06-04 at 23:33 +0200, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Add a new vhost-user message to give a unix socket for gpu updates to a vhost-user backend.
--verbose please.
cheers,
Gerd
RFC 14/14 Add virtio-gpu vhost-user backend
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add to virtio-gpu devices a "vhost-user" property. When set, the associated vhost-user backend is used to handle the virtio rings.
For now, a socketpair is created for the backend to share the rendering results with qemu via a simple VHOST_GPU protocol.
Example usage:
-object vhost-user-backend,id=vug,cmd="./vhost-user-gpu" -device virtio-vga,virgl=true,vhost-user=vug
--- hw/display/Makefile.objs | 2 +- hw/display/vhost-gpu.c | 264 +++++++++++++++++++++++++++++++++++++++++ hw/display/virtio-gpu-pci.c | 6 + hw/display/virtio-gpu.c | 75 +++++++++++- hw/display/virtio-vga.c | 5 + include/hw/virtio/virtio-gpu.h | 7 ++ 6 files changed, 356 insertions(+), 3 deletions(-) create mode 100644 hw/display/vhost-gpu.c
hw/display/Makefile.objs +1 -1
@@ -36,7 +36,7 @@ obj-$(CONFIG_VGA) += vga.o common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o -obj-$(CONFIG_VIRTIO) += virtio-gpu.o virtio-gpu-3d.o +obj-$(CONFIG_VIRTIO) += virtio-gpu.o virtio-gpu-3d.o vhost-gpu.o obj-$(CONFIG_VIRTIO_PCI) += virtio-gpu-pci.o obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o virtio-gpu.o-cflags := $(VIRGL_CFLAGS)
hw/display/vhost-gpu.c new file +264 -0
264 lines not on this page · raw message
hw/display/virtio-gpu-pci.c +6 -0
@@ -16,6 +16,7 @@#include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-gpu.h" +#include "qapi/error.h" static Property virtio_gpu_pci_properties[] = {DEFINE_VIRTIO_GPU_PCI_PROPERTIES (VirtIOPCIProxy),
@@ -60,6 +61,11 @@ static void virtio_gpu_initfn(Object *obj)virtio_instance_init_common (obj, &dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_GPU ); + +/* could eventually be included in qdev_alias_all_properties? */ +object_property_add_alias (obj,"vhost-user" , +OBJECT (&dev->vdev),"vhost-user" , + &error_abort); }static const TypeInfo virtio_gpu_pci_info = {
hw/display/virtio-gpu.c +73 -2
119 lines not on this page · raw message
hw/display/virtio-vga.c +5 -0
@@ -181,6 +181,11 @@ static void virtio_vga_inst_initfn(Object *obj)virtio_instance_init_common (obj, &dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_GPU ); + +/* could eventually be included in qdev_alias_all_properties? */ +object_property_add_alias (obj,"vhost-user" , +OBJECT (&dev->vdev),"vhost-user" , + &error_abort); }static TypeInfo virtio_vga_info = {
include/hw/virtio/virtio-gpu.h +7 -0
@@ -19,6 +19,7 @@#include "ui/console.h" #include "hw/virtio/virtio.h" #include "hw/pci/pci.h" +#include "sysemu/vhost-user-backend.h" #include "standard-headers/linux/virtio_gpu.h" #define TYPE_VIRTIO_GPU "virtio-gpu-device"
@@ -82,6 +83,9 @@ struct virtio_gpu_ctrl_command { typedef struct VirtIOGPU { VirtIODevice parent_obj; + VhostUserBackend *vhost; + CharDriverState *vhost_chr; + QEMUBH *ctrl_bh; QEMUBH *cursor_bh; VirtQueue *ctrl_vq;
@@ -161,4 +165,7 @@ void virtio_gpu_virgl_fence_poll(VirtIOGPU *g);void virtio_gpu_virgl_reset (VirtIOGPU *g);int virtio_gpu_virgl_init (VirtIOGPU *g); +/* vhost-gpu.c */ +int vhost_gpu_init (VirtIOGPU *g,Error **errp); +#endif
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC 14/14] Add virtio-gpu vhost-user backend
Quoted 7 lines · On Sa, 2016-06-04 at 23:33 +0200, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Add to virtio-gpu devices a "vhost-user" property. When set, the associated vhost-user backend is used to handle the virtio rings.
For now, a socketpair is created for the backend to share the rendering results with qemu via a simple
VHOST_GPUprotocol.
Can you give a design overview?
On a first look this seems to not share much code with virtio-gpu either, so I guess it makes sense to put this into a separate virtio-gpu-vhost device too.
cheers,
Gerd
Hi Gerd
Thanks for your feedback on the series. Your remarks are all valid, but before doing more work I would like to know if there is enough interest. It duplicates work and adds some complexity. Also, some general feedback on design would be welcome.
What is proposed in this series:
- the vhost-user-backend is a helper object spawning, setting up and holding a connection to a backend
- the vhost-user socket is set to be fd 3 in child process
- we may want to use only or allow specifying a unix socket chardev to a backend (like vhost-net), in which case management of backend would be left outside of qemu
- "add vhost-user backend to virtio-input-host" patch shows how little is required for a virtio device to use vhost-user-backend, and is quite a neat use case imho (allowing various input backends)
- there are device specific vhost-user messages to be added, such as VHOST_USER_INPUT_GET_CONFIG, or we may use extra fd for communication to pass to child during fork
- when there is a whole set of messages to add, like the VHOST_GPU*, I decided to use a different socket, given to backend with VHOST_USER_GPU_SET_SOCKET.
I am not sold that we need to develop a new vhost protocol for the gpu though. I am considering the Spice worker thread (handling cursor and display) to actually run in the vhost backend. That would make the solution Spice specific though (unless qemu implements some of the Spice protocol ...). Having the spice worker running in the backend has similar advantages of robustness to reduce attack to qemu by a spice user.
I am also wondering if several virtio backends could be combined in the same process. This would allow to have quite easily qemu gtk/sdl UI in a subprocess.
Going further, once we have proper reconnect & reset support in vhost-user & virtio, one can imagine running/stoping different UIs too.
(so after this initial rfc, that look all nice to me, the question I ask myself is what do we actually want?)
Signature · 1 line
Marc-André Lureau
Quoted 11 lines · Marc-André Lureau
Hi Gerd
Thanks for your feedback on the series. Your remarks are all valid, but before doing more work I would like to know if there is enough interest. It duplicates work and adds some complexity. Also, some general feedback on design would be welcome.
What is proposed in this series:
- the vhost-user-backend is a helper object spawning, setting up and holding a connection to a backend
- the vhost-user socket is set to be fd 3 in child process
Which implies a 1:1 relationship between object and backend. Which isn't that great if we want allow for multiple backends in one process (your idea below, and I think it can be useful).
Quoted 3 lines
- "add vhost-user backend to virtio-input-host" patch shows how little is required for a virtio device to use vhost-user-backend, and is quite a neat use case imho (allowing various input backends)
Indeed. Doing a "mouse wiggler" would be a pretty minimal backend.
Quoted 3 lines
- there are device specific vhost-user messages to be added, such as
VHOST_USER_INPUT_GET_CONFIG, or we may use extra fd for communication to pass to child during fork
Is that needed? I think it should be possible to create device-agnostic messages for config access.
Quoted 3 lines
- when there is a whole set of messages to add, like the VHOST_GPU*, I decided to use a different socket, given to backend with
VHOST_USER_GPU_SET_SOCKET.
I would tend to send it all over the same socket.
Quoted 3 lines
I am not sold that we need to develop a new vhost protocol for the gpu though. I am considering the Spice worker thread (handling cursor and display) to actually run in the vhost backend.
Interesting idea, would safe quite a few context switches for dma-buf passing. But it also brings new challenges, vga compatibility for example. Also spice channel management. vdagent, ...
I'd suggest put it aside for now though. Get the other stuff done first. Running virglrenderer in a separate process is certainly very useful from a security point of view, and that is a big enough project for a while I suspect.
Quoted 3 lines
Going further, once we have proper reconnect & reset support in vhost-user & virtio, one can imagine running/stoping different UIs too.
That'll be quite difficult for virtio-gpu too.
virtio-input should be easy though.
cheers,
Gerd
Hi
----- Original Message -----
Quoted 8 lines · Marc-André Lureau
Quoted 7 lines
Hi Gerd
Thanks for your feedback on the series. Your remarks are all valid, but before doing more work I would like to know if there is enough interest. It duplicates work and adds some complexity. Also, some general feedback on design would be welcome.
Quoted 9 lines
Quoted 4 lines
What is proposed in this series:
- the vhost-user-backend is a helper object spawning, setting up and holding a connection to a backend
- the vhost-user socket is set to be fd 3 in child processWhich implies a 1:1 relationship between object and backend. Which isn't that great if we want allow for multiple backends in one process (your idea below, and I think it can be useful).
That socket could use a different protocol to instantiate vhost-user device/backends (passing vhost-user sockets per device)?
Quoted 4 lines
Quoted 3 lines
- "add vhost-user backend to virtio-input-host" patch shows how little is required for a virtio device to use vhost-user-backend, and is quite a neat use case imho (allowing various input backends)
Quoted 8 lines
Indeed. Doing a "mouse wiggler" would be a pretty minimal backend.
Quoted 3 lines
- there are device specific vhost-user messages to be added, such as
VHOST_USER_INPUT_GET_CONFIG, or we may use extra fd for communication to pass to child during forkIs that needed? I think it should be possible to create device-agnostic messages for config access.
VHOST_USER_INPUT_GET_CONFIG is quite virtio-input specific, since it returns the array of virtio_input_config, that is later read via virtio config selection. Can this be generalized?
Quoted 5 lines
Quoted 3 lines
- when there is a whole set of messages to add, like the VHOST_GPU*, I decided to use a different socket, given to backend with
VHOST_USER_GPU_SET_SOCKET.I would tend to send it all over the same socket.
It's possible, but currently vhost-user protocol is unidirectional (master/slave request/reply relationship). The backend cannot easily send messages on its own. So beside reinventing some display protocol, it is hard to fit in vhost-user socket today.
Quoted 8 lines
Quoted 4 lines
I am not sold that we need to develop a new vhost protocol for the gpu though. I am considering the Spice worker thread (handling cursor and display) to actually run in the vhost backend.
Interesting idea, would safe quite a few context switches for dma-buf passing. But it also brings new challenges, vga compatibility for example. Also spice channel management. vdagent, ...
What I had in mind is to hand off only the cursor and display channel to the vhost-gpu backend once the channel is up and the gpu is active. Eventually hand it back to qemu when switching back to VGA (sounds like it should be doable to me, but perhaps not worth it like this?)
Quoted 4 lines
I'd suggest put it aside for now though. Get the other stuff done first. Running virglrenderer in a separate process is certainly very useful from a security point of view, and that is a big enough project for a while I suspect.
Agree, then it will require the VHOST_GPU_* messages to update qemu&spice process.
Quoted 6 lines
Quoted 3 lines
Going further, once we have proper reconnect & reset support in vhost-user & virtio, one can imagine running/stoping different UIs too.
That'll be quite difficult for virtio-gpu too.
virtio-input should be easy though.
Right, I wasn't thinking about 3d in this case ;) Although I still hope we can get there some day.
thanks
Quoted 16 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 13 lines · Marc-André Lureau
Quoted 11 lines
Hi Gerd
Thanks for your feedback on the series. Your remarks are all valid, but before doing more work I would like to know if there is enough interest. It duplicates work and adds some complexity. Also, some general feedback on design would be welcome.
What is proposed in this series:
- the vhost-user-backend is a helper object spawning, setting up and holding a connection to a backend
- the vhost-user socket is set to be fd 3 in child process
Quoted 6 lines
Quoted 4 lines
Which implies a 1:1 relationship between object and backend. Which isn't that great if we want allow for multiple backends in one process (your idea below, and I think it can be useful).
That socket could use a different protocol to instantiate vhost-user device/backends (passing vhost-user sockets per device)?
I'd tend to simply hand the backend process one unix socket path per device. Maybe also allow libvirt to link things using monitor fd passing.
It's a little less automatic, but more flexible.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
- there are device specific vhost-user messages to be added, such as
VHOST_USER_INPUT_GET_CONFIG, or we may use extra fd for communication to pass to child during forkIs that needed? I think it should be possible to create device-agnostic messages for config access.
VHOST_USER_INPUT_GET_CONFIGis quite virtio-input specific, since it returns the array ofvirtio_input_config, that is later read via virtio config selection. Can this be generalized?
Well, not as one-time init call. You have to forward every write access to the backend. For read access the easiest would be to forward every access too. Or have a shadow copy for read access which is updated after every write.
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
- when there is a whole set of messages to add, like the VHOST_GPU*, I decided to use a different socket, given to backend with
VHOST_USER_GPU_SET_SOCKET.I would tend to send it all over the same socket.
It's possible, but currently vhost-user protocol is unidirectional (master/slave request/reply relationship). The backend cannot easily send messages on its own. So beside reinventing some display protocol, it is hard to fit in vhost-user socket today.
Ok. So maybe it isn't that useful to use vhost-user for the gpu? The fundamental issue here is that qemu needs to process some of the messages. So you send those back to qemu via VHOST_GPU*.
So maybe it works better when we continue to terminate the rings in qemu, then forward messages relevant for virglrenderer to the external process.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am not sold that we need to develop a new vhost protocol for the gpu though. I am considering the Spice worker thread (handling cursor and display) to actually run in the vhost backend.
Quoted 8 lines
Quoted 3 lines
Interesting idea, would safe quite a few context switches for dma-buf passing. But it also brings new challenges, vga compatibility for example. Also spice channel management. vdagent, ...
What I had in mind is to hand off only the cursor and display channel to the vhost-gpu backend once the channel is up and the gpu is active. Eventually hand it back to qemu when switching back to VGA (sounds like it should be doable to me, but perhaps not worth it like this?)
It's not clear to me how you want hand over the display channel from qemu (and spice-server running as thread in qemu process context) to the vhost backend (running in a separate process).
cheers,
Gerd
Hi
----- Original Message -----
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
- the vhost-user-backend is a helper object spawning, setting up and holding a connection to a backend
- the vhost-user socket is set to be fd 3 in child processWhich implies a 1:1 relationship between object and backend. Which isn't that great if we want allow for multiple backends in one process (your idea below, and I think it can be useful).
Quoted 8 lines
Quoted 2 lines
That socket could use a different protocol to instantiate vhost-user device/backends (passing vhost-user sockets per device)?
I'd tend to simply hand the backend process one unix socket path per device. Maybe also allow libvirt to link things using monitor fd passing.
It's a little less automatic, but more flexible.
Having explicit socket path is closer to the current vhost-user-net approach:
-chardev socket,id=char0,path=/tmp/vubr.sock -netdev type=vhost-user,id=mynet1,chardev=char0
so we could have:
-chardev socket,id=char0,path=/tmp/vgpu.sock
-object vhost-user-backend,id=vug,chardev=char0
-device virtio-vga,virgl=true,vhost-user=vug
This is not incompatible with what I proposed, and I think that would be enough to allow libvirt to link things using monitor fd pass.
Other option is to hide vhost-user-backend object behind a property, and use chardev only:
-chardev socket,id=char0,path=/tmp/vgpu.sock
-device virtio-vga,virgl=true,vhost-user=char0
But I found it more convenient to allow qemu to manage the backend process, if only for development.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
- there are device specific vhost-user messages to be added, such as
VHOST_USER_INPUT_GET_CONFIG, or we may use extra fd for communication to pass to child during forkIs that needed? I think it should be possible to create device-agnostic messages for config access.
Quoted 8 lines
Quoted 3 lines
VHOST_USER_INPUT_GET_CONFIGis quite virtio-input specific, since it returns the array ofvirtio_input_config, that is later read via virtio config selection. Can this be generalized?Well, not as one-time init call. You have to forward every write access to the backend. For read access the easiest would be to forward every access too. Or have a shadow copy for read access which is updated after every write.
I see. But it would have to be explicit which device requires read/write config and which not, and many config details would have to be specified on backend side. So far, only input requires config data, gpu and net have "static" qemu side config.
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
- when there is a whole set of messages to add, like the VHOST_GPU*, I decided to use a different socket, given to backend with
VHOST_USER_GPU_SET_SOCKET.I would tend to send it all over the same socket.
It's possible, but currently vhost-user protocol is unidirectional (master/slave request/reply relationship). The backend cannot easily send messages on its own. So beside reinventing some display protocol, it is hard to fit in vhost-user socket today.
Quoted 7 lines
Ok. So maybe it isn't that useful to use vhost-user for the gpu? The fundamental issue here is that qemu needs to process some of the messages. So you send those back to qemu via VHOST_GPU*.
So maybe it works better when we continue to terminate the rings in qemu, then forward messages relevant for virglrenderer to the external process.
I would have to think about it, I am not sure how this would impact performance. I would rather teach vhost-user protocol to be bidirectionnal (and async), there would be benefits of doing that for the protocol in general (the graceful shutdown request would benefit such backend-side request support)
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
I am not sold that we need to develop a new vhost protocol for the gpu though. I am considering the Spice worker thread (handling cursor and display) to actually run in the vhost backend.
Interesting idea, would safe quite a few context switches for dma-buf passing. But it also brings new challenges, vga compatibility for example. Also spice channel management. vdagent, ...
Quoted 8 lines
Quoted 4 lines
What I had in mind is to hand off only the cursor and display channel to the vhost-gpu backend once the channel is up and the gpu is active. Eventually hand it back to qemu when switching back to VGA (sounds like it should be doable to me, but perhaps not worth it like this?)
It's not clear to me how you want hand over the display channel from qemu (and spice-server running as thread in qemu process context) to the vhost backend (running in a separate process).
10000ft view would be a qemu call like spice_qxl_steal(&state, &statesize, &fds, &nfds), that would gather all config and state related data and clients fds for cursor and display (qxl instance), and stop the worker thread. Then it would send this over to the backend, and resume a worker thread with a call like spice_qxl_resume(state, fds). The server is not ready for this sort of operations today though.