From: Aravind Gopalakrishnan <aravind.gopalakrishnan@amd.com>
To: chegger@amazon.de, jinsong.liu@intel.com,
suravee.suthikulpanit@amd.com, boris.ostrovsky@oracle.com,
xen-devel@lists.xen.org, JBeulich@suse.com
Cc: Aravind Gopalakrishnan <aravind.gopalakrishnan@amd.com>
Subject: [PATCH] mcheck, vmce: Allow vmce_amd_* functions to handle AMD thresolding MSRs
Date: Thu, 6 Feb 2014 18:32:56 -0600 [thread overview]
Message-ID: <1391733176-2941-1-git-send-email-aravind.gopalakrishnan@amd.com> (raw)
vmce_amd_[rd|wr]msr functions can handle accesses to AMD thresholding
registers. But due to this statement here:
switch ( msr & (MSR_IA32_MC0_CTL | 3) )
we are wrongly masking off top two bits which meant the register
accesses never made it to vmce_amd_* functions.
We correct this problem by modifying the mask in this patch to allow
AMD thresholding registers to fall to 'default' case which in turn
allows vmce_amd_* functions to handle access to the registers.
Also, the extended block of AMD MC4 MISC registers do not exist always.
In this patch, we rework the vmce_amd_[wr|rd]msr functions
to return #GP to guest if register does not exist in HW. If they do,
retain current behavior.
Signed-off-by: Aravind Gopalakrishnan <aravind.gopalakrishnan@amd.com>
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Reviewed-by: Christoph Egger <chegger@amazon.de>
---
xen/arch/x86/cpu/mcheck/amd_f10.c | 54 +++++++++++++++----------------------
xen/arch/x86/cpu/mcheck/mce_amd.h | 3 +++
xen/arch/x86/cpu/mcheck/vmce.c | 4 +--
3 files changed, 26 insertions(+), 35 deletions(-)
diff --git a/xen/arch/x86/cpu/mcheck/amd_f10.c b/xen/arch/x86/cpu/mcheck/amd_f10.c
index 61319dc..605f277 100644
--- a/xen/arch/x86/cpu/mcheck/amd_f10.c
+++ b/xen/arch/x86/cpu/mcheck/amd_f10.c
@@ -102,46 +102,34 @@ enum mcheck_type amd_f10_mcheck_init(struct cpuinfo_x86 *c)
return mcheck_amd_famXX;
}
+/* check for AMD MC4 extended MISC register presence */
+static inline int amd_thresholding_reg_present(uint32_t msr)
+{
+ uint64_t val;
+ rdmsr_safe(msr, val);
+ if ( val & (AMD_MC4_MISC_VAL_MASK | AMD_MC4_MISC_CNTP_MASK) )
+ return 1;
+
+ return 0;
+}
+
/* amd specific MCA MSR */
int vmce_amd_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
{
- switch (msr) {
- case MSR_F10_MC4_MISC1: /* DRAM error type */
- v->arch.vmce.bank[1].mci_misc = val;
- mce_printk(MCE_VERBOSE, "MCE: wr msr %#"PRIx64"\n", val);
- break;
- case MSR_F10_MC4_MISC2: /* Link error type */
- case MSR_F10_MC4_MISC3: /* L3 cache error type */
- /* ignore write: we do not emulate link and l3 cache errors
- * to the guest.
- */
- mce_printk(MCE_VERBOSE, "MCE: wr msr %#"PRIx64"\n", val);
- break;
- default:
- return 0;
- }
+ /* If not present, #GP fault, else do nothing as we don't emulate */
+ if ( !amd_thresholding_reg_present(msr) )
+ return -1;
- return 1;
+ mce_printk(MCE_VERBOSE, "MCE: wr msr %#"PRIx64"\n", val);
+ return 1;
}
int vmce_amd_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
{
- switch (msr) {
- case MSR_F10_MC4_MISC1: /* DRAM error type */
- *val = v->arch.vmce.bank[1].mci_misc;
- mce_printk(MCE_VERBOSE, "MCE: rd msr %#"PRIx64"\n", *val);
- break;
- case MSR_F10_MC4_MISC2: /* Link error type */
- case MSR_F10_MC4_MISC3: /* L3 cache error type */
- /* we do not emulate link and l3 cache
- * errors to the guest.
- */
- *val = 0;
- mce_printk(MCE_VERBOSE, "MCE: rd msr %#"PRIx64"\n", *val);
- break;
- default:
- return 0;
- }
+ /* If not present, #GP fault, else assign '0' as we don't emulate */
+ if ( !amd_thresholding_reg_present(msr) )
+ return -1;
- return 1;
+ *val = 0;
+ return 1;
}
diff --git a/xen/arch/x86/cpu/mcheck/mce_amd.h b/xen/arch/x86/cpu/mcheck/mce_amd.h
index 5d047e7..a6024fb 100644
--- a/xen/arch/x86/cpu/mcheck/mce_amd.h
+++ b/xen/arch/x86/cpu/mcheck/mce_amd.h
@@ -1,6 +1,9 @@
#ifndef _MCHECK_AMD_H
#define _MCHECK_AMD_H
+#define AMD_MC4_MISC_VAL_MASK (1ULL << 63)
+#define AMD_MC4_MISC_CNTP_MASK (1ULL << 62)
+
enum mcheck_type amd_k8_mcheck_init(struct cpuinfo_x86 *c);
enum mcheck_type amd_f10_mcheck_init(struct cpuinfo_x86 *c);
diff --git a/xen/arch/x86/cpu/mcheck/vmce.c b/xen/arch/x86/cpu/mcheck/vmce.c
index f6c35db..be9bb5e 100644
--- a/xen/arch/x86/cpu/mcheck/vmce.c
+++ b/xen/arch/x86/cpu/mcheck/vmce.c
@@ -107,7 +107,7 @@ static int bank_mce_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
*val = 0;
- switch ( msr & (MSR_IA32_MC0_CTL | 3) )
+ switch ( msr & (-MSR_IA32_MC0_CTL | 3) )
{
case MSR_IA32_MC0_CTL:
/* stick all 1's to MCi_CTL */
@@ -210,7 +210,7 @@ static int bank_mce_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
int ret = 1;
unsigned int bank = (msr - MSR_IA32_MC0_CTL) / 4;
- switch ( msr & (MSR_IA32_MC0_CTL | 3) )
+ switch ( msr & (-MSR_IA32_MC0_CTL | 3) )
{
case MSR_IA32_MC0_CTL:
/*
--
1.7.9.5
next reply other threads:[~2014-02-07 0:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-07 0:32 Aravind Gopalakrishnan [this message]
2014-02-07 11:05 ` [PATCH] mcheck, vmce: Allow vmce_amd_* functions to handle AMD thresolding MSRs Jan Beulich
2014-02-07 21:27 ` Aravind Gopalakrishnan
2014-02-10 7:41 ` Jan Beulich
2014-02-10 16:54 ` Aravind Gopalakrishnan
2014-02-12 9:58 ` Egger, Christoph
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=1391733176-2941-1-git-send-email-aravind.gopalakrishnan@amd.com \
--to=aravind.gopalakrishnan@amd.com \
--cc=JBeulich@suse.com \
--cc=boris.ostrovsky@oracle.com \
--cc=chegger@amazon.de \
--cc=jinsong.liu@intel.com \
--cc=suravee.suthikulpanit@amd.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).