From patchwork Wed Jul 3 16:27:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 142096 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3C41E45563; Wed, 3 Jul 2024 18:27:52 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0A0514279A; Wed, 3 Jul 2024 18:27:52 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id A8FDE4111C for ; Wed, 3 Jul 2024 18:27:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720024070; 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; bh=zMvuMsiJqfZLuZ9Lwyu73G3QF8SXW4bguprN7bKi5Vc=; b=BxOO4/HSe8BPzSQ8q7p40rCm1EL9/WrNKHtxcwSgu7RqZt+UiairQRQOAYW5xWVJyE/G/4 4/ms/vGdwXH391Spzt7aG0qaywqYVFB+Ig9UYZK17sEiOX17O8r8QnZbj7ExZBQA/mchAV bv2aKT3+LQk2TrBIqeszwLY8FWGoWbg= Received: from mx-prod-mc-03.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-630-ZIA9MZTVO4aagAU5RR5IOQ-1; Wed, 03 Jul 2024 12:27:44 -0400 X-MC-Unique: ZIA9MZTVO4aagAU5RR5IOQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 66D3419560B3; Wed, 3 Jul 2024 16:27:43 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.11]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4808D1955BC0; Wed, 3 Jul 2024 16:27:40 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH] net/virtio-user: fix control queue allocation for non-vDPA Date: Wed, 3 Jul 2024 18:27:38 +0200 Message-ID: <20240703162738.283162-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org For non-vDPA backends, where the backend does not support control queue, it is still emulated in the Virtio-user layer to handle multiqueue feature. The frontend setups a control queue, which is hidden to the device. It means the number of vrings metadata to allocate should be based on the frontend features and not the device features. This patch fixes out-of-range access reported by ASan, which could sometimes be noticed at exit time by a segmentation fault when disabled: Fixes: b80947743f5e ("net/virtio-user: fix control queue allocation") Reported-by: David Marchand Signed-off-by: Maxime Coquelin Reviewed-by: David Marchand --- drivers/net/virtio/virtio_user/virtio_user_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index b2c6c2b7df..fed66d2ae9 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -624,7 +624,7 @@ virtio_user_alloc_vrings(struct virtio_user_dev *dev) bool packed_ring = !!(dev->device_features & (1ull << VIRTIO_F_RING_PACKED)); nr_vrings = dev->max_queue_pairs * 2; - if (dev->device_features & (1ull << VIRTIO_NET_F_CTRL_VQ)) + if (dev->frontend_features & (1ull << VIRTIO_NET_F_CTRL_VQ)) nr_vrings++; dev->callfds = rte_zmalloc("virtio_user_dev", nr_vrings * sizeof(*dev->callfds), 0);