From patchwork Fri Oct 30 05:25:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 55815 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp965555lbr; Thu, 29 Oct 2015 22:27:15 -0700 (PDT) X-Received: by 10.50.153.111 with SMTP id vf15mr1040745igb.31.1446182835639; Thu, 29 Oct 2015 22:27:15 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p78si6123322iop.65.2015.10.29.22.27.15; Thu, 29 Oct 2015 22:27:15 -0700 (PDT) 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 S1758432AbbJ3F1N (ORCPT + 28 others); Fri, 30 Oct 2015 01:27:13 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:35189 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758253AbbJ3F1L (ORCPT ); Fri, 30 Oct 2015 01:27:11 -0400 Received: by pasz6 with SMTP id z6so62920341pas.2 for ; Thu, 29 Oct 2015 22:27:11 -0700 (PDT) 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=ePa0KIUSIJKCf7Xk8q0LTx7TQfOAQdv8LBYAVVSKZis=; b=aBebfBjDNZP86IhK3d9YYJhTUrCVdhbM7Kk0vTgJx9pDRqbB9K8eodrXYFX9E/BM/W g6miLSk/YaQgFQveGuKlOZI5+483mCQIAO+UknaUMWpdNwyCLwYDlnGxTjgQnCAN9M3V NUSWzGs81/Z8FHBO+ZEQg4Hp0j5uySWEJzGdgkc001mrdwPBAo7L18DSmP4MM+4Hwkwe JZFtMxpLqSWpsp4B5YI4oMQVxner4l+2eqvbXe/HN+5wOEHrlTGjQnw2fCrDmcTCMUoP ETTk+Z7ieuXxoqeuYDBNsQRABKjxI46mFix0FSUJ8z3i4chfMxSO12No4dMlu3AYiCP/ DWWw== 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=ePa0KIUSIJKCf7Xk8q0LTx7TQfOAQdv8LBYAVVSKZis=; b=PcO2mlFK65ttMSY+yoRYKs0Jyv1S80K69MiSXkvJbZ6Qoz8kkoFElzaYlMU0iz0w62 7/lX69xNOX1wZU0mJOBqMqsRQ/Powakm5onFZSZFPhwF2QLpee4C8eYgYUEZgQ262ACq 4ujDP3aZctfK5fblGQJ8xnjkidwvmEsykTwD+xwnuTBh3mptqsfjjrWoVMBTb6/UYNDp osLNkUm0loZDD0MfAUMAv00HBD47/uvzki15ajFscwYClLhj+R3Sy29JkAsgURDbfO5R TSRSOGKYUHqFd4eMs9FDzlQpxcRPsmnQ0prNKRCJt59rQs2cRUqzRWc57RHGC09NgppM nTZg== X-Gm-Message-State: ALoCoQnC4fdC06QyK+OulEuZJuJkARLhoiQub/cLRClG1wltp3XGhDKx1HqDg8XiDfoEL0ZYOqjI X-Received: by 10.66.192.106 with SMTP id hf10mr6546903pac.16.1446182830972; Thu, 29 Oct 2015 22:27:10 -0700 (PDT) Received: from localhost.localdomain (61-205-6-54m5.grp1.mineo.jp. [61.205.6.54]) by smtp.googlemail.com with ESMTPSA id ho3sm5571377pbb.18.2015.10.29.22.27.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Oct 2015 22:27:10 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, rostedt@goodmis.org Cc: jungseoklee85@gmail.com, olof@lixom.net, broonie@kernel.org, david.griego@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v4 1/6] arm64: ftrace: adjust callsite addresses examined by stack tracer Date: Fri, 30 Oct 2015 14:25:36 +0900 Message-Id: <1446182741-31019-2-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446182741-31019-1-git-send-email-takahiro.akashi@linaro.org> References: <1446182741-31019-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 On arm64, no PC values returned by save_stack_trace() will match to LR values saved in stack frames on a stack after the following commit: commit e306dfd06fcb ("ARM64: unwind: Fix PC calculation") As a result, the output from stack tracer will be messed up. This patch introduces an arch-defined macro, FTRACE_STACK_FRAME_OFFSET, so that check_stack() can handle this case correctly. Signed-off-by: AKASHI Takahiro --- arch/arm64/include/asm/ftrace.h | 5 +++-- arch/arm64/kernel/stacktrace.c | 7 ++++--- include/linux/ftrace.h | 7 +++++++ kernel/trace/trace_stack.c | 8 +++++--- 4 files changed, 19 insertions(+), 8 deletions(-) -- 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/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index c5534fa..2b43e20 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -13,8 +13,9 @@ #include -#define MCOUNT_ADDR ((unsigned long)_mcount) -#define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE +#define MCOUNT_ADDR ((unsigned long)_mcount) +#define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE +#define FTRACE_STACK_FRAME_OFFSET AARCH64_INSN_SIZE #ifndef __ASSEMBLY__ #include diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 407991b..bc0689a 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -20,6 +20,7 @@ #include #include +#include #include /* @@ -49,10 +50,10 @@ int notrace unwind_frame(struct stackframe *frame) frame->sp = fp + 0x10; frame->fp = *(unsigned long *)(fp); /* - * -4 here because we care about the PC at time of bl, - * not where the return will go. + * decrement PC by AARCH64_INSN_SIZE here because we care about + * the PC at time of bl, not where the return will go. */ - frame->pc = *(unsigned long *)(fp + 8) - 4; + frame->pc = *(unsigned long *)(fp + 8) - AARCH64_INSN_SIZE; return 0; } diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 6cd8c0e..d77b195 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -263,6 +263,13 @@ static inline void ftrace_kill(void) { } #endif /* CONFIG_FUNCTION_TRACER */ #ifdef CONFIG_STACK_TRACER +/* + * the offset value to add to return address from save_stack_trace() + */ +#ifndef FTRACE_STACK_FRAME_OFFSET +#define FTRACE_STACK_FRAME_OFFSET 0 +#endif + extern int stack_tracer_enabled; int stack_trace_sysctl(struct ctl_table *table, int write, diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c index 8abf1ba..2e452e8 100644 --- a/kernel/trace/trace_stack.c +++ b/kernel/trace/trace_stack.c @@ -68,7 +68,7 @@ static inline void print_max_stack(void) static inline void check_stack(unsigned long ip, unsigned long *stack) { - unsigned long this_size, flags; unsigned long *p, *top, *start; + unsigned long this_size, flags; unsigned long *p, *top, *start, addr; static int tracer_frame; int frame_size = ACCESS_ONCE(tracer_frame); int i, x; @@ -115,7 +115,8 @@ check_stack(unsigned long ip, unsigned long *stack) /* Skip over the overhead of the stack tracer itself */ for (i = 0; i < max_stack_trace.nr_entries; i++) { - if (stack_dump_trace[i] == ip) + addr = stack_dump_trace[i] + FTRACE_STACK_FRAME_OFFSET; + if (addr == ip) break; } @@ -143,7 +144,8 @@ check_stack(unsigned long ip, unsigned long *stack) for (; p < top && i < max_stack_trace.nr_entries; p++) { if (stack_dump_trace[i] == ULONG_MAX) break; - if (*p == stack_dump_trace[i]) { + addr = stack_dump_trace[i] + FTRACE_STACK_FRAME_OFFSET; + if (*p == addr) { stack_dump_trace[x] = stack_dump_trace[i++]; this_size = stack_dump_index[x++] = (top - p) * sizeof(unsigned long);