Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1944642ybv; Fri, 14 Feb 2020 08:38:59 -0800 (PST) X-Google-Smtp-Source: APXvYqwhYijUG1V9G/kJqwjFhKCECQ+Wb/UY0XydGYGnQv874mk60rGUU2q4j1gC7mPmSPMlItuD X-Received: by 2002:a05:6830:14c3:: with SMTP id t3mr2910014otq.213.1581698339511; Fri, 14 Feb 2020 08:38:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698339; cv=none; d=google.com; s=arc-20160816; b=Mg4WVqCIigYVOwR8447BmxiWQFw0IPPRuz3yZUfvy3UBHXf7hUp2qm7RAq/GAYFy1+ tpp6aWoOYjAkcXhCLYbopSs8mP7WI5u410hhbGGalFZh30x+PdNzMtHUEPqpN7mBoz6u B8746D8nB48Vu+7rpHd1iuOQmIAyxsJQgMMEcDhqmnH+Ur8rWtA/FKi/RAnv9VNALurc wn50Nc0JJgicNwcB9XxcoRKlDiChmG+COz371L4bc006DwLu+YW8zrnJI1D5BYhqeEuI UHQ+5gnbPElUsr4L97QJ7OZbuRjBFawkroykwKK/nyrXu4obByFqIphKuw7HjJks88U6 329w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HTqI9HihM6IXIWEsoFmH67dDgXnUtv5T0Kv1E5sVR44=; b=x8gnCHhZv9ldtjCJ//FtEYPvEXB4fUfa0uWB7un+GVWIraBg4WKDIRp04J5H1q1+AD qVchkm9wx4AxANQC5zubJrEcrMZOsbQ2C6J0Awbyh6yHNTHa9skrCe50o5CktM4liZov 2+nfMKQ2LaVHYP1nZk2br2S1macmNWZcaRejNxcQKtM5QU9wY+Kjlyo+jFUvpZiqy4pt OA2qlp6cUlx2s3d9IzvwlXr9UuEsVY24i6hFHulwJ/OBX9TeuotpGkO8urM+c0FBlxkR ga4hDCLRPrfdsFicaDtgpKO44x+V8LOuMUi2LjaZQNRU2VshF60O7QlND6/x92PDR6dS Kwew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sUv4mQTJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c189si2647024oig.74.2020.02.14.08.38.46; Fri, 14 Feb 2020 08:38:59 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=sUv4mQTJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393816AbgBNQiD (ORCPT + 99 others); Fri, 14 Feb 2020 11:38:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:60184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405704AbgBNQXm (ORCPT ); Fri, 14 Feb 2020 11:23:42 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E535324772; Fri, 14 Feb 2020 16:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697421; bh=Y3pyy1a91dcT2uOGt0m1i2q0UP8gkIqP0mq2PHR0szo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sUv4mQTJ7B5e0E1t2WAXL4YdhYQoRHg4dzlojiRwQa5r7fjCVTwhq8nRLJLBzoehV 0hXVpCtLwEF5EPoYmw7Cmxd17tXEpBbNfwgMQkQYTVOBuFPB3QSdj/8xiBaJW0kEuI 0zegpJ3NGtTS+DSV96tT4G8uSne+KSReqXWMjNiU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vasily Gorbik , Sven Schnelle , Heiko Carstens , Sasha Levin , linux-s390@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 111/141] s390/ftrace: generate traced function stack frame Date: Fri, 14 Feb 2020 11:20:51 -0500 Message-Id: <20200214162122.19794-111-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vasily Gorbik [ Upstream commit 45f7a0da600d3c409b5ad8d5ddddacd98ddc8840 ] Currently backtrace from ftraced function does not contain ftraced function itself. e.g. for "path_openat": arch_stack_walk+0x15c/0x2d8 stack_trace_save+0x50/0x68 stack_trace_call+0x15e/0x3d8 ftrace_graph_caller+0x0/0x1c <-- ftrace code do_filp_open+0x7c/0xe8 <-- ftraced function caller do_open_execat+0x76/0x1b8 open_exec+0x52/0x78 load_elf_binary+0x180/0x1160 search_binary_handler+0x8e/0x288 load_script+0x2a8/0x2b8 search_binary_handler+0x8e/0x288 __do_execve_file.isra.39+0x6fa/0xb40 __s390x_sys_execve+0x56/0x68 system_call+0xdc/0x2d8 Ftraced function is expected in the backtrace by ftrace kselftests, which are now failing. It would also be nice to have it for clarity reasons. "ftrace_caller" itself is called without stack frame allocated for it and does not store its caller (ftraced function). Instead it simply allocates a stack frame for "ftrace_trace_function" and sets backchain to point to ftraced function stack frame (which contains ftraced function caller in saved r14). To fix this issue make "ftrace_caller" allocate a stack frame for itself just to store ftraced function for the stack unwinder. As a result backtrace looks like the following: arch_stack_walk+0x15c/0x2d8 stack_trace_save+0x50/0x68 stack_trace_call+0x15e/0x3d8 ftrace_graph_caller+0x0/0x1c <-- ftrace code path_openat+0x6/0xd60 <-- ftraced function do_filp_open+0x7c/0xe8 <-- ftraced function caller do_open_execat+0x76/0x1b8 open_exec+0x52/0x78 load_elf_binary+0x180/0x1160 search_binary_handler+0x8e/0x288 load_script+0x2a8/0x2b8 search_binary_handler+0x8e/0x288 __do_execve_file.isra.39+0x6fa/0xb40 __s390x_sys_execve+0x56/0x68 system_call+0xdc/0x2d8 Reported-by: Sven Schnelle Tested-by: Sven Schnelle Reviewed-by: Heiko Carstens Signed-off-by: Vasily Gorbik Signed-off-by: Sasha Levin --- arch/s390/kernel/mcount.S | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/s390/kernel/mcount.S b/arch/s390/kernel/mcount.S index be75e8e49e43d..802a4ded9a626 100644 --- a/arch/s390/kernel/mcount.S +++ b/arch/s390/kernel/mcount.S @@ -24,6 +24,12 @@ ENTRY(ftrace_stub) #define STACK_PTREGS (STACK_FRAME_OVERHEAD) #define STACK_PTREGS_GPRS (STACK_PTREGS + __PT_GPRS) #define STACK_PTREGS_PSW (STACK_PTREGS + __PT_PSW) +#ifdef __PACK_STACK +/* allocate just enough for r14, r15 and backchain */ +#define TRACED_FUNC_FRAME_SIZE 24 +#else +#define TRACED_FUNC_FRAME_SIZE STACK_FRAME_OVERHEAD +#endif ENTRY(_mcount) BR_EX %r14 @@ -37,9 +43,16 @@ ENTRY(ftrace_caller) #ifndef CC_USING_HOTPATCH aghi %r0,MCOUNT_RETURN_FIXUP #endif - aghi %r15,-STACK_FRAME_SIZE + # allocate stack frame for ftrace_caller to contain traced function + aghi %r15,-TRACED_FUNC_FRAME_SIZE stg %r1,__SF_BACKCHAIN(%r15) + stg %r0,(__SF_GPRS+8*8)(%r15) + stg %r15,(__SF_GPRS+9*8)(%r15) + # allocate pt_regs and stack frame for ftrace_trace_function + aghi %r15,-STACK_FRAME_SIZE stg %r1,(STACK_PTREGS_GPRS+15*8)(%r15) + aghi %r1,-TRACED_FUNC_FRAME_SIZE + stg %r1,__SF_BACKCHAIN(%r15) stg %r0,(STACK_PTREGS_PSW+8)(%r15) stmg %r2,%r14,(STACK_PTREGS_GPRS+2*8)(%r15) #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES -- 2.20.1