From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-f67.google.com (mail-oi0-f67.google.com [209.85.218.67]) by dpdk.org (Postfix) with ESMTP id D39631559; Wed, 5 Sep 2018 10:11:29 +0200 (CEST) Received: by mail-oi0-f67.google.com with SMTP id t68-v6so11946717oie.12; Wed, 05 Sep 2018 01:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=xme7G/t2U3o+9JOseGkS9X4VJ/1GOLojbn8EK4wZpss=; b=lScw6zFBCLS+/rfkVEtsq2wm1AaKPXre1qAMYf+cLTeV3sFH43TXjkni8snC5V6lkQ r2wFlTff6LVIDo2oJv2Bq2r9jbsH/m1w+RSESUuzsSjm1YjMp2J5z2pafMggDpcQhHRj Iw7fpKv3m9Ct61iwNLfHpAavVSHhfQbgFOehZE0kqyWawyzRkRcwPQDuAnCv3QHlmuk6 42jqMyNYtZ2rIEON1bbSbPO8iMuftwn8USGYhF/9tdYbkiSnu2AbOATExkq3mux2elz1 GdqEcLbmBFB3WdIb0Pz8eaMBw+HQwGJxPogo5jp1oABI1K04QZwFPaIcf7LwL8Wi9gUy TmOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=xme7G/t2U3o+9JOseGkS9X4VJ/1GOLojbn8EK4wZpss=; b=TkETQ8vF5sRbxFUiuntQVBl1KJTRF7YhOFeoyJm9k72G1CF2ymBRAeQyOof/QBtH/s rgy5hOomHY/l9lto8kbIwXQ3VoJ5PHxsZnnSRrM28FhkGOMiGq1UXGbP3RF+XVc538TN gvAeYCOk+A2Lld0GL1FG7ynWtlYUMvrmzEzUYC9f9UFLp6f2Dy12LlO9kx9FQ330Rm+f ubr5CiipTnOSzrGMlRlVWWdM3alBnK/gj9XLsRsa8E7lyBCyJW6sjCcMjfko4sfBL0GE NAOJuM30sl35qxo3vISGQrEd0yXkeWb0WaLTlpPAfKh7oDgTM4xcoaq6DDYUpNqv9stR bOGw== X-Gm-Message-State: APzg51BC0SsLTI71GDQdAYkUMmmYIyVgiS+caXOJUAuHtKY79EZ+aTwj SWBRwntpi87Qu/H9ybEgxv/dzhKX9RNg627Suzs= X-Google-Smtp-Source: ANB0VdYkdbSmpAlnqfZBdy1BOp91ArAXgIkl1QSFokNJXcOyTI8MvdkpO8am/YMwRf8TimwlW6dduP8NTr5uvv66+BY= X-Received: by 2002:aca:5714:: with SMTP id l20-v6mr30881921oib.100.1536135089309; Wed, 05 Sep 2018 01:11:29 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:373:0:0:0:0:0 with HTTP; Wed, 5 Sep 2018 01:10:48 -0700 (PDT) In-Reply-To: <20180905042852.6212-2-tiwei.bie@intel.com> References: <20180905042852.6212-1-tiwei.bie@intel.com> <20180905042852.6212-2-tiwei.bie@intel.com> From: Sean Harte Date: Wed, 5 Sep 2018 09:10:48 +0100 Message-ID: To: Tiwei Bie Cc: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org, anatoly.burakov@intel.com, stable@dpdk.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] [PATCH 1/3] net/virtio-user: fix deadlock in memory events callback 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: , X-List-Received-Date: Wed, 05 Sep 2018 08:11:31 -0000 On 5 September 2018 at 05:28, Tiwei Bie wrote: > 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") > Cc: stable@dpdk.org > > Reported-by: Se=C3=A1n Harte > Signed-off-by: Tiwei Bie > --- > 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 b2444096c..897fee0af 100644 > --- a/drivers/net/virtio/virtio_user/vhost_kernel.c > +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c > @@ -115,7 +115,11 @@ prepare_vhost_memory_kernel(void) > wa.region_nr =3D 0; > wa.vm =3D 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/n= et/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 > @@ -13,6 +13,8 @@ > #include > #include > > +#include > + > #include "vhost.h" > #include "virtio_user_dev.h" > #include "../virtio_ethdev.h" > @@ -109,9 +111,24 @@ is_vhost_user_by_type(const char *path) > int > virtio_user_start_device(struct virtio_user_dev *dev) > { > + struct rte_mem_config *mcfg =3D 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); > > if (is_vhost_user_by_type(dev->path) && dev->vhostfd < 0) > @@ -152,10 +169,12 @@ virtio_user_start_device(struct virtio_user_dev *de= v) > > dev->started =3D 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.18.0 > Tested-by: Se=C3=A1n Harte Reviewed-by: Se=C3=A1n Harte