netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: davem@davemloft.net, dsahern@kernel.org,
	Eric Dumazet <edumazet@google.com>,
	kraig@google.com, kuba@kernel.org, kuni1840@gmail.com,
	martin.lau@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com,
	willemb@google.com, yoshfuji@linux-ipv6.org
Subject: Re: [PATCH v2 net] udp: Update reuse->has_conns under reuseport_lock.
Date: Thu, 13 Oct 2022 10:41:53 -0700	[thread overview]
Message-ID: <c4f74864-0a6a-5075-891c-d20d0dc20f2f@linux.dev> (raw)
In-Reply-To: <CANn89iLja=eQHbsM_Ta2sQF0tOGU8vAGrh_izRuuHjuO1ouUag@mail.gmail.com>

On 10/13/22 9:09 AM, Eric Dumazet wrote:
>>>> diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
>>>> index 5daa1fa54249..abb414ed4aa7 100644
>>>> --- a/net/core/sock_reuseport.c
>>>> +++ b/net/core/sock_reuseport.c
>>>> @@ -21,6 +21,21 @@ static DEFINE_IDA(reuseport_ida);
>>>>   static int reuseport_resurrect(struct sock *sk, struct sock_reuseport *old_reuse,
>>>>                                 struct sock_reuseport *reuse, bool bind_inany);
>>>>
>>>> +void reuseport_has_conns_set(struct sock *sk)
>>>> +{
>>>> +       struct sock_reuseport *reuse;
>>>> +
>>>> +       if (!rcu_access_pointer(sk->sk_reuseport_cb))
>>>> +               return;
>>>> +
>>>> +       spin_lock(&reuseport_lock);

It seems other paths are still using the spin_lock_bh().  It will be useful to 
have a few words here why _bh() is not needed.

>>>> +       reuse = rcu_dereference_protected(sk->sk_reuseport_cb,
>>>> +                                         lockdep_is_held(&reuseport_lock));
>>>
>>> Could @reuse be NULL at this point ?
>>>
>>> Previous  test was performed without reuseport_lock being held.
>>
>> Usually, sk_reuseport_cb is changed under lock_sock().
>>
>> The only exception is reuseport_grow() & TCP reqsk migration case.
>>
>> 1) shutdown() TCP listener, which is moved into the latter part of
>>     reuse->socks[] to migrate reqsk.
>>
>> 2) New listen() overflows reuse->socks[] and call reuseport_grow().
>>
>> 3) reuse->max_socks overflows u16 with the new listener.
>>
>> 4) reuseport_grow() pops the old shutdown()ed listener from the array
>>     and update its sk->sk_reuseport_cb as NULL without lock_sock().
>>
>> shutdown()ed sk->sk_reuseport_cb can be changed without lock_sock().
>>
>> But, reuseport_has_conns_set() is called only for UDP and under
>> lock_sock(), so @reuse never be NULL in this case.
> 
> Given the complexity of this code and how much time is needed to
> review all possibilities, please add an additional
> 
> if (reuse)
>     reuse->has_conns = 1;

+1


  parent reply	other threads:[~2022-10-13 17:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12 18:52 [PATCH v2 net] udp: Update reuse->has_conns under reuseport_lock Kuniyuki Iwashima
2022-10-12 18:59 ` Eric Dumazet
2022-10-12 19:27   ` Kuniyuki Iwashima
2022-10-13 16:09     ` Eric Dumazet
2022-10-13 16:51       ` Kuniyuki Iwashima
2022-10-13 17:41       ` Martin KaFai Lau [this message]
2022-10-13 18:46         ` Kuniyuki Iwashima

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=c4f74864-0a6a-5075-891c-d20d0dc20f2f@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kraig@google.com \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=kuniyu@amazon.com \
    --cc=martin.lau@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    --cc=yoshfuji@linux-ipv6.org \
    /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).