All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/3] bpf, x64: Fix tailcall hierarchy
@ 2024-04-02 15:26 Leon Hwang
  2024-04-02 15:26 ` [PATCH bpf-next v3 1/3] bpf: Add bpf_tail_call_cnt to task_struct Leon Hwang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Leon Hwang @ 2024-04-02 15:26 UTC (permalink / raw
  To: bpf
  Cc: ast, daniel, andrii, maciej.fijalkowski, jakub, pulehui,
	hengqi.chen, hffilwlqm, kernel-patches-bot

The patchset fixes a tailcall hierarchy issue.

The issue is confirmed in the discussions of "bpf, x64: Fix tailcall infinite
loop"[0].

The issue is only resolved on x86.

This CI history[1] confirms the issue on aarch64.

I provide a long commit message in the second patch to describe how the issue
happens and how this patchset resolves the issue in details.

In short, it stores tail_call_cnt at task_struct.

First, at the prologue of bpf prog, it initialise the tail_call_cnt at
task_struct like "current->bpf_tail_call_cnt = 0;".

Then, when a tailcall happens, it compares the tail_call_cnt with
MAX_TAIL_CALL_CNT, and then increment it.

v2 -> v3:
  * Solution changes from percpu tail_call_cnt to tail_call_cnt at task_struct.

v1 -> v2:
  * Solution changes from extra run-time call insn to percpu tail_call_cnt.
  * Address comments from Alexei:
    * Use percpu tail_call_cnt.
    * Use asm to make sure no callee saved registers are touched.

RFC v2 -> v1:
  * Solution changes from propagating tail_call_cnt with its pointer to extra
    run-time call insn.
  * Address comments from Maciej:
    * Replace all memcpy(prog, x86_nops[5], X86_PATCH_SIZE) with
        emit_nops(&prog, X86_PATCH_SIZE)

RFC v1 -> RFC v2:
  * Address comments from Stanislav:
    * Separate moving emit_nops() as first patch.

Links:
[0] https://lore.kernel.org/bpf/6203dd01-789d-f02c-5293-def4c1b18aef@gmail.com/
[1] https://github.com/kernel-patches/bpf/pull/6721/checks

Leon Hwang (3):
  bpf: Add bpf_tail_call_cnt to task_struct
  bpf, x64: Fix tailcall hierarchy
  selftests/bpf: Add testcases for tailcall hierarchy fixing

 arch/x86/net/bpf_jit_comp.c                   | 137 +++---
 include/linux/sched.h                         |   2 +
 .../selftests/bpf/prog_tests/tailcalls.c      | 418 ++++++++++++++++++
 .../bpf/progs/tailcall_bpf2bpf_hierarchy1.c   |  38 ++
 .../bpf/progs/tailcall_bpf2bpf_hierarchy2.c   |  63 +++
 .../bpf/progs/tailcall_bpf2bpf_hierarchy3.c   |  50 +++
 6 files changed, 652 insertions(+), 56 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy1.c
 create mode 100644 tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy2.c
 create mode 100644 tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy3.c


base-commit: 8f1ff3cf139bc1269eebae5d43ffbe482675f360
-- 
2.44.0


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

end of thread, other threads:[~2024-04-14 11:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-02 15:26 [PATCH bpf-next v3 0/3] bpf, x64: Fix tailcall hierarchy Leon Hwang
2024-04-02 15:26 ` [PATCH bpf-next v3 1/3] bpf: Add bpf_tail_call_cnt to task_struct Leon Hwang
2024-04-02 15:26 ` [PATCH bpf-next v3 2/3] bpf, x64: Fix tailcall hierarchy Leon Hwang
2024-04-05  1:03   ` Alexei Starovoitov
2024-04-07 11:34     ` Leon Hwang
2024-04-07 16:30       ` Alexei Starovoitov
2024-04-10 14:09         ` Leon Hwang
2024-04-11  3:42           ` Alexei Starovoitov
2024-04-14 11:47             ` Leon Hwang
2024-04-02 15:26 ` [PATCH bpf-next v3 3/3] selftests/bpf: Add testcases for tailcall hierarchy fixing Leon Hwang

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.