mce: use safe MSR accesses
PATCH 1/1 mce: use safe MSR accesses
From: Jesse Larrew <[email protected]>
When running as a guest under kvm, it's possible that the MSR being accessed may not be implemented. All MSR accesses should be prepared to handle exceptions.
--- arch/x86/kernel/cpu/mcheck/mce.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
@@ -1556,12 +1556,12 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)wrmsrl (MSR_K7_HWCR , hwcr |BIT (18 ));for (i =0 ; i <ARRAY_SIZE (msrs); i++) { -rdmsrl (msrs[i], val); +rdmsrl_safe (msrs[i], &val);/* CntP bit set? */ if (val &BIT_64 (62 )) { val &= ~BIT_64 (62 ); -wrmsrl (msrs[i], val); +wrmsrl_safe (msrs[i], val); } }
Signature · 1 line
1.9.1
Quoted 3 lines
When running as a guest under kvm, it's possible that the MSR being accessed may not be implemented. All MSR accesses should be prepared to handle exceptions.
Isn't that a KVM bug? The code here first checks family/model before accessing the MSR:
if (c->x86 == 0x15 &&
(c->x86_model >= 0x10 && c->x86_model <= 0x1f)) {If kvm tells the guest that it is running on one of these models, shouldn't it provide complete coverage for that model?
If that isn't possible - then you should still do more than just s/rdmsrl/rdmsrl_safe/ ... like check the return value to see whether you got an exception .. and thus should skip past code that uses the "val" that you thought you read from the non-existent MSR.
-Tony
Quoted 10 lines · Tony
Quoted 3 lines
When running as a guest under kvm, it's possible that the MSR being accessed may not be implemented. All MSR accesses should be prepared to handle exceptions.
Isn't that a KVM bug? The code here first checks family/model before accessing the MSR:
if (c->x86 == 0x15 && (c->x86_model >= 0x10 && c->x86_model <= 0x1f)) {If kvm tells the guest that it is running on one of these models, shouldn't it provide complete coverage for that model?
These MSRs don't make sense in guest mode. The real question is if we fix that in KVM, here, or both. I'm a fan of fixing it in both places. Xen's behavior is to return a value of 0 if the guest tries to access these, that seems like a reasonable thing to do in KVM as well. I am volunteering myself to write that patch for KVM, but I would encourage accepting an updated version of this patch as well.
Quoted 4 lines
If that isn't possible - then you should still do more than just s/rdmsrl/rdmsrl_safe/ ... like check the return value to see whether you got an exception .. and thus should skip past code that uses the "val" that you thought you read from the non-existent MSR.
Initializing val to 0 where it is declared should have the desired effect.
Borislav Petkov
maintainerQuoted 5 lines · Joel Schopp
These MSRs don't make sense in guest mode. The real question is if we fix that in KVM, here, or both. I'm a fan of fixing it in both places. Xen's behavior is to return a value of 0 if the guest tries to access these, that seems like a reasonable thing to do in KVM as well. I am volunteering myself to write that patch for KVM, but I would encourage
This should be first and foremost fixed in KVM as it is KVM which is advertizing MCA CPUID feature and the guest simply uses it with all MSRs which belong to it.
Quoted 1 line
accepting an updated version of this patch as well.
If you want to do that, I'd suggest using the error checking variants in arch/x86/lib/msr.c which should also facilitate toggling of bits in MSRs.
Quoted 2 lines
Initializing val to 0 where it is declared should have the desired effect.
Yes, as long as KVM returns 0 for MC4_MISC0/1.
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--