Skip to contentSkip to conversation

x86/microcode: early microcode patch loading support on AMD

PATCH Superseded Jacob Shin 2 participants 5 messages May 23, 2013 x86

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jacob Shin

author
#0 lore raw

cover x86/microcode: early microcode patch loading support on AMD

The following patchset adds early microcode patch loading support on AMD systems, on top of the framework introduced by:
https://lkml.org/lkml/2012/12/21/193

Jacob Shin (2):
x86/microcode: vendor abstract out save_microcode_in_initrd() x86/microcode: early microcode patch loading support on AMD

 arch/x86/Kconfig                        |   14 +-
 arch/x86/include/asm/microcode_amd.h    |   14 ++
 arch/x86/include/asm/microcode_intel.h  |    2 +
 arch/x86/kernel/microcode_amd.c         |  335 +++++++++++++++++++++++++++----
 arch/x86/kernel/microcode_core_early.c  |   17 ++
 arch/x86/kernel/microcode_intel_early.c |    2 +-
 6 files changed, 337 insertions(+), 47 deletions(-)
 create mode 100644 arch/x86/include/asm/microcode_amd.h
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 1/2 x86/microcode: vendor abstract out save_microcode_in_initrd()

Currently save_microcode_in_initrd() is declared in vendor neutural microcode.h file, but defined in vendor specific microcode_intel_early.c file. Vendor abstract it out to microcode_core_early.c with a wrapper function.

---
 arch/x86/include/asm/microcode_intel.h  |    2 ++
 arch/x86/kernel/microcode_core_early.c  |   10 ++++++++++
 arch/x86/kernel/microcode_intel_early.c |    2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)
arch/x86/include/asm/microcode_intel.h +2 -0
index 5356f92..cf729eb 100644
@@ -67,10 +67,12 @@ update_match_revision(struct microcode_header_intel *mc_header, int rev);
 extern void __init load_ucode_intel_bsp(void);
 extern void __cpuinit load_ucode_intel_ap(void);
 extern void show_ucode_info_early(void);
+extern int __init save_microcode_in_initrd_intel(void);
 #else
 static inline __init void load_ucode_intel_bsp(void) {}
 static inline __cpuinit void load_ucode_intel_ap(void) {}
 static inline void show_ucode_info_early(void) {}
+static inline int __init save_microcode_in_initrd_intel(void) {}
 #endif
 
 #if defined(CONFIG_MICROCODE_INTEL_EARLY) && defined(CONFIG_HOTPLUG_CPU)
arch/x86/kernel/microcode_core_early.c +10 -0
index 833d51d..0d19ac5 100644
@@ -98,3 +98,13 @@ void __cpuinit load_ucode_ap(void)
 	if (vendor == X86_VENDOR_INTEL && x86 >= 6)
 		load_ucode_intel_ap();
 }
