Skip to contentSkip to conversation

vhost-user for input & GPU

PATCH Superseded Marc-André Lureau 8 participants 52 messages Jun 18, 2018 – Jun 26, 2018

Subsystems (2)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v3 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.

Feedback welcome,

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 (26):
chardev: avoid crash if no associated address
chardev: remove qemu_chr_fe_write_all() counter
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
qio: add qio_channel_command_new_spawn_with_pre_exec() Add vhost-user-backend
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
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             |  167 +++
 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       |   48 +
 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/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                          |    6 +-
 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               |  189 ++++
 contrib/vhost-user-gpu/main.c              | 1100 ++++++++++++++++++++
 contrib/vhost-user-gpu/virgl.c             |  579 +++++++++++
 contrib/vhost-user-input/main.c            |  364 +++++++
 hw/block/vhost-user-blk.c                  |   22 +-
 hw/display/vhost-user-gpu-pci.c            |   51 +
 hw/display/vhost-user-gpu.c                |  488 +++++++++
 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                    |  367 ++-----
 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                     |    2 +-
 hw/virtio/vhost-user.c                     |  143 ++-
 hw/virtio/virtio-pci.c                     |   20 +
 io/channel-command.c                       |   33 +-
 net/vhost-user.c                           |    8 +-
 ui/egl-helpers.c                           |   51 +-
 ui/spice-display.c                         |    3 +-
 util/drm.c                                 |   66 ++
 vl.c                                       |    4 +-
 MAINTAINERS                                |   12 +-
 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.txt            |  236 +++++
 docs/interop/vhost-user.txt                |   15 +
 hw/display/Makefile.objs                   |    5 +-
 hw/input/Makefile.objs                     |    1 +
 util/Makefile.objs                         |    1 +
 60 files changed, 4871 insertions(+), 585 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.txt
Signature · 1 line
2.18.0.rc1
#1 lore raw

PATCH v3 1/26 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
index 159e69c3b1..2a33079f8e 100644
@@ -416,8 +416,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.rc1
Reviewed-by on v3 1/26
#2 lore raw

Re: [Qemu-devel] [PATCH v3 01/26] chardev: avoid crash if no associated address

Quoted 14 lines · Marc-André Lureau

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
Quoted 6 lines

Replace filename with a generic "disconnected:socket" in this case.

---
 chardev/char-socket.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 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 :|
#3 lore raw

PATCH v3 2/26 chardev: remove qemu_chr_fe_write_all() counter

In reply to 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.

---
 chardev/char-fe.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
chardev/char-fe.c +1 -5
index b1f228e8b5..f158f158f8 100644
@@ -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.rc1
Reviewed-by on v3 2/26
#4 lore raw

Re: [Qemu-devel] [PATCH v3 02/26] chardev: remove qemu_chr_fe_write_all() counter

Quoted 24 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.

---
 chardev/char-fe.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
chardev/char-fe.c +1 -1
index b1f228e8b5..f158f158f8 100644
@@ -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) {

chardev/char-fe.c int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) · line 93

Quoted 10 lines
chardev/char-fe.c +0 -4
@@ -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) {
#5 lore raw

Re: [Qemu-devel] [PATCH v3 02/26] chardev: remove qemu_chr_fe_write_all() counter

In reply to Marc-André Lureau
Quoted 14 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.

---
 chardev/char-fe.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
chardev/char-fe.c +0 -0
index b1f228e8b5..f158f158f8 100644

chardev/char-fe.c int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len) · line 60

Quoted 6 lines
chardev/char-fe.c +1 -1
@@ -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;

Subject says "qemu_char_fe_write_all()" but patch is changing qemu_chr_fe_read_all()...

thanks
-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH v3 02/26] chardev: remove qemu_chr_fe_write_all() counter

Quoted 10 lines · Peter Maydell
Quoted 8 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.

---
 chardev/char-fe.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
Quoted 15 lines

chardev/char-fe.c int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len) · line 60

Quoted 11 lines
chardev/char-fe.c +1 -1
index b1f228e8b5..f158f158f8 100644
@@ -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;

Subject says "qemu_char_fe_write_all()" but patch is changing qemu_chr_fe_read_all()...

indeed, fixed.
thanks

Signature · 1 line
Marc-André Lureau
#7 lore raw

PATCH v3 3/26 dmabuf: add y0_top, pass it to spice

In reply to Marc-André Lureau

Some scanouts during boot are top-down without this.

---
 include/ui/console.h | 1 +
 ui/spice-display.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/ui/console.h +1 -0
index 981b519dde..fb969caf70 100644
@@ -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
index fe734821dd..81f08a85bc 100644
@@ -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.rc1
#8 lore raw

Re: [Qemu-devel] [PATCH v3 03/26] dmabuf: add y0_top, pass it to spice

Quoted 13 lines · Marc-André Lureau

Some scanouts during boot are top-down without this.

---
 include/ui/console.h | 1 +
 ui/spice-display.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/ui/console.h +0 -0
index 981b519dde..fb969caf70 100644

