From patchwork Wed Sep 23 11:22:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54044 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id 0680622E14 for ; Wed, 23 Sep 2015 11:26:35 +0000 (UTC) Received: by lagj9 with SMTP id j9sf21675565lag.0 for ; Wed, 23 Sep 2015 04:26:33 -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=bOX4s1yb8rAYT2QV5qv91gkstya7+GL9VhgE3xWdzto=; b=HzVOexdPMvGl4h5/jUU9SFsuZJWbLlFn+MsbEAiJXz1tq81mdNPSlQk0BKjWoeqMQy 45mQ1J3XOMzKKd5Ns/O4nXyBcSzQBy1zkoRKEoyyIZUe02Ugx+Q334RHaTpLK96NrQ+r VNvl2hRiV2thdzjOrEjJhV390y/VNVb5WR1gFhpWegldZbwwzfJLobwG1IJQSi0NHZc6 FnySI55E9JFT1R1X1REgPtLE8PVI7u9WPPg3Dwtin4Q+RVSrwrVxTw/IvQaw8cMxlDMb eQVBGhTdxesA0zbqUwkHEGiDa7WmXsYEwkMVRo08iV/S3lc9hnZv6eDv9socqfCAMHzj Wfkw== X-Gm-Message-State: ALoCoQkydKE95OaZg2yDm0kfu9LVVT8l3ehIk2Qs/Y9ZQkIBjmIY21s7N71wp5aEnd31AHDloTJ8 X-Received: by 10.112.78.101 with SMTP id a5mr5273435lbx.9.1443007593977; Wed, 23 Sep 2015 04:26:33 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.1 with SMTP id i1ls13367laf.105.gmail; Wed, 23 Sep 2015 04:26:33 -0700 (PDT) X-Received: by 10.25.17.149 with SMTP id 21mr3653714lfr.38.1443007593808; Wed, 23 Sep 2015 04:26:33 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id n7si1637823lbc.113.2015.09.23.04.26.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2015 04:26:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lagj9 with SMTP id j9so46409567lag.2 for ; Wed, 23 Sep 2015 04:26:33 -0700 (PDT) X-Received: by 10.152.18.167 with SMTP id x7mr764279lad.29.1443007593687; Wed, 23 Sep 2015 04:26:33 -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 w3csp1044638lbq; Wed, 23 Sep 2015 04:26:32 -0700 (PDT) X-Received: by 10.68.135.136 with SMTP id ps8mr37198248pbb.123.1443007592550; Wed, 23 Sep 2015 04:26:32 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pj2si9894263pbc.180.2015.09.23.04.26.32; Wed, 23 Sep 2015 04:26:32 -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 S1754743AbbIWL0a (ORCPT + 30 others); Wed, 23 Sep 2015 07:26:30 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:19575 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754448AbbIWLXq (ORCPT ); Wed, 23 Sep 2015 07:23:46 -0400 Received: from 172.24.1.47 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CTE39090; Wed, 23 Sep 2015 19:23:22 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Wed, 23 Sep 2015 19:23:13 +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 , Zefan Li Subject: [PATCH 19/22] perf tools: Allow BPF program attach to uprobe events Date: Wed, 23 Sep 2015 11:22:40 +0000 Message-ID: <1443007363-124182-20-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1443007363-124182-1-git-send-email-wangnan0@huawei.com> References: <1443007363-124182-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.215.48 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 8e9c882..9cc2822 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",