From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by dpdk.org (Postfix) with ESMTP id 533CF1B3C0 for ; Fri, 14 Dec 2018 11:07:14 +0100 (CET) Received: by mail-wr1-f65.google.com with SMTP id t6so4655986wrr.12 for ; Fri, 14 Dec 2018 02:07:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outscale-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xlHTcXWaNnFbLkivuE1cZuEdqLnzZm+RjKKCkwbfaU4=; b=FMDIv1QhLHz8dV07sDJ9uXHYl2Z3Fp4tC9gAL3Ez3ivRXHUargX/dkXf9Eup+uUvDv 6QrwfclWMJkRnyqBnCBn9T3iygBQvItEyqdwlBaP2NEirTsFX6hzN3pm6tSKYzzvz7VN XuHIDhHIqLiFD3IO2KRCw8iAwC1J1cK/7T7qGZOU5XR7nMuv+fLMJxJigNmwW+DiB7d9 fLuDNmpM6NQkJEgHeY5v9HGoExsk/+EzcOGrahq2pyj5OenFR4cTxy/wX2A6V4KlO/cE FVbE1sgKfDxiEy6aLUJWezAzgd3xzzSukSoznwJY9xwRZzm9QHzu/+rMa1bLi8ZubZDO eccg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xlHTcXWaNnFbLkivuE1cZuEdqLnzZm+RjKKCkwbfaU4=; b=CiLJfgyipzgQj7sH9mUp0fsCttCL88CG4zo2R/mBfNDy9VJ6zuIxabruQCd6Gj+A2p 9QkT3gcPGcwu/JjzkKypri2FCsf46USeggoO11KSajxTNbtdHMINs52hI0dGlwGy2cWL C9CELDOLB1X6ycYkClKIRv4OWmBwG9jZxSNiNqn/aDlnMYjmKWkiMkXV0W42mOwVOfkr +lvuY3TL1v7Nc6RE9V9P2gKxLlg4Hwofv/NrjDu/SFu33BEQdIOWkk5x0qJiaV6vy0jH pKawd1kyUYv2hmwsFDoCYNvUdnsqru64f6kq1itgI3/r9bH1OMdK10cp/lcaqxrow4wB eOSQ== X-Gm-Message-State: AA+aEWYy4tzwP3qRdJg2dvV1TQ3IHurP1BnpC0OaEqO5IG09B9/DWFyH mSQtJpQRBrtIQdWJxfTTm27JmTEP+4H552qMWolx7H+8Ux8= X-Google-Smtp-Source: AFSGD/XseOmIRyR3hCrwBc/t2q5CC8CeFIdJ5yV48Whbhp4ceDlRB4Oh/Xq0k6LEBVGUEaXvPqtdiW9BYO52GZ7NHhM= X-Received: by 2002:a05:6000:120a:: with SMTP id e10mr2056742wrx.85.1544782034011; Fri, 14 Dec 2018 02:07:14 -0800 (PST) MIME-Version: 1.0 References: <1544112007-23177-1-git-send-email-matthias.gatto@outscale.com> <1f9db33f-b281-b794-bc00-ad83490c2fbd@redhat.com> <1fa47f8c-18a1-fbb4-1794-3324126cf9f1@redhat.com> In-Reply-To: <1fa47f8c-18a1-fbb4-1794-3324126cf9f1@redhat.com> From: Matthias Gatto Date: Fri, 14 Dec 2018 11:07:00 +0100 Message-ID: To: maxime.coquelin@redhat.com Cc: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com, stable@dpdk.org Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH] vhost: fix race condition in fdset_add 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: Fri, 14 Dec 2018 10:07:14 -0000 On Fri, Dec 14, 2018 at 10:53 AM Maxime Coquelin wrote: > > > > On 12/14/18 10:51 AM, Maxime Coquelin wrote: > > > > > > On 12/14/18 10:32 AM, Matthias Gatto wrote: > >> On Tue, Dec 11, 2018 at 7:11 PM Maxime Coquelin > >> wrote: > >>> > >>> Hi Matthias, > >>> > >>> On 12/6/18 5:00 PM, Matthias Gatto wrote: > >>>> fdset_add can call fdset_shrink_nolock which call fdset_move > >>>> concurrently to poll that is call in fdset_event_dispatch. > >>>> > >>>> This patch add a mutex to protect poll from been call at the same time > >>>> fdset_add call fdset_shrink_nolock. > >>>> > >>>> Signed-off-by: Matthias Gatto > >>>> --- > >>>> lib/librte_vhost/fd_man.c | 4 ++++ > >>>> lib/librte_vhost/fd_man.h | 1 + > >>>> lib/librte_vhost/socket.c | 1 + > >>>> 3 files changed, 6 insertions(+) > >>>> > >>>> diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c > >>>> index 38347ab..55d4856 100644 > >>>> --- a/lib/librte_vhost/fd_man.c > >>>> +++ b/lib/librte_vhost/fd_man.c > >>>> @@ -129,7 +129,9 @@ > >>>> pthread_mutex_lock(&pfdset->fd_mutex); > >>>> i = pfdset->num < MAX_FDS ? pfdset->num++ : -1; > >>>> if (i == -1) { > >>>> + pthread_mutex_lock(&pfdset->fd_pooling_mutex); > >>>> fdset_shrink_nolock(pfdset); > >>>> + pthread_mutex_unlock(&pfdset->fd_pooling_mutex); > >>>> i = pfdset->num < MAX_FDS ? pfdset->num++ : -1; > >>>> if (i == -1) { > >>>> pthread_mutex_unlock(&pfdset->fd_mutex); > >>>> @@ -246,7 +248,9 @@ > >>>> numfds = pfdset->num; > >>>> pthread_mutex_unlock(&pfdset->fd_mutex); > >>>> > >>>> + pthread_mutex_lock(&pfdset->fd_pooling_mutex); > >>>> val = poll(pfdset->rwfds, numfds, 1000 /* millisecs */); > >>>> + pthread_mutex_unlock(&pfdset->fd_pooling_mutex); > >>> > >>> Any reason we cannot use the existing fd_mutex? > >> > >> yes, using the existing fd_mutex would block fdset_add during the > >> polling in > >> fdset_event_dispatch. > >> > >> here fd_pooling_mutex block only fdset_shrink_nolock inside > >> fdset_add which happen only in very rare occasions. > > > > > > Thanks for the clarification: > > > > Reviewed-by: Maxime Coquelin > > I guess we need to cc: stable, can you help with specifying which > commit it fixes? > > Thanks in advance, > Maxime > this commit 1b815b89599cdd9b54e5aa70f5b97088225b2bcc which was actually a commit I've made, sorry for that. Thanks for the review, Matthias > > Maxime