From: Mohit Gambhir <mohit.gambhir@oracle.com>
To: jun.nakajima@intel.com, kevin.tian@intel.com, xen-devel@lists.xen.org
Cc: boris.ostrovsky@oracle.com, Mohit Gambhir <mohit.gambhir@oracle.com>
Subject: [PATCH] x86/vpmu_intel: Fix hypervisor crash by catching wrmsr fault
Date: Thu, 20 Apr 2017 13:49:42 -0400 [thread overview]
Message-ID: <20170420174942.12913-2-mohit.gambhir@oracle.com> (raw)
In-Reply-To: <20170420174942.12913-1-mohit.gambhir@oracle.com>
This patch changes wrmsrl() calls to write to MSR_P6_EVTSEL register in the
VPMU to wrmsr_safe(). There are known (and possibly some unknown) cases where
setting certain bits in MSR_P6_EVTSEL reg. can cause a General Protection
fault on some machines. Unless we catch this fault when it happens, it will
result in a hypervisor crash.
For instance, setting Pin Control (PC) bit (19) in MSR_P6_EVNTSEL results
in a General Protection Fault on Broadwell machines and thus causes the
hypervisor to crash.
This patch fixes the above mentioned crash (and other possible
hypervisor crashes that may occur while writing MSR_P6_EVNTSEL reg) by
catching and returning the fault to the guest OS.
Signed-off-by: Mohit Gambhir <mohit.gambhir@oracle.com>
---
xen/arch/x86/cpu/vpmu_intel.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/xen/arch/x86/cpu/vpmu_intel.c b/xen/arch/x86/cpu/vpmu_intel.c
index 3f0322c..13808b5 100644
--- a/xen/arch/x86/cpu/vpmu_intel.c
+++ b/xen/arch/x86/cpu/vpmu_intel.c
@@ -338,7 +338,7 @@ static int core2_vpmu_save(struct vcpu *v, bool_t to_guest)
return 1;
}
-static inline void __core2_vpmu_load(struct vcpu *v)
+static inline int __core2_vpmu_load(struct vcpu *v)
{
unsigned int i, pmc_start;
struct xen_pmu_intel_ctxt *core2_vpmu_cxt = vcpu_vpmu(v)->context;
@@ -356,7 +356,9 @@ static inline void __core2_vpmu_load(struct vcpu *v)
for ( i = 0; i < arch_pmc_cnt; i++ )
{
wrmsrl(pmc_start + i, xen_pmu_cntr_pair[i].counter);
- wrmsrl(MSR_P6_EVNTSEL(i), xen_pmu_cntr_pair[i].control);
+ if ( wrmsr_safe(MSR_P6_EVNTSEL(i), xen_pmu_cntr_pair[i].control) ==
+ -EFAULT)
+ return -EFAULT;
}
wrmsrl(MSR_CORE_PERF_FIXED_CTR_CTRL, core2_vpmu_cxt->fixed_ctrl);
@@ -369,6 +371,7 @@ static inline void __core2_vpmu_load(struct vcpu *v)
core2_vpmu_cxt->global_ovf_ctrl = 0;
wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, core2_vpmu_cxt->global_ctrl);
}
+ return 0;
}
static int core2_vpmu_verify(struct vcpu *v)
@@ -461,9 +464,8 @@ static int core2_vpmu_load(struct vcpu *v, bool_t from_guest)
vpmu_set(vpmu, VPMU_CONTEXT_LOADED);
- __core2_vpmu_load(v);
+ return __core2_vpmu_load(v);
- return 0;
}
static int core2_vpmu_alloc_resource(struct vcpu *v)
@@ -538,7 +540,8 @@ static int core2_vpmu_msr_common_check(u32 msr_index, int *type, int *index)
/* Do the lazy load staff. */
if ( !vpmu_is_set(vpmu, VPMU_CONTEXT_LOADED) )
{
- __core2_vpmu_load(current);
+ if ( __core2_vpmu_load(current) )
+ return 0;
vpmu_set(vpmu, VPMU_CONTEXT_LOADED);
if ( is_hvm_vcpu(current) &&
cpu_has_vmx_msr_bitmap )
@@ -719,8 +722,11 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content,
}
}
- if ( type != MSR_TYPE_GLOBAL )
- wrmsrl(msr, msr_content);
+ if ( type != MSR_TYPE_GLOBAL)
+ {
+ if ( wrmsr_safe(msr, msr_content) == -EFAULT )
+ return -EFAULT;
+ }
else
{
if ( is_hvm_vcpu(v) )
--
2.9.3
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-04-20 17:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-20 17:49 [PATCH] Fix hypervisor crash when writing to VPMU MSR Mohit Gambhir
2017-04-20 17:49 ` Mohit Gambhir [this message]
2017-04-21 7:14 ` [PATCH] x86/vpmu_intel: Fix hypervisor crash by catching wrmsr fault Jan Beulich
2017-04-24 15:44 ` Mohit Gambhir
2017-04-24 16:00 ` Boris Ostrovsky
2017-04-24 18:49 ` Mohit Gambhir
2017-04-24 16:04 ` Jan Beulich
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=20170420174942.12913-2-mohit.gambhir@oracle.com \
--to=mohit.gambhir@oracle.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.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).