Skip to content

Commit f77ac50

Browse files
Jesse LarrewIngo Molnar
authored andcommitted
x86/mce: Use safe MSR accesses for AMD quirk
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> [ Drop {} braces around loop ] Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Joel Schopp <joel.schopp@amd.com> Acked-by: Tony Luck <tony.luck@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-edac@vger.kernel.org Link: http://lkml.kernel.org/r/1426262619-5016-1-git-send-email-jesse.larrew@amd.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent fa45a45 commit f77ac50

File tree

1 file changed

+4
-10
lines changed
  • arch/x86/kernel/cpu/mcheck

1 file changed

+4
-10
lines changed

arch/x86/kernel/cpu/mcheck/mce.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
15411541
if (c->x86 == 0x15 &&
15421542
(c->x86_model >= 0x10 && c->x86_model <= 0x1f)) {
15431543
int i;
1544-
u64 val, hwcr;
1544+
u64 hwcr;
15451545
bool need_toggle;
15461546
u32 msrs[] = {
15471547
0x00000413, /* MC4_MISC0 */
@@ -1556,15 +1556,9 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
15561556
if (need_toggle)
15571557
wrmsrl(MSR_K7_HWCR, hwcr | BIT(18));
15581558

1559-
for (i = 0; i < ARRAY_SIZE(msrs); i++) {
1560-
rdmsrl(msrs[i], val);
1561-
1562-
/* CntP bit set? */
1563-
if (val & BIT_64(62)) {
1564-
val &= ~BIT_64(62);
1565-
wrmsrl(msrs[i], val);
1566-
}
1567-
}
1559+
/* Clear CntP bit safely */
1560+
for (i = 0; i < ARRAY_SIZE(msrs); i++)
1561+
msr_clear_bit(msrs[i], 62);
15681562

15691563
/* restore old settings */
15701564
if (need_toggle)

0 commit comments

Comments
 (0)