Skip to contentSkip to conversation

Common hash function for kernel and user space in XDP

DISCUSSION Anmol Panda 2 participants 2 messages Dec 4, 2017

lore
Share & tools
lore
#0 lore raw

Hello All,
We are trying to implement L2 forwarding in xdp and we need to
convert the mac-address to a hash value. Thus far, we have tried using crc32 functions from <linux/crc32.h> for kernel space but it can't be used in user space. We need a common crc hash function for both kernel and user space.

The kernel crc function causes the following error:

invalid relo for insn[24].code 0x85
bpf_load_program() err=22
0: (61) r2 = *(u32 *)(r1 +4)
1: (61) r1 = *(u32 *)(r1 +0)
.
.
.
23: (b7) r3 = 6
24: (85) call unknown#-1
BPF_CALL uses reserved fields

Can you please point to some examples or references? We would be highly grateful.

Thanks,
Sincerely,

#1 lore raw
Quoted 8 lines · Anmol Panda

Hello All,
We are trying to implement L2 forwarding in xdp and we need to convert
the mac-address to a hash value. Thus far, we have tried using crc32 functions from <linux/crc32.h> for kernel space but it can't be used in user space. We need a common crc hash function for both kernel and user space.

The kernel crc function causes the following error:

Quoted 10 lines

invalid relo for insn[24].code 0x85
bpf_load_program() err=22
0: (61) r2 = *(u32 *)(r1 +4)
1: (61) r1 = *(u32 *)(r1 +0)
.
.
.
23: (b7) r3 = 6
24: (85) call unknown#-1
BPF_CALL uses reserved fields

The kernel crc function eventually calls crc32_le_shift or other variants in lib/crc32.c. BPF program is able to resolve the reference to crc32_le_shift at verification time, hence you will see the failure above.

You may need to implement one or re-structure an existing implementation (e.g. the one from linux) into separate header files, so you can include in both bpf program and your user space application.

Quoted 8 lines

Can you please point to some examples or references? We would be highly grateful.

Thanks,
Sincerely,