[PATCH bpf-next v4 0/2] bpf, x86: inline bpf_get_current_task() for x86_64

Menglong Dong posted 2 patches 3 weeks, 5 days ago
There is a newer version of this series
kernel/bpf/verifier.c                         | 29 +++++++++++++++
.../selftests/bpf/prog_tests/verifier.c       |  2 ++
.../selftests/bpf/progs/verifier_jit_inline.c | 35 +++++++++++++++++++
3 files changed, 66 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/verifier_jit_inline.c
[PATCH bpf-next v4 0/2] bpf, x86: inline bpf_get_current_task() for x86_64
Posted by Menglong Dong 3 weeks, 5 days ago
Inline bpf_get_current_task() and bpf_get_current_task_btf() for x86_64
to obtain better performance, and add the testcase for it.

I'd prefer to the approach in V2. The code is still architecture
specific, and now we implement it in the verifier.c, which is a little
weird for me.

What's more, it need 3 instructions with BPF_MOV64_PERCPU_REG():
  mov rax, &current_task
  addq rax, gs:[this_cpu_off]
  movq rax, rax[0]
which is 1 instruction in V2:
  movq rax, gs:[current_task]

Maybe we can implement a BPF_LDX_MEM_PERCPU() instead:
  #define BPF_LDX_MEM_PERCPU(dst, size, variable)
and use it with:
  BPF_LDX_MEM_PERCPU(BPF_REG_0, BPF_DW, current_task)
which will generate the instruction:
  movq rax, gs:[current_task]

Changes since v3:
* handle the !CONFIG_SMP case
* ignore the !CONFIG_SMP case in the testcase, as we enable CONFIG_SMP
  for x86_64 in the selftests

Changes since v2:
* implement it in the verifier with BPF_MOV64_PERCPU_REG() instead of in
  x86_64 JIT (Alexei).

Changes since v1:
* add the testcase
* remove the usage of const_current_task

Menglong Dong (2):
  bpf, x86: inline bpf_get_current_task() for x86_64
  selftests/bpf: test the jited inline of bpf_get_current_task

 kernel/bpf/verifier.c                         | 29 +++++++++++++++
 .../selftests/bpf/prog_tests/verifier.c       |  2 ++
 .../selftests/bpf/progs/verifier_jit_inline.c | 35 +++++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_jit_inline.c

-- 
2.52.0