mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: alexis.lothore@bootlin.com,ast@kernel.org,daniel@iogearbox.net,john.fastabend@gmail.com,andrii@kernel.org,martin.lau@linux.dev,eddyz87@gmail.com,memxor@gmail.com,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,tglx@kernel.org,bp@alien8.de,dave.hansen@linux.intel.com,x86@kernel.org,hpa@zytor.com,shuah@kernel.org,mingo@redhat.com,andreyknvl@gmail.com
Cc: ebpf@linuxfoundation.org,bastien.curutchet@bootlin.com,thomas.petazzoni@bootlin.com,bpf@vger.kernel.org,linux-kernel@vger.kernel.org,linux-kselftest@vger.kernel.org,ihor.solodrai@linux.dev,alexis.lothore@bootlin.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v6 3/9] bpf, x86: refactor BPF_ST management in do_jit
Date: Tue,  4 Aug 2026 19:04:32 +0000 (UTC)	[thread overview]
Message-ID: <0cfcfa102964139337a4ea45df33b83bb79f6d516738cd2d1cb2d18e4e1f3431@mail.kernel.org> (raw)
In-Reply-To: <20260804-kasan-v6-3-549ef845f491@bootlin.com>

[-- Attachment #1: Type: text/plain, Size: 3415 bytes --]

> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index 01e7ce569c1ed..0b8b5dfe37ab0 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -1315,6 +1315,64 @@ static void emit_st_index(u8 **pprog, u32 size, u32 dst_reg, u32 index_reg, int
>  	*pprog = prog;
>  }
>
> +static void emit_st(u8 **pprog, struct bpf_insn *insn, int dst_reg,
> +		    s32 outgoing_arg_base, u16 outgoing_rsp)

This isn't a bug, but any reason for `int dst_reg` here rather than the
`u32 dst_reg` used by emit_stx()/emit_st_index() alongside it?

> +{
> +	s32 imm32 = insn->imm;
> +	u8 *prog = *pprog;
> +	s32 insn_off;
> +
> +	switch (BPF_SIZE(insn->code)) {
> +	case BPF_B:
> +		if (is_ereg(dst_reg))
> +			EMIT2(0x41, 0xC6);
> +		else
> +			EMIT1(0xC6);
> +		break;
> +	case BPF_H:
> +		if (is_ereg(dst_reg))
> +			EMIT3(0x66, 0x41, 0xC7);
> +		else
> +			EMIT2(0x66, 0xC7);
> +		break;
> +	case BPF_W:
> +		if (is_ereg(dst_reg))
> +			EMIT2(0x41, 0xC7);
> +		else
> +			EMIT1(0xC7);
> +		break;
> +	case BPF_DW:
> +		if (dst_reg == BPF_REG_PARAMS && insn->off == -8) {
> +			/* Arg 6: store immediate in r9 register */
> +			emit_mov_imm64(&prog, X86_REG_R9, imm32 >> 31,
> +				       (u32)imm32);

This isn't a bug, but since these two lines now sit two levels shallower
and fit in 80 columns unwrapped, could they stay on one line to keep the
diff a pure code move?

The call unwrapped is:

emit_mov_imm64(&prog, X86_REG_R9, imm32 >> 31, (u32)imm32);

which is 75 columns at the new indentation level.

> +			*pprog = prog;
> +			return;
> +		}
> +		EMIT2(add_1mod(0x48, dst_reg), 0xC7);
> +		break;
> +	}
> +
> +	insn_off = insn->off;
> +	if (dst_reg == BPF_REG_PARAMS) {
> +		/*
> +		 * Args 7+: reverse BPF negative offsets to
> +		 * x86 positive rsp offsets.
> +		 * BPF off=-16 → [rsp+0], off=-24 → [rsp+8], ...
> +		 */
> +		insn_off = outgoing_arg_base - outgoing_rsp -
> +			insn_off - 16;

This isn't a bug, but this line also became shorter by two indentation
levels. Unwrapped it is:

insn_off = outgoing_arg_base - outgoing_rsp - insn_off - 16;

which is 76 columns. Could it stay on one line rather than splitting the
arithmetic expression mid-subtraction?

> +		dst_reg = BPF_REG_FP;
> +	}
> +	if (is_imm8(insn_off))
> +		EMIT2(add_1reg(0x40, dst_reg), insn_off);
> +	else
> +		EMIT1_off32(add_1reg(0x80, dst_reg), insn_off);
> +
> +	EMIT(imm32, bpf_size_to_x86_bytes(BPF_SIZE(insn->code)));
> +	*pprog = prog;
> +}

This isn't a bug, but would it be worth carrying the `/* ST: *(u8*)(dst_reg
+ off) = imm */` line over onto the new emit_st(), so it matches
emit_ldx()/emit_stx()/emit_st_index() just above?

Looking at the neighbouring base emit helpers in this file, they all carry
that one-line semantic summary: emit_ldx has `/* LDX: dst_reg = *(u8*)(src_reg
+ off) */`, emit_ldsx, emit_stx, and emit_st_index has `/* ST: *(u8*)(dst_reg +
index_reg + off) = imm32 */`. The hunk in do_jit deletes the `/* ST:
*(u8*)(dst_reg + off) = imm */` one-liner that documented the BPF_ST arm, and
the new emit_st() helper is added without an equivalent, making emit_st the only
one of that group with no such line.

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/30936192563

  reply	other threads:[~2026-08-04 19:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 17:45 [PATCH bpf-next v6 0/9] bpf: add support for KASAN checks in JITed programs Alexis Lothoré (eBPF Foundation)
2026-08-04 17:45 ` [PATCH bpf-next v6 1/9] bpf: mark instructions accessing program stack Alexis Lothoré (eBPF Foundation)
2026-08-04 17:45 ` [PATCH bpf-next v6 2/9] bpf: add BPF_JIT_KASAN for KASAN instrumentation of JITed programs Alexis Lothoré (eBPF Foundation)
2026-08-04 17:45 ` [PATCH bpf-next v6 3/9] bpf, x86: refactor BPF_ST management in do_jit Alexis Lothoré (eBPF Foundation)
2026-08-04 19:04   ` bot+bpf-ci [this message]
2026-08-04 17:45 ` [PATCH bpf-next v6 4/9] bpf, x86: emit KASAN checks in x86 JITed programs Alexis Lothoré (eBPF Foundation)
2026-08-04 17:45 ` [PATCH bpf-next v6 5/9] bpf, x86: enable KASAN for JITed programs on x86 Alexis Lothoré (eBPF Foundation)
2026-08-04 17:45 ` [PATCH bpf-next v6 6/9] selftests/bpf: make cmdline_contains stricter Alexis Lothoré (eBPF Foundation)
2026-08-04 18:49   ` bot+bpf-ci
2026-08-04 17:45 ` [PATCH bpf-next v6 7/9] selftests/bpf: add helpers for KASAN in JIT testing Alexis Lothoré (eBPF Foundation)
2026-08-04 17:45 ` [PATCH bpf-next v6 8/9] selftests/bpf: move bpf_jit_harden helper into testing_helpers Alexis Lothoré (eBPF Foundation)
2026-08-04 17:45 ` [PATCH bpf-next v6 9/9] selftests/bpf: add tests to validate KASAN on JIT programs Alexis Lothoré (eBPF Foundation)
2026-08-21 18:59 ` [PATCH bpf-next v6 0/9] bpf: add support for KASAN checks in JITed programs Andrii Nakryiko
2026-08-21 19:44   ` Alexis Lothoré

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=0cfcfa102964139337a4ea45df33b83bb79f6d516738cd2d1cb2d18e4e1f3431@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=alexis.lothore@bootlin.com \
    --cc=andreyknvl@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bastien.curutchet@bootlin.com \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebpf@linuxfoundation.org \
    --cc=eddyz87@gmail.com \
    --cc=hpa@zytor.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=mingo@redhat.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tglx@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=x86@kernel.org \
    --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

all inboxes | Powered by JetHome®