From patchwork Wed Dec 23 06:39:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11987751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E115EC433DB for ; Wed, 23 Dec 2020 06:41:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 732B220771 for ; Wed, 23 Dec 2020 06:41:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 732B220771 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6SziU8hvDBCqDLmPuvI8ILKIoiCRU4g2naRDIhvVkcc=; b=X0Wf4//VjfF37PbBHbKFn5fk8y HSCfn0UobjxCXYpXGImeTL3zjBVXazcS2lzNhRfUVDW/jh6YnQefa4mchhZegUrWO3mw05JCYk5nw c4ctcHP/7I/ykrFWr6gbaOLMU8mMXAQq7LRE2U63qvD2HDGBd/aHCCsIEmM+/mFJqSn2z5c9tDG0M Y8r76UsnHJfKUIbtXgbHnUeMUmWYExlxWPSUFxg/HQWoRp9GzTwjVQZwz7M/txnhgh57cud+ug4mw pDNRzffiORJaDWdvNqxn/nIkF67ynk9FaCnVhKvo5TOV/yWiD/6/mH5pErxb1LdIiXeZmluCVSlHl jL0tSysQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1krxoZ-0007wG-SF; Wed, 23 Dec 2020 06:40:03 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1krxoS-0007rg-Jm for linux-arm-kernel@lists.infradead.org; Wed, 23 Dec 2020 06:39:57 +0000 Received: by mail-pl1-x62a.google.com with SMTP id 4so8646385plk.5 for ; Tue, 22 Dec 2020 22:39:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J6uJ+kErWklNE/7gO57BMrhqrOWmHLQYq2mwzGxfa8Y=; b=PNLk4qHQtyvRwY/OmJ+vez7yBo96Xg4JAC2HxGo9NwlQ7I7yJ1JvpiPKQ4IERJQYTq FEKC9ejA3T56V0ynXpcGwnPjQoxBZMgP8OOFS709tcheaKJLa2bkXGmJetgp9wrrsXqA AbyoF8CEs2hP33xV7O4Ui0KkSIVPhp88FfOgHPm61IEonKSw5FmV5+WoPaebtXlHUoW5 3DUoV7keG4zFcuCwqy76gtOE13KzxP02eCX/Bf8KZ7uQQ00m3DGeqFNuXmHdWL1pmMmr NyMiQV9L2VtAc7kfQRBwHHUVZ6ATalnRBM+GwL2Fz6pbqOpd4I7e0EPvIKRyKZwYlMMl bTnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=J6uJ+kErWklNE/7gO57BMrhqrOWmHLQYq2mwzGxfa8Y=; b=DDIYLIp7zF4V8w5HE1J0nxwAm8a0pt+p4lyxM/vyBq16QuD7tOljW3+Mkm+cmyvY8r SRb3pU5wnvyVPuQB3976Z09CJuf2ZUWzw0cXjSyCHmFV6a3HoMxR/E3Wa6vKKWYs38Sa 2rB5VfkohqdHNxGRpmYu/L8wNrmfe4n2My23a66O8G5U43vUQVO+GL3hT1oB/gsHLpcU K9RK4Ox8SjlO2GCCweLLZTaUoicAWzZvr24P7z6nyfYf21XH1oGuMmac2ecvhVSmHIUM WI/mKr3DbsX6DoLH+XZZGRH507vrUzkKCXm6JSAs580E39E6uxnSVfuqUtg1Xq2ufJZt DJTQ== X-Gm-Message-State: AOAM530YFbPGveOSe8CvIomUyjmjfN1SNixbmt1tNL6eIP7shT2DaaaN 8fViWt9HbLyxEvmUKve8a3CCWg== X-Google-Smtp-Source: ABdhPJwLdksuy3q/3B3+z2o6Vs3HiUJbLNYvWdNYiZ8lQF+JtLu0b2vU22cVoQnvbRHfayRlCXV3AQ== X-Received: by 2002:a17:90b:1213:: with SMTP id gl19mr25581931pjb.232.1608705594570; Tue, 22 Dec 2020 22:39:54 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id n4sm22242926pfu.150.2020.12.22.22.39.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Dec 2020 22:39:54 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Will Deacon , John Garry , Mathieu Poirier , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Alexandre Truong , Masami Hiramatsu , He Zhe , Thomas Richter , Sumanth Korikkar , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] perf probe: Fixup Arm64 SDT arguments Date: Wed, 23 Dec 2020 14:39:04 +0800 Message-Id: <20201223063905.25784-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201223063905.25784-1-leo.yan@linaro.org> References: <20201223063905.25784-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201223_013956_696413_5E12922C X-CRM114-Status: GOOD ( 20.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Arm64 ELF section '.note.stapsdt' uses string format "-4@[sp, NUM]" if the probe is to access data in stack, e.g. below is an example for dumping Arm64 ELF file and shows the argument format: Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4] Comparing against other archs' argument format, Arm64's argument introduces an extra space character in the middle of square brackets, due to argv_split() uses space as splitter, the argument is wrongly divided into two items. To support Arm64 SDT, this patch fixes up for this case, if any item contains sub string "[sp", concatenates the two continuous items. And adds the detailed explaination in comment. Signed-off-by: Leo Yan --- tools/perf/util/probe-file.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index 064b63a6a3f3..60878c859e60 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -794,6 +794,8 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, char *ret = NULL, **args; int i, args_count, err; unsigned long long ref_ctr_offset; + char *arg; + int arg_idx = 0; if (strbuf_init(&buf, 32) < 0) return NULL; @@ -815,8 +817,34 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, if (note->args) { args = argv_split(note->args, &args_count); - for (i = 0; i < args_count; ++i) { - if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) + for (i = 0; i < args_count; ) { + /* + * FIXUP: Arm64 ELF section '.note.stapsdt' uses string + * format "-4@[sp, NUM]" if a probe is to access data in + * the stack, e.g. below is an example for the SDT + * Arguments: + * + * Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4] + * + * Since the string introduces an extra space character + * in the middle of square brackets, the argument is + * divided into two items. Fixup for this case, if an + * item contains sub string "[sp,", need to concatenate + * the two items. + */ + if (strstr(args[i], "[sp,") && (i+1) < args_count) { + arg = strcat(args[i], args[i+1]); + i += 2; + } else { + arg = strdup(args[i]); + i += 1; + } + + err = synthesize_sdt_probe_arg(&buf, arg_idx, arg); + free(arg); + arg_idx++; + + if (err < 0) goto error; } } From patchwork Wed Dec 23 06:39:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11987755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 971B3C433E0 for ; Wed, 23 Dec 2020 06:41:21 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 31E4120771 for ; Wed, 23 Dec 2020 06:41:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31E4120771 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KGSwdCtTKzP4hrf4dtUdQZ4LUfDJKHMnCDUFjQuE/Ys=; b=OwTj013pIeBrx4VlyKpbX2gZhx we99EwB7iz+Iw4Ew8gbrU1tLZSXcnaA/6JOd7Uw4M33sVPmNMkVMf2Ci6uJPkqYjEZZk4YGCIQTpX HtRQ4aU0UEeb41NlLCyFTDVKrbMyYW4h0f4S/AAAsULNbTeKq1RnyWKC+kCdoFq7oWbybgoXYcOWf qw4OGb1gekdOjsAsblqJ98pLoaktUPtSvNe26TJMjHUk+igsfayM2xJQ5Es5WG6jtwJm7ONkBld6v QBrSL2StnxUtRg+AFRYnSoPS7k69GesHr9Mfylnbu+vAQEjNdTw9UjMpXaxSvRYCC36jvxkkdr2Sy zZU3qTAQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1krxoc-0007wg-75; Wed, 23 Dec 2020 06:40:06 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1krxoW-0007td-7h for linux-arm-kernel@lists.infradead.org; Wed, 23 Dec 2020 06:40:02 +0000 Received: by mail-pj1-x1031.google.com with SMTP id lj6so2526096pjb.0 for ; Tue, 22 Dec 2020 22:39:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=467lFgAtQsgtCwBZ9cW2L8IHsN+b1oJWtlD6IzgSFFI=; b=d446zeA4uH4Y0+x1O/BSppDYUxhtb4x78BQy3xs5EDDCtPXSh52bztqT5GIQZkXVHD xuVbJckUmaSYlS/CyspydhE6GI43ARrWGBXGmnZf8FA68nvi/vPlwJ1DqkVk/rdyWlQ6 nKiyCNdzR+KMe7yLAtOHF6ZtLCxWW+AAkWK9ZiutTajOwvKtrao6T/2pM12psw7WzSm+ Xquy8qyKaoVf1rlWuCG3sit+gTYJTRZQxBhDIxbuu9yCThsETHBSdFnjtME5JwcDREx7 7WWqij9dekWvUFsiidbDV9toS/0lsl1vExeXDw/Eo/E5tz4q8nfVbd2wM36kD4Kuy7Ro 300Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=467lFgAtQsgtCwBZ9cW2L8IHsN+b1oJWtlD6IzgSFFI=; b=hHzh/iPW6bl8/5T3ucTt9tfUu2dsDEzb4YWqJthNH79d0Xz+ktmdXp9480FehII9li TOO+9lQxWcUwTzCVpOWXGY1Cm61+69oXGJuV+QfJQlPXSAXViPmdIGFAwDzxh8DQq+7C IXzRG0bGTlPjq4eLUGMkaljZ/omijwOZX4sPWNrHEl49+Y4Pd0PDs4qKDYUxTLZtT120 /mS+odSyTCo22K9t1JCiT2KVm8rzoNduzJv2FB26LK0sp5nDjGXiklpjEvV1Mh73wLSL TvG80I+hU5nRl4dUluNV7yE+zKR3IDknLOWax397Ps4IazWnVJj1qMpotRzCAtqZTjDO x+9w== X-Gm-Message-State: AOAM533tr910gdK5ha0XPBtbO+0FWAos4lXvxTSL0guf3IV5DojFQCK2 E4ERmytcJZbuiLAa2wdVlM9hlg== X-Google-Smtp-Source: ABdhPJwzDH6uuTjVup7Xb65qTxOPldy6fSUD2MrRS5KkW93S9TDqr9xamcozg8/9O3NB277Gs3DboQ== X-Received: by 2002:a17:90a:1b0d:: with SMTP id q13mr24721470pjq.21.1608705597984; Tue, 22 Dec 2020 22:39:57 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id x12sm22519430pgf.13.2020.12.22.22.39.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Dec 2020 22:39:57 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Will Deacon , John Garry , Mathieu Poirier , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Alexandre Truong , Masami Hiramatsu , He Zhe , Thomas Richter , Sumanth Korikkar , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] perf arm64: Add argument support for SDT Date: Wed, 23 Dec 2020 14:39:05 +0800 Message-Id: <20201223063905.25784-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201223063905.25784-1-leo.yan@linaro.org> References: <20201223063905.25784-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201223_014000_349082_A6EA4513 X-CRM114-Status: GOOD ( 20.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Now the two OP formats are used for SDT marker argument in Arm64 ELF, one format is genreal register xNUM (e.g. x1, x2, etc), another is for using stack pointer to access local variables (e.g. [sp], [sp, 8]). This patch adds support SDT marker argument for Arm64, it parses OP and converts to uprobe compatible format. Signed-off-by: Leo Yan --- tools/perf/arch/arm64/util/perf_regs.c | 94 ++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tools/perf/arch/arm64/util/perf_regs.c b/tools/perf/arch/arm64/util/perf_regs.c index 54efa12fdbea..6b4b18283041 100644 --- a/tools/perf/arch/arm64/util/perf_regs.c +++ b/tools/perf/arch/arm64/util/perf_regs.c @@ -1,4 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include + +#include "../../../util/debug.h" +#include "../../../util/event.h" #include "../../../util/perf_regs.h" const struct sample_reg sample_reg_masks[] = { @@ -37,3 +45,89 @@ const struct sample_reg sample_reg_masks[] = { SMPL_REG(pc, PERF_REG_ARM64_PC), SMPL_REG_END }; + +/* %xNUM */ +#define SDT_OP_REGEX1 "^(x[1-2]?[0-9]|3[0-1])$" + +/* [sp], [sp, NUM] or [sp,NUM] */ +#define SDT_OP_REGEX2 "^\\[sp(, *)?([0-9]+)?\\]$" + +static regex_t sdt_op_regex1, sdt_op_regex2; + +static int sdt_init_op_regex(void) +{ + static int initialized; + int ret = 0; + + if (initialized) + return 0; + + ret = regcomp(&sdt_op_regex1, SDT_OP_REGEX1, REG_EXTENDED); + if (ret) + goto error; + + ret = regcomp(&sdt_op_regex2, SDT_OP_REGEX2, REG_EXTENDED); + if (ret) + goto free_regex1; + + initialized = 1; + return 0; + +free_regex1: + regfree(&sdt_op_regex1); +error: + pr_debug4("Regex compilation error.\n"); + return ret; +} + +/* + * SDT marker arguments on Arm64 uses %xREG or [sp, NUM], currently + * support these two formats. + */ +int arch_sdt_arg_parse_op(char *old_op, char **new_op) +{ + int ret, new_len; + regmatch_t rm[5]; + + ret = sdt_init_op_regex(); + if (ret < 0) + return ret; + + if (!regexec(&sdt_op_regex1, old_op, 3, rm, 0)) { + /* Extract xNUM */ + new_len = 2; /* % NULL */ + new_len += (int)(rm[1].rm_eo - rm[1].rm_so); + + *new_op = zalloc(new_len); + if (!*new_op) + return -ENOMEM; + + scnprintf(*new_op, new_len, "%%%.*s", + (int)(rm[1].rm_eo - rm[1].rm_so), old_op + rm[1].rm_so); + } else if (!regexec(&sdt_op_regex2, old_op, 5, rm, 0)) { + /* [sp], [sp, NUM] or [sp,NUM] */ + new_len = 7; /* + ( % s p ) NULL */ + + /* If the arugment is [sp], need to fill offset '0' */ + if (rm[2].rm_so == -1) + new_len += 1; + else + new_len += (int)(rm[2].rm_eo - rm[2].rm_so); + + *new_op = zalloc(new_len); + if (!*new_op) + return -ENOMEM; + + if (rm[2].rm_so == -1) + scnprintf(*new_op, new_len, "+0(%%sp)"); + else + scnprintf(*new_op, new_len, "+%.*s(%%sp)", + (int)(rm[2].rm_eo - rm[2].rm_so), + old_op + rm[2].rm_so); + } else { + pr_debug4("Skipping unsupported SDT argument: %s\n", old_op); + return SDT_ARG_SKIP; + } + + return SDT_ARG_VALID; +}