From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Kevin Tian" <kevin.tian@intel.com>,
"Wei Liu" <wei.liu2@citrix.com>,
"Jan Beulich" <JBeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Jun Nakajima" <jun.nakajima@intel.com>,
"Boris Ostrovsky" <boris.ostrovsky@oracle.com>,
"Suravee Suthikulpanit" <suravee.suthikulpanit@amd.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 2/5] x86/pv: Avoid leaking other guests' MSR_TSC_AUX values into PV context
Date: Tue, 20 Feb 2018 11:58:40 +0000 [thread overview]
Message-ID: <1519127923-23539-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1519127923-23539-1-git-send-email-andrew.cooper3@citrix.com>
If the CPU pipeline supports RDTSCP or RDPID, a guest can observe the value in
MSR_TSC_AUX, irrespective of whether the relevant CPUID features are
advertised/hidden.
At the moment, paravirt_ctxt_switch_to() only writes to MSR_TSC_AUX if
TSC_MODE_PVRDTSCP mode is enabled, but this is not the default mode.
Therefore, default PV guests can read the value from a previously scheduled
HVM vcpu, or TSC_MODE_PVRDTSCP-enabled PV guest.
Alter the PV path to always write to MSR_TSC_AUX, using 0 in the common case.
To amortise overhead cost, introduce wrmsr_tsc_aux() which performs a lazy
update of the MSR, and use this function consistently across the codebase.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Jun Nakajima <jun.nakajima@intel.com>
CC: Kevin Tian <kevin.tian@intel.com>
CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
CC: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
N.B. This has been deemed not a security issue, because the MSR doesn't store
any sensitive information.
---
xen/arch/x86/domain.c | 6 +++---
xen/arch/x86/hvm/hvm.c | 2 +-
xen/arch/x86/hvm/svm/svm.c | 2 +-
xen/arch/x86/hvm/vmx/vmx.c | 2 +-
xen/arch/x86/msr.c | 2 ++
xen/include/asm-x86/msr.h | 16 ++++++++++++++--
6 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index f93327b..9c3527f 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1533,9 +1533,9 @@ void paravirt_ctxt_switch_to(struct vcpu *v)
if ( unlikely(v->arch.debugreg[7] & DR7_ACTIVE_MASK) )
activate_debugregs(v);
- if ( (v->domain->arch.tsc_mode == TSC_MODE_PVRDTSCP) &&
- boot_cpu_has(X86_FEATURE_RDTSCP) )
- write_rdtscp_aux(v->domain->arch.incarnation);
+ if ( cpu_has_rdtscp )
+ wrmsr_tsc_aux(v->domain->arch.tsc_mode == TSC_MODE_PVRDTSCP
+ ? v->domain->arch.incarnation : 0);
}
/* Update per-VCPU guest runstate shared memory area (if registered). */
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 5d39210..0539551 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3579,7 +3579,7 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content,
v->arch.hvm_vcpu.msr_tsc_aux = (uint32_t)msr_content;
if ( cpu_has_rdtscp
&& (v->domain->arch.tsc_mode != TSC_MODE_PVRDTSCP) )
- wrmsrl(MSR_TSC_AUX, (uint32_t)msr_content);
+ wrmsr_tsc_aux(msr_content);
break;
case MSR_IA32_APICBASE:
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 9f58afc..f53f430 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1093,7 +1093,7 @@ static void svm_ctxt_switch_to(struct vcpu *v)
svm_tsc_ratio_load(v);
if ( cpu_has_rdtscp )
- wrmsrl(MSR_TSC_AUX, hvm_msr_tsc_aux(v));
+ wrmsr_tsc_aux(hvm_msr_tsc_aux(v));
}
static void noreturn svm_do_resume(struct vcpu *v)
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 5cd689e..31acb0e 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -618,7 +618,7 @@ static void vmx_restore_guest_msrs(struct vcpu *v)
}
if ( cpu_has_rdtscp )
- wrmsrl(MSR_TSC_AUX, hvm_msr_tsc_aux(v));
+ wrmsr_tsc_aux(hvm_msr_tsc_aux(v));
}
void vmx_update_cpu_exec_control(struct vcpu *v)
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 7875d9c..7ba9a10 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -24,6 +24,8 @@
#include <xen/sched.h>
#include <asm/msr.h>
+DEFINE_PER_CPU(uint32_t, tsc_aux);
+
struct msr_domain_policy __read_mostly hvm_max_msr_domain_policy,
__read_mostly pv_max_msr_domain_policy;
diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h
index 928f1cc..9475a71 100644
--- a/xen/include/asm-x86/msr.h
+++ b/xen/include/asm-x86/msr.h
@@ -115,8 +115,6 @@ static inline uint64_t rdtsc_ordered(void)
__write_tsc(val); \
})
-#define write_rdtscp_aux(val) wrmsr(MSR_TSC_AUX, (val), 0)
-
#define rdpmc(counter,low,high) \
__asm__ __volatile__("rdpmc" \
: "=a" (low), "=d" (high) \
@@ -210,6 +208,20 @@ static inline void write_efer(uint64_t val)
DECLARE_PER_CPU(u32, ler_msr);
+DECLARE_PER_CPU(uint32_t, tsc_aux);
+
+/* Lazy update of MSR_TSC_AUX */
+static inline void wrmsr_tsc_aux(uint32_t val)
+{
+ uint32_t *this_tsc_aux = &this_cpu(tsc_aux);
+
+ if ( *this_tsc_aux != val )
+ {
+ wrmsr(MSR_TSC_AUX, val, 0);
+ *this_tsc_aux = val;
+ }
+}
+
/* MSR policy object for shared per-domain MSRs */
struct msr_domain_policy
{
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-02-20 11:58 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-20 11:58 [RFC PATCH 0/5] x86: Multiple fixes to MSR_TSC_AUX and RDTSCP handling for guests Andrew Cooper
2018-02-20 11:58 ` [PATCH 1/5] x86/hvm: Don't shadow the domain parameter in hvm_save_cpu_msrs() Andrew Cooper
2018-02-20 14:54 ` Roger Pau Monné
2018-02-20 15:12 ` Wei Liu
2018-02-23 13:53 ` Jan Beulich
2018-02-20 11:58 ` Andrew Cooper [this message]
2018-02-20 15:22 ` [PATCH 2/5] x86/pv: Avoid leaking other guests' MSR_TSC_AUX values into PV context Wei Liu
2018-02-20 15:26 ` Andrew Cooper
2018-02-20 15:32 ` Wei Liu
2018-02-20 15:49 ` Roger Pau Monné
2018-02-23 14:04 ` Jan Beulich
2018-02-23 14:22 ` Andrew Cooper
2018-02-23 15:09 ` Jan Beulich
2018-02-26 11:25 ` Jan Beulich
2018-02-26 19:11 ` [ping] " Andrew Cooper
2018-02-27 5:38 ` Tian, Kevin
2018-02-26 19:52 ` Boris Ostrovsky
2018-02-20 11:58 ` [PATCH 3/5] x86/time: Rework pv_soft_rdtsc() to aid further cleanup Andrew Cooper
2018-02-20 15:32 ` Wei Liu
2018-02-20 16:04 ` Roger Pau Monné
2018-02-20 16:07 ` Andrew Cooper
2018-02-23 14:38 ` Jan Beulich
2018-02-20 11:58 ` [PATCH 4/5] x86/pv: Remove deferred RDTSC{, P} handling in pv_emulate_privileged_op() Andrew Cooper
2018-02-20 16:08 ` Wei Liu
2018-02-20 16:28 ` Roger Pau Monné
2018-02-20 16:37 ` Andrew Cooper
2018-02-20 17:40 ` Roger Pau Monné
2018-02-23 14:40 ` Jan Beulich
2018-02-20 11:58 ` [PATCH 5/5] x86: Rework MSR_TSC_AUX handling from scratch Andrew Cooper
2018-02-20 17:03 ` Wei Liu
2018-02-20 17:42 ` Andrew Cooper
2018-02-21 11:08 ` Wei Liu
2018-02-20 17:35 ` Roger Pau Monné
2018-02-20 18:28 ` Andrew Cooper
2018-02-21 10:13 ` Roger Pau Monné
2018-02-21 11:36 ` [PATCH v2 " Andrew Cooper
2018-02-21 12:06 ` Wei Liu
2018-02-21 13:04 ` Roger Pau Monné
2018-02-23 15:05 ` Jan Beulich
2018-02-23 15:51 ` Andrew Cooper
2018-02-26 11:30 ` Jan Beulich
2018-02-26 19:12 ` [RFC PATCH 0/5] x86: Multiple fixes to MSR_TSC_AUX and RDTSCP handling for guests Andrew Cooper
2018-02-26 19:44 ` Boris Ostrovsky
2018-02-26 23:30 ` Andrew Cooper
2018-03-09 18:05 ` Boris Ostrovsky
2018-03-09 18:41 ` Andrew Cooper
2018-03-09 19:10 ` Boris Ostrovsky
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=1519127923-23539-3-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=roger.pau@citrix.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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).