+
+int __init save_microcode_in_initrd(void)
+{
+	struct cpuinfo_x86 *c = &boot_cpu_data;
+
+	if (c->x86_vendor == X86_VENDOR_INTEL && c->x86 >= 6)
+		return save_microcode_in_initrd_intel();
+
+	return 0;
+}
arch/x86/kernel/microcode_intel_early.c +1 -1
index 2e9e128..88f0edc 100644
@@ -699,7 +699,7 @@ static int __cpuinit apply_microcode_early(struct mc_saved_data *mc_saved_data,
  * This function converts microcode patch offsets previously stored in
  * mc_saved_in_initrd to pointers and stores the pointers in mc_saved_data.
  */
-int __init save_microcode_in_initrd(void)
+int __init save_microcode_in_initrd_intel(void)
 {
 	unsigned int count = mc_saved_data.mc_saved_count;
 	struct microcode_intel *mc_saved[MAX_UCODE_COUNT];
Signature · 1 line
1.7.9.5
maintainer
#2 lore raw

Re: [PATCH 1/2] x86/microcode: vendor abstract out save_microcode_in_initrd()

Quoted 17 lines · Jacob Shin

Currently save_microcode_in_initrd() is declared in vendor neutural microcode.h file, but defined in vendor specific microcode_intel_early.c file. Vendor abstract it out to microcode_core_early.c with a wrapper function.

---
 arch/x86/include/asm/microcode_intel.h  |    2 ++
 arch/x86/kernel/microcode_core_early.c  |   10 ++++++++++
 arch/x86/kernel/microcode_intel_early.c |    2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)
arch/x86/include/asm/microcode_intel.h +0 -0
index 5356f92..cf729eb 100644

arch/x86/include/asm/microcode_intel.h update_match_revision(struct microcode_header_intel *mc_header, int rev); · line 75

Quoted 9 lines
arch/x86/include/asm/microcode_intel.h +2 -0
@@ -67,10 +67,12 @@ update_match_revision(struct microcode_header_intel *mc_header, int rev);
 extern void __init load_ucode_intel_bsp(void);
 extern void __cpuinit load_ucode_intel_ap(void);
 extern void show_ucode_info_early(void);
+extern int __init save_microcode_in_initrd_intel(void);
 #else
 static inline __init void load_ucode_intel_bsp(void) {}
 static inline __cpuinit void load_ucode_intel_ap(void) {}
 static inline void show_ucode_info_early(void) {}
+static inline int __init save_microcode_in_initrd_intel(void) {}

In file included from arch/x86/kernel/cpu/common.c:41:0:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h: In function ‘save_microcode_in_initrd_intel’:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h:75:1: warning: no return statement in function returning non-void [-Wreturn-type] In file included from arch/x86/kernel/microcode_intel_lib.c:30:0:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h: In function ‘save_microcode_in_initrd_intel’:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h:75:1: warning: no return statement in function returning non-void [-Wreturn-type] In file included from arch/x86/kernel/microcode_intel.c:82:0:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h: In function ‘save_microcode_in_initrd_intel’:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h:75:1: warning: no return statement in function returning non-void [-Wreturn-type] Setup is 15436 bytes (padded to 15872 bytes).
System is 4268 kB
CRC a330a73f

You need:

arch/x86/include/asm/microcode_intel.h +1 -1
index cf729eb3beee..87a085333cbf 100644
@@ -72,7 +72,7 @@ extern int __init save_microcode_in_initrd_intel(void);
 static inline __init void load_ucode_intel_bsp(void) {}
 static inline __cpuinit void load_ucode_intel_ap(void) {}
 static inline void show_ucode_info_early(void) {}
-static inline int __init save_microcode_in_initrd_intel(void) {}
+static inline int __init save_microcode_in_initrd_intel(void) { return -EINVAL; }
 #endif
 
 #if defined(CONFIG_MICROCODE_INTEL_EARLY) && defined(CONFIG_HOTPLUG_CPU)

Btw,

could you pick up this trivial fix and add it to your set - I can't help myself when I see typos, especially in user-visible printks :)

Thanks.

--

Quoted 1 line

From fefc8dec3fb301f217909f04a1805563fcd65329 Mon Sep 17 00:00:00 2001

From: Borislav Petkov <[email protected]>
Date: Thu, 23 May 2013 09:51:06 +0200
Subject: [PATCH] x86, microcode, intel: Correct typo in printk

User-visible so correct it.

---
 arch/x86/kernel/microcode_intel_early.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/microcode_intel_early.c +1 -1
index 88f0edc8bb25..317aea99f130 100644
@@ -711,7 +711,7 @@ int __init save_microcode_in_initrd_intel(void)
 	microcode_pointer(mc_saved, mc_saved_in_initrd, initrd_start, count);
 	ret = save_microcode(&mc_saved_data, mc_saved, count);
 	if (ret)
-		pr_err("Can not save microcod patches from initrd");
+		pr_err("Cannot save microcode patches from initrd.\n");
 
 	show_saved_mc();
 
Signature · 9 lines
1.8.3.rc0


-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
author
#3 lore raw

Re: [PATCH 1/2] x86/microcode: vendor abstract out save_microcode_in_initrd()

Quoted 48 lines · Borislav Petkov
Quoted 17 lines · Jacob Shin

Currently save_microcode_in_initrd() is declared in vendor neutural microcode.h file, but defined in vendor specific microcode_intel_early.c file. Vendor abstract it out to microcode_core_early.c with a wrapper function.

---
 arch/x86/include/asm/microcode_intel.h  |    2 ++
 arch/x86/kernel/microcode_core_early.c  |   10 ++++++++++
 arch/x86/kernel/microcode_intel_early.c |    2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)
