From patchwork Wed Dec 6 22:45:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 845388 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="MoVY5cB/"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ysYft2NSVz9s71 for ; Thu, 7 Dec 2017 09:48:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752905AbdLFWq4 (ORCPT ); Wed, 6 Dec 2017 17:46:56 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:47714 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752771AbdLFWpY (ORCPT ); Wed, 6 Dec 2017 17:45:24 -0500 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB6MjNbx004486 for ; Wed, 6 Dec 2017 14:45:23 -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=uuATOzQtPTft2ReqLjdX6xoIhUUBvIgFnaJiAlqLCoc=; b=MoVY5cB/AI7fRokC6rzcE/mFjZxzQmWcnhmaT3CoN/aNi6SOZ3nr/kE784+gTVWry/O0 DEr29Ybe+JczD8g9gxaUjlzc29/7UF7vRGOSG0W6RJnNBEuseDNGOoQEQt7SBvJ4hMaJ DhR7iTpOyNX6UXBMgqtAhzS2ErrzMNA7Ntw= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2eppx2ggj5-3 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 06 Dec 2017 14:45:23 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB14.TheFacebook.com (192.168.16.24) with Microsoft SMTP Server id 14.3.361.1; Wed, 6 Dec 2017 14:45:21 -0800 Received: by devbig102.frc2.facebook.com (Postfix, from userid 4523) id 180CA428280F; Wed, 6 Dec 2017 14:45:21 -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: [PATCH v5 0/6] enable creating [k,u]probe with perf_event_open Date: Wed, 6 Dec 2017 14:45:10 -0800 Message-ID: <20171206224518.3598254-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-12-06_08:, , 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 PATCH v4 to PATCH v5: Remove PERF_PROBE_CONFIG_IS_RETPROBE from uapi, use PMU_FORMAT_ATTR instead. Changes PATCH v3 to PATCH v4: Remove uapi define MAX_PROBE_FUNC_NAME_LEN, use KSYM_NAME_LEN instead. Add flag PERF_PROBE_CONFIG_IS_RETPROBE for config field of [k,u]probe. Optimize ifdef's of CONFIG_KPROBE_EVENTS and CONFIG_UPROBE_EVENTS. Optimize checks in perf_event_is_tracing(). Optimize perf_tp_register(). Changes PATCH v2 to PATCH v3: Remove fixed type PERF_TYPE_KPROBE and PERF_TYPE_UPROBE, use dynamic type instead. Update userspace (samples/bpf, bcc) to look up type from sysfs. Change License info in test_many_kprobe_user.c as Philippe Ombredanne suggested. Changes PATCH v1 to PATCH v2: Split PERF_TYPE_PROBE into PERF_TYPE_KPROBE and PERF_TYPE_UPROBE. Split perf_probe into perf_kprobe and perf_uprobe. Remove struct probe_desc, use config1 and config2 instead. Changes RFC v2 to PATCH v1: Check type PERF_TYPE_PROBE in perf_event_set_filter(). Rebase on to tip perf/core. Changes RFC v1 to RFC v2: Fix build issue reported by kbuild test bot by adding ifdef of CONFIG_KPROBE_EVENTS, and CONFIG_UPROBE_EVENTS. RFC 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/perf_event_open Thanks, Song man-pages patch: perf_event_open.2: add type kprobe and uprobe bcc patch: bcc: Try use new API to create [k,u]probe with perf_event_open kernel patches: Song Liu (6): perf: prepare perf_event.h for new types perf_kprobe and perf_uprobe perf: copy new perf_event.h to tools/include/uapi perf: implement pmu perf_kprobe perf: implement pmu perf_uprobe bpf: add option for bpf_load.c to use perf_kprobe bpf: add new test test_many_kprobe include/linux/trace_events.h | 8 ++ include/uapi/linux/perf_event.h | 4 + kernel/events/core.c | 131 +++++++++++++++++++++++- kernel/trace/trace_event_perf.c | 102 +++++++++++++++++++ kernel/trace/trace_kprobe.c | 91 +++++++++++++++-- kernel/trace/trace_probe.h | 11 ++ kernel/trace/trace_uprobe.c | 86 ++++++++++++++-- samples/bpf/Makefile | 3 + samples/bpf/bpf_load.c | 66 ++++++++++-- samples/bpf/bpf_load.h | 14 +++ samples/bpf/test_many_kprobe_user.c | 186 ++++++++++++++++++++++++++++++++++ tools/include/uapi/linux/perf_event.h | 4 + 12 files changed, 677 insertions(+), 29 deletions(-) create mode 100644 samples/bpf/test_many_kprobe_user.c Acked-by: Philippe Ombredanne --- 2.9.5