From patchwork Tue Sep 17 13:30:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 1163392 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=dxuuu.xyz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="M7/yT+Yk"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="INF5Hsph"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46XkXp6xlsz9sCJ for ; Tue, 17 Sep 2019 23:31:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728338AbfIQNbf (ORCPT ); Tue, 17 Sep 2019 09:31:35 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:36271 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbfIQNbd (ORCPT ); Tue, 17 Sep 2019 09:31:33 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 21CCF3955; Tue, 17 Sep 2019 09:31:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 17 Sep 2019 09:31:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=GJV3QxlCo4B38 CZxCwMYESB8BQr0ysoGirhVOVPTXPg=; b=M7/yT+YkNbwMvtjxSy9SCuuXcdnAi WLhAFdfva1u5YNT9qstvdzKbH808QLuPCLeOtweRAEiW+nhF/JKw3lArAx3Yx4Cc W7X0DqlveUpVCYo1TQzqvv2nhITqh9UggMpoicV7ZJTDCeX76YAYIoH+jR5+EPuW R84WkOGRjgRg2HNbmXPMazLQce6f6I0teUXKFwOlLk2GeL1OBwGudHVHRKyptJ39 kJVNVhrCto1MCNTbOdsgJzTatsJAKXSSZztFFouiIW3170yW/IsbvM1CyJoQAVN7 nYmWTWNdJq+e5Qqo85hcGAuoenlViGHkOPhNif8gxJRqG33hQOI6BYALA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=GJV3QxlCo4B38CZxCwMYESB8BQr0ysoGirhVOVPTXPg=; b=INF5Hsph D5J3bypAjbNqXX2ilbdyVPSs1rWNPSqJMJ2BeR4VvvyDNnOK0CWCWQZyI9gAKZXK OoprdOsY0p+GF6vODk/n095KUjG2p0EpiLHfVd+B8Vm0ttCthcB6kviuxjxpedzQ OuiED22CKm9vvB6GatwdXyxWYqKR/6Npt2WT+NYDU1lrL/P0iyc2/7ijpnjmf66Z ndodX0yg2o64NTAy5bqlHR2qEywElth3PIdWJ3xMLlL/LvnGf6WN7zHPl07HFD43 M87HA3PWvtr/T4re5pkeiujrjpTo7Dx63mFF5LZd0UpZL+Sx8DErUVwojWChRMq2 yMj76B8dpg+z0g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudeigdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougig uhesugiguhhuuhdrgiihiieqnecukfhppeduleelrddvtddurdeiiedrtdenucfrrghrrg hmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihiienucevlhhushhtvghrufhi iigvpedt X-ME-Proxy: Received: from dlxu-fedora-R90QNFJV.thefacebook.com (unknown [199.201.66.0]) by mail.messagingengine.com (Postfix) with ESMTPA id 9888BD60063; Tue, 17 Sep 2019 09:31:29 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, songliubraving@fb.com, yhs@fb.com, andriin@fb.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: Daniel Xu , ast@fb.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-team@fb.com Subject: [PATCH bpf-next 1/5] perf/core: Add PERF_FORMAT_LOST read_format Date: Tue, 17 Sep 2019 06:30:52 -0700 Message-Id: <20190917133056.5545-2-dxu@dxuuu.xyz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190917133056.5545-1-dxu@dxuuu.xyz> References: <20190917133056.5545-1-dxu@dxuuu.xyz> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It's useful to know kprobe's nmissed count. For example with tracing tools, it's important to know when events may have been lost. debugfs currently exposes a control file to get this information, but it is not compatible with probes registered with the perf API. While bpf programs may be able to manually count nhit, there is no way to gather nmissed. In other words, it is currently not possible to this retrieve information about FD-based probes. This patch adds a new field to perf's read_format that lets users query misses. Misses include both misses from the underlying kprobe infrastructure and misses from ringbuffer infrastructure. Signed-off-by: Daniel Xu --- include/linux/trace_events.h | 1 + include/uapi/linux/perf_event.h | 5 ++++- kernel/events/core.c | 39 ++++++++++++++++++++++++++++++--- kernel/trace/trace_kprobe.c | 8 +++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 30a8cdcfd4a4..952520c1240a 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -587,6 +587,7 @@ extern int bpf_get_kprobe_info(const struct perf_event *event, u32 *fd_type, const char **symbol, u64 *probe_offset, u64 *probe_addr, bool perf_type_tracepoint); +extern u64 perf_kprobe_missed(const struct perf_event *event); #endif #ifdef CONFIG_UPROBE_EVENTS extern int perf_uprobe_init(struct perf_event *event, diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index 7198ddd0c6b1..bd874c7257f0 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -273,6 +273,7 @@ enum { * { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING * { u64 id; } && PERF_FORMAT_ID + * { u64 missed; } && PERF_FORMAT_LOST * } && !PERF_FORMAT_GROUP * * { u64 nr; @@ -280,6 +281,7 @@ enum { * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING * { u64 value; * { u64 id; } && PERF_FORMAT_ID + * { u64 missed; } && PERF_FORMAT_LOST * } cntr[nr]; * } && PERF_FORMAT_GROUP * }; @@ -289,8 +291,9 @@ enum perf_event_read_format { PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1, PERF_FORMAT_ID = 1U << 2, PERF_FORMAT_GROUP = 1U << 3, + PERF_FORMAT_LOST = 1U << 4, - PERF_FORMAT_MAX = 1U << 4, /* non-ABI */ + PERF_FORMAT_MAX = 1U << 5, /* non-ABI */ }; #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */ diff --git a/kernel/events/core.c b/kernel/events/core.c index 0463c1151bae..ee08d3ed6299 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1715,6 +1715,9 @@ static void __perf_event_read_size(struct perf_event *event, int nr_siblings) if (event->attr.read_format & PERF_FORMAT_ID) entry += sizeof(u64); + if (event->attr.read_format & PERF_FORMAT_LOST) + entry += sizeof(u64); + if (event->attr.read_format & PERF_FORMAT_GROUP) { nr += nr_siblings; size += sizeof(u64); @@ -4734,6 +4737,24 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running) } EXPORT_SYMBOL_GPL(perf_event_read_value); +static struct pmu perf_kprobe; +static u64 perf_event_lost(struct perf_event *event) +{ + struct ring_buffer *rb; + u64 lost = 0; + + rcu_read_lock(); + rb = rcu_dereference(event->rb); + if (likely(!!rb)) + lost += local_read(&rb->lost); + rcu_read_unlock(); + + if (event->attr.type == perf_kprobe.type) + lost += perf_kprobe_missed(event); + + return lost; +} + static int __perf_read_group_add(struct perf_event *leader, u64 read_format, u64 *values) { @@ -4770,11 +4791,15 @@ static int __perf_read_group_add(struct perf_event *leader, values[n++] += perf_event_count(leader); if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(leader); + if (read_format & PERF_FORMAT_LOST) + values[n++] = perf_event_lost(leader); for_each_sibling_event(sub, leader) { values[n++] += perf_event_count(sub); if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(sub); + if (read_format & PERF_FORMAT_LOST) + values[n++] = perf_event_lost(sub); } raw_spin_unlock_irqrestore(&ctx->lock, flags); @@ -4831,7 +4856,7 @@ static int perf_read_one(struct perf_event *event, u64 read_format, char __user *buf) { u64 enabled, running; - u64 values[4]; + u64 values[5]; int n = 0; values[n++] = __perf_event_read_value(event, &enabled, &running); @@ -4841,6 +4866,8 @@ static int perf_read_one(struct perf_event *event, values[n++] = running; if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(event); + if (read_format & PERF_FORMAT_LOST) + values[n++] = perf_event_lost(event); if (copy_to_user(buf, values, n * sizeof(u64))) return -EFAULT; @@ -6141,7 +6168,7 @@ static void perf_output_read_one(struct perf_output_handle *handle, u64 enabled, u64 running) { u64 read_format = event->attr.read_format; - u64 values[4]; + u64 values[5]; int n = 0; values[n++] = perf_event_count(event); @@ -6155,6 +6182,8 @@ static void perf_output_read_one(struct perf_output_handle *handle, } if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(event); + if (read_format & PERF_FORMAT_LOST) + values[n++] = perf_event_lost(event); __output_copy(handle, values, n * sizeof(u64)); } @@ -6165,7 +6194,7 @@ static void perf_output_read_group(struct perf_output_handle *handle, { struct perf_event *leader = event->group_leader, *sub; u64 read_format = event->attr.read_format; - u64 values[5]; + u64 values[6]; int n = 0; values[n++] = 1 + leader->nr_siblings; @@ -6183,6 +6212,8 @@ static void perf_output_read_group(struct perf_output_handle *handle, values[n++] = perf_event_count(leader); if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(leader); + if (read_format & PERF_FORMAT_LOST) + values[n++] = perf_event_lost(leader); __output_copy(handle, values, n * sizeof(u64)); @@ -6196,6 +6227,8 @@ static void perf_output_read_group(struct perf_output_handle *handle, values[n++] = perf_event_count(sub); if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(sub); + if (read_format & PERF_FORMAT_LOST) + values[n++] = perf_event_lost(sub); __output_copy(handle, values, n * sizeof(u64)); } diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 9d483ad9bb6c..cff471c8750b 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -196,6 +196,14 @@ bool trace_kprobe_error_injectable(struct trace_event_call *call) return within_error_injection_list(trace_kprobe_address(tk)); } +u64 perf_kprobe_missed(const struct perf_event *event) +{ + struct trace_event_call *call = event->tp_event; + struct trace_kprobe *tk = (struct trace_kprobe *)call->data; + + return tk->rp.kp.nmissed; +} + static int register_kprobe_event(struct trace_kprobe *tk); static int unregister_kprobe_event(struct trace_kprobe *tk); From patchwork Tue Sep 17 13:30:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 1163400 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=dxuuu.xyz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="ENVCxXQk"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="lnPWJyZh"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46XkY972xbz9sP6 for ; Tue, 17 Sep 2019 23:31:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726230AbfIQNb5 (ORCPT ); Tue, 17 Sep 2019 09:31:57 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:57951 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726131AbfIQNbe (ORCPT ); Tue, 17 Sep 2019 09:31:34 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 828C01282; Tue, 17 Sep 2019 09:31:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 17 Sep 2019 09:31:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=pIV+W4mI1mhQp QNrmXn//XRASWzx2LWV3Ls02jzraw0=; b=ENVCxXQkFfhNjUfhdYmzVlcevTVgd EPhnebAPkQLgkbGp25kVPo7g6CsstQBvv7ytxBt5QNV/GiPKpUPYLumPsxcGmfTR vjk9oHYjgnvW2PLSc0F3CmS+TTJUH73D8HebLybm8UN45z7/x7HDygqkAFsiITg6 0EmgXohZMoeWFL/ecb639JA/QoiW4K93vL5xxUGNh0QPWOH8oQxaZBE+VSVPfoVO RwRgjHgtbZhPkaFsU97pzYAEioDLNLjgNP2grbVy7ScRgqugD/LItgMb9JLsp7LE eAi7pdgVb0bFNeUmn+h+sYOJjB4JOLNo9pr49isnoWNwig2EJInr0yxMQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=pIV+W4mI1mhQpQNrmXn//XRASWzx2LWV3Ls02jzraw0=; b=lnPWJyZh 4aP3xY877eQFYxlVN3g7kuQqZSuUBLM4MFOU3DMtxkZsj9Kom8JhaFpbNydXxLVh NdQ0AUDVXD7CLApslf8MR5oswUJGT0ILrKUCNjuyHSMD68tmkwIl8fuHkFWHPXqo ZfBoSjX2qIXFqntKhlA+6urMnuEmhrvVx9CnuAQQZF3kKLzre5qlmnqIH1Ipm5kn EOCOho+zNhGByEvM4FTH5+Zi2/7y7n4e+m1LI3OO6MNgczTxUdAiPY/KT3SHUy8P Xxa5XzXvMExy7lGjAk1XYms0VeHWlWsvEjCA5NbHxLuKdVroHmJu8HvF56qVxktY PxHGsqVrgsplLw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudeigdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougig uhesugiguhhuuhdrgiihiieqnecukfhppeduleelrddvtddurdeiiedrtdenucfrrghrrg hmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihiienucevlhhushhtvghrufhi iigvpedu X-ME-Proxy: Received: from dlxu-fedora-R90QNFJV.thefacebook.com (unknown [199.201.66.0]) by mail.messagingengine.com (Postfix) with ESMTPA id 15032D6005A; Tue, 17 Sep 2019 09:31:31 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, songliubraving@fb.com, yhs@fb.com, andriin@fb.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: Daniel Xu , ast@fb.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-team@fb.com Subject: [PATCH bpf-next 2/5] perf/core: Sync perf_event.h to tools Date: Tue, 17 Sep 2019 06:30:53 -0700 Message-Id: <20190917133056.5545-3-dxu@dxuuu.xyz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190917133056.5545-1-dxu@dxuuu.xyz> References: <20190917133056.5545-1-dxu@dxuuu.xyz> MIME-Version: 1.0 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Signed-off-by: Daniel Xu --- tools/include/uapi/linux/perf_event.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h index 7198ddd0c6b1..bd874c7257f0 100644 --- a/tools/include/uapi/linux/perf_event.h +++ b/tools/include/uapi/linux/perf_event.h @@ -273,6 +273,7 @@ enum { * { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING * { u64 id; } && PERF_FORMAT_ID + * { u64 missed; } && PERF_FORMAT_LOST * } && !PERF_FORMAT_GROUP * * { u64 nr; @@ -280,6 +281,7 @@ enum { * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING * { u64 value; * { u64 id; } && PERF_FORMAT_ID + * { u64 missed; } && PERF_FORMAT_LOST * } cntr[nr]; * } && PERF_FORMAT_GROUP * }; @@ -289,8 +291,9 @@ enum perf_event_read_format { PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1, PERF_FORMAT_ID = 1U << 2, PERF_FORMAT_GROUP = 1U << 3, + PERF_FORMAT_LOST = 1U << 4, - PERF_FORMAT_MAX = 1U << 4, /* non-ABI */ + PERF_FORMAT_MAX = 1U << 5, /* non-ABI */ }; #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */ From patchwork Tue Sep 17 13:30:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 1163393 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=dxuuu.xyz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="d4Y1LE9+"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="xxhskt1q"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46XkXv0zrXz9sNx for ; Tue, 17 Sep 2019 23:31:43 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728488AbfIQNbi (ORCPT ); Tue, 17 Sep 2019 09:31:38 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:57951 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728372AbfIQNbg (ORCPT ); Tue, 17 Sep 2019 09:31:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id D45D939E6; Tue, 17 Sep 2019 09:31:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 17 Sep 2019 09:31:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=ZwW7fkRd9gZh9 tDNNySIyBWq5uzvW1saTrgDMoAFOvk=; b=d4Y1LE9+5YPArtmdXmpgmcn92BecV iW9bhbWlVueDg+ZpgLeZro1c+F60+qDGdiARBYl4u9S++9iJ8nU4Nqqq064Q0qHB hzrb6hRtYV90cOrtmwLP0oEaObY6dJUjXvwoZV9qJ6OW8KD7IPUJFLDIKcYBWbGz qS/nWVnaOHCXbNTLmY1HytRTPTVJWyebRrJeDlLbQRykpiLugaX/1c/ruE9tFzNU cO1Axz9/EBE8xACXsjUCHdYXQFFf9per2bU+xgciEJA4ylLKRnGAvho+b0Pcfpe1 2jmZslJX3wEjLUziZaNwgB/i7D6ZiS5NEFmHBx5rzkNcW2jUzy5HTJn6g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=ZwW7fkRd9gZh9tDNNySIyBWq5uzvW1saTrgDMoAFOvk=; b=xxhskt1q hKcaUOxS7BV7J52wmR/pHhQhsNFvOHH9f6MLetOtLWD4aAJ2428PS/CI0K3fo2aZ MCobfzbCSmPOHcGE9v6Eo5236oqOYFIzFos87+TTp4nk3gWnjLX2gTseSGRL+R48 7MoOfMPP9rHrnv1TKZTn41MGsHd0t29YUa+MdbMJ7ZAYd8RcMEQXVpjKm1Fx14bY gAltumB2wprDROmM69TF2ZNkanp/NELcVPdA8LtxZlcVLKiQ+jv0Pai5QlJd0vvK 8kyb8ZZyjDSjjd0vMfqBj9lxEBODaOjs/s1co9U5ZkwAi2P7BBQMRQwYdKu3cTTa Ex2CLHooN9+kOQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudeigdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdefhedmnecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougig uhesugiguhhuuhdrgiihiieqnecukfhppeduleelrddvtddurdeiiedrtdenucfrrghrrg hmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihiienucevlhhushhtvghrufhi iigvpedu X-ME-Proxy: Received: from dlxu-fedora-R90QNFJV.thefacebook.com (unknown [199.201.66.0]) by mail.messagingengine.com (Postfix) with ESMTPA id 771A5D6005B; Tue, 17 Sep 2019 09:31:32 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, songliubraving@fb.com, yhs@fb.com, andriin@fb.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: Daniel Xu , ast@fb.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-team@fb.com Subject: [PATCH bpf-next 3/5] libbpf: Add helpers to extract perf fd from bpf_link Date: Tue, 17 Sep 2019 06:30:54 -0700 Message-Id: <20190917133056.5545-4-dxu@dxuuu.xyz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190917133056.5545-1-dxu@dxuuu.xyz> References: <20190917133056.5545-1-dxu@dxuuu.xyz> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It is sometimes necessary to perform operations on the underlying perf fd. There is not currently a way to extract the fd given a bpf_link, so add a a pair of casting and getting helpers. The casting and getting helpers are nice because they let us define broad categories of links that makes it clear to users what they can expect to extract from what type of link. Acked-by: Song Liu Acked-by: Andrii Nakryiko Signed-off-by: Daniel Xu --- tools/lib/bpf/libbpf.c | 21 +++++++++++++++++++++ tools/lib/bpf/libbpf.h | 13 +++++++++++++ tools/lib/bpf/libbpf.map | 3 +++ 3 files changed, 37 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index e0276520171b..1ca0acd1d823 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -4875,6 +4875,7 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, struct bpf_link { int (*destroy)(struct bpf_link *link); + enum bpf_link_type type; }; int bpf_link__destroy(struct bpf_link *link) @@ -4908,6 +4909,24 @@ static int bpf_link__destroy_perf_event(struct bpf_link *link) return err; } +const struct bpf_link_fd *bpf_link__as_fd(const struct bpf_link *link) +{ + if (link->type != LIBBPF_LINK_FD) + return NULL; + + return (struct bpf_link_fd *)link; +} + +enum bpf_link_type bpf_link__type(const struct bpf_link *link) +{ + return link->type; +} + +int bpf_link_fd__fd(const struct bpf_link_fd *link) +{ + return link->fd; +} + struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog, int pfd) { @@ -4931,6 +4950,7 @@ struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog, if (!link) return ERR_PTR(-ENOMEM); link->link.destroy = &bpf_link__destroy_perf_event; + link->link.type = LIBBPF_LINK_FD; link->fd = pfd; if (ioctl(pfd, PERF_EVENT_IOC_SET_BPF, prog_fd) < 0) { @@ -5224,6 +5244,7 @@ struct bpf_link *bpf_program__attach_raw_tracepoint(struct bpf_program *prog, link = malloc(sizeof(*link)); if (!link) return ERR_PTR(-ENOMEM); + link->link.type = LIBBPF_LINK_FD; link->link.destroy = &bpf_link__destroy_fd; pfd = bpf_raw_tracepoint_open(tp_name, prog_fd); diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index e8f70977d137..2ddef5315ff9 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -166,7 +166,20 @@ LIBBPF_API int bpf_program__pin(struct bpf_program *prog, const char *path); LIBBPF_API int bpf_program__unpin(struct bpf_program *prog, const char *path); LIBBPF_API void bpf_program__unload(struct bpf_program *prog); +enum bpf_link_type { + LIBBPF_LINK_FD, +}; + struct bpf_link; +struct bpf_link_fd; + +/* casting APIs */ +LIBBPF_API const struct bpf_link_fd * +bpf_link__as_fd(const struct bpf_link *link); + +/* getters APIs */ +LIBBPF_API enum bpf_link_type bpf_link__type(const struct bpf_link *link); +LIBBPF_API int bpf_link_fd__fd(const struct bpf_link_fd *link); LIBBPF_API int bpf_link__destroy(struct bpf_link *link); diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index d04c7cb623ed..216713b9eef6 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -189,4 +189,7 @@ LIBBPF_0.0.4 { LIBBPF_0.0.5 { global: bpf_btf_get_next_id; + bpf_link__type; + bpf_link__as_fd; + bpf_link_fd__fd; } LIBBPF_0.0.4; From patchwork Tue Sep 17 13:30:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 1163397 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=dxuuu.xyz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="zKcskGT4"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="gYIH4hII"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46XkY61fhjz9sNx for ; Tue, 17 Sep 2019 23:31:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728656AbfIQNbu (ORCPT ); Tue, 17 Sep 2019 09:31:50 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:60105 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbfIQNbh (ORCPT ); Tue, 17 Sep 2019 09:31:37 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 45CB32E12; Tue, 17 Sep 2019 09:31:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 17 Sep 2019 09:31:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=wVxLkASr4WgjE Vi71vH9ixp5KrWmhI1orhWokzEt9X8=; b=zKcskGT4h6RF+C7xpW8WTiVytDeNa HGE6RrXYCxRA7F5ZB9rbVrqJzDS/zKZ8pvE10YxmWFgPO0C8FCdGln2Vp0oH1+Hq IQGkBz+WA2z20HxxcRBYokrANIwXhpi/9sIyV3BN0lXq95U5rJnX7eZEKqVBaj4X 5H0N6p7oiuKdDFV2Pmz12AnBfK6xvPGA8XE3f5hxT/m3TomaE5zJniPWElw17rxE HsfpjOTzWgAszKmpIpDSiLTdRJCavv8YqHRtkAisZOQ7hBsSSGMF7NuQPkVxSvZf U4g9bhJkeQZKYRzyemYsxDCI+BHHCYWrqSqfh+0YNApVgNmq6zDNIkkHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=wVxLkASr4WgjEVi71vH9ixp5KrWmhI1orhWokzEt9X8=; b=gYIH4hII Fji6sdX4JYHLkBMS56gs0v1KPOgaoY42JrmbY7lOe1Rv5VRWh/21BVAeilocaLLL GFWzO7xjux+blhkfxUbury5D0OWi6v2V/WdXBxruXfm3I/c0PnjN3VzwUnydqi98 LZ6LXim9JjlnP0AjzbQwoYxRSI6Eq3v0Wl+DdUFAqqCROp9JlY2Rd1KMqtv95ESD zqYjMqF1p2FOYEAfjK0tlyl+oQ+mmsGQom8iUS59QrRKuwK7i2NYbXyuiz8PEeXw Z7ILDRCazM9WBIF7FZ7/9JPwSK8/+drFkStSC+kVVd6FfJdLxGDVunmsst5fDBnP b9sFP+mHySGcEg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudeigdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougig uhesugiguhhuuhdrgiihiieqnecukfhppeduleelrddvtddurdeiiedrtdenucfrrghrrg hmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihiienucevlhhushhtvghrufhi iigvpedu X-ME-Proxy: Received: from dlxu-fedora-R90QNFJV.thefacebook.com (unknown [199.201.66.0]) by mail.messagingengine.com (Postfix) with ESMTPA id D4DBED6005D; Tue, 17 Sep 2019 09:31:33 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, songliubraving@fb.com, yhs@fb.com, andriin@fb.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: Daniel Xu , ast@fb.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-team@fb.com Subject: [PATCH bpf-next 4/5] libbpf: Set read_format PERF_FORMAT_LOST on kprobe perf fds Date: Tue, 17 Sep 2019 06:30:55 -0700 Message-Id: <20190917133056.5545-5-dxu@dxuuu.xyz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190917133056.5545-1-dxu@dxuuu.xyz> References: <20190917133056.5545-1-dxu@dxuuu.xyz> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is no way to get the nmissed count from kprobes that are created using the perf API. The previous commits added read_format support for this count. Enable it in this commit. Signed-off-by: Daniel Xu --- tools/lib/bpf/libbpf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 1ca0acd1d823..43f45f6d914d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -5031,7 +5031,7 @@ static int determine_uprobe_retprobe_bit(void) } static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name, - uint64_t offset, int pid) + uint64_t offset, int pid, uint64_t read_format) { struct perf_event_attr attr = {}; char errmsg[STRERR_BUFSIZE]; @@ -5060,6 +5060,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name, } attr.size = sizeof(attr); attr.type = type; + attr.read_format = read_format; attr.config1 = ptr_to_u64(name); /* kprobe_func or uprobe_path */ attr.config2 = offset; /* kprobe_addr or probe_offset */ @@ -5087,7 +5088,8 @@ struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog, int pfd, err; pfd = perf_event_open_probe(false /* uprobe */, retprobe, func_name, - 0 /* offset */, -1 /* pid */); + 0 /* offset */, -1 /* pid */, + PERF_FORMAT_LOST /* read_format */); if (pfd < 0) { pr_warning("program '%s': failed to create %s '%s' perf event: %s\n", bpf_program__title(prog, false), @@ -5118,7 +5120,8 @@ struct bpf_link *bpf_program__attach_uprobe(struct bpf_program *prog, int pfd, err; pfd = perf_event_open_probe(true /* uprobe */, retprobe, - binary_path, func_offset, pid); + binary_path, func_offset, pid, + 0 /* read_format */); if (pfd < 0) { pr_warning("program '%s': failed to create %s '%s:0x%zx' perf event: %s\n", bpf_program__title(prog, false), From patchwork Tue Sep 17 13:30:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 1163394 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=dxuuu.xyz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="nhdSIJ0B"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="uQIYOeZi"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46XkXw2L6jz9sP6 for ; Tue, 17 Sep 2019 23:31:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728559AbfIQNbm (ORCPT ); Tue, 17 Sep 2019 09:31:42 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:41901 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728389AbfIQNbi (ORCPT ); Tue, 17 Sep 2019 09:31:38 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id B201539D1; Tue, 17 Sep 2019 09:31:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 17 Sep 2019 09:31:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=dX7odFuYQlYRo aazX3l6kQgfWSrUlRAtCfmm0Llb/vo=; b=nhdSIJ0BeLlEZ4IIlAAQjRPlf21HP ZO+QN0BRkv/FA5Z/+tCwmE4nP5oNfJJ5P4S7tpQdbbU5BwItnwv807Y7cPaFb+yd ceurAaROCn59+sG5mibqkxbYmwo1QKHbmExMbCBHXqTYDln2iT/oApReJWdWlJTR RBZ04cZ2R0v+wPCdajvqbarV7nMzxPTXciKLEoLV0ap7QzbWcjY0wEckGJgZNbtK GS9qAtZGfRdubQY9DlW09fle0oocDDKRi15LRE2RH1ixX1kL8VUO1i51UmLUHOk4 2/XtfxEOhLkt5OgFQkaneSz4dHUizP0heqNJvBu480izoGonOHLEnpYJQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=dX7odFuYQlYRoaazX3l6kQgfWSrUlRAtCfmm0Llb/vo=; b=uQIYOeZi uh1IdMphoAoUceTANPz/IybEQhFKSFTxEXks46G5RhEts7Nk7loSMWEB7oKfsvG3 j5VSNdA++TSlHQk4sSyvMp9Hg+pBfZ79vFSVF9nMQMKm+QAXqbscpmmX9Dli6Sem R5+edUug9h9u5sbdQz9kwIDPRi1w+A2ZK6beP5lHDMHBpQqjKMdS5v4aCxBUeIoa EheK/EbdIYIVJxOqSqM01PamTst8SmrSwHakV6dWFGtLw0NDUJc5CvQpyK8cTeX3 2+Plc2D+b3qCsNoPpG54gNOl4HS+4RfunWuW4WAVM+PWg3wmBIKymjFjvNlep8XY BkkQ2nCxaBWiYg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudeigdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougig uhesugiguhhuuhdrgiihiieqnecukfhppeduleelrddvtddurdeiiedrtdenucfrrghrrg hmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihiienucevlhhushhtvghrufhi iigvpedu X-ME-Proxy: Received: from dlxu-fedora-R90QNFJV.thefacebook.com (unknown [199.201.66.0]) by mail.messagingengine.com (Postfix) with ESMTPA id 40AE4D6005A; Tue, 17 Sep 2019 09:31:35 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, songliubraving@fb.com, yhs@fb.com, andriin@fb.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: Daniel Xu , ast@fb.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-team@fb.com Subject: [PATCH bpf-next 5/5] libbpf: Add selftest for PERF_FORMAT_LOST perf read_format Date: Tue, 17 Sep 2019 06:30:56 -0700 Message-Id: <20190917133056.5545-6-dxu@dxuuu.xyz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190917133056.5545-1-dxu@dxuuu.xyz> References: <20190917133056.5545-1-dxu@dxuuu.xyz> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Daniel Xu --- .../selftests/bpf/prog_tests/attach_probe.c | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c index 5ecc267d98b0..3d636cccb6dc 100644 --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c @@ -1,6 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 #include +struct perf_read_output { + u64 count; + u64 lost; +}; + ssize_t get_base_addr() { size_t start; char buf[256]; @@ -32,6 +37,8 @@ void test_attach_probe(void) const char *file = "./test_attach_probe.o"; struct bpf_program *kprobe_prog, *kretprobe_prog; struct bpf_program *uprobe_prog, *uretprobe_prog; + struct perf_read_output kprobe_read_output; + const struct bpf_link_fd *kprobe_fd_link; struct bpf_object *obj; int err, prog_fd, duration = 0, res; struct bpf_link *kprobe_link = NULL; @@ -40,7 +47,8 @@ void test_attach_probe(void) struct bpf_link *uretprobe_link = NULL; int results_map_fd; size_t uprobe_offset; - ssize_t base_addr; + ssize_t base_addr, nread; + int kprobe_fd; base_addr = get_base_addr(); if (CHECK(base_addr < 0, "get_base_addr", @@ -116,6 +124,28 @@ void test_attach_probe(void) /* trigger & validate kprobe && kretprobe */ usleep(1); + kprobe_fd_link = bpf_link__as_fd(kprobe_link); + if (CHECK(!kprobe_fd_link, "kprobe_link_as_fd", + "failed to cast link to fd link\n")) + goto cleanup; + + kprobe_fd = bpf_link_fd__fd(kprobe_fd_link); + if (CHECK(kprobe_fd < 0, "kprobe_get_perf_fd", + "failed to get perf fd from kprobe link\n")) + goto cleanup; + + /* Set to unexpected value so we can check the read(2) did stuff */ + kprobe_read_output.lost = 1; + nread = read(kprobe_fd, &kprobe_read_output, + sizeof(kprobe_read_output)); + if (CHECK(nread != sizeof(kprobe_read_output), "kprobe_perf_read", + "failed to read from perf fd\n")) + goto cleanup; + if (CHECK(kprobe_read_output.lost != 0, "kprobe_lost", + "read wrong value from perf fd: %lu\n", + kprobe_read_output.lost)) + goto cleanup; + err = bpf_map_lookup_elem(results_map_fd, &kprobe_idx, &res); if (CHECK(err, "get_kprobe_res", "failed to get kprobe res: %d\n", err))