bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* accessing global and per-cpu vars
@ 2020-05-21 17:03 Alexei Starovoitov
  2020-05-21 18:58 ` Andrii Nakryiko
  0 siblings, 1 reply; 6+ messages in thread
From: Alexei Starovoitov @ 2020-05-21 17:03 UTC (permalink / raw)
  To: haoluo, Andrii Nakryiko, Arnaldo Carvalho de Melo,
	Daniel Borkmann, bpf, olegrom, Martin KaFai Lau

Hi,

here are my notes from the bpf office hours today.
Does it sound as what we discussed?

Steps to add incremental support to global vars:
1. teach libbpf to replace "ld_imm64 rX, foo" with absolute address
of var "foo" by reading that value from kallsyms.
From the verifier point of view ld_imm64 instruction will look like it's
assigning large constant into a register.
The bpf prog would need to use bpf_probe_read_kernel()
to further access vars.

2. teach pahole to store ' A ' annotated kallsyms into vmlinux BTF as
BTF_KIND_VAR.
There are ~300 of them, so should be minimal increase in size.

3. teach libbpf to scan vmlinux BTF for vars and replace "ld_imm64 rX, foo"
with BPF_PSEUDO_BTF_ID.
From the verifier point of view 'ld_imm64 rX, 123 // pseudo_btf_id'
will be similar to ld_imm64 with pseudo_map_fd and pseudo_map_value.
The verifier will check btf_id and replace that with actual kernel address
at program load time. It will also know that exact type of 'rX' from there on.
That gives big performance win since bpf prog will be able to use
direct load instructions to access vars.

4. add bpf_per_cpu(var, cpu) helper.
It will accept 'var' in R1 and the verifier will enforce that R1 is
PTR_TO_BTF_ID type
and it's BTF_KIND_VAR and it's in per-cpu datasec.
The return value from that helper will be normal PTR_TO_BTF_ID,
so subsequent load instruction can use it directly.
Would be nice to have this helper without BTF requirement,
but I don't see how to make it safe without BTF at the moment.
Similarly bpf_this_cpu_ptr(var) helper could be necessary or
we may fold it into cpu == BPF_F_CURRENT_CPU as a single helper.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-28 20:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-21 17:03 accessing global and per-cpu vars Alexei Starovoitov
2020-05-21 18:58 ` Andrii Nakryiko
2020-05-22 14:28   ` Arnaldo Carvalho de Melo
     [not found]     ` <CA+khW7j=ejncVYgY=hKEnkrkwA=Wjwa6Y2PFWgzrV1EV_8rvpw@mail.gmail.com>
2020-05-26 18:20       ` Andrii Nakryiko
     [not found]         ` <CA+khW7ha-5YSgm5kARO=+JEtf-Ahmc1N_TBJ2iLSntk12pfy3w@mail.gmail.com>
     [not found]           ` <CA+khW7hqemc+xsbMQq-DW3X+mHKO+Lm64hNpWNRyZ75MkUa0Gg@mail.gmail.com>
2020-05-28 20:58             ` Arnaldo Carvalho de Melo
2020-05-28 20:58             ` Andrii Nakryiko

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).