BPF updates
Subsystems (6)
v2 cover BPF updates
I had these cleanups still in my queue before the merge window. The set is against net-next tree, but with 83d5b7ef99 ("net: filter:
initialize A and X registers") applied on top of it, so a merge of net into net-next would be required *before* applying this set.
The main objective for these updates is that we get the code a bit more readable/comprehensible and avoid one additional instruction in the interpreter during fast-path.
Tested with Alexei's BPF test suite and seccomp test suite, no issues found.
Thanks!
v1->v2:
- Only changed patch 5 as to suggestion from Alexei
- Rest is the same
Daniel Borkmann (5):
net: filter: simplify label names from jump-table
net: filter: misc/various cleanups
net: filter: get rid of sock_fprog_kern
net: filter: make register namings more comprehensible
net: filter: optimize BPF migration for ARG1/CTX handling
include/linux/filter.h | 60 ++++-- net/core/filter.c | 568 ++++++++++++++++++++++++------------------------- net/core/sock_diag.c | 4 +- 3 files changed, 329 insertions(+), 303 deletions(-)
Signature · 1 line
1.7.11.7
PATCH v2 1/5 net: filter: simplify label names from jump-table
This patch simplifies label naming for the BPF jump-table. When we define labels via DL(), we just concatenate/textify the combination of instruction opcode which consists of the class, subclass, word size, target register and so on. Each time we leave BPF_ prefix intact, so that e.g. the preprocessor generates a label BPF_ALU_BPF_ADD_BPF_X for DL(BPF_ALU, BPF_ADD, BPF_X) whereas a label name of ALU_ADD_X is much more easy to grasp.
--- include/linux/filter.h | 3 + net/core/filter.c | 308 ++++++++++++++++++++++++------------------------- 2 files changed, 157 insertions(+), 154 deletions(-)
include/linux/filter.h +3 -0
@@ -37,6 +37,9 @@#define BPF_CALL 0x80/* function call */ #define BPF_EXIT 0x90/* function return */ +/* Placeholder/dummy for 0 */ +#define BPF_0 0 +/* BPF has 10 general purpose 64-bit registers and stack frame. */ #define MAX_BPF_REG 11
net/core/filter.c +154 -154
504 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH v2 2/5 net: filter: misc/various cleanups
In reply to Daniel BorkmannThis contains only some minor misc cleanpus. We can spare us the extra variable declaration in __skb_get_pay_offset(), we can mark some unexpected conditions in the fast-path as unlikely(), the cast in __get_random_u32() is rather unnecessary and in __sk_migrate_realloc() we can remove the memcpy() and do a direct assignment of the structs. Latter was suggested by Fengguang Wu found with coccinelle.
--- net/core/filter.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
net/core/filter.c +10 -11
@@ -57,9 +57,9 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns ptr =skb_network_header (skb) + k -SKF_NET_OFF ; else if (k >= SKF_LL_OFF) ptr =skb_mac_header (skb) + k -SKF_LL_OFF ; -if (ptr >= skb->head && ptr + size <=skb_tail_pointer (skb))return ptr; +return NULL ; }
@@ -68,6 +68,7 @@ static inline void *load_pointer(const struct sk_buff *skb, int k, {if (k >=0 )return skb_header_pointer (skb, k, size, buffer); +return bpf_internal_load_pointer_neg_helper (skb, k, size); }
@@ -596,9 +597,7 @@ static unsigned int pkt_type_offset(void)static u64 __skb_get_pay_offset (u64 ctx,u64 A ,u64 X ,u64 r4,u64 r5) { -struct sk_buff *skb = (struct sk_buff *)(long ) ctx; - -return __skb_get_poff (skb); +return __skb_get_poff ((struct sk_buff *)(long ) ctx); }static u64 __skb_get_nlattr (u64 ctx,u64 A ,u64 X ,u64 r4,u64 r5)
@@ -609,10 +608,10 @@ static u64 __skb_get_nlattr(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)if (skb_is_nonlinear (skb))return 0 ; -if (skb->len <sizeof (struct nlattr )) +if (unlikely (skb->len <sizeof (struct nlattr )))return 0 ; -if (A > skb->len -sizeof (struct nlattr )) +if (unlikely (A > skb->len -sizeof (struct nlattr )))return 0 ; nla =nla_find ((struct nlattr *) &skb->data[A ], skb->len -A ,X );
@@ -630,14 +629,14 @@ static u64 __skb_get_nlattr_nest(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)if (skb_is_nonlinear (skb))return 0 ; -if (skb->len <sizeof (struct nlattr )) +if (unlikely (skb->len <sizeof (struct nlattr )))return 0 ; -if (A > skb->len -sizeof (struct nlattr )) +if (unlikely (A > skb->len -sizeof (struct nlattr )))return 0 ; nla = (struct nlattr *) &skb->data[A ]; -if (nla->nla_len > skb->len -A ) +if (unlikely (nla->nla_len > skb->len -A ))return 0 ; nla =nla_find_nested (nla,X );
@@ -655,7 +654,7 @@ static u64 __get_raw_cpu_id(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)/* note that this only generates 32-bit random numbers */ static u64 __get_random_u32 (u64 ctx,u64 A ,u64 X ,u64 r4,u64 r5) { -return (u64 )prandom_u32 (); +return prandom_u32 (); } static bool convert_bpf_extensions(struct sock_filter *fp,
@@ -1472,7 +1471,7 @@ static struct sk_filter *__sk_migrate_realloc(struct sk_filter *fp, fp_new =sock_kmalloc (sk, len,GFP_KERNEL );if (fp_new) { -memcpy (fp_new, fp,sizeof (struct sk_filter )); + *fp_new = *fp;/* As we're kepping orig_prog in fp_new along, * we need to make sure we're not evicting it * from the old fp.
Signature · 1 line
1.7.11.7
David Miller
maintainerRe: [PATCH net-next v2 2/5] net: filter: misc/various cleanups
From: Daniel Borkmann <[email protected]>
Date: Thu, 24 Apr 2014 08:45:24 +0200
net/core/filter.c static unsigned int pkt_type_offset(void) · line 600
Quoted 1 line
net/core/filter.c +1
-0+return __skb_get_poff ((struct sk_buff *)(long ) ctx);
Please use "unsigned long" when casting pointers to/from integers.
Re: [PATCH net-next v2 2/5] net: filter: misc/various cleanups
Quoted 6 lines · David Miller
From: Daniel Borkmann <[email protected]>
Date: Thu, 24 Apr 2014 08:45:24 +0200net/core/filter.c static unsigned int pkt_type_offset(void) · line 600
Quoted 1 line
net/core/filter.c +1
-0+return __skb_get_poff ((struct sk_buff *)(long ) ctx);Please use "unsigned long" when casting pointers to/from integers.
I'll fix it up, thanks.
There's ongoing work to improve the documentation file to address your concerns.
Thanks,
Daniel
PATCH v2 3/5 net: filter: get rid of sock_fprog_kern
In reply to Daniel BorkmannIt is actually cleaner to just get rid of sock_fprog_kern structure. It's not really useful as we can just use sock_fprog structure as we do elsewhere in the kernel, this could throw some sparse false positives though, but getting rid of the structure duplication is probably the better way to go.
--- include/linux/filter.h | 13 +++++-------- net/core/filter.c | 24 ++++++++++++------------ net/core/sock_diag.c | 4 ++-- 3 files changed, 19 insertions(+), 22 deletions(-)
include/linux/filter.h +5 -8
@@ -67,11 +67,6 @@ struct compat_sock_fprog { };#endif -struct sock_fprog_kern { -u16 len; -struct sock_filter *filter; -}; -struct sk_buff ;struct sock ;struct seccomp_data ;
@@ -80,7 +75,7 @@ struct sk_filter {atomic_t refcnt; u32 jited:1, /* Is our filter JIT'ed? */ len:31; /* Number of filter blocks */ -struct sock_fprog_kern *orig_prog;/* Original BPF program */ +struct sock_fprog *orig_prog;/* Original BPF program */ struct rcu_head rcu;unsigned int (*bpf_func)(const struct sk_buff *skb,const struct sock_filter_int *filter);
@@ -97,8 +92,10 @@ static inline unsigned int sk_filter_size(unsigned int proglen) offsetof(struct sk_filter, insns[proglen])); } -#define sk_filter_proglen (fprog) \ - (fprog->len * sizeof(fprog->filter[0])) +static inline unsigned int sk_filter_prog_size (const struct sock_fprog *fprog) +{ +return fprog->len *sizeof (fprog->filter[0 ]); +}#define SK_RUN_FILTER (filter, ctx) \ (*filter->bpf_func)(ctx, filter->insnsi)
net/core/filter.c +12 -12
@@ -1396,17 +1396,17 @@ EXPORT_SYMBOL(sk_chk_filter);static int sk_store_orig_filter (struct sk_filter *fp,const struct sock_fprog *fprog) { -unsigned int fsize =sk_filter_proglen (fprog); -struct sock_fprog_kern *fkprog; +unsigned int fsize =sk_filter_prog_size (fprog); +struct sock_fprog *op; - fp->orig_prog =kmalloc (sizeof (*fkprog),GFP_KERNEL ); + fp->orig_prog =kmalloc (sizeof (*op),GFP_KERNEL );if (!fp->orig_prog)return -ENOMEM ; - fkprog = fp->orig_prog; - fkprog->len = fprog->len; - fkprog->filter =kmemdup (fp->insns, fsize,GFP_KERNEL ); -if (!fkprog->filter) { + op = fp->orig_prog; + op->len = fprog->len; + op->filter =kmemdup (fp->insns, fsize,GFP_KERNEL ); +if (!op->filter) {kfree (fp->orig_prog);return -ENOMEM ; }
@@ -1416,7 +1416,7 @@ static int sk_store_orig_filter(struct sk_filter *fp,static void sk_release_orig_filter (struct sk_filter *fp) { -struct sock_fprog_kern *fprog = fp->orig_prog; +struct sock_fprog *fprog = fp->orig_prog;if (fprog) {kfree (fprog->filter);
@@ -1599,7 +1599,7 @@ static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,int sk_unattached_filter_create (struct sk_filter **pfp,struct sock_fprog *fprog) { -unsigned int fsize =sk_filter_proglen (fprog); +unsigned int fsize =sk_filter_prog_size (fprog);struct sk_filter *fp;/* Make sure new filter is there and in the right amounts. */
@@ -1651,7 +1651,7 @@ EXPORT_SYMBOL_GPL(sk_unattached_filter_destroy);int sk_attach_filter (struct sock_fprog *fprog,struct sock *sk) {struct sk_filter *fp, *old_fp; -unsigned int fsize =sk_filter_proglen (fprog); +unsigned int fsize =sk_filter_prog_size (fprog);unsigned int sk_fsize =sk_filter_size (fprog->len);int err;
@@ -1799,7 +1799,7 @@ void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to)int sk_get_filter (struct sock *sk,struct sock_filter __user *ubuf,unsigned int len) { -struct sock_fprog_kern *fprog; +struct sock_fprog *fprog;struct sk_filter *filter;int ret =0 ;
@@ -1824,7 +1824,7 @@ int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf, goto out; ret = -EFAULT ; -if (copy_to_user (ubuf, fprog->filter,sk_filter_proglen (fprog))) +if (copy_to_user (ubuf, fprog->filter,sk_filter_prog_size (fprog))) goto out;/* Instead of bytes, the API requests to return the number
net/core/sock_diag.c +2 -2
@@ -52,7 +52,7 @@ EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);int sock_diag_put_filterinfo (struct user_namespace *user_ns,struct sock *sk,struct sk_buff *skb,int attrtype) { -struct sock_fprog_kern *fprog; +struct sock_fprog *fprog;struct sk_filter *filter;struct nlattr *attr;unsigned int flen;
@@ -69,7 +69,7 @@ int sock_diag_put_filterinfo(struct user_namespace *user_ns, struct sock *sk, goto out; fprog = filter->orig_prog; - flen =sk_filter_proglen (fprog); + flen =sk_filter_prog_size (fprog); attr =nla_reserve (skb, attrtype, flen);if (attr ==NULL ) {
Signature · 1 line
1.7.11.7
David Miller
maintainerRe: [PATCH net-next v2 3/5] net: filter: get rid of sock_fprog_kern
From: Daniel Borkmann <[email protected]>
Date: Thu, 24 Apr 2014 08:45:25 +0200
Quoted 8 lines
It is actually cleaner to just get rid of
sock_fprog_kernstructure. It's not really useful as we can just usesock_fprogstructure as we do elsewhere in the kernel, this could throw some sparse false positives though, but getting rid of the structure duplication is probably the better way to go.Signed-off-by Daniel Borkmann <[email protected]>
But this is the whole point of sock_fprog_kern.
It's so that we can always have the correct type for the pointers, and we can show cleanly (without lots of ugly casts) to sparse that whether we expect a pointer to be a user or a kernel one.
I really don't like this change, sorry.
Re: [PATCH net-next v2 3/5] net: filter: get rid of sock_fprog_kern
On 04/24/2014 10:02 PM, David Miller wrote:
...
Quoted 3 lines
It's so that we can always have the correct type for the pointers, and we can show cleanly (without lots of ugly casts) to sparse that whether we expect a pointer to be a user or a kernel one.
Understood, I'll take the time to go the other way around and try to convert sk_unattached_filter_create() API to use struct sock_fprog_kern instead as this is only for in-kernel users.
PATCH v2 4/5 net: filter: make register namings more comprehensible
In reply to Daniel BorkmannThe current code is a bit hard to parse on which registers can be used, how they are mapped and all play together. It makes much more sense to define this a bit more clearly so that the code is a bit more intuitive. This patch cleans this up, and makes naming a bit more consistent among the code. This also allows for moving some of the defines into the header file. Clearing of A and X registers in __sk_run_filter() do not get a particular register name assigned as they have not an 'official' function, but rather just result from the concrete initial mapping. Since for BPF helper functions for BPF_CALL we already use small letters, so be consistent here as well.
--- include/linux/filter.h | 44 ++++++++-- net/core/filter.c | 215 +++++++++++++++++++++++++------------------------ 2 files changed, 145 insertions(+), 114 deletions(-)
include/linux/filter.h +36 -8
@@ -40,16 +40,47 @@/* Placeholder/dummy for 0 */ #define BPF_0 0 +/* Register numbers */ +enum { +BPF_REG_0 =0 , +BPF_REG_1 , +BPF_REG_2 , +BPF_REG_3 , +BPF_REG_4 , +BPF_REG_5 , +BPF_REG_6 , +BPF_REG_7 , +BPF_REG_8 , +BPF_REG_9 , +BPF_REG_10 , + __MAX_BPF_REG, +}; +/* BPF has 10 general purpose 64-bit registers and stack frame. */ -#define MAX_BPF_REG 11 +#define MAX_BPF_REG __MAX_BPF_REG + +/* ArgX, context and stack frame pointer register positions. Note, +* Arg1, Arg2, Arg3, etc are used as argument mappings of function +* calls in BPF_CALL instruction. +*/ +#define BPF_REG_ARG1 BPF_REG_1 +#define BPF_REG_ARG2 BPF_REG_2 +#define BPF_REG_ARG3 BPF_REG_3 +#define BPF_REG_ARG4 BPF_REG_4 +#define BPF_REG_ARG5 BPF_REG_5 +#define BPF_REG_CTX BPF_REG_6 +#define BPF_REG_FP BPF_REG_10 + +/* Additional register mappings for converted user programs. */ +#define BPF_REG_A BPF_REG_0 +#define BPF_REG_X BPF_REG_7 +#define BPF_REG_TMP BPF_REG_8/* BPF program can access up to 512 bytes of stack space. */ #define MAX_BPF_STACK 512 -/* Arg1, context and stack frame pointer register positions. */ -#define ARG1_REG 1 -#define CTX_REG 6 -#define FP_REG 10 +/* Macro to invoke filter function. */ +#define SK_RUN_FILTER (filter, ctx) (*filter->bpf_func)(ctx, filter->insnsi)struct sock_filter_int {__u8 code;/* opcode */
@@ -97,9 +128,6 @@ static inline unsigned int sk_filter_prog_size(const struct sock_fprog *fprog)return fprog->len *sizeof (fprog->filter[0 ]); } -#define SK_RUN_FILTER (filter, ctx) \ - (*filter->bpf_func)(ctx, filter->insnsi) -int sk_filter (struct sock *sk,struct sk_buff *skb); u32 sk_run_filter_int_seccomp(const struct seccomp_data *ctx,
net/core/filter.c +109 -106
498 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH v2 5/5 net: filter: optimize BPF migration for ARG1/CTX handling
In reply to Daniel BorkmannCurrently, at initial setup in __sk_run_filter() we initialize the BPF stack's frame-pointer and CTX register. However, instead of the CTX register, we initialize context to ARG1, and during user filter migration we emit *always* an instruction that copies the content from ARG1 over to CTX. ARG1 is needed in BPF_CALL instructions to setup ctx; for user BPF filter ARG2 has A, and ARG3 X for call emission. However, we nevertheless copy CTX over to ARG1 in these cases for user migrated filters. We can spare us this extra interpreter instruction and assign it during initial setup time.
--- net/core/filter.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
net/core/filter.c +4 -8
@@ -257,7 +257,10 @@ unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *insn)#define CONT_JMP ({ insn++; goto select_insn; })FP = (u64 ) (unsigned long ) &stack[ARRAY_SIZE (stack)]; -ARG1 = (u64 ) (unsigned long ) ctx; +CTX = (u64 ) (unsigned long ) ctx; + +/* Direct users expect arg1 to be filled already with ctx. */ +ARG1 =CTX ;/* Register for user BPF programs need to be reset first. */ regs[BPF_REG_A ] =0 ;
@@ -896,13 +899,6 @@ do_pass: new_insn = new_prog; fp = prog; -if (new_insn) { - new_insn->code =BPF_ALU64 |BPF_MOV |BPF_X ; - new_insn->a_reg =BPF_REG_CTX ; - new_insn->x_reg =BPF_REG_ARG1 ; - } - new_insn++; -for (i =0 ; i < len; fp++, i++) {struct sock_filter_int tmp_insns[6 ] = { };struct sock_filter_int *insn = tmp_insns;
Signature · 1 line
1.7.11.7
Re: [PATCH net-next v2 5/5] net: filter: optimize BPF migration for ARG1/CTX handling
Quoted 10 lines · Daniel Borkmann
Currently, at initial setup in
__sk_run_filter()we initialize the BPF stack's frame-pointer and CTX register. However, instead of the CTX register, we initialize context to ARG1, and during user filter migration we emit *always* an instruction that copies the content from ARG1 over to CTX. ARG1 is needed inBPF_CALLinstructions to setup ctx; for user BPF filter ARG2 has A, and ARG3 X for call emission. However, we nevertheless copy CTX over to ARG1 in these cases for user migrated filters. We can spare us this extra interpreter instruction and assign it during initial setup time.
Quoted 2 lines
Signed-off-by Daniel Borkmann <[email protected]>Cc Alexei Starovoitov <[email protected]>
Quoted 2 lines
opinion on this particular patch, just wanted to have clarified what we have with ABI here as there's no particular freeze from the code we have
yes. Of course, we do not have a freeze on ABI.
I was arguing about merits of not changing it for this particular case. Especially when the difference is a single line of code.
If we want to add another register to ISA, that would be a fine reason to change it.
Thanks!
Quoted 37 lines
--- net/core/filter.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)net/core/filter.c +4
-9@@ -257,7 +257,10 @@ unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *insn)#define CONT_JMP ({ insn++; goto select_insn; })FP = (u64 ) (unsigned long ) &stack[ARRAY_SIZE (stack)]; -ARG1 = (u64 ) (unsigned long ) ctx; +CTX = (u64 ) (unsigned long ) ctx; + +/* Direct users expect arg1 to be filled already with ctx. */ +ARG1 =CTX ;/* Register for user BPF programs need to be reset first. */ regs[BPF_REG_A ] =0 ;@@ -896,13 +899,6 @@ do_pass: new_insn = new_prog; fp = prog; -if (new_insn) { - new_insn->code =BPF_ALU64 |BPF_MOV |BPF_X ; - new_insn->a_reg =BPF_REG_CTX ; - new_insn->x_reg =BPF_REG_ARG1 ; - } - new_insn++; -for (i =0 ; i < len; fp++, i++) {struct sock_filter_int tmp_insns[6 ] = { };struct sock_filter_int *insn = tmp_insns; --1.7.11.7
David Miller
maintainerRe: [PATCH net-next v2 5/5] net: filter: optimize BPF migration for ARG1/CTX handling
In reply to Daniel BorkmannFrom: Daniel Borkmann <[email protected]>
Date: Thu, 24 Apr 2014 08:45:27 +0200
Quoted 11 lines
Currently, at initial setup in
__sk_run_filter()we initialize the BPF stack's frame-pointer and CTX register. However, instead of the CTX register, we initialize context to ARG1, and during user filter migration we emit *always* an instruction that copies the content from ARG1 over to CTX. ARG1 is needed inBPF_CALLinstructions to setup ctx; for user BPF filter ARG2 has A, and ARG3 X for call emission. However, we nevertheless copy CTX over to ARG1 in these cases for user migrated filters. We can spare us this extra interpreter instruction and assign it during initial setup time.Signed-off-by Daniel Borkmann <[email protected]>
We're adjust code for facilities that aren't even used.
I want someone to explain to me exactly how calls in and out of the EBPF context are expected to behave.
There are so many cpu calling conventions. Some use registers up to a certain number for passing arguments, then any overflow args go on the stack. Some pass all args on the stack.
How will all such schemes be accomodated by the BPF_CALL facilities?
Until I personally can even begin to understand this, I'm not applying any more patches to these areas of the code, sorry.
Re: [PATCH net-next v2 5/5] net: filter: optimize BPF migration for ARG1/CTX handling
Quoted 17 lines · David Miller
From: Daniel Borkmann <[email protected]>
Date: Thu, 24 Apr 2014 08:45:27 +0200Quoted 11 lines
Currently, at initial setup in
__sk_run_filter()we initialize the BPF stack's frame-pointer and CTX register. However, instead of the CTX register, we initialize context to ARG1, and during user filter migration we emit *always* an instruction that copies the content from ARG1 over to CTX. ARG1 is needed inBPF_CALLinstructions to setup ctx; for user BPF filter ARG2 has A, and ARG3 X for call emission. However, we nevertheless copy CTX over to ARG1 in these cases for user migrated filters. We can spare us this extra interpreter instruction and assign it during initial setup time.Signed-off-by Daniel Borkmann <[email protected]>We're adjust code for facilities that aren't even used.
Quoted 8 lines
I want someone to explain to me exactly how calls in and out of the EBPF context are expected to behave.
There are so many cpu calling conventions. Some use registers up to a certain number for passing arguments, then any overflow args go on the stack. Some pass all args on the stack.
How will all such schemes be accomodated by the
BPF_CALLfacilities?
calling convention was picked to cover common call situations without performance penalty:
"R1-R5 - arguments to in-kernel function or to bpf program"
Calls from kernel into bpf are limited to one argument (in R1), since that's what socket filters and seccomp use,
and tracing filters will be fine as well.
(can be extended in the future if needed).
Calls from bpf to kernel are limited to 5 arguments and all in kernel helper functions look like:
u64 __bpf_helper_func(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); these functions may ignore some or all arguments,
(since on most architectures there is no penalty to ignore args and negligible cost to pass them comparing to the rest of the program)
Calls from bpf to kernel with 6 or more arguments are not supported, since they are rare in normal programs and would unnecessary complicate code and JITs.x86_64 passes first 6 arguments via registers and the rest on the stack, other 64-bit architectures pass 7+ in registers.
So from JITs point of view passing 5 is straightforward and no messy stack manipulations are necessary.
JIT to 32-bit CPUs is not easy,
since all ebpf registers are 64-bit, but underlying cpu is 32-bit, JIT needs to do 64-bit arithmetic with 32-bit hw registers. Can be an interesting project for someone with time on hands. In any case ebpf interpreter is quite fast and well optimized.
32-bit JITs can use middle ground approach too.
If program contains only 32-bit arithmetic, jit it, otherwise let interpreter run it.
btw the JIT of BPF_CALL to x86_64 looks like:
case BPF_JMP | BPF_CALL:
func = (u8 *)__bpf_call_base + K;
jmp_offset = func - (image + addrs[i]);
if (!K || !is_simm32(jmp_offset)) {
pr_err(...);
return -EINVAL;
}
EMIT1_off32(0xE8, jmp_offset);
break;it's really one to one.
Quoted 2 lines
Until I personally can even begin to understand this, I'm not applying any more patches to these areas of the code, sorry.
Point taken.
We realize that documentation in filter.txt is not sufficient. Last few days we've been working on extensive documentation update. It should be ready by Monday or Tuesday.
Thank you
Alexei