From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B4F55A04DD; Wed, 21 Oct 2020 14:07:03 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 400AA5A71; Wed, 21 Oct 2020 14:07:01 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id 3B81C5A56 for ; Wed, 21 Oct 2020 14:06:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603282016; 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=gLfZawgwuz1KvnD3WraBmyzY5EbQdU3Yxv7Rw6Log/I=; b=Bb1tuoLER5QAebRqOIy0idTCb4qy1ge/6dUGNGYxe9gFsTHD8vYVBoNh9mrdIAaiUN8oM4 WjChxQdz/r7Y4pygvuthrZNX6lGO7s+0da2Cfkw7oZGk1YDBVbaWSk1pShJufO0CA39WhJ PjurtHtBEmiXV0z60nwXRQC4D3y8vGM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-377-plluCQ11OoeHUtNXhE9P2A-1; Wed, 21 Oct 2020 08:06:54 -0400 X-MC-Unique: plluCQ11OoeHUtNXhE9P2A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 662D41868429; Wed, 21 Oct 2020 12:06:53 +0000 (UTC) Received: from [10.36.110.17] (unknown [10.36.110.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEE6B27BA3; Wed, 21 Oct 2020 12:06:51 +0000 (UTC) To: "Xia, Chenbo" , "dev@dpdk.org" , "amorenoz@redhat.com" Cc: "stable@dpdk.org" References: <20201019173415.582407-1-maxime.coquelin@redhat.com> <20201019173415.582407-2-maxime.coquelin@redhat.com> From: Maxime Coquelin Message-ID: Date: Wed, 21 Oct 2020 14:06:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 1/7] vhost: fix virtqueues metadata allocation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Chenbon On 10/21/20 1:10 PM, Xia, Chenbo wrote: > Hi Maxime, > >> -----Original Message----- >> From: Maxime Coquelin >> Sent: Tuesday, October 20, 2020 1:34 AM >> To: dev@dpdk.org; Xia, Chenbo ; amorenoz@redhat.com >> Cc: Maxime Coquelin ; stable@dpdk.org >> Subject: [PATCH 1/7] vhost: fix virtqueues metadata allocation >> >> The Vhost-user backend implementation assumes there will be >> no holes in the device's array of virtqueues metadata >> pointers. >> >> It can happen though, and would cause segmentation faults, >> memory leaks or undefined behaviour. > > Could I ask when will this happen? > > When QEMU does not configure all virtqueues? I'm not very sure. > Could you point that out for me? It has been reported by our QE when doing reconnect with multiqueue with vIOMMU enabled: https://bugzilla.redhat.com/show_bug.cgi?id=1880299 Regards, Maxime > Thanks! > Chenbo > >> >> This patch keep the assumption that there is no holes in this >> array, and allocate all uninitialized virtqueues metadata up >> to requested index. >> >> Fixes: 160cbc815b41 ("vhost: remove a hack on queue allocation") >> Cc: stable@dpdk.org >> >> Suggested-by: Adrian Moreno >> Signed-off-by: Maxime Coquelin >> --- >> lib/librte_vhost/vhost.c | 33 ++++++++++++++++++++------------- >> 1 file changed, 20 insertions(+), 13 deletions(-) >> >> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c >> index 6068c38ec6..0c9ba3b3af 100644 >> --- a/lib/librte_vhost/vhost.c >> +++ b/lib/librte_vhost/vhost.c >> @@ -579,22 +579,29 @@ int >> alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx) >> { >> struct vhost_virtqueue *vq; >> + uint32_t i; >> >> - vq = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); >> - if (vq == NULL) { >> - VHOST_LOG_CONFIG(ERR, >> - "Failed to allocate memory for vring:%u.\n", vring_idx); >> - return -1; >> - } >> + /* Also allocate holes, if any, up to requested vring index. */ >> + for (i = 0; i <= vring_idx; i++) { >> + if (dev->virtqueue[i]) >> + continue; >> >> - dev->virtqueue[vring_idx] = vq; >> - init_vring_queue(dev, vring_idx); >> - rte_spinlock_init(&vq->access_lock); >> - vq->avail_wrap_counter = 1; >> - vq->used_wrap_counter = 1; >> - vq->signalled_used_valid = false; >> + vq = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); >> + if (vq == NULL) { >> + VHOST_LOG_CONFIG(ERR, >> + "Failed to allocate memory for vring:%u.\n", i); >> + return -1; >> + } >> + >> + dev->virtqueue[i] = vq; >> + init_vring_queue(dev, vring_idx); >> + rte_spinlock_init(&vq->access_lock); >> + vq->avail_wrap_counter = 1; >> + vq->used_wrap_counter = 1; >> + vq->signalled_used_valid = false; >> + } >> >> - dev->nr_vring += 1; >> + dev->nr_vring = RTE_MAX(dev->nr_vring, vring_idx + 1); >> >> return 0; >> } >> -- >> 2.26.2 >