include/ui/console.h struct QemuDmaBuf { · line 192

Quoted 7 lines
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 {

Looks incomplete, who sets y0_top?

Also: send the bugfixes (patches 1-6 ?) separate, so they can be merged already while the input + gpu details are hashed out?

cheers,
Gerd

#9 lore raw

Re: [Qemu-devel] [PATCH v3 03/26] dmabuf: add y0_top, pass it to spice

Hi

Quoted 20 lines · Gerd Hoffmann
Quoted 19 lines · Marc-André Lureau

Some scanouts during boot are top-down without this.

---
 include/ui/console.h | 1 +
 ui/spice-display.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/ui/console.h +1 -0
index 981b519dde..fb969caf70 100644
@@ -186,6 +186,7 @@ struct QemuDmaBuf {
     uint32_t  stride;
     uint32_t  fourcc;
     uint32_t  texture;
+    bool      y0_top;
 };
 
Quoted 6 lines

include/ui/console.h struct QemuDmaBuf { · line 192

Quoted 1 line
include/ui/console.h +0 -0
 typedef struct DisplayChangeListenerOps {

Looks incomplete, who sets y0_top?

Also: send the bugfixes (patches 1-6 ?) separate, so they can be merged already while the input + gpu details are hashed out?

That makes sending / managing seperate series more complicated. You need to reference some other series for reviewers, patchew etc,

It's easier if the first / reviewed patches of the series are picked. But that may involve separate maintainers, I'll ping some of them.

thanks

Signature · 1 line
Marc-André Lureau
#10 lore raw

Re: [Qemu-devel] [PATCH v3 03/26] dmabuf: add y0_top, pass it to spice

In reply to Gerd Hoffmann

Hi

Quoted 20 lines · Gerd Hoffmann
Quoted 19 lines · Marc-André Lureau

Some scanouts during boot are top-down without this.

---
 include/ui/console.h | 1 +
 ui/spice-display.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/ui/console.h +1 -0
index 981b519dde..fb969caf70 100644
@@ -186,6 +186,7 @@ struct QemuDmaBuf {
     uint32_t  stride;
     uint32_t  fourcc;
     uint32_t  texture;
+    bool      y0_top;
 };
 
Quoted 3 lines

include/ui/console.h struct QemuDmaBuf { · line 192

Quoted 1 line
include/ui/console.h +0 -0
 typedef struct DisplayChangeListenerOps {

Looks incomplete, who sets y0_top?

It is set from VHOST_USER_GPU_DMABUF_SCANOUT code path in the last patch.

In current qemu code base, only vfio/display uses dmabuf API. But the VFIO query interface doesn't provide or need that detail.

Signature · 1 line
Marc-André Lureau
#11 lore raw

PATCH v3 4/26 vhost-user: simplify vhost_user_init/vhost_user_cleanup

In reply to Marc-André Lureau

Take 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              |  2 +-
 hw/virtio/vhost-user.c              | 16 ++++++++++++----
 net/vhost-user.c                    |  8 ++++----
 9 files changed, 32 insertions(+), 60 deletions(-)
include/hw/virtio/vhost-user-blk.h +1 -1
index d52944aeeb..a8a106eecb 100644
@@ -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
index 3ec34ae867..7c22bdc957 100644
@@ -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
index fd660393a0..811e325f42 100644
@@ -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
index d52daccfcd..63573e211e 100644
@@ -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
index d755223643..5a2c6fe5f3 100644
@@ -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
index 9355cfdf07..b620725bc2 100644
@@ -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 +1 -1
index 049089b5e2..323dfcc46a 100644
@@ -7,7 +7,7 @@ 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;
 }
hw/virtio/vhost-user.c +12 -4
index b041343632..44795880d6 100644
@@ -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 -4
index a39f9c9974..5e5b8f3fc9 100644
@@ -291,14 +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();
+    user = g_new0(struct VhostUserState, 1);
     if (!user) {
         error_report("failed to init vhost_user");
         goto err;
@@ -312,11 +312,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.rc1
#12 lore raw

Re: [Qemu-devel] [PATCH v3 04/26] vhost-user: simplify vhost_user_init/vhost_user_cleanup

On Mon, Jun 18, 2018 at 06:17:07PM +0200, Marc-André Lureau wrote:
[...]

hw/virtio/vhost-stub.c bool vhost_has_free_slot(void) · line 12

Quoted 12 lines
hw/virtio/vhost-stub.c +1 -1
index 049089b5e2..323dfcc46a 100644
@@ -7,7 +7,7 @@ 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;

It would be better to return false.

Best regards,
Tiwei Bie

Quoted 1 line
hw/virtio/vhost-stub.c +0 -0
 }

[...]

#13 lore raw

Re: [Qemu-devel] [PATCH v3 04/26] vhost-user: simplify vhost_user_init/vhost_user_cleanup

Quoted 10 lines · Tiwei Bie

On Mon, Jun 18, 2018 at 06:17:07PM +0200, Marc-André Lureau wrote:
[...]

Quoted 8 lines
hw/virtio/vhost-stub.c +0 -0
index 049089b5e2..323dfcc46a 100644
@@ -7,7 +7,7 @@ bool vhost_has_free_slot(void)
     return true;
 }
 
Quoted 7 lines

hw/virtio/vhost-stub.c bool vhost_has_free_slot(void) · line 12

Quoted 4 lines
hw/virtio/vhost-stub.c +1 -1
-VhostUserState *vhost_user_init(void)
+bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp)
 {
     return NULL;

It would be better to return false.

Good catch, fixed.

Except that, would you give a reviewed-by?

Quoted 6 lines

Best regards,
Tiwei Bie

Quoted 1 line
hw/virtio/vhost-stub.c +0 -0
 }

[...]

Signature · 1 line
Marc-André Lureau
#14 lore raw

Re: [Qemu-devel] [PATCH v3 04/26] vhost-user: simplify vhost_user_init/vhost_user_cleanup

Quoted 19 lines · Marc-André Lureau
Quoted 10 lines · Tiwei Bie

On Mon, Jun 18, 2018 at 06:17:07PM +0200, Marc-André Lureau wrote:
[...]

Quoted 8 lines
hw/virtio/vhost-stub.c +0 -0
index 049089b5e2..323dfcc46a 100644
@@ -7,7 +7,7 @@ bool vhost_has_free_slot(void)
     return true;
 }
 
Quoted 7 lines

hw/virtio/vhost-stub.c bool vhost_has_free_slot(void) · line 12

Quoted 4 lines
hw/virtio/vhost-stub.c +1 -1
-VhostUserState *vhost_user_init(void)
+bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp)
 {
     return NULL;

It would be better to return false.

Quoted 3 lines

Good catch, fixed.

Except that, would you give a reviewed-by?

Sorry, I missed something previously. In below diff:

net/vhost-user.c +2 -2
index a39f9c9974..5e5b8f3fc9 100644
@@ -291,14 +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();
+    user = g_new0(struct VhostUserState, 1);
     if (!user) {
         error_report("failed to init vhost_user");
         goto err;

It might be better to change the error message
to something like:

"failed to allocate vhost-user state".

Except that, it looks good to me and you can add
my reviewed-by.

Best regards,
Tiwei Bie

Quoted 12 lines
Quoted 7 lines

Best regards,
Tiwei Bie

Quoted 1 line
hw/virtio/vhost-stub.c +0 -0
 }

[...]

Signature · 1 line
Marc-André Lureau
#15 lore raw

Re: [Qemu-devel] [PATCH v3 04/26] vhost-user: simplify vhost_user_init/vhost_user_cleanup

Hi

Quoted 48 lines · Tiwei Bie
Quoted 19 lines · Marc-André Lureau
Quoted 10 lines · Tiwei Bie

On Mon, Jun 18, 2018 at 06:17:07PM +0200, Marc-André Lureau wrote:
[...]

Quoted 8 lines
hw/virtio/vhost-stub.c +0 -0
index 049089b5e2..323dfcc46a 100644
@@ -7,7 +7,7 @@ bool vhost_has_free_slot(void)
     return true;
 }
 
Quoted 7 lines

hw/virtio/vhost-stub.c bool vhost_has_free_slot(void) · line 12

Quoted 4 lines
hw/virtio/vhost-stub.c +1 -1
-VhostUserState *vhost_user_init(void)
+bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp)
 {
     return NULL;

It would be better to return false.

Quoted 3 lines

Good catch, fixed.

Except that, would you give a reviewed-by?

Sorry, I missed something previously. In below diff:

net/vhost-user.c +2 -2
index a39f9c9974..5e5b8f3fc9 100644
@@ -291,14 +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();
+    user = g_new0(struct VhostUserState, 1);
     if (!user) {
         error_report("failed to init vhost_user");
         goto err;
Quoted 7 lines

It might be better to change the error message
to something like:

"failed to allocate vhost-user state".

Except that, it looks good to me and you can add
my reviewed-by.

Good point, g_new() aborts on failure, so we can simply remove the error report.

Thanks

Quoted 16 lines

Best regards,
Tiwei Bie

Quoted 12 lines
Quoted 7 lines

Best regards,
Tiwei Bie

Quoted 1 line
hw/virtio/vhost-stub.c +0 -0
 }

[...]

--
Marc-André Lureau

Signature · 1 line
Marc-André Lureau
#16 lore raw

PATCH v3 5/26 libvhost-user: exit by default on VHOST_USER_NONE

In reply to Marc-André Lureau

Since 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
index a6b46cdc03..41470daf57 100644
@@ -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.rc1
#17 lore raw

PATCH v3 6/26 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
index 44795880d6..5b4188bc27 100644
@@ -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.rc1
#18 lore raw

PATCH v3 7/26 qio: add qio_channel_command_new_spawn_with_pre_exec()

In reply to Marc-André Lureau

Add 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
index 336d47fa5c..96c833daab 100644
@@ -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
index 3e7eb17eff..05903ff194 100644
@@ -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.rc1
#19 lore raw

PATCH v3 8/26 Add vhost-user-backend

In reply to Marc-André Lureau

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. 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               | 257 ++++++++++++++++++++++++++++
 vl.c                                |   3 +-
 backends/Makefile.objs              |   3 +-
 4 files changed, 321 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
new file mode 100644
index 0000000000..60f811cae7
@@ -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 +257 -0

257 lines not on this page · raw message

vl.c +2 -1
index 6e34fb348d..1c21339ba7 100644
@@ -2718,7 +2718,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
backends/Makefile.objs +2 -1
index ad7c0325ed..1ffcf76bb1 100644
@@ -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
Signature · 1 line
2.18.0.rc1
#20 lore raw

Re: [Qemu-devel] [PATCH v3 08/26] Add vhost-user-backend

Hi

Quoted 230 lines · Marc-André Lureau

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. 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               | 257 ++++++++++++++++++++++++++++
 vl.c                                |   3 +-
 backends/Makefile.objs              |   3 +-
 4 files changed, 321 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
new file mode 100644
index 0000000000..60f811cae7
@@ -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 +140 -0
new file mode 100644
index 0000000000..db97037306
@@ -0,0 +1,257 @@
+/*
+ * 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.
+ */
+
+
+#include "qemu/osdep.h"
+#include "hw/qdev.h"
+#include "qapi/error.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/error-report.h"
+#include "qom/object_interfaces.h"
+#include "sysemu/vhost-user-backend.h"
+#include "sysemu/kvm.h"
+#include "io/channel-command.h"
+#include "hw/virtio/virtio-bus.h"
+
+static bool
+ioeventfd_enabled(void)
+{
+    return kvm_enabled() && kvm_eventfds_enabled();
+}
+
+int
+vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODevice *vdev,
+                            unsigned nvqs, Error **errp)
+{
+    int ret;
+
+    assert(!b->vdev && vdev);
+
+    if (!ioeventfd_enabled()) {
+        error_setg(errp, "vhost initialization failed: requires kvm");
+        return -1;
+    }
+
+    if (!vhost_user_init(&b->vhost_user, &b->chr, errp)) {
+        return -1;
+    }
+
+    b->vdev = vdev;
+    b->dev.nvqs = nvqs;
+    b->dev.vqs = g_new(struct vhost_virtqueue, nvqs);
+
+    ret = vhost_dev_init(&b->dev, &b->vhost_user, VHOST_BACKEND_TYPE_USER, 0);
+    if (ret < 0) {
+        error_setg_errno(errp, -ret, "vhost initialization failed");
+        return -1;
+    }
+
+    return 0;
+}
+
+void
+vhost_user_backend_start(VhostUserBackend *b)
+{
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(b->vdev)));
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+    int ret, i ;
+
+    if (b->started) {
+        return;
+    }
+
+    if (!k->set_guest_notifiers) {
+        error_report("binding does not support guest notifiers");
+        return;
+    }
+
+    ret = vhost_dev_enable_notifiers(&b->dev, b->vdev);
+    if (ret < 0) {
+        return;
+    }
+
+    ret = k->set_guest_notifiers(qbus->parent, b->dev.nvqs, true);
+    if (ret < 0) {
+        error_report("Error binding guest notifier");
+        goto err_host_notifiers;
+    }
+
+    b->dev.acked_features = b->vdev->guest_features;
+    ret = vhost_dev_start(&b->dev, b->vdev);
+    if (ret < 0) {
+        error_report("Error start vhost dev");
+        goto err_guest_notifiers;
+    }
+
+    /* guest_notifier_mask/pending not used yet, so just unmask
+     * everything here.  virtio-pci will do the right thing by
+     * enabling/disabling irqfd.
+     */
+    for (i = 0; i < b->dev.nvqs; i++) {
+        vhost_virtqueue_mask(&b->dev, b->vdev,
+                             b->dev.vq_index + i, false);
+    }
+
+    b->started = true;
+    return;
+
+err_guest_notifiers:
+    k->set_guest_notifiers(qbus->parent, b->dev.nvqs, false);
+err_host_notifiers:
+    vhost_dev_disable_notifiers(&b->dev, b->vdev);
+}
+
+void
+vhost_user_backend_stop(VhostUserBackend *b)
+{
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(b->vdev)));
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+    int ret = 0;
+
+    if (!b->started) {
+        return;
+    }
+
+    vhost_dev_stop(&b->dev, b->vdev);
+
+    if (k->set_guest_notifiers) {
+        ret = k->set_guest_notifiers(qbus->parent,
+                                     b->dev.nvqs, false);
+        if (ret < 0) {
+            error_report("vhost guest notifier cleanup failed: %d", ret);
+        }
+    }
+    assert(ret >= 0);
+
+    vhost_dev_disable_notifiers(&b->dev, b->vdev);
+    b->started = false;
+}
+
+static void
+pre_exec_cb(void *data)

