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=Pxk8BpG+; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 1B1A95A026D for ; Fri, 27 Feb 2026 15:03:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772201019; 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=HDrgZy12mdE1FU7fFH71p4IUISfJ5BVkbVBhmVNysdU=; b=Pxk8BpG+VbA4zHCVhNLSG7lllzTt2J/ddgxPVwRt3RO3OG/vB3jpY0wAr9qZFooV5LMc97 c1rpq/MLRmjl+U5MewMjx1XUmv+OrvhMnNmSvWbmYdEwpNqIdpayn5reIJEKHksXQ5Ce0W dQiNAhjxx3oKAluF5oHdjcRwowXjllA= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-s3q-6QuFPSuLBqjf7nZZ5g-1; Fri, 27 Feb 2026 09:03:37 -0500 X-MC-Unique: s3q-6QuFPSuLBqjf7nZZ5g-1 X-Mimecast-MFC-AGG-ID: s3q-6QuFPSuLBqjf7nZZ5g_1772201016 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6CFA419560AA for ; Fri, 27 Feb 2026 14:03:36 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.225.86]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6157830001B9; Fri, 27 Feb 2026 14:03:35 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 02/12] vhost-user: Use ARRAY_SIZE(elem) instead of VIRTQUEUE_MAX_SIZE Date: Fri, 27 Feb 2026 15:03:20 +0100 Message-ID: <20260227140330.2216753-3-lvivier@redhat.com> In-Reply-To: <20260227140330.2216753-1-lvivier@redhat.com> References: <20260227140330.2216753-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Vjm1cSSTOYEu2AnUBNRamrx-iAGrAXv_gll-_AZb9f0_1772201016 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: IVR4UDJFFXMR22RA3PTP2EHNZ2P47XE3 X-Message-ID-Hash: IVR4UDJFFXMR22RA3PTP2EHNZ2P47XE3 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: When passing the element count to vu_init_elem(), vu_collect(), or using it as a loop bound, use ARRAY_SIZE(elem) instead of the VIRTQUEUE_MAX_SIZE. No functional change. Signed-off-by: Laurent Vivier --- tcp_vu.c | 6 +++--- udp_vu.c | 4 ++-- vu_common.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tcp_vu.c b/tcp_vu.c index bb05fbf45826..98e5974fee0e 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -201,17 +201,17 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, hdrlen = tcp_vu_hdrlen(v6); - vu_init_elem(elem, &iov_vu[DISCARD_IOV_NUM], VIRTQUEUE_MAX_SIZE); + vu_init_elem(elem, &iov_vu[DISCARD_IOV_NUM], ARRAY_SIZE(elem)); elem_cnt = 0; *head_cnt = 0; - while (fillsize > 0 && elem_cnt < VIRTQUEUE_MAX_SIZE) { + while (fillsize > 0 && elem_cnt < ARRAY_SIZE(elem)) { struct iovec *iov; size_t frame_size, dlen; int cnt; cnt = vu_collect(vdev, vq, &elem[elem_cnt], - VIRTQUEUE_MAX_SIZE - elem_cnt, + ARRAY_SIZE(elem) - elem_cnt, MAX(MIN(mss, fillsize) + hdrlen, ETH_ZLEN + VNET_HLEN), &frame_size); if (cnt == 0) diff --git a/udp_vu.c b/udp_vu.c index 51f3718f5925..6f6477f7d046 100644 --- a/udp_vu.c +++ b/udp_vu.c @@ -89,9 +89,9 @@ static int udp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, int s, /* compute L2 header length */ hdrlen = udp_vu_hdrlen(v6); - vu_init_elem(elem, iov_vu, VIRTQUEUE_MAX_SIZE); + vu_init_elem(elem, iov_vu, ARRAY_SIZE(elem)); - iov_cnt = vu_collect(vdev, vq, elem, VIRTQUEUE_MAX_SIZE, + iov_cnt = vu_collect(vdev, vq, elem, ARRAY_SIZE(elem), IP_MAX_MTU + ETH_HLEN + VNET_HLEN, NULL); if (iov_cnt == 0) return -1; diff --git a/vu_common.c b/vu_common.c index aa14598ea028..7a8cd18f4e81 100644 --- a/vu_common.c +++ b/vu_common.c @@ -174,7 +174,7 @@ static void vu_handle_tx(struct vu_dev *vdev, int index, count = 0; out_sg_count = 0; - while (count < VIRTQUEUE_MAX_SIZE && + while (count < ARRAY_SIZE(elem) && out_sg_count + VU_MAX_TX_BUFFER_NB <= VIRTQUEUE_MAX_SIZE) { int ret; struct iov_tail data; @@ -259,10 +259,10 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) return -1; } - vu_init_elem(elem, in_sg, VIRTQUEUE_MAX_SIZE); + vu_init_elem(elem, in_sg, ARRAY_SIZE(elem)); size += VNET_HLEN; - elem_cnt = vu_collect(vdev, vq, elem, VIRTQUEUE_MAX_SIZE, size, &total); + elem_cnt = vu_collect(vdev, vq, elem, ARRAY_SIZE(elem), size, &total); if (total < size) { debug("vu_send_single: no space to send the data " "elem_cnt %d size %zd", elem_cnt, total); -- 2.53.0