linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT
@ 2023-02-28 11:33 Jiaxun Yang
  2023-02-28 11:33 ` [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds Jiaxun Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jiaxun Yang @ 2023-02-28 11:33 UTC (permalink / raw)
  To: linux-mips
  Cc: linux-kernel, tsbogend, johan.almbladh, paulburton, bpf, Jiaxun Yang

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)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds
  2023-02-28 11:33 [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT Jiaxun Yang
@ 2023-02-28 11:33 ` Jiaxun Yang
  2023-02-28 12:02   ` Philippe Mathieu-Daudé
  2023-02-28 12:35   ` Johan Almbladh
  2023-02-28 11:33 ` [PATCH v2 2/2] MIPS: ebpf jit: Implement R4000 workarounds Jiaxun Yang
  2023-02-28 14:00 ` [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT patchwork-bot+netdevbpf
  2 siblings, 2 replies; 6+ messages in thread
From: Jiaxun Yang @ 2023-02-28 11:33 UTC (permalink / raw)
  To: linux-mips
  Cc: linux-kernel, tsbogend, johan.almbladh, paulburton, bpf, Jiaxun Yang

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 <jiaxun.yang@flygoat.com>
---
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)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] MIPS: ebpf jit: Implement R4000 workarounds
  2023-02-28 11:33 [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT Jiaxun Yang
  2023-02-28 11:33 ` [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds Jiaxun Yang
@ 2023-02-28 11:33 ` Jiaxun Yang
  2023-02-28 14:00 ` [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Jiaxun Yang @ 2023-02-28 11:33 UTC (permalink / raw)
  To: linux-mips
  Cc: linux-kernel, tsbogend, johan.almbladh, paulburton, bpf,
	Jiaxun Yang, Philippe Mathieu-Daudé

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 <jiaxun.yang@flygoat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
---
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)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds
  2023-02-28 11:33 ` [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds Jiaxun Yang
@ 2023-02-28 12:02   ` Philippe Mathieu-Daudé
  2023-02-28 12:35   ` Johan Almbladh
  1 sibling, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-28 12:02 UTC (permalink / raw)
  To: Jiaxun Yang, linux-mips
  Cc: linux-kernel, tsbogend, johan.almbladh, paulburton, bpf

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 <jiaxun.yang@flygoat.com>
> ---
> 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é <philmd@linaro.org>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds
  2023-02-28 11:33 ` [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds Jiaxun Yang
  2023-02-28 12:02   ` Philippe Mathieu-Daudé
@ 2023-02-28 12:35   ` Johan Almbladh
  1 sibling, 0 replies; 6+ messages in thread
From: Johan Almbladh @ 2023-02-28 12:35 UTC (permalink / raw)
  To: Jiaxun Yang; +Cc: linux-mips, linux-kernel, tsbogend, paulburton, bpf

Acked-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>

On Tue, Feb 28, 2023 at 12:33 PM Jiaxun Yang <jiaxun.yang@flygoat.com> 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 <jiaxun.yang@flygoat.com>
> ---
> 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)
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT
  2023-02-28 11:33 [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT Jiaxun Yang
  2023-02-28 11:33 ` [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds Jiaxun Yang
  2023-02-28 11:33 ` [PATCH v2 2/2] MIPS: ebpf jit: Implement R4000 workarounds Jiaxun Yang
@ 2023-02-28 14:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-02-28 14:00 UTC (permalink / raw)
  To: Jiaxun Yang
  Cc: linux-mips, linux-kernel, tsbogend, johan.almbladh, paulburton, bpf

Hello:

This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-02-28 14:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-28 11:33 [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT Jiaxun Yang
2023-02-28 11:33 ` [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds Jiaxun Yang
2023-02-28 12:02   ` Philippe Mathieu-Daudé
2023-02-28 12:35   ` Johan Almbladh
2023-02-28 11:33 ` [PATCH v2 2/2] MIPS: ebpf jit: Implement R4000 workarounds Jiaxun Yang
2023-02-28 14:00 ` [PATCH v2 0/2] MIPS: Implement two workarounds for BPF JIT patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).