From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
hpa@zytor.com
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
Sean Christopherson <sean.j.christopherson@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
luto@kernel.org, Peter Zijlstra <peterz@infradead.org>,
Arvind Sankar <nivedita@alum.mit.edu>,
Fenghua Yu <fenghua.yu@intel.com>,
Tony Luck <tony.luck@intel.com>,
Xiaoyao Li <xiaoyao.li@intel.com>
Subject: [PATCH v7 2/2] x86/split_lock: Avoid runtime reads of the TEST_CTRL MSR
Date: Wed, 25 Mar 2020 11:09:24 +0800 [thread overview]
Message-ID: <20200325030924.132881-3-xiaoyao.li@intel.com> (raw)
In-Reply-To: <20200325030924.132881-1-xiaoyao.li@intel.com>
In a context switch from a task that is detecting split locks
to one that is not (or vice versa) we need to update the TEST_CTRL
MSR. Currently this is done with the common sequence:
read the MSR
flip the bit
write the MSR
in order to avoid changing the value of any reserved bits in the MSR.
Cache unused and reserved bits of TEST_CTRL MSR with SPLIT_LOCK_DETECT
bit cleared during initialization, so we can avoid an expensive RDMSR
instruction during context switch.
Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com>
Originally-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
arch/x86/kernel/cpu/intel.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index deb5c42c2089..1f414578899c 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -45,6 +45,7 @@ enum split_lock_detect_state {
* split lock detect, unless there is a command line override.
*/
static enum split_lock_detect_state sld_state __ro_after_init = sld_off;
+static u64 msr_test_ctrl_cache __ro_after_init;
/*
* Processors which have self-snooping capability can handle conflicting
@@ -1037,6 +1038,8 @@ static void __init split_lock_setup(void)
break;
}
+ rdmsrl(MSR_TEST_CTRL, msr_test_ctrl_cache);
+
if (!split_lock_verify_msr(true)) {
pr_info("MSR access failed: Disabled\n");
return;
@@ -1053,14 +1056,10 @@ static void __init split_lock_setup(void)
*/
static void sld_update_msr(bool on)
{
- u64 test_ctrl_val;
-
- rdmsrl(MSR_TEST_CTRL, test_ctrl_val);
+ u64 test_ctrl_val = msr_test_ctrl_cache;
if (on)
test_ctrl_val |= MSR_TEST_CTRL_SPLIT_LOCK_DETECT;
- else
- test_ctrl_val &= ~MSR_TEST_CTRL_SPLIT_LOCK_DETECT;
wrmsrl(MSR_TEST_CTRL, test_ctrl_val);
}
--
2.20.1
next prev parent reply other threads:[~2020-03-25 3:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-25 3:09 [PATCH v7 0/2] Fix and optimization of split_lock_detection Xiaoyao Li
2020-03-25 3:09 ` [PATCH v7 1/2] x86/split_lock: Rework the initialization flow of split lock detection Xiaoyao Li
2020-03-28 16:32 ` Sean Christopherson
2020-03-30 13:26 ` Xiaoyao Li
2020-03-30 14:26 ` Sean Christopherson
2020-03-25 3:09 ` Xiaoyao Li [this message]
2020-03-28 16:34 ` [PATCH v7 2/2] x86/split_lock: Avoid runtime reads of the TEST_CTRL MSR Sean Christopherson
2020-03-29 9:13 ` Xiaoyao Li
2020-03-30 18:18 ` Sean Christopherson
2020-04-03 17:44 ` [PATCH 0/1] x86/split_lock: check split lock feature on initialization Benjamin Lamowski
2020-04-03 17:44 ` [PATCH 1/1] " Benjamin Lamowski
2020-04-03 18:01 ` Sean Christopherson
2020-04-06 8:23 ` Benjamin Lamowski
2020-04-06 11:48 ` Xiaoyao Li
2020-04-06 15:57 ` [PATCH v2 0/1] x86/split_lock: check split lock support " Benjamin Lamowski
2020-04-06 16:02 ` [PATCH v2 1/1] " Benjamin Lamowski
2020-04-06 16:17 ` [PATCH v3 " Benjamin Lamowski
2020-04-06 21:24 ` Thomas Gleixner
2020-04-06 21:21 ` [PATCH 0/1] x86/split_lock: check split lock feature " Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200325030924.132881-3-xiaoyao.li@intel.com \
--to=xiaoyao.li@intel.com \
--cc=bp@alien8.de \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=nivedita@alum.mit.edu \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).