* [PATCH v2] mce: use safe MSR accesses
@ 2015-03-13 16:03 jesse.larrew
2015-03-13 16:29 ` Luck, Tony
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: jesse.larrew @ 2015-03-13 16:03 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>
Certain MSRs are only relevant to a kernel in host mode, and kvm had
chosen not to implement these MSRs at all for guests. If a guest kernel
ever tried to access these MSRs, the result was a general protection
fault.
KVM will be separately patched to return 0 when these MSRs are read,
and this patch ensures that MSR accesses are tolerant of exceptions.
Signed-off-by: Jesse Larrew <jesse.larrew@amd.com>
---
arch/x86/kernel/cpu/mcheck/mce.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 61a9668ce..2737ced 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1540,7 +1540,7 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
if (c->x86 == 0x15 &&
(c->x86_model >= 0x10 && c->x86_model <= 0x1f)) {
int i;
- u64 val, hwcr;
+ u64 hwcr;
bool need_toggle;
u32 msrs[] = {
0x00000413, /* MC4_MISC0 */
@@ -1556,13 +1556,8 @@ 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);
-
- /* CntP bit set? */
- if (val & BIT_64(62)) {
- val &= ~BIT_64(62);
- wrmsrl(msrs[i], val);
- }
+ /* Clear CntP bit safely */
+ msr_clear_bit(msrs[i], 62);
}
/* restore old settings */
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH v2] mce: use safe MSR accesses
2015-03-13 16:03 [PATCH v2] mce: use safe MSR accesses jesse.larrew
@ 2015-03-13 16:29 ` Luck, Tony
2015-03-13 16:51 ` Joel Schopp
2015-03-13 22:22 ` Borislav Petkov
2 siblings, 0 replies; 4+ messages in thread
From: Luck, Tony @ 2015-03-13 16:29 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
- rdmsrl(msrs[i], val);
-
- /* CntP bit set? */
- if (val & BIT_64(62)) {
- val &= ~BIT_64(62);
- wrmsrl(msrs[i], val);
- }
+ /* Clear CntP bit safely */
+ msr_clear_bit(msrs[i], 62);
Very nice! Clean solution with less lines of code than the original.
Acked-by: Tony Luck <tony.luck@intel.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mce: use safe MSR accesses
2015-03-13 16:03 [PATCH v2] mce: use safe MSR accesses jesse.larrew
2015-03-13 16:29 ` Luck, Tony
@ 2015-03-13 16:51 ` Joel Schopp
2015-03-13 22:22 ` Borislav Petkov
2 siblings, 0 replies; 4+ messages in thread
From: Joel Schopp @ 2015-03-13 16:51 UTC (permalink / raw)
To: jesse.larrew, x86
Cc: Tony Luck, Borislav Petkov, Thomas Gleixner, Ingo Molnar,
H. Peter Anvin, linux-edac, linux-kernel
On 03/13/2015 11:03 AM, jesse.larrew@amd.com wrote:
> From: Jesse Larrew <jesse.larrew@amd.com>
>
> Certain MSRs are only relevant to a kernel in host mode, and kvm had
> chosen not to implement these MSRs at all for guests. If a guest kernel
> ever tried to access these MSRs, the result was a general protection
> fault.
>
> KVM will be separately patched to return 0 when these MSRs are read,
> and this patch ensures that MSR accesses are tolerant of exceptions.
>
> Signed-off-by: Jesse Larrew <jesse.larrew@amd.com>
> ---
> arch/x86/kernel/cpu/mcheck/mce.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
> index 61a9668ce..2737ced 100644
> --- a/arch/x86/kernel/cpu/mcheck/mce.c
> +++ b/arch/x86/kernel/cpu/mcheck/mce.c
> @@ -1540,7 +1540,7 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
> if (c->x86 == 0x15 &&
> (c->x86_model >= 0x10 && c->x86_model <= 0x1f)) {
> int i;
> - u64 val, hwcr;
> + u64 hwcr;
> bool need_toggle;
> u32 msrs[] = {
> 0x00000413, /* MC4_MISC0 */
> @@ -1556,13 +1556,8 @@ 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);
> -
> - /* CntP bit set? */
> - if (val & BIT_64(62)) {
> - val &= ~BIT_64(62);
> - wrmsrl(msrs[i], val);
> - }
> + /* Clear CntP bit safely */
> + msr_clear_bit(msrs[i], 62);
> }
>
> /* restore old settings */
I like it.
Reviewed-by: Joel Schopp <joel.schopp@amd.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mce: use safe MSR accesses
2015-03-13 16:03 [PATCH v2] mce: use safe MSR accesses jesse.larrew
2015-03-13 16:29 ` Luck, Tony
2015-03-13 16:51 ` Joel Schopp
@ 2015-03-13 22:22 ` Borislav Petkov
2 siblings, 0 replies; 4+ messages in thread
From: Borislav Petkov @ 2015-03-13 22:22 UTC (permalink / raw)
To: jesse.larrew
Cc: x86, Joel Schopp, Tony Luck, Thomas Gleixner, Ingo Molnar,
H. Peter Anvin, linux-edac, linux-kernel
On Fri, Mar 13, 2015 at 11:03:39AM -0500, jesse.larrew@amd.com wrote:
> From: Jesse Larrew <jesse.larrew@amd.com>
>
> Certain MSRs are only relevant to a kernel in host mode, and kvm had
> chosen not to implement these MSRs at all for guests. If a guest kernel
> ever tried to access these MSRs, the result was a general protection
> fault.
>
> KVM will be separately patched to return 0 when these MSRs are read,
> and this patch ensures that MSR accesses are tolerant of exceptions.
>
> Signed-off-by: Jesse Larrew <jesse.larrew@amd.com>
> ---
> arch/x86/kernel/cpu/mcheck/mce.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
Applied, 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-13 22:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-13 16:03 [PATCH v2] mce: use safe MSR accesses jesse.larrew
2015-03-13 16:29 ` Luck, Tony
2015-03-13 16:51 ` Joel Schopp
2015-03-13 22:22 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox