Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1190434ybv; Wed, 5 Feb 2020 23:10:43 -0800 (PST) X-Google-Smtp-Source: APXvYqy9z/fJ5H+YYXTCDiS/xLqEP1Hz41znmMtmn3ZZEMDZ6bMpUFBTFjjUhStdefi67CPQr1zw X-Received: by 2002:a05:6808:3b4:: with SMTP id n20mr5807011oie.78.1580973043699; Wed, 05 Feb 2020 23:10:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580973043; cv=none; d=google.com; s=arc-20160816; b=ZGlZRWl9b1E/niUUnefi3wETR7ETB4bkp8/ZwSBIJhQqMtDKmeEoIKeHX7QMOq5Gcg 8UoG0SxOFEkrMa4lWvWVq3CE+ung5+1EV36dmulYAfSvY0/oVK7I3SINI/WalSgl2zNG QEqN7b3OENRB7+iqJn1LiPcdGzeBB1Buh9bTTJevnnwO4CMYL7x4MXAPoPo2gGKyLUuG NZi1nYh41yfDQslALj8q/0t6UqMeKtK1NQMAGnEKnm2P/7zt0oNQ8q7FbC83kMAix1Sv IOK8/dNdRHVCN1xS1qbT4SJS7UWBX7OKn+wJebsVDPRG+q/TYx1JJbADFnDyfp4DujdJ qnDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=b4pliS+SMAGQoXI+ajN+Hm5k8blhxyxj20gRKdJE0B8=; b=tme78xFx64Mn+VRfzWhdchtGRNSSsBNvfVPfqPF1e8NLSOkaRoSDbzrs4CA+Zx+M8t kL+P9Ed7IP+8oRVyinGGPwkmMfPXTviJhagVm7cltF+GZ0XGmWug3n2gqqkraWBu02v6 Ko4rVETn2GuAB+0cCmpIzt3xLGPoIE+qb5TxG7al6J5FzAF+jRmqWIYg11AuwkWPkWRg oTRIWMDOs+UZ6MoDhMjz4G4o7WpuTrQtjdAM/NN5UJT+kVERYjcAtPtpXXn1THjOGaRd uS7wBJZAxGzyqVVLWxrkku2rtwV8OjZB3SteFjn20DBnOT9s1UQN83yO3NFYknq/PXcU bK/w== 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 z15si1249888otm.168.2020.02.05.23.10.32; Wed, 05 Feb 2020 23:10:43 -0800 (PST) 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 S1727980AbgBFHJa (ORCPT + 99 others); Thu, 6 Feb 2020 02:09:30 -0500 Received: from mga04.intel.com ([192.55.52.120]:56103 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725895AbgBFHJ3 (ORCPT ); Thu, 6 Feb 2020 02:09:29 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2020 23:09:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,408,1574150400"; d="scan'208";a="231957225" Received: from lxy-dell.sh.intel.com ([10.239.13.109]) by orsmga003.jf.intel.com with ESMTP; 05 Feb 2020 23:09:26 -0800 From: Xiaoyao Li To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , hpa@zytor.com, Paolo Bonzini , Sean Christopherson , Andy Lutomirski , tony.luck@intel.com Cc: peterz@infradead.org, fenghua.yu@intel.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li Subject: [PATCH v3 3/8] x86/split_lock: Cache the value of MSR_TEST_CTRL in percpu data Date: Thu, 6 Feb 2020 15:04:07 +0800 Message-Id: <20200206070412.17400-4-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200206070412.17400-1-xiaoyao.li@intel.com> References: <20200206070412.17400-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cache the value of MSR_TEST_CTRL in percpu data msr_test_ctrl_cache, which will be used by KVM module. It also avoids an expensive RDMSR instruction if SLD needs to be context switched. Suggested-by: Sean Christopherson Signed-off-by: Xiaoyao Li --- arch/x86/include/asm/cpu.h | 2 ++ arch/x86/kernel/cpu/intel.c | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index ff567afa6ee1..2b20829db450 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -27,6 +27,8 @@ struct x86_cpu { }; #ifdef CONFIG_HOTPLUG_CPU +DECLARE_PER_CPU(u64, msr_test_ctrl_cache); + extern int arch_register_cpu(int num); extern void arch_unregister_cpu(int); extern void start_cpu0(void); diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 49535ed81c22..ff27d026cb4a 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -46,6 +46,9 @@ enum split_lock_detect_state { */ static enum split_lock_detect_state sld_state = sld_off; +DEFINE_PER_CPU(u64, msr_test_ctrl_cache); +EXPORT_PER_CPU_SYMBOL_GPL(msr_test_ctrl_cache); + /* * Processors which have self-snooping capability can handle conflicting * memory type across CPUs by snooping its own cache. However, there exists @@ -1043,20 +1046,22 @@ static void __init split_lock_setup(void) */ static void __sld_msr_set(bool on) { - u64 test_ctrl_val; - - rdmsrl(MSR_TEST_CTRL, test_ctrl_val); - if (on) - test_ctrl_val |= MSR_TEST_CTRL_SPLIT_LOCK_DETECT; + this_cpu_or(msr_test_ctrl_cache, MSR_TEST_CTRL_SPLIT_LOCK_DETECT); else - test_ctrl_val &= ~MSR_TEST_CTRL_SPLIT_LOCK_DETECT; + this_cpu_and(msr_test_ctrl_cache, ~MSR_TEST_CTRL_SPLIT_LOCK_DETECT); - wrmsrl(MSR_TEST_CTRL, test_ctrl_val); + wrmsrl(MSR_TEST_CTRL, this_cpu_read(msr_test_ctrl_cache)); } static void split_lock_init(void) { + u64 test_ctrl_val; + + /* Cache MSR TEST_CTRL */ + rdmsrl(MSR_TEST_CTRL, test_ctrl_val); + this_cpu_write(msr_test_ctrl_cache, test_ctrl_val); + if (sld_state == sld_off) return; -- 2.23.0