x86, amd_ucode: Safeguard against #GP
PATCH 1/1 x86, amd_ucode: Safeguard against #GP
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use wrmsr_safe instead so that we fail to load microcode gracefully.
Example on a Fam15h system-
(XEN) microcode: CPU0 collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID 0x6012 rev 0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version 0x6000637 (current=0x6000626)
(XEN) traps.c:3073: GPF (0000): ffff82d08016f682 -> ffff82d08022d9f8 (XEN) microcode: CPU0 update from revision 0x6000637 to 0x6000626 failed
--- xen/arch/x86/microcode_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/microcode_amd.c +1 -1
@@ -191,7 +191,7 @@ static int apply_microcode(int cpu)spin_lock_irqsave (µcode_update_lock, flags); -wrmsrl (MSR_AMD_PATCHLOADER , (unsigned long )hdr); +wrmsr_safe (MSR_AMD_PATCHLOADER , (unsigned long )hdr);/* get patch id after patching */ rdmsrl (MSR_AMD_PATCHLEVEL , rev);
Signature · 1 line
1.7.9.5
Quoted 13 lines · Aravind Gopalakrishnan
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failed
Quoted 1 line
Signed-off-by Aravind Gopalakrishnan <[email protected]>
Quoted 17 lines
--- xen/arch/x86/microcode_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/x86/microcode_amd.c +1
-1@@ -191,7 +191,7 @@ static int apply_microcode(int cpu)spin_lock_irqsave (µcode_update_lock, flags); -wrmsrl (MSR_AMD_PATCHLOADER , (unsigned long )hdr); +wrmsr_safe (MSR_AMD_PATCHLOADER , (unsigned long )hdr);/* get patch id after patching */ rdmsrl (MSR_AMD_PATCHLEVEL , rev);
Quoted 13 lines · Aravind Gopalakrishnan
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failed
Quoted 1 line
Signed-off-by Aravind Gopalakrishnan <[email protected]>
I suspect that you will find with a *very* up-to-date master tree, an early #GP should result in panic() instead of a hang, following 279840d5ea646 (If it doesn't I would be interested to know)
As for the patch itself, is it worth using the failure to purge this patch from the cache? Nothing good can come of attempting to load the same patch on a different cpu.
~Andrew
Quoted 17 lines
--- xen/arch/x86/microcode_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/x86/microcode_amd.c +1
-1@@ -191,7 +191,7 @@ static int apply_microcode(int cpu)spin_lock_irqsave (µcode_update_lock, flags); -wrmsrl (MSR_AMD_PATCHLOADER , (unsigned long )hdr); +wrmsr_safe (MSR_AMD_PATCHLOADER , (unsigned long )hdr);/* get patch id after patching */ rdmsrl (MSR_AMD_PATCHLEVEL , rev);
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Aravind Gopalakrishnan
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failed
Quoted 4 lines
Quoted 1 line
Signed-off-by Aravind Gopalakrishnan <[email protected]>I suspect that you will find with a *very* up-to-date master tree, an early #GP should result in
panic()instead of a hang, following279840d5ea646(If it doesn't I would be interested to know)
The console log states 'Panic on CPU0'. But system is basically hung after that. (attached snapshot)
Quoted 5 lines
As for the patch itself, is it worth using the failure to purge this patch from the cache? Nothing good can come of attempting to load the same patch on a different cpu.
I don't think we do..
We only save the patch for apply on resume if 'applied_offset' has a value right?
-Aravind.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 16 lines · Aravind Gopalakrishnan
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Aravind Gopalakrishnan
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failed
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Aravind Gopalakrishnan <[email protected]>I suspect that you will find with a *very* up-to-date master tree, an early #GP should result in
panic()instead of a hang, following279840d5ea646(If it doesn't I would be interested to know)The console log states 'Panic on CPU0'. But system is basically hung after that.
(attached snapshot)
I refer you to the last line :)
You have "noreboot" on your command line
~Andrew
Quoted 21 lines · Andrew Cooper
Quoted 20 lines · Aravind Gopalakrishnan
Quoted 19 lines · Andrew Cooper
Quoted 14 lines · Aravind Gopalakrishnan
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failedQuoted 1 line
Signed-off-by Aravind Gopalakrishnan <[email protected]>I suspect that you will find with a *very* up-to-date master tree, an early #GP should result in
panic()instead of a hang, following279840d5ea646(If it doesn't I would be interested to know)
Quoted 7 lines
Quoted 3 lines
The console log states 'Panic on CPU0'. But system is basically hung after that.
(attached snapshot)I refer you to the last line :)
You have "noreboot" on your command line
Ah. Okay, Will try again.
Thanks,
-Aravind.
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 21.05.14 at 23:28, <[email protected]> wrote:
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failedSigned-off-by Aravind Gopalakrishnan <[email protected]>--- xen/arch/x86/microcode_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/x86/microcode_amd.c +0
-0
xen/arch/x86/microcode_amd.c static int apply_microcode(int cpu) · line 194
Quoted 5 lines
xen/arch/x86/microcode_amd.c +1
-1@@ -191,7 +191,7 @@ static int apply_microcode(int cpu)spin_lock_irqsave (µcode_update_lock, flags); -wrmsrl (MSR_AMD_PATCHLOADER , (unsigned long )hdr); +wrmsr_safe (MSR_AMD_PATCHLOADER , (unsigned long )hdr);
I think you shouldn't ignore the "return" value here.
Also the last quoted log message above has the two revisions reversed - mind fixing this at the same time?
Jan
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 21.05.14 at 23:28, <[email protected]> wrote:
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failedSigned-off-by Aravind Gopalakrishnan <[email protected]>--- xen/arch/x86/microcode_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/x86/microcode_amd.c +0
-0@@ -191,7 +191,7 @@ static int apply_microcode(int cpu)
Quoted 5 lines
xen/arch/x86/microcode_amd.c static int apply_microcode(int cpu) · line 194
Quoted 4 lines
xen/arch/x86/microcode_amd.c +1
-1spin_lock_irqsave (µcode_update_lock, flags); -wrmsrl (MSR_AMD_PATCHLOADER , (unsigned long )hdr); +wrmsr_safe (MSR_AMD_PATCHLOADER , (unsigned long )hdr);I think you shouldn't ignore the "return" value here.
Not sure I understand..
Do you mean you want to capture return value and bubble it up? maybe print a debug message too? Since we check if patch application succeeded using -
if ( rev != hdr->patch_id )
and return a error val here, would this not be sufficient?
Quoted 4 lines
Also the last quoted log message above has the two revisions reversed - mind fixing this at the same time?
Will fix this.
Thanks,
-Aravind.
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 17:59, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 21.05.14 at 23:28, <[email protected]> wrote:
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failedSigned-off-by Aravind Gopalakrishnan <[email protected]>--- xen/arch/x86/microcode_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/x86/microcode_amd.c +0
-0@@ -191,7 +191,7 @@ static int apply_microcode(int cpu)
Quoted 8 lines
Quoted 5 lines
xen/arch/x86/microcode_amd.c static int apply_microcode(int cpu) · line 194
Quoted 4 lines
xen/arch/x86/microcode_amd.c +1
-1spin_lock_irqsave (µcode_update_lock, flags); -wrmsrl (MSR_AMD_PATCHLOADER , (unsigned long )hdr); +wrmsr_safe (MSR_AMD_PATCHLOADER , (unsigned long )hdr);I think you shouldn't ignore the "return" value here.
Not sure I understand..
Do you mean you want to capture return value and bubble it up? maybe print a debug message too?
Yes.
Quoted 3 lines
Since we check if patch application succeeded using - if ( rev !=
hdr->patch_id)
and return a error val here, would this not be sufficient?
It might, but I'm of the opinion that errors should never be ignored _and_ be detected as early as possible.
Jan
Quoted 35 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 22.05.14 at 17:59, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 21.05.14 at 23:28, <[email protected]> wrote:
When HW tries to load a corrupted patch, it generates #GP and hangs the system. Use
wrmsr_safeinstead so that we fail to load microcode gracefully.Example on a Fam15h system-
(XEN) microcode: CPU0collect_cpu_info: patch_id=0x6000626 (XEN) microcode: CPU0 size 7870, block size 2586 offset 76 equivID0x6012rev0x6000637
(XEN) microcode: CPU0 found a matching microcode update with version0x6000637(current=0x6000626)
(XEN) traps.c:3073: GPF (0000):ffff82d08016f682->ffff82d08022d9f8(XEN) microcode: CPU0 update from revision0x6000637to0x6000626failedSigned-off-by Aravind Gopalakrishnan <[email protected]>--- xen/arch/x86/microcode_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/x86/microcode_amd.c +0
-0@@ -191,7 +191,7 @@ static int apply_microcode(int cpu)Quoted 8 lines
Quoted 5 lines
xen/arch/x86/microcode_amd.c static int apply_microcode(int cpu) · line 194
Quoted 4 lines
xen/arch/x86/microcode_amd.c +1
-1spin_lock_irqsave (µcode_update_lock, flags); -wrmsrl (MSR_AMD_PATCHLOADER , (unsigned long )hdr); +wrmsr_safe (MSR_AMD_PATCHLOADER , (unsigned long )hdr);I think you shouldn't ignore the "return" value here.
Not sure I understand..
Do you mean you want to capture return value and bubble it up? maybe print a debug message too?
Quoted 9 lines
Yes.
Quoted 3 lines
Since we check if patch application succeeded using - if ( rev !=
hdr->patch_id)
and return a error val here, would this not be sufficient?It might, but I'm of the opinion that errors should never be ignored _and_ be detected as early as possible.
Have addressed above issues and sending out V2 with Boris' Reviewed-by tag.
Thanks,
-Aravind.