From patchwork Wed Nov 15 17:23:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 838267 X-Patchwork-Delegate: davem@davemloft.net 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="G5qpW9SZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ycWV805RBz9s7M for ; Thu, 16 Nov 2017 04:25:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758384AbdKORZQ (ORCPT ); Wed, 15 Nov 2017 12:25:16 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:45752 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758117AbdKORX6 (ORCPT ); Wed, 15 Nov 2017 12:23:58 -0500 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAFHNuvo026854 for ; Wed, 15 Nov 2017 09:23:57 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=HJN1JeuPQ+lCnNvIb01WmdGVEALPeqDQ2NJWbG4E3gE=; b=G5qpW9SZnQFWVGFyJbQ/afxi1BSd1SJBGE1vcvherV1cyzWvG4GmlaGCdEEBSU8N/tk8 hPxgN2c4x8zbGPhvjYMvImxeYUXtW+0SPYkcq6uX+Q6raIH4jMx/0E7b9gm51ugahJCz wurfsFQdlbNp0gpxezRDj8VeGV02BX55Xc0= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2e8rh6gb17-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 15 Nov 2017 09:23:57 -0800 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; Wed, 15 Nov 2017 09:23:46 -0800 Received: by devbig102.frc2.facebook.com (Postfix, from userid 4523) id 60E9042824EB; Wed, 15 Nov 2017 09:23:46 -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 1/6] perf: Add new type PERF_TYPE_PROBE Date: Wed, 15 Nov 2017 09:23:33 -0800 Message-ID: <20171115172339.1791161-3-songliubraving@fb.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171115172339.1791161-1-songliubraving@fb.com> References: <20171115172339.1791161-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-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 A new perf type PERF_TYPE_PROBE is added to allow creating [k,u]probe with perf_event_open. These [k,u]probe are associated with the file decriptor created by perf_event_open, thus are easy to clean when the file descriptor is destroyed. Struct probe_desc and two flags, is_uprobe and is_return, are added to describe the probe being created with perf_event_open. Note: We use type __u64 for pointer probe_desc instead of __aligned_u64. The reason here is to avoid changing the size of struct perf_event_attr, and breaking new-kernel-old-utility scenario. To avoid alignment problem with the pointer, we will (in the following patches) copy probe_desc to __aligned_u64 before using it as pointer. Signed-off-by: Song Liu Reviewed-by: Yonghong Song Reviewed-by: Josef Bacik Acked-by: Alexei Starovoitov --- include/uapi/linux/perf_event.h | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index 362493a..cc42d59 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -33,6 +33,7 @@ enum perf_type_id { PERF_TYPE_HW_CACHE = 3, PERF_TYPE_RAW = 4, PERF_TYPE_BREAKPOINT = 5, + PERF_TYPE_PROBE = 6, PERF_TYPE_MAX, /* non-ABI */ }; @@ -299,6 +300,29 @@ enum perf_event_read_format { #define PERF_ATTR_SIZE_VER4 104 /* add: sample_regs_intr */ #define PERF_ATTR_SIZE_VER5 112 /* add: aux_watermark */ +#define MAX_PROBE_FUNC_NAME_LEN 64 +/* + * Describe a kprobe or uprobe for PERF_TYPE_PROBE. + * perf_event_attr.probe_desc will point to this structure. is_uprobe + * and is_return are used to differentiate different types of probe + * (k/u, probe/retprobe). + * + * The two unions should be used as follows: + * For uprobe: use path and offset; + * For kprobe: if func is empty, use addr + * if func is not emtpy, use func and offset + */ +struct probe_desc { + union { + __aligned_u64 func; + __aligned_u64 path; + }; + union { + __aligned_u64 addr; + __u64 offset; + }; +}; + /* * Hardware event_id to monitor via a performance monitoring event: * @@ -320,7 +344,10 @@ struct perf_event_attr { /* * Type specific configuration information. */ - __u64 config; + union { + __u64 config; + __u64 probe_desc; /* ptr to struct probe_desc */ + }; union { __u64 sample_period; @@ -370,7 +397,11 @@ struct perf_event_attr { context_switch : 1, /* context switch data */ write_backward : 1, /* Write ring buffer from end to beginning */ namespaces : 1, /* include namespaces data */ - __reserved_1 : 35; + + /* For PERF_TYPE_PROBE */ + is_uprobe : 1, /* 0: kprobe, 1: uprobe */ + is_return : 1, /* 0: probe, 1: retprobe */ + __reserved_1 : 33; union { __u32 wakeup_events; /* wakeup every n events */