Path: csiph.com!aioe.org!bofh.it!news.nic.it!robomod From: AKASHI Takahiro Newsgroups: linux.kernel Subject: [RFC 3/3] arm64: ftrace: mcount() should not create a stack frame Date: Mon, 13 Jul 2015 07:40:02 +0200 Message-ID: References: X-Original-To: catalin.marinas@arm.com, will.deacon@arm.com, rostedt@goodmis.org 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=JmC4NmxsLkHeIXxmrszua/gCTOBPTMIKf2qlFByL3ZQ=; b=EXgAd0WjH6eOKM0pyMNuCuLaudkwRcZNFjm3Ol11DpsAhmX7ADEt0d/OTHw+IHF6rw ASgSojLI+DK6jpVE0OfqJCF14OXD4xDb+hbUYAImm1WwTEyUp2tm3xF2lT5pijYqN6AW paKqEUoRBfpFMHsm2vDsJX5A1dCQPKVSbIDSby1O54eHBx8CpG1xexW+EYcOUQCbAvuI qtRpHuKF+JgQmCrYdvpXRSBWfpJkDuuqqO8teLaOmxJwfvWm0N1wAOD0tc+bEQK6JXSX SFGtVoon358a8GPcpUKBn4pB63sbYcbceZSNy1m2cOUdh5LkhTbYIeT+QsPs7JMfMymz clnQ== X-Gm-Message-State: ALoCoQkqfnwUnTYR9j26vhgiXIklONMegnKhzvrwJyJbJAKzCsRB+hrIeCW1P2I/ydm8F3AC+Dak X-Received: by 10.70.41.165 with SMTP id g5mr65706488pdl.143.1436765462802; Sun, 12 Jul 2015 22:31:02 -0700 (PDT) X-Mailer: git-send-email 1.9.1 Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 101 Organization: linux.* mail to news gateway X-Original-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 X-Original-Date: Mon, 13 Jul 2015 14:29:35 +0900 X-Original-Message-ID: <1436765375-7119-4-git-send-email-takahiro.akashi@linaro.org> X-Original-References: <1436765375-7119-1-git-send-email-takahiro.akashi@linaro.org> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: aioe.org linux.kernel:1182525 Ftrace's stack tracer on arm64 returns wrong information about call stacks: Depth Size Location (50 entries) ----- ---- -------- 0) 5256 0 notifier_call_chain+0x30/0x94 1) 5256 0 ftrace_call+0x0/0x4 2) 5256 0 notifier_call_chain+0x2c/0x94 3) 5256 0 raw_notifier_call_chain+0x34/0x44 4) 5256 0 timekeeping_update.constprop.9+0xb8/0x114 5) 5256 0 update_wall_time+0x408/0x6dc The instrumented function, notifier_call_chain(), appears twice. On x86 (and other arch's), mcount (or ftrace_call) does not create a new stack frame. This will eventually result in not listing the instrumented function in save_stack_call() because the function's returned address does not appear as saved lr in the stack. Stack tracer, instead, explicitly adds this skipped function at the top of the list later in check_stack(). That is why it is listed twice on arm64 as shown above. This patch modifies arm64 function tracer not to create a stack frame at mcount() in order to fix this issue. Signed-off-by: AKASHI Takahiro --- arch/arm64/kernel/entry-ftrace.S | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S index 08cafc5..c74fa12 100644 --- a/arch/arm64/kernel/entry-ftrace.S +++ b/arch/arm64/kernel/entry-ftrace.S @@ -26,9 +26,11 @@ * as long as the kernel is compiled without -fomit-frame-pointer. * (or CONFIG_FRAME_POINTER, this is forced on arm64) * + * We don't update a frame pointer here as ftrace, in special stack tracer, + * assumes not. If we did, the instrumented function would be listed twice. * stack layout after mcount_enter in _mcount(): * - * current sp/fp => 0:+-----+ + * current sp => 0:+-----+ * in _mcount() | x29 | -> instrumented function's fp * +-----+ * | x30 | -> _mcount()'s lr (= instrumented function's pc) @@ -47,7 +49,6 @@ .macro mcount_enter stp x29, x30, [sp, #-16]! - mov x29, sp .endm .macro mcount_exit @@ -61,7 +62,7 @@ /* for instrumented function's parent */ .macro mcount_get_parent_fp reg - ldr \reg, [x29] + ldr \reg, [sp] ldr \reg, [\reg] .endm @@ -71,18 +72,18 @@ .endm .macro mcount_get_pc reg - ldr \reg, [x29, #8] + ldr \reg, [sp, #8] mcount_adjust_addr \reg, \reg .endm .macro mcount_get_lr reg - ldr \reg, [x29] + ldr \reg, [sp] ldr \reg, [\reg, #8] mcount_adjust_addr \reg, \reg .endm .macro mcount_get_lr_addr reg - ldr \reg, [x29] + ldr \reg, [sp] add \reg, \reg, #8 .endm @@ -205,7 +206,7 @@ ENDPROC(ftrace_graph_caller) */ ENTRY(return_to_handler) str x0, [sp, #-16]! - mov x0, x29 // parent's fp + mov x0, sp // parent's fp bl ftrace_return_to_handler// addr = ftrace_return_to_hander(fp); mov x30, x0 // restore the original return address ldr x0, [sp], #16 -- 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/