From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 126F92BD5 for ; Tue, 20 Nov 2018 20:16:05 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F31CC04FFEB; Tue, 20 Nov 2018 19:16:04 +0000 (UTC) Received: from ktraynor.remote.csb (unknown [10.36.118.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBA36601A6; Tue, 20 Nov 2018 19:15:59 +0000 (UTC) From: Kevin Traynor To: Tiwei Bie Cc: =?UTF-8?q?Se=C3=A1n=20Harte?= , Anatoly Burakov , Maxime Coquelin , dpdk stable Date: Tue, 20 Nov 2018 19:12:47 +0000 Message-Id: <20181120191252.30277-57-ktraynor@redhat.com> In-Reply-To: <20181120191252.30277-1-ktraynor@redhat.com> References: <20181120191252.30277-1-ktraynor@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 20 Nov 2018 19:16:04 +0000 (UTC) Subject: [dpdk-stable] patch 'net/virtio-user: fix deadlock in memory events callback' has been queued to stable release 18.08.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Nov 2018 19:16:05 -0000 Hi, FYI, your patch has been queued to stable release 18.08.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 11/23/18. 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. If the code is different (ie: not only metadata diffs), due for example to a change in context or macro names, please double check it. Thanks. Kevin Traynor --- >>From 9a3059147371629a60cd19ce9cd78643616de9ae Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Wed, 5 Sep 2018 12:28:50 +0800 Subject: [PATCH] net/virtio-user: fix deadlock in memory events callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ upstream commit 7ff269575bd144482d56a20fec61187f1af15dda ] Deadlock can occur when allocating memory if a vhost-kernel based virtio-user device is in use. To fix the deadlock, we will take memory hotplug lock explicitly in virtio-user when necessary, and always call the _thread_unsafe memory functions. Bugzilla ID: 81 Fixes: 12ecb2f63b12 ("net/virtio-user: support memory hotplug") Reported-by: Seán Harte Signed-off-by: Tiwei Bie Tested-by: Seán Harte Reviewed-by: Seán Harte Reviewed-by: Anatoly Burakov Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/vhost_kernel.c | 6 +++++- .../net/virtio/virtio_user/virtio_user_dev.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c index d1be82162..a93fe5b28 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -116,5 +116,9 @@ prepare_vhost_memory_kernel(void) wa.vm = vm; - if (rte_memseg_contig_walk(add_memory_region, &wa) < 0) { + /* + * The memory lock has already been taken by memory subsystem + * or virtio_user_start_device(). + */ + if (rte_memseg_contig_walk_thread_unsafe(add_memory_region, &wa) < 0) { free(vm); return NULL; diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 7df600b02..869e96f87 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -14,4 +14,6 @@ #include +#include + #include "vhost.h" #include "virtio_user_dev.h" @@ -110,7 +112,22 @@ int virtio_user_start_device(struct virtio_user_dev *dev) { + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; uint64_t features; int ret; + /* + * XXX workaround! + * + * We need to make sure that the locks will be + * taken in the correct order to avoid deadlocks. + * + * Before releasing this lock, this thread should + * not trigger any memory hotplug events. + * + * This is a temporary workaround, and should be + * replaced when we get proper supports from the + * memory subsystem in the future. + */ + rte_rwlock_read_lock(&mcfg->memory_hotplug_lock); pthread_mutex_lock(&dev->mutex); @@ -153,8 +170,10 @@ virtio_user_start_device(struct virtio_user_dev *dev) dev->started = true; pthread_mutex_unlock(&dev->mutex); + rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock); return 0; error: pthread_mutex_unlock(&dev->mutex); + rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock); /* TODO: free resource here or caller to check */ return -1; -- 2.19.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2018-11-20 17:53:08.832978388 +0000 +++ 0057-net-virtio-user-fix-deadlock-in-memory-events-callba.patch 2018-11-20 17:53:07.000000000 +0000 @@ -1,4 +1,4 @@ -From 7ff269575bd144482d56a20fec61187f1af15dda Mon Sep 17 00:00:00 2001 +From 9a3059147371629a60cd19ce9cd78643616de9ae Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Wed, 5 Sep 2018 12:28:50 +0800 Subject: [PATCH] net/virtio-user: fix deadlock in memory events callback @@ -6,6 +6,8 @@ Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit +[ upstream commit 7ff269575bd144482d56a20fec61187f1af15dda ] + Deadlock can occur when allocating memory if a vhost-kernel based virtio-user device is in use. To fix the deadlock, we will take memory hotplug lock explicitly in virtio-user @@ -14,7 +16,6 @@ Bugzilla ID: 81 Fixes: 12ecb2f63b12 ("net/virtio-user: support memory hotplug") -Cc: stable@dpdk.org Reported-by: Seán Harte Signed-off-by: Tiwei Bie