backends/vhost-user.c line 150

Quoted 10 lines
backends/vhost-user.c new file +10 -0
+{
+    int *sv = data;
+    int maxfd = sysconf(_SC_OPEN_MAX);
+    int fd;
+
+    dup2(sv[1], 3);
+    for (fd = 4; fd < maxfd; fd++) {
+        close(fd);
+    }
+}

I moved that function to the next patch.

Added files to MAINTAINERS

Added help to qemu-options.hx

Quoted 139 lines
backends/vhost-user.c new file +107 -0
+
+static void
+vhost_user_backend_complete(UserCreatable *uc, Error **errp)
+{
+    VhostUserBackend *b = VHOST_USER_BACKEND(uc);
+    Chardev *chr;
+
+    if (!b->chr_name) {
+        error_setg(errp, "You must specificy 'chardev'.");
+        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 (!qemu_chr_fe_init(&b->chr, chr, errp)) {
+        return;
+    }
+
+    b->completed = true;
+    /* could vhost_dev_init() happen here, so early vhost-user message
+     * can be exchanged */
+}
+
+static void set_chardev(Object *obj, const char *value, Error **errp)
+{
+    VhostUserBackend *b = VHOST_USER_BACKEND(obj);
+
+    if (b->completed) {
+        error_setg(errp, QERR_PERMISSION_DENIED);
+    } else {
+        g_free(b->chr_name);
+        b->chr_name = g_strdup(value);
+    }
+}
+
+static char *get_chardev(Object *obj, Error **errp)
+{
+    VhostUserBackend *b = VHOST_USER_BACKEND(obj);
+    Chardev *chr = qemu_chr_fe_get_driver(&b->chr);
+
+    if (chr && chr->label) {
+        return g_strdup(chr->label);
+    }
+
+    return NULL;
+}
+
+static void vhost_user_backend_init(Object *obj)
+{
+    object_property_add_str(obj, "chardev", get_chardev, set_chardev, NULL);
+}
+
+static void vhost_user_backend_finalize(Object *obj)
+{
+    VhostUserBackend *b = VHOST_USER_BACKEND(obj);
+
+    g_free(b->dev.vqs);
+    g_free(b->chr_name);
+
+    vhost_user_cleanup(&b->vhost_user);
+    qemu_chr_fe_deinit(&b->chr, true);
+
+    if (b->child) {
+        object_unref(OBJECT(b->child));
+    }
+}
+
+static bool
+vhost_user_backend_can_be_deleted(UserCreatable *uc)
+{
+    return true;
+}
+
+static void
+vhost_user_backend_class_init(ObjectClass *oc, void *data)
+{
+    UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
+
+    ucc->complete = vhost_user_backend_complete;
+    ucc->can_be_deleted = vhost_user_backend_can_be_deleted;
+}
+
+static const TypeInfo vhost_user_backend_info = {
+    .name = TYPE_VHOST_USER_BACKEND,
+    .parent = TYPE_OBJECT,
+    .instance_size = sizeof(VhostUserBackend),
+    .instance_init = vhost_user_backend_init,
+    .instance_finalize = vhost_user_backend_finalize,
+    .class_size = sizeof(VhostUserBackendClass),
+    .class_init = vhost_user_backend_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_USER_CREATABLE },
+        { }
+    }
+};
+
+static void register_types(void)
+{
+    type_register_static(&vhost_user_backend_info);
+}
+
+type_init(register_types);
vl.c +2 -1
index 6e34fb348d..1c21339ba7 100644
@@ -2718,7 +2718,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
backends/Makefile.objs +2 -2
index ad7c0325ed..1ffcf76bb1 100644
@@ -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
--

