Re: [PATCH bpf-next v2 1/2] bpf, mips: Factor out div/mod emission helpers

[email protected] Wed, 29 Jul 2026 17:10:20 +0000 (UTC)
Newsgroups org.kernel.vger.linux-mips,org.kernel.vger.bpf,org.kernel.vger.linux-kernel
Message-ID <c517c61555d5ac0e7dda77c6f9a4e3624ef8ed742d6372ab3d5af4879291ec4f@mail.kernel.org>
--===============0867181835217338259==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

> diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c
> index 6ee4abe6a1f7..f99bb5705d00 100644
> --- a/arch/mips/net/bpf_jit_comp.c
> +++ b/arch/mips/net/bpf_jit_comp.c
> @@ -338,6 +338,26 @@ void emit_alu_i(struct jit_context *ctx, u8 dst, s32 imm, u8 op)
>  	clobber_reg(ctx, dst);
>  }
>
> +static void emit_div(struct jit_context *ctx, u8 dst, u8 src)
> +{
> +	if (cpu_has_mips32r6) {
> +		emit(ctx, divu_r6, dst, dst, src);
> +	} else {
> +		emit(ctx, divu, dst, src);
> +		emit(ctx, mflo, dst);
> +	}
> +}
> +
> +static void emit_mod(struct jit_context *ctx, u8 dst, u8 src)
> +{
> +	if (cpu_has_mips32r6) {
> +		emit(ctx, modu, dst, dst, src);
> +	} else {
> +		emit(ctx, divu, dst, src);
> +		emit(ctx, mfhi, dst);
> +	}
> +}

This isn't a bug, but would a short header comment on emit_div() and
emit_mod(), in the style of the neighbouring '/* ALU register operation
(32-bit) */', keep these consistent with the rest of the file? Every
other emitter here carries one.

[ ... ]

> diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c
> index fa7e9aa37f49..befeb63ae447 100644
> --- a/arch/mips/net/bpf_jit_comp64.c
> +++ b/arch/mips/net/bpf_jit_comp64.c
> @@ -197,6 +197,26 @@ static void emit_alu_i64(struct jit_context *ctx, u8 dst, s32 imm, u8 op)
>  	clobber_reg(ctx, dst);
>  }
>
> +static void emit_div64(struct jit_context *ctx, u8 dst, u8 src)
> +{
> +	if (cpu_has_mips64r6) {
> +		emit(ctx, ddivu_r6, dst, dst, src);
> +	} else {
> +		emit(ctx, ddivu, dst, src);
> +		emit(ctx, mflo, dst);
> +	}
> +}
> +
> +static void emit_mod64(struct jit_context *ctx, u8 dst, u8 src)
> +{
> +	if (cpu_has_mips64r6) {
> +		emit(ctx, dmodu, dst, dst, src);
> +	} else {
> +		emit(ctx, ddivu, dst, src);
> +		emit(ctx, mfhi, dst);
> +	}
> +}

Same for emit_div64() and emit_mod64() here.


---
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/30472129214
--===============0867181835217338259==--