Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754167AbdFMXuT (ORCPT ); Tue, 13 Jun 2017 19:50:19 -0400 Received: from mail-dm3nam03on0070.outbound.protection.outlook.com ([104.47.41.70]:9568 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753825AbdFMXt6 (ORCPT ); Tue, 13 Jun 2017 19:49:58 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=David.Daney@cavium.com; From: David Daney To: Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mips@linux-mips.org, ralf@linux-mips.org, David Daney Subject: [PATCH 4/4] samples/bpf: Fix tracex5 to work with MIPS syscalls. Date: Tue, 13 Jun 2017 16:49:38 -0700 Message-Id: <20170613234938.4823-5-david.daney@cavium.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170613234938.4823-1-david.daney@cavium.com> References: <20170613234938.4823-1-david.daney@cavium.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: BY2PR07CA0024.namprd07.prod.outlook.com (10.166.107.19) To MWHPR07MB3501.namprd07.prod.outlook.com (10.164.192.28) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR07MB3501: X-MS-Office365-Filtering-Correlation-Id: 7c0acaea-9bd3-4286-f5a1-08d4b2b6df3d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:MWHPR07MB3501; X-Microsoft-Exchange-Diagnostics: 1;MWHPR07MB3501;3:FB+CDRGOoBoZ0+9LSTFuDn1tXo0mNBjz2MVXJGIk2AAn9JJ5VazzhFOL8iafjcAdwa1AqqLCCuOJJ4ZPBj7Zyosb6yraTMaWFiSIKWbXXpM7mnK4NyqN3Ll05Xwyl85nEUQI4XvdgqHj7GasvHbX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tnvi8QoZcc881oLLSUp+xR5KAUqlbG+0vfZh15nMFbObcMMb52UtOrrR+Qq1HFgxfm2+Ya4OqlK3ij7/4aKx0AUHhxKZlTiCh9cBlhQOhUIaKtTwhpwS0D4LGUrc8/OqQV62xnMpUWDmsB4c36lU9kGBanAvxf1EGoKA8O3gpqRWksN3VCALNSsBZ0PL+tGRS6GAHgbHP+bsUgHxcUru/1bunQPsUPZtS51/YVGQ5vGgjZGbvEWeMI6cRt/Rqu0q6Dr1P32527yLnE4LcDgLEKMj5xYdfsilv90d14bXMXsJfnxrxdteZ5HyC+aLd5Pq5tMMXtYCiU2b6bWvKC/NlkiBiBHP3t55snwTQEbEpxamtXew3IASd51a1oR5Oe1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123562025)(20161123555025)(20161123558100)(20161123560025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR07MB3501;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR07MB3501; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;MWHPR07MB3501;4:DRHTYGr4TJ3y2JhF853Yfrve74H1dnexx0Ya5SX7vA?= =?us-ascii?Q?9f0qCLDVC87VVL4SPns0f+kpH/R4Vgg6saQ6gTb/Y+MACvRvrH42n/8acEPI?= =?us-ascii?Q?a6Ns/aZ7cEsk0AM5/nL0o/qD/EO/bcA98WUulkiGrJk4p9YARtBkLWqX5xY/?= =?us-ascii?Q?FcPjc+znVUrbRS5a40/gzgF2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us-ascii?Q?VLnyFIhWP+s6FaC/1ShjbMkx/NNdEl+KopEcoDFk7H+h8tX82qKOtOAYCghv?= =?us-ascii?Q?lcBo7nzVRtAZq/e81WT2cFVBGqrP2F?= X-Forefront-PRVS: 0337AFFE9A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39840400002)(39450400003)(39410400002)(39400400002)(39850400002)(189002)(199003)(6512007)(105586002)(53936002)(50226002)(53416004)(2950100002)(106356001)(4326008)(189998001)(6506006)(25786009)(42186005)(6666003)(33646002)(50466002)(69596002)(5003940100001)(6486002)(48376002)(76176999)(47776003)(7736002)(305945005)(1076002)(478600001)(101416001)(2906002)(81156014)(8676002)(81166006)(72206003)(107886003)(36756003)(5660300001)(66066001)(38730400002)(3846002)(68736007)(97736004)(6116002)(86362001)(50986999);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR07MB3501;H:ddl.caveonetworks.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;MWHPR07MB3501;23:2tVakW8euONaz+hokt6ejTniUjLxEc8/KP4bHqzba?= =?us-ascii?Q?BAYcsnDUNeStw9EFkOm8JTCcOJZY8/Ywd6dvURXL6gANRANljD+gevMKJuKk?= =?us-ascii?Q?duLFJqFRaasifcU+pZanvhUityT7m9zq/slq3wXot0Lv2vzZ/zeYx42UKHw1?= =?us-ascii?Q?+1TTsKNoo70sJsTE7ijiFNu+EeS1Fmnv2JtA/a6LBQWmbp1rVcjKIba1mex3?= =?us-ascii?Q?aHsT0tjKZ7ZMc41ACQJG7Se8s99icw1VuKgbsh8LYLNOLUiJlhEz/koxU8s2?= =?us-ascii?Q?zPkhqdLrvVKjSqPFEKisSYdS1NeH71wKp8QJSZbxarmYobYBNPWp2r+6eoZp?= =?us-ascii?Q?LkbN0HrLZGnoraTZ16bIHLXEHqopni6w+P93vzC3YkbFzdb0KQfo8fWqzWKt?= =?us-ascii?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jJT7kmhriRly4S+2ieNHeivxMLbYDnmia15AHDL0bOUDvsbOodkCPsyrszqvvjE9LwxnTQVGLFjrRitJvpUxTva0FV37yVylzGG3kFx3M5Y= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR07MB3501;7:YSDUvbtZSLMktfgaVvwOlfk13Y5dKUeSTUYkwuh52pkqHMjvS++cLw21+GxkJuZFAQPIQPc3LxlyAdWXzme+aYBnmkzaHJ+dWxiSFPD53KoXHH/h/uzvNscYHd+PopXhG7/bQLlLA1cHUmJ5oHOwIjiO5Hy14FGkGaRnuFMPiK45tOaU8zHn8bi4Pg/oN2L9nPEne53GJsizLcAUauefShDQrIvHKapq0OE4Ly+lsITimjAguKMeRCv2yLb8zlTNywzdcssLMDinJzvfGIL0Vm+38lfJy8iHUqJrSOL2PVaEm7wGNjjcEX/WEviHT5RoSsX/eesuJ7Y+4WtUQE/rwg== X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2017 23:49:46.2754 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR07MB3501 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3536 Lines: 132 There are two problems: 1) In MIPS the __NR_* macros expand to an expression, this causes the sections of the object file to be named like: . . . [ 5] kprobe/(5000 + 1) PROGBITS 0000000000000000 000160 ... [ 6] kprobe/(5000 + 0) PROGBITS 0000000000000000 000258 ... [ 7] kprobe/(5000 + 9) PROGBITS 0000000000000000 000348 ... . . . The fix here is to use the "asm_offsets" trick to evaluate the macros in the C compiler and generate a header file with a usable form of the macros. 2) MIPS syscall numbers start at 5000, so we need a bigger map to hold the sub-programs. Signed-off-by: David Daney --- samples/bpf/Makefile | 13 +++++++++++++ samples/bpf/syscall_nrs.c | 12 ++++++++++++ samples/bpf/tracex5_kern.c | 11 ++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 samples/bpf/syscall_nrs.c diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 6c7468e..a0561dc 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -160,6 +160,17 @@ clean: $(MAKE) -C ../../ M=$(CURDIR) clean @rm -f *~ +$(obj)/syscall_nrs.s: $(src)/syscall_nrs.c + $(call if_changed_dep,cc_s_c) + +$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE + $(call filechk,offsets,__SYSCALL_NRS_H__) + +clean-files += syscall_nrs.h + +FORCE: + + # Verify LLVM compiler tools are available and bpf target is supported by llc .PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC) @@ -180,6 +191,8 @@ verify_target_bpf: verify_cmds $(src)/*.c: verify_target_bpf +$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h + # asm/sysreg.h - inline assembly used by it is incompatible with llvm. # But, there is no easy way to fix it, so just exclude it since it is # useless for BPF samples. diff --git a/samples/bpf/syscall_nrs.c b/samples/bpf/syscall_nrs.c new file mode 100644 index 0000000..ce2a30b --- /dev/null +++ b/samples/bpf/syscall_nrs.c @@ -0,0 +1,12 @@ +#include +#include + +#define SYSNR(_NR) DEFINE(SYS ## _NR, _NR) + +void syscall_defines(void) +{ + COMMENT("Linux system call numbers."); + SYSNR(__NR_write); + SYSNR(__NR_read); + SYSNR(__NR_mmap); +} diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5_kern.c index 7e4cf74..f57f4e1 100644 --- a/samples/bpf/tracex5_kern.c +++ b/samples/bpf/tracex5_kern.c @@ -9,6 +9,7 @@ #include #include #include +#include "syscall_nrs.h" #include "bpf_helpers.h" #define PROG(F) SEC("kprobe/"__stringify(F)) int bpf_func_##F @@ -17,7 +18,11 @@ struct bpf_map_def SEC("maps") progs = { .type = BPF_MAP_TYPE_PROG_ARRAY, .key_size = sizeof(u32), .value_size = sizeof(u32), +#ifdef __mips__ + .max_entries = 6000, /* MIPS n64 syscalls start at 5000 */ +#else .max_entries = 1024, +#endif }; SEC("kprobe/__seccomp_filter") @@ -37,7 +42,7 @@ int bpf_prog1(struct pt_regs *ctx) } /* we jump here when syscall number == __NR_write */ -PROG(__NR_write)(struct pt_regs *ctx) +PROG(SYS__NR_write)(struct pt_regs *ctx) { struct seccomp_data sd; @@ -50,7 +55,7 @@ PROG(__NR_write)(struct pt_regs *ctx) return 0; } -PROG(__NR_read)(struct pt_regs *ctx) +PROG(SYS__NR_read)(struct pt_regs *ctx) { struct seccomp_data sd; @@ -63,7 +68,7 @@ PROG(__NR_read)(struct pt_regs *ctx) return 0; } -PROG(__NR_mmap)(struct pt_regs *ctx) +PROG(SYS__NR_mmap)(struct pt_regs *ctx) { char fmt[] = "mmap\n"; bpf_trace_printk(fmt, sizeof(fmt)); -- 2.9.4