@samitouri / QOSamiQemu / commits / 458f80f661

vhost_user: Add frontend get_shmem_config command

The frontend can use this command to retrieve VirtIO Shared Memory Regions configuration from the backend. The response contains the number of shared memory regions, their size, and shmid. This is useful when the frontend is unaware of specific backend type and configuration, for example, in the `vhost-user-device` case. Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Albert Esteve <aesteve@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260304165223.2166175-5-aesteve@redhat.com>

Albert Esteve committed Mar 4, 2026 at 17:52 UTC 458f80f661e51d09936efb53eaba7c0d81ba323c
4 files changed +16 -1
include/hw/virtio/vhost-backend.h
+10
@@ -162,6 +162,15 @@ typedef int (*vhost_set_device_state_fd_op)(struct vhost_dev *dev,
162 int *reply_fd,
163 Error **errp);
164 typedef int (*vhost_check_device_state_op)(struct vhost_dev *dev, Error **errp);
165 +/*
166 + * Max regions is VIRTIO_MAX_SHMEM_REGIONS, so that is the maximum
167 + * number of memory_sizes that will be accepted.
168 + */
169 +typedef int (*vhost_get_shmem_config_op)(struct vhost_dev *dev,
170 + int *nregions,
171 + uint64_t *memory_sizes,
172 + Error **errp);
173 +
174
175 typedef struct VhostOps {
176 VhostBackendType backend_type;
@@ -220,6 +229,7 @@ typedef struct VhostOps {
229 vhost_supports_device_state_op vhost_supports_device_state;
230 vhost_set_device_state_fd_op vhost_set_device_state_fd;
231 vhost_check_device_state_op vhost_check_device_state;
232 + vhost_get_shmem_config_op vhost_get_shmem_config;
233 } VhostOps;
234
235 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd);
include/hw/virtio/vhost-user.h
+1
@@ -35,6 +35,7 @@ enum VhostUserProtocolFeature {
35 VHOST_USER_PROTOCOL_F_DEVICE_STATE = 19,
36 VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT = 20,
37 VHOST_USER_PROTOCOL_F_GPA_ADDRESSES = 21,
38 + VHOST_USER_PROTOCOL_F_SHMEM = 22,
39 VHOST_USER_PROTOCOL_F_MAX
40 };
41
include/hw/virtio/virtio.h
+2
@@ -82,6 +82,8 @@ typedef struct VirtQueueElement
82
83 #define VIRTIO_NO_VECTOR 0xffff
84
85 +#define VIRTIO_MAX_SHMEM_REGIONS 256
86 +
87 /* special index value used internally for config irqs */
88 #define VIRTIO_CONFIG_IRQ_IDX -1
89
subprojects/libvhost-user/libvhost-user.h
+3 -1
@@ -70,7 +70,9 @@ enum VhostUserProtocolFeature {
70 /* Feature 17 reserved for VHOST_USER_PROTOCOL_F_XEN_MMAP. */
71 VHOST_USER_PROTOCOL_F_SHARED_OBJECT = 18,
72 /* Feature 19 is reserved for VHOST_USER_PROTOCOL_F_DEVICE_STATE */
73 - VHOST_USER_PROTOCOL_F_SHMEM = 20,
73 + /* Feature 20 is reserved for VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT */
74 + /* Feature 21 is reserved for VHOST_USER_PROTOCOL_F_GPA_ADDRESSES */
75 + VHOST_USER_PROTOCOL_F_SHMEM = 22,
76 VHOST_USER_PROTOCOL_F_MAX
77 };
78