bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: haoluo@google.com, Andrii Nakryiko <andriin@fb.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, bpf <bpf@vger.kernel.org>,
	olegrom@google.com, Martin KaFai Lau <kafai@fb.com>
Subject: Re: accessing global and per-cpu vars
Date: Thu, 21 May 2020 11:58:47 -0700	[thread overview]
Message-ID: <CAEf4BzZVVgMbNE4d7b5kPUoWPJz-ENgyP1BfC+h-X29r1Pk2fA@mail.gmail.com> (raw)
In-Reply-To: <CAADnVQJwqH2XFnTeXLnqbONtaU3akNh9BZ-tXk8r=NcGGY_noQ@mail.gmail.com>

On Thu, May 21, 2020 at 10:07 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> 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.

yep

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

I thought we'd do that based on section name? Or we will actually
teach pahole to extract kallsyms from vmlinux image?

There was step 1.5 (or even 0.5) to see if it's feasible to add not
just per-CPU variables as well.

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

yep

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

separate helper sounds better to me, both from usability stand point,
as well as not using extra register unnecessarily

  reply	other threads:[~2020-05-21 18:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 17:03 accessing global and per-cpu vars Alexei Starovoitov
2020-05-21 18:58 ` Andrii Nakryiko [this message]
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

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=CAEf4BzZVVgMbNE4d7b5kPUoWPJz-ENgyP1BfC+h-X29r1Pk2fA@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=acme@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andriin@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=kafai@fb.com \
    --cc=olegrom@google.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;
as well as URLs for NNTP newsgroup(s).