From patchwork Sun Sep 6 07:13:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 53187 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 9E8D022B05 for ; Sun, 6 Sep 2015 07:19:11 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf17393860lbb.3 for ; Sun, 06 Sep 2015 00:19:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=V3VenOCYmEU2BdQlElK+kEa1EWthsz0BFiP6sRrZahA=; b=lB4brGaScw+FVqGdD1RdBpwJ/w+IGuZ41Ickc2SkwBOQcYcdi2s1FY1CTpeSPfQF8s L1m7pxNspzroTKt+bOyF4wgwwMGmWBJx+Lmlw4FqevkBf8o04/517hUBlQ3xZldj4MZl n7PDnvYyEUfBAoRoOoUQSJoNY1me9M/RfkWHeCGyn1qKTxKv3a8XtX3H7POq47/05WuQ hFpqf9aO+L2AS6atnsM50rnZBCsMqaZ80DbyOHtssiSwsGnlkbW+iKxCGkJH5TeKJiKV bNs5HtXyiNaI0hshWS0udBwRrfaxmCWyeAfmXktqM+A3iHruGSnUvozuzkU1r6JxKTbo hzmA== X-Gm-Message-State: ALoCoQnZUCoS33ZaxA5pdfzqGBw4bNCl1nG5yeYMwnvC6Qx9JFeycDgGw1r++P0C7s8tNHLO9aza X-Received: by 10.112.149.39 with SMTP id tx7mr3336972lbb.11.1441523950296; Sun, 06 Sep 2015 00:19:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.71 with SMTP id i7ls85620lai.11.gmail; Sun, 06 Sep 2015 00:19:10 -0700 (PDT) X-Received: by 10.112.11.163 with SMTP id r3mr11631838lbb.45.1441523949982; Sun, 06 Sep 2015 00:19:09 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id o2si7209925lah.162.2015.09.06.00.19.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 00:19:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbpo4 with SMTP id o4so27013516lbp.2 for ; Sun, 06 Sep 2015 00:19:09 -0700 (PDT) X-Received: by 10.112.146.135 with SMTP id tc7mr11887964lbb.35.1441523949881; Sun, 06 Sep 2015 00:19:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.164.42 with SMTP id yn10csp844757lbb; Sun, 6 Sep 2015 00:19:08 -0700 (PDT) X-Received: by 10.69.3.228 with SMTP id bz4mr30546743pbd.79.1441523948800; Sun, 06 Sep 2015 00:19:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v10si3005225pdr.170.2015.09.06.00.19.07; Sun, 06 Sep 2015 00:19:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752792AbbIFHTF (ORCPT + 28 others); Sun, 6 Sep 2015 03:19:05 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:7838 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751073AbbIFHPO (ORCPT ); Sun, 6 Sep 2015 03:15:14 -0400 Received: from 172.24.1.48 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.48]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUK94082; Sun, 06 Sep 2015 15:14:27 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Sun, 6 Sep 2015 15:14:18 +0800 From: Wang Nan To: , , , CC: , , , , , , , , , , , Subject: [PATCH 25/27] perf tools: Allow BPF program attach to uprobe events Date: Sun, 6 Sep 2015 07:13:41 +0000 Message-ID: <1441523623-152703-26-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1441523623-152703-1-git-send-email-wangnan0@huawei.com> References: <1441523623-152703-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch appends new syntax to BPF object section name to support probing at uprobe event. Now we can use BPF program like this: SEC( "target=/lib64/libc.so.6\n" "libcwrite=__write" ) int libcwrite(void *ctx) { return 1; } Where, in section name of a program, before the main config string, we can use 'key=value' style options. Now the only option key "target" is for uprobe probing. Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Cc: Arnaldo Carvalho de Melo Link: http://lkml.kernel.org/n/1436445342-1402-40-git-send-email-wangnan0@huawei.com --- tools/perf/util/bpf-loader.c | 88 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 67193d2..1b7742b 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -78,6 +78,84 @@ bpf_prog_priv__clear(struct bpf_program *prog __maybe_unused, } static int +do_config(const char *key, const char *value, + struct perf_probe_event *pev) +{ + pr_debug("config bpf program: %s=%s\n", key, value); + if (strcmp(key, "target") == 0) { + pev->uprobes = true; + pev->target = strdup(value); + return 0; + } + + pr_warning("BPF: WARNING: invalid config option in object: %s=%s\n", + key, value); + pr_warning("\tHint: Currently only valid option is 'target='\n"); + return 0; +} + +static const char * +parse_config_kvpair(const char *config_str, struct perf_probe_event *pev) +{ + char *text = strdup(config_str); + char *sep, *line; + const char *main_str = NULL; + int err = 0; + + if (!text) { + pr_debug("No enough memory: dup config_str failed\n"); + return NULL; + } + + line = text; + while ((sep = strchr(line, '\n'))) { + char *equ; + + *sep = '\0'; + equ = strchr(line, '='); + if (!equ) { + pr_warning("WARNING: invalid config in BPF object: %s\n", + line); + pr_warning("\tShould be 'key=value'.\n"); + goto nextline; + } + *equ = '\0'; + + err = do_config(line, equ + 1, pev); + if (err) + break; +nextline: + line = sep + 1; + } + + if (!err) + main_str = config_str + (line - text); + free(text); + + return main_str; +} + +static int +parse_config(const char *config_str, struct perf_probe_event *pev) +{ + const char *main_str; + int err; + + main_str = parse_config_kvpair(config_str, pev); + if (!main_str) + return -EINVAL; + + err = parse_perf_probe_command(main_str, pev); + if (err < 0) { + pr_debug("bpf: '%s' is not a valid config string\n", + config_str); + /* parse failed, don't need clear pev. */ + return -EINVAL; + } + return 0; +} + +static int config_bpf_program(struct bpf_program *prog, struct perf_probe_event *pev) { struct bpf_prog_priv *priv = NULL; @@ -91,13 +169,9 @@ config_bpf_program(struct bpf_program *prog, struct perf_probe_event *pev) } pr_debug("bpf: config program '%s'\n", config_str); - err = parse_perf_probe_command(config_str, pev); - if (err < 0) { - pr_debug("bpf: '%s' is not a valid config string\n", - config_str); - /* parse failed, don't need clear pev. */ - return -EINVAL; - } + err = parse_config(config_str, pev); + if (err) + return err; if (pev->group && strcmp(pev->group, PERF_BPF_PROBE_GROUP)) { pr_debug("bpf: '%s': group for event is set and not '%s'.\n",