All of lore.kernel.org
 help / color / mirror / Atom feed
From: Puranjay Mohan <puranjay@kernel.org>
To: Eduard Zingerman <eddyz87@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	kkd@meta.com, kernel-team@meta.com,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>
Subject: Re: [PATCH bpf-next v3 1/3] bpf, x86: Add support for signed arena loads
Date: Wed, 17 Sep 2025 14:16:06 +0000	[thread overview]
Message-ID: <mb61p4it1qi55.fsf@kernel.org> (raw)
In-Reply-To: <ba84c72f4732b0fe180b2ba40cc66577c78c177b.camel@gmail.com>

Eduard Zingerman <eddyz87@gmail.com> writes:

> On Mon, 2025-09-15 at 16:28 +0000, Puranjay Mohan wrote:
>
> [...]
>
>> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
>> index 008273a53e04..f2b85a10add2 100644
>> --- a/arch/arm64/net/bpf_jit_comp.c
>> +++ b/arch/arm64/net/bpf_jit_comp.c
>> @@ -3064,6 +3064,11 @@ bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)
>>  		if (!bpf_atomic_is_load_store(insn) &&
>>  		    !cpus_have_cap(ARM64_HAS_LSE_ATOMICS))
>>  			return false;
>> +		break;
>> +	case BPF_LDX | BPF_MEMSX | BPF_B:
>> +	case BPF_LDX | BPF_MEMSX | BPF_H:
>> +	case BPF_LDX | BPF_MEMSX | BPF_W:
>> +		return false;
>>  	}
>>  	return true;
>>  }
>
> Is the same hunk necessary in riscv/net/bpf_jit_comp64.c?

Yes, will add in next version.

> [...]
>
>> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
>> index 8d34a9400a5e..a6550da34268 100644
>> --- a/arch/x86/net/bpf_jit_comp.c
>> +++ b/arch/x86/net/bpf_jit_comp.c
>> @@ -1152,11 +1152,38 @@ static void emit_ldx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 i
>>  	*pprog = prog;
>>  }
>>  
>> +static void emit_ldsx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 index_reg, int off)
>> +{
>> +	u8 *prog = *pprog;
>> +
>> +	switch (size) {
>> +	case BPF_B:
>> +		/* movsx rax, byte ptr [rax + r12 + off] */
>> +		EMIT3(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x0F, 0xBE);
>> +		break;
>> +	case BPF_H:
>> +		/* movsx rax, word ptr [rax + r12 + off] */
>> +		EMIT3(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x0F, 0xBF);
>> +		break;
>> +	case BPF_W:
>> +		/* movsx rax, dword ptr [rax + r12 + off] */
>> +		EMIT2(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x63);
>> +		break;
>> +	}
>> +	emit_insn_suffix_SIB(&prog, src_reg, dst_reg, index_reg, off);
>> +	*pprog = prog;
>> +}
>> +
>
> Encoding looks correct.
>
> [...]
>
>> @@ -2109,13 +2136,19 @@ st:			if (is_imm8(insn->off))
>>  		case BPF_LDX | BPF_PROBE_MEM32 | BPF_H:
>>  		case BPF_LDX | BPF_PROBE_MEM32 | BPF_W:
>>  		case BPF_LDX | BPF_PROBE_MEM32 | BPF_DW:
>> +		case BPF_LDX | BPF_PROBE_MEM32SX | BPF_B:
>> +		case BPF_LDX | BPF_PROBE_MEM32SX | BPF_H:
>> +		case BPF_LDX | BPF_PROBE_MEM32SX | BPF_W:
>>  		case BPF_STX | BPF_PROBE_MEM32 | BPF_B:
>>  		case BPF_STX | BPF_PROBE_MEM32 | BPF_H:
>>  		case BPF_STX | BPF_PROBE_MEM32 | BPF_W:
>>  		case BPF_STX | BPF_PROBE_MEM32 | BPF_DW:
>>  			start_of_ldx = prog;
>>  			if (BPF_CLASS(insn->code) == BPF_LDX)
>> -				emit_ldx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
>> +				if (BPF_MODE(insn->code) == BPF_PROBE_MEM32SX)
>> +					emit_ldsx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
>> +				else
>> +					emit_ldx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
>>  			else
>>  				emit_stx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
>
> Heh, apparently this is correct C code. Dangling else is associated
> with the closest 'if' statement. Didn't know that.

This code goes against kernel coding style, I should have used braces.
Will fix it in next version.

  parent reply	other threads:[~2025-09-17 14:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 16:28 [PATCH bpf-next v3 0/3] Signed loads from Arena Puranjay Mohan
2025-09-15 16:28 ` [PATCH bpf-next v3 1/3] bpf, x86: Add support for signed arena loads Puranjay Mohan
2025-09-17  1:05   ` Eduard Zingerman
2025-09-17  1:08     ` Kumar Kartikeya Dwivedi
2025-09-17 14:16     ` Puranjay Mohan [this message]
2025-09-15 16:28 ` [PATCH bpf-next v3 2/3] bpf, arm64: " Puranjay Mohan
2025-09-20 10:37   ` Xu Kuohai
2025-09-23 10:52     ` Puranjay Mohan
2025-09-25 13:10       ` Xu Kuohai
2025-09-15 16:28 ` [PATCH bpf-next v3 3/3] selftests: bpf: Add tests for signed loads from arena Puranjay Mohan
2025-09-17  1:03 ` [PATCH bpf-next v3 0/3] Signed loads from Arena Kumar Kartikeya Dwivedi
2025-09-17  3:41   ` Xu Kuohai

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=mb61p4it1qi55.fsf@kernel.org \
    --to=puranjay@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.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 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.