Fix AMD threshold register definitions and activate vmce_amd_* functions
v2 cover Fix AMD threshold register definitions and activate vmce_amd_* functions
Patch 1: Deals with correcting AMD threshold register definitions. Patch 2: Fixes mask in vmce.c to allow vmce_amd_* functions to handle access to
AMD thresholding registers.
Changes from V1:
- Correct time skew on the V1 patch.
Aravind Gopalakrishnan (2):
hvm,svm: Update AMD Thresholding MSR definitions mcheck,vmce: Allow vmce_amd_* functions to handle AMD thresolding
MSRs
xen/arch/x86/cpu/mcheck/vmce.c | 4 ++-- xen/arch/x86/hvm/svm/svm.c | 10 ++++++---- xen/include/asm-x86/msr-index.h | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 1/2 hvm, svm: Update AMD Thresholding MSR definitions
MSR 0xC000040A is marked as reserved from Fam15 onwards and MSR 0x413 is marked alias of MSR0xC000040A on Fam10 BKDG. So remove the unnecessary definition of the reserved MSR and use MSR_IA32_MCx_MISC() to define MSR 0x413.
Also, according to BKDG, MSR 0x413 is the first of the thresholding registers; MSR 0xC0000408 and MSR 0xC0000409 are second and third respectively. So rework the #define's accordingly.
Fam15 Model 00h-0fh BKDG reference:
http://support.amd.com/TechDocs/42301_15h_Mod_00h-0Fh_BKDG.pdf
--- xen/arch/x86/hvm/svm/svm.c | 10 ++++++---- xen/include/asm-x86/msr-index.h | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/svm/svm.c +6 -4
@@ -1461,8 +1461,9 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) *msr_content = v->arch.hvm_svm.guest_sysenter_eip;break ; -case MSR_IA32_MCx_MISC (4 ):/* Threshold register */ - case MSR_F10_MC4_MISC1 ... MSR_F10_MC4_MISC3: +case MSR_F10_MC4_MISC1 :/* Threshold registers */ +case MSR_F10_MC4_MISC2 : +case MSR_F10_MC4_MISC3 :/* * MCA/MCE: We report that the threshold register is unavailable * for OS use (locked by the BIOS).
@@ -1660,8 +1661,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)vpmu_do_wrmsr (msr, msr_content);break ; -case MSR_IA32_MCx_MISC (4 ):/* Threshold register */ - case MSR_F10_MC4_MISC1 ... MSR_F10_MC4_MISC3: +case MSR_F10_MC4_MISC1 :/* Threshold registers */ +case MSR_F10_MC4_MISC2 : +case MSR_F10_MC4_MISC3 :/* * MCA/MCE: Threshold register is reported to be locked, so we ignore * all write accesses. This behaviour matches real HW, so guests should
xen/include/asm-x86/msr-index.h +3 -3
@@ -219,9 +219,9 @@#define AMD64_NB_CFG_CF8_EXT_ENABLE_BIT 46/* AMD Family10h machine check MSRs */ -#define MSR_F10_MC4_MISC1 0xc0000408 -#define MSR_F10_MC4_MISC2 0xc0000409 -#define MSR_F10_MC4_MISC3 0xc000040A +#define MSR_F10_MC4_MISC1 MSR_IA32_MCx_MISC(4) +#define MSR_F10_MC4_MISC2 0xc0000408 +#define MSR_F10_MC4_MISC3 0xc0000409/* AMD Family10h Bus Unit MSRs */ #define MSR_F10_BU_CFG 0xc0011023
Signature · 1 line
1.7.9.5
Re: [PATCH 1/2 V2] hvm, svm: Update AMD Thresholding MSR definitions
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Aravind Gopalakrishnan
MSR
0xC000040Ais marked as reserved from Fam15 onwards and MSR0x413is marked alias of MSR0xC000040A on Fam10 BKDG. So remove the unnecessary definition of the reserved MSR and useMSR_IA32_MCx_MISC()to define MSR0x413.
My Fam10 BKDG version doesn't say anything like this. Instead it says that the low 32 bits of all 4 registers are identical (i.e. all are aliasing 0x413), whereas the high 32 bits are different among all the four registers (with 0xc000040a having them all zero).
Quoted 6 lines
Also, according to BKDG, MSR
0x413is the first of the thresholding registers; MSR0xC0000408and MSR0xC0000409are second and third respectively. So rework the #define's accordingly.Fam15 Model 00h-0fh BKDG reference:
http://support.amd.com/TechDocs/42301_15h_Mod_00h-0Fh_BKDG.pdf
Higher model numbers appear to also have 0xc0000409 reserved...
Jan
Quoted 65 lines
Signed-off-by Aravind Gopalakrishnan <[email protected]>Reviewed-by Suravee Suthikulpanit <[email protected]>--- xen/arch/x86/hvm/svm/svm.c | 10 ++++++---- xen/include/asm-x86/msr-index.h | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-)xen/arch/x86/hvm/svm/svm.c +3
-2@@ -1461,8 +1461,9 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) *msr_content = v->arch.hvm_svm.guest_sysenter_eip;break ; -case MSR_IA32_MCx_MISC (4 ):/* Threshold register */ - case MSR_F10_MC4_MISC1 ... MSR_F10_MC4_MISC3: +case MSR_F10_MC4_MISC1 :/* Threshold registers */ +case MSR_F10_MC4_MISC2 : +case MSR_F10_MC4_MISC3 :/* * MCA/MCE: We report that the threshold register is unavailable * for OS use (locked by the BIOS).
xen/arch/x86/hvm/svm/svm.c +3
-2@@ -1660,8 +1661,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)vpmu_do_wrmsr (msr ,msr_content );break ; -case MSR_IA32_MCx_MISC (4 ):/* Threshold register */ - case MSR_F10_MC4_MISC1 ... MSR_F10_MC4_MISC3: +case MSR_F10_MC4_MISC1 :/* Threshold registers */ +case MSR_F10_MC4_MISC2 : +case MSR_F10_MC4_MISC3 :/* * MCA/MCE: Threshold register is reported to be locked, so we ignore
* all write accesses. This behaviour matches real HW, so guests
shouldxen/include/asm-x86/msr-index.h +3
-3@@ -219,9 +219,9 @@#define AMD64_NB_CFG_CF8_EXT_ENABLE_BIT 46/* AMD Family10h machine check MSRs */ -#define MSR_F10_MC4_MISC1 0xc0000408 -#define MSR_F10_MC4_MISC2 0xc0000409 -#define MSR_F10_MC4_MISC3 0xc000040A +#define MSR_F10_MC4_MISC1 MSR_IA32_MCx_MISC(4) +#define MSR_F10_MC4_MISC2 0xc0000408 +#define MSR_F10_MC4_MISC3 0xc0000409/* AMD Family10h Bus Unit MSRs */ #define MSR_F10_BU_CFG 0xc0011023Signature · 8 lines
1.7.9.5 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 1/2 V2] hvm, svm: Update AMD Thresholding MSR definitions
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Aravind Gopalakrishnan
MSR
0xC000040Ais marked as reserved from Fam15 onwards and MSR0x413is marked alias of MSR0xC000040A on Fam10 BKDG. So remove the unnecessary definition of the reserved MSR and useMSR_IA32_MCx_MISC()to define MSR0x413.My Fam10 BKDG version doesn't say anything like this. Instead it says that the low 32 bits of all 4 registers are identical (i.e. all are aliasing
0x413), whereas the high 32 bits are different among all the four registers (with0xc000040ahaving them all zero).
Thanks for pointing this out; looks like MSR 0xc000040a is zeroed out completely:
(F3x178 (MSRC000_040A): RAZ.)(page 339 on http://support.amd.com/TechDocs/31116.pdf)
I have reworded commit message which (hopefully) conveys this better..
Quoted 9 lines
Quoted 6 lines
Also, according to BKDG, MSR
0x413is the first of the thresholding registers; MSR0xC0000408and MSR0xC0000409are second and third respectively. So rework the #define's accordingly.Fam15 Model 00h-0fh BKDG reference:
http://support.amd.com/TechDocs/42301_15h_Mod_00h-0Fh_BKDG.pdfHigher model numbers appear to also have
0xc0000409reserved...
Yes, thanks again for the pointer..
I have now reworked the code to care for the existence of extended block of MC4_MISC registers..
(Note: 0xc0000409 is reserved in newer model of F15h, while both 0xc0000408 and 0xc0000409 are reserved in F16h)
a) If the registers exist in HW, then we continue to enforce current policy of not emulating as we do not expose MC4 to guest
b) If they don't, then #GP fault to guest.
-Aravind.
PATCH v2 2/2 mcheck, vmce: Allow vmce_amd_* functions to handle AMD thresolding MSRs
In reply to Aravind Gopalakrishnanvmce_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 and bit 4 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.
--- xen/arch/x86/cpu/mcheck/vmce.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/cpu/mcheck/vmce.c +2 -2
@@ -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 | (0x3 <<30 ) |0x13 )) {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 | (0x3 <<30 ) |0x13 )) {case MSR_IA32_MC0_CTL :/*
Signature · 1 line
1.7.9.5
Re: [PATCH 2/2 V2] mcheck, vmce: Allow vmce_amd_* functions to handle AMD thresolding MSRs
xen/arch/x86/cpu/mcheck/vmce.c static int bank_mce_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val) · line 110
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Aravind Gopalakrishnan
xen/arch/x86/cpu/mcheck/vmce.c +1
-1@@ -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 | (0x3 << 30) | 0x13))
As one of the other reviewers already said - 0xC0000000 would be better recognizable here.
As to the 3 -> 0x13 change - I don't think this is conceptually correct. While at present we emulate only 2 banks, this had been different in the past and may become different again. Hence introducing a dis-contiguity after bank 3 is undesirable.
Jan
Re: [PATCH 2/2 V2] mcheck, vmce: Allow vmce_amd_* functions to handle AMD thresolding MSRs
Quoted 12 lines · Jan Beulich
xen/arch/x86/cpu/mcheck/vmce.c static int bank_mce_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val) · line 110
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Aravind Gopalakrishnan
xen/arch/x86/cpu/mcheck/vmce.c +1
-1@@ -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 | (0x3 << 30) | 0x13))As one of the other reviewers already said -
0xC0000000would be better recognizable here.
Quoted 6 lines
As to the 3 ->
0x13change - I don't think this is conceptually correct. While at present we emulate only 2 banks, this had been different in the past and may become different again. Hence introducing a dis-contiguity after bank 3 is undesirable.
IMHO, including the '0x13' is necessary. The reason is that 0x413, 0xc0000408 and 0xc0000409 together form the set of MC4 thresholding registers. Not including 0x13 in the mask would mean that accesses to 0x413 alone would not be handled. (which would be confusing if someone new were to look into the mce codebase)
Also, (in response to Boris's comments) - AFAICT, this should not affect Intel codepath.. Intel's vmce_* functions only care about MSR_IA32_MC0_CTL2 = 0x00000280 (if bank0) or 0x00000281 (if bank 1) and, having 0x13 in the mask does not affect the ability of bank_mce_[rd|wr]msr functions to call into vmce_intel* functions..
(I haven't tested this, so if someone could test and let me know, that'd be great.)
I have addressed Christoph's and Boris.O's earlier comments too in the next version of this patch.
Thanks,
-Aravind.
Re: [PATCH 2/2 V2] mcheck, vmce: Allow vmce_amd_* functions to handle AMD thresolding MSRs
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 05.02.14 at 21:41, Aravind Gopalakrishnan <[email protected]>
Quoted 20 lines · wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 27.01.14 at 23:44, Aravind Gopalakrishnan <[email protected]>
Quoted 3 lines · wrote:
xen/arch/x86/cpu/mcheck/vmce.c static int bank_mce_rdmsr(const struct vcpu *v, uint32_t
Quoted 3 lines
xen/arch/x86/cpu/mcheck/vmce.c +0
-0@@ -107,7 +107,7 @@ static int bank_mce_rdmsr(const struct vcpu *v, uint32_tmsr,
uint64_t*val)Quoted 5 lines
xen/arch/x86/cpu/mcheck/vmce.c static int bank_mce_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val) · line 110
Quoted 5 lines
xen/arch/x86/cpu/mcheck/vmce.c +1
-1*val =0 ; - switch ( msr & (MSR_IA32_MC0_CTL | 3) ) + switch ( msr & (MSR_IA32_MC0_CTL | (0x3 << 30) | 0x13))Quoted 7 lines
As one of the other reviewers already said -
0xC0000000would be better recognizable here.As to the 3 ->
0x13change - I don't think this is conceptually correct. While at present we emulate only 2 banks, this had been different in the past and may become different again. Hence introducing a dis-contiguity after bank 3 is undesirable.
Quoted 7 lines
IMHO, including the '
0x13' is necessary. The reason is that0x413,0xc0000408and0xc0000409
together form the set of MC4 thresholding registers. Not including0x13in the mask would mean
that accesses to0x413alone would not be handled. (which would be confusing if someone new
were to look into the mce codebase)
No - bit 4 is part of what forms the bank number. Hence it must be masked out in the switch() expression.
Jan
Re: [PATCH 2/2 V2] mcheck, vmce: Allow vmce_amd_* functions to handle AMD thresolding MSRs
Quoted 30 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 05.02.14 at 21:41, Aravind Gopalakrishnan <[email protected]>
Quoted 20 lines · wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 27.01.14 at 23:44, Aravind Gopalakrishnan <[email protected]>
Quoted 3 lines · wrote:
xen/arch/x86/cpu/mcheck/vmce.c static int bank_mce_rdmsr(const struct vcpu *v, uint32_t
Quoted 3 lines
xen/arch/x86/cpu/mcheck/vmce.c +0
-0@@ -107,7 +107,7 @@ static int bank_mce_rdmsr(const struct vcpu *v, uint32_tmsr,
uint64_t*val)Quoted 5 lines
xen/arch/x86/cpu/mcheck/vmce.c static int bank_mce_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val) · line 110
Quoted 5 lines
xen/arch/x86/cpu/mcheck/vmce.c +1
-1*val =0 ; - switch ( msr & (MSR_IA32_MC0_CTL | 3) ) + switch ( msr & (MSR_IA32_MC0_CTL | (0x3 << 30) | 0x13))Quoted 7 lines
As one of the other reviewers already said -
0xC0000000would be better recognizable here.As to the 3 ->
0x13change - I don't think this is conceptually correct. While at present we emulate only 2 banks, this had been different in the past and may become different again. Hence introducing a dis-contiguity after bank 3 is undesirable.Quoted 7 lines
IMHO, including the '
0x13' is necessary. The reason is that0x413,0xc0000408and0xc0000409
together form the set of MC4 thresholding registers. Not including0x13in the mask would mean
that accesses to0x413alone would not be handled. (which would be confusing if someone new
were to look into the mce codebase)
Quoted 2 lines
No - bit 4 is part of what forms the bank number. Hence it must be masked out in the
switch()expression.
I prefer to see a comment in the code that makes this clear.
Christoph
Re: [PATCH 2/2 V2] mcheck, vmce: Allow vmce_amd_* functions to handle AMD thresolding MSRs
Quoted 12 lines · Christoph
Quoted 8 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 05.02.14 at 21:41, Aravind Gopalakrishnan <[email protected]>
Quoted 3 lines · wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 27.01.14 at 23:44, Aravind Gopalakrishnan <[email protected]>
wrote:
No - bit 4 is part of what forms the bank number. Hence it must be masked out in the
switch()expression.I prefer to see a comment in the code that makes this clear.
Agreed, I have added very brief comments in the code. Do let me know if it needs to be more verbose..
Thanks,
-Aravind.