2.18.0.rc1

Signature · 1 line
Marc-André Lureau
#21 lore raw

PATCH v3 9/26 HACK: vhost-user-backend: allow to specify binary to execute

In reply to 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.

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 | 83 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 73 insertions(+), 10 deletions(-)
backends/vhost-user.c +73 -10
index db97037306..32d3ec0e8b 100644
@@ -154,26 +154,87 @@ 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)
@@ -202,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);
 }
 
@@ -210,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);
Signature · 1 line
2.18.0.rc1
#22 lore raw

Re: [Qemu-devel] [PATCH v3 09/26] 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.

Hmm, maybe let the device which uses vhost-user-backend handle this?

So you use "-device vhost-user-input-pci,device=/dev/input/$dev" and vhost-user-input-pci translates that into ...

argv = { "$dir/vhost-user-input", "-device", "/dev/input/$dev", NULL }

... for vhost-user-backend ?

cheers,
Gerd

#23 lore raw

Re: [Qemu-devel] [PATCH v3 09/26] HACK: vhost-user-backend: allow to specify binary to execute

Quoted 9 lines · Gerd Hoffmann
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.

Quoted 8 lines

Hmm, maybe let the device which uses vhost-user-backend handle this?

So you use "-device vhost-user-input-pci,device=/dev/input/$dev" and vhost-user-input-pci translates that into ...

argv = { "$dir/vhost-user-input", "-device", "/dev/input/$dev", NULL }

... for vhost-user-backend ?

Or just accept the binary name, but mandate a pre-determined set of argv, in the same way we do for TAP device 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 :|
#24 lore raw

PATCH v3 10/26 vhost-user: split vhost_user_read()

In reply to Marc-André Lureau

Split 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
index 5b4188bc27..29f8568a13 100644
@@ -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.rc1
#25 lore raw

Re: [Qemu-devel] [PATCH v3 10/26] vhost-user: split vhost_user_read()

hw/virtio/vhost-user.c static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) · line 254

Quoted 6 lines
hw/virtio/vhost-user.c +1 -1
@@ -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;

Hmm? Looks like a pointless indirection ...

Quoted 6 lines
hw/virtio/vhost-user.c +0 -0
     }
 
     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."

hw/virtio/vhost-user.c static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) · line 257

Quoted 10 lines
hw/virtio/vhost-user.c +1 -4
                          " Read %d instead of %d.", r, msg->hdr.size);
-            goto fail;
+            return -1;
         }
     }
 
     return 0;
-
-fail:
-    return -1;

... if there is nothing to cleanup here.

cheers,
Gerd

#26 lore raw

Re: [Qemu-devel] [PATCH v3 10/26] vhost-user: split vhost_user_read()

Hi

Quoted 8 lines · Gerd Hoffmann

hw/virtio/vhost-user.c static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) · line 254

Quoted 6 lines
hw/virtio/vhost-user.c +1 -1
@@ -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;

Hmm? Looks like a pointless indirection ...

Isn't it removed by the patch? :)

Quoted 24 lines
Quoted 7 lines
hw/virtio/vhost-user.c +0 -0
     }
 
     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."

hw/virtio/vhost-user.c static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) · line 257

Quoted 10 lines
hw/virtio/vhost-user.c +1 -4
                          " Read %d instead of %d.", r, msg->hdr.size);
-            goto fail;
+            return -1;
         }
     }
 
     return 0;
-
-fail:
-    return -1;

... if there is nothing to cleanup here.

cheers,
Gerd

Signature · 1 line
Marc-André Lureau
#27 lore raw

Re: [Qemu-devel] [PATCH v3 10/26] vhost-user: split vhost_user_read()

Quoted 12 lines · Marc-André Lureau

Hi

Quoted 8 lines · Gerd Hoffmann

hw/virtio/vhost-user.c static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) · line 254

Quoted 6 lines
hw/virtio/vhost-user.c +1 -1
@@ -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;

Hmm? Looks like a pointless indirection ...

Quoted 1 line

Isn't it removed by the patch? :)

Ah, right. Sorry about the noise.

cheers,
Gerd

#28 lore raw

PATCH v3 11/26 vhost-user: add vhost_user_input_get_config()

In reply to Marc-André Lureau

Ask vhost user input backend the list of virtio_input_config.

---
 include/hw/virtio/vhost-backend.h |  4 +++
 hw/virtio/vhost-user.c            | 59 +++++++++++++++++++++++++++++++
 docs/interop/vhost-user.txt       |  7 ++++
 3 files changed, 70 insertions(+)
include/hw/virtio/vhost-backend.h +4 -0
index 81283ec50f..1fca321d8a 100644
@@ -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
index d51fd58242..2efa44d124 100644
@@ -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: TBD
+      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.rc1
#29 lore raw

PATCH v3 12/26 libvhost-user: export vug_source_new()

In reply to Marc-André Lureau

Simplify 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
index 6b2110b94c..d3200f3afc 100644
@@ -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
index 545f089587..0e2c467f28 100644
@@ -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.rc1
#30 lore raw

PATCH v3 13/26 contrib: add vhost-user-input

In reply to Marc-André Lureau

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"

---
 contrib/libvhost-user/libvhost-user.h  |   1 +
 contrib/vhost-user-input/main.c        | 364 +++++++++++++++++++++++++
 Makefile                               |   3 +
 Makefile.objs                          |   1 +
 configure                              |   3 +
 contrib/vhost-user-input/Makefile.objs |   1 +
 6 files changed, 373 insertions(+)
 create mode 100644 contrib/vhost-user-input/main.c
 create mode 100644 contrib/vhost-user-input/Makefile.objs
contrib/libvhost-user/libvhost-user.h +1 -0
index 4aa55b4d2d..40d7cbfc2a 100644
@@ -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,
     VHOST_USER_MAX
 } VhostUserRequest;
 
contrib/vhost-user-input/main.c new file +364 -0

364 lines not on this page · raw message

Makefile +3 -0
index e46f2b625a..1d4d9441b1 100644
@@ -421,6 +421,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 \
@@ -719,6 +720,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
index 7a9828da28..b0f48d667c 100644
@@ -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
index a8c4094c87..28aef55d06 100755
@@ -5551,6 +5551,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
new file mode 100644
index 0000000000..b1fad90d51
@@ -0,0 +1 @@
+vhost-user-input-obj-y = main.o
Signature · 1 line
2.18.0.rc1
#31 lore raw

