Re: [PATCH RFC 05/15] vhost-user: add memory_isolation to VhostUserState
Akihiko Odaki <[email protected]> Fri, 24 Jul 2026 20:09:48 +0900
| Newsgroups | dev.linux.lists.virtio-fs,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
On 2026/07/24 7:30, Connor Kite wrote: > Add a memory_isolation bool to the VhostUserState struct. This > bool is set within vhost_user_init(), which takes a > memory_isolation bool as an argument. > > Refactor all call locations of vhost_user_init to include the new > argument. > > Signed-off-by: Connor Kite <[email protected]> > --- > backends/cryptodev-vhost-user.c | 2 +- > backends/vhost-user.c | 4 ++-- > hw/block/vhost-user-blk.c | 3 ++- > hw/display/vhost-user-gpu.c | 3 ++- > hw/scsi/vhost-user-scsi.c | 3 ++- > hw/virtio/vhost-stub.c | 3 ++- > hw/virtio/vhost-user-base.c | 3 ++- > hw/virtio/vhost-user-fs.c | 3 ++- > hw/virtio/vhost-user-scmi.c | 3 ++- > hw/virtio/vhost-user-vsock.c | 3 ++- > hw/virtio/vhost-user.c | 5 ++++- > include/hw/virtio/vhost-user.h | 6 +++++- > include/system/vhost-user-backend.h | 3 ++- > net/passt.c | 13 ++++++++----- > net/vhost-user.c | 9 +++++---- > 15 files changed, 43 insertions(+), 23 deletions(-) > > diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c > index e0547c5d40..328d7fbdfe 100644 > --- a/backends/cryptodev-vhost-user.c > +++ b/backends/cryptodev-vhost-user.c > @@ -214,7 +214,7 @@ static void cryptodev_vhost_user_init( > } > } > > - if (!vhost_user_init(&s->vhost_user, &s->chr, errp)) { > + if (!vhost_user_init(&s->vhost_user, &s->chr, s->memory_isolation, errp)) { > return; > } > > diff --git a/backends/vhost-user.c b/backends/vhost-user.c > index 380d825023..470eba1775 100644 > --- a/backends/vhost-user.c > +++ b/backends/vhost-user.c > @@ -22,13 +22,13 @@ > > int > vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODevice *vdev, > - unsigned nvqs, Error **errp) > + unsigned nvqs, bool memory_isolation, Error **errp) > { > int ret; > > assert(!b->vdev && vdev); > > - if (!vhost_user_init(&b->vhost_user, &b->chr, errp)) { > + if (!vhost_user_init(&b->vhost_user, &b->chr, memory_isolation, errp)) { > return -1; > } > > diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c > index 9830dc6c35..5c1a19eb50 100644 > --- a/hw/block/vhost-user-blk.c > +++ b/hw/block/vhost-user-blk.c > @@ -505,7 +505,8 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) > return; > } > > - if (!vhost_user_init(&s->vhost_user, &s->chardev, errp)) { > + if (!vhost_user_init(&s->vhost_user, &s->chardev, > + s->memory_isolation, errp)) { > return; > } > > diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c > index 6d0ede672a..b44c989f58 100644 > --- a/hw/display/vhost-user-gpu.c > +++ b/hw/display/vhost-user-gpu.c > @@ -625,7 +625,8 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp) > VirtIODevice *vdev = VIRTIO_DEVICE(g); > > vhost_dev_set_config_notifier(&g->vhost->dev, &config_ops); > - if (vhost_user_backend_dev_init(g->vhost, vdev, 2, errp) < 0) { > + if (vhost_user_backend_dev_init(g->vhost, vdev, 2, g->memory_isolation, > + errp) < 0) { > return; > } > > diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c > index c1a0393220..5a19182f2b 100644 > --- a/hw/scsi/vhost-user-scsi.c > +++ b/hw/scsi/vhost-user-scsi.c > @@ -276,7 +276,8 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) > return; > } > > - if (!vhost_user_init(&s->vhost_user, &vs->conf.chardev, errp)) { > + if (!vhost_user_init(&s->vhost_user, &vs->conf.chardev, > + vs->conf.memory_isolation, errp)) { > goto free_virtio; > } > > diff --git a/hw/virtio/vhost-stub.c b/hw/virtio/vhost-stub.c > index 7321dc9210..d1e1075a31 100644 > --- a/hw/virtio/vhost-stub.c > +++ b/hw/virtio/vhost-stub.c > @@ -12,7 +12,8 @@ unsigned int vhost_get_free_memslots(void) > return UINT_MAX; > } > > -bool vhost_user_init(VhostUserState *user, CharFrontend *chr, Error **errp) > +bool vhost_user_init(VhostUserState *user, CharFrontend *chr, > + bool memory_isolation, Error **errp) > { > return false; > } > diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c > index d2a74a2860..11864a3f08 100644 > --- a/hw/virtio/vhost-user-base.c > +++ b/hw/virtio/vhost-user-base.c > @@ -317,7 +317,8 @@ static void vub_device_realize(DeviceState *dev, Error **errp) > vub->vhost_user.supports_config = true; > } > > - if (!vhost_user_init(&vub->vhost_user, &vub->chardev, errp)) { > + if (!vhost_user_init(&vub->vhost_user, &vub->chardev, > + vub->memory_isolation, errp)) { > return; > } > > diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c > index 3d980d814b..07ff2a35e0 100644 > --- a/hw/virtio/vhost-user-fs.c > +++ b/hw/virtio/vhost-user-fs.c > @@ -238,7 +238,8 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) > return; > } > > - if (!vhost_user_init(&fs->vhost_user, &fs->conf.chardev, errp)) { > + if (!vhost_user_init(&fs->vhost_user, &fs->conf.chardev, > + fs->conf.memory_isolation, errp)) { > return; > } > > diff --git a/hw/virtio/vhost-user-scmi.c b/hw/virtio/vhost-user-scmi.c > index d514d89392..2c1dbb723e 100644 > --- a/hw/virtio/vhost-user-scmi.c > +++ b/hw/virtio/vhost-user-scmi.c > @@ -244,7 +244,8 @@ static void vu_scmi_device_realize(DeviceState *dev, Error **errp) > > vdev->host_features |= (1ULL << VIRTIO_SCMI_F_P2A_CHANNELS); > > - if (!vhost_user_init(&scmi->vhost_user, &scmi->chardev, errp)) { > + if (!vhost_user_init(&scmi->vhost_user, &scmi->chardev, > + scmi->memory_isolation, errp)) { > return; > } > > diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c > index 89aa789e22..33ab3b69e6 100644 > --- a/hw/virtio/vhost-user-vsock.c > +++ b/hw/virtio/vhost-user-vsock.c > @@ -106,7 +106,8 @@ static void vuv_device_realize(DeviceState *dev, Error **errp) > return; > } > > - if (!vhost_user_init(&vsock->vhost_user, &vsock->conf.chardev, errp)) { > + if (!vhost_user_init(&vsock->vhost_user, &vsock->conf.chardev, > + vsock->conf.memory_isolation, errp)) { > return; > } > > diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c > index 517cc4ca71..f296b63fb9 100644 > --- a/hw/virtio/vhost-user.c > +++ b/hw/virtio/vhost-user.c > @@ -3118,13 +3118,16 @@ static void vhost_user_state_destroy(gpointer data) > vhost_user_host_notifier_remove(n, NULL, true); > } > > -bool vhost_user_init(VhostUserState *user, CharFrontend *chr, Error **errp) > +bool vhost_user_init(VhostUserState *user, CharFrontend *chr, > + bool memory_isolation, > + Error **errp) > { > if (user->chr) { > error_setg(errp, "Cannot initialize vhost-user state"); > return false; > } > user->chr = chr; > + user->memory_isolation = memory_isolation; > user->memory_slots = 0; > user->notifiers = g_ptr_array_new_full(VIRTIO_QUEUE_MAX / 4, > &vhost_user_state_destroy); > diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h > index 06c360af18..72b5787efe 100644 > --- a/include/hw/virtio/vhost-user.h > +++ b/include/hw/virtio/vhost-user.h > @@ -66,6 +66,7 @@ typedef struct VhostUserHostNotifier { > * @chr: the character backend for the socket > * @notifiers: GPtrArray of @VhostUserHostnotifier > * @memory_slots: > + * @memory_isolation: determines whether data is shared or copied > */ > typedef struct VhostUserState { > CharFrontend *chr; > @@ -73,12 +74,14 @@ typedef struct VhostUserState { > int memory_slots; > bool supports_config; > bool supports_inflight_migration; > + bool memory_isolation; > } VhostUserState; > > /** > * vhost_user_init() - initialise shared vhost_user state > * @user: allocated area for storing shared state > * @chr: the chardev for the vhost socket > + * @memory_isolation: disables device access to guest memory > * @errp: error handle > * > * User can either directly g_new() space for the state or embed > @@ -87,7 +90,8 @@ typedef struct VhostUserState { > * > * Return: true on success, false on error while setting errp. > */ > -bool vhost_user_init(VhostUserState *user, CharFrontend *chr, Error **errp); > +bool vhost_user_init(VhostUserState *user, CharFrontend *chr, > + bool memory_isolation, Error **errp); The signature of the stub for !defined(CONFIG_VHOST_USER) is not updated, breaking builds. Regards, Akihiko Odaki > > /** > * vhost_user_cleanup() - cleanup state > diff --git a/include/system/vhost-user-backend.h b/include/system/vhost-user-backend.h > index 3184c8e799..c23f689182 100644 > --- a/include/system/vhost-user-backend.h > +++ b/include/system/vhost-user-backend.h > @@ -41,7 +41,8 @@ struct VhostUserBackend { > }; > > int vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODevice *vdev, > - unsigned nvqs, Error **errp); > + unsigned nvqs, bool memory_isolation, > + Error **errp); > void vhost_user_backend_start(VhostUserBackend *b); > int vhost_user_backend_stop(VhostUserBackend *b); > > diff --git a/net/passt.c b/net/passt.c > index ce80186883..a3021f37ef 100644 > --- a/net/passt.c > +++ b/net/passt.c > @@ -433,7 +433,9 @@ static void passt_vhost_user_event(void *opaque, QEMUChrEvent event) > } > } > > -static int net_passt_vhost_user_init(NetPasstState *s, Error **errp) > +static int net_passt_vhost_user_init(NetPasstState *s, > + bool memory_isolation, > + Error **errp) > { > Chardev *chr; > int sv[2]; > @@ -457,7 +459,8 @@ static int net_passt_vhost_user_init(NetPasstState *s, Error **errp) > > s->vhost_user = g_new0(struct VhostUserState, 1); > if (!qemu_chr_fe_init(&s->vhost_chr, chr, errp) || > - !vhost_user_init(s->vhost_user, &s->vhost_chr, errp)) { > + !vhost_user_init(s->vhost_user, &s->vhost_chr, memory_isolation, > + errp)) { > goto err; > } > > @@ -735,14 +738,14 @@ int net_init_passt(const Netdev *netdev, const char *name, > s->pidfile = pidfile; > > if (netdev->u.passt.has_vhost_user && netdev->u.passt.vhost_user) { > - bool memory_isolation G_GNUC_UNUSED = false; > + bool memory_isolation = false; > > if (netdev->u.passt.has_memory_isolation && > - netdev->u.passt.memory_isolation) { > + netdev->u.passt.memory_isolation) { > memory_isolation = true; > } > > - if (net_passt_vhost_user_init(s, errp) == -1) { > + if (net_passt_vhost_user_init(s, memory_isolation, errp) == -1) { > qemu_del_net_client(nc); > return -1; > } > diff --git a/net/vhost-user.c b/net/vhost-user.c > index 8fa303f901..722ab20228 100644 > --- a/net/vhost-user.c > +++ b/net/vhost-user.c > @@ -370,7 +370,7 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event) > > static int net_vhost_user_init(NetClientState *peer, const char *device, > const char *name, Chardev *chr, > - int queues) > + int queues, bool memory_isolation) > { > Error *err = NULL; > NetClientState *nc, *nc0 = NULL; > @@ -390,7 +390,7 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, > nc0 = nc; > s = DO_UPCAST(NetVhostUserState, nc, nc); > if (!qemu_chr_fe_init(&s->chr, chr, &err) || > - !vhost_user_init(user, &s->chr, &err)) { > + !vhost_user_init(user, &s->chr, memory_isolation, &err)) { > error_report_err(err); > goto err; > } > @@ -459,7 +459,7 @@ int net_init_vhost_user(const Netdev *netdev, const char *name, > int queues; > const NetdevVhostUserOptions *vhost_user_opts; > Chardev *chr; > - bool memory_isolation G_GNUC_UNUSED; > + bool memory_isolation; > > assert(netdev->type == NET_CLIENT_DRIVER_VHOST_USER); > vhost_user_opts = &netdev->u.vhost_user; > @@ -480,5 +480,6 @@ int net_init_vhost_user(const Netdev *netdev, const char *name, > memory_isolation = vhost_user_opts->has_memory_isolation ? > vhost_user_opts->memory_isolation : false; > > - return net_vhost_user_init(peer, "vhost_user", name, chr, queues); > + return net_vhost_user_init(peer, "vhost_user", name, chr, queues, > + memory_isolation); > } >