Skip to contentSkip to conversation

parisc: fix unaligned accesses in BPF

PATCH In review Mikulas Patocka 2 participants 2 messages Jul 27, 2024 – Jul 28, 2024

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

PATCH 1/1 parisc: fix unaligned accesses in BPF

There were spurious unaligned access warnings when calling BPF code. Sometimes, the warnings were triggered with any incoming packet, making the machine hard to use.

The reason for the warnings is this: on parisc64, pointers to functions are not really pointers to functions, they are pointers to 16-byte descriptor. The first 8 bytes of the descriptor is a pointer to the function and the next 8 bytes of the descriptor is the content of the "dp" register. This descriptor is generated in the function bpf_jit_build_prologue.

The problem is that the function bpf_int_jit_compile advertises 4-byte alignment when calling bpf_jit_binary_alloc, bpf_jit_binary_alloc randomizes the returned array and if the array happens to be not aligned on 8-byte boundary, the descriptor generated in bpf_jit_build_prologue is also not aligned and this triggers the unaligned access warning.

Fix this by advertising 8-byte alignment on parisc64 when calling bpf_jit_binary_alloc.

---
 arch/parisc/net/bpf_jit_core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/net/bpf_jit_core.c +1 -1
Index: linux-6.10/arch/parisc/net/bpf_jit_core.c
===================================================================
@@ -114,7 +114,7 @@ struct bpf_prog *bpf_int_jit_compile(str
 			jit_data->header =
 				bpf_jit_binary_alloc(prog_size + extable_size,
 						     &jit_data->image,
-						     sizeof(u32),
+						     sizeof(long),
 						     bpf_fill_ill_insns);
 			if (!jit_data->header) {
 				prog = orig_prog;
maintainer
#1 lore raw
Quoted 17 lines · Mikulas Patocka

There were spurious unaligned access warnings when calling BPF code. Sometimes, the warnings were triggered with any incoming packet, making the machine hard to use.

The reason for the warnings is this: on parisc64, pointers to functions are not really pointers to functions, they are pointers to 16-byte descriptor. The first 8 bytes of the descriptor is a pointer to the function and the next 8 bytes of the descriptor is the content of the "dp" register. This descriptor is generated in the function bpf_jit_build_prologue.

The problem is that the function bpf_int_jit_compile advertises 4-byte alignment when calling bpf_jit_binary_alloc, bpf_jit_binary_alloc randomizes the returned array and if the array happens to be not aligned on 8-byte boundary, the descriptor generated in bpf_jit_build_prologue is also not aligned and this triggers the unaligned access warning.

Quoted 5 lines

Fix this by advertising 8-byte alignment on parisc64 when calling bpf_jit_binary_alloc.

Nice catch!
Applied.

Thanks!
Helge

Quoted 19 lines
---
  arch/parisc/net/bpf_jit_core.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-6.10/arch/parisc/net/bpf_jit_core.c
===================================================================

arch/parisc/net/bpf_jit_core.c +1 -1
@@ -114,7 +114,7 @@ struct bpf_prog *bpf_int_jit_compile(str
  			jit_data->header =
  				bpf_jit_binary_alloc(prog_size + extable_size,
  						     &jit_data->image,
-						     sizeof(u32),
+						     sizeof(long),
  						     bpf_fill_ill_insns);
  			if (!jit_data->header) {
  				prog = orig_prog;