filter: add XOR instruction for use with X/K
Subsystems (5)
PATCH 1/1 filter: add XOR instruction for use with X/K
BPF_S_ANC_ALU_XOR_X has been added a while ago, but as an 'ancillary' operation that is invoked through a negative offset in K within BPF load operations. Since BPF_MOD has recently been added, BPF_XOR should also be part of the common ALU operations. Removing BPF_S_ANC_ALU_XOR_X might not be an option since this is exposed to user space.
--- include/linux/filter.h | 3 +++ net/core/filter.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
include/linux/filter.h +3 -0
@@ -75,6 +75,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */#define BPF_RSH 0x70#define BPF_NEG 0x80#define BPF_MOD 0x90 +#define BPF_XOR 0xa0#define BPF_JA 0x00#define BPF_JEQ 0x10
@@ -204,6 +205,8 @@ enum {BPF_S_ALU_AND_X ,BPF_S_ALU_OR_K ,BPF_S_ALU_OR_X , +BPF_S_ALU_XOR_K , +BPF_S_ALU_XOR_X ,BPF_S_ALU_LSH_K ,BPF_S_ALU_LSH_X , BPF_S_ALU_RSH_K,
net/core/filter.c +9 -3
@@ -187,6 +187,13 @@ unsigned int sk_run_filter(const struct sk_buff *skb,case BPF_S_ALU_OR_K :A |=K ;continue ; +case BPF_S_ANC_ALU_XOR_X : +case BPF_S_ALU_XOR_X : +A ^=X ; +continue ; +case BPF_S_ALU_XOR_K : +A ^=K ; +continue ;case BPF_S_ALU_LSH_X :A <<=X ;continue ;
@@ -334,9 +341,6 @@ load_b:case BPF_S_ANC_CPU :A =raw_smp_processor_id ();continue ; -case BPF_S_ANC_ALU_XOR_X : -A ^=X ; -continue ;case BPF_S_ANC_NLATTR : {struct nlattr *nla;
@@ -483,6 +487,8 @@ int sk_chk_filter(struct sock_filter *filter, unsigned int flen) [BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X, [BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K, [BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X, + [BPF_ALU|BPF_XOR|BPF_K] = BPF_S_ALU_XOR_K, + [BPF_ALU|BPF_XOR|BPF_X] = BPF_S_ALU_XOR_X, [BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K, [BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X, [BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K,
Quoted 5 lines · Daniel Borkmann
BPF_S_ANC_ALU_XOR_Xhas been added a while ago, but as an 'ancillary' operation that is invoked through a negative offset in K within BPF load operations. SinceBPF_MODhas recently been added,BPF_XORshould also be part of the common ALU operations. RemovingBPF_S_ANC_ALU_XOR_Xmight not be an option since this is exposed to user space.
Please note we dont expose BPF_S_ANC_ALU_XOR_X to user space.
We expose SKF_AD_ALU_XOR_X instead.
But it seems easier to leave it to keep this patch small (not touching various JIT implementations, even if followup are welcomed)
Quoted 10 lines · Eric Dumazet <[email protected]> [2012-09-24 15:43:48 +0200] wrote:
Quoted 5 lines · Daniel Borkmann
BPF_S_ANC_ALU_XOR_Xhas been added a while ago, but as an 'ancillary' operation that is invoked through a negative offset in K within BPF load operations. SinceBPF_MODhas recently been added,BPF_XORshould also be part of the common ALU operations. RemovingBPF_S_ANC_ALU_XOR_Xmight not be an option since this is exposed to user space.Please note we dont expose
BPF_S_ANC_ALU_XOR_Xto user space.We expose
SKF_AD_ALU_XOR_Xinstead.
Indeed. Sorry for that typo.
Quoted 6 lines
But it seems easier to leave it to keep this patch small (not touching various JIT implementations, even if followup are welcomed)
Acked-by Eric Dumazet <[email protected]>
From: Eric Dumazet <[email protected]>
Date: Mon, 24 Sep 2012 15:43:48 +0200
Quoted 7 lines · Daniel Borkmann
Quoted 5 lines
BPF_S_ANC_ALU_XOR_Xhas been added a while ago, but as an 'ancillary' operation that is invoked through a negative offset in K within BPF load operations. SinceBPF_MODhas recently been added,BPF_XORshould also be part of the common ALU operations. RemovingBPF_S_ANC_ALU_XOR_Xmight not be an option since this is exposed to user space.
Quoted 8 lines
Please note we dont expose
BPF_S_ANC_ALU_XOR_Xto user space.We expose
SKF_AD_ALU_XOR_Xinstead.But it seems easier to leave it to keep this patch small (not touching various JIT implementations, even if followup are welcomed)
Acked-by Eric Dumazet <[email protected]>
I applied this, fixing the commit message to refer to SKF_AD_ALU_XOR_X instead of BPF_S_ANC_ALU_XOR_X.
Quoted 13 lines · David Miller <[email protected]> [2012-09-24 16:50:05 -0400] wrote:
From: Eric Dumazet <[email protected]>
Date: Mon, 24 Sep 2012 15:43:48 +0200Quoted 11 lines · Daniel Borkmann
Quoted 5 lines
BPF_S_ANC_ALU_XOR_Xhas been added a while ago, but as an 'ancillary' operation that is invoked through a negative offset in K within BPF load operations. SinceBPF_MODhas recently been added,BPF_XORshould also be part of the common ALU operations. RemovingBPF_S_ANC_ALU_XOR_Xmight not be an option since this is exposed to user space.Please note we dont expose
BPF_S_ANC_ALU_XOR_Xto user space.We expose
SKF_AD_ALU_XOR_Xinstead.
Quoted 7 lines
Quoted 4 lines
But it seems easier to leave it to keep this patch small (not touching various JIT implementations, even if followup are welcomed)
Acked-by Eric Dumazet <[email protected]>I applied this, fixing the commit message to refer to
SKF_AD_ALU_XOR_Xinstead ofBPF_S_ANC_ALU_XOR_X.
Thanks David!