Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1513984imm; Sun, 27 May 2018 08:47:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqcDL1zK3RIYh1Ca/puYsamFTUgc2cp6hs/ukj/FHKNbXst32bYXww4kDzg0h1eeM5jbphh X-Received: by 2002:a63:7209:: with SMTP id n9-v6mr8018579pgc.146.1527436028319; Sun, 27 May 2018 08:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527436028; cv=none; d=google.com; s=arc-20160816; b=VMo80/cqUeoCT/QzeDPfBnBQF/5COq4Nv09Doso2IgKSvRmzpz/QRgXoS4DiRqy9PW 8vK1T4LriJ0mCXvZC8kQbpHOXRQ2TPqFzQonMuhKeCiI61uydi022CHICJ6HGCEOI616 PRUTTGjSgC0EB7S7zUn9BxsUaa46KlQRkHr/K0I8IhBp/ykHyTfk9srUHSFZzCT1tOjX QvT4SddXq7A/pJhgyyYKxTwe/y1YC54XObaP4VFWUfdZQRo1EQfa7uIwnUtbUExiFIGC 1pMLL1lA6i18ifxQViEZQtXntL3xevrvZ6vv+jGPRRKQUcp/octvhqBPQa0VPST5VjQX dEuQ== 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=Hjll53pcXMWGbl0tuVv399DxousWHB3CoQwifsbTM8o=; b=MkFKo2qgbzWd43vaqGZpa8ZIazL+mk6BBB/2YSz0bMGx2A1rIa9Wk8sLRng7uAuBTK SwW593DkucfbwWfvcCZCVpqWtL/KN3/rSUUteyGPTIh3zq11c5BeBZtCtx2QgrFpflzS qnEfoUBwmcOCv/Rkt/Dx3eNA+nYYNlDd8kOtOVD3fI3DiET+B2ipfWisq7PyBf6EPB+S aLtu/3OLXlrL/8Tgz5f2nQp7Bz6sR8R9be2+/5qrbHmznQ9j9f/wkLJQHDBofYdSp2Ju k9cImXCYfiymdq0MXRR8WldinZptX5xj+Ph7hfjk2etkwlU/xxf/onPkzmccs1CGj9NY hNWg== 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 l7-v6si17236744pgq.121.2018.05.27.08.46.49; Sun, 27 May 2018 08:47:08 -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 S1032786AbeE0Pqe (ORCPT + 99 others); Sun, 27 May 2018 11:46:34 -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 S1032815AbeE0PqV (ORCPT ); Sun, 27 May 2018 11:46:21 -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="227741102" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by orsmga005.jf.intel.com with ESMTP; 27 May 2018 08:46:16 -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 12/16] x86/split_lock: Add a debugfs interface to allow user to change how to handle split lock in kernel mode during run time Date: Sun, 27 May 2018 08:46:01 -0700 Message-Id: <1527435965-202085-13-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 CONFIG_SPLIT_LOCK_AC_PANIC_ON_KERNEL defines how to handle split lock in kernel mode by default. But sometimes user wants to change the default behavior. The interface /sys/kernel/debug/x86/split_lock/kernel_mode is added to allow user to do so. For example, the interface shows "[re-execute] panic" which means two behaviors: re-execute kernel faulting instruction after #AC (default) and panic in #AC. User can change the default behavior by writing "re-execute" or "panic" to the interface. Signed-off-by: Fenghua Yu --- arch/x86/kernel/cpu/test_ctl.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/arch/x86/kernel/cpu/test_ctl.c b/arch/x86/kernel/cpu/test_ctl.c index 6784f68af26a..0212a7979a14 100644 --- a/arch/x86/kernel/cpu/test_ctl.c +++ b/arch/x86/kernel/cpu/test_ctl.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #define DISABLE_SPLIT_LOCK_AC 0 @@ -49,6 +50,11 @@ enum { KERNEL_MODE_LAST }; +static const char * const kernel_modes[KERNEL_MODE_LAST] = { + [KERNEL_MODE_RE_EXECUTE] = "re-execute", + [KERNEL_MODE_PANIC] = "panic", +}; + static int kernel_mode_reaction = KERNEL_MODE_RE_EXECUTE; /* Detete feature of #AC for split lock by probing bit 29 in MSR_TEST_CTL. */ @@ -361,10 +367,93 @@ static int enable_store(void *data, u64 val) DEFINE_DEBUGFS_ATTRIBUTE(enable_ops, enable_show, enable_store, "%llx\n"); +static ssize_t +mode_show(char __user *user_buf, const char * const *modes, int start_reaction, + int last_reaction, int mode_reaction, size_t count, loff_t *ppos) +{ + char buf[32], *s = buf; + int reaction, len; + + mutex_lock(&split_lock_mutex); + for (reaction = start_reaction; reaction < last_reaction; reaction++) { + if (reaction == mode_reaction) + s += sprintf(s, "[%s] ", modes[reaction]); + else + s += sprintf(s, "%s ", modes[reaction]); + } + + if (s != buf) + /* convert the last space to a newline */ + *(s - 1) = '\n'; + mutex_unlock(&split_lock_mutex); + + len = strlen(buf); + + return simple_read_from_buffer(user_buf, count, ppos, buf, len); +} + +static ssize_t +mode_store(const char __user *user_buf, size_t count, const char * const *modes, + int start_reaction, int last_reaction, int *mode_reaction) +{ + int reaction, len, ret = -EINVAL; + const char * const *s, *p; + char buf[32]; + + len = min(count, sizeof(buf) - 1); + if (copy_from_user(buf, user_buf, len)) + return -EFAULT; + + buf[len] = '\0'; + + mutex_lock(&split_lock_mutex); + p = memchr(buf, '\n', count); + len = p ? p - buf : count; + + reaction = start_reaction; + for (s = &modes[reaction]; reaction < last_reaction; s++, reaction++) { + if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) { + *mode_reaction = reaction; + ret = 0; + break; + } + } + mutex_unlock(&split_lock_mutex); + + return ret; +} + +static ssize_t kernel_mode_show(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + return mode_show(user_buf, kernel_modes, KERNEL_MODE_RE_EXECUTE, + KERNEL_MODE_LAST, kernel_mode_reaction, count, ppos); +} + +static ssize_t kernel_mode_store(struct file *file, const char __user *user_buf, + size_t count, loff_t *ppos) +{ + int ret; + + ret = mode_store(user_buf, count, kernel_modes, KERNEL_MODE_RE_EXECUTE, + KERNEL_MODE_LAST, &kernel_mode_reaction); + if (ret) + return ret; + + return count; +} + +static const struct file_operations kernel_mode_ops = { + .read = kernel_mode_show, + .write = kernel_mode_store, + .llseek = default_llseek, +}; + static int __init debugfs_setup_split_lock(void) { struct debugfs_file debugfs_files[] = { {"enable", 0600, &enable_ops}, + {"kernel_mode", 0600, &kernel_mode_ops }, }; struct dentry *split_lock_dir, *fd; int i; -- 2.5.0