All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@meta.com>
To: John Fastabend <john.fastabend@gmail.com>,
	Yonghong Song <yhs@meta.com>, Yonghong Song <yhs@fb.com>,
	bpf@vger.kernel.org, alan.maguire@oracle.com
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com, Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v4 0/4] bpf: Implement two type cast kfuncs
Date: Wed, 23 Nov 2022 12:46:33 -0800	[thread overview]
Message-ID: <13196687-fc16-f690-e2cb-f051aabae228@meta.com> (raw)
In-Reply-To: <637d911914799_2b649208da@john.notmuch>

On 11/22/22 7:18 PM, John Fastabend wrote:
> Alexei Starovoitov wrote:
>> On 11/21/22 5:48 PM, John Fastabend wrote:
>>> Yonghong Song wrote:
>>>>
>>>>
>>>> On 11/20/22 6:10 PM, John Fastabend wrote:
>>>>> Yonghong Song wrote:
>>>>>> Currenty, a non-tracing bpf program typically has a single 'context' argument
>>>>>> with predefined uapi struct type. Following these uapi struct, user is able
>>>>>> to access other fields defined in uapi header. Inside the kernel, the
>>>>>> user-seen 'context' argument is replaced with 'kernel context' (or 'kctx'
>>>>>> in short) which can access more information than what uapi header provides.
>>>>>> To access other info not in uapi header, people typically do two things:
>>>>>>      (1). extend uapi to access more fields rooted from 'context'.
>>>>>>      (2). use bpf_probe_read_kernl() helper to read particular field based on
>>>>>>        kctx.
>>>
>>> [...]
>>>
>>>>>    From myside this allows us to pull in the dev info and from that get
>>>>> netns so fixes a gap we had to split into a kprobe + xdp.
>>>>>
>>>>> If we can get a pointer to the recv queue then with a few reads we
>>>>> get the hash, vlan, etc. (see timestapm thread)
>>>>
>>>> Thanks, John. Glad to see it is useful.
>>>>
>>>>>
>>>>> And then last bit is if we can get a ptr to the net ns list, plus
>>>>
>>>> Unfortunately, currently vmlinux btf does not have non-percpu global
>>>> variables, so net_namespace_list is not available to bpf programs.
>>>> But I think we could do the following with a little bit user space
>>>> initial involvement as a workaround.
>>>
>>> What would you think of another kfunc, bpf_get_global_var() to fetch
>>> the global reference and cast it with a type? I think even if you
>>> had it in BTF you would still need some sort of helper otherwise
>>> how would you know what scope of the var should be and get it
>>> correct in type checker as a TRUSTED arg? I think for my use case
>>> UNTRUSTED is find, seeing we do it with probe_reads already, but
>>> getting a TRUSTED arg seems nicer given it can be known correct
>>> from kernel side.
>>>
>>> I was thinking something like,
>>>
>>>     struct net *head = bpf_get_global_var(net_namespace_list,
>>> 				bpf_core_type_id_kernel(struct *net));
>>
>> We cannot do this as ptr_trusted, since it's an unknown cast.
> 
> I think you _could_ do it if the kfunc new to check the case type
> and knew that net_namespace_list should return that specific global.
> The verifier would special code that var and type.

Hard code it in the verifier just for one or two variables? Ouch.
Let's see whether all export_symbol_gpl can work.

>> The verifier cannot trust bpf prog to do the right thing.
>> But we can enable this buy adding export_symbol_gpl global vars to BTF.
>> Then they will be trusted and their types correct.
>> Pretty much like per-cpu variables.
>>
> 
> Yep this is the more generic way and sounds better to me. Anyone
> working on adding the global var to BTF now?

Alan Maguire looked at it. cc-ing.


  reply	other threads:[~2022-11-23 20:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-20 19:54 [PATCH bpf-next v4 0/4] bpf: Implement two type cast kfuncs Yonghong Song
2022-11-20 19:54 ` [PATCH bpf-next v4 1/4] bpf: Add support for kfunc set with common btf_ids Yonghong Song
2022-11-20 19:54 ` [PATCH bpf-next v4 2/4] bpf: Add a kfunc to type cast from bpf uapi ctx to kernel ctx Yonghong Song
2022-11-20 19:54 ` [PATCH bpf-next v4 3/4] bpf: Add a kfunc for generic type cast Yonghong Song
2022-11-20 20:16   ` Alexei Starovoitov
2022-11-20 20:49     ` Kumar Kartikeya Dwivedi
2022-11-20 22:34       ` Alexei Starovoitov
2022-11-20 23:32         ` Alexei Starovoitov
2022-11-20 23:47           ` Alexei Starovoitov
2022-11-20 19:54 ` [PATCH bpf-next v4 4/4] bpf: Add type cast unit tests Yonghong Song
2022-11-21  0:00 ` [PATCH bpf-next v4 0/4] bpf: Implement two type cast kfuncs patchwork-bot+netdevbpf
2022-11-21  2:10 ` John Fastabend
2022-11-21 17:29   ` Yonghong Song
2022-11-22  1:48     ` John Fastabend
2022-11-22  4:52       ` Alexei Starovoitov
2022-11-23  3:18         ` John Fastabend
2022-11-23 20:46           ` Alexei Starovoitov [this message]
2022-11-29 16:30             ` Alan Maguire

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=13196687-fc16-f690-e2cb-f051aabae228@meta.com \
    --to=ast@meta.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=yhs@fb.com \
    --cc=yhs@meta.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.