Enable vhost-user to be used on BSD systems
Subsystems (2)
v4 cover Enable vhost-user to be used on BSD systems
Since QEMU is already able to emulate ioeventfd using pipefd, we're already pretty close to supporting vhost-user on non-Linux systems.
This two patches bridge the gap by:
1. Adding a new event_notifier_get_wfd() to return wfd on the places where the peer is expected to write to the notifier.
2. Modifying the build system to it allows enabling vhost-user on BSD.
v1->v2:
- Drop: "Allow returning EventNotifier's wfd" (Alex Williamson)
- Add: "event_notifier: add event_notifier_get_wfd()" (Alex Williamson)
- Add: "vhost: use wfd on functions setting vring call fd"
- Rename: "Allow building vhost-user in BSD" to "configure, meson: allow enabling vhost-user on all POSIX systems"
- Instead of making possible enabling vhost-user on Linux and BSD systems, allow enabling it on all non-Windows platforms. (Paolo Bonzini)
v2->v3:
- Add a section to docs/interop/vhost-user.rst explaining how vhost-user is supported on non-Linux platforms. (Stefan Hajnoczi)
v3->v4:
- Some documentation fixes. (Stefan Hajnoczi)
- Pick up Reviewed-by tags.
Sergio Lopez (4):
event_notifier: add event_notifier_get_wfd()
vhost: use wfd on functions setting vring call fd configure, meson: allow enabling vhost-user on all POSIX systems
docs: vhost-user: add subsection for non-Linux platforms
configure | 4 ++-- docs/interop/vhost-user.rst | 20 ++++++++++++++++++++ hw/virtio/vhost.c | 6 +++--- include/qemu/event_notifier.h | 1 + meson.build | 2 +- util/event_notifier-posix.c | 5 +++++ 6 files changed, 32 insertions(+), 6 deletions(-)
Signature · 1 line
2.35.1
PATCH v4 1/4 event_notifier: add event_notifier_get_wfd()
event_notifier_get_fd(const EventNotifier *e) always returns EventNotifier's read file descriptor (rfd). This is not a problem when the EventNotifier is backed by a an eventfd, as a single file descriptor is used both for reading and triggering events (rfd == wfd).
But, when EventNotifier is backed by a pipe pair, we have two file descriptors, one that can only be used for reads (rfd), and the other only for writes (wfd).
There's, at least, one known situation in which we need to obtain wfd instead of rfd, which is when setting up the file that's going to be sent to the peer in vhost's SET_VRING_CALL.
Add a new event_notifier_get_wfd(const EventNotifier *e) that can be used to obtain wfd where needed.
--- include/qemu/event_notifier.h | 1 + util/event_notifier-posix.c | 5 +++++ 2 files changed, 6 insertions(+)
include/qemu/event_notifier.h +1 -0
@@ -38,6 +38,7 @@ int event_notifier_test_and_clear(EventNotifier *);#ifdef CONFIG_POSIX void event_notifier_init_fd (EventNotifier *,int fd);int event_notifier_get_fd (const EventNotifier *); +int event_notifier_get_wfd (const EventNotifier *);#else HANDLE event_notifier_get_handle (EventNotifier *);#endif
util/event_notifier-posix.c +5 -0
@@ -99,6 +99,11 @@ int event_notifier_get_fd(const EventNotifier *e)return e->rfd; } +int event_notifier_get_wfd (const EventNotifier *e) +{ +return e->wfd; +} +int event_notifier_set (EventNotifier *e) {static const uint64_t value =1 ;
Signature · 1 line
2.35.1
PATCH v4 2/4 vhost: use wfd on functions setting vring call fd
In reply to Sergio LopezWhen ioeventfd is emulated using qemu_pipe(), only EventNotifier's wfd can be used for writing.
Use the recently introduced event_notifier_get_wfd() function to obtain the fd that our peer must use to signal the vring.
--- hw/virtio/vhost.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/virtio/vhost.c +3 -3
@@ -1287,7 +1287,7 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,return r; } - file.fd =event_notifier_get_fd (&vq->masked_notifier); + file.fd =event_notifier_get_wfd (&vq->masked_notifier); r = dev->vhost_ops->vhost_set_vring_call (dev, &file);if (r) {VHOST_OPS_DEBUG (r,"vhost_set_vring_call failed" );
@@ -1542,9 +1542,9 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,if (mask) {assert (vdev->use_guest_notifier_mask); - file.fd =event_notifier_get_fd (&hdev->vqs[index].masked_notifier); + file.fd =event_notifier_get_wfd (&hdev->vqs[index].masked_notifier); }else { - file.fd =event_notifier_get_fd (virtio_queue_get_guest_notifier (vvq)); + file.fd =event_notifier_get_wfd (virtio_queue_get_guest_notifier (vvq)); } file.index = hdev->vhost_ops->vhost_get_vq_index (hdev, n);
Signature · 1 line
2.35.1
PATCH v4 3/4 configure, meson: allow enabling vhost-user on all POSIX systems
In reply to Sergio LopezWith the possibility of using a pipe pair via qemu_pipe() as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on all POSIX systems.
This change allows enabling vhost-user on all non-Windows platforms and makes libvhost_user (which still depends on eventfd) a linux-only feature.
--- configure | 4 ++-- meson.build | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
configure +2 -2
@@ -1659,8 +1659,8 @@ fi # vhost interdependencies and host support # vhost backends -if test "$vhost_user" = "yes" && test "$linux" != "yes"; then - error_exit "vhost-user is only available on Linux" +if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then + error_exit "vhost-user is not available on Windows" fi test "$vhost_vdpa" = "" && vhost_vdpa=$linux if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
meson.build +1 -1
@@ -2701,7 +2701,7 @@ if have_system or have_user endif vhost_user = not_found -if 'CONFIG_VHOST_USER' in config_host +if targetos == 'linux' and 'CONFIG_VHOST_USER' in config_host libvhost_user = subproject('libvhost-user') vhost_user = libvhost_user.get_variable('vhost_user_dep') endif
Signature · 1 line
2.35.1
Re: [PATCH v4 3/4] configure, meson: allow enabling vhost-user on all POSIX systems
Quoted 35 lines · Sergio Lopez
With the possibility of using a pipe pair via
qemu_pipe()as a replacement on operating systems that doesn't support eventfd, vhost-user can also work on all POSIX systems.This change allows enabling vhost-user on all non-Windows platforms and makes
libvhost_user(which still depends on eventfd) a linux-only feature.Signed-off-by Sergio Lopez <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>--- configure | 4 ++-- meson.build | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)configure +2
-2@@ -1659,8 +1659,8 @@ fi # vhost interdependencies and host support # vhost backends -if test "$vhost_user" = "yes" && test "$linux" != "yes"; then - error_exit "vhost-user is only available on Linux" +if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then + error_exit "vhost-user is not available on Windows" fi test "$vhost_vdpa" = "" && vhost_vdpa=$linux if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; thenmeson.build +0
-0
meson.build if have_system or have_user · line 2707
Quoted 8 lines
meson.build +1
-1@@ -2701,7 +2701,7 @@ if have_system or have_user endif vhost_user = not_found -if 'CONFIG_VHOST_USER' in config_host +if targetos == 'linux' and 'CONFIG_VHOST_USER' in config_host libvhost_user = subproject('libvhost-user') vhost_user = libvhost_user.get_variable('vhost_user_dep') endif
PATCH v4 4/4 docs: vhost-user: add subsection for non-Linux platforms
In reply to Sergio LopezAdd a section explaining how vhost-user is supported on platforms other than Linux.
--- docs/interop/vhost-user.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
docs/interop/vhost-user.rst +20 -0
@@ -38,6 +38,26 @@ conventions <backend_conventions>`. *Master* and *slave* can be either a client (i.e. connecting) or server (listening) in the socket communication. +Support for platforms other than Linux +-------------------------------------- + +While vhost-user was initially developed targeting Linux, nowadays it +is supported on any platform that provides the following features: + +- A way for requesting shared memory represented by a file descriptor + so it can be passed over a UNIX domain socket and then mapped by the + other process. + +- AF_UNIX sockets with SCM_RIGHTS, so QEMU and the other process can + exchange messages through it, including ancillary data when needed. + +- Either eventfd or pipe/pipe2. On platforms where eventfd is not + available, QEMU will automatically fall back to pipe2 or, as a last + resort, pipe. Each file descriptor will be used for receiving or + sending events by reading or writing (respectively) an 8-byte value + to the corresponding it. The 8-value itself has no meaning and + should not be interpreted. + Message Specification =====================
Signature · 1 line
2.35.1
Quoted 33 lines · Sergio Lopez
Since QEMU is already able to emulate ioeventfd using pipefd, we're already pretty close to supporting vhost-user on non-Linux systems.
This two patches bridge the gap by:
1. Adding a new
event_notifier_get_wfd()to return wfd on the places where the peer is expected to write to the notifier.2. Modifying the build system to it allows enabling vhost-user on BSD.
v1->v2:
- Drop: "Allow returning EventNotifier's wfd" (Alex Williamson)
- Add: "event_notifier: addevent_notifier_get_wfd()" (Alex Williamson)
- Add: "vhost: use wfd on functions setting vring call fd"
- Rename: "Allow building vhost-user in BSD" to "configure, meson: allow enabling vhost-user on all POSIX systems"
- Instead of making possible enabling vhost-user on Linux and BSD systems, allow enabling it on all non-Windows platforms. (Paolo Bonzini)
v2->v3:
- Add a section todocs/interop/vhost-user.rstexplaining how vhost-user is supported on non-Linux platforms. (Stefan Hajnoczi)
v3->v4:
- Some documentation fixes. (Stefan Hajnoczi)
- Pick up Reviewed-by tags.Sergio Lopez (4):
event_notifier: addevent_notifier_get_wfd()
vhost: use wfd on functions setting vring call fd configure, meson: allow enabling vhost-user on all POSIX systems
docs: vhost-user: add subsection for non-Linux platforms
Quoted 12 lines
configure | 4 ++-- docs/interop/vhost-user.rst | 20 ++++++++++++++++++++ hw/virtio/vhost.c | 6 +++--- include/qemu/event_notifier.h | 1 + meson.build | 2 +- util/event_notifier-posix.c | 5 +++++ 6 files changed, 32 insertions(+), 6 deletions(-)Signature · 1 line
2.35.1