Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2437677ybi; Sun, 9 Jun 2019 11:47:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3m07iZ/M+t3Jqy7PJoA2UCUa4RHjgc89prfQztGJ79kMvQ3XPf0l4JXu1rbaz9Oi1MsgS X-Received: by 2002:a62:36c1:: with SMTP id d184mr72280713pfa.49.1560106055395; Sun, 09 Jun 2019 11:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560106055; cv=none; d=google.com; s=arc-20160816; b=SSj2hwJxKXvrCYy3OyXFoCE+7hQudArmJKmZiK0mAgYaj6ePqVz5lilTtc5XI2FyvE xQosUJIZnuXI6eHLniBHRYar+2XP8I3BlSMu3hHqyRlqqsATZ+GI3pMySIOgSlHWi8l6 fw8DfG6swu7u3JB2pZPHYiu2i25vL9K9KBOVrmBh/+thB+EEfE8IWOLP9vptJWCq2S2Z GmdZ244tgqbPUwDejzXW2v+PpH/a4RaHN/tLHD5z4+X6ROyU13LwR7U1HyoZCTRToMeu MTarnsIgfe+IBq9ZXTDAzN5aSE10i49KsQH3i2NfO6FPT3ZM+Ta8o7uW4+DiuyvEjC6a jNxg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qbsXrhqD1hkQZ0uAnwZiGUnNCpi53TsOgyIY96FeKJw=; b=C8bkR6XmHWqWBiykn7e05JndjmGPXzP1aIiPgbILXVU2IdOjviBXzMoYrLljkwci+5 GctBCjjhYFhtpLjFTXPql+5OsRgJnKisT72iEHav42/ZoZKP8riDz7A7JAa9N5jynhnO b9qWMoczA9NAKJ8trdNkQ3yu2n8OwPZUk9KZ2knH3vy/szMCfyXjjOCpKzBSh46kM4iz x/4NVXCRj6MlMxqEdI9e5EASYkVVTRHEc+1d+8HlbLapQSDESXW8Tv2KopWEMFdXAJ5j v7wVU3QJ1z6Fs2Ke8WnaAW/cn+MoIADkFiPG5esKuzKY6uIL/r/Lbw0MuOkVyBTEIrEs miIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FZQAB4lO; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j15si8166543pgs.43.2019.06.09.11.47.19; Sun, 09 Jun 2019 11:47:35 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FZQAB4lO; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730445AbfFIRUo (ORCPT + 99 others); Sun, 9 Jun 2019 13:20:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:45448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729678AbfFIQq7 (ORCPT ); Sun, 9 Jun 2019 12:46:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5F5C720833; Sun, 9 Jun 2019 16:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560098818; bh=+DdyUJJARkx/BvERWHEtustyPlb2PjQGw2nsot5s5Uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FZQAB4lOvZRExp0DvX0PvrpxfvwKwYMQL6ezzrWIHRcVcQ7xBsCb2yd/q+RhTErxa gBou9PDTIQIg7cMWArRzpBKbYsCdcAsbc07BRvbQCT5Rv7ypm3GI+IeCI4KjvaGHzs 0xfZVsOs2thr87Bd2rVtQZW8n3r6sOxo5ROKNFHI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Kosina , Pavel Machek , Thomas Gleixner , Josh Poimboeuf , "Rafael J. Wysocki" Subject: [PATCH 5.1 39/70] x86/power: Fix nosmt vs hibernation triple fault during resume Date: Sun, 9 Jun 2019 18:41:50 +0200 Message-Id: <20190609164130.488111346@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164127.541128197@linuxfoundation.org> References: <20190609164127.541128197@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Kosina commit ec527c318036a65a083ef68d8ba95789d2212246 upstream. As explained in 0cc3cd21657b ("cpu/hotplug: Boot HT siblings at least once") we always, no matter what, have to bring up x86 HT siblings during boot at least once in order to avoid first MCE bringing the system to its knees. That means that whenever 'nosmt' is supplied on the kernel command-line, all the HT siblings are as a result sitting in mwait or cpudile after going through the online-offline cycle at least once. This causes a serious issue though when a kernel, which saw 'nosmt' on its commandline, is going to perform resume from hibernation: if the resume from the hibernated image is successful, cr3 is flipped in order to point to the address space of the kernel that is being resumed, which in turn means that all the HT siblings are all of a sudden mwaiting on address which is no longer valid. That results in triple fault shortly after cr3 is switched, and machine reboots. Fix this by always waking up all the SMT siblings before initiating the 'restore from hibernation' process; this guarantees that all the HT siblings will be properly carried over to the resumed kernel waiting in resume_play_dead(), and acted upon accordingly afterwards, based on the target kernel configuration. Symmetricaly, the resumed kernel has to push the SMT siblings to mwait again in case it has SMT disabled; this means it has to online all the siblings when resuming (so that they come out of hlt) and offline them again to let them reach mwait. Cc: 4.19+ # v4.19+ Debugged-by: Thomas Gleixner Fixes: 0cc3cd21657b ("cpu/hotplug: Boot HT siblings at least once") Signed-off-by: Jiri Kosina Acked-by: Pavel Machek Reviewed-by: Thomas Gleixner Reviewed-by: Josh Poimboeuf Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- arch/x86/power/cpu.c | 10 ++++++++++ arch/x86/power/hibernate.c | 33 +++++++++++++++++++++++++++++++++ include/linux/cpu.h | 4 ++++ kernel/cpu.c | 4 ++-- kernel/power/hibernate.c | 9 +++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -299,7 +299,17 @@ int hibernate_resume_nonboot_cpu_disable * address in its instruction pointer may not be possible to resolve * any more at that point (the page tables used by it previously may * have been overwritten by hibernate image data). + * + * First, make sure that we wake up all the potentially disabled SMT + * threads which have been initially brought up and then put into + * mwait/cpuidle sleep. + * Those will be put to proper (not interfering with hibernation + * resume) sleep afterwards, and the resumed kernel will decide itself + * what to do with them. */ + ret = cpuhp_smt_enable(); + if (ret) + return ret; smp_ops.play_dead = resume_play_dead; ret = disable_nonboot_cpus(); smp_ops.play_dead = play_dead; --- a/arch/x86/power/hibernate.c +++ b/arch/x86/power/hibernate.c @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -246,3 +247,35 @@ out: __flush_tlb_all(); return 0; } + +int arch_resume_nosmt(void) +{ + int ret = 0; + /* + * We reached this while coming out of hibernation. This means + * that SMT siblings are sleeping in hlt, as mwait is not safe + * against control transition during resume (see comment in + * hibernate_resume_nonboot_cpu_disable()). + * + * If the resumed kernel has SMT disabled, we have to take all the + * SMT siblings out of hlt, and offline them again so that they + * end up in mwait proper. + * + * Called with hotplug disabled. + */ + cpu_hotplug_enable(); + if (cpu_smt_control == CPU_SMT_DISABLED || + cpu_smt_control == CPU_SMT_FORCE_DISABLED) { + enum cpuhp_smt_control old = cpu_smt_control; + + ret = cpuhp_smt_enable(); + if (ret) + goto out; + ret = cpuhp_smt_disable(old); + if (ret) + goto out; + } +out: + cpu_hotplug_disable(); + return ret; +} --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -183,10 +183,14 @@ enum cpuhp_smt_control { extern enum cpuhp_smt_control cpu_smt_control; extern void cpu_smt_disable(bool force); extern void cpu_smt_check_topology(void); +extern int cpuhp_smt_enable(void); +extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval); #else # define cpu_smt_control (CPU_SMT_ENABLED) static inline void cpu_smt_disable(bool force) { } static inline void cpu_smt_check_topology(void) { } +static inline int cpuhp_smt_enable(void) { return 0; } +static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; } #endif /* --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -2064,7 +2064,7 @@ static void cpuhp_online_cpu_device(unsi kobject_uevent(&dev->kobj, KOBJ_ONLINE); } -static int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) +int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { int cpu, ret = 0; @@ -2096,7 +2096,7 @@ static int cpuhp_smt_disable(enum cpuhp_ return ret; } -static int cpuhp_smt_enable(void) +int cpuhp_smt_enable(void) { int cpu, ret = 0; --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -258,6 +258,11 @@ void swsusp_show_speed(ktime_t start, kt (kps % 1000) / 10); } +__weak int arch_resume_nosmt(void) +{ + return 0; +} + /** * create_image - Create a hibernation image. * @platform_mode: Whether or not to use the platform driver. @@ -325,6 +330,10 @@ static int create_image(int platform_mod Enable_cpus: enable_nonboot_cpus(); + /* Allow architectures to do nosmt-specific post-resume dances */ + if (!in_suspend) + error = arch_resume_nosmt(); + Platform_finish: platform_finish(platform_mode);