From patchwork Tue May 15 23:45:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 914034 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=pass (p=none dis=none) header.from=fb.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="LsOVUWoU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40lvMm1WGLz9s16 for ; Wed, 16 May 2018 09:45:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752574AbeEOXpw (ORCPT ); Tue, 15 May 2018 19:45:52 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:60528 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752513AbeEOXpd (ORCPT ); Tue, 15 May 2018 19:45:33 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.22/8.16.0.22) with SMTP id w4FNfdw6029381 for ; Tue, 15 May 2018 16:45:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=5tp+igI3j6GBUQyQuVIse7Hz+NJpdLrZwnyPzayjHfo=; b=LsOVUWoUGDD8EtA/g3yt1OCCZfN5OduPHToSGPCHd93kOtUomMKFfXHK9rUXFeAs3Ymk uBoggU3afAK+sPhgwUDrYP8nnwzZtcRUIlLUI/NefgEq7/jzzHxGt+ScMnum3JccMrcp rQDSUY6CMLmBaZf0N4O1Eci0FfSrgStd62I= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 2j08jcg4dg-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 15 May 2018 16:45:33 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB10.TheFacebook.com (192.168.16.20) with Microsoft SMTP Server id 14.3.361.1; Tue, 15 May 2018 16:45:30 -0700 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id 0FEF73701617; Tue, 15 May 2018 16:45:21 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Yonghong Song Smtp-Origin-Hostname: devbig003.ftw2.facebook.com To: , , , CC: Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next 0/7] bpf: implement BPF_PERF_EVENT_QUERY for perf event query Date: Tue, 15 May 2018 16:45:14 -0700 Message-ID: <20180515234521.856763-1-yhs@fb.com> X-Mailer: git-send-email 2.9.5 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-15_09:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, suppose a userspace application has loaded a bpf program and attached it to a tracepoint/kprobe/uprobe, and a bpf introspection tool, e.g., bpftool, wants to show which bpf program is attached to which tracepoint/kprobe/uprobe. Such attachment information will be really useful to understand the overall bpf deployment in the system. There is a name field (16 bytes) for each program, which could be used to encode the attachment point. There are some drawbacks for this approaches. First, bpftool user (e.g., an admin) may not really understand the association between the name and the attachment point. Second, if one program is attached to multiple places, encoding a proper name which can imply all these attachments becomes difficult. This patch introduces a new bpf subcommand BPF_PERF_EVENT_QUERY. Given a pid and fd, if the is associated with a tracepoint/kprobe/uprobea perf event, BPF_PERF_EVENT_QUERY will return . prog_id . tracepoint name, or . k[ret]probe funcname + offset or kernel addr, or . u[ret]probe filename + offset to the userspace. The user can use "bpftool prog" to find more information about bpf program itself with prog_id. Patch #1 adds function perf_get_event() in kernel/events/core.c. Patch #2 implements the bpf subcommand BPF_PERF_EVENT_QUERY. Patch #3 syncs tools bpf.h header and also add bpf_trace_event_query() in the libbpf library for samples/selftests/bpftool to use. Patch #4 adds ksym_get_addr() utility function. Patch #5 add a test in samples/bpf for querying k[ret]probes and u[ret]probes. Patch #6 add a test in tools/testing/selftests/bpf for querying raw_tracepoint and tracepoint. Patch #7 add a new subcommand "perf" to bpftool. Yonghong Song (7): perf/core: add perf_get_event() to return perf_event given a struct file bpf: introduce bpf subcommand BPF_PERF_EVENT_QUERY tools/bpf: sync kernel header bpf.h and add bpf_trace_event_query in libbpf tools/bpf: add ksym_get_addr() in trace_helpers samples/bpf: add a samples/bpf test for BPF_PERF_EVENT_QUERY tools/bpf: add two BPF_PERF_EVENT_QUERY tests in test_progs tools/bpftool: add perf subcommand include/linux/perf_event.h | 5 + include/linux/trace_events.h | 15 ++ include/uapi/linux/bpf.h | 25 ++ kernel/bpf/syscall.c | 113 +++++++++ kernel/events/core.c | 8 + kernel/trace/bpf_trace.c | 53 ++++ kernel/trace/trace_kprobe.c | 29 +++ kernel/trace/trace_uprobe.c | 22 ++ samples/bpf/Makefile | 4 + samples/bpf/perf_event_query_kern.c | 19 ++ samples/bpf/perf_event_query_user.c | 376 ++++++++++++++++++++++++++++ tools/bpf/bpftool/main.c | 3 +- tools/bpf/bpftool/main.h | 1 + tools/bpf/bpftool/perf.c | 188 ++++++++++++++ tools/include/uapi/linux/bpf.h | 25 ++ tools/lib/bpf/bpf.c | 23 ++ tools/lib/bpf/bpf.h | 3 + tools/testing/selftests/bpf/test_progs.c | 133 ++++++++++ tools/testing/selftests/bpf/trace_helpers.c | 12 + tools/testing/selftests/bpf/trace_helpers.h | 1 + 20 files changed, 1057 insertions(+), 1 deletion(-) create mode 100644 samples/bpf/perf_event_query_kern.c create mode 100644 samples/bpf/perf_event_query_user.c create mode 100644 tools/bpf/bpftool/perf.c