* [PATCH] mce: use safe MSR accesses
@ 2015-03-11 22:09 jesse.larrew
2015-03-11 22:47 ` Luck, Tony
0 siblings, 1 reply; 4+ messages in thread
From: jesse.larrew @ 2015-03-11 22:09 UTC (permalink / raw)
To: x86
Cc: Joel Schopp, Tony Luck, Borislav Petkov, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, linux-edac, linux-kernel,
Jesse Larrew
From: Jesse Larrew <jesse.larrew@amd.com>
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.
Signed-off-by: Jesse Larrew <jesse.larrew@amd.com>
---
arch/x86/kernel/cpu/mcheck/mce.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 61a9668ce..4151ba9 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -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);
}
}
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] mce: use safe MSR accesses
2015-03-11 22:09 [PATCH] mce: use safe MSR accesses jesse.larrew
@ 2015-03-11 22:47 ` Luck, Tony
2015-03-12 17:20 ` Joel Schopp
0 siblings, 1 reply; 4+ messages in thread
From: Luck, Tony @ 2015-03-11 22:47 UTC (permalink / raw)
To: jesse.larrew@amd.com, x86@kernel.org
Cc: Joel Schopp, Borislav Petkov, Thomas Gleixner, Ingo Molnar,
H. Peter Anvin, linux-edac@vger.kernel.org,
linux-kernel@vger.kernel.org
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mce: use safe MSR accesses
2015-03-11 22:47 ` Luck, Tony
@ 2015-03-12 17:20 ` Joel Schopp
2015-03-12 17:30 ` Borislav Petkov
0 siblings, 1 reply; 4+ messages in thread
From: Joel Schopp @ 2015-03-12 17:20 UTC (permalink / raw)
To: Luck, Tony, jesse.larrew@amd.com, x86@kernel.org
Cc: Borislav Petkov, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org
On 03/11/2015 05:47 PM, Luck, Tony wrote:
>> 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.
>
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mce: use safe MSR accesses
2015-03-12 17:20 ` Joel Schopp
@ 2015-03-12 17:30 ` Borislav Petkov
0 siblings, 0 replies; 4+ messages in thread
From: Borislav Petkov @ 2015-03-12 17:30 UTC (permalink / raw)
To: Joel Schopp
Cc: Luck, Tony, jesse.larrew@amd.com, x86@kernel.org, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, linux-edac@vger.kernel.org,
linux-kernel@vger.kernel.org
On Thu, Mar 12, 2015 at 12:20:07PM -0500, Joel Schopp wrote:
> 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.
> 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.
> 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.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-12 17:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-11 22:09 [PATCH] mce: use safe MSR accesses jesse.larrew
2015-03-11 22:47 ` Luck, Tony
2015-03-12 17:20 ` Joel Schopp
2015-03-12 17:30 ` Borislav Petkov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.