netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 1/2] bpf: set inner_map_meta->spin_lock_off correctly
Date: Thu, 28 Feb 2019 00:40:08 +0000	[thread overview]
Message-ID: <e02db95d-107d-79b4-653c-c3a4436b7376@fb.com> (raw)
In-Reply-To: <CAEf4BzZE8W7_VnoPTBftMUjuhVOTFmfWZS8kihPFjqZ+tP5N6w@mail.gmail.com>



On 2/27/19 4:28 PM, Andrii Nakryiko wrote:
> On Wed, Feb 27, 2019 at 4:19 PM Yonghong Song <yhs@fb.com> wrote:
>>
>>
>>
>> On 2/27/19 3:34 PM, Andrii Nakryiko wrote:
>>> On Wed, Feb 27, 2019 at 1:23 PM Yonghong Song <yhs@fb.com> wrote:
>>>>
>>>> Commit d83525ca62cf ("bpf: introduce bpf_spin_lock")
>>>> introduced bpf_spin_lock and the field spin_lock_off
>>>> in kernel internal structure bpf_map has the following
>>>> meaning:
>>>>     >=0 valid offset, <0 error
>>>>
>>>> For every map created, the kernel will ensure
>>>> spin_lock_off has correct value.
>>>>
>>>> Currently, bpf_map->spin_lock_off is not copied
>>>> from the inner map to the map_in_map inner_map_meta
>>>> during a map_in_map type map creation, so
>>>> inner_map_meta->spin_lock_off = 0.
>>>> This will give verifier wrong information that
>>>> inner_map has bpf_spin_lock and the bpf_spin_lock
>>>> is defined at offset 0. An access to offset 0
>>>> of a value pointer will trigger the following error:
>>>>      bpf_spin_lock cannot be accessed directly by load/store
>>>>
>>>> This patch fixed the issue by copy inner map's spin_lock_off
>>>> value to inner_map_meta->spin_lock_off.
>>>>
>>>> Fixes: d83525ca62cf ("bpf: introduce bpf_spin_lock")
>>>> Signed-off-by: Yonghong Song <yhs@fb.com>
> 
> Acked-by: Andrii Nakryiko <andriin@fb.com>
> 
>>>> ---
>>>>    kernel/bpf/map_in_map.c | 1 +
>>>>    1 file changed, 1 insertion(+)
>>>>
>>>> diff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c
>>>> index 583346a0ab29..3dff41403583 100644
>>>> --- a/kernel/bpf/map_in_map.c
>>>> +++ b/kernel/bpf/map_in_map.c
>>>> @@ -58,6 +58,7 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
>>>>           inner_map_meta->value_size = inner_map->value_size;
>>>>           inner_map_meta->map_flags = inner_map->map_flags;
>>>>           inner_map_meta->max_entries = inner_map->max_entries;
>>>> +       inner_map_meta->spin_lock_off = inner_map->spin_lock_off;
>>>
>>> Looks like spinlock inside inner map is not supported: there is
>>> specific check few lines above returning -ENOSUPP for such case. In
>>> that case, maybe assign -1 here to make this explicit?
>>
>> -1 (-EPERM) probably not the best choice. The verifier already has
>> knowledge that a particular tracked map is an inner map or not. So
>> keeping the original error code (mostly -EINVAL) is preferred I think.
> 
> Ah, I actually missed the fact that verifier actually checks those
> values (so it's not just >= 0 or < 0), so yeah, let's just pass
> through. Btw, the value when there is no spinlock is actually -ENOENT.

If there is no BTF, it will be -EINVAL. If there is BTF and no spinlock 
member, mostly -ENOENT.

> 
>>
>>>
>>> Though I guess that also brings up the question: is there any harm in
>>> supporting spin lock for inner map and why it was disabled in the
>>> first place?
>>
>> Not exactly sure about the reason. Maybe with this patch, it can get
>> proper support. Not 100% sure.
> 
> No, it won't, because bpf_map_meta_alloc explicitly tests for it:
> 
>          if (map_value_has_spin_lock(inner_map)) {
>                  fdput(f);
>                  return ERR_PTR(-ENOTSUPP);
>          }

I mean that this can be removed after my patch and it may work :-)

> 
> Maybe Alexei can clarify?
> 
> 
>>
>>>
>>>>
>>>>           /* Misc members not needed in bpf_map_meta_equal() check. */
>>>>           inner_map_meta->ops = inner_map->ops;
>>>> --
>>>> 2.17.1
>>>>

  reply	other threads:[~2019-02-28  0:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 21:22 [PATCH bpf-next 0/2] bpf: set inner_map_meta->spin_lock_off correctly Yonghong Song
2019-02-27 21:22 ` [PATCH bpf-next 1/2] " Yonghong Song
2019-02-27 23:34   ` Andrii Nakryiko
2019-02-28  0:19     ` Yonghong Song
2019-02-28  0:28       ` Andrii Nakryiko
2019-02-28  0:40         ` Yonghong Song [this message]
2019-02-28  0:43           ` Andrii Nakryiko
2019-02-28  0:56         ` Alexei Starovoitov
2019-02-27 21:22 ` [PATCH bpf-next 2/2] tools/bpf: selftests: add map lookup to test_map_in_map bpf prog Yonghong Song
2019-02-27 23:36   ` Andrii Nakryiko
2019-02-28  1:07 ` [PATCH bpf-next 0/2] bpf: set inner_map_meta->spin_lock_off correctly Alexei Starovoitov

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=e02db95d-107d-79b4-653c-c3a4436b7376@fb.com \
    --to=yhs@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.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).