From patchwork Mon Jul 13 05:29:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 51061 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1635322916 for ; Mon, 13 Jul 2015 05:31:11 +0000 (UTC) Received: by wgwk7 with SMTP id k7sf45255319wgw.0 for ; Sun, 12 Jul 2015 22:31:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Qa3gluLxVhcdqDh5KNiorIZKX3B/yhxM9PVh7wFg9lY=; b=JD8F8mLuxD/USJSIA9VVWFt8k6MJbvpX26Dotdpp7SvMF1Oz04L6KXrm2IEKlYmPzZ tl6Pe+zi4uWAzhnV2YCD24YE1SqPjO3YtF6ZBmxzePFtI1XnYwiCPtdxQSUO8gGdbgBy GMrV0MDOt1kABUGa/jRCdVg88rIcsoHY0XJrKm/QgYXGHxbDtzvgg0LlCW8J5lWd+UUC Dr1W0X2V6dwZilf4wuprhAkBQHZy3Iudu99YJ3vhKiXLywfvPjrlmXsW4L15Ng8HOpDb YNzoNkOQ/kNofLJv8+qCKgSVh3kL/LTWmA5Hv2SCSCNgyxhaRczyXN2ctF7bnbf5FzY/ BxAA== X-Gm-Message-State: ALoCoQmCki56U0Zu0bdAMG+5aJrqypilKOHjPA2/VjqHgW5Abx2xlepo7rt4Y4hIseIQlz1hSIx1 X-Received: by 10.180.11.226 with SMTP id t2mr6359887wib.0.1436765470426; Sun, 12 Jul 2015 22:31:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.232 with SMTP id d8ls621537lab.13.gmail; Sun, 12 Jul 2015 22:31:10 -0700 (PDT) X-Received: by 10.152.25.227 with SMTP id f3mr29864981lag.67.1436765470225; Sun, 12 Jul 2015 22:31:10 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id u8si2895225laz.114.2015.07.12.22.31.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Jul 2015 22:31:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lahh5 with SMTP id h5so9922799lah.2 for ; Sun, 12 Jul 2015 22:31:10 -0700 (PDT) X-Received: by 10.113.4.105 with SMTP id cd9mr24948851lbd.106.1436765470089; Sun, 12 Jul 2015 22:31:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1500026lbb; Sun, 12 Jul 2015 22:31:09 -0700 (PDT) X-Received: by 10.67.4.201 with SMTP id cg9mr66141254pad.53.1436765468299; Sun, 12 Jul 2015 22:31:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ju17si26553933pab.94.2015.07.12.22.31.07; Sun, 12 Jul 2015 22:31:08 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751493AbbGMFbF (ORCPT + 28 others); Mon, 13 Jul 2015 01:31:05 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:36842 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751432AbbGMFbD (ORCPT ); Mon, 13 Jul 2015 01:31:03 -0400 Received: by pachj5 with SMTP id hj5so25780781pac.3 for ; Sun, 12 Jul 2015 22:31:02 -0700 (PDT) X-Received: by 10.70.41.165 with SMTP id g5mr65706488pdl.143.1436765462802; Sun, 12 Jul 2015 22:31:02 -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.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Jul 2015 22:31:01 -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: [RFC 3/3] arm64: ftrace: mcount() should not create a stack frame Date: Mon, 13 Jul 2015 14:29:35 +0900 Message-Id: <1436765375-7119-4-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> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: takahiro.akashi@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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