The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Tiezhu Yang" <yangtiezhu@loongson.cn>,
	"Leon Huang Fu" <leon.huangfu@shopee.com>
Cc: "Leon Hwang" <leon.hwang@linux.dev>,
	"KaFai Wan" <kafai.wan@linux.dev>, <bpf@vger.kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Shuah Khan" <shuah@kernel.org>,
	"Puranjay Mohan" <puranjay@kernel.org>,
	"Anton Protopopov" <a.s.protopopov@gmail.com>,
	<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Subject: Re: [RFC PATCH bpf 1/6] bpf: Disallow interpreter fallback for user BPF_ADDR_SPACE_CAST insn
Date: Wed, 01 Jul 2026 11:47:30 -0700	[thread overview]
Message-ID: <DJNGIT00SJG4.3LBZ5DHQDHLHU@gmail.com> (raw)
In-Reply-To: <d369317a-e695-7b56-2efd-f53ec76c6688@loongson.cn>

On Wed Jul 1, 2026 at 2:07 AM PDT, Tiezhu Yang wrote:
> On 2026/7/1 下午4:04, Leon Huang Fu wrote:
>> On Wed, 1 Jul 2026 15:29:28 +0800, Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>> On 2026/7/1 下午3:02, Leon Hwang wrote:
>>>> On 1/7/26 14:49, Tiezhu Yang wrote:
>>>> [...]
>>>>>>
>>>>>> It is a real issue.
>>>>>>
>>>>>> Instead of fixing up helper calls, it seems better to prevent
>>>>>> interpreter fallback if the prog has any JIT-inlineable helper call.
>>>>>
>>>>> Hi Alexei and Leon,
>>>>>
>>>>> What about the following: (not tested yet, if it is good, I can test it)
>>>>>
>>>>> [...]
>>>>>
>>>>> If you are OK with the above changes, I will test it again and send
>>>>> a new version later.
>>>>>
>>>>
>>>> If you don't mind, I think I can disallow the interpreter fallback by
>>>> the below diff in the next revision of this series.
>>>>
>>>> The 'aux->jit_required' is introduced by following Alexei's suggestion.
>>>
>>> I am not sure if introducing a new aux->jit_required member is necessary,
>>> as we already have a local jit_needed flag in the current logic.
>> 
>> A 'must_jit'-like member was suggested by Alexei [1].
>> 
>> Probably, the commits in [2] could help to understand 'aux->jit_required'.
>> 
>> [1] https://lore.kernel.org/bpf/DJMRIZ5PDWP4.12OOZ8H881H6O@gmail.com/
>> [2] https://github.com/Asphaltt/bpf/commits/bpf/fix-interpreter-fallback/v2/
>> 
>>>
>>> Additionally, the issue reported in my patch [1] is fundamentally tied
>>> to bpf_jit_inlines_helper_call(). Maybe we can simply reuse jit_needed
>>> by checking bpf_prog_has_inline_helpers() right before JITing, and then
>>> reject fallback with -ENOTSUPP if JIT compilation fails.
>> 
>> Correct. Reusing jit_needed is preferred.
>
> I agree.
>
> To avoid bloating struct bpf_prog_aux and to keep the refactoring
> minimal, I suggest that you submit a patch to introduce a centralized
> bpf_prog_requires_jit() helper in kernel/bpf/core.c.
>
> This will cleanly bundle bpf_prog_has_kfunc_call() and other JIT-only
> instructions (like user cast, arena, etc.) together, like this:
>
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 649cce41e13f..4e96272f7377 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -2608,6 +2608,24 @@ static struct bpf_prog 
> *bpf_prog_jit_compile(struct bpf_verifier_env *env, struc
>          return prog;
>   }
>
> +static bool bpf_prog_requires_jit(const struct bpf_prog *fp)
> +{
> +       struct bpf_insn *insn = fp->insnsi;
> +       int i;
> +
> +       if (bpf_prog_has_kfunc_call(fp))
> +               return true;
> +
> +       for (i = 0; i < fp->len; i++, insn++) {
> +               if (insn_is_cast_user(insn) ||
> +                   insn_is_arena_load_store(insn) ||
> +                   insn_is_indirect_jump(insn))
> +                       return true;
> +       }
> +
> +       return false;
> +}

No. I already explained that this forking of the logic is not ok.

> +
>   struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env 
> *env, struct bpf_prog *fp,
>                                             int *err)
>   {
> @@ -2620,7 +2638,7 @@ struct bpf_prog *__bpf_prog_select_runtime(struct 
> bpf_verifier_env *env, struct
>                  goto finalize;
>
>          if (IS_ENABLED(CONFIG_BPF_JIT_ALWAYS_ON) ||
> -           bpf_prog_has_kfunc_call(fp))
> +           bpf_prog_requires_jit(fp))

This has to be fp->jit_required and
the verifier has to set it when necessary.

  reply	other threads:[~2026-07-01 18:47 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26 15:43 [RFC PATCH bpf 0/6] bpf: Disallow interpreter fallback for interpreter-unsupported insns Leon Hwang
2026-06-26 15:43 ` [RFC PATCH bpf 1/6] bpf: Disallow interpreter fallback for user BPF_ADDR_SPACE_CAST insn Leon Hwang
2026-06-30 14:29   ` KaFai Wan
2026-06-30 14:36     ` Leon Hwang
2026-07-01  1:26       ` Tiezhu Yang
2026-07-01  6:21         ` Leon Hwang
2026-07-01  6:49           ` Tiezhu Yang
2026-07-01  7:02             ` Leon Hwang
2026-07-01  7:29               ` Tiezhu Yang
2026-07-01  8:04                 ` Leon Huang Fu
2026-07-01  9:07                   ` Tiezhu Yang
2026-07-01 18:47                     ` Alexei Starovoitov [this message]
2026-06-26 15:43 ` [RFC PATCH bpf 2/6] bpf: Disallow interpreter fallback for arena insn Leon Hwang
2026-06-26 15:43 ` [RFC PATCH bpf 3/6] bpf: Disallow interpreter fallback for BPF_MOV64_PERCPU_REG insn Leon Hwang
2026-06-26 15:43 ` [RFC PATCH bpf 4/6] bpf: Disallow interpreter fallback for internal BPF_PROBE_ATOMIC insn Leon Hwang
2026-06-26 15:43 ` [RFC PATCH bpf 5/6] bpf: Disallow interpreter fallback for gotox insn Leon Hwang
2026-06-26 15:43 ` [RFC PATCH bpf 6/6] lib/test_bpf: Add interpreter-fallback tests Leon Hwang
2026-06-26 16:11 ` [RFC PATCH bpf 0/6] bpf: Disallow interpreter fallback for interpreter-unsupported insns Leon Hwang
2026-06-30 23:12 ` Alexei Starovoitov
2026-07-01  2:59   ` Leon Hwang
2026-07-01  3:05     ` Leon Hwang
2026-07-01  5:50     ` Alexei Starovoitov
2026-07-01  6:20       ` 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=DJNGIT00SJG4.3LBZ5DHQDHLHU@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=a.s.protopopov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai.wan@linux.dev \
    --cc=leon.huangfu@shopee.com \
    --cc=leon.hwang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=puranjay@kernel.org \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yangtiezhu@loongson.cn \
    --cc=yonghong.song@linux.dev \
    /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