Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4726548imm; Mon, 14 May 2018 11:56:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqeNDf4DqBdj70bO0cJridxE3aGBjmUXQiCsda1VCWfHu4gQy0k1t5oWSYP0qBbnM0uKPZv X-Received: by 2002:a17:902:1023:: with SMTP id b32-v6mr11027097pla.145.1526324205657; Mon, 14 May 2018 11:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526324205; cv=none; d=google.com; s=arc-20160816; b=SAroAGGVUd/oB2tK5DoVIud2iB1t1b0kQWTkMSPl8XVOGH5aqErKFW1FSbQ16cPBbJ BDhw9gemMzYVpCCaONGpN/dTB9EL7YUyi+MkzpZQ8AAIy6QkWxJr69YXougWnxCig1gu /WahtkR3OUQzZYh3DoycOKjv8UbRhHzAv+3NadRor/EP/KhhBB2SyefGSmywhTTHxha0 sy6/teUD9tSchx8aE0cxtvkbUclppacqcLLiyhR1b2kfOcNAj3XMc3W/5c/IUNPrk1vi DoWtJXQVMbCsr15vWHlpF4eDppElN/MVZP8+LLdS/4wFXrg/svzB90bDnjX6rJgXQknx 5Kjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=EBMh8aZiAYeM324FGMxfKY3JVR6jnkhV8cnzRzZw87A=; b=C9RYABsb/eHqnsjm3SCPqiSPi+Dg2xfQYLQAsDgdTxWzckzs2bhjBK9Ucy8QYeIacb 7TyNfLJzV7RtMs0lBXTgNWgnvCrgv3PpfegeGjNSJYnrq4uJb/S7u+/+d96RHzSqmzxJ 9UW0BctrFmAXisevM/AlgFOuT1Ce5W6xYtaIFTNSG5kyIkfdrFjRwqKMOsOGj/MHtxMH 1UPCYlZ0GB6LhiX9fBXMEh/RhiZ9M7mikTC1hfTnXnt5+EKqSJSg1VO+pnSJ1Keez/Y4 kPN2vbk3I2RGuivO3LnII3pNTHO4c1opalFkCf4CEKUl1sDWnaZEyQbzpfEC7IJsZl0a WLcg== ARC-Authentication-Results: i=1; mx.google.com; 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 o13-v6si3883004pgs.491.2018.05.14.11.56.31; Mon, 14 May 2018 11:56:45 -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; 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 S1752350AbeENSyR (ORCPT + 99 others); Mon, 14 May 2018 14:54:17 -0400 Received: from mga06.intel.com ([134.134.136.31]:55031 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752044AbeENSwa (ORCPT ); Mon, 14 May 2018 14:52:30 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2018 11:52:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,401,1520924400"; d="scan'208";a="39244641" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by fmsmga007.fm.intel.com with ESMTP; 14 May 2018 11:52:27 -0700 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "H. Peter Anvin" , "Ashok Raj" , "Ravi V Shankar" , "Tony Luck" , "Dave Hansen" , "Rafael Wysocki" , "Arjan van de Ven" , "Alan Cox" Cc: "x86" , "linux-kernel" , Fenghua Yu Subject: [PATCH 07/15] x86/split_lock: Handle suspend/hibernate and resume Date: Mon, 14 May 2018 11:52:17 -0700 Message-Id: <1526323945-211107-8-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1526323945-211107-1-git-send-email-fenghua.yu@intel.com> References: <1526323945-211107-1-git-send-email-fenghua.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During suspend or hibernation, system enters BIOS. To avoid potential BIOS issue that may generate #AC exception for split locked accesses, handle the #AC as fatal exception, and block suspend or hibernation, the split lock setting is restored to BIOS setting. When resuming from suspend or hibernation, the split lock setting is restored to kernel setting. Signed-off-by: Fenghua Yu --- arch/x86/include/asm/cpu.h | 2 ++ arch/x86/kernel/cpu/split_lock.c | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index 0b00033b6fa8..89d62d7051fa 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -45,11 +45,13 @@ int __init enumerate_split_lock(void); void setup_split_lock(void); bool do_split_lock_exception(struct pt_regs *regs, unsigned long error_code); bool restore_split_lock_ac_bios(int *enable); +bool restore_split_lock_ac_kernel(int *enable); #else /* CONFIG_SPLIT_LOCK_AC */ static inline int enumerate_split_lock(void) { return 0; } static inline void setup_split_lock(void) {} static inline bool do_split_lock_exception(struct pt_regs *regs, unsigned long error_code) {} static inline bool restore_split_lock_ac_bios(int *enable) { return true; } +static inline bool restore_split_lock_ac_kernel(int *enable) { return true; } #endif /* CONFIG_SPLIT_LOCK_AC */ #endif /* _ASM_X86_CPU_H */ diff --git a/arch/x86/kernel/cpu/split_lock.c b/arch/x86/kernel/cpu/split_lock.c index d2735259800b..5187a9c6cea6 100644 --- a/arch/x86/kernel/cpu/split_lock.c +++ b/arch/x86/kernel/cpu/split_lock.c @@ -14,6 +14,7 @@ #include #include #include +#include #include static bool split_lock_ac_supported; @@ -143,6 +144,15 @@ bool restore_split_lock_ac_bios(int *enable) return restore_split_lock_ac(split_lock_ac_bios); } +/* Restore kernel setting for #AC enable bit for split lock. */ +bool restore_split_lock_ac_kernel(int *enable) +{ + if (enable) + *enable = split_lock_ac == ENABLE_SPLIT_LOCK_AC ? 1 : 0; + + return restore_split_lock_ac(split_lock_ac); +} + static void split_lock_cpu_reboot(void *unused) { restore_split_lock_ac_bios(NULL); @@ -223,11 +233,55 @@ bool do_split_lock_exception(struct pt_regs *regs, unsigned long error_code) return true; } +static int split_lock_offline(unsigned int cpu) +{ + int enable; + + if (restore_split_lock_ac_bios(&enable)) + pr_info("%s split lock on CPU%d\n", + enable ? "enable" : "disable", smp_processor_id()); + + return 0; +} + +static int split_lock_bsp_suspend(void) +{ + restore_split_lock_ac_bios(NULL); + + return 0; +} + +static void split_lock_bsp_resume(void) +{ + restore_split_lock_ac_kernel(NULL); +} + +static struct syscore_ops split_lock_syscore_ops = { + .suspend = split_lock_bsp_suspend, + .resume = split_lock_bsp_resume, +}; + static int __init split_lock_init(void) { + int ret; + + if (!split_lock_ac_supported) + return -ENODEV; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, + "x86/split_lock:online:", + NULL, split_lock_offline); + if (ret < 0) + goto out_fail; + + register_syscore_ops(&split_lock_syscore_ops); + register_reboot_notifier(&split_lock_reboot_nb); return 0; + +out_fail: + return ret; } late_initcall(split_lock_init); -- 2.5.0