From patchwork Fri Dec 25 05:27:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11989817 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 211D5C433DB for ; Fri, 25 Dec 2020 05:29:31 +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 D1C3C22AAA for ; Fri, 25 Dec 2020 05:29:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1C3C22AAA 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=gquFPDwDtJbHBVO/lSPjnBkvFxIZsbDWw+q+B+sLwBo=; b=nSPKfp7AqvH1mxkQXUA9ul2vgt M725Pz8ELBIPNqOTQaZ0qkcNQFxU7Jb36vnXq9HdaCnvZfkNuAJCMede0PLjx5oi4a4PwcGSrCE8F tFAVP5VD8Rj4SlJl62Up74aH8OZmJfi90T9qExGQ+h0TrdQcwWqeu70nnW7SS8n4dE15MeqJGQmSn ECyR75UJRD0R7PaRxQm4IIkLC89Mmod6lDw9Fi8zmlGSS0rkcFiERh/iwX7Va3CiFjKclJ66KSSP/ R6pQ86xhqYAVdHfMjf+vhrzq/MvJ8KzIzPK+yMLTAXRd8WV9LK9JqeeS8m7YN62PIJo/auJ3D5T8B A8VP/sKA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ksfeB-00055k-8n; Fri, 25 Dec 2020 05:28:15 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ksfe5-0004zE-1Q for linux-arm-kernel@lists.infradead.org; Fri, 25 Dec 2020 05:28:11 +0000 Received: by mail-pf1-x429.google.com with SMTP id t22so2155579pfl.3 for ; Thu, 24 Dec 2020 21:28:08 -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=fggFNHkIm4LYrEAhkgghWWYvuA1sVNNnoLCFYuyGlq0=; b=kEN7zSRi+7riSkXhcZrU8TJWQ4DnunTjyGXKsR69nYEFYNq64ohC72qdjFnHuXBBhC y9REVFiXQvPsL4WT62tXjdG5TZbFfQ5JFtRrN078rt8NzJ/v/z73Z70RYBj60V5fM6IR 2Ipq89qwjypEeyT92GO2qgvF0tobYN3uu4bGeyQHOWXpT4kN3mg0AA2/Edmt//bL8JaM jJ4P7b5tmFsz2GCc/ImFJyv+ts+nQm7jPrAyk/TQ11nLu4TyaFMycOL1Nrnu3Yw/YErp 0B7b6IRQRtKIWwN9Ql17vWPXVnEjn2HFGEnStKxReFEmDIHCXFMnfFJ0AQiLRNm11VbM fODg== 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=fggFNHkIm4LYrEAhkgghWWYvuA1sVNNnoLCFYuyGlq0=; b=QxhDwEH/gmu+YT3zvDU2NESET5wLLHZU9e94FMSUmvyVtzfUw4y7ng/XedrgLWj1b5 dRgYbT6LnzZjvvk97ysoalxrqA7q5vRkEtwm2pma7axhE2MEHX6DaND0V9tKO1SZ5+gf 0CpI7AFSwqEx3j4LxHiz2RbZuDGowH2h0W3wX/ZWhhCP3+AXYg0MrW/hYRyYGKzsjPp5 fIDS/I4hqJWsT/3x3inw3T59johJuyXPzM4s9aCIXOya6EUmeV9K1jDf5Dy3cZyrXrAv QIlmNSoZZQCvl2ZcCp20H8O4BsFzDB19ZqS4xBJV5aSOeO2mjwAm8o3e11OlvyQ4l02O JqtA== X-Gm-Message-State: AOAM532K0MMkyQuWxTDjvisbTUzPrhnmzngHErc87gWNQWGHt8sjSgFl B7ZaVqbCg5pDRaKrEVcclkcVvQ== X-Google-Smtp-Source: ABdhPJxH3HZ5HXhbr/CHl5MUe98jSpKJsDIbtdnv3P2YMkrXMNZCm+tx78RxEj+4EoNtjQ8SOVcwyA== X-Received: by 2002:aa7:9ab7:0:b029:19d:ac89:39aa with SMTP id x23-20020aa79ab70000b029019dac8939aamr30486597pfi.10.1608874086935; Thu, 24 Dec 2020 21:28:06 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id g85sm28526152pfb.4.2020.12.24.21.28.06 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Dec 2020 21:28:06 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , John Garry , Will Deacon , Mathieu Poirier , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexandre Truong , Ian Rogers , Thomas Richter , He Zhe , Sumanth Korikkar , Alexis Berlemont , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] perf probe: Fix memory leak in synthesize_sdt_probe_command() Date: Fri, 25 Dec 2020 13:27:49 +0800 Message-Id: <20201225052751.24513-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201225052751.24513-1-leo.yan@linaro.org> References: <20201225052751.24513-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201225_002809_199209_F9D0354F X-CRM114-Status: GOOD ( 16.40 ) 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: Arnaldo Carvalho de Melo , stable@vger.kernel.org, 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 From: Arnaldo Carvalho de Melo In synthesize_sdt_probe_command(), it gets argument array from argv_split() but forgets to free it. This patch calls argv_free() to free the argument array to avoid memory leak. Fixes: 3b1f8311f696 ("perf probe: Add sdt probes arguments into the uprobe cmd string") Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Leo Yan Cc: stable@vger.kernel.org --- tools/perf/util/probe-file.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index 064b63a6a3f3..bbecb449ea94 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -791,7 +791,7 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, const char *sdtgrp) { struct strbuf buf; - char *ret = NULL, **args; + char *ret = NULL; int i, args_count, err; unsigned long long ref_ctr_offset; @@ -813,12 +813,19 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, goto out; if (note->args) { - args = argv_split(note->args, &args_count); + char **args = argv_split(note->args, &args_count); + + if (args == NULL) + goto error; for (i = 0; i < args_count; ++i) { - if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) + if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) { + argv_free(args); goto error; + } } + + argv_free(args); } out: From patchwork Fri Dec 25 05:27:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11989819 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 8AF44C433DB for ; Fri, 25 Dec 2020 05:29:33 +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 4989C22AAA for ; Fri, 25 Dec 2020 05:29:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4989C22AAA 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=WoWitmLqW4SXmJIhn21MPbI+vksXsuJTpWuZAj7wIyM=; b=yyBSYzywS0bPoHFSXSF121uSLI PR7WmEosmJDH+oPCPjGRnYkhuBoohpiWXGHKdhS4jigmalkWvB3p+zAbcBUAX0Y11Y57SyFLWqyxw ZxnZPQaz1S9Xgv+2g7HuatZrrHP54NQcmHtF660/P+hRA5HhgFy+m1Yov+GolMMdstSF0qPtFiZFB 3k1aQm1EWRm0cyUA8XBIpr7Uicp/u+COVtgjU7eqmrHrd54UgixE1RStqjkC5QK6A+2S3TvPtTXD0 0fFEnCNO9lQYeTCcOTFkoTGiSYQDDKNX9mQrd63gjeguyxilQDlgpplNVdPBBzT37W9SqYW+p5RT+ ustKUgIA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ksfeE-00056R-9p; Fri, 25 Dec 2020 05:28:19 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ksfe8-00050V-Ge for linux-arm-kernel@lists.infradead.org; Fri, 25 Dec 2020 05:28:14 +0000 Received: by mail-pj1-x102d.google.com with SMTP id iq13so2005202pjb.3 for ; Thu, 24 Dec 2020 21:28:12 -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=HfQeMTR9dHIFoLebfafxegiW3US03+p5EYWEz17ILko=; b=HvswmbMDL5uxqB0KAbPcLNnn+5vuDGciqdkPp8cLLiFowOTsnt2IpO66ZQq3/eFtND 9RAVODop0575vtynRDfV8yk0g2eoRiSMLPj7ACMw9U86P6k45SkXO955Wb9FyxMwrGjm Qn6Z5WJWYHuzASpFJfIae3mF3TpQAbrYn1Uls/Dqd8LZh1JF4MRI0PuGZXpx+sLnhBN/ n6vF2LUWpKWeTQAyXzAdaRYFymypMBc62kUu2uC6P1O+w4L56GkLs5452qAg6Ieji8dO nZYNdetwUmuFNUpdE6q8tWL9ShTWWI+6Ossq+vMHxbSJgjXV/nW3GoElhbUKFamCpF4N dfZQ== 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=HfQeMTR9dHIFoLebfafxegiW3US03+p5EYWEz17ILko=; b=RWOcHmoOehMdOFBkK3iqJFvn4y38R0FNtJCZOD4Qf88M4y926s4h6XYpMMbUiAj4Ru f+miS+b4VMnvQWnkC/04X6UEAUjqrrJgdwLonZQlO7xv2Z/GGlGaUM6+/XeAqx3jKhSr kQzZoSObFK3R3kYOtCH2Wsos3yEe+8rCIB9NHrMUhHkOwUncjVL1Y1HSbr4LdvHoC62K yWSzW0ZgzX5p/4UNWEpvBr5yF5vwriejcahDzF9jjeSyAkTcNDYUzJfk+zP4RUGUjGLi Rh+Tu1vsJXbhF5TTG5RqdKmtcJPpv41qK22B/2V7CuJBPoryjKEJys/2SFnRK4hxY/eS svTw== X-Gm-Message-State: AOAM533EVyMuEtVFJoMuwHI+gpJ8KivLWng4na/d+5uitsKLJRrD7NZI 9yRx/cdvY573G2l+84HS2Hy8fA== X-Google-Smtp-Source: ABdhPJxa4v8+ZEPmtpingASgL6mL9hIJ/HsSt0yN+89oa3vDVZanYG1LKPFxrCXADzFZ98phXDi9mA== X-Received: by 2002:a17:90b:8d8:: with SMTP id ds24mr7246522pjb.134.1608874090429; Thu, 24 Dec 2020 21:28:10 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id f15sm4156167pju.49.2020.12.24.21.28.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Dec 2020 21:28:09 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , John Garry , Will Deacon , Mathieu Poirier , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexandre Truong , Ian Rogers , Thomas Richter , He Zhe , Sumanth Korikkar , Alexis Berlemont , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] perf probe: Fixup Arm64 SDT arguments Date: Fri, 25 Dec 2020 13:27:50 +0800 Message-Id: <20201225052751.24513-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201225052751.24513-1-leo.yan@linaro.org> References: <20201225052751.24513-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201225_002812_611307_A7006168 X-CRM114-Status: GOOD ( 21.46 ) 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 | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index bbecb449ea94..52273542e6ef 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; 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; @@ -818,11 +820,43 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, if (args == NULL) goto error; - 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) { + err = asprintf(&arg, "%s %s", args[i], args[i+1]); + i += 2; + } else { + err = asprintf(&arg, "%s", args[i]); + i += 1; + } + + /* Failed to allocate memory */ + if (err < 0) { argv_free(args); goto error; } + + if (synthesize_sdt_probe_arg(&buf, arg_idx, arg) < 0) { + free(arg); + argv_free(args); + goto error; + } + + free(arg); + arg_idx++; } argv_free(args); From patchwork Fri Dec 25 05:27:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11989821 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 27161C433E0 for ; Fri, 25 Dec 2020 05:29:38 +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 DFC9522AAA for ; Fri, 25 Dec 2020 05:29:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFC9522AAA 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=ygPREeWV/k1idLdmwwzw8vRBQUUkWdYUI6DXDzlCwiY=; b=WACMOuBq4d5eS2r0/cV5cDi93X /tBLHBZOCaaaMIi0aNAQOMRBdSb3uqTuEBU6/2sUjnyEuP8e4cr27WnKeyUAwiL8IG/vq2L3IgNtA 8hrOzfMbU6N637qEexbugXolsZtr8gNJ59a/WfsEl3MQh2dw0iI1PIdjqw/2TRfxOtZbog8CYXj4B SiBp4oQWIPI5Acagx1n+hMQcgYnN3Vrb3UQdFrQ6xe/uZg8nZiSMfcV+tXgt5wWQgqvkSKw7V0km8 NC+VzgfbxMbRiP0Egkw5EG/D7k66NA9Py/z62lVIHV/jicrhwFtHdYoQlcztCPpX0p75mB2YG53xc X81w4N6w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ksfeM-0005Br-Mj; Fri, 25 Dec 2020 05:28:26 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ksfeC-00054u-1u for linux-arm-kernel@lists.infradead.org; Fri, 25 Dec 2020 05:28:18 +0000 Received: by mail-pg1-x530.google.com with SMTP id n25so2687343pgb.0 for ; Thu, 24 Dec 2020 21:28:15 -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=QxEw73aH8htDNc2tPH/epFrL2eOdsg6Hp+cPBazlzqE=; b=BhA2tHDLnHDPPgpjtgASdT3Z6FwgjaCYNFHye6ROWmX8IpKNd+66sfLwRoMSGUAR6Z D/mpTUIIsu4aC6DaBVTsWkP8/Vb7nBiKTcdz286Qs4w11XfFTQh+h8hgJBjyOgWW7pfs n6c8pFULCW0aBQWnUAK1KOFfBDlELmjr7bDovUpF2QmNk5LhJ82JC6KUC6ss7le7qzw0 FMZwZMotPWVvRE6p+8FNoXSpYe6EpqQBWmFupZI4ypo1tMf1I3R6CuoxgnYGxjb+cTbM wWgxqFc4XhKpFcREb2KyWUGvBhTz1ue+L0/aUFIV/zSBQkMCbKn4A4rXDaGwrtY4IJVf k32Q== 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=QxEw73aH8htDNc2tPH/epFrL2eOdsg6Hp+cPBazlzqE=; b=ghPE8eYD+vxVLjmvMBCXBZFmCPAu8bNv23sv2sQzZXLYaaaoXq4SXf9YObHsQysaN5 H1cDA4CuevmRcdzWct9gFneNwtJ4o/5SP1sR+x42+bDtDxp7oMkv6Ghu4nzrhqPTbiNj 7CfAnHdf6jpFX6vI0N+PhF88Fp7VVx2OkYCnkTya3rjOo+cMoUX77ZuDDE0pOLDX6CmG +3pJV4O5JsaLec9iqDBYP3N+DqZoDgVYU1QJmoQWRNetI7Oai+B8SxGdLv5n+BEcolWZ JMzDQTZBxykGM+0uMrh0SHRUWpLnoopfrXJ8GErwxpw4IfNVa2HdVuc+8mydNnnBMqYI /r8w== X-Gm-Message-State: AOAM533+sv1SPmkOENJWk1C/whLLKb+BuYQAXl1VHFEHZtDgMGUqP8/K G61ExKidSs/S9i9GdgB1ycg88g== X-Google-Smtp-Source: ABdhPJzFrfFhDXrOAD8lhm8vjoUNQDaoWG/S0zkZlpElQjhLJdBlklM7vJDWIGGuCqZfZ0bc+fvz/w== X-Received: by 2002:a63:da4e:: with SMTP id l14mr13737064pgj.248.1608874093876; Thu, 24 Dec 2020 21:28:13 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id l11sm29184800pgt.79.2020.12.24.21.28.12 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Dec 2020 21:28:13 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , John Garry , Will Deacon , Mathieu Poirier , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexandre Truong , Ian Rogers , Thomas Richter , He Zhe , Sumanth Korikkar , Alexis Berlemont , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] perf arm64: Add argument support for SDT Date: Fri, 25 Dec 2020 13:27:51 +0800 Message-Id: <20201225052751.24513-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201225052751.24513-1-leo.yan@linaro.org> References: <20201225052751.24513-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201225_002816_137292_E832B9AC X-CRM114-Status: GOOD ( 21.01 ) 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 general 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 Acked-by: Masami Hiramatsu --- 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..2518cde18b34 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] */ +#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; +}