From patchwork Tue Dec 15 08:33:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 7852041 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7AA4BBEEE1 for ; Tue, 15 Dec 2015 08:38:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B67D20279 for ; Tue, 15 Dec 2015 08:38:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A389C2021F for ; Tue, 15 Dec 2015 08:38:50 +0000 (UTC) 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 1a8l6S-0002CF-J8; Tue, 15 Dec 2015 08:37:00 +0000 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a8l5A-0000lL-J8 for linux-arm-kernel@lists.infradead.org; Tue, 15 Dec 2015 08:35:43 +0000 Received: by mail-pf0-x235.google.com with SMTP id 63so1140240pff.2 for ; Tue, 15 Dec 2015 00:35:23 -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=IUkowEsGICm+ttGj+ilBJvsJMdaElUJbEx1NrnFTnaA=; b=Iu7FNf9u6mzSpMyxPsb/6ktbyQkF1aZ6aIAVeg6vdpCbrPhnoXMaiZZczsWXTXATLs c7puV+080Cz6HINlr/75Pv88kmnNOG4VOQdpxk4p+wWIizAHin2uj2sKpPcX8XaqkUyp L8luLvzSx1pVA5XOSaC5a/eNgv3aFJQZOduDw= 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=IUkowEsGICm+ttGj+ilBJvsJMdaElUJbEx1NrnFTnaA=; b=LOzGBSm28M+wVLDMo/iuCu+UA7HWIMorhGm6lVtz+HTZcVoxgfduJJZSuxgn4QxVd9 4DDGgQgB0pTBi/xM4d0xLGLkVEVDTjec1CHFwGpIAAbeJ/tToNdS5K4ULGaoMPztC/dm OxMaf9V5Q2Zk/iQH0CyFMmuwl3Qr++RDISyJCkvh9p3VfbJ/oj7vGPwdRJeqs2Uj9Ps2 0ahTTgFiDAVYaqXH1vwhmQUa7RSKsJfKNruorBwv19y6NXDLpzEOanIbN0l9pcZauJ3I E+9VEHsxliHpqYFUb2FJF4M6r7LMy1xwO/CvrbC6X6ZngR/Slk5Ljz8Q1/cFwJOxT/JR HRjw== X-Gm-Message-State: ALoCoQkgLg8AXzvHbOQ6u2r+7bPi8NJAhVEj+y7FKTBPd/qcv9PUMy/802YZqranNPAu4HY9fQKjK1ok5pT+7XoldxXnSU738w== X-Received: by 10.98.16.81 with SMTP id y78mr42459655pfi.158.1450168522907; Tue, 15 Dec 2015 00:35:22 -0800 (PST) Received: from localhost.localdomain (61-205-82-105m5.grp2.mineo.jp. [61.205.82.105]) by smtp.googlemail.com with ESMTPSA id f5sm586757pas.8.2015.12.15.00.35.18 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Dec 2015 00:35:21 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, rostedt@goodmis.org Subject: [PATCH v7 6/6] arm64: ftrace: add a test of function prologue analyzer Date: Tue, 15 Dec 2015 17:33:44 +0900 Message-Id: <1450168424-10010-7-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450168424-10010-1-git-send-email-takahiro.akashi@linaro.org> References: <1450168424-10010-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151215_003541_196152_080244F7 X-CRM114-Status: GOOD ( 17.68 ) X-Spam-Score: -2.0 (--) 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 allows us to run a basic test in boot time by executing an analyzer against all the *traceable* functions. The test can be turned on and off with a kernel command line option, function_prologue_analyzer_test. For function_prologue_analyzer_test=2, the output looks like: po sp fp symbol == == == ====== 0: 0 0x040 0x000 OK gic_handle_irq+0x20/0xa4 1: 0 0x040 0x000 OK gic_handle_irq+0x34/0x114 2: 0 0x030 0x000 OK run_init_process+0x14/0x48 3: 0 0x020 0x000 OK try_to_run_init_process+0x14/0x58 4: 0 0x080 0x000 OK do_one_initcall+0x1c/0x194 ... 22959: 0 0x020 0x000 OK tty_lock_slave+0x14/0x3c 22960: 0 0x020 0x000 OK tty_unlock_slave+0x14/0x3c function prologue analyzer test: 0 errors Here, pos = analyze_function_prologue(unsigned long pc, unsigned long *size, unsigned long *size2); pos -> "po" size -> "sp" size2 -> "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. Reviewed-by: Jungseok Lee Signed-off-by: AKASHI Takahiro --- arch/arm64/kernel/stacktrace.c | 59 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 1d18bc4..acbca22 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -101,7 +102,7 @@ static int analyze_function_prologue(unsigned long pc, /* exiting a basic block */ goto out; - if (aarch64_insn_decode_add_sub_imm(insn, &dst, &src, + if (!aarch64_insn_extract_add_sub_imm(insn, &dst, &src, &imm, &variant, &adsb_type)) { if ((adsb_type == AARCH64_INSN_ADSB_SUB) && (dst == AARCH64_INSN_REG_SP) && @@ -129,7 +130,7 @@ static int analyze_function_prologue(unsigned long pc, break; } - } else if (aarch64_insn_decode_load_store_pair(insn, + } else if (!aarch64_insn_extract_load_store_pair(insn, ®1, ®2, &base, &imm, &variant, &ldst_type)) { if ((ldst_type == @@ -146,7 +147,7 @@ static int analyze_function_prologue(unsigned long pc, pos = 3; *size += -imm; } else if ((ldst_type == - AARCH64_INSN_LDST_STORE_PAIR) && + AARCH64_INSN_LDST_STORE_PAIR_REG_OFFSET) && (reg1 == AARCH64_INSN_REG_29) && (reg2 == AARCH64_INSN_REG_30) && (base == AARCH64_INSN_REG_SP)) { @@ -348,5 +349,57 @@ 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 %s\n", + i, pos, sp_off, fp_off, + check ? "NG" : "OK", 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