arch/x86/include/asm/microcode_intel.h +0 -0
index 5356f92..cf729eb 100644

arch/x86/include/asm/microcode_intel.h update_match_revision(struct microcode_header_intel *mc_header, int rev); · line 75

Quoted 9 lines
arch/x86/include/asm/microcode_intel.h +2 -0
@@ -67,10 +67,12 @@ update_match_revision(struct microcode_header_intel *mc_header, int rev);
 extern void __init load_ucode_intel_bsp(void);
 extern void __cpuinit load_ucode_intel_ap(void);
 extern void show_ucode_info_early(void);
+extern int __init save_microcode_in_initrd_intel(void);
 #else
 static inline __init void load_ucode_intel_bsp(void) {}
 static inline __cpuinit void load_ucode_intel_ap(void) {}
 static inline void show_ucode_info_early(void) {}
+static inline int __init save_microcode_in_initrd_intel(void) {}

In file included from arch/x86/kernel/cpu/common.c:41:0:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h: In function ‘save_microcode_in_initrd_intel’:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h:75:1: warning: no return statement in function returning non-void [-Wreturn-type] In file included from arch/x86/kernel/microcode_intel_lib.c:30:0:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h: In function ‘save_microcode_in_initrd_intel’:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h:75:1: warning: no return statement in function returning non-void [-Wreturn-type] In file included from arch/x86/kernel/microcode_intel.c:82:0:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h: In function ‘save_microcode_in_initrd_intel’:
/w/kernel/linux-2.6/arch/x86/include/asm/microcode_intel.h:75:1: warning: no return statement in function returning non-void [-Wreturn-type] Setup is 15436 bytes (padded to 15872 bytes).
System is 4268 kB
CRC a330a73f

You need:

arch/x86/include/asm/microcode_intel.h +0 -0
index cf729eb3beee..87a085333cbf 100644

arch/x86/include/asm/microcode_intel.h extern int __init save_microcode_in_initrd_intel(void); · line 75

Quoted 5 lines
arch/x86/include/asm/microcode_intel.h +1 -1
@@ -72,7 +72,7 @@ extern int __init save_microcode_in_initrd_intel(void);
 static inline __init void load_ucode_intel_bsp(void) {}
 static inline __cpuinit void load_ucode_intel_ap(void) {}
 static inline void show_ucode_info_early(void) {}
-static inline int __init save_microcode_in_initrd_intel(void) {}
+static inline int __init save_microcode_in_initrd_intel(void) { return -EINVAL; }

Oops, sorry about that. Will fix,

Quoted 8 lines
arch/x86/include/asm/microcode_intel.h +0 -0
 #endif
 
 #if defined(CONFIG_MICROCODE_INTEL_EARLY) && defined(CONFIG_HOTPLUG_CPU)

Btw,

could you pick up this trivial fix and add it to your set - I can't help myself when I see typos, especially in user-visible printks :)

Will do and send out a V2 today.

Thanks!

author
#4 lore raw

PATCH 2/2 x86/microcode: early microcode patch loading support on AMD

In reply to Jacob Shin

Add support for early microcode patch loading on AMD.

---
 arch/x86/Kconfig                       |   14 +-
 arch/x86/include/asm/microcode_amd.h   |   14 ++
 arch/x86/kernel/microcode_amd.c        |  335 ++++++++++++++++++++++++++++----
 arch/x86/kernel/microcode_core_early.c |    7 +
 4 files changed, 324 insertions(+), 46 deletions(-)
 create mode 100644 arch/x86/include/asm/microcode_amd.h
