From patchwork Mon Jul 13 05:29:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 6774141 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EAE2D9F2F0 for ; Mon, 13 Jul 2015 05:34:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0C94120678 for ; Mon, 13 Jul 2015 05:34:13 +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 0B226205D8 for ; Mon, 13 Jul 2015 05:34:12 +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 1ZEWKW-0003Wm-BQ; Mon, 13 Jul 2015 05:31:04 +0000 Received: from mail-pd0-f180.google.com ([209.85.192.180]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZEWKU-0003To-Ah for linux-arm-kernel@lists.infradead.org; Mon, 13 Jul 2015 05:31:03 +0000 Received: by pdjr16 with SMTP id r16so56494584pdj.3 for ; Sun, 12 Jul 2015 22:30:39 -0700 (PDT) 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=79z77NVQtxBrtwMGErRhcy+CoK9PpE/+G9OyyIDvazA=; b=CUvejctfAFqLXjCbGdh+Y2mwT9u+VPFGLOzUn4tqdg0PS7YUITlJtEMKcNYrUo8N5x 1wEP53WzGOGOhrnxKazde2oq7K9Zjf1qfGbtoku9lJQxGzwbBue5lr9aIGj3SwxfTpyJ UsjotVMEx8kV4zSrKsep6mMm9BEtqy+Yc8ZQVqIlSpXCXBuaFSxcUg7rtmCKyk/SB+w+ kNffN7R6e2T3AgcyzkDgCa1EFh8Zeaqe2rnlEbmADJJp/MBZ/LLskgxAUBztpDz2/qzc bgZ2pjaPFqFWvPEY953LDZ9jiJnbKNpURKcYWJjdVdma3oycqI96mICKQSQoesC6CJgq qJ6w== X-Gm-Message-State: ALoCoQknRSDyw//NciQ36JNj0P8NcHu0UjZq82fhsR4cYFMRYXp1pmct+33CeroZZGI+OTz7JnDe X-Received: by 10.70.64.162 with SMTP id p2mr66541372pds.54.1436765439732; Sun, 12 Jul 2015 22:30:39 -0700 (PDT) Received: from localhost.localdomain (61-205-7-98m5.grp1.mineo.jp. [61.205.7.98]) by smtp.googlemail.com with ESMTPSA id cz1sm16903229pbc.84.2015.07.12.22.30.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Jul 2015 22:30:38 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, rostedt@goodmis.org Subject: [RFC 2/3] arm64: refactor save_stack_trace() Date: Mon, 13 Jul 2015 14:29:34 +0900 Message-Id: <1436765375-7119-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436765375-7119-1-git-send-email-takahiro.akashi@linaro.org> References: <1436765375-7119-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150712_223102_397002_9360D834 X-CRM114-Status: GOOD ( 14.79 ) X-Spam-Score: -2.6 (--) 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, linux-kernel@vger.kernel.org, AKASHI Takahiro , broonie@kernel.org, david.griego@linaro.org, olof@lixom.net, 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=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 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 One of tracer functions, ftrace_call (or mcount), is unexpectedly listed. The *bare* stack dump returned by save_stack_trace() is: save_stack_trace_tsk() save_stack_trace() stack_trace_call() ftrace_ops_no_ops() ftrace_call() notifier_call_chain() raw_notifier_call_chain() ... On arm64, save_stack_trace() calls save_stack_trace_tsk() and this will result in putting additional stack frame in the returned list. This behavior, however, conflicts with stack stracer's assumption that the number of functions to be skiped as part of tracer is 4, from save_stack_trace() to mcount(), if ftrace_ops_list_func() is used. The value is hard coded in check_patch(). This patch refactors save_stack_trace() and save_stack_trace_tsk() in order to reduce the stack depth by making the common code inlined. Signed-off-by: AKASHI Takahiro --- arch/arm64/kernel/stacktrace.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 407991b..978c923 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -97,34 +97,49 @@ static int save_trace(struct stackframe *frame, void *d) return trace->nr_entries >= trace->max_entries; } -void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) +static inline void __save_stack_trace(struct stackframe *frame, + struct stack_trace *trace, int no_sched) { struct stack_trace_data data; - struct stackframe frame; data.trace = trace; data.skip = trace->skip; + data.no_sched_functions = no_sched; + + walk_stackframe(frame, save_trace, &data); + if (trace->nr_entries < trace->max_entries) + trace->entries[trace->nr_entries++] = ULONG_MAX; +} + +void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) +{ + struct stackframe frame; + int no_sched; if (tsk != current) { - data.no_sched_functions = 1; + no_sched = 1; frame.fp = thread_saved_fp(tsk); frame.sp = thread_saved_sp(tsk); frame.pc = thread_saved_pc(tsk); } else { - data.no_sched_functions = 0; + no_sched = 0; frame.fp = (unsigned long)__builtin_frame_address(0); frame.sp = current_stack_pointer; frame.pc = (unsigned long)save_stack_trace_tsk; } - walk_stackframe(&frame, save_trace, &data); - if (trace->nr_entries < trace->max_entries) - trace->entries[trace->nr_entries++] = ULONG_MAX; + __save_stack_trace(&frame, trace, no_sched); } void save_stack_trace(struct stack_trace *trace) { - save_stack_trace_tsk(current, trace); + struct stackframe frame; + + frame.fp = (unsigned long)__builtin_frame_address(0); + frame.sp = current_stack_pointer; + frame.pc = (unsigned long)save_stack_trace_tsk; + + __save_stack_trace(&frame, trace, 0); } EXPORT_SYMBOL_GPL(save_stack_trace); #endif