[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <874izus6ok.fsf@fau.de>
Date: Sat, 15 Mar 2025 15:35:23 +0100
From: Luis Gerhorst <luis.gerhorst@....de>
To: Eduard Zingerman <eddyz87@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann
<daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>, Martin
KaFai Lau <martin.lau@...ux.dev>, Song Liu <song@...nel.org>, Yonghong
Song <yonghong.song@...ux.dev>, John Fastabend
<john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>, Stanislav
Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>, Jiri Olsa
<jolsa@...nel.org>, Puranjay Mohan <puranjay@...nel.org>, Xu Kuohai
<xukuohai@...weicloud.com>, Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>, Hari Bathini <hbathini@...ux.ibm.com>,
Christophe Leroy <christophe.leroy@...roup.eu>, Naveen N Rao
<naveen@...nel.org>, Madhavan Srinivasan <maddy@...ux.ibm.com>, Michael
Ellerman <mpe@...erman.id.au>, Nicholas Piggin <npiggin@...il.com>,
Mykola Lysenko <mykolal@...com>, Shuah Khan <shuah@...nel.org>,
Henriette Herzog <henriette.herzog@....de>, Cupertino Miranda
<cupertino.miranda@...cle.com>, Matan Shachnai <m.shachnai@...il.com>,
Dimitar Kanaliev <dimitar.kanaliev@...eground.com>, Shung-Hsi Yu
<shung-hsi.yu@...e.com>, Daniel Xu <dxu@...uu.xyz>, bpf@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
linuxppc-dev@...ts.ozlabs.org, linux-kselftest@...r.kernel.org, George
Guo <guodongtai@...inos.cn>, WANG Xuerui <git@...0n.name>, Tiezhu Yang
<yangtiezhu@...ngson.cn>, Maximilian Ott <ott@...fau.de>, Milan Stephan
<milan.stephan@....de>
Subject: Re: [PATCH bpf-next 01/11] bpf: Move insn if/else into do_check_insn()
Eduard Zingerman <eddyz87@...il.com> writes:
> On Thu, 2025-03-13 at 18:21 +0100, Luis Gerhorst wrote:
>> + err = do_check_insn(env, insn, pop_log, &do_print_state, regs, state,
>> + &prev_insn_idx);
>
> - `regs` remains declared in do_check(), while nothing prevents
> pushing its declaration to do_check_insn().
> - `state` is `env->cur_state`, so I'd avoid passing it as a parameter
> (just to reduce count);
> - `prev_insn_idx` is unused by `do_check_insn`;
> - `pop_log` is not used by `do_check_insn`;
Changed for v2, thank you very much.
> - given that `insn` is presumed to correspond to `env->insn_idx` in
> many places down the stack not sure about this parameter.
I don't have a strong opinion on this either. Unless someone objects I
will keep it as it matches the other check_*() functions like this.
>> + if (err < 0) {
>> + return err;
>> + } else if (err == INSN_IDX_MODIFIED) {
>
> Also, I'd get rid of `INSN_IDX_MODIFIED` and move `env->insn_idx++`
> into `do_check_insn()`. This would save a few mental cycles when
> looking at the code with full patch-set applied:
>
> } else if (err == INSN_IDX_MODIFIED) {
> continue;
> } else if (err == PROCESS_BPF_EXIT) {
> goto process_bpf_exit;
> }
> WARN_ON_ONCE(err);
>
> if (state->speculative && cur_aux(env)->nospec_result) {
> ... bunch of actions ...
> }
>
> env->insn_idx++;
>
> One needs to stop for a moment and think why "bunch of actions" is
> performed for regular index increment, but not for INSN_IDX_MODIFIED.
That certainly makes it more readable. I changed it for v2.
If we have an instruction that does not simply do `insn_idx++` but
jumps, the `nospec_result` check should never trigger. Otherwise, the
patched nospec might be skipped. Currently, this is satisfied because
`nospec_result` is only used for store-instructions. I will add a
comment and WARN_ON_ONCE to document that for v2.
Powered by blists - more mailing lists