From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5A5FBA0093 for ; Fri, 17 Jun 2022 07:52:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4EF3640689; Fri, 17 Jun 2022 07:52:37 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id B5C6840689 for ; Fri, 17 Jun 2022 07:52:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655445155; 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=b8sTRKMSK7xUNPqardKDNviOYzK+6lmd8QEvgtZo/uE=; b=fTy2eYBQU4Zqi4L2ZHrrU8Ef9BjFZM58OnKgnyvzaNq1ANjgBd9kqMVnjNoQGtzTbJZRQc DnRA8UUqC9KnvbeahyubL+IbW5Z4tbaegxrBrCwsHGF610jg6c5AYyKS0roO6h5+mcDSOD JNlKxi1URnJedx8Uun6INajKfOFK5vc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-177-K840bjVvOC-FH-29giIKUw-1; Fri, 17 Jun 2022 01:52:33 -0400 X-MC-Unique: K840bjVvOC-FH-29giIKUw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5BB151C1CB87; Fri, 17 Jun 2022 05:52:33 +0000 (UTC) Received: from fchome.redhat.com (unknown [10.40.193.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E6B1492C3B; Fri, 17 Jun 2022 05:52:31 +0000 (UTC) From: David Marchand To: xuemingl@nvidia.com, stable@dpdk.org Cc: Sunil Pai G , Maxime Coquelin , Patrick Fu , Jiayu Hu Subject: [PATCH 20.11] vhost: fix async access Date: Fri, 17 Jun 2022 07:52:27 +0200 Message-Id: <20220617055227.1292067-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit 2d47fd3dfb596d266b89d82c2c4b2351c3d6fe20 ] vq->async accesses must be protected with vq->access_lock. Fixes: eb666d24085f ("vhost: fix async unregister deadlock") Fixes: 0c0935c5f794 ("vhost: allow to check in-flight packets for async vhost") Signed-off-by: David Marchand Acked-by: Sunil Pai G Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 1a7c240492..40a2554417 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -1693,31 +1693,26 @@ int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id) if (vq == NULL) return ret; - ret = 0; - - if (!vq->async_registered) - return ret; - if (!rte_spinlock_trylock(&vq->access_lock)) { VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. " "virt queue busy.\n"); - return -1; + return ret; } - if (vq->async_pkts_inflight_n) { + if (!vq->async_registered) { + ret = 0; + } else if (vq->async_pkts_inflight_n) { VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. " "async inflight packets must be completed before unregistration.\n"); - ret = -1; - goto out; - } - - vhost_free_async_mem(vq); + } else { + ret = 0; + vhost_free_async_mem(vq); - vq->async_ops.transfer_data = NULL; - vq->async_ops.check_completed_copies = NULL; - vq->async_registered = false; + vq->async_ops.transfer_data = NULL; + vq->async_ops.check_completed_copies = NULL; + vq->async_registered = false; + } -out: rte_spinlock_unlock(&vq->access_lock); return ret; -- 2.36.1