PATCH v3 14/26 Add vhost-user-input-pci

In reply to Marc-André Lureau

Add a new virtio-input device, which connects to a vhost-user backend. Usage:

-object vhost-user-backend,id=vuid -device vhost-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
index 813082b0d7..c7e28e1b9c 100644
@@ -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
index 054c38836f..4fca03e796 100644
@@ -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
index 3a01fe90f0..6bb0575257 100644
@@ -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
index 0fb5f38f9f..773624f095 100644
@@ -1206,6 +1206,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
 
hw/input/Makefile.objs +1 -0
index c8b00f71ec..6adc308cdd 100644
@@ -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.rc1
#32 lore raw

Re: [Qemu-devel] [PATCH v3 14/26] Add vhost-user-input-pci

MAINTAINERS L: [email protected] · line 1207

Quoted 5 lines
MAINTAINERS +0 -0
@@ -1206,6 +1206,7 @@ L: [email protected]
 virtio-input
 M: Gerd Hoffmann <[email protected]>

R: Marc-André Lureau <[email protected]>

(or a separate vhost-input-user entry)

MAINTAINERS L: [email protected] · line 1209

Quoted 2 lines
MAINTAINERS +1 -0
 S: Maintained
+F: hw/input/vhost-user-input.c

F: contrib/vhost-user-input/*

MAINTAINERS L: [email protected] · line 1211

Quoted 2 lines
MAINTAINERS +0 -0
 F: hw/input/virtio-input*.c
 F: include/hw/virtio/virtio-input.h

cheers,
Gerd

#33 lore raw

PATCH v3 15/26 vhost-user: add vhost_user_gpu_set_socket()

In reply to Marc-André Lureau

Add a new vhost-user message to give a unix socket for gpu updates to a vhost-user backend.

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 and may not need the same kind of stability guarantees, thus I chose to have a new dedicated channel.

---
 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.txt       | 236 ++++++++++++++++++++++++++
 docs/interop/vhost-user.txt           |   8 +
 6 files changed, 263 insertions(+)
 create mode 100644 docs/interop/vhost-user-gpu.txt
contrib/libvhost-user/libvhost-user.h +1 -0
index 40d7cbfc2a..9899bfda9e 100644
@@ -92,6 +92,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_POSTCOPY_LISTEN  = 29,
     VHOST_USER_POSTCOPY_END     = 30,
     VHOST_USER_INPUT_GET_CONFIG,
+    VHOST_USER_GPU_SET_SOCKET,
     VHOST_USER_MAX
 } VhostUserRequest;
 
include/hw/virtio/vhost-backend.h +1 -0
index 1fca321d8a..daf9180c33 100644
@@ -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
index cbd2900f39..37864bc06a 100644
@@ -90,6 +90,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_POSTCOPY_LISTEN  = 29,
     VHOST_USER_POSTCOPY_END     = 30,
     VHOST_USER_INPUT_GET_CONFIG,
+    VHOST_USER_GPU_SET_SOCKET,
     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
index 773624f095..e5dee15967 100644
@@ -1339,6 +1339,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.txt
+
 Cirrus VGA
 M: Gerd Hoffmann <[email protected]>
 S: Odd Fixes
docs/interop/vhost-user-gpu.txt new file +236 -0

236 lines not on this page · raw message

docs/interop/vhost-user.txt +8 -0
index 2efa44d124..40ba89675c 100644
@@ -768,6 +768,14 @@ Master message types
 
       Ask vhost user input backend the list of virtio_input_config.
 
+ * VHOST_USER_GPU_SET_SOCKET
+      Id: TBD
+      Master 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.txt for details.
+
 Slave message types
 -------------------
 
Signature · 1 line
2.18.0.rc1
#34 lore raw

PATCH v3 16/26 vhost-user: add vhost_user_gpu_get_num_capsets()

In reply to Marc-André Lureau
---
 contrib/libvhost-user/libvhost-user.h |  1 +
 include/hw/virtio/vhost-backend.h     |  1 +
 hw/virtio/vhost-user.c                | 15 +++++++++++++++
 3 files changed, 17 insertions(+)
contrib/libvhost-user/libvhost-user.h +1 -0
index 9899bfda9e..b572071d61 100644
@@ -93,6 +93,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_POSTCOPY_END     = 30,
     VHOST_USER_INPUT_GET_CONFIG,
     VHOST_USER_GPU_SET_SOCKET,
+    VHOST_USER_GPU_GET_NUM_CAPSETS,
     VHOST_USER_MAX
 } VhostUserRequest;
 
include/hw/virtio/vhost-backend.h +1 -0
index daf9180c33..730e24c33b 100644
@@ -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
index 37864bc06a..8702027269 100644
@@ -91,6 +91,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_POSTCOPY_END     = 30,
     VHOST_USER_INPUT_GET_CONFIG,
     VHOST_USER_GPU_SET_SOCKET,
+    VHOST_USER_GPU_GET_NUM_CAPSETS,
     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 > UINT32_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);
Signature · 1 line
2.18.0.rc1
#35 lore raw

PATCH v3 17/26 virtio: add virtio-gpu bswap helpers header

In reply to Marc-André Lureau
---
 include/hw/virtio/virtio-gpu-bswap.h | 48 ++++++++++++++++++++++++++++
 hw/display/virtio-gpu.c              | 43 +------------------------
 2 files changed, 49 insertions(+), 42 deletions(-)
 create mode 100644 include/hw/virtio/virtio-gpu-bswap.h
include/hw/virtio/virtio-gpu-bswap.h new file +48 -0
new file mode 100644
index 0000000000..bc9e895f9c
@@ -0,0 +1,48 @@
+#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.rc1
#36 lore raw

PATCH v3 18/26 util: promote qemu_egl_rendernode_open() to libqemuutil

In reply to Marc-André Lureau

vhost-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
new file mode 100644
index 0000000000..4c3e622f5c
@@ -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
index e5dee15967..42a5d46acd 100644
@@ -1533,6 +1533,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
index e1c3fed4dc..1810f970ef 100644
@@ -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.rc1
#37 lore raw

PATCH v3 19/26 contrib: add vhost-user-gpu

In reply to Marc-André Lureau

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"

TODO:
- add/check multi-head support
- stop/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       |  167 ++++
 contrib/vhost-user-gpu/drm.c         |  189 +++++
 contrib/vhost-user-gpu/main.c        | 1100 ++++++++++++++++++++++++++
 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, 2171 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
new file mode 100644
index 0000000000..ee95816cc9
@@ -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
new file mode 100644
index 0000000000..f952bc9d4f
@@ -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 +167 -0

167 lines not on this page · raw message

contrib/vhost-user-gpu/drm.c new file +189 -0

189 lines not on this page · raw message

contrib/vhost-user-gpu/main.c new file +1100 -0

1,100 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
index 42a5d46acd..5dc312f7de 100644
@@ -1344,6 +1344,8 @@ M: Marc-André Lureau <[email protected]>
 M: Gerd Hoffmann <[email protected]>
 S: Maintained
 F: docs/interop/vhost-user-gpu.txt
+F: contrib/vhost-user-gpu
+F: hw/display/vhost-user-*
 
 Cirrus VGA
 M: Gerd Hoffmann <[email protected]>
Makefile +3 -0
index 1d4d9441b1..5c42e8897e 100644
@@ -422,6 +422,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 \
@@ -722,6 +723,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
index b0f48d667c..a8789a165e 100644
@@ -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
index 28aef55d06..cab6edd35b 100755
@@ -3815,6 +3815,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 libdrm gbm"
   if $pkg_config $opengl_pkgs; then
@@ -5554,6 +5568,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
@@ -6420,6 +6437,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
@@ -7169,6 +7198,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 [ "$fdt" = "git" ]; then
   echo "config-host.h: subdir-dtc" >> $config_host_mak
 fi
contrib/vhost-user-gpu/Makefile.objs new file +10 -0
new file mode 100644
index 0000000000..4da8c09cbb
@@ -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.rc1
#38 lore raw

PATCH v3 20/26 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
index d6ba61f2f1..6cb13d2711 100644
@@ -102,7 +102,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
index 6a55416be7..7f7e18c2ee 100644
@@ -1192,7 +1192,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.rc1
#39 lore raw

PATCH v3 21/26 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
index 6cb13d2711..1cf8ec1aa8 100644
@@ -101,8 +101,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
index 7f7e18c2ee..cd48a928ca 100644
@@ -1162,10 +1162,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.rc1
#40 lore raw

PATCH v3 22/26 virtio-gpu: block both 2d and 3d rendering

In reply to Marc-André Lureau

Now 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
index 1cf8ec1aa8..fb74fba4a9 100644
@@ -171,7 +171,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
index 3558f38fe8..6fee0e8582 100644
@@ -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
index cd48a928ca..48b3e0ceaa 100644
@@ -813,12 +813,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++;
@@ -954,6 +957,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.rc1
#41 lore raw

PATCH v3 23/26 virtio-gpu: remove useless 'waiting' field

In reply to Marc-André Lureau

Let'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
index fb74fba4a9..5b19b0d9d4 100644
@@ -86,7 +86,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
index 48b3e0ceaa..37055926d3 100644
@@ -813,8 +813,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;
         }
 
@@ -863,7 +862,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.rc1
#42 lore raw

PATCH v3 24/26 virtio-gpu: split virtio-gpu, introduce virtio-gpu-base

In reply to Marc-André Lureau

Add a base class that is common to virtio-gpu and vhost-user-gpu devices.

---
 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        | 331 ++++++---------------------------
 hw/display/virtio-vga.c        |  15 +-
 hw/display/Makefile.objs       |   2 +-
 7 files changed, 446 insertions(+), 317 deletions(-)
 create mode 100644 hw/display/virtio-gpu-base.c
include/hw/virtio/virtio-gpu.h +55 -17
index 5b19b0d9d4..4a17000ce4 100644
@@ -27,6 +27,14 @@
 #define VIRTIO_GPU_CAPSET_VIRGL2 2
 #endif
 
+#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)
@@ -63,7 +71,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,
 };
@@ -73,8 +81,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;
@@ -90,31 +97,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;
 
@@ -125,8 +154,6 @@ typedef struct VirtIOGPU {
         uint32_t req_3d;
         uint32_t bytes_3d;
     } stats;
-
-    Error *migration_blocker;
 } VirtIOGPU;
 
 extern const GraphicHwOps virtio_gpu_ops;
@@ -149,6 +176,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,
@@ -172,4 +209,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
index cece4aa495..741badd909 100644
@@ -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 +61 -270

554 lines not on this page · raw message

hw/display/virtio-vga.c +10 -5
index baa74ba82c..98388762f6 100644
@@ -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
index b5d97ab26d..d1d2711475 100644
@@ -36,7 +36,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.rc1
#43 lore raw

Re: [Qemu-devel] [PATCH v3 24/26] virtio-gpu: split virtio-gpu, introduce virtio-gpu-base

Quoted 2 lines · Marc-André Lureau

Add a base class that is common to virtio-gpu and vhost-user-gpu devices.

More verbose commit message please. What functionality is common and handled by the new (abstract?) base class? (same for patch #25).

cheers,
Gerd

#44 lore raw

Re: [Qemu-devel] [PATCH v3 24/26] virtio-gpu: split virtio-gpu, introduce virtio-gpu-base

Hi

Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · Marc-André Lureau

Add a base class that is common to virtio-gpu and vhost-user-gpu devices.

More verbose commit message please. What functionality is common and handled by the new (abstract?) base class? (same for patch #25).

Would that level of details be enough?

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.

thanks

#45 lore raw

Re: [Qemu-devel] [PATCH v3 24/26] virtio-gpu: split virtio-gpu, introduce virtio-gpu-base

Quoted 24 lines · Marc-André Lureau

Hi

Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · Marc-André Lureau

Add a base class that is common to virtio-gpu and vhost-user-gpu devices.

More verbose commit message please. What functionality is common and handled by the new (abstract?) base class? (same for patch #25).

Would that level of details be enough?

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)

Quoted 2 lines

What is left to the virtio-gpu subdevice to take care of, in short, are all the virtio queues handling, command processing and migration.

Looks good.

cheers,
Gerd

#46 lore raw

PATCH v3 25/26 virtio-gpu: split virtio-gpu-pci & virtio-vga

In reply to Marc-André Lureau

Add 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
new file mode 100644
index 0000000000..212624449c
@@ -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
index c7e28e1b9c..42240f47b3 100644
@@ -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
index 741badd909..5db6ad890d 100644
@@ -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
index 5dc312f7de..c958fff474 100644
@@ -1336,7 +1336,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.rc1
#47 lore raw

Re: [Qemu-devel] [PATCH v3 25/26] virtio-gpu: split virtio-gpu-pci & virtio-vga

Hi

Quoted 3 lines · Marc-André Lureau

Add base classes that are common to vhost-user-gpu-pci and vhost-user-vga.

Here is a bit more details on the base class split:

Both virtio-gpu-pci and virtio-vga are inheriting from virtio-pci. vhost-user-gpu devices will share very similar setup and integration with qemu than virtio-gpu, except that the virtio backend differs (VhostUserGPU vs VirtIOGPU), and vhost-user-gpu devices take an extra "vhost-user" property (aliased to the backend property).

Extract virtio-gpu-pci-base and virtio-vga-base classes, they are inherited by the respective virtio & vhost-user devices with the few differences mentionned.

Quoted 414 lines
---
 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
new file mode 100644
index 0000000000..212624449c
@@ -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
index c7e28e1b9c..42240f47b3 100644
@@ -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
index 741badd909..5db6ad890d 100644
@@ -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
index 98388762f6..0c503460af 100644
@@ -1,56 +1,41 @@
 #include "qemu/osdep.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
-#include "vga_int.h"
-#include "hw/virtio/virtio-pci.h"
 #include "qapi/error.h"
+#include "virtio-vga.h"
 
-/*
- * virtio-vga: This extends VirtioPCIProxy.
- */
-#define TYPE_VIRTIO_VGA "virtio-vga"
-#define VIRTIO_VGA(obj) \
-        OBJECT_CHECK(VirtIOVGA, (obj), TYPE_VIRTIO_VGA)
-
-typedef struct VirtIOVGA {
-    VirtIOPCIProxy parent_obj;
-    VirtIOGPU      vdev;
-    VGACommonState vga;
-    MemoryRegion   vga_mrs[3];
-} VirtIOVGA;
-
-static void virtio_vga_invalidate_display(void *opaque)
+static void virtio_vga_base_invalidate_display(void *opaque)
 {
-    VirtIOVGA *vvga = opaque;
-    VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
 
     if (g->enable) {
-        virtio_gpu_ops.invalidate(&vvga->vdev);
+        virtio_gpu_ops.invalidate(g);
     } else {
         vvga->vga.hw_ops->invalidate(&vvga->vga);
     }
 }
 
