From patchwork Thu Oct 8 08:29:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54638 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 5914722FF8 for ; Thu, 8 Oct 2015 08:38:13 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf19959448lbb.3 for ; Thu, 08 Oct 2015 01:38:12 -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=PpxSajoucWwIFFTx7IDejk1bfH0+Spsea0y4efSsshc=; b=GLd9jW2mhdJzZ+weI4DhK/UmJSBFbHVlXQc6JYd2PGBYZIGWwDEe/1J7qf8eRtfdL2 pWakvYjd9OrMovlgppdAfTUWqOpNZTnk6oMivMOFnYFhpJ55605Xqi1mo0QEL+YCu+z+ ojvT0L6iPl7WFzvzaL4qjFrS8f5CkzVbgN71dtaBtRD0498WwqlK8svfMAsapptMk/pA mmJhwGL/RNHhbGdU4PIwB4/Axl+9GKn+ZjbQfvcRudMO+x9fDti0U4SlfT/N7btDg9ZE 4fy0H0jjyckS4YnPnrdLxKoC0KfZr7UhI1E7K+vkMYfU80CrTyY6AgSpsoSFS9tUexK0 mqCw== X-Gm-Message-State: ALoCoQkp7rnivClD1JQop5zVHCVGMcAMir5eNcCnD1L/mlPx2RVl19USRj6WXbDSyryANC14bPJG X-Received: by 10.180.208.7 with SMTP id ma7mr433322wic.5.1444293492335; Thu, 08 Oct 2015 01:38:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.163.194 with SMTP id m185ls166387lfe.66.gmail; Thu, 08 Oct 2015 01:38:12 -0700 (PDT) X-Received: by 10.25.166.139 with SMTP id p133mr1904488lfe.51.1444293492077; Thu, 08 Oct 2015 01:38:12 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id yk9si28793238lbb.107.2015.10.08.01.38.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2015 01:38:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbos8 with SMTP id s8so38357200lbo.0 for ; Thu, 08 Oct 2015 01:38:12 -0700 (PDT) X-Received: by 10.25.86.213 with SMTP id k204mr1941970lfb.36.1444293491916; Thu, 08 Oct 2015 01:38:11 -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.59.35 with SMTP id w3csp440904lbq; Thu, 8 Oct 2015 01:38:10 -0700 (PDT) X-Received: by 10.68.68.133 with SMTP id w5mr6666453pbt.143.1444293490726; Thu, 08 Oct 2015 01:38:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id de10si64742809pad.66.2015.10.08.01.38.10; Thu, 08 Oct 2015 01:38:10 -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 S1754648AbbJHIiD (ORCPT + 30 others); Thu, 8 Oct 2015 04:38:03 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:54827 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754279AbbJHIh6 (ORCPT ); Thu, 8 Oct 2015 04:37:58 -0400 Received: from 172.24.1.49 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.49]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BOO15961; Thu, 08 Oct 2015 16:30:51 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Thu, 8 Oct 2015 16:29:44 +0800 From: Wang Nan To: CC: , , , Wang Nan , Alexei Starovoitov , Brendan Gregg , Daniel Borkmann , David Ahern , He Kuang , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Paul Mackerras , Peter Zijlstra Subject: [PATCH 20/22] perf tools: Allow BPF program attach to uprobe events Date: Thu, 8 Oct 2015 08:29:42 +0000 Message-ID: <1444292984-13135-21-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444292984-13135-1-git-send-email-wangnan0@huawei.com> References: <1444292984-13135-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.56162A84.0182, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 5e7db3ed12d0982eeb295ead39dcb1c6 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.180 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/ebpf-6yw9eg0ej3l4jnqhinngkw86@git.kernel.org --- tools/perf/util/bpf-loader.c | 86 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index af549ea..73ff9a9 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -111,6 +111,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 = NULL; @@ -132,13 +210,9 @@ config_bpf_program(struct bpf_program *prog) pev = &priv->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); - err = -EINVAL; + err = parse_config(config_str, pev); + if (err) goto errout; - } if (pev->group && strcmp(pev->group, PERF_BPF_PROBE_GROUP)) { pr_debug("bpf: '%s': group for event is set and not '%s'.\n",