From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D3oKTWtz; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 0D8795A0271 for ; Fri, 05 Sep 2025 17:49:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757087381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l0UTzCSuLZdi/2jgKxDbKCU1YS7nEZUWKaVyliQIOGA=; b=D3oKTWtzlvOF3bcdoau9sgznmiLLvhus5aS9oGNLOlU5GdxtZQ7GX9MPSKF4RT3/o0nAyZ Q7WMxdF2eSQ0KMeeaQ94ALEhjsxyKTpOnoIqBLFkAOhowzyTe9PQ/H2tP/1qD7BUn9Dtig 2aB8/hoppAfqXZzBR2frofPNw3XWSfo= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-vJYHtjdVPjWdGaK_krXICA-1; Fri, 05 Sep 2025 11:49:39 -0400 X-MC-Unique: vJYHtjdVPjWdGaK_krXICA-1 X-Mimecast-MFC-AGG-ID: vJYHtjdVPjWdGaK_krXICA_1757087379 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22AEF1800359 for ; Fri, 5 Sep 2025 15:49:39 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.9]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 071F41800576; Fri, 5 Sep 2025 15:49:37 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 1/3] vhost-user: Fix VHOST_USER_GET_QUEUE_NUM to return number of queues Date: Fri, 5 Sep 2025 17:49:33 +0200 Message-ID: <20250905154935.389634-2-lvivier@redhat.com> In-Reply-To: <20250905154935.389634-1-lvivier@redhat.com> References: <20250905154935.389634-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: mLHED4LS3QbzC_P_-ssWOnxoQocENBtLZwZNZatTi98_1757087379 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: BEL7D2YMPCEHWAKNGQ6SJ7L6LFN2RTXN X-Message-ID-Hash: BEL7D2YMPCEHWAKNGQ6SJ7L6LFN2RTXN X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The vhost-user specification states that VHOST_USER_GET_QUEUE_NUM should return the maximum number of queues supported by the back-end, not the number of virtqueues. Since each queue pair consists of RX and TX virtqueues, we need to divide VHOST_USER_MAX_QUEUES by 2 to get the correct queue count. Also rename VHOST_USER_MAX_QUEUES to VHOST_USER_MAX_VQS throughout the codebase to better reflect that it represents the maximum number of virtqueues, not queue pairs. Signed-off-by: Laurent Vivier --- vhost_user.c | 16 +++++++++------- virtio.h | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/vhost_user.c b/vhost_user.c index f97ec6064cac..fa343a86fac2 100644 --- a/vhost_user.c +++ b/vhost_user.c @@ -345,7 +345,7 @@ static void vu_set_enable_all_rings(struct vu_dev *vdev, bool enable) { uint16_t i; - for (i = 0; i < VHOST_USER_MAX_QUEUES; i++) + for (i = 0; i < VHOST_USER_MAX_VQS; i++) vdev->vq[i].enable = enable; } @@ -477,7 +477,7 @@ static bool vu_set_mem_table_exec(struct vu_dev *vdev, close(vmsg->fds[i]); } - for (i = 0; i < VHOST_USER_MAX_QUEUES; i++) { + for (i = 0; i < VHOST_USER_MAX_VQS; i++) { if (vdev->vq[i].vring.desc) { if (map_ring(vdev, &vdev->vq[i])) die("remapping queue %d during setmemtable", i); @@ -770,7 +770,7 @@ static void vu_check_queue_msg_file(struct vhost_user_msg *vmsg) bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; int idx = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; - if (idx >= VHOST_USER_MAX_QUEUES) + if (idx >= VHOST_USER_MAX_VQS) die("Invalid vhost-user queue index: %u", idx); if (nofd) { @@ -939,7 +939,9 @@ static bool vu_get_queue_num_exec(struct vu_dev *vdev, { (void)vdev; - vmsg_set_reply_u64(vmsg, VHOST_USER_MAX_QUEUES); + vmsg_set_reply_u64(vmsg, VHOST_USER_MAX_VQS / 2); + + debug("VHOST_USER_MAX_VQS %u", VHOST_USER_MAX_VQS / 2); return true; } @@ -960,7 +962,7 @@ static bool vu_set_vring_enable_exec(struct vu_dev *vdev, debug("State.index: %u", idx); debug("State.enable: %u", enable); - if (idx >= VHOST_USER_MAX_QUEUES) + if (idx >= VHOST_USER_MAX_VQS) die("Invalid vring_enable index: %u", idx); vdev->vq[idx].enable = enable; @@ -1052,7 +1054,7 @@ void vu_init(struct ctx *c) c->vdev = &vdev_storage; c->vdev->context = c; - for (i = 0; i < VHOST_USER_MAX_QUEUES; i++) { + for (i = 0; i < VHOST_USER_MAX_VQS; i++) { c->vdev->vq[i] = (struct vu_virtq){ .call_fd = -1, .kick_fd = -1, @@ -1075,7 +1077,7 @@ void vu_cleanup(struct vu_dev *vdev) { unsigned int i; - for (i = 0; i < VHOST_USER_MAX_QUEUES; i++) { + for (i = 0; i < VHOST_USER_MAX_VQS; i++) { struct vu_virtq *vq = &vdev->vq[i]; vq->started = false; diff --git a/virtio.h b/virtio.h index b55cc4042521..12caaa0b6def 100644 --- a/virtio.h +++ b/virtio.h @@ -88,7 +88,7 @@ struct vu_dev_region { uint64_t mmap_addr; }; -#define VHOST_USER_MAX_QUEUES 2 +#define VHOST_USER_MAX_VQS 2 /* * Set a reasonable maximum number of ram slots, which will be supported by @@ -121,7 +121,7 @@ struct vdev_memory { struct vu_dev { struct ctx *context; struct vdev_memory memory; - struct vu_virtq vq[VHOST_USER_MAX_QUEUES]; + struct vu_virtq vq[VHOST_USER_MAX_VQS]; uint64_t features; uint64_t protocol_features; int log_call_fd; -- 2.50.1