Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp565561yba; Wed, 3 Apr 2019 14:34:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwII/jYt5hdw2jUz8IwZlGvuQo9+uqjQ9uGzHFJGon2/tUFYros1M/C//7cSAlzrLg6oce X-Received: by 2002:a62:cfc4:: with SMTP id b187mr1815053pfg.130.1554327248442; Wed, 03 Apr 2019 14:34:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554327248; cv=none; d=google.com; s=arc-20160816; b=GCUnht0rX3eDTB7hLNSTFwHS+tCQNzpuO0JY5uW7Sow85wO2bOI/oO3XA4LiaI8CAs qiInRwSY7lTioZqNkQ8aAsM1SZw0dmWxpmOcN9B7rrm+chRllDOQ39LUi5DQvFuzf++v 2A/QBAoA8+lYS+980T+ct/5LWz6t3KXngeeC98SMBuy4qB4UJ9aLfSaVelBLuvs+28yj ktSFym3onX5pZ3la2I2+Llf4Qlwd0Z00a+wD3XiJxsaxkhF8AnSGrFGUAHgPoGZqf7Fo BGGdnrgDV3Kdic6/drAG0nYGwhQIAHuqfqdCpi6TPtrtNQ9/lRNf3/Mjub3hwVBuCK3j fKQA== 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; bh=L7n1/RcvGNqxSf3HC/RiUGX9iYZ8ESqaL3bhXusLTm4=; b=QoM0h9A/y7vE+AnqoYfc5MGifPvCLBkHkDE99hpfWVl9SgnY8EntLgDSNEq7bpH5mm SzzVKUAqoEcVOAM8XBwtE57lTJY2i5ueeRJ8uw6sUEJ+kOZx1gnbmPcY99dFY2+c6N/v 0zT1S17r5txQHnQ/m1Nffx7rloUBF3y5zSSf8yjA4c9vARTfPx36MyVNJVthELCL5Otm JOUbWACv7660/YhoLVnagFKexejnVg54so3RzPLwGy76HcqJk0C2dKW9Ty/QXv6c0unY JiWyngIsd5l0XVicGlEdxxc2KdqSVskwhEHigd1mWaKPqL6Swnz4822zRF0Tq4KAJcCX EkSQ== 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 z72si14704684pgd.401.2019.04.03.14.33.53; Wed, 03 Apr 2019 14:34: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 S1728729AbfDCVco (ORCPT + 99 others); Wed, 3 Apr 2019 17:32:44 -0400 Received: from mga05.intel.com ([192.55.52.43]:37323 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbfDCVaT (ORCPT ); Wed, 3 Apr 2019 17:30:19 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2019 14:30:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,306,1549958400"; d="scan'208";a="334754267" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by fmsmga005.fm.intel.com with ESMTP; 03 Apr 2019 14:30:12 -0700 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "H Peter Anvin" , "Dave Hansen" , "Paolo Bonzini" , "Ashok Raj" , "Peter Zijlstra" , "Kalle Valo" , "Xiaoyao Li " , "Michael Chan" , "Ravi V Shankar" Cc: "linux-kernel" , "x86" , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Fenghua Yu Subject: [PATCH v6 14/20] x86/split_lock: Add a sysfs interface to enable/disable split lock detection during run time Date: Wed, 3 Apr 2019 14:22:00 -0700 Message-Id: <1554326526-172295-15-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1554326526-172295-1-git-send-email-fenghua.yu@intel.com> References: <1554326526-172295-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 The interface /sys/device/system/cpu/split_lock_detect is added to allow user to control split lock detection and show current split lock detection setting. Writing 1 to the file enables split lock detection and writing 0 disables split lock detection. Split lock detection is enabled or disabled on all CPUs. Reading the file returns current global split lock detection setting: 0: disabled 1: enabled Please note the interface only shows global setting. During run time, split lock detection on one CPU may be disabled if split lock in kernel code happens on the CPU. The interface doesn't show split lock detection status on individual CPU. User can run rdmsr on 0x33 to check split lock detection on each CPU. Signed-off-by: Fenghua Yu --- arch/x86/kernel/cpu/intel.c | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index ae3e327d5e35..166033fa8423 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -1102,3 +1102,69 @@ void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c) if (ia32_core_cap & CORE_CAP_SPLIT_LOCK_DETECT) set_split_lock_detect(); } + +static ssize_t +split_lock_detect_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "%u\n", READ_ONCE(split_lock_detect_val)); +} + +static ssize_t +split_lock_detect_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + u32 val, l, h; + int cpu, ret; + + ret = kstrtou32(buf, 10, &val); + if (ret) + return ret; + + if (val != DISABLE_SPLIT_LOCK_DETECT && val != ENABLE_SPLIT_LOCK_DETECT) + return -EINVAL; + + /* + * Since split lock could be disabled by kernel #AC handler or user + * may directly change bit 29 in MSR_TEST_CTL, split lock setting on + * each CPU may be different from global setting split_lock_detect_val + * by now. Update MSR on each CPU, so all of CPUs will have same split + * lock setting. + */ + mutex_lock(&split_lock_detect_mutex); + + WRITE_ONCE(split_lock_detect_val, val); + + /* + * Get MSR_TEST_CTL on this CPU, assuming all CPUs have same value + * in the MSR except split lock detection bit (bit 29). + */ + rdmsr(MSR_TEST_CTL, l, h); + l = new_sp_test_ctl_val(l); + /* Update the split lock detection setting on all online CPUs. */ + for_each_online_cpu(cpu) + wrmsr_on_cpu(cpu, MSR_TEST_CTL, l, h); + + mutex_unlock(&split_lock_detect_mutex); + + return count; +} + +static DEVICE_ATTR_RW(split_lock_detect); + +static int __init split_lock_init(void) +{ + int ret; + + if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT)) + return -ENODEV; + + ret = device_create_file(cpu_subsys.dev_root, + &dev_attr_split_lock_detect); + if (ret) + return ret; + + return 0; +} + +subsys_initcall(split_lock_init); -- 2.19.1