Skip to contentSkip to conversation

MIPS eBPF JIT support on pre-32R2

DISCUSSION Alexander Lobakin 3 participants 5 messages Dec 5, 2019 – Dec 6, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hey all,

I'm writing about lines arch/mips/net/ebpf_jit.c:1806-1807:

	if (!prog->jit_requested || MIPS_ISA_REV < 2)
		return prog;

Do pre-32R2 architectures (32R1, maybe even R3000-like) actually support this eBPF JIT code? If they do, then the condition 'MIPS_ISA_REV < 2' should be removed as it is always true for them and tells CC to remove JIT completely.

If they don't support instructions from this JIT, then the line arch/mips/Kconfig:50:

select HAVE_EBPF_JIT if (!CPU_MICROMIPS)

should be changed to something like:

	select HAVE_EBPF_JIT if !CPU_MICROMIPS && TARGET_ISA_REV >= 2

(and then the mentioned 'if' condition would become redundant)

At the moment it is possible to build a kernel without both JIT and interpreter, but with CONFIG_BPF_SYSCALL=y (what should not be allowed I suppose?) within the following configuration:

- select any pre-32R2 CPU (e.g. CONFIG_CPU_MIPS32_R1);
- enable CONFIG_BPF_JIT (CONFIG_MIPS_EBPF_JIT will be autoselected);
- enable CONFIG_BPF_JIT_ALWAYS_ON (this removes BPF interpreter from the system).

I may prepare a proper patch by myself if needed (after clarification). Thanks.

Regards,
ᚷ ᛖ ᚢ ᚦ ᚠ ᚱ

maintainer
#1 lore raw
Quoted 19 lines · Alexander Lobakin

Hey all,

I'm writing about lines arch/mips/net/ebpf_jit.c:1806-1807:

	if (!prog->jit_requested || MIPS_ISA_REV < 2)
		return prog;

Do pre-32R2 architectures (32R1, maybe even R3000-like) actually support this eBPF JIT code? If they do, then the condition 'MIPS_ISA_REV < 2' should be removed as it is always true for them and tells CC to remove JIT completely.

If they don't support instructions from this JIT, then the line arch/mips/Kconfig:50:

select HAVE_EBPF_JIT if (!CPU_MICROMIPS)

should be changed to something like:

Quoted 7 lines
	select HAVE_EBPF_JIT if !CPU_MICROMIPS && TARGET_ISA_REV >= 2

(and then the mentioned 'if' condition would become redundant)

At the moment it is possible to build a kernel without both JIT and interpreter, but with CONFIG_BPF_SYSCALL=y (what should not be allowed I suppose?) within the following configuration:

Cannot comment on the MIPS ISA question above, but it would definiely be a bug to build a kernel with neither JIT nor interpreter. If a JIT is not available, then there /must/ be the interpreter as fallback to be able to run BPF programs.

Quoted 10 lines

- select any pre-32R2 CPU (e.g. CONFIG_CPU_MIPS32_R1);
- enable CONFIG_BPF_JIT (CONFIG_MIPS_EBPF_JIT will be autoselected);
- enable CONFIG_BPF_JIT_ALWAYS_ON (this removes BPF interpreter from the system).

I may prepare a proper patch by myself if needed (after clarification). Thanks.

Regards,
ᚷ ᛖ ᚢ ᚦ ᚠ ᚱ

#2 lore raw
In reply to Alexander Lobakin

Hi Alexander,

Quoted 9 lines · Alexander Lobakin

Hey all,

I'm writing about lines arch/mips/net/ebpf_jit.c:1806-1807:

	if (!prog->jit_requested || MIPS_ISA_REV < 2)
		return prog;

Do pre-32R2 architectures (32R1, maybe even R3000-like) actually support this eBPF JIT code?

No, they don't; the eBPF JIT makes unconditional use of at least the (d)ins & (d)ext instructions which were added in MIPSr2, so it would result in reserved instruction exceptions & panics if enabled on pre-MIPSr2 CPUs.

Quoted 7 lines

If they do, then the condition 'MIPS_ISA_REV < 2'
should be removed as it is always true for them and tells CC to remove JIT completely.

If they don't support instructions from this JIT, then the line arch/mips/Kconfig:50:

Quoted 7 lines

select HAVE_EBPF_JIT if (!CPU_MICROMIPS)

should be changed to something like:

	select HAVE_EBPF_JIT if !CPU_MICROMIPS && TARGET_ISA_REV >= 2

(and then the mentioned 'if' condition would become redundant)

Good spot; I agree entirely, this dependency should be reflected in Kconfig.

Quoted 10 lines

At the moment it is possible to build a kernel without both JIT and interpreter, but with CONFIG_BPF_SYSCALL=y (what should not be allowed I suppose?) within the following configuration:

- select any pre-32R2 CPU (e.g. CONFIG_CPU_MIPS32_R1);
- enable CONFIG_BPF_JIT (CONFIG_MIPS_EBPF_JIT will be autoselected);
- enable CONFIG_BPF_JIT_ALWAYS_ON (this removes BPF interpreter from the system).

I may prepare a proper patch by myself if needed (after clarification).

That would be great, thanks!

One thing to note is that I hope we'll restore the cBPF JIT with this patch:

https://lore.kernel.org/linux-mips/[email protected]/T/#u

The cBPF JIT looks like it should work on older pre-MIPSr2 CPUs, so the only way this is relevant is that your patch might have a minor conflict. But I thought I'd mention it anyway :)

Thanks,
Paul

#3 lore raw

Paul Burton wrote 05.12.2019 21:44:

Quoted 1 line

Hi Alexander,

Hi Paul!

