From patchwork Tue Aug 20 23:08:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 1150463 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lekensteyn.nl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lekensteyn.nl header.i=@lekensteyn.nl header.b="FJyfkcTL"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Cmh8611yz9sNF for ; Wed, 21 Aug 2019 09:09:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726556AbfHTXJJ (ORCPT ); Tue, 20 Aug 2019 19:09:09 -0400 Received: from lekensteyn.nl ([178.21.112.251]:44209 "EHLO lekensteyn.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbfHTXJJ (ORCPT ); Tue, 20 Aug 2019 19:09:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2015-q1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=CPhDF5jnURDhjAxSFhJHWKq3/SRRecFjjjdMVgviX/E=; b=FJyfkcTLJKVSBbaflGqIw9KS4QzhZVM6wE+k1gOvJaoDwRS0+H2euts5GT1LGJNwwFCf7ZJfhbyXMxf6qZ0ZtZTLVGSPa8eeC2ayjO4DTepd0D6jDjzyZsRtty1+VhxSOq1R1hpPArQ7B3oI/5rCwEgkmDjw6SB34jy9Hl2sM08JbPgUAog7ymiODaIc1EODMWCzU+Ty/vox6T4EAcO4Qq+PX5Zi0bXNkODFcuRQRxarbwoSd7sV12aznyKaiL05xlrY/7oE1v/yfNAp99HUVDEtHo4Euzt6FQQyrMdcmOJVnQRGVN32hGNZdjoTjym2fMrRSLn5v2YynZeDSKToCg==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1i0DFQ-00055S-8n; Wed, 21 Aug 2019 01:09:04 +0200 From: Peter Wu To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v2 1/4] bpf: clarify description for CONFIG_BPF_EVENTS Date: Wed, 21 Aug 2019 00:08:57 +0100 Message-Id: <20190820230900.23445-2-peter@lekensteyn.nl> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190820230900.23445-1-peter@lekensteyn.nl> References: <20190820230900.23445-1-peter@lekensteyn.nl> MIME-Version: 1.0 X-Spam-Score: -0.0 (/) X-Spam-Status: No, hits=-0.0 required=5.0 tests=NO_RELAYS=-0.001 autolearn=unavailable autolearn_force=no Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org PERF_EVENT_IOC_SET_BPF supports uprobes since v4.3, and tracepoints since v4.7 via commit 04a22fae4cbc ("tracing, perf: Implement BPF programs attached to uprobes"), and commit 98b5c2c65c29 ("perf, bpf: allow bpf programs attach to tracepoints") respectively. Signed-off-by: Peter Wu --- kernel/trace/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 98da8998c25c..b09d7b1ffffd 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -520,7 +520,8 @@ config BPF_EVENTS bool default y help - This allows the user to attach BPF programs to kprobe events. + This allows the user to attach BPF programs to kprobe, uprobe, and + tracepoint events. config DYNAMIC_EVENTS def_bool n From patchwork Tue Aug 20 23:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 1150469 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lekensteyn.nl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lekensteyn.nl header.i=@lekensteyn.nl header.b="X19LfTUd"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46CmhD1vn8z9sBp for ; Wed, 21 Aug 2019 09:09:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726618AbfHTXJP (ORCPT ); Tue, 20 Aug 2019 19:09:15 -0400 Received: from lekensteyn.nl ([178.21.112.251]:51785 "EHLO lekensteyn.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726317AbfHTXJI (ORCPT ); Tue, 20 Aug 2019 19:09:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2015-q1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=4pxomqX2YRpm2Ejb0bxAI4CKwQidMFt5OJE5J3FrhiE=; b=X19LfTUdA3joSllsolRzkLSGkOMA7VihhSE3hrFbZhBJIdzjW18Dsl0mbfkoUEUK0a9wgnpkplKN9YNbPUsjJAlJz05gVShVIc4ZMk7l7XEilcOXKNrcmQ7xzoDmyyN72FBGGPP5sUa+Z1zg9r0n3M+ZmR2OTmHipEc3EcYho9cCaGmtoEVG/5Q2EiEqS+yHI/cJZvSfSEed2vYwZBPo90CHCtLH+nxmz0DtpcEMGG8Sh7LMrf4hoBPHTEbiE8dUAvXXr6eraSLmcU1iETpkcS2xjH8y6lEz4FXUvRP3Xg7RFiD6ytUwmb+hTuWNGa/8nOh+ZyX9qZzwz0j+lhiEiA==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1i0DFQ-00055S-W4; Wed, 21 Aug 2019 01:09:05 +0200 From: Peter Wu To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v2 2/4] bpf: fix 'struct pt_reg' typo in documentation Date: Wed, 21 Aug 2019 00:08:58 +0100 Message-Id: <20190820230900.23445-3-peter@lekensteyn.nl> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190820230900.23445-1-peter@lekensteyn.nl> References: <20190820230900.23445-1-peter@lekensteyn.nl> MIME-Version: 1.0 X-Spam-Score: -0.0 (/) X-Spam-Status: No, hits=-0.0 required=5.0 tests=NO_RELAYS=-0.001 autolearn=unavailable autolearn_force=no Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is no 'struct pt_reg'. Signed-off-by: Peter Wu Reviewed-by: Quentin Monnet --- include/uapi/linux/bpf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index fa1c753dcdbc..9ca333c3ce91 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1013,7 +1013,7 @@ union bpf_attr { * The realm of the route for the packet associated to *skb*, or 0 * if none was found. * - * int bpf_perf_event_output(struct pt_reg *ctx, struct bpf_map *map, u64 flags, void *data, u64 size) + * int bpf_perf_event_output(struct pt_regs *ctx, struct bpf_map *map, u64 flags, void *data, u64 size) * Description * Write raw *data* blob into a special BPF perf event held by * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf @@ -1075,7 +1075,7 @@ union bpf_attr { * Return * 0 on success, or a negative error in case of failure. * - * int bpf_get_stackid(struct pt_reg *ctx, struct bpf_map *map, u64 flags) + * int bpf_get_stackid(struct pt_regs *ctx, struct bpf_map *map, u64 flags) * Description * Walk a user or a kernel stack and return its id. To achieve * this, the helper needs *ctx*, which is a pointer to the context @@ -1724,7 +1724,7 @@ union bpf_attr { * Return * 0 on success, or a negative error in case of failure. * - * int bpf_override_return(struct pt_reg *regs, u64 rc) + * int bpf_override_return(struct pt_regs *regs, u64 rc) * Description * Used for error injection, this helper uses kprobes to override * the return value of the probed function, and to set it to *rc*. From patchwork Tue Aug 20 23:08:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 1150464 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lekensteyn.nl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lekensteyn.nl header.i=@lekensteyn.nl header.b="Ncim4CHF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Cmh86DCBz9sNf for ; Wed, 21 Aug 2019 09:09:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726362AbfHTXJJ (ORCPT ); Tue, 20 Aug 2019 19:09:09 -0400 Received: from lekensteyn.nl ([178.21.112.251]:41075 "EHLO lekensteyn.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726354AbfHTXJI (ORCPT ); Tue, 20 Aug 2019 19:09:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2015-q1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Q+UDWMYEYIrMXXf99yl5++TT8RhBbJ8ffMGbmG6M8fY=; b=Ncim4CHFR1Q5+pd5BNiNHzCvws2Ijii1/CviLZYp5ZSWR4Knp+bFWtUXA4inj+VXxP/LbmslA8R0lI+PQszg7deLDswysKr8qIESiNHsUEg3fpY3T2WheqhouGW6ViDxZKJqPo0FYcuaHnT7A35lEKVss95cKOjpB23BLJ/RIPUimBmtZoZawJtSzRQmdzanEaEHM2WAxLzQof1XsglWFMlQZvZqrMkrWmTvWdHvAtDtrXyPU9HNWjnlIaN0e2oTtV8p4EcWyUUyvn8bMyRKk80RLyX8POgnhIX2G3hIJlaEKIdtmivX62gLQIip1fFKrkMGABkjKA+zKqSVO+AtfQ==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1i0DFR-00055S-D6; Wed, 21 Aug 2019 01:09:05 +0200 From: Peter Wu To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v2 3/4] bpf: clarify when bpf_trace_printk discards lines Date: Wed, 21 Aug 2019 00:08:59 +0100 Message-Id: <20190820230900.23445-4-peter@lekensteyn.nl> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190820230900.23445-1-peter@lekensteyn.nl> References: <20190820230900.23445-1-peter@lekensteyn.nl> MIME-Version: 1.0 X-Spam-Score: -0.0 (/) X-Spam-Status: No, hits=-0.0 required=5.0 tests=NO_RELAYS=-0.001 autolearn=unavailable autolearn_force=no Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org I opened /sys/kernel/tracing/trace once and kept reading from it. bpf_trace_printk somehow did not seem to work, no entries were appended to that trace file. It turns out that tracing is disabled when that file is open. Save the next person some time and document this. The trace file is described in Documentation/trace/ftrace.rst, however the implication "tracing is disabled" did not immediate translate to "bpf_trace_printk silently discards entries". Signed-off-by: Peter Wu --- include/uapi/linux/bpf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 9ca333c3ce91..e4236e357ed9 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -575,6 +575,8 @@ union bpf_attr { * limited to five). * * Each time the helper is called, it appends a line to the trace. + * Lines are discarded while *\/sys/kernel/debug/tracing/trace* is + * open, use *\/sys/kernel/debug/tracing/trace_pipe* to avoid this. * The format of the trace is customizable, and the exact output * one will get depends on the options set in * *\/sys/kernel/debug/tracing/trace_options* (see also the From patchwork Tue Aug 20 23:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 1150461 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lekensteyn.nl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lekensteyn.nl header.i=@lekensteyn.nl header.b="BSaZJSOI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Cmh61Y4gz9sBp for ; Wed, 21 Aug 2019 09:09:09 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726413AbfHTXJI (ORCPT ); Tue, 20 Aug 2019 19:09:08 -0400 Received: from lekensteyn.nl ([178.21.112.251]:43647 "EHLO lekensteyn.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbfHTXJI (ORCPT ); Tue, 20 Aug 2019 19:09:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2015-q1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=aTs/19MyORw3OpmJFYMSjvA9Q0yVU+se+6r/BJ0qdiU=; b=BSaZJSOI0BcGsmGwvW5jiiW/W0Ln5eJWYXS6BlI2IQLa8JVpexEwrGnu5q8jxhozsIAssg6GzZ4LSnzUJJvLgVP56qJY/cIgCiSLkM059gvXCb8YA59q9QTZwwJcUB6qP89BcQfSjkjFeFDKUeGtboTiAPQMoAxv+4p5SZMoB4b80NKUQwdl2o7CayGL9+pVsW87nB1DD+1fj7evgdFdX6AOWtzazCJ+zv/MkPKJ2+99Y2xnAjaoOKIv9pQCX0LN+6sPcryNCOEW+pvH1Xw8UqbxLHC58e5pL3WMl7nHqLV1MOlAGF6oMXpyHALW1A66TAKcfDwmH72NTiuMf7669w==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1i0DFR-00055S-Np; Wed, 21 Aug 2019 01:09:05 +0200 From: Peter Wu To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v2 4/4] bpf: sync bpf.h to tools/ Date: Wed, 21 Aug 2019 00:09:00 +0100 Message-Id: <20190820230900.23445-5-peter@lekensteyn.nl> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190820230900.23445-1-peter@lekensteyn.nl> References: <20190820230900.23445-1-peter@lekensteyn.nl> MIME-Version: 1.0 X-Spam-Score: -0.0 (/) X-Spam-Status: No, hits=-0.0 required=5.0 tests=NO_RELAYS=-0.001 autolearn=unavailable autolearn_force=no Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Fix a 'struct pt_reg' typo and clarify when bpf_trace_printk discards lines. Affects documentation only. Signed-off-by: Peter Wu --- tools/include/uapi/linux/bpf.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 4e455018da65..58bdb89599c9 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -575,6 +575,8 @@ union bpf_attr { * limited to five). * * Each time the helper is called, it appends a line to the trace. + * Lines are discarded while *\/sys/kernel/debug/tracing/trace* is + * open, use *\/sys/kernel/debug/tracing/trace_pipe* to avoid this. * The format of the trace is customizable, and the exact output * one will get depends on the options set in * *\/sys/kernel/debug/tracing/trace_options* (see also the @@ -1013,7 +1015,7 @@ union bpf_attr { * The realm of the route for the packet associated to *skb*, or 0 * if none was found. * - * int bpf_perf_event_output(struct pt_reg *ctx, struct bpf_map *map, u64 flags, void *data, u64 size) + * int bpf_perf_event_output(struct pt_regs *ctx, struct bpf_map *map, u64 flags, void *data, u64 size) * Description * Write raw *data* blob into a special BPF perf event held by * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf @@ -1075,7 +1077,7 @@ union bpf_attr { * Return * 0 on success, or a negative error in case of failure. * - * int bpf_get_stackid(struct pt_reg *ctx, struct bpf_map *map, u64 flags) + * int bpf_get_stackid(struct pt_regs *ctx, struct bpf_map *map, u64 flags) * Description * Walk a user or a kernel stack and return its id. To achieve * this, the helper needs *ctx*, which is a pointer to the context @@ -1721,7 +1723,7 @@ union bpf_attr { * Return * 0 on success, or a negative error in case of failure. * - * int bpf_override_return(struct pt_reg *regs, u64 rc) + * int bpf_override_return(struct pt_regs *regs, u64 rc) * Description * Used for error injection, this helper uses kprobes to override * the return value of the probed function, and to set it to *rc*.