From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755580AbbIHOeE (ORCPT ); Tue, 8 Sep 2015 10:34:04 -0400 Received: from terminus.zytor.com ([198.137.202.10]:52241 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754946AbbIHOd6 (ORCPT ); Tue, 8 Sep 2015 10:33:58 -0400 Date: Tue, 8 Sep 2015 07:31:06 -0700 From: tip-bot for He Kuang Message-ID: Cc: brendan.d.gregg@gmail.com, xiakaixu@huawei.com, hekuang@huawei.com, acme@redhat.com, ast@plumgrid.com, mingo@kernel.org, masami.hiramatsu.pt@hitachi.com, namhyung@kernel.org, paulus@samba.org, dsahern@gmail.com, jolsa@kernel.org, hpa@zytor.com, daniel@iogearbox.net, wangnan0@huawei.com, a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org, tglx@linutronix.de, lizefan@huawei.com Reply-To: jolsa@kernel.org, namhyung@kernel.org, dsahern@gmail.com, paulus@samba.org, linux-kernel@vger.kernel.org, a.p.zijlstra@chello.nl, lizefan@huawei.com, tglx@linutronix.de, daniel@iogearbox.net, wangnan0@huawei.com, hpa@zytor.com, acme@redhat.com, ast@plumgrid.com, hekuang@huawei.com, xiakaixu@huawei.com, brendan.d.gregg@gmail.com, masami.hiramatsu.pt@hitachi.com, mingo@kernel.org In-Reply-To: <1440822125-52691-22-git-send-email-wangnan0@huawei.com> References: <1440822125-52691-22-git-send-email-wangnan0@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Copy linux/filter.h to tools/include Git-Commit-ID: dabf626f7f0e5cbef0d1cfb5143e40213f079bb8 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: dabf626f7f0e5cbef0d1cfb5143e40213f079bb8 Gitweb: http://git.kernel.org/tip/dabf626f7f0e5cbef0d1cfb5143e40213f079bb8 Author: He Kuang AuthorDate: Sat, 29 Aug 2015 04:21:55 +0000 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 2 Sep 2015 16:30:46 -0300 perf tools: Copy linux/filter.h to tools/include This patch copies filter.h from include/linux/kernel.h to tools/include/linux/filter.h to enable other libraries to use macros in it, like libbpf which will be introduced by further patches. Currently, the filter.h copy only contains the useful macros needed by libbpf for not introducing too much dependence. tools/perf/MANIFEST is also updated for 'make perf-*-src-pkg'. One change: The 'imm' field of BPF_EMIT_CALL becomes ((FUNC) - BPF_FUNC_unspec) to suit user space code generator. Signed-off-by: He Kuang Cc: David Ahern Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Wang Nan Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1440822125-52691-22-git-send-email-wangnan0@huawei.com Signed-off-by: Wang Nan [ Removed stylistic changes, so that a diff to the original file gets reduced ] Signed-off-by: Arnaldo Carvalho de Melo --- .../bpf/libbpf.h => tools/include/linux/filter.h | 131 ++++++++++++++------- tools/perf/MANIFEST | 1 + 2 files changed, 87 insertions(+), 45 deletions(-) diff --git a/samples/bpf/libbpf.h b/tools/include/linux/filter.h similarity index 61% copy from samples/bpf/libbpf.h copy to tools/include/linux/filter.h index 7235e29..3276625 100644 --- a/samples/bpf/libbpf.h +++ b/tools/include/linux/filter.h @@ -1,22 +1,32 @@ -/* eBPF mini library */ -#ifndef __LIBBPF_H -#define __LIBBPF_H - -struct bpf_insn; - -int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, - int max_entries); -int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags); -int bpf_lookup_elem(int fd, void *key, void *value); -int bpf_delete_elem(int fd, void *key); -int bpf_get_next_key(int fd, void *key, void *next_key); - -int bpf_prog_load(enum bpf_prog_type prog_type, - const struct bpf_insn *insns, int insn_len, - const char *license, int kern_version); - -#define LOG_BUF_SIZE 65536 -extern char bpf_log_buf[LOG_BUF_SIZE]; +/* + * Linux Socket Filter Data Structures + */ +#ifndef __TOOLS_LINUX_FILTER_H +#define __TOOLS_LINUX_FILTER_H + +#include + +/* 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 + +/* Helper macros for filter block array initializers. */ /* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */ @@ -54,6 +64,16 @@ extern char bpf_log_buf[LOG_BUF_SIZE]; .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) \ @@ -64,6 +84,14 @@ extern char bpf_log_buf[LOG_BUF_SIZE]; .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) \ @@ -74,32 +102,31 @@ extern char bpf_log_buf[LOG_BUF_SIZE]; .off = 0, \ .imm = IMM }) -/* BPF_LD_IMM64 macro encodes single 'load 64-bit immediate' insn */ -#define BPF_LD_IMM64(DST, IMM) \ - BPF_LD_IMM64_RAW(DST, 0, IMM) - -#define BPF_LD_IMM64_RAW(DST, SRC, IMM) \ +#define BPF_MOV32_IMM(DST, IMM) \ ((struct bpf_insn) { \ - .code = BPF_LD | BPF_DW | BPF_IMM, \ + .code = BPF_ALU | BPF_MOV | BPF_K, \ .dst_reg = DST, \ - .src_reg = SRC, \ - .off = 0, \ - .imm = (__u32) (IMM) }), \ - ((struct bpf_insn) { \ - .code = 0, /* zero is reserved opcode */ \ - .dst_reg = 0, \ .src_reg = 0, \ .off = 0, \ - .imm = ((__u64) (IMM)) >> 32 }) + .imm = IMM }) -#ifndef BPF_PSEUDO_MAP_FD -# define BPF_PSEUDO_MAP_FD 1 -#endif +/* Short form of mov based on type, BPF_X: dst_reg = src_reg, BPF_K: dst_reg = imm32 */ -/* pseudo BPF_LD_IMM64 insn used to refer to process-local map_fd */ -#define BPF_LD_MAP_FD(DST, MAP_FD) \ - BPF_LD_IMM64_RAW(DST, BPF_PSEUDO_MAP_FD, MAP_FD) +#define BPF_MOV64_RAW(TYPE, DST, SRC, IMM) \ + ((struct bpf_insn) { \ + .code = BPF_ALU64 | BPF_MOV | BPF_SRC(TYPE), \ + .dst_reg = DST, \ + .src_reg = SRC, \ + .off = 0, \ + .imm = IMM }) +#define BPF_MOV32_RAW(TYPE, DST, SRC, IMM) \ + ((struct bpf_insn) { \ + .code = BPF_ALU | BPF_MOV | BPF_SRC(TYPE), \ + .dst_reg = DST, \ + .src_reg = SRC, \ + .off = 0, \ + .imm = IMM }) /* Direct packet access, R0 = *(uint *) (skb->data + imm32) */ @@ -111,6 +138,16 @@ extern char bpf_log_buf[LOG_BUF_SIZE]; .off = 0, \ .imm = IMM }) +/* Indirect packet access, R0 = *(uint *) (skb->data + src_reg + imm32) */ + +#define BPF_LD_IND(SIZE, SRC, IMM) \ + ((struct bpf_insn) { \ + .code = BPF_LD | BPF_SIZE(SIZE) | BPF_IND, \ + .dst_reg = 0, \ + .src_reg = SRC, \ + .off = 0, \ + .imm = IMM }) + /* Memory load, dst_reg = *(uint *) (src_reg + off16) */ #define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \ @@ -161,6 +198,16 @@ extern char bpf_log_buf[LOG_BUF_SIZE]; .off = OFF, \ .imm = IMM }) +/* Function call */ + +#define BPF_EMIT_CALL(FUNC) \ + ((struct bpf_insn) { \ + .code = BPF_JMP | BPF_CALL, \ + .dst_reg = 0, \ + .src_reg = 0, \ + .off = 0, \ + .imm = ((FUNC) - BPF_FUNC_unspec) }) + /* Raw code statement block */ #define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \ @@ -181,10 +228,4 @@ extern char bpf_log_buf[LOG_BUF_SIZE]; .off = 0, \ .imm = 0 }) -/* create RAW socket and bind to interface 'name' */ -int open_raw_sock(const char *name); - -struct perf_event_attr; -int perf_event_open(struct perf_event_attr *attr, int pid, int cpu, - int group_fd, unsigned long flags); -#endif +#endif /* __TOOLS_LINUX_FILTER_H */ diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index af009bd..2a958a8 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST @@ -41,6 +41,7 @@ tools/include/asm-generic/bitops.h tools/include/linux/atomic.h tools/include/linux/bitops.h tools/include/linux/compiler.h +tools/include/linux/filter.h tools/include/linux/hash.h tools/include/linux/kernel.h tools/include/linux/list.h