From patchwork Fri Sep 1 05:48:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Anand X-Patchwork-Id: 9933503 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 33CE26016C for ; Fri, 1 Sep 2017 05:49:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2401828471 for ; Fri, 1 Sep 2017 05:49:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1595928522; Fri, 1 Sep 2017 05:49:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 837AE28471 for ; Fri, 1 Sep 2017 05:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=W/PIyRZ/HkL1k0TH91hh1mG3gsEFM8lSketL0zoPhFo=; b=Av2 BKEKv9XUtv84xAtItBEQHv8Rz5SrVqw6syCscQmpvd1NZqs+5LDQf7SRVVFI62MCXOpmiT4Cp43vk /eQd7+44G2Qw7IdDWJMZYKbd/c2TL6luWG2cAgtm3aPQ9i2nAMqyc0K562LNjCKlE9vkjKWFWEnyK 56zy1KEUE3C5V6NmogWZbJIDBGPmv9AzvFy9Drz/ePKurtj7iqrOqPXuT3sQ0dMdQrkL0ZjgVrS5C xrzmNJUWR/yGHDPzwPYUtUV05X/9hYlDi6Slggh4Tky5O/8WufvZMg6jwAxoEgvB2bryRxEGhVNdV pGWhEh1ad9cCwjzaCdNyLO8NFpiHcwQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dnepw-0007ub-2E; Fri, 01 Sep 2017 05:49:48 +0000 Received: from mail-pg0-f41.google.com ([74.125.83.41]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dneps-0007pz-DK for linux-arm-kernel@lists.infradead.org; Fri, 01 Sep 2017 05:49:46 +0000 Received: by mail-pg0-f41.google.com with SMTP id 83so5241223pgb.4 for ; Thu, 31 Aug 2017 22:49:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=aWHNwOf8RAQCib+BlKvX9CBZVz0w5kT745SLSEbtW1g=; b=IkgNqExCURUWRkBagGWMijGlQkRpVXgkM8+WAN4hdvzp5MAjbt9lV8sPJnYM1bce+J h9DPime69N7Z0W2Z1KFL2HupnbObsaxmo14W8rpW877WhvPdRV/7UDaNMvonIYuLJpKs 9GAzebMXL/ekPHAeHpw/jFTSCr3h/wvDYuVrG6UvIcKfbVqNci1OlyZWghQicss35e2d dNwq2n1h1xzzDOiYOb/e3E21fg9szJ4FdhAJ05dVTim0dd3Y/1YePxImHl1q0fd+dK9J wgZimEdXLAO6smEEGU+mPIEBki2YK7aJ7DZ1UUj2/9cadmGv0IVJDzhpQ39z+OIH+otC 8Bng== X-Gm-Message-State: AHPjjUjh96DBdadUkOXJb+oNhw+XkQkd2idgowoUE0t/chIyXGcuBDlI avxwkx4KpLI285m5LJi0kA== X-Google-Smtp-Source: ADKCNb7kbWATOsmHwp//5Fqr6NCI/7DQiZyxsmzXuSVtaliOPVl0vXFrep4UTbwiaESdzWsV+CWSIg== X-Received: by 10.98.85.132 with SMTP id j126mr1036158pfb.203.1504244961769; Thu, 31 Aug 2017 22:49:21 -0700 (PDT) Received: from localhost ([122.162.11.247]) by smtp.gmail.com with ESMTPSA id d18sm905619pfk.104.2017.08.31.22.49.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Aug 2017 22:49:21 -0700 (PDT) From: Pratyush Anand To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] arm64: fix unwind_frame() for filtered out fn for function graph tracing Date: Fri, 1 Sep 2017 11:18:47 +0530 Message-Id: <3c175a7a1f7c2e08098f6d5e84dc247ce94846d2.1504244801.git.panand@redhat.com> X-Mailer: git-send-email 2.9.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170831_224944_491129_E83DBAD4 X-CRM114-Status: GOOD ( 15.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pratyush Anand , Catalin Marinas , james.morse@arm.com, linux-kernel@vger.kernel.org, Will Deacon MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP do_task_stat() calls get_wchan(), which further does unbind_frame(). unbind_frame() restores frame->pc to original value in case function graph tracer has modified a return address (LR) in a stack frame to hook a function return. However, if function graph tracer has hit a filtered function, then we can't unwind it as ftrace_push_return_trace() has biased the index(frame->graph) with a 'huge negative' offset(-FTRACE_NOTRACE_DEPTH). Moreover, arm64 stack walker defines index(frame->graph) as unsigned int, which can not compare a -ve number. Similar problem we can have with calling of walk_stackframe() from save_stack_trace_tsk() or dump_backtrace(). This patch fixes unwind_frame() to test the index for -ve value and restore index accordingly before we can restore frame->pc. Reproducer: cd /sys/kernel/debug/tracing/ echo schedule > set_graph_notrace echo 1 > options/display-graph echo wakeup > current_tracer ps -ef | grep -i agent Above commands result in: Unable to handle kernel paging request at virtual address ffff801bd3d1e000 pgd = ffff8003cbe97c00 [ffff801bd3d1e000] *pgd=0000000000000000, *pud=0000000000000000 Internal error: Oops: 96000006 [#1] SMP [...] CPU: 5 PID: 11696 Comm: ps Not tainted 4.11.0+ #33 [...] task: ffff8003c21ba000 task.stack: ffff8003cc6c0000 PC is at unwind_frame+0x12c/0x180 LR is at get_wchan+0xd4/0x134 pc : [] lr : [] pstate: 60000145 sp : ffff8003cc6c3ab0 x29: ffff8003cc6c3ab0 x28: 0000000000000001 x27: 0000000000000026 x26: 0000000000000026 x25: 00000000000012d8 x24: 0000000000000000 x23: ffff8003c1c04000 x22: ffff000008c83000 x21: ffff8003c1c00000 x20: 000000000000000f x19: ffff8003c1bc0000 x18: 0000fffffc593690 x17: 0000000000000000 x16: 0000000000000001 x15: 0000b855670e2b60 x14: 0003e97f22cf1d0f x13: 0000000000000001 x12: 0000000000000000 x11: 00000000e8f4883e x10: 0000000154f47ec8 x9 : 0000000070f367c0 x8 : 0000000000000000 x7 : 00008003f7290000 x6 : 0000000000000018 x5 : 0000000000000000 x4 : ffff8003c1c03cb0 x3 : ffff8003c1c03ca0 x2 : 00000017ffe80000 x1 : ffff8003cc6c3af8 x0 : ffff8003d3e9e000 Process ps (pid: 11696, stack limit = 0xffff8003cc6c0000) Stack: (0xffff8003cc6c3ab0 to 0xffff8003cc6c4000) [...] [] unwind_frame+0x12c/0x180 [] do_task_stat+0x864/0x870 [] proc_tgid_stat+0x3c/0x48 [] proc_single_show+0x5c/0xb8 [] seq_read+0x160/0x414 [] __vfs_read+0x58/0x164 [] vfs_read+0x88/0x144 [] SyS_read+0x60/0xc0 [] __sys_trace_return+0x0/0x4 fixes: 20380bb390a4 (arm64: ftrace: fix a stack tracer's output under function graph tracer) Signed-off-by: Pratyush Anand --- v1 -> v2: - improved commit log - now index is restored and thereafter frame->pc as well. arch/arm64/include/asm/stacktrace.h | 2 +- arch/arm64/kernel/stacktrace.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h index 5b6eafccc5d8..816db5b9b874 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -23,7 +23,7 @@ struct stackframe { unsigned long sp; unsigned long pc; #ifdef CONFIG_FUNCTION_GRAPH_TRACER - unsigned int graph; + int graph; #endif }; diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 09d37d66b630..4c47147d0554 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -75,6 +75,9 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) #ifdef CONFIG_FUNCTION_GRAPH_TRACER if (tsk->ret_stack && (frame->pc == (unsigned long)return_to_handler)) { + if (frame->graph < 0) + frame->graph += FTRACE_NOTRACE_DEPTH; + /* * This is a case where function graph tracer has * modified a return address (LR) in a stack frame