patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: Matthias Gatto <matthias.gatto@outscale.com>
Cc: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com,
	stable@dpdk.org
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH] vhost: fix race condition in fdset_add
Date: Fri, 14 Dec 2018 11:08:52 +0100	[thread overview]
Message-ID: <7a7a3181-1529-dd5f-b95f-9f8fef77fa8f@redhat.com> (raw)
In-Reply-To: <CAAsw5Bd_rvrK=LCbFo-FX0o-VHXqgNG-CEA1e6SQfu-arELTCQ@mail.gmail.com>



On 12/14/18 11:07 AM, Matthias Gatto wrote:
> On Fri, Dec 14, 2018 at 10:53 AM Maxime Coquelin
> <maxime.coquelin@redhat.com> 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
>>>> <maxime.coquelin@redhat.com> 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 <matthias.gatto@outscale.com>
>>>>>> ---
>>>>>>     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 <maxime.coquelin@redhat.com>
>>
>> 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.

Don't be sorry, your contributions are welcome!
I'll fixup the commit message with adding Fixes line.

Thanks,
Maxime

> Thanks for the review,
> 
> Matthias
>>> Maxime

      reply	other threads:[~2018-12-14 10:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1544112007-23177-1-git-send-email-matthias.gatto@outscale.com>
     [not found] ` <a5a9c7bb-3950-5248-84d3-cfe3a2961fe6@redhat.com>
     [not found]   ` <CAAsw5BcCVv-tthNgpqrOgg_HT5kw486=C4Dvn_XO6G8KOQtSug@mail.gmail.com>
     [not found]     ` <1f9db33f-b281-b794-bc00-ad83490c2fbd@redhat.com>
     [not found]       ` <1fa47f8c-18a1-fbb4-1794-3324126cf9f1@redhat.com>
2018-12-14 10:07         ` Matthias Gatto
2018-12-14 10:08           ` Maxime Coquelin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a7a3181-1529-dd5f-b95f-9f8fef77fa8f@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=dev@dpdk.org \
    --cc=matthias.gatto@outscale.com \
    --cc=stable@dpdk.org \
    --cc=tiwei.bie@intel.com \
    --cc=zhihong.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).