-static void virtio_vga_update_display(void *opaque)
+static void virtio_vga_base_update_display(void *opaque)
 {
-    VirtIOVGA *vvga = opaque;
-    VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
 
     if (g->enable) {
-        virtio_gpu_ops.gfx_update(&vvga->vdev);
+        virtio_gpu_ops.gfx_update(g);
     } else {
         vvga->vga.hw_ops->gfx_update(&vvga->vga);
     }
 }
 
-static void virtio_vga_text_update(void *opaque, console_ch_t *chardata)
+static void virtio_vga_base_text_update(void *opaque, console_ch_t *chardata)
 {
-    VirtIOVGA *vvga = opaque;
-    VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
 
     if (g->enable) {
         if (virtio_gpu_ops.text_update) {
-            virtio_gpu_ops.text_update(&vvga->vdev, chardata);
+            virtio_gpu_ops.text_update(g, chardata);
         }
     } else {
         if (vvga->vga.hw_ops->text_update) {
@@ -59,49 +44,52 @@ static void virtio_vga_text_update(void *opaque, console_ch_t *chardata)
     }
 }
 
-static int virtio_vga_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
+static int virtio_vga_base_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
 {
-    VirtIOVGA *vvga = opaque;
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
 
     if (virtio_gpu_ops.ui_info) {
-        return virtio_gpu_ops.ui_info(&vvga->vdev, idx, info);
+        return virtio_gpu_ops.ui_info(g, idx, info);
     }
     return -1;
 }
 
-static void virtio_vga_gl_block(void *opaque, bool block)
+static void virtio_vga_base_gl_block(void *opaque, bool block)
 {
-    VirtIOVGA *vvga = opaque;
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
 
     if (virtio_gpu_ops.gl_block) {
-        virtio_gpu_ops.gl_block(&vvga->vdev, block);
+        virtio_gpu_ops.gl_block(g, block);
     }
 }
 
-static const GraphicHwOps virtio_vga_ops = {
-    .invalidate = virtio_vga_invalidate_display,
-    .gfx_update = virtio_vga_update_display,
-    .text_update = virtio_vga_text_update,
-    .ui_info = virtio_vga_ui_info,
-    .gl_block = virtio_vga_gl_block,
+static const GraphicHwOps virtio_vga_base_ops = {
+    .invalidate = virtio_vga_base_invalidate_display,
+    .gfx_update = virtio_vga_base_update_display,
+    .text_update = virtio_vga_base_text_update,
+    .ui_info = virtio_vga_base_ui_info,
+    .gl_block = virtio_vga_base_gl_block,
 };
 
-static const VMStateDescription vmstate_virtio_vga = {
+static const VMStateDescription vmstate_virtio_vga_base = {
     .name = "virtio-vga",
     .version_id = 2,
     .minimum_version_id = 2,
     .fields = (VMStateField[]) {
         /* no pci stuff here, saving the virtio device will handle that */
-        VMSTATE_STRUCT(vga, VirtIOVGA, 0, vmstate_vga_common, VGACommonState),
+        VMSTATE_STRUCT(vga, VirtIOVGABase, 0,
+                       vmstate_vga_common, VGACommonState),
         VMSTATE_END_OF_LIST()
     }
 };
 
 /* VGA device wrapper around PCI device around virtio GPU */
-static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
 {
-    VirtIOVGA *vvga = VIRTIO_VGA(vpci_dev);
-    VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+    VirtIOVGABase *vvga = VIRTIO_VGA_BASE(vpci_dev);
+    VirtIOGPUBase *g = vvga->vgpu;
     VGACommonState *vga = &vvga->vga;
     Error *err = NULL;
     uint32_t offset;
@@ -159,7 +147,7 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
                                  vvga->vga_mrs, true);
 
     vga->con = g->scanout[0].con;
-    graphic_console_set_hwops(vga->con, &virtio_vga_ops, vvga);
+    graphic_console_set_hwops(vga->con, &virtio_vga_base_ops, vvga);
 
     for (i = 0; i < g->conf.max_outputs; i++) {
         object_property_set_link(OBJECT(g->scanout[i].con),
@@ -168,56 +156,76 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     }
 }
 
-static void virtio_vga_reset(DeviceState *dev)
+static void virtio_vga_base_reset(DeviceState *dev)
 {
-    VirtIOVGA *vvga = VIRTIO_VGA(dev);
-    VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+    VirtIOVGABase *vvga = VIRTIO_VGA_BASE(dev);
+    VirtIOGPUBase *g = vvga->vgpu;
 
     g->enable = 0;
 
     vga_dirty_log_start(&vvga->vga);
 }
 
-static Property virtio_vga_properties[] = {
+static Property virtio_vga_base_properties[] = {
     DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void virtio_vga_class_init(ObjectClass *klass, void *data)
+static void virtio_vga_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_vga_properties;
-    dc->reset = virtio_vga_reset;
-    dc->vmsd = &vmstate_virtio_vga;
+    dc->props = virtio_vga_base_properties;
+    dc->reset = virtio_vga_base_reset;
+    dc->vmsd = &vmstate_virtio_vga_base;
     dc->hotpluggable = false;
 
-    k->realize = virtio_vga_realize;
+    k->realize = virtio_vga_base_realize;
     pcidev_k->romfile = "vgabios-virtio.bin";
     pcidev_k->class_id = PCI_CLASS_DISPLAY_VGA;
 }
 
+static TypeInfo virtio_vga_base_info = {
+    .name          = TYPE_VIRTIO_VGA_BASE,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(struct VirtIOVGABase),
+    .class_init    = virtio_vga_base_class_init,
+    .abstract      = true,
+};
+
+#define TYPE_VIRTIO_VGA "virtio-vga"
+
+#define VIRTIO_VGA(obj)                             \
+    OBJECT_CHECK(VirtIOVGA, (obj), TYPE_VIRTIO_VGA)
+
+typedef struct VirtIOVGA {
+    VirtIOVGABase parent_obj;
+
+    VirtIOGPU     vdev;
+} VirtIOVGA;
+
 static void virtio_vga_inst_initfn(Object *obj)
 {
     VirtIOVGA *dev = VIRTIO_VGA(obj);
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_GPU);
+    VIRTIO_VGA_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
 }
 
 static TypeInfo virtio_vga_info = {
     .name          = TYPE_VIRTIO_VGA,
-    .parent        = TYPE_VIRTIO_PCI,
+    .parent        = TYPE_VIRTIO_VGA_BASE,
     .instance_size = sizeof(struct VirtIOVGA),
     .instance_init = virtio_vga_inst_initfn,
-    .class_init    = virtio_vga_class_init,
 };
 
 static void virtio_vga_register_types(void)
 {
+    type_register_static(&virtio_vga_base_info);
     type_register_static(&virtio_vga_info);
 }
 
MAINTAINERS +1 -2
index 5dc312f7de..c958fff474 100644
@@ -1336,7 +1336,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
--

2.18.0.rc1

#48 lore raw

PATCH v3 26/26 hw/display: add vhost-user-vga & gpu-pci

In reply to 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:
-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     | 488 ++++++++++++++++++++++++++++++++
 hw/display/vhost-user-vga.c     |  52 ++++
 vl.c                            |   1 +
 hw/display/Makefile.objs        |   3 +
 7 files changed, 609 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
index 42240f47b3..ec8eeb2a93 100644
@@ -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
index 4a17000ce4..c5648d426a 100644
@@ -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"
 
@@ -39,6 +40,8 @@
 #define VIRTIO_GPU(obj)                                        \
         OBJECT_CHECK(VirtIOGPU, (obj), TYPE_VIRTIO_GPU)
 
+#define TYPE_VHOST_USER_GPU "vhost-user-gpu"
+
 #define VIRTIO_ID_GPU 16
 
 struct virtio_gpu_simple_resource {
@@ -156,6 +159,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 +488 -0

488 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
index 1c21339ba7..3f620f56a7 100644
@@ -235,6 +235,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
index d1d2711475..a98328d692 100644
@@ -37,8 +37,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.rc1
#49 lore raw

Re: [Qemu-devel] [PATCH v3 26/26] hw/display: add vhost-user-vga & gpu-pci

Hi,

hw/display/vhost-user-gpu.c line 32

Quoted 4 lines
hw/display/vhost-user-gpu.c new file +4 -0
+    VHOST_USER_GPU_SCANOUT,
+    VHOST_USER_GPU_UPDATE,
+    VHOST_USER_GPU_DMABUF_SCANOUT,
+    VHOST_USER_GPU_DMABUF_UPDATE,

Hmm, still two command versions.

I still think there should be no separate 2d code path. Just put the 2d display updates into a texture, or into a drm buffer, then use VHOST_USER_GPU_DMABUF_* for both 2d and 3d updates (see also ui/console-gl.c, which does basically the same).

cheers,
Gerd

#50 lore raw

Re: [Qemu-devel] [PATCH v3 26/26] hw/display: add vhost-user-vga & gpu-pci

Hi

Quoted 7 lines · Gerd Hoffmann

Hi,

hw/display/vhost-user-gpu.c line 32

Quoted 4 lines
hw/display/vhost-user-gpu.c new file +4 -0
+    VHOST_USER_GPU_SCANOUT,
+    VHOST_USER_GPU_UPDATE,
+    VHOST_USER_GPU_DMABUF_SCANOUT,
+    VHOST_USER_GPU_DMABUF_UPDATE,
Quoted 6 lines

Hmm, still two command versions.

I still think there should be no separate 2d code path. Just put the 2d display updates into a texture, or into a drm buffer, then use VHOST_USER_GPU_DMABUF_* for both 2d and 3d updates (see also ui/console-gl.c, which does basically the same).

It will use DMABUF for both 2d and 3d, unless it's not capable of doing it (currently only intel gpu). So the regular scanout/update are fallback. They share a lot of similarities.

Signature · 1 line
Marc-André Lureau
#51 lore raw
In reply to Marc-André Lureau
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v3 00/26] vhost-user for input & GPU

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
5b9f38a1ca hw/display: add vhost-user-vga & gpu-pci 326428ad0c virtio-gpu: split virtio-gpu-pci & virtio-vga 875a640573 virtio-gpu: split virtio-gpu, introduce virtio-gpu-base 30f670795b virtio-gpu: remove useless 'waiting' field 8b62eaebc8 virtio-gpu: block both 2d and 3d rendering 099eb18894 virtio-gpu: remove unused config_size
c7ebfdac23 virtio-gpu: remove unused qdev
bcbc153a12 contrib: add vhost-user-gpu
287104e286 util: promote qemu_egl_rendernode_open() to libqemuutil 1734608225 virtio: add virtio-gpu bswap helpers header fe8a420d35 vhost-user: add vhost_user_gpu_get_num_capsets() 106d9b6c82 vhost-user: add vhost_user_gpu_set_socket() 73ac986cce Add vhost-user-input-pci
7b3ced4f9e contrib: add vhost-user-input
6285d76ff7 libvhost-user: export vug_source_new()
901a25da6d vhost-user: add vhost_user_input_get_config() 7d0d590b7f vhost-user: split vhost_user_read()
a9bdc75110 HACK: vhost-user-backend: allow to specify binary to execute c228612ab8 Add vhost-user-backend
0617a84bf3 qio: add qio_channel_command_new_spawn_with_pre_exec() 07bff83cac vhost-user: wrap some read/write with retry handling a836d90351 libvhost-user: exit by default on VHOST_USER_NONE fc54036235 vhost-user: simplify vhost_user_init/vhost_user_cleanup 9438a02db7 dmabuf: add y0_top, pass it to spice
9074228c84 chardev: remove qemu_chr_fe_write_all() counter 58f6db3fb0 chardev: avoid crash if no associated address

=== OUTPUT BEGIN ===
Checking PATCH 1/26: chardev: avoid crash if no associated address... Checking PATCH 2/26: chardev: remove qemu_chr_fe_write_all() counter... Checking PATCH 3/26: dmabuf: add y0_top, pass it to spice... Checking PATCH 4/26: vhost-user: simplify vhost_user_init/vhost_user_cleanup... Checking PATCH 5/26: libvhost-user: exit by default on VHOST_USER_NONE... Checking PATCH 6/26: vhost-user: wrap some read/write with retry handling... Checking PATCH 7/26: qio: add qio_channel_command_new_spawn_with_pre_exec()... Checking PATCH 8/26: Add vhost-user-backend...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #35:
new file mode 100644

total: 0 errors, 1 warnings, 335 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 9/26: HACK: vhost-user-backend: allow to specify binary to execute... Checking PATCH 10/26: vhost-user: split vhost_user_read()...
Checking PATCH 11/26: vhost-user: add vhost_user_input_get_config()... Checking PATCH 12/26: libvhost-user: export vug_source_new()... Checking PATCH 13/26: contrib: add vhost-user-input...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #78:
new file mode 100644

total: 0 errors, 1 warnings, 403 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 14/26: Add vhost-user-input-pci...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #42:
new file mode 100644

total: 0 errors, 1 warnings, 215 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 15/26: vhost-user: add vhost_user_gpu_set_socket()...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #52:
new file mode 100644

total: 0 errors, 1 warnings, 298 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 16/26: vhost-user: add vhost_user_gpu_get_num_capsets()... Checking PATCH 17/26: virtio: add virtio-gpu bswap helpers header...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #74:
new file mode 100644

total: 0 errors, 1 warnings, 103 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 18/26: util: promote qemu_egl_rendernode_open() to libqemuutil...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #27:
new file mode 100644

total: 0 errors, 1 warnings, 151 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 19/26: contrib: add vhost-user-gpu...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #133:
new file mode 100644

total: 0 errors, 1 warnings, 2219 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 20/26: virtio-gpu: remove unused qdev...
Checking PATCH 21/26: virtio-gpu: remove unused config_size... Checking PATCH 22/26: virtio-gpu: block both 2d and 3d rendering... Checking PATCH 23/26: virtio-gpu: remove useless 'waiting' field... Checking PATCH 24/26: virtio-gpu: split virtio-gpu, introduce virtio-gpu-base...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #175:
new file mode 100644

ERROR: Macros with complex values should be enclosed in parenthesis #1196: FILE: include/hw/virtio/virtio-gpu.h:124:

+#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)

total: 1 errors, 1 warnings, 1143 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 25/26: virtio-gpu: split virtio-gpu-pci & virtio-vga...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #358:
new file mode 100644

total: 0 errors, 1 warnings, 373 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 26/26: hw/display: add vhost-user-vga & gpu-pci...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #37:
new file mode 100644

total: 0 errors, 1 warnings, 647 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]