From 86a5001d4ad7111bd565d8fc4de9c231b8a9e835 Mon Sep 17 00:00:00 2001 From: Alan Jowett Date: Tue, 1 Jun 2021 16:27:25 -0600 Subject: [PATCH 1/3] Fix register mapping to avoid volatile registers and issues with R12 Signed-off-by: Alan Jowett --- vm/ubpf_jit_x86_64.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vm/ubpf_jit_x86_64.c b/vm/ubpf_jit_x86_64.c index 6e8db798..41a833af 100644 --- a/vm/ubpf_jit_x86_64.c +++ b/vm/ubpf_jit_x86_64.c @@ -52,15 +52,21 @@ static int platform_parameter_registers[] = { RCX, RDX, R8, R9 }; #define RCX_ALT R15 +// Register assignments: +// BPF R0-R4 are "volatile" +// BPF R5-R10 are "non-volatile" +// Map BPF volatile registers to x64 volatile and map BPF non-volatile to +// x64 non-volatile. +// Avoid R12 as we don't support encoding modrm modifier for using R12. static int register_map[REGISTER_MAP_SIZE] = { RAX, R15, RDX, R8, R9, - R10, - R11, - R12, + RBX, + RDI, + RSI, R13, R14, RBP, From e2b41e24ee76f04c64a36454c549acab891959a7 Mon Sep 17 00:00:00 2001 From: Alan Jowett Date: Tue, 1 Jun 2021 19:04:39 -0600 Subject: [PATCH 2/3] Tweak register mapping Signed-off-by: Alan Jowett --- vm/ubpf_jit_x86_64.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vm/ubpf_jit_x86_64.c b/vm/ubpf_jit_x86_64.c index 41a833af..fb8a403b 100644 --- a/vm/ubpf_jit_x86_64.c +++ b/vm/ubpf_jit_x86_64.c @@ -51,7 +51,7 @@ static int platform_nonvolatile_registers[] = { static int platform_parameter_registers[] = { RCX, RDX, R8, R9 }; -#define RCX_ALT R15 +#define RCX_ALT R10 // Register assignments: // BPF R0-R4 are "volatile" // BPF R5-R10 are "non-volatile" @@ -64,11 +64,11 @@ static int register_map[REGISTER_MAP_SIZE] = { RDX, R8, R9, - RBX, + R14, + R15, RDI, RSI, - R13, - R14, + RBX, RBP, }; #else From 955e51cca08fbe75b683fe213db5140468f251c4 Mon Sep 17 00:00:00 2001 From: Alan Jowett Date: Mon, 7 Jun 2021 09:01:01 -0600 Subject: [PATCH 3/3] PR feedback Signed-off-by: Alan Jowett --- vm/ubpf_jit_x86_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/ubpf_jit_x86_64.c b/vm/ubpf_jit_x86_64.c index fb8a403b..a9b488bf 100644 --- a/vm/ubpf_jit_x86_64.c +++ b/vm/ubpf_jit_x86_64.c @@ -60,7 +60,7 @@ static int platform_parameter_registers[] = { // Avoid R12 as we don't support encoding modrm modifier for using R12. static int register_map[REGISTER_MAP_SIZE] = { RAX, - R15, + R10, RDX, R8, R9,