From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752744AbdDNJyc (ORCPT ); Fri, 14 Apr 2017 05:54:32 -0400 Received: from terminus.zytor.com ([65.50.211.136]:36187 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751278AbdDNJyb (ORCPT ); Fri, 14 Apr 2017 05:54:31 -0400 Date: Fri, 14 Apr 2017 02:51:52 -0700 From: tip-bot for Josh Poimboeuf Message-ID: Cc: rostedt@goodmis.org, bp@alien8.de, lenb@kernel.org, mingo@kernel.org, pmenzel@molgen.mpg.de, hpa@zytor.com, rjw@rjwysocki.net, jpoimboe@redhat.com, tglx@linutronix.de, linux-kernel@vger.kernel.org Reply-To: rjw@rjwysocki.net, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, jpoimboe@redhat.com, bp@alien8.de, rostedt@goodmis.org, lenb@kernel.org, mingo@kernel.org, pmenzel@molgen.mpg.de In-Reply-To: <5c1272269a580660703ed2eccf44308e790c7a98.1492123841.git.jpoimboe@redhat.com> References: <5c1272269a580660703ed2eccf44308e790c7a98.1492123841.git.jpoimboe@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] ftrace/x86: Fix triple fault with graph tracing and suspend-to-ram Git-Commit-ID: 34a477e5297cbaa6ecc6e17c042a866e1cbe80d6 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 34a477e5297cbaa6ecc6e17c042a866e1cbe80d6 Gitweb: http://git.kernel.org/tip/34a477e5297cbaa6ecc6e17c042a866e1cbe80d6 Author: Josh Poimboeuf AuthorDate: Thu, 13 Apr 2017 17:53:55 -0500 Committer: Thomas Gleixner CommitDate: Fri, 14 Apr 2017 11:48:51 +0200 ftrace/x86: Fix triple fault with graph tracing and suspend-to-ram On x86-32, with CONFIG_FIRMWARE and multiple CPUs, if you enable function graph tracing and then suspend to RAM, it will triple fault and reboot when it resumes. The first fault happens when booting a secondary CPU: startup_32_smp() load_ucode_ap() prepare_ftrace_return() ftrace_graph_is_dead() (accesses 'kill_ftrace_graph') The early head_32.S code calls into load_ucode_ap(), which has an an ftrace hook, so it calls prepare_ftrace_return(), which calls ftrace_graph_is_dead(), which tries to access the global 'kill_ftrace_graph' variable with a virtual address, causing a fault because the CPU is still in real mode. The fix is to add a check in prepare_ftrace_return() to make sure it's running in protected mode before continuing. The check makes sure the stack pointer is a virtual kernel address. It's a bit of a hack, but it's not very intrusive and it works well enough. For reference, here are a few other (more difficult) ways this could have potentially been fixed: - Move startup_32_smp()'s call to load_ucode_ap() down to *after* paging is enabled. (No idea what that would break.) - Track down load_ucode_ap()'s entire callee tree and mark all the functions 'notrace'. (Probably not realistic.) - Pause graph tracing in ftrace_suspend_notifier_call() or bringup_cpu() or __cpu_up(), and ensure that the pause facility can be queried from real mode. Reported-by: Paul Menzel Signed-off-by: Josh Poimboeuf Tested-by: Paul Menzel Reviewed-by: Steven Rostedt (VMware) Cc: "Rafael J . Wysocki" Cc: linux-acpi@vger.kernel.org Cc: Borislav Petkov Cc: stable@kernel.org Cc: Len Brown Link: http://lkml.kernel.org/r/5c1272269a580660703ed2eccf44308e790c7a98.1492123841.git.jpoimboe@redhat.com Signed-off-by: Thomas Gleixner --- arch/x86/kernel/ftrace.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index cbd73eb..0e5ceac 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -989,6 +989,18 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent, unsigned long return_hooker = (unsigned long) &return_to_handler; + /* + * When resuming from suspend-to-ram, this function can be indirectly + * called from early CPU startup code while the CPU is in real mode, + * which would fail miserably. Make sure the stack pointer is a + * virtual address. + * + * This check isn't as accurate as virt_addr_valid(), but it should be + * good enough for this purpose, and it's fast. + */ + if (unlikely((long)__builtin_frame_address(0) >= 0)) + return; + if (unlikely(ftrace_graph_is_dead())) return;