[PATCH RFC v9 net-next 3/4] net: filter: move eBPF instruction macros
move instruction macros (like BPF_MOV64_REG or BPF_ALU32_IMM) from linux/filter.h into uapi/linux/bpf.h so that userspace programs can use them. verifier testsuite (in later patches) will be using them. Signed-off-by: Alexei Starovoitov --- include/linux/filter.h | 226 -- include/uapi/linux/bpf.h | 226 ++ 2 files changed, 226 insertions(+), 226 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index ff77842af3e1..c220b27b10df 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -37,232 +37,6 @@ struct bpf_prog_info; /* BPF program can access up to 512 bytes of stack space. */ #define MAX_BPF_STACK 512 -/* Helper macros for filter block array initializers. */ - -/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */ - -#define BPF_ALU64_REG(OP, DST, SRC)\ - ((struct bpf_insn) {\ - .code = BPF_ALU64 | BPF_OP(OP) | BPF_X,\ - .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = 0 }) - -#define BPF_ALU32_REG(OP, DST, SRC)\ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_OP(OP) | BPF_X, \ - .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = 0 }) - -/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */ - -#define BPF_ALU64_IMM(OP, DST, IMM)\ - ((struct bpf_insn) {\ - .code = BPF_ALU64 | BPF_OP(OP) | BPF_K,\ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = IMM }) - -#define BPF_ALU32_IMM(OP, DST, IMM)\ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_OP(OP) | BPF_K, \ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = IMM }) - -/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */ - -#define BPF_ENDIAN(TYPE, DST, LEN) \ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_END | BPF_SRC(TYPE), \ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = LEN }) - -/* Short form of mov, dst_reg = src_reg */ - -#define BPF_MOV64_REG(DST, SRC)\ - ((struct bpf_insn) {\ - .code = BPF_ALU64 | BPF_MOV | BPF_X, \ - .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = 0 }) - -#define BPF_MOV32_REG(DST, SRC)\ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_MOV | BPF_X, \ - .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = 0 }) - -/* Short form of mov, dst_reg = imm32 */ - -#define BPF_MOV64_IMM(DST, IMM)\ - ((struct bpf_insn) {\ - .code = BPF_ALU64 | BPF_MOV | BPF_K, \ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = IMM }) - -#define BPF_MOV32_IMM(DST, IMM)\ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_MOV | BPF_K, \ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = IMM }) - -/*
[PATCH RFC v9 net-next 3/4] net: filter: move eBPF instruction macros
move instruction macros (like BPF_MOV64_REG or BPF_ALU32_IMM) from linux/filter.h into uapi/linux/bpf.h so that userspace programs can use them. verifier testsuite (in later patches) will be using them. Signed-off-by: Alexei Starovoitov a...@plumgrid.com --- include/linux/filter.h | 226 -- include/uapi/linux/bpf.h | 226 ++ 2 files changed, 226 insertions(+), 226 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index ff77842af3e1..c220b27b10df 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -37,232 +37,6 @@ struct bpf_prog_info; /* BPF program can access up to 512 bytes of stack space. */ #define MAX_BPF_STACK 512 -/* Helper macros for filter block array initializers. */ - -/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */ - -#define BPF_ALU64_REG(OP, DST, SRC)\ - ((struct bpf_insn) {\ - .code = BPF_ALU64 | BPF_OP(OP) | BPF_X,\ - .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = 0 }) - -#define BPF_ALU32_REG(OP, DST, SRC)\ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_OP(OP) | BPF_X, \ - .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = 0 }) - -/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */ - -#define BPF_ALU64_IMM(OP, DST, IMM)\ - ((struct bpf_insn) {\ - .code = BPF_ALU64 | BPF_OP(OP) | BPF_K,\ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = IMM }) - -#define BPF_ALU32_IMM(OP, DST, IMM)\ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_OP(OP) | BPF_K, \ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = IMM }) - -/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */ - -#define BPF_ENDIAN(TYPE, DST, LEN) \ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_END | BPF_SRC(TYPE), \ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = LEN }) - -/* Short form of mov, dst_reg = src_reg */ - -#define BPF_MOV64_REG(DST, SRC)\ - ((struct bpf_insn) {\ - .code = BPF_ALU64 | BPF_MOV | BPF_X, \ - .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = 0 }) - -#define BPF_MOV32_REG(DST, SRC)\ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_MOV | BPF_X, \ - .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = 0 }) - -/* Short form of mov, dst_reg = imm32 */ - -#define BPF_MOV64_IMM(DST, IMM)\ - ((struct bpf_insn) {\ - .code = BPF_ALU64 | BPF_MOV | BPF_K, \ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm = IMM }) - -#define BPF_MOV32_IMM(DST, IMM)\ - ((struct bpf_insn) {\ - .code = BPF_ALU | BPF_MOV | BPF_K, \ - .dst_reg = DST, \ - .src_reg = 0, \ - .off = 0, \ - .imm