From patchwork Sat Aug 29 04:22:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 52830 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id A620720503 for ; Sat, 29 Aug 2015 04:25:18 +0000 (UTC) Received: by wicne3 with SMTP id ne3sf13852454wic.1 for ; Fri, 28 Aug 2015 21:25:18 -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=gtkbv5QiRX1p9kJg1GzXcG7v8ZLz0j05/hxA6WiiwBM=; b=BcTleh4yTh3ccqDU2+KgyYadOCRxe7aJ9otrnvGaOuRQrHOPHVn4yJkqpNQFzmqn3Q i1OZJqmptGE9mz3yZyvfYoAv9umtc0joP4O8DP5hym4rLWMdd1tvIEevpWJUNNqPjBRh NWYpzDnzYHIURlGEGgl/l4Z388wWiXA+hezm+ee6Woq2YH3x625JksRiyrj0m9tfEEZ1 xb7nJNTTuheszYVtvAPsgf1UXjwI64tnsQRBDhGPJuVtQTcUPTXnQbNngOJWBExZch37 zZJsELTVLMXxpY5K85tatUhwEyoCaBgnJbAs9Izh9e3E4SHrp1zuYGgptUPGBUFJcWXU Nmmg== X-Gm-Message-State: ALoCoQlIkDRCBuE2p19yBfQQ9CaCjju6oyH8H932RKOB9+BtKWhpvaYpmcPMAJaZg6f6U3lr2P1X X-Received: by 10.152.1.164 with SMTP id 4mr3623945lan.2.1440822317958; Fri, 28 Aug 2015 21:25:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.229 with SMTP id z5ls288966lal.8.gmail; Fri, 28 Aug 2015 21:25:17 -0700 (PDT) X-Received: by 10.112.161.232 with SMTP id xv8mr6202060lbb.123.1440822317669; Fri, 28 Aug 2015 21:25:17 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id le2si7650372lbc.154.2015.08.28.21.25.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Aug 2015 21:25:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbcbn3 with SMTP id bn3so39421388lbc.2 for ; Fri, 28 Aug 2015 21:25:17 -0700 (PDT) X-Received: by 10.112.125.34 with SMTP id mn2mr5100211lbb.76.1440822317512; Fri, 28 Aug 2015 21:25:17 -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.151.194 with SMTP id us2csp267837lbb; Fri, 28 Aug 2015 21:25:16 -0700 (PDT) X-Received: by 10.68.166.97 with SMTP id zf1mr20487299pbb.72.1440822316426; Fri, 28 Aug 2015 21:25:16 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id uw8si13345592pbc.16.2015.08.28.21.25.14; Fri, 28 Aug 2015 21:25:16 -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 S1752845AbbH2EYV (ORCPT + 28 others); Sat, 29 Aug 2015 00:24:21 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:3780 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752801AbbH2EYR (ORCPT ); Sat, 29 Aug 2015 00:24:17 -0400 Received: from 172.24.1.50 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.50]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BLW04322; Sat, 29 Aug 2015 12:23:33 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Sat, 29 Aug 2015 12:23:22 +0800 From: Wang Nan To: , , CC: , , , Wang Nan , Brendan Gregg , Daniel Borkmann , David Ahern , "He Kuang" , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Paul Mackerras , Peter Zijlstra Subject: [PATCH 29/31] perf tools: Support attach BPF program on uprobe events Date: Sat, 29 Aug 2015 04:22:03 +0000 Message-ID: <1440822125-52691-30-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1440822125-52691-1-git-send-email-wangnan0@huawei.com> References: <1440822125-52691-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.0A020202.55E133C5.00FE, 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: 3aa99de3e3094468dff93ab482a72158 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.170 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 a23aaf0..2735389 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -66,6 +66,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; @@ -79,13 +157,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",