BPF List
 help / color / mirror / Atom feed
From: Leon Hwang <hffilwlqm@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	maciej.fijalkowski@intel.com, jakub@cloudflare.com,
	iii@linux.ibm.com, hengqi.chen@gmail.com, hffilwlqm@gmail.com,
	kernel-patches-bot@fb.com
Subject: [PATCH bpf-next v2 0/2] bpf, x64: Fix tailcall hierarchy
Date: Thu, 22 Feb 2024 16:52:30 +0800	[thread overview]
Message-ID: <20240222085232.62483-1-hffilwlqm@gmail.com> (raw)

The patchset fixes a tailcall hierarchy issue.

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

But, the issue is only resolved on x86.

Hopefully, the issue on aarch64 and s390x will be resolved soon.

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

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

In short, it uses PERCPU tail_call_cnt to store the temporary tail_call_cnt.

First, at the prologue of bpf prog, it initialise the PERCPU
tail_call_cnt by setting current CPU's tail_call_cnt to 0.

Then, when a tailcall happens, it fetches and increments current CPU's
tail_call_cnt, and compares to MAX_TAIL_CALL_CNT.

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/6476/checks

Leon Hwang (2):
  bpf, x64: Fix tailcall hierarchy
  selftests/bpf: Add testcases for tailcall hierarchy fixing

 arch/x86/net/bpf_jit_comp.c                   | 128 +++---
 .../selftests/bpf/prog_tests/tailcalls.c      | 418 ++++++++++++++++++
 .../bpf/progs/tailcall_bpf2bpf_hierarchy1.c   |  34 ++
 .../bpf/progs/tailcall_bpf2bpf_hierarchy2.c   |  55 +++
 .../bpf/progs/tailcall_bpf2bpf_hierarchy3.c   |  46 ++
 5 files changed, 624 insertions(+), 57 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: 499e99ea0e8020bfc84b2327d4c37e45dc40bbd1
-- 
2.42.1


             reply	other threads:[~2024-02-22  8:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22  8:52 Leon Hwang [this message]
2024-02-22  8:52 ` [PATCH bpf-next v2 1/2] bpf, x64: Fix tailcall hierarchy Leon Hwang
2024-02-22 10:59   ` Leon Hwang
2024-02-23  4:06   ` Pu Lehui
2024-02-23 15:30     ` Leon Hwang
2024-02-23 16:35       ` Alexei Starovoitov
2024-02-26 15:32         ` Leon Hwang
2024-02-26 16:04           ` Leon Hwang
2024-02-26 22:12           ` Alexei Starovoitov
2024-02-28 14:30             ` Leon Hwang
2024-03-29 18:49               ` Alexei Starovoitov
2024-02-23 17:21   ` Alexei Starovoitov
2024-02-22  8:52 ` [PATCH bpf-next v2 2/2] selftests/bpf: Add testcases for tailcall hierarchy fixing Leon Hwang

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=20240222085232.62483-1-hffilwlqm@gmail.com \
    --to=hffilwlqm@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hengqi.chen@gmail.com \
    --cc=iii@linux.ibm.com \
    --cc=jakub@cloudflare.com \
    --cc=kernel-patches-bot@fb.com \
    --cc=maciej.fijalkowski@intel.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