Netdev List
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Tariq Toukan <tariqt@mellanox.com>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, Eran Ben Elisha <eranbe@mellanox.com>,
	Jesper Dangaard Brouer <brouer@redhat.com>
Subject: Re: [PATCH net] net/xdp: Fix suspicious RCU usage warning
Date: Mon, 13 Aug 2018 01:04:40 +0200	[thread overview]
Message-ID: <e4310900-3f2e-3118-59fc-cc9aa5b0b1dc@iogearbox.net> (raw)
In-Reply-To: <44cb66c6-2542-3f6a-c426-5b1d1665ea61@mellanox.com>

On 08/12/2018 10:45 AM, Tariq Toukan wrote:
> 
> 
> On 20/07/2018 12:36 AM, Alexei Starovoitov wrote:
>> On Wed, Jul 18, 2018 at 05:13:54PM +0300, Tariq Toukan wrote:
>>>
>>>
>>> On 17/07/2018 10:27 PM, Daniel Borkmann wrote:
>>>> On 07/17/2018 06:47 PM, Alexei Starovoitov wrote:
>>>>> On Tue, Jul 17, 2018 at 06:10:38PM +0300, Tariq Toukan wrote:
>>>>>> Fix the warning below by calling rhashtable_lookup under
>>>>>> RCU read lock.
>>>>>>
>>>
>>> ...
>>>
>>>>>>        mutex_lock(&mem_id_lock);
>>>>>> +    rcu_read_lock();
>>>>>>        xa = rhashtable_lookup(mem_id_ht, &id, mem_id_rht_params);
>>>>>> +    rcu_read_unlock();
>>>>>>        if (!xa) {
>>>>>
>>>>> if it's an actual bug rcu_read_unlock seems to be misplaced.
>>>>> It silences the warn, but rcu section looks wrong.
>>>>
>>>> I think that whole piece in __xdp_rxq_info_unreg_mem_model() should be:
>>>>
>>>>     mutex_lock(&mem_id_lock);
>>>>     xa = rhashtable_lookup_fast(mem_id_ht, &id, mem_id_rht_params);
>>>>     if (xa && rhashtable_remove_fast(mem_id_ht, &xa->node, mem_id_rht_params) == 0)
>>>>             call_rcu(&xa->rcu, __xdp_mem_allocator_rcu_free);
>>>>     mutex_unlock(&mem_id_lock);
>>>>
>>>> Technically the RCU read side plus rhashtable_lookup() is the same, but lets
>>>> use proper api. From the doc (https://lwn.net/Articles/751374/) object removal
>>>> is wrapped around the RCU read side additionally, but in our case we're behind
>>>> mem_id_lock for insertion/removal serialization.
>>>>
>>>> Cheers,
>>>> Daniel
>>>>
>>>
>>> Just as Daniel stated, I think there's no actual bug here, but we still want
>>> to silence the RCU warning.
>>>
>>> Alexei, did you mean getting the if statement into the RCU lock critical
>>> section?
>>
>> If what Daniel proposes silences the warn, I'd rather do that.
>> Pattern like:
>>    rcu_lock;
>>    val = lookup();
>>    rcu_unlock;
>>    if (val)
>> will cause people to question the quality of the code and whether
>> authors of the code understand rcu.
>> There should be a way to silence the warn without adding
>> "wrong on the first glance" code.
> 
> I'm re-spinning this.
> Can it still go to net, or better send it to bpf-next ?

Please rebase against bpf-next and we route it to stable, thanks!

  reply	other threads:[~2018-08-13  1:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-17 15:10 [PATCH net] net/page_pool: Fix inconsistent lock state warning Tariq Toukan
2018-07-17 15:10 ` [PATCH net] net/xdp: Fix suspicious RCU usage warning Tariq Toukan
2018-07-17 16:47   ` Alexei Starovoitov
2018-07-17 19:27     ` Daniel Borkmann
2018-07-18 14:13       ` Tariq Toukan
2018-07-19 21:36         ` Alexei Starovoitov
2018-08-12  8:45           ` Tariq Toukan
2018-08-12 23:04             ` Daniel Borkmann [this message]
2018-07-20  6:23 ` [PATCH net] net/page_pool: Fix inconsistent lock state warning David Miller

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=e4310900-3f2e-3118-59fc-cc9aa5b0b1dc@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=alexei.starovoitov@gmail.com \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eranbe@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=tariqt@mellanox.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