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 26FBAA0547 for ; Tue, 9 Feb 2021 11:35:58 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2092A160715; Tue, 9 Feb 2021 11:35:58 +0100 (CET) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mails.dpdk.org (Postfix) with ESMTP id AC6F6160712 for ; Tue, 9 Feb 2021 11:35:56 +0100 (CET) Received: by mail-wm1-f52.google.com with SMTP id f16so2578039wmq.5 for ; Tue, 09 Feb 2021 02:35:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AAMDv3QUktGQdl8TB8yAn7jjTL9YvBWM7OcKcMDr+ws=; b=PVJATb//llIgc8AOmpYw+Ged9HTdVKeDW+FCm4rntq71AAGG3HtYW/hWxxpF0ngPKq hTPe2EYQUd0ncXCosCweL90CX+aoKhDSp97sF1dZMkmyaqNQWx5O3Q9c00jZjA3XDpvp 1/k/dGJ5zoaGVfmmeOxVDLiM8ZJ5+zWvNvTEnB5J079KqCxqZIsq3SsvEhVVkevg6wfi 2LhnBJlmF01EhgKww5kJ6uZFCVEeK+ZIwIECKaTbAzwixcATeqcImOC8HJE9hWtZfy3Q ohF1a1KvAYEWICqev/ZwQhCT1XA2tJFO/Ec6m927nwiX+yp4vL0i5x5bBoF3mhHyVp8/ +JyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AAMDv3QUktGQdl8TB8yAn7jjTL9YvBWM7OcKcMDr+ws=; b=D6xQF7qLwNMG0NhL8pSWXV3+qeq1At6p1YIwwMqdtTLMDoRUVWlvL8Qc0QcOqihdUs UUYDTp+7+DVxFzD04rAZDMJGohjrzSsm1Cr65twSDYDMvxWJt541ODHtGHFUMQUBnowV 0Sty5dpl67jNyyIukkvySNYTDmIHeYbA/pNi1gy/9cF1JezA/FZaTEc/KJ8r7dE8+27N 2aKCtTW7orbBrvJNVWncbqNTVxWMZQChayuMS6L8TIFKip79hRgEb3bCUtlX0UDx4PT8 RWl/DnRPcf00+hN9BdfaDiDMBGkePwc5ZXDDALb8MTmXJaSIqLPSwgwkTwT3QgUpMRt3 PHBg== X-Gm-Message-State: AOAM531E3ayOLuBdssb2LeNa1MeF/xVozpnLiSG7fphBaMRApnFa5+nP lxyY/r2CKHHKu+SR+0js7XE= X-Google-Smtp-Source: ABdhPJzKwP9aX3i1hzs365ldozTwaXTMuYSTyndbC+jiQauXrOvuikgjAOZMQEzeIis1g6gFrV6Y0Q== X-Received: by 2002:a05:600c:4f07:: with SMTP id l7mr2727766wmq.111.1612866956497; Tue, 09 Feb 2021 02:35:56 -0800 (PST) Received: from localhost ([88.98.246.218]) by smtp.gmail.com with ESMTPSA id j11sm35147730wrt.26.2021.02.09.02.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 02:35:55 -0800 (PST) From: luca.boccassi@gmail.com To: Fei Chen Cc: Peng He , Zhihong Wang , Chenbo Xia , dpdk stable Date: Tue, 9 Feb 2021 10:35:08 +0000 Message-Id: <20210209103529.466775-10-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210209103529.466775-1-luca.boccassi@gmail.com> References: <20210205111920.1272063-1-luca.boccassi@gmail.com> <20210209103529.466775-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'vhost: fix vid allocation race' has been queued to stable release 20.11.1 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 Sender: "stable" Hi, FYI, your patch has been queued to stable release 20.11.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 02/11/21. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/9f014a02d2276f4fa38d112172d0d8635a06fab4 Thanks. Luca Boccassi --- >From 9f014a02d2276f4fa38d112172d0d8635a06fab4 Mon Sep 17 00:00:00 2001 From: Fei Chen Date: Mon, 1 Feb 2021 16:48:44 +0800 Subject: [PATCH] vhost: fix vid allocation race [ upstream commit 9944bddf80d692ade5ef6f7326541b13881cbbb9 ] vhost_new_device might be called in different threads at the same time. thread 1(config thread) rte_vhost_driver_start ->vhost_user_start_client ->vhost_user_add_connection -> vhost_new_device thread 2(vhost-events) vhost_user_read_cb ->vhost_user_msg_handler (return value < 0) -> vhost_user_start_client -> vhost_new_device So there could be a case that a same vid has been allocated twice, or some vid might be lost in DPDK lib however still held by the upper applications. Another place where race would happen is at the func *vhost_destroy_device*, but after a detailed investigation, the race does not exist as long as no two devices have the same vid: Calling vhost_destroy_devices in different threads with different vids is actually safe. Fixes: a277c7159876 ("vhost: refactor code structure") Reported-by: Peng He Signed-off-by: Fei Chen Reviewed-by: Zhihong Wang Reviewed-by: Chenbo Xia --- lib/librte_vhost/vhost.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index b83cf639eb..4de588d752 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -26,6 +26,7 @@ #include "vhost_user.h" struct virtio_net *vhost_devices[MAX_VHOST_DEVICE]; +pthread_mutex_t vhost_dev_lock = PTHREAD_MUTEX_INITIALIZER; /* Called with iotlb_lock read-locked */ uint64_t @@ -645,6 +646,7 @@ vhost_new_device(void) struct virtio_net *dev; int i; + pthread_mutex_lock(&vhost_dev_lock); for (i = 0; i < MAX_VHOST_DEVICE; i++) { if (vhost_devices[i] == NULL) break; @@ -653,6 +655,7 @@ vhost_new_device(void) if (i == MAX_VHOST_DEVICE) { VHOST_LOG_CONFIG(ERR, "Failed to find a free slot for new device.\n"); + pthread_mutex_unlock(&vhost_dev_lock); return -1; } @@ -660,10 +663,13 @@ vhost_new_device(void) if (dev == NULL) { VHOST_LOG_CONFIG(ERR, "Failed to allocate memory for new dev.\n"); + pthread_mutex_unlock(&vhost_dev_lock); return -1; } vhost_devices[i] = dev; + pthread_mutex_unlock(&vhost_dev_lock); + dev->vid = i; dev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET; dev->slave_req_fd = -1; -- 2.29.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-02-09 10:34:58.320549798 +0000 +++ 0010-vhost-fix-vid-allocation-race.patch 2021-02-09 10:34:57.870583228 +0000 @@ -1 +1 @@ -From 9944bddf80d692ade5ef6f7326541b13881cbbb9 Mon Sep 17 00:00:00 2001 +From 9f014a02d2276f4fa38d112172d0d8635a06fab4 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 9944bddf80d692ade5ef6f7326541b13881cbbb9 ] + @@ -32 +33,0 @@ -Cc: stable@dpdk.org @@ -43 +44 @@ -index efb136edd1..52ab93d1ec 100644 +index b83cf639eb..4de588d752 100644