Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1515893imm; Sun, 27 May 2018 08:50:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKbrHJUSFfHTvbr/SIChU8rFKYRy/qLVZXM+dQWN26mBI8D6ezCzUhPfj7jiNuWSFQGlQkw X-Received: by 2002:aa7:8051:: with SMTP id y17-v6mr1393335pfm.148.1527436218736; Sun, 27 May 2018 08:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527436218; cv=none; d=google.com; s=arc-20160816; b=pLwA43vtdvIAghuEtpunB5tOgQQN5uFKDCIwE7o9Sz0CHlWuoC0MUAg4UYZtzogmNT Jih6GPJtYP2AGFz1BeY2+hrib/CTeD45tB1te/SaSMf21qxt85NKpW7qUe+GWGNEDOpJ /y0zFgwEeQt7+q1psVm7rxJQU+zoMP2ZSIaDstUm91kh3vOv/P9VzWuL9EWdxsVtTqZ8 XQEfrGqXzWdSZGDYkBdiH1QFCHNtk+7Bfbd1pW9lsYHPkxs6JsY7E8ykl3oqkz8ApwhH U+oCF5O9TUNp+D8rkE3se75FauLPvE6WsGPH4GsJKF66JZ+sidQcjMNQ+qxdrjr3Dpkq +vtw== 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=+W/oCjASt4tIVHDkRaZtCYKzwvJhDsSvIEmXPp5IG9E=; b=E39imB08IjTWQDVJFFVgVklesyQOdyE3AmMkRRjuEy2UXV0VnocSONHTeUwSR5U7MQ wlKXTia3vCzI5/3r0JSfJ/TspvLEc1Sr/LY7A+mKjfaUG0O0AfBepGqJ5x7Pn8rmVmka 11Sw++OrrckKPe2gewLnBUyb6qeahp2+6DjcoGRrRKPbEllIgMA+RKvPyLV6py/1Mkh1 KYCbPM6y67iGtRpB3/RomQGvqvqdy4ZUpjGJgUtXeClipwy+YJMAU8OxRs+Zv434sMQ8 vboYxboWFfP2pAZO0jRTmvi+GGm5Z3Jps+JAm2N4a2kdjcEZrzv63JpiLzP3CK9xNL4g crOA== 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 p11-v6si27630614pfh.249.2018.05.27.08.50.03; Sun, 27 May 2018 08:50:18 -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 S1032935AbeE0Pst (ORCPT + 99 others); Sun, 27 May 2018 11:48:49 -0400 Received: from mga02.intel.com ([134.134.136.20]:28379 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032803AbeE0PqU (ORCPT ); Sun, 27 May 2018 11:46:20 -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:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,448,1520924400"; d="scan'208";a="227741099" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by orsmga005.jf.intel.com with ESMTP; 27 May 2018 08:46:15 -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 11/16] x86/split_lock: Add CONFIG to control #AC for split lock from kernel at boot time Date: Sun, 27 May 2018 08:46:00 -0700 Message-Id: <1527435965-202085-12-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 By default, faulting kernel instruction that generates #AC due to split locked access is re-executed and doesn't block system. But in cases when user doesn't tolerate any split lock (e.g. in hard real time system), CONFIG_SPLIT_LOCK_AC_PANIC_ON_KERNEL is added to opt-in panic when #AC for split lock is triggered from kernel. If it's configured as N (default), faulting instruction in kernel mode will be recorded in #AC handler and re-executed. Split lock is not treated as fatal fault. If configured as Y, kernel will panic if #AC triggered by split lock is from a kernel instruction. Signed-off-by: Fenghua Yu --- arch/x86/Kconfig | 13 +++++++++++++ arch/x86/kernel/cpu/test_ctl.c | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1d0dcd6fa69a..d42d90abd644 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -475,6 +475,19 @@ config SPLIT_LOCK_AC_ENABLE_DEFAULT Leave this to the default value of 2 if you are unsure. +config SPLIT_LOCK_AC_PANIC_ON_KERNEL + bool "Panic on #AC for split lock in kernel mode" + default n + depends on SPLIT_LOCK_AC + help + If you enable this option, kernel goes to panic when hitting + #AC for split lock from kernel. + + If you disable this option, the kernel faulting instruction + is re-executed after hitting #AC for split lock. + + Say N if unsure. + if X86_32 config X86_BIGSMP bool "Support for big SMP systems with more than 8 CPUs" diff --git a/arch/x86/kernel/cpu/test_ctl.c b/arch/x86/kernel/cpu/test_ctl.c index e8b3032f3db0..6784f68af26a 100644 --- a/arch/x86/kernel/cpu/test_ctl.c +++ b/arch/x86/kernel/cpu/test_ctl.c @@ -43,6 +43,14 @@ struct debugfs_file { const struct file_operations *fops; }; +enum { + KERNEL_MODE_RE_EXECUTE, + KERNEL_MODE_PANIC, + KERNEL_MODE_LAST +}; + +static int kernel_mode_reaction = KERNEL_MODE_RE_EXECUTE; + /* Detete feature of #AC for split lock by probing bit 29 in MSR_TEST_CTL. */ void detect_split_lock_ac(void) { @@ -238,6 +246,10 @@ bool do_split_lock_exception(struct pt_regs *regs, unsigned long error_code) struct task_struct *tsk = current; int cpu = task_cpu(tsk); + /* If configured as panic for split lock in kernel mode, panic. */ + if (kernel_mode_reaction == KERNEL_MODE_PANIC && !user_mode(regs)) + panic("Alignment Check exception for split lock in kernel."); + if (!re_execute(regs)) return false; @@ -391,6 +403,9 @@ static int __init split_lock_init(void) if (ret) pr_warn("debugfs for #AC for split lock cannot be set up\n"); + if (IS_ENABLED(CONFIG_SPLIT_LOCK_AC_PANIC_ON_KERNEL)) + kernel_mode_reaction = KERNEL_MODE_PANIC; + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/split_lock:online", split_lock_online, split_lock_offline); if (ret < 0) -- 2.5.0