Hi all,
Just noticed eBPF JIT is not working on R4000 when messing around with QEMU.
This patchset implements two workarounds that is blocking us from enabling eBPF
JIT on R4000.
Thanks.
- Jiaxun
Jiaxun Yang (2):
MIPS: ebpf jit: Implement DADDI workarounds
MIPS: ebpf jit: Implement R4000 workarounds
arch/mips/Kconfig | 5 +----
arch/mips/net/bpf_jit_comp.c | 4 ++++
arch/mips/net/bpf_jit_comp64.c | 3 +++
3 files changed, 8 insertions(+), 4 deletions(-)
--
2.37.1 (Apple Git-137.1)
For DADDI errata we just workaround by disable immediate operation
for BPF_ADD / BPF_SUB to avoid generation of DADDIU.
All other use cases in JIT won't cause overflow thus they are all safe.
Signed-off-by: Jiaxun Yang <[email protected]>
---
v2: Drop 64BIT ifdef
---
arch/mips/Kconfig | 1 -
arch/mips/net/bpf_jit_comp.c | 4 ++++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 37072e15b263..df0910e3895c 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -64,7 +64,6 @@ config MIPS
select HAVE_DMA_CONTIGUOUS
select HAVE_DYNAMIC_FTRACE
select HAVE_EBPF_JIT if !CPU_MICROMIPS && \
- !CPU_DADDI_WORKAROUNDS && \
!CPU_R4000_WORKAROUNDS && \
!CPU_R4400_WORKAROUNDS
select HAVE_EXIT_THREAD
diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c
index b17130d510d4..a40d926b6513 100644
--- a/arch/mips/net/bpf_jit_comp.c
+++ b/arch/mips/net/bpf_jit_comp.c
@@ -218,9 +218,13 @@ bool valid_alu_i(u8 op, s32 imm)
/* All legal eBPF values are valid */
return true;
case BPF_ADD:
+ if (IS_ENABLED(CONFIG_CPU_DADDI_WORKAROUNDS))
+ return false;
/* imm must be 16 bits */
return imm >= -0x8000 && imm <= 0x7fff;
case BPF_SUB:
+ if (IS_ENABLED(CONFIG_CPU_DADDI_WORKAROUNDS))
+ return false;
/* -imm must be 16 bits */
return imm >= -0x7fff && imm <= 0x8000;
case BPF_AND:
--
2.37.1 (Apple Git-137.1)
For R4000 erratas around multiplication and division instructions,
as our use of those instructions are always followed by mflo/mfhi
instructions, the only issue we need care is
"MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0" Errata 28:
"A double-word or a variable shift may give an incorrect result if
executed while an integer multiplication is in progress."
We just emit a mfhi $0 to ensure the operation is completed after
every multiplication instruction according to workaround suggestion
in the document.
Signed-off-by: Jiaxun Yang <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Acked-by: Johan Almbladh <[email protected]>
---
v2: Drop 32bit part
---
arch/mips/Kconfig | 4 +---
arch/mips/net/bpf_jit_comp64.c | 3 +++
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index df0910e3895c..5ea07c833c5b 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -63,9 +63,7 @@ config MIPS
select HAVE_DEBUG_STACKOVERFLOW
select HAVE_DMA_CONTIGUOUS
select HAVE_DYNAMIC_FTRACE
- select HAVE_EBPF_JIT if !CPU_MICROMIPS && \
- !CPU_R4000_WORKAROUNDS && \
- !CPU_R4400_WORKAROUNDS
+ select HAVE_EBPF_JIT if !CPU_MICROMIPS
select HAVE_EXIT_THREAD
select HAVE_FAST_GUP
select HAVE_FTRACE_MCOUNT_RECORD
diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c
index 0e7c1bdcf914..fa7e9aa37f49 100644
--- a/arch/mips/net/bpf_jit_comp64.c
+++ b/arch/mips/net/bpf_jit_comp64.c
@@ -228,6 +228,9 @@ static void emit_alu_r64(struct jit_context *ctx, u8 dst, u8 src, u8 op)
} else {
emit(ctx, dmultu, dst, src);
emit(ctx, mflo, dst);
+ /* Ensure multiplication is completed */
+ if (IS_ENABLED(CONFIG_CPU_R4000_WORKAROUNDS))
+ emit(ctx, mfhi, MIPS_R_ZERO);
}
break;
/* dst = dst / src */
--
2.37.1 (Apple Git-137.1)
On 28/2/23 12:33, Jiaxun Yang wrote:
> For DADDI errata we just workaround by disable immediate operation
> for BPF_ADD / BPF_SUB to avoid generation of DADDIU.
>
> All other use cases in JIT won't cause overflow thus they are all safe.
>
> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> v2: Drop 64BIT ifdef
> ---
> arch/mips/Kconfig | 1 -
> arch/mips/net/bpf_jit_comp.c | 4 ++++
> 2 files changed, 4 insertions(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Acked-by: Johan Almbladh <[email protected]>
On Tue, Feb 28, 2023 at 12:33 PM Jiaxun Yang <[email protected]> wrote:
>
> For DADDI errata we just workaround by disable immediate operation
> for BPF_ADD / BPF_SUB to avoid generation of DADDIU.
>
> All other use cases in JIT won't cause overflow thus they are all safe.
>
> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> v2: Drop 64BIT ifdef
> ---
> arch/mips/Kconfig | 1 -
> arch/mips/net/bpf_jit_comp.c | 4 ++++
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index 37072e15b263..df0910e3895c 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -64,7 +64,6 @@ config MIPS
> select HAVE_DMA_CONTIGUOUS
> select HAVE_DYNAMIC_FTRACE
> select HAVE_EBPF_JIT if !CPU_MICROMIPS && \
> - !CPU_DADDI_WORKAROUNDS && \
> !CPU_R4000_WORKAROUNDS && \
> !CPU_R4400_WORKAROUNDS
> select HAVE_EXIT_THREAD
> diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c
> index b17130d510d4..a40d926b6513 100644
> --- a/arch/mips/net/bpf_jit_comp.c
> +++ b/arch/mips/net/bpf_jit_comp.c
> @@ -218,9 +218,13 @@ bool valid_alu_i(u8 op, s32 imm)
> /* All legal eBPF values are valid */
> return true;
> case BPF_ADD:
> + if (IS_ENABLED(CONFIG_CPU_DADDI_WORKAROUNDS))
> + return false;
> /* imm must be 16 bits */
> return imm >= -0x8000 && imm <= 0x7fff;
> case BPF_SUB:
> + if (IS_ENABLED(CONFIG_CPU_DADDI_WORKAROUNDS))
> + return false;
> /* -imm must be 16 bits */
> return imm >= -0x7fff && imm <= 0x8000;
> case BPF_AND:
> --
> 2.37.1 (Apple Git-137.1)
>
Hello:
This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <[email protected]>:
On Tue, 28 Feb 2023 11:33:03 +0000 you wrote:
> Hi all,
>
> Just noticed eBPF JIT is not working on R4000 when messing around with QEMU.
>
> This patchset implements two workarounds that is blocking us from enabling eBPF
> JIT on R4000.
>
> [...]
Here is the summary with links:
- [v2,1/2] MIPS: ebpf jit: Implement DADDI workarounds
https://git.kernel.org/bpf/bpf-next/c/bbefef2f0708
- [v2,2/2] MIPS: ebpf jit: Implement R4000 workarounds
https://git.kernel.org/bpf/bpf-next/c/7364d60c2661
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html