From patchwork Wed Nov 18 06:43:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 56915 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2383157lbb; Tue, 17 Nov 2015 22:48:03 -0800 (PST) X-Received: by 10.68.204.226 with SMTP id lb2mr69058887pbc.151.1447829272261; Tue, 17 Nov 2015 22:47:52 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id to8si2237550pab.76.2015.11.17.22.47.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Nov 2015 22:47:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZywVT-0005Aj-UV; Wed, 18 Nov 2015 06:46:15 +0000 Received: from mail-pa0-x235.google.com ([2607:f8b0:400e:c03::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZywUq-00043j-Od for linux-arm-kernel@lists.infradead.org; Wed, 18 Nov 2015 06:45:39 +0000 Received: by padhx2 with SMTP id hx2so35021116pad.1 for ; Tue, 17 Nov 2015 22:45:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SS0dHaZT/tofACwr9ESWH34HP5DuUAeCL9HtpxzoNxg=; b=jne545fLcUniV36OB/n15azsttNK+RESgs3Nf3j5z6R7HJOqbASOaRt72p0uWMFRBx 3/ydlhRbkamz9yM6Aq0eYJlxiCtdtanfGi208bBo4Be5jJNpXjwOQdb3uL92AVds5f2e HlROwjiAM0tBTerCf51WT+Ani+gybFbKm5En9tNdK9O8oxYr6DJcC9OlpvvJpVlrOynf G46CbuiT5w46AY0DorcZEPZNv53qUaGwW0LoeimFYSQI1lfvsEfMVbbHACGtJlLRS5ij jg+goh4t0PFt0TeiVNNNJQAy/0l3W+CpSWaJK79hOdH6FqSYSigsMIUu9iWJ44lHGaD+ bi4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SS0dHaZT/tofACwr9ESWH34HP5DuUAeCL9HtpxzoNxg=; b=jKe9BLwvDqY71/OddiHoRODgEpNRjnX2r9FJMvSwzFcPb20lomStZMqLnPU0OPcOY7 nB8vUkDAuUeCavxBSyTRgZDRwPXv85VzBGYGPH87Kc3kN6seOy9524PbPbdGsMXECW+E eYpWVXmdlV39CGZdQ7udtgN0RuKhMkq8J4oFxNBKBnjv+8oSTdbSZOh19+5wJ9PaUPnT XA55OprNN2prRui5dX/tZfEAdJR43Q3yRYeeSIedUTcGiDo8ZVwBBUr+AwfjP6fiZhYr NCdZhyCkpjAC85JFEpJKqHGoo1WKqrMKy2rSurf4aViDRVwKAwauVx4duUX2LNR59cgf osKw== X-Gm-Message-State: ALoCoQlI6nIx2sraDjc3Ds/vtpeyAZpSwYVDl95lmIW2suko/EGMasxks+tXOH+C2HlBzrLDr5aW X-Received: by 10.68.240.99 with SMTP id vz3mr52397412pbc.8.1447829116192; Tue, 17 Nov 2015 22:45:16 -0800 (PST) Received: from localhost.localdomain (61-205-7-47m5.grp1.mineo.jp. [61.205.7.47]) by smtp.googlemail.com with ESMTPSA id xr8sm1685523pab.26.2015.11.17.22.45.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 22:45:14 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, rostedt@goodmis.org Subject: [PATCH v6 6/6] arm64: ftrace: add a test of function prologue analyzer Date: Wed, 18 Nov 2015 15:43:09 +0900 Message-Id: <1447828989-4980-7-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447828989-4980-1-git-send-email-takahiro.akashi@linaro.org> References: <1447828989-4980-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151117_224537_096806_E2D78592 X-CRM114-Status: GOOD ( 19.08 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c03:0:0:0:235 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jungseoklee85@gmail.com, AKASHI Takahiro , broonie@kernel.org, yalin.wang2010@gmail.com, david.griego@linaro.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org The patch ("arm64: ftrace: add arch-specific stack tracer") introduced a function prologue analyzer. Given that there is no fixed template for a function prologue, at least on gcc for aarch64, a function prologue analyzer may be rather heuristic. So this patch adds a kernel command line option, function_prologue_analyzer_test, in order to run a basic test at startup by executing an analyzer against all the *traceable* functions. For function_prologue_analyzer_test=2, the output looks like: po sp fp symbol == == == ====== 0: 0 0x040 0x000 gic_handle_irq+0x20/0xa4 1: 0 0x040 0x000 gic_handle_irq+0x34/0x114 2: 0 0x030 0x000 run_init_process+0x14/0x48 3: 0 0x020 0x000 try_to_run_init_process+0x14/0x58 4: 0 0x080 0x000 do_one_initcall+0x1c/0x194 ... 22959: 0 0x020 0x000 tty_lock_slave+0x14/0x3c 22960: 0 0x020 0x000 tty_unlock_slave+0x14/0x3c function prologue analyzer test: 0 errors "po" indicates a position of callsite of mcount(), and should be zero if an analyzer has parsed a function prologue successfully and reached a location where fp is properly updated. "sp" is a final offset to a parent's fp at the exit of function prologue. "fp" is also an ofset against sp at the exit of function prologue. So normally, = + <"sp"> = - <"fp"> And the last line shows the number of possible errors in the result. For function_prologue_analyzer_test=1, only the last line will be shown. Signed-off-by: AKASHI Takahiro --- arch/arm64/include/asm/insn.h | 2 +- arch/arm64/kernel/stacktrace.c | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) -- 1.7.9.5 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h index 8d5c538..1dfae16 100644 --- a/arch/arm64/include/asm/insn.h +++ b/arch/arm64/include/asm/insn.h @@ -281,7 +281,7 @@ __AARCH64_INSN_FUNCS(hint, 0xFFFFF01F, 0xD503201F) __AARCH64_INSN_FUNCS(br, 0xFFFFFC1F, 0xD61F0000) __AARCH64_INSN_FUNCS(blr, 0xFFFFFC1F, 0xD63F0000) __AARCH64_INSN_FUNCS(ret, 0xFFFFFC1F, 0xD65F0000) -__AARCH64_INSN_FUNCS(eret, 0xFFFFFFFF, 0xD69F00E0) +__AARCH64_INSN_FUNCS(eret, 0xFFFFFFFF, 0xD69F03E0) #undef __AARCH64_INSN_FUNCS diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 1d18bc4..19dad62 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -348,5 +349,56 @@ void save_stack_trace_sp(struct stack_trace *trace, { __save_stack_trace_tsk(current, trace, stack_dump_sp); } + +static int start_analyzer_test __initdata; + +static int __init enable_analyzer_test(char *str) +{ + get_option(&str, &start_analyzer_test); + return 0; +} +early_param("function_prologue_analyzer_test", enable_analyzer_test); + +static void __init do_test_function_prologue_analyzer(void) +{ + extern unsigned long __start_mcount_loc[]; + extern unsigned long __stop_mcount_loc[]; + unsigned long count, i, errors; + int print_once; + + count = __stop_mcount_loc - __start_mcount_loc; + errors = print_once = 0; + for (i = 0; i < count; i++) { + unsigned long addr, sp_off, fp_off; + int pos; + bool check; + char buf[60]; + + addr = __start_mcount_loc[i]; + pos = analyze_function_prologue(addr, &sp_off, &fp_off); + check = ((pos != 0) || !sp_off || (sp_off <= fp_off)); + if (check) + errors++; + if (check || (start_analyzer_test > 1)) { + if (!print_once) { + pr_debug(" po sp fp symbol\n"); + pr_debug(" == == == ======\n"); + print_once++; + } + sprint_symbol(buf, addr); + pr_debug("%5ld: %d 0x%03lx 0x%03lx %s\n", + i, pos, sp_off, fp_off, buf); + } + } + pr_debug("function prologue analyzer test: %ld errors\n", errors); +} + +static int __init test_function_prologue_analyzer(void) +{ + if (start_analyzer_test) + do_test_function_prologue_analyzer(); + return 0; +} +late_initcall(test_function_prologue_analyzer); #endif /* CONFIG_STACK_TRACER */ #endif