BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
	Song Liu <songliubraving@fb.com>
Subject: Re: [PATCH bpf-next v3] bpf: using rcu_read_lock for bpf_sk_storage_map iterator
Date: Wed, 16 Sep 2020 15:43:03 -0700	[thread overview]
Message-ID: <b4db3cc4-ecdc-1372-183d-5e96dde2ca8b@fb.com> (raw)
In-Reply-To: <20200916175553.4fevmxgcv2r6nhiu@kafai-mbp>



On 9/16/20 10:55 AM, Martin KaFai Lau wrote:
> On Tue, Sep 15, 2020 at 11:16:49PM -0700, Yonghong Song wrote:
> [ ... ]
> 
>> diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
>> index 4a86ea34f29e..d43c3d6d0693 100644
>> --- a/net/core/bpf_sk_storage.c
>> +++ b/net/core/bpf_sk_storage.c
>> @@ -678,6 +678,7 @@ struct bpf_iter_seq_sk_storage_map_info {
>>   static struct bpf_local_storage_elem *
>>   bpf_sk_storage_map_seq_find_next(struct bpf_iter_seq_sk_storage_map_info *info,
>>   				 struct bpf_local_storage_elem *prev_selem)
>> +	__acquires(RCU) __releases(RCU)
>>   {
>>   	struct bpf_local_storage *sk_storage;
>>   	struct bpf_local_storage_elem *selem;
> In the while loop earlier in this function, if I read it correctly,
> it is sort of continuing the earlier hlist_for_each_entry_rcu() for the
> same bucket, so the hlist_entry_safe() needs to be changed also.
> Something like this (uncompiled code):
> 
>          while (selem) {
> -               selem = hlist_entry_safe(selem->map_node.next,
> +               selem = hlist_entry_safe(rcu_dereference(hlist_next_rcu(&selem->map_node)),
>                                           struct bpf_local_storage_elem, map_node);
>                  if (!selem) {
>                          /* not found, unlock and go to the next bucket */

Thanks and Ack. Will send v4 shortly.

> 
>> @@ -701,11 +702,11 @@ bpf_sk_storage_map_seq_find_next(struct bpf_iter_seq_sk_storage_map_info *info,
>>   		if (!selem) {
>>   			/* not found, unlock and go to the next bucket */
>>   			b = &smap->buckets[bucket_id++];
>> -			raw_spin_unlock_bh(&b->lock);
>> +			rcu_read_unlock();
>>   			skip_elems = 0;
>>   			break;
>>   		}
>> -		sk_storage = rcu_dereference_raw(selem->local_storage);
>> +		sk_storage = rcu_dereference(selem->local_storage);
>>   		if (sk_storage) {
>>   			info->skip_elems = skip_elems + count;
>>   			return selem;

      reply	other threads:[~2020-09-17 17:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16  6:16 [PATCH bpf-next v3] bpf: using rcu_read_lock for bpf_sk_storage_map iterator Yonghong Song
2020-09-16 17:55 ` Martin KaFai Lau
2020-09-16 22:43   ` Yonghong Song [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=b4db3cc4-ecdc-1372-183d-5e96dde2ca8b@fb.com \
    --to=yhs@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.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