Skip to contentSkip to conversation

net: filter: rename 'struct sock_filter_int' into 'struct bpf_insn'

PATCH Superseded Alexei Starovoitov 2 participants 4 messages Jul 24, 2014

Subsystems (9)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: filter: rename 'struct sock_filter_int' into 'struct bpf_insn'

eBPF is used by socket filtering, seccomp and soon by tracing and exposed to userspace, therefore 'sock_filter_int' name is not accurate. Rename it to 'bpf_insn'

---
 arch/x86/net/bpf_jit_comp.c |    2 +-
 include/linux/filter.h      |   50 +++++++++++++++++++++----------------------
 kernel/bpf/core.c           |    2 +-
 kernel/seccomp.c            |    2 +-
 lib/test_bpf.c              |    4 ++--
 net/core/filter.c           |   18 ++++++++--------
 6 files changed, 39 insertions(+), 39 deletions(-)
arch/x86/net/bpf_jit_comp.c +1 -1
index 99bef86ed6df..71737a83f022 100644
@@ -214,7 +214,7 @@ struct jit_context {
 static int do_jit(struct sk_filter *bpf_prog, int *addrs, u8 *image,
 		  int oldproglen, struct jit_context *ctx)
 {
-	struct sock_filter_int *insn = bpf_prog->insnsi;
+	struct bpf_insn *insn = bpf_prog->insnsi;
 	int insn_cnt = bpf_prog->len;
 	u8 temp[64];
 	int i;
include/linux/filter.h +25 -25

196 lines not on this page · raw message

kernel/bpf/core.c +1 -1
index 77a240a1ce11..265a02cc822d 100644
@@ -81,7 +81,7 @@ noinline u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
  * keep, 0 for none. @ctx is the data we are operating on, @insn is the
  * array of filter instructions.
  */
-static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *insn)
+static unsigned int __sk_run_filter(void *ctx, const struct bpf_insn *insn)
 {
 	u64 stack[MAX_BPF_STACK / sizeof(u64)];
 	u64 regs[MAX_BPF_REG], tmp;
kernel/seccomp.c +1 -1
index 301bbc24739c..565743db5384 100644
@@ -248,7 +248,7 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
 	if (ret)
 		goto free_prog;
 
-	/* Convert 'sock_filter' insns to 'sock_filter_int' insns */
+	/* Convert 'sock_filter' insns to 'bpf_insn' insns */
 	ret = sk_convert_filter(fp, fprog->len, NULL, &new_len);
 	if (ret)
 		goto free_prog;
lib/test_bpf.c +2 -2
index c579e0f58818..5f48623ee1a7 100644
@@ -66,7 +66,7 @@ struct bpf_test {
 	const char *descr;
 	union {
 		struct sock_filter insns[MAX_INSNS];
-		struct sock_filter_int insns_int[MAX_INSNS];
+		struct bpf_insn insns_int[MAX_INSNS];
 	} u;
 	__u8 aux;
 	__u8 data[MAX_DATA];
@@ -1807,7 +1807,7 @@ static struct sk_filter *generate_filter(int which, int *err)
 
 		fp->len = flen;
 		memcpy(fp->insnsi, tests[which].u.insns_int,
-		       fp->len * sizeof(struct sock_filter_int));
+		       fp->len * sizeof(struct bpf_insn));
 
 		sk_filter_select_runtime(fp);
 		break;
net/core/filter.c +9 -9
index 1d0e9492e4fa..f3b2d5e9fe5f 100644
@@ -174,9 +174,9 @@ static u64 __get_random_u32(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
 }
 
 static bool convert_bpf_extensions(struct sock_filter *fp,
-				   struct sock_filter_int **insnp)
+				   struct bpf_insn **insnp)
 {
-	struct sock_filter_int *insn = *insnp;
+	struct bpf_insn *insn = *insnp;
 
 	switch (fp->k) {
 	case SKF_AD_OFF + SKF_AD_PROTOCOL:
@@ -326,7 +326,7 @@ static bool convert_bpf_extensions(struct sock_filter *fp,
  *
  * 2) 2nd pass to remap in two passes: 1st pass finds new
  *    jump offsets, 2nd pass remapping:
- *   new_prog = kmalloc(sizeof(struct sock_filter_int) * new_len);
+ *   new_prog = kmalloc(sizeof(struct bpf_insn) * new_len);
  *   sk_convert_filter(old_prog, old_len, new_prog, &new_len);
  *
  * User BPF's register A is mapped to our BPF register 6, user BPF
@@ -336,10 +336,10 @@ static bool convert_bpf_extensions(struct sock_filter *fp,
  * ctx == 'struct seccomp_data *'.
  */
 int sk_convert_filter(struct sock_filter *prog, int len,
-		      struct sock_filter_int *new_prog, int *new_len)
+		      struct bpf_insn *new_prog, int *new_len)
 {
 	int new_flen = 0, pass = 0, target, i;
-	struct sock_filter_int *new_insn;
+	struct bpf_insn *new_insn;
 	struct sock_filter *fp;
 	int *addrs = NULL;
 	u8 bpf_src;
@@ -365,8 +365,8 @@ do_pass:
 	new_insn++;
 
 	for (i = 0; i < len; fp++, i++) {
-		struct sock_filter_int tmp_insns[6] = { };
-		struct sock_filter_int *insn = tmp_insns;
+		struct bpf_insn tmp_insns[6] = { };
+		struct bpf_insn *insn = tmp_insns;
 
 		if (addrs)
 			addrs[i] = new_insn - new_prog;
@@ -913,7 +913,7 @@ static struct sk_filter *__sk_migrate_filter(struct sk_filter *fp,
 	 * representation.
 	 */
 	BUILD_BUG_ON(sizeof(struct sock_filter) !=
-		     sizeof(struct sock_filter_int));
+		     sizeof(struct bpf_insn));
 
 	/* Conversion cannot happen on overlapping memory areas,
 	 * so we need to keep the user BPF around until the 2nd
@@ -945,7 +945,7 @@ static struct sk_filter *__sk_migrate_filter(struct sk_filter *fp,
 
 	fp->len = new_len;
 
-	/* 2nd pass: remap sock_filter insns into sock_filter_int insns. */
+	/* 2nd pass: remap sock_filter insns into bpf_insn insns. */
 	err = sk_convert_filter(old_prog, old_len, fp->insnsi, &new_len);
 	if (err)
 		/* 2nd sk_convert_filter() can fail only if it fails
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 6 lines · Alexei Starovoitov

eBPF is used by socket filtering, seccomp and soon by tracing and exposed to userspace, therefore 'sock_filter_int' name is not accurate. Rename it to 'bpf_insn'

---

...

Review

Quoted 3 lines
  #define BPF_ALU64_REG(OP, DST, SRC)				\
(quoted diff) +1 -1
-	((struct sock_filter_int) {				\
+	((struct bpf_insn) {				\

^^^ Please also fix up whitespacing here
and all the other sections below.

Quoted 57 lines
  		.code  = BPF_ALU64 | BPF_OP(OP) | BPF_X,	\
  		.dst_reg = DST,					\
  		.src_reg = SRC,					\
include/linux/filter.h +6 -6
@@ -90,7 +90,7 @@ enum {
  		.imm   = 0 })
 
  #define BPF_ALU32_REG(OP, DST, SRC)				\
-	((struct sock_filter_int) {				\
+	((struct bpf_insn) {				\
  		.code  = BPF_ALU | BPF_OP(OP) | BPF_X,		\
  		.dst_reg = DST,					\
  		.src_reg = SRC,					\
@@ -100,7 +100,7 @@ enum {
  /* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
 
  #define BPF_ALU64_IMM(OP, DST, IMM)				\
-	((struct sock_filter_int) {				\
+	((struct bpf_insn) {				\
  		.code  = BPF_ALU64 | BPF_OP(OP) | BPF_K,	\
  		.dst_reg = DST,					\
  		.src_reg = 0,					\
@@ -108,7 +108,7 @@ enum {
  		.imm   = IMM })
 
  #define BPF_ALU32_IMM(OP, DST, IMM)				\
-	((struct sock_filter_int) {				\
+	((struct bpf_insn) {				\
  		.code  = BPF_ALU | BPF_OP(OP) | BPF_K,		\
  		.dst_reg = DST,					\
  		.src_reg = 0,					\
@@ -118,7 +118,7 @@ enum {
  /* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
 
  #define BPF_ENDIAN(TYPE, DST, LEN)				\
-	((struct sock_filter_int) {				\
+	((struct bpf_insn) {				\
  		.code  = BPF_ALU | BPF_END | BPF_SRC(TYPE),	\
  		.dst_reg = DST,					\
  		.src_reg = 0,					\
@@ -128,7 +128,7 @@ enum {
  /* Short form of mov, dst_reg = src_reg */
 
  #define BPF_MOV64_REG(DST, SRC)					\
-	((struct sock_filter_int) {				\
+	((struct bpf_insn) {				\
  		.code  = BPF_ALU64 | BPF_MOV | BPF_X,		\
  		.dst_reg = DST,					\
  		.src_reg = SRC,					\
@@ -136,7 +136,7 @@ enum {
  		.imm   = 0 })
 
  #define BPF_MOV32_REG(DST, SRC)					\
-	((struct sock_filter_int) {				\
+	((struct bpf_insn) {				\
  		.code  = BPF_ALU | BPF_MOV | BPF_X,		\
  		.dst_reg = DST,					\
  		.src_reg = SRC,					\

....

#2 lore raw
Quoted 11 lines · Daniel Borkmann
Quoted 7 lines · Alexei Starovoitov

eBPF is used by socket filtering, seccomp and soon by tracing and exposed to userspace, therefore 'sock_filter_int' name is not accurate. Rename it to 'bpf_insn'

---

...

Quoted 7 lines

Review

Quoted 3 lines
  #define BPF_ALU64_REG(OP, DST, SRC)                           \
(quoted diff) +1 -1
-       ((struct sock_filter_int) {                             \
+       ((struct bpf_insn) {                            \

^^^ Please also fix up whitespacing here
and all the other sections below.

you mean to align last \ with other lines?
sure. good point.

#3 lore raw

On 07/25/2014 01:26 AM, Alexei Starovoitov wrote:
...

Quoted 2 lines

you mean to align last \ with other lines?
sure. good point.

Yeah, would be good. Otherwise looks good, of course.