From patchwork Wed Oct 14 12:41:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54926 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f70.google.com (mail-lf0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id 289C823012 for ; Wed, 14 Oct 2015 12:44:39 +0000 (UTC) Received: by lffy185 with SMTP id y185sf554015lff.2 for ; Wed, 14 Oct 2015 05:44:37 -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=D3Z48/POvvMpy7D8cRnPz7boXCJKRZQNkxVlzScC0k1oElX3bLsq6WqJ7QH5X44nIE YsaemaVbUqbNji8J59prcp+Kcs1AA0jwfzacLP0r1lPpiuOAEDGQ8dx37DlMADFZomLk VdeIa7cVlZTiOGJXPneupNJ7nBSKw9JQnJ7bfvCalkYzo8Q4XmdG1ZOwtR4OowZvT0OB yepyBOe6mteJQOMfMk0bTqfnmYb7e30k/HNSas6SaPvkwRN9CKIWqYodtYA6HfKOTIkA 9hNfR8LFb1ShbuXZX+7jUj5E1SbYRYhsv9zI4s+CWAci+E70306a7KoinABVB5ZPxQgH hkfQ== X-Gm-Message-State: ALoCoQntcmJEqxGctrLSRZWBkueiB4o4cQmTkSYqLwkMDcRMmWWaf35xn0VktWz3JSaZl5xjW4B9 X-Received: by 10.112.132.10 with SMTP id oq10mr724449lbb.1.1444826677669; Wed, 14 Oct 2015 05:44:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.156.78 with SMTP id f75ls35990lfe.69.gmail; Wed, 14 Oct 2015 05:44:37 -0700 (PDT) X-Received: by 10.112.234.199 with SMTP id ug7mr1525656lbc.116.1444826677498; Wed, 14 Oct 2015 05:44:37 -0700 (PDT) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id d196si5418056lfe.175.2015.10.14.05.44.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 05:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by lfeh64 with SMTP id h64so10640488lfe.3 for ; Wed, 14 Oct 2015 05:44:37 -0700 (PDT) X-Received: by 10.25.28.81 with SMTP id c78mr978711lfc.29.1444826677325; Wed, 14 Oct 2015 05:44:37 -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 w3csp2710534lbq; Wed, 14 Oct 2015 05:44:36 -0700 (PDT) X-Received: by 10.66.227.230 with SMTP id sd6mr3592569pac.60.1444826676191; Wed, 14 Oct 2015 05:44:36 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qp7si13063985pbc.93.2015.10.14.05.44.35; Wed, 14 Oct 2015 05:44:36 -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 S932255AbbJNMoe (ORCPT + 30 others); Wed, 14 Oct 2015 08:44:34 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:50476 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753672AbbJNMnG (ORCPT ); Wed, 14 Oct 2015 08:43:06 -0400 Received: from 172.24.1.48 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.48]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CWT05966; Wed, 14 Oct 2015 20:42:38 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Wed, 14 Oct 2015 20:42:28 +0800 From: Wang Nan To: , , CC: , , , , , , , , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [PATCH 20/31] perf tools: Allow BPF program attach to uprobe events Date: Wed, 14 Oct 2015 12:41:31 +0000 Message-ID: <1444826502-49291-21-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> References: <1444826502-49291-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.44 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",