From patchwork Fri Nov 6 06:44:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 56094 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp829986lbr; Thu, 5 Nov 2015 22:46:17 -0800 (PST) X-Received: by 10.66.150.165 with SMTP id uj5mr15176147pab.23.1446792377804; Thu, 05 Nov 2015 22:46:17 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yn2si15535449pbb.236.2015.11.05.22.46.17; Thu, 05 Nov 2015 22:46:17 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032213AbbKFGqP (ORCPT + 28 others); Fri, 6 Nov 2015 01:46:15 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:35799 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032001AbbKFGqL (ORCPT ); Fri, 6 Nov 2015 01:46:11 -0500 Received: by pasz6 with SMTP id z6so117228025pas.2 for ; Thu, 05 Nov 2015 22:46:11 -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=BCzLs00MLZT6dLkADEcJ8ZMQQRckhv6kFWlgX1lih9Q=; b=NYqYC6Q3+95VNVVeg3h+xWF47DXe/NGT17/60YgA4Y/kdAXlvV920UtaBNF2GMccfA +H9KOroVXZvGOsHFTjbwxXT65WEfksxbaaK+pMU5Vr7m2D/JNV8qoBtROOY4+Jv1AJdK K6ulaWY+c7+kPRVR64nRfYi5ynppxI9fFm8ovsSJIBTrpoS7nnAiUJd1rqB90MdVcWTD X3I4e7f+f6zJxtxWTDmomRTwpbcacdgMVjCzepmqarK/gKwu+Sb2Iyy9V2Z7QtLQ+qw8 7AB1uRdZf3IhLStDYFiUq4bmnkYobeQBj+HRCKBpwizUNGtTUvC9oJjrzLRTGUOOVlPe aLEw== 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=BCzLs00MLZT6dLkADEcJ8ZMQQRckhv6kFWlgX1lih9Q=; b=T9BbBiMWHA2M60wP2vJi69r3TIPG6j87oQ8jASHJwWbCF/vMnWoDN7LHeQHSZlbn78 GAyMNP36lC+K7Yi/yLWzTrFD3Hu+/kn/8ExCJzcwmnrOqYO/UbGJND/q4dIZ3XrQbJzL Unjjy1YOSkaH0jwFrO89RRxA7avSXhTlU1gBDMKEi1kq2pA0F5tK6u14lLVot2HmoqcI N2PxCj/FKR/MzTqBzcxaYGw/EnZ2MLq8r/zUuYbAeP2UVl1lEuGjWx687SvohUIti6NH 8QCYcYOG8pL+4pxQZ7rLiXVIYaU4qX4sLJpJnLNBBDbmjibX+HlT1PMhC+NKLYTWq3Dt hlVQ== X-Gm-Message-State: ALoCoQnX8AW7Li7QoSvq+H7p4z1xy1Qiz5UTEZK/XMohSsSyKRicWVi+QonFD3j2d5wPAe7nBI7U X-Received: by 10.68.169.34 with SMTP id ab2mr15547382pbc.44.1446792370921; Thu, 05 Nov 2015 22:46:10 -0800 (PST) Received: from localhost.localdomain (61-205-2-204m5.grp1.mineo.jp. [61.205.2.204]) by smtp.googlemail.com with ESMTPSA id zi1sm11732096pbc.10.2015.11.05.22.46.06 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 Nov 2015 22:46:10 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, rostedt@goodmis.org Cc: jungseoklee85@gmail.com, broonie@kernel.org, david.griego@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 6/6] arm64: ftrace: add a test of function prologue analyzer Date: Fri, 6 Nov 2015 15:44:45 +0900 Message-Id: <1446792285-1154-7-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446792285-1154-1-git-send-email-takahiro.akashi@linaro.org> References: <1446792285-1154-1-git-send-email-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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/kernel/stacktrace.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 4ee052a..d1a9e5b 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -322,5 +323,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