From patchwork Sun Nov 12 23:40:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 837299 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@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; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="ie0U7ph7"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yZqyX1Z7Zz9s84 for ; Mon, 13 Nov 2017 10:40:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751102AbdKLXkU (ORCPT ); Sun, 12 Nov 2017 18:40:20 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:40360 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750961AbdKLXkS (ORCPT ); Sun, 12 Nov 2017 18:40:18 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.21/8.16.0.21) with SMTP id vACNbLQb002642 for ; Sun, 12 Nov 2017 15:40:17 -0800 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=gDeVnch3HdcdnmL7dMY8bmBEHFQ11Svz+GwcFg0F8XQ=; b=ie0U7ph7zqi1xQJ+5j9T7b7151St+yNMeeD5sVNCmahBfor+/6BiwvpK1lkPdITBDbD1 2ENZO03IZ5tRltlJXRRhK7Cv3TVrXhRuHe11jp1Denbva1j0Xg6qNVH41dw01BXl+aQ4 y4T3eGVBpP5hLYW1QB97joyAung2NQwYhFo= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 2e6tjq0fy4-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sun, 12 Nov 2017 15:40:17 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB03.TheFacebook.com (192.168.16.13) with Microsoft SMTP Server id 14.3.361.1; Sun, 12 Nov 2017 15:40:16 -0800 Received: by devbig102.frc2.facebook.com (Postfix, from userid 4523) id DBF41428249D; Sun, 12 Nov 2017 15:40:15 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig102.frc2.facebook.com To: , , , , , , CC: , Song Liu Smtp-Origin-Cluster: frc2c02 Subject: [RFC v2 0/6] enable creating [k,u]probe with perf_event_open Date: Sun, 12 Nov 2017 15:40:06 -0800 Message-ID: <20171112234014.2983360-1-songliubraving@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.10432:, , definitions=2017-11-12_10:, , 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 Changes v1 to v2: Fix build issue reported by kbuild test bot by adding ifdef of CONFIG_KPROBE_EVENTS, and CONFIG_UPROBE_EVENTS. v1 cover letter: This is to follow up the discussion over "new kprobe api" at Linux Plumbers 2017: https://www.linuxplumbersconf.org/2017/ocw/proposals/4808 With current kernel, user space tools can only create/destroy [k,u]probes with a text-based API (kprobe_events and uprobe_events in tracefs). This approach relies on user space to clean up the [k,u]probe after using them. However, this is not easy for user space to clean up properly. To solve this problem, we introduce a file descriptor based API. Specifically, we extended perf_event_open to create [k,u]probe, and attach this [k,u]probe to the file descriptor created by perf_event_open. These [k,u]probe are associated with this file descriptor, so they are not available in tracefs. We reuse large portion of existing trace_kprobe and trace_uprobe code. Currently, the file descriptor API does not support arguments as the text-based API does. This should not be a problem, as user of the file decriptor based API read data through other methods (bpf, etc.). I also include a patch to to bcc, and a patch to man-page perf_even_open. Please see the list below. A fork of bcc with this patch is also available on github: https://github.com/liu-song-6/bcc/tree/new_perf_event_opn Thanks, Song man-pages patch: perf_event_open.2: add new type PERF_TYPE_PROBE bcc patch: bcc: Try use new API to create [k,u]probe with perf_event_open kernel patches: Song Liu (6): perf: Add new type PERF_TYPE_PROBE perf: copy new perf_event.h to tools/include/uapi perf: implement kprobe support to PERF_TYPE_PROBE perf: implement uprobe support to PERF_TYPE_PROBE bpf: add option for bpf_load.c to use PERF_TYPE_PROBE bpf: add new test test_many_kprobe include/linux/trace_events.h | 2 + include/uapi/linux/perf_event.h | 35 ++++++- kernel/events/core.c | 39 ++++++- kernel/trace/trace_event_perf.c | 127 +++++++++++++++++++++++ kernel/trace/trace_kprobe.c | 91 +++++++++++++++-- kernel/trace/trace_probe.h | 11 ++ kernel/trace/trace_uprobe.c | 90 +++++++++++++++-- samples/bpf/Makefile | 3 + samples/bpf/bpf_load.c | 61 ++++++----- samples/bpf/bpf_load.h | 12 +++ samples/bpf/test_many_kprobe_user.c | 184 ++++++++++++++++++++++++++++++++++ tools/include/uapi/linux/perf_event.h | 35 ++++++- 12 files changed, 643 insertions(+), 47 deletions(-) create mode 100644 samples/bpf/test_many_kprobe_user.c --- 2.9.5