arch/x86/Kconfig +9 -5
index 3a5bced..8ab7b6a 100644
@@ -1090,8 +1090,16 @@ config MICROCODE_INTEL_LIB
 	depends on MICROCODE_INTEL
 
 config MICROCODE_INTEL_EARLY
-	bool "Early load microcode"
+	def_bool y
 	depends on MICROCODE_INTEL && BLK_DEV_INITRD
+
+config MICROCODE_AMD_EARLY
+	def_bool y
+	depends on MICROCODE_AMD && BLK_DEV_INITRD
+
+config MICROCODE_EARLY
+	bool "Early load microcode"
+	depends on MICROCODE_INTEL_EARLY || MICROCODE_AMD_EARLY
 	default y
 	help
 	  This option provides functionality to read additional microcode data
@@ -1099,10 +1107,6 @@ config MICROCODE_INTEL_EARLY
 	  microcode to CPU's as early as possible. No functional change if no
 	  microcode data is glued to the initrd, therefore it's safe to say Y.
 
-config MICROCODE_EARLY
-	def_bool y
-	depends on MICROCODE_INTEL_EARLY
-
 config X86_MSR
 	tristate "/dev/cpu/*/msr - Model-specific register support"
 	---help---
arch/x86/include/asm/microcode_amd.h new file +14 -0
new file mode 100644
index 0000000..56274b3
@@ -0,0 +1,14 @@
+#ifndef _ASM_X86_MICROCODE_AMD_H
+#define _ASM_X86_MICROCODE_AMD_H
+
+#ifdef CONFIG_MICROCODE_AMD_EARLY
+extern void __init load_ucode_amd_bsp(void);
+extern void __cpuinit load_ucode_amd_ap(void);
+extern int __init save_microcode_in_initrd_amd(void);
+#else
+static inline void __init load_ucode_amd_bsp(void) {}
+static inline void __cpuinit load_ucode_amd_ap(void) {}
+static inline int __init save_microcode_in_initrd_amd(void) {}
+#endif
+
+#endif /* _ASM_X86_MICROCODE_AMD_H */
arch/x86/kernel/microcode_amd.c +294 -41

423 lines not on this page · raw message

arch/x86/kernel/microcode_core_early.c +7 -0
index 0d19ac5..1221c22 100644
@@ -18,6 +18,7 @@
  */
 #include <linux/module.h>
 #include <asm/microcode_intel.h>
+#include <asm/microcode_amd.h>
 #include <asm/processor.h>
 
 #define QCHAR(a, b, c, d) ((a) + ((b) << 8) + ((c) << 16) + ((d) << 24))
@@ -83,6 +84,8 @@ void __init load_ucode_bsp(void)
 
 	if (vendor == X86_VENDOR_INTEL && x86 >= 6)
 		load_ucode_intel_bsp();
+	else if (vendor == X86_VENDOR_AMD && x86 >= 0x10)
+		load_ucode_amd_bsp();
 }
 
 void __cpuinit load_ucode_ap(void)
@@ -97,6 +100,8 @@ void __cpuinit load_ucode_ap(void)
 
 	if (vendor == X86_VENDOR_INTEL && x86 >= 6)
 		load_ucode_intel_ap();
+	else if (vendor == X86_VENDOR_AMD && x86 >= 0x10)
+		load_ucode_amd_ap();
 }
 
 int __init save_microcode_in_initrd(void)
@@ -105,6 +110,8 @@ int __init save_microcode_in_initrd(void)
 
 	if (c->x86_vendor == X86_VENDOR_INTEL && c->x86 >= 6)
 		return save_microcode_in_initrd_intel();
+	else if (c->x86_vendor == X86_VENDOR_AMD && c->x86 >= 0x10)
+		return save_microcode_in_initrd_amd();
 
 	return 0;
 }
Signature · 1 line
1.7.9.5