Quoted 38 lines · Alexander Lobakin
Quoted 9 lines

Hey all,

I'm writing about lines arch/mips/net/ebpf_jit.c:1806-1807:

	if (!prog->jit_requested || MIPS_ISA_REV < 2)
		return prog;

Do pre-32R2 architectures (32R1, maybe even R3000-like) actually support this eBPF JIT code?

No, they don't; the eBPF JIT makes unconditional use of at least the (d)ins & (d)ext instructions which were added in MIPSr2, so it would result in reserved instruction exceptions & panics if enabled on pre-MIPSr2 CPUs.

Quoted 7 lines

If they do, then the condition 'MIPS_ISA_REV < 2'
should be removed as it is always true for them and tells CC to remove JIT completely.

If they don't support instructions from this JIT, then the line arch/mips/Kconfig:50:

Quoted 7 lines

select HAVE_EBPF_JIT if (!CPU_MICROMIPS)

should be changed to something like:

	select HAVE_EBPF_JIT if !CPU_MICROMIPS && TARGET_ISA_REV >= 2

(and then the mentioned 'if' condition would become redundant)

Good spot; I agree entirely, this dependency should be reflected in Kconfig.

Quoted 4 lines

At the moment it is possible to build a kernel without both JIT and interpreter, but with CONFIG_BPF_SYSCALL=y (what should not be allowed I suppose?) within the following configuration:

Quoted 8 lines
Quoted 6 lines

- select any pre-32R2 CPU (e.g. CONFIG_CPU_MIPS32_R1);
- enable CONFIG_BPF_JIT (CONFIG_MIPS_EBPF_JIT will be autoselected);
- enable CONFIG_BPF_JIT_ALWAYS_ON (this removes BPF interpreter from the system).

I may prepare a proper patch by myself if needed (after clarification).

That would be great, thanks!

Great, I'll send it in about ~2-3 hours.

Quoted 8 lines

One thing to note is that I hope we'll restore the cBPF JIT with this patch:

https://lore.kernel.org/linux-mips/[email protected]/T/#u

The cBPF JIT looks like it should work on older pre-MIPSr2 CPUs, so the only way this is relevant is that your patch might have a minor conflict. But I thought I'd mention it anyway :)

Yes, I thought about this too. If pre-32R2 CPUs don't support our eBPF JIT, we'd better restore cBPF for them, so they could speed-up at least "classic" instructions. Glad you've decided to do that.

Quoted 2 lines

Thanks,
Paul

Regards,
ᚷ ᛖ ᚢ ᚦ ᚠ ᚱ

#4 lore raw

Alexander Lobakin писал 06.12.2019 10:20:

Quoted 48 lines

Paul Burton wrote 05.12.2019 21:44:

Quoted 1 line

Hi Alexander,

Hi Paul!

Quoted 43 lines · Alexander Lobakin
Quoted 9 lines

Hey all,

I'm writing about lines arch/mips/net/ebpf_jit.c:1806-1807:

	if (!prog->jit_requested || MIPS_ISA_REV < 2)
		return prog;

Do pre-32R2 architectures (32R1, maybe even R3000-like) actually support this eBPF JIT code?

No, they don't; the eBPF JIT makes unconditional use of at least the (d)ins & (d)ext instructions which were added in MIPSr2, so it would result in reserved instruction exceptions & panics if enabled on pre-MIPSr2 CPUs.

Quoted 7 lines

If they do, then the condition 'MIPS_ISA_REV < 2'
should be removed as it is always true for them and tells CC to remove JIT completely.

If they don't support instructions from this JIT, then the line arch/mips/Kconfig:50:

Quoted 7 lines

select HAVE_EBPF_JIT if (!CPU_MICROMIPS)

should be changed to something like:

	select HAVE_EBPF_JIT if !CPU_MICROMIPS && TARGET_ISA_REV >= 2

(and then the mentioned 'if' condition would become redundant)

Good spot; I agree entirely, this dependency should be reflected in Kconfig.

Quoted 9 lines

At the moment it is possible to build a kernel without both JIT and interpreter, but with CONFIG_BPF_SYSCALL=y (what should not be allowed I suppose?) within the following configuration:

- select any pre-32R2 CPU (e.g. CONFIG_CPU_MIPS32_R1);
- enable CONFIG_BPF_JIT (CONFIG_MIPS_EBPF_JIT will be autoselected);
- enable CONFIG_BPF_JIT_ALWAYS_ON (this removes BPF interpreter from the system).

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I may prepare a proper patch by myself if needed (after clarification).

That would be great, thanks!

Great, I'll send it in about ~2-3 hours.

Here we are: [1]
Yep, this will conflict with your patch restoring cBPF for MIPS32. If you have any questions about my patch or I should change anything in it, please let me know.
Thanks!

Quoted 13 lines
Quoted 8 lines

One thing to note is that I hope we'll restore the cBPF JIT with this patch:

https://lore.kernel.org/linux-mips/[email protected]/T/#u

The cBPF JIT looks like it should work on older pre-MIPSr2 CPUs, so the only way this is relevant is that your patch might have a minor conflict. But I thought I'd mention it anyway :)

Yes, I thought about this too. If pre-32R2 CPUs don't support our eBPF JIT, we'd better restore cBPF for them, so they could speed-up at least "classic" instructions. Glad you've decided to do that.

Quoted 5 lines
Quoted 2 lines

Thanks,
Paul

Regards,
ᚷ ᛖ ᚢ ᚦ ᚠ ᚱ

[1] https://lore.kernel.org/linux-mips/[email protected]/

Regards,
ᚷ ᛖ ᚢ ᚦ ᚠ ᚱ