Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1514544imm; Sun, 27 May 2018 08:48:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp1qW1wb85P+nLaACKhGSVOvza3gvxOBwy+cEtFNmH3mLzZoC5sgGahyrWPN/OsCq8dcpIJ X-Received: by 2002:a62:883:: with SMTP id 3-v6mr10326204pfi.154.1527436083988; Sun, 27 May 2018 08:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527436083; cv=none; d=google.com; s=arc-20160816; b=A3PZO2zcthzv3GQdE20RsmLrJOxNL3GYWdGWKY+0SwTFCF5VIYERR/bduCvWhZxT3G bs6k9dPirCovKvyjjCcInhcb3PIvKpo36OFppftIrGJZktqCJC/kP0gpmc3GGeH6JZB4 q07WC3Nwojiz1fRjY2gdYYMCqLgkAA+Ix+ZHicEmiFAa35FnF80qO+kvQelZlVqCG+NE x60coNHfBhnJhXQr3BppzQsW6QCNKZGZrj9Ujc25j0YYhAOrwkbl5w5E207y6JJvjoLP YClcvSd90Bft0gk7hBbw/UpPZFh8Jsm7I52hU9CNn++sjKEgE9EwYmhIYsz54vySks4t xDvQ== 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=oezxhgRdgICIRAzice1hpp3a/lv9ClWhHRP/hX+eg30=; b=GMbc414zSVrDKUFwbL6IYnnhuPgx3BV4cQJWoy/DCC/D9O9HzmgtwB2QQgOqnANVLZ BDEWEOzxUlnTj32nG1uA358RGY6j5yU0Y8JQCsJB0LLPwvEfLskMcVeiVlfsQPzPhBbE ufelRuCmpuJwfBwxjyUbMLxBj61OuXh2GJuCtOgZ2qEppG6YTj5XWGVBovfoRACmEyx0 3Cm7v+jeViypU8svFrefLiXH1ZpZ0NX27ZGbEyjdSuTbpMSKI8AkNGdGiZB+5PGarFlT 3iDgdGyMUz8eVm5eicZLf901mQZ7UEy3pIPkf8q33PrHWc4zjECRXntmAsJ4g1c6SYiO zweQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17-v6si6785746pgw.440.2018.05.27.08.47.49; Sun, 27 May 2018 08:48:03 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032876AbeE0Pqa (ORCPT + 99 others); Sun, 27 May 2018 11:46:30 -0400 Received: from mga02.intel.com ([134.134.136.20]:28381 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032700AbeE0PqT (ORCPT ); Sun, 27 May 2018 11:46:19 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 May 2018 08:46:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,448,1520924400"; d="scan'208";a="227741079" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by orsmga005.jf.intel.com with ESMTP; 27 May 2018 08:46:13 -0700 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "H. Peter Anvin" Cc: "Ashok Raj" , "Dave Hansen" , "Rafael Wysocki" , "Tony Luck" , "Alan Cox" , "Ravi V Shankar" , "Arjan van de Ven" , "linux-kernel" , "x86" , Fenghua Yu Subject: [RFC PATCH 06/16] x86/split_lock: Save #AC setting for split lock in firmware in boot time and restore the setting in reboot Date: Sun, 27 May 2018 08:45:55 -0700 Message-Id: <1527435965-202085-7-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1527435965-202085-1-git-send-email-fenghua.yu@intel.com> References: <1527435965-202085-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 Firmware may contain split locked instructions. #AC handler in firmware may treat split lock as fatal fault and stop execution. If kernel enables #AC exception for split locked accesses and then kernel returns to firmware during reboot, the firmware reboot code may hit #AC exception and block the reboot. This issue happens in reality. Instead of debugging the buggy firmware, setting of #AC for split lock is restored to original firmware setting to hide the potential firmware issue and allow kernel reboot succeed. Signed-off-by: Fenghua Yu --- arch/x86/include/asm/cpu.h | 2 ++ arch/x86/kernel/cpu/test_ctl.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index 00f453fd44ac..45fec729c470 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -44,6 +44,7 @@ unsigned int x86_stepping(unsigned int sig); void detect_split_lock_ac(void); bool do_split_lock_exception(struct pt_regs *regs, unsigned long error_code); void setup_split_lock(void); +void restore_split_lock_ac_firmware(void); #else /* CONFIG_SPLIT_LOCK_AC */ static inline void detect_split_lock_ac(void) {} static inline bool @@ -53,5 +54,6 @@ do_split_lock_exception(struct pt_regs *regs, unsigned long error_code) } static inline void setup_split_lock(void) {} +static inline void restore_split_lock_ac_firmware(void) {} #endif /* CONFIG_SPLIT_LOCK_AC */ #endif /* _ASM_X86_CPU_H */ diff --git a/arch/x86/kernel/cpu/test_ctl.c b/arch/x86/kernel/cpu/test_ctl.c index c72c0517c6ab..9e47f8174a47 100644 --- a/arch/x86/kernel/cpu/test_ctl.c +++ b/arch/x86/kernel/cpu/test_ctl.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #define DISABLE_SPLIT_LOCK_AC 0 @@ -29,6 +30,7 @@ static unsigned long disable_split_lock_jiffies; static DEFINE_MUTEX(reexecute_split_lock_mutex); static int split_lock_ac_kernel = DISABLE_SPLIT_LOCK_AC; +static int split_lock_ac_firmware = DISABLE_SPLIT_LOCK_AC; /* Detete feature of #AC for split lock by probing bit 29 in MSR_TEST_CTL. */ void detect_split_lock_ac(void) @@ -62,6 +64,12 @@ void detect_split_lock_ac(void) * before leaving. */ wrmsrl(MSR_TEST_CTL, orig_val); + + /* Get previous firmware setting. */ + if (orig_val & MSR_TEST_CTL_ENABLE_AC_SPLIT_LOCK) + split_lock_ac_firmware = ENABLE_SPLIT_LOCK_AC; + else + split_lock_ac_firmware = DISABLE_SPLIT_LOCK_AC; } static void _setup_split_lock(int split_lock_ac_val) @@ -86,6 +94,41 @@ static void _setup_split_lock(int split_lock_ac_val) wrmsrl(MSR_TEST_CTL, val); } +static void restore_split_lock_ac(int split_lock_ac_val) +{ + _setup_split_lock(split_lock_ac_val); +} + +/* Restore firmware setting for #AC exception for split lock. */ +void restore_split_lock_ac_firmware(void) +{ + if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_AC)) + return; + + /* Don't restore the firmware setting if kernel didn't change it. */ + if (split_lock_ac_kernel == split_lock_ac_firmware) + return; + + restore_split_lock_ac(split_lock_ac_firmware); +} + +static void split_lock_cpu_reboot(void *unused) +{ + restore_split_lock_ac_firmware(); +} + +static int split_lock_reboot_notify(struct notifier_block *nb, + unsigned long code, void *unused) +{ + on_each_cpu_mask(cpu_online_mask, split_lock_cpu_reboot, NULL, 1); + + return NOTIFY_DONE; +} + +static struct notifier_block split_lock_reboot_nb = { + .notifier_call = split_lock_reboot_notify, +}; + void setup_split_lock(void) { if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_AC)) @@ -221,6 +264,8 @@ static int __init split_lock_init(void) if (ret < 0) return ret; + register_reboot_notifier(&split_lock_reboot_nb); + return 0; } -- 2.5.0