Skip to content

Commit 1d4d0ef

Browse files
benzeajmberg-intel
authored andcommitted
um: virtio_uml: query the number of vqs if supported
When the VHOST_USER_PROTOCOL_F_MQ protocol feature flag is set, we can query the maximum number of virtual queues. Do so when supported and extend the check to verify that we are not trying to allocate more queues. Signed-off-by: Benjamin Berg <benjamin.berg@intel.com> Link: https://patch.msgid.link/20241103212854.1436046-5-benjamin@sipsolutions.net [add a message to the WARN_ON] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent d85dead commit 1d4d0ef

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

arch/um/drivers/vhost_user.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/* Feature bits */
1111
#define VHOST_USER_F_PROTOCOL_FEATURES 30
1212
/* Protocol feature bits */
13+
#define VHOST_USER_PROTOCOL_F_MQ 0
1314
#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
1415
#define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5
1516
#define VHOST_USER_PROTOCOL_F_CONFIG 9
@@ -23,7 +24,8 @@
2324
/* Supported transport features */
2425
#define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)
2526
/* Supported protocol features */
26-
#define VHOST_USER_SUPPORTED_PROTOCOL_F (BIT_ULL(VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
27+
#define VHOST_USER_SUPPORTED_PROTOCOL_F (BIT_ULL(VHOST_USER_PROTOCOL_F_MQ) | \
28+
BIT_ULL(VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
2729
BIT_ULL(VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \
2830
BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG) | \
2931
BIT_ULL(VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS))

arch/um/drivers/virtio_uml.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct virtio_uml_device {
5656
int sock, req_fd, irq;
5757
u64 features;
5858
u64 protocol_features;
59+
u64 max_vqs;
5960
u8 status;
6061
u8 registered:1;
6162
u8 suspended:1;
@@ -341,6 +342,17 @@ static int vhost_user_set_protocol_features(struct virtio_uml_device *vu_dev,
341342
protocol_features);
342343
}
343344

345+
static int vhost_user_get_queue_num(struct virtio_uml_device *vu_dev,
346+
u64 *queue_num)
347+
{
348+
int rc = vhost_user_send_no_payload(vu_dev, true,
349+
VHOST_USER_GET_QUEUE_NUM);
350+
351+
if (rc)
352+
return rc;
353+
return vhost_user_recv_u64(vu_dev, queue_num);
354+
}
355+
344356
static void vhost_user_reply(struct virtio_uml_device *vu_dev,
345357
struct vhost_user_msg *msg, int response)
346358
{
@@ -514,6 +526,15 @@ static int vhost_user_init(struct virtio_uml_device *vu_dev)
514526
return rc;
515527
}
516528

529+
if (vu_dev->protocol_features &
530+
BIT_ULL(VHOST_USER_PROTOCOL_F_MQ)) {
531+
rc = vhost_user_get_queue_num(vu_dev, &vu_dev->max_vqs);
532+
if (rc)
533+
return rc;
534+
} else {
535+
vu_dev->max_vqs = U64_MAX;
536+
}
537+
517538
return 0;
518539
}
519540

@@ -1018,7 +1039,9 @@ static int vu_find_vqs(struct virtio_device *vdev, unsigned nvqs,
10181039
struct virtqueue *vq;
10191040

10201041
/* not supported for now */
1021-
if (WARN_ON(nvqs > 64))
1042+
if (WARN(nvqs > 64 || nvqs > vu_dev->max_vqs,
1043+
"%d VQs requested, only up to 64 or %lld supported\n",
1044+
nvqs, vu_dev->max_vqs))
10221045
return -EINVAL;
10231046

10241047
rc = vhost_user_set_mem_table(vu_dev);

0 commit comments

Comments
 (0)