Skip to contentSkip to conversation

x86/microcode: Rework microcode loading

PATCH New Borislav Petkov 2 participants 25 messages Oct 25, 2016

Subsystems (2)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

cover x86/microcode: Rework microcode loading

From: Borislav Petkov <[email protected]>

So this is something I've been meaning to do for a while now: cleanup the Intel side of the microcode loader. But who has time?

Luckily (or not), CONFIG_RANDOMIZE_MEMORY came about and broke the loader just enough so that I can finally force myself to go and clean it all up, make it more robust.

So this is my attempt at it, the meat of the whole change is patch 11. Which is unreadable as a diff to almost everyone, except to me, maybe :) But it is the only way I could think of to do this without breaking the driver knowingly. Oh, and staring at the code after the patch applied makes it much clearer and nicer again anyway.

This pile has been tested on both AMD and Intel boxes of different garden variety, with suspend to disk and to RAM and 32-bit and 64-bit.

Comments, suggestions and eventual pickup are appreciated :)

Thanks.

Borislav Petkov (12):
x86/microcode: Run the AP-loading routine only on the application
processors
x86/microcode: Move driver authors to CREDITS x86/microcode/intel: Simplify generic_load_microcode() x86/microcode: Remove one ifdef clause
x86/microcode: Export the microcode cache linked list x86/microcode/AMD: Hand down the CPU family x86/microcode: Issue the debug printk on resume only on success x86/microcode: Collect CPU info on resume x86/microcode/AMD: Retract functions x86/microcode/intel: Remove intel_lib.c
x86/microcode: Rework microcode loading
x86/microcode: Bump driver version, update copyrights

 CREDITS                                   |   4 +
 arch/x86/include/asm/microcode.h          |  18 +-
 arch/x86/include/asm/microcode_amd.h      |  30 +-
 arch/x86/include/asm/microcode_intel.h    |   4 -
 arch/x86/kernel/cpu/common.c              |   7 +-
 arch/x86/kernel/cpu/microcode/Makefile    |   2 +-
 arch/x86/kernel/cpu/microcode/amd.c       | 421 ++++++++-------
 arch/x86/kernel/cpu/microcode/core.c      |  83 ++-
 arch/x86/kernel/cpu/microcode/intel.c     | 834 +++++++++++++-----------------
 arch/x86/kernel/cpu/microcode/intel_lib.c | 184 -------
 10 files changed, 647 insertions(+), 940 deletions(-)
 delete mode 100644 arch/x86/kernel/cpu/microcode/intel_lib.c
Signature · 1 line
2.10.0
author maintainer
#1 lore raw

PATCH 1/12 x86/microcode: Run the AP-loading routine only on the application processors

From: Borislav Petkov <[email protected]>

cpu_init() is run also on the BSP (in addition to the APs):

x86_64_start_kernel

|-> x86_64_start_reservations
|-> start_kernel
|-> trap_init
|-> cpu_init
|-> load_ucode_ap

...

but we run the AP (Application Processors) microcode loading routine there too even though we have a BSP-specific routine for that:
load_ucode_bsp().

Which is unnecessary. So let's limit the AP microcode loading routine to the APs only.

Remove a useless comment while at it.

---
 arch/x86/kernel/cpu/common.c        | 7 ++-----
 arch/x86/kernel/cpu/microcode/amd.c | 5 -----
 2 files changed, 2 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/common.c +2 -5
index 9bd910a7dd0a..1a1d668263b9 100644
@@ -1462,11 +1462,8 @@ void cpu_init(void)
 	 */
 	cr4_init_shadow();
 
-	/*
-	 * Load microcode on this cpu if a valid microcode is available.
-	 * This is early microcode loading procedure.
-	 */
-	load_ucode_ap();
+	if (cpu)
+		load_ucode_ap();
 
 	t = &per_cpu(cpu_tss, cpu);
 	oist = &per_cpu(orig_ist, cpu);
arch/x86/kernel/cpu/microcode/amd.c +0 -5
index 620ab06bcf45..6b3929e80fd4 100644
@@ -357,17 +357,12 @@ static void __init get_bsp_sig(void)
 #else
 void load_ucode_amd_ap(void)
 {
-	unsigned int cpu = smp_processor_id();
 	struct equiv_cpu_entry *eq;
 	struct microcode_amd *mc;
 	u8 *cont = container;
 	u32 rev, eax;
 	u16 eq_id;
 
-	/* Exit if called on the BSP. */
-	if (!cpu)
-		return;
-
 	if (!container)
 		return;
 
Signature · 1 line
2.10.0
#2 lore raw

[tip:x86/microcode] x86/microcode: Run the AP-loading routine only on the application processors

x86/microcode: Run the AP-loading routine only on the application processors
Commit-ID:  777284b66f2326c7cb4c541e2224b638b562a9d3
Gitweb:     http://git.kernel.org/tip/777284b66f2326c7cb4c541e2224b638b562a9d3
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:11 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:57 +0200

x86/microcode: Run the AP-loading routine only on the application processors

cpu_init() is run also on the BSP (in addition to the APs):

x86_64_start_kernel

 |-> x86_64_start_reservations
 |-> start_kernel
 |-> trap_init
 |-> cpu_init
 |-> load_ucode_ap

...

but we run the AP (Application Processors) microcode loading routine there too even though we have a BSP-specific routine for that:
load_ucode_bsp().

Which is unnecessary. So let's limit the AP microcode loading routine to the APs only.

Remove a useless comment while at it.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/cpu/common.c        | 7 ++-----
 arch/x86/kernel/cpu/microcode/amd.c | 5 -----
 2 files changed, 2 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/common.c +2 -5
index 9bd910a..1a1d668 100644
@@ -1462,11 +1462,8 @@ void cpu_init(void)
 	 */
 	cr4_init_shadow();
 
-	/*
-	 * Load microcode on this cpu if a valid microcode is available.
-	 * This is early microcode loading procedure.
-	 */
-	load_ucode_ap();
+	if (cpu)
+		load_ucode_ap();
 
 	t = &per_cpu(cpu_tss, cpu);
 	oist = &per_cpu(orig_ist, cpu);
arch/x86/kernel/cpu/microcode/amd.c +0 -5
index 620ab06..6b3929e 100644
@@ -357,17 +357,12 @@ static void __init get_bsp_sig(void)
 #else
 void load_ucode_amd_ap(void)
 {
-	unsigned int cpu = smp_processor_id();
 	struct equiv_cpu_entry *eq;
 	struct microcode_amd *mc;
 	u8 *cont = container;
 	u32 rev, eax;
 	u16 eq_id;
 
-	/* Exit if called on the BSP. */
-	if (!cpu)
-		return;
-
 	if (!container)
 		return;
 
author maintainer
#3 lore raw

PATCH 2/12 x86/microcode: Move driver authors to CREDITS

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

They're not active anymore.

---
 CREDITS                              | 4 ++++
 arch/x86/kernel/cpu/microcode/core.c | 3 +--
 2 files changed, 5 insertions(+), 2 deletions(-)
CREDITS +4 -0
index 513aaa3546bf..e69077c258eb 100644
@@ -2774,6 +2774,10 @@ S: C/ Mieses 20, 9-B
 S: Valladolid 47009
 S: Spain
 
+N: Peter Oruba
+D: AMD Microcode loader driver
+S: Germany
+
 N: Jens Osterkamp
 E: [email protected]
 D: Maintainer of Spidernet network driver for Cell
arch/x86/kernel/cpu/microcode/core.c +1 -2
index 5ce5155f0695..d0d1a0f5a497 100644
@@ -649,8 +649,7 @@ int __init microcode_init(void)
 	cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/microcode:online",
 				  mc_cpu_online, mc_cpu_down_prep);
 
-	pr_info("Microcode Update Driver: v" MICROCODE_VERSION
-		" <[email protected]>, Peter Oruba\n");
+	pr_info("Microcode Update Driver: v%s.", MICROCODE_VERSION);
 
 	return 0;
 
Signature · 1 line
2.10.0
#4 lore raw

[tip:x86/microcode] x86/microcode: Move driver authors to CREDITS

x86/microcode: Move driver authors to CREDITS
Commit-ID:  5879a267520898d595e9cbcae0aad4739c822146
Gitweb:     http://git.kernel.org/tip/5879a267520898d595e9cbcae0aad4739c822146
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:12 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:57 +0200

x86/microcode: Move driver authors to CREDITS

They're not active anymore.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 CREDITS                              | 4 ++++
 arch/x86/kernel/cpu/microcode/core.c | 3 +--
 2 files changed, 5 insertions(+), 2 deletions(-)
CREDITS +4 -0
index 513aaa3..e69077c 100644
@@ -2774,6 +2774,10 @@ S: C/ Mieses 20, 9-B
 S: Valladolid 47009
 S: Spain
 
+N: Peter Oruba
+D: AMD Microcode loader driver
+S: Germany
+
 N: Jens Osterkamp
 E: [email protected]
 D: Maintainer of Spidernet network driver for Cell
arch/x86/kernel/cpu/microcode/core.c +1 -2
index 5ce5155..d0d1a0f 100644
@@ -649,8 +649,7 @@ int __init microcode_init(void)
 	cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/microcode:online",
 				  mc_cpu_online, mc_cpu_down_prep);
 
-	pr_info("Microcode Update Driver: v" MICROCODE_VERSION
-		" <[email protected]>, Peter Oruba\n");
+	pr_info("Microcode Update Driver: v%s.", MICROCODE_VERSION);
 
 	return 0;
 
author maintainer
#5 lore raw

PATCH 3/12 x86/microcode/intel: Simplify generic_load_microcode()

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Make it return the ucode_state directly instead of assigning to a state variable and jumping to an out: label.

No functionality change.

---
 arch/x86/kernel/cpu/microcode/intel.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +5 -9
index cdc0deab00c9..b84288e08098 100644
@@ -962,7 +962,6 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 	u8 *ucode_ptr = data, *new_mc = NULL, *mc = NULL;
 	int new_rev = uci->cpu_sig.rev;
 	unsigned int leftover = size;
-	enum ucode_state state = UCODE_OK;
 	unsigned int curr_mc_size = 0;
 	unsigned int csig, cpf;
 
@@ -1015,14 +1014,11 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 
 	if (leftover) {
 		vfree(new_mc);
-		state = UCODE_ERROR;
-		goto out;
+		return UCODE_ERROR;
 	}
 
-	if (!new_mc) {
-		state = UCODE_NFOUND;
-		goto out;
-	}
+	if (!new_mc)
+		return UCODE_NFOUND;
 
 	vfree(uci->mc);
 	uci->mc = (struct microcode_intel *)new_mc;
@@ -1036,8 +1032,8 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 
 	pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n",
 		 cpu, new_rev, uci->cpu_sig.rev);
-out:
-	return state;
+
+	return UCODE_OK;
 }
 
 static int get_ucode_fw(void *to, const void *from, size_t n)
Signature · 1 line
2.10.0
#6 lore raw

[tip:x86/microcode] x86/microcode/intel: Simplify generic_load_microcode()

x86/microcode/intel: Simplify generic_load_microcode()
Commit-ID:  f61337d9841210329c177a20061f49fafff3ff76
Gitweb:     http://git.kernel.org/tip/f61337d9841210329c177a20061f49fafff3ff76
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:13 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:57 +0200

x86/microcode/intel: Simplify generic_load_microcode()

Make it return the ucode_state directly instead of assigning to a state variable and jumping to an out: label.

No functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/cpu/microcode/intel.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +5 -9
index cdc0dea..b84288e 100644
@@ -962,7 +962,6 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 	u8 *ucode_ptr = data, *new_mc = NULL, *mc = NULL;
 	int new_rev = uci->cpu_sig.rev;
 	unsigned int leftover = size;
-	enum ucode_state state = UCODE_OK;
 	unsigned int curr_mc_size = 0;
 	unsigned int csig, cpf;
 
@@ -1015,14 +1014,11 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 
 	if (leftover) {
 		vfree(new_mc);
-		state = UCODE_ERROR;
-		goto out;
+		return UCODE_ERROR;
 	}
 
-	if (!new_mc) {
-		state = UCODE_NFOUND;
-		goto out;
-	}
+	if (!new_mc)
+		return UCODE_NFOUND;
 
 	vfree(uci->mc);
 	uci->mc = (struct microcode_intel *)new_mc;
@@ -1036,8 +1032,8 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 
 	pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n",
 		 cpu, new_rev, uci->cpu_sig.rev);
-out:
-	return state;
+
+	return UCODE_OK;
 }
 
 static int get_ucode_fw(void *to, const void *from, size_t n)
author maintainer
#7 lore raw

PATCH 4/12 x86/microcode: Remove one ifdef clause

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Move the function declaration to the other #ifdef CONFIG_MICROCODE together with the other functions.

No functionality change.

---
 arch/x86/include/asm/microcode.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/include/asm/microcode.h +2 -6
index da0d81fa0b54..05e56d0968d4 100644
@@ -56,12 +56,6 @@ struct ucode_cpu_info {
 };
 extern struct ucode_cpu_info ucode_cpu_info[];
 
-#ifdef CONFIG_MICROCODE
-int __init microcode_init(void);
-#else
-static inline int __init microcode_init(void)	{ return 0; };
-#endif
-
 #ifdef CONFIG_MICROCODE_INTEL
 extern struct microcode_ops * __init init_intel_microcode(void);
 #else
@@ -131,11 +125,13 @@ static inline unsigned int x86_cpuid_family(void)
 }
 
 #ifdef CONFIG_MICROCODE
+int __init microcode_init(void);
 extern void __init load_ucode_bsp(void);
 extern void load_ucode_ap(void);
 void reload_early_microcode(void);
 extern bool get_builtin_firmware(struct cpio_data *cd, const char *name);
 #else
+static inline int __init microcode_init(void)			{ return 0; };
 static inline void __init load_ucode_bsp(void)			{ }
 static inline void load_ucode_ap(void)				{ }
 static inline void reload_early_microcode(void)			{ }
Signature · 1 line
2.10.0
#8 lore raw

[tip:x86/microcode] x86/microcode: Remove one #ifdef clause

x86/microcode: Remove one #ifdef clause
Commit-ID:  f5bdfefbf96279b4eb431606cec7a662f5d3ba88
Gitweb:     http://git.kernel.org/tip/f5bdfefbf96279b4eb431606cec7a662f5d3ba88
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:14 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:57 +0200

x86/microcode: Remove one #ifdef clause

Move the function declaration to the other #ifdef CONFIG_MICROCODE together with the other functions.

No functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/include/asm/microcode.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/include/asm/microcode.h +2 -6
index da0d81f..05e56d0 100644
@@ -56,12 +56,6 @@ struct ucode_cpu_info {
 };
 extern struct ucode_cpu_info ucode_cpu_info[];
 
-#ifdef CONFIG_MICROCODE
-int __init microcode_init(void);
-#else
-static inline int __init microcode_init(void)	{ return 0; };
-#endif
-
 #ifdef CONFIG_MICROCODE_INTEL
 extern struct microcode_ops * __init init_intel_microcode(void);
 #else
@@ -131,11 +125,13 @@ static inline unsigned int x86_cpuid_family(void)
 }
 
 #ifdef CONFIG_MICROCODE
+int __init microcode_init(void);
 extern void __init load_ucode_bsp(void);
 extern void load_ucode_ap(void);
 void reload_early_microcode(void);
 extern bool get_builtin_firmware(struct cpio_data *cd, const char *name);
 #else
+static inline int __init microcode_init(void)			{ return 0; };
 static inline void __init load_ucode_bsp(void)			{ }
 static inline void load_ucode_ap(void)				{ }
 static inline void reload_early_microcode(void)			{ }
author maintainer
#9 lore raw

PATCH 5/12 x86/microcode: Export the microcode cache linked list

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

It will be used by both drivers so move it to core.c.

No functionality change.

---
 arch/x86/include/asm/microcode.h     |  9 +++++++++
 arch/x86/kernel/cpu/microcode/amd.c  | 23 +++++++----------------
 arch/x86/kernel/cpu/microcode/core.c |  2 ++
 3 files changed, 18 insertions(+), 16 deletions(-)
arch/x86/include/asm/microcode.h +9 -0
index 05e56d0968d4..91595ecb3689 100644
@@ -20,6 +20,15 @@ do {							\
 			 (u32)((u64)(val)),		\
 			 (u32)((u64)(val) >> 32))
 
+struct ucode_patch {
+	struct list_head plist;
+	void *data;		/* Intel uses only this one */
+	u32 patch_id;
+	u16 equiv_cpu;
+};
+
+extern struct list_head microcode_cache;
+
 struct cpu_signature {
 	unsigned int sig;
 	unsigned int pf;
arch/x86/kernel/cpu/microcode/amd.c +7 -16
index 6b3929e80fd4..8cb20e3e9436 100644
@@ -39,15 +39,6 @@
 
 static struct equiv_cpu_entry *equiv_cpu_table;
 
-struct ucode_patch {
-	struct list_head plist;
-	void *data;
-	u32 patch_id;
-	u16 equiv_cpu;
-};
-
-static LIST_HEAD(pcache);
-
 /*
  * This points to the current valid container of microcode patches which we will
  * save from the initrd before jettisoning its contents.
@@ -312,9 +303,9 @@ void __init load_ucode_amd_bsp(unsigned int family)
 #ifdef CONFIG_X86_32
 /*
  * On 32-bit, since AP's early load occurs before paging is turned on, we
- * cannot traverse cpu_equiv_table and pcache in kernel heap memory. So during
- * cold boot, AP will apply_ucode_in_initrd() just like the BSP. During
- * save_microcode_in_initrd_amd() BSP's patch is copied to amd_ucode_patch,
+ * cannot traverse cpu_equiv_table and microcode_cache in kernel heap memory.
+ * So during cold boot, AP will apply_ucode_in_initrd() just like the BSP.
+ * In save_microcode_in_initrd_amd() BSP's patch is copied to amd_ucode_patch,
  * which is used upon resume from suspend.
  */
 void load_ucode_amd_ap(void)
@@ -508,7 +499,7 @@ static struct ucode_patch *cache_find_patch(u16 equiv_cpu)
 {
 	struct ucode_patch *p;
 
-	list_for_each_entry(p, &pcache, plist)
+	list_for_each_entry(p, &microcode_cache, plist)
 		if (p->equiv_cpu == equiv_cpu)
 			return p;
 	return NULL;
@@ -518,7 +509,7 @@ static void update_cache(struct ucode_patch *new_patch)
 {
 	struct ucode_patch *p;
 
-	list_for_each_entry(p, &pcache, plist) {
+	list_for_each_entry(p, &microcode_cache, plist) {
 		if (p->equiv_cpu == new_patch->equiv_cpu) {
 			if (p->patch_id >= new_patch->patch_id)
 				/* we already have the latest patch */
@@ -531,14 +522,14 @@ static void update_cache(struct ucode_patch *new_patch)
 		}
 	}
 	/* no patch found, add it */
-	list_add_tail(&new_patch->plist, &pcache);
+	list_add_tail(&new_patch->plist, &microcode_cache);
 }
 
 static void free_cache(void)
 {
 	struct ucode_patch *p, *tmp;
 
-	list_for_each_entry_safe(p, tmp, &pcache, plist) {
+	list_for_each_entry_safe(p, tmp, &microcode_cache, plist) {
 		__list_del(p->plist.prev, p->plist.next);
 		kfree(p->data);
 		kfree(p);
arch/x86/kernel/cpu/microcode/core.c +2 -0
index d0d1a0f5a497..55a2b24b2bdd 100644
@@ -45,6 +45,8 @@
 static struct microcode_ops	*microcode_ops;
 static bool dis_ucode_ldr;
 
+LIST_HEAD(microcode_cache);
+
 /*
  * Synchronization.
  *
Signature · 1 line
2.10.0
#10 lore raw

[tip:x86/microcode] x86/microcode: Export the microcode cache linked list

x86/microcode: Export the microcode cache linked list
Commit-ID:  058dc49803171f37b25f053182835f2969d1c43f
Gitweb:     http://git.kernel.org/tip/058dc49803171f37b25f053182835f2969d1c43f
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:15 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:58 +0200

x86/microcode: Export the microcode cache linked list

It will be used by both drivers so move it to core.c.

No functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/include/asm/microcode.h     |  9 +++++++++
 arch/x86/kernel/cpu/microcode/amd.c  | 23 +++++++----------------
 arch/x86/kernel/cpu/microcode/core.c |  2 ++
 3 files changed, 18 insertions(+), 16 deletions(-)
arch/x86/include/asm/microcode.h +9 -0
index 05e56d0..91595ec 100644
@@ -20,6 +20,15 @@ do {							\
 			 (u32)((u64)(val)),		\
 			 (u32)((u64)(val) >> 32))
 
+struct ucode_patch {
+	struct list_head plist;
+	void *data;		/* Intel uses only this one */
+	u32 patch_id;
+	u16 equiv_cpu;
+};
+
+extern struct list_head microcode_cache;
+
 struct cpu_signature {
 	unsigned int sig;
 	unsigned int pf;
arch/x86/kernel/cpu/microcode/amd.c +7 -16
index 6b3929e..8cb20e3 100644
@@ -39,15 +39,6 @@
 
 static struct equiv_cpu_entry *equiv_cpu_table;
 
-struct ucode_patch {
-	struct list_head plist;
-	void *data;
-	u32 patch_id;
-	u16 equiv_cpu;
-};
-
-static LIST_HEAD(pcache);
-
 /*
  * This points to the current valid container of microcode patches which we will
  * save from the initrd before jettisoning its contents.
@@ -312,9 +303,9 @@ void __init load_ucode_amd_bsp(unsigned int family)
 #ifdef CONFIG_X86_32
 /*
  * On 32-bit, since AP's early load occurs before paging is turned on, we
- * cannot traverse cpu_equiv_table and pcache in kernel heap memory. So during
- * cold boot, AP will apply_ucode_in_initrd() just like the BSP. During
- * save_microcode_in_initrd_amd() BSP's patch is copied to amd_ucode_patch,
+ * cannot traverse cpu_equiv_table and microcode_cache in kernel heap memory.
+ * So during cold boot, AP will apply_ucode_in_initrd() just like the BSP.
+ * In save_microcode_in_initrd_amd() BSP's patch is copied to amd_ucode_patch,
  * which is used upon resume from suspend.
  */
 void load_ucode_amd_ap(void)
@@ -508,7 +499,7 @@ static struct ucode_patch *cache_find_patch(u16 equiv_cpu)
 {
 	struct ucode_patch *p;
 
-	list_for_each_entry(p, &pcache, plist)
+	list_for_each_entry(p, &microcode_cache, plist)
 		if (p->equiv_cpu == equiv_cpu)
 			return p;
 	return NULL;
@@ -518,7 +509,7 @@ static void update_cache(struct ucode_patch *new_patch)
 {
 	struct ucode_patch *p;
 
-	list_for_each_entry(p, &pcache, plist) {
+	list_for_each_entry(p, &microcode_cache, plist) {
 		if (p->equiv_cpu == new_patch->equiv_cpu) {
 			if (p->patch_id >= new_patch->patch_id)
 				/* we already have the latest patch */
@@ -531,14 +522,14 @@ static void update_cache(struct ucode_patch *new_patch)
 		}
 	}
 	/* no patch found, add it */
-	list_add_tail(&new_patch->plist, &pcache);
+	list_add_tail(&new_patch->plist, &microcode_cache);
 }
 
 static void free_cache(void)
 {
 	struct ucode_patch *p, *tmp;
 
-	list_for_each_entry_safe(p, tmp, &pcache, plist) {
+	list_for_each_entry_safe(p, tmp, &microcode_cache, plist) {
 		__list_del(p->plist.prev, p->plist.next);
 		kfree(p->data);
 		kfree(p);
arch/x86/kernel/cpu/microcode/core.c +2 -0
index d0d1a0f..55a2b24 100644
@@ -45,6 +45,8 @@
 static struct microcode_ops	*microcode_ops;
 static bool dis_ucode_ldr;
 
+LIST_HEAD(microcode_cache);
+
 /*
  * Synchronization.
  *
author maintainer
#11 lore raw

PATCH 6/12 x86/microcode/AMD: Hand down the CPU family

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Will be needed in a following patch.

No functionality change.

---
 arch/x86/include/asm/microcode_amd.h | 9 +++++----
 arch/x86/kernel/cpu/microcode/amd.c  | 6 +++---
 arch/x86/kernel/cpu/microcode/core.c | 4 ++--
 3 files changed, 10 insertions(+), 9 deletions(-)
arch/x86/include/asm/microcode_amd.h +5 -4
index 15eb75484cc0..ad6a7be3b1f8 100644
@@ -65,13 +65,14 @@ extern enum ucode_state load_microcode_amd(int cpu, u8 family, const u8 *data, s
 
 #ifdef CONFIG_MICROCODE_AMD
 extern void __init load_ucode_amd_bsp(unsigned int family);
-extern void load_ucode_amd_ap(void);
-extern int __init save_microcode_in_initrd_amd(void);
+extern void load_ucode_amd_ap(unsigned int family);
+extern int __init save_microcode_in_initrd_amd(unsigned int family);
 void reload_ucode_amd(void);
 #else
 static inline void __init load_ucode_amd_bsp(unsigned int family) {}
-static inline void load_ucode_amd_ap(void) {}
-static inline int __init save_microcode_in_initrd_amd(void) { return -EINVAL; }
+static inline void load_ucode_amd_ap(unsigned int family) {}
+static inline int __init
+save_microcode_in_initrd_amd(unsigned int family) { return -EINVAL; }
 void reload_ucode_amd(void) {}
 #endif
 
arch/x86/kernel/cpu/microcode/amd.c +3 -3
index 8cb20e3e9436..bb16418ecaa9 100644
@@ -308,7 +308,7 @@ void __init load_ucode_amd_bsp(unsigned int family)
  * In save_microcode_in_initrd_amd() BSP's patch is copied to amd_ucode_patch,
  * which is used upon resume from suspend.
  */
-void load_ucode_amd_ap(void)
+void load_ucode_amd_ap(unsigned int family)
 {
 	struct microcode_amd *mc;
 	size_t *usize;
@@ -346,7 +346,7 @@ static void __init get_bsp_sig(void)
 		smp_call_function_single(bsp, collect_cpu_sig_on_bsp, NULL, 1);
 }
 #else
-void load_ucode_amd_ap(void)
+void load_ucode_amd_ap(unsigned int family)
 {
 	struct equiv_cpu_entry *eq;
 	struct microcode_amd *mc;
@@ -395,7 +395,7 @@ void load_ucode_amd_ap(void)
 }
 #endif
 
-int __init save_microcode_in_initrd_amd(void)
+int __init save_microcode_in_initrd_amd(unsigned int family)
 {
 	unsigned long cont;
 	int retval = 0;
arch/x86/kernel/cpu/microcode/core.c +2 -2
index 55a2b24b2bdd..b67145dcfdaf 100644
@@ -169,7 +169,7 @@ void load_ucode_ap(void)
 		break;
 	case X86_VENDOR_AMD:
 		if (family >= 0x10)
-			load_ucode_amd_ap();
+			load_ucode_amd_ap(family);
 		break;
 	default:
 		break;
@@ -187,7 +187,7 @@ static int __init save_microcode_in_initrd(void)
 		break;
 	case X86_VENDOR_AMD:
 		if (c->x86 >= 0x10)
-			return save_microcode_in_initrd_amd();
+			return save_microcode_in_initrd_amd(c->x86);
 		break;
 	default:
 		break;
Signature · 1 line
2.10.0
#12 lore raw

[tip:x86/microcode] x86/microcode/amd: Hand down the CPU family

x86/microcode/amd: Hand down the CPU family
Commit-ID:  b3763a672dc0cdaf494a28ec4c2b4e5e0e93334e
Gitweb:     http://git.kernel.org/tip/b3763a672dc0cdaf494a28ec4c2b4e5e0e93334e
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:16 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:58 +0200

x86/microcode/amd: Hand down the CPU family

Will be needed in a following patch.

No functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/include/asm/microcode_amd.h | 9 +++++----
 arch/x86/kernel/cpu/microcode/amd.c  | 6 +++---
 arch/x86/kernel/cpu/microcode/core.c | 4 ++--
 3 files changed, 10 insertions(+), 9 deletions(-)
arch/x86/include/asm/microcode_amd.h +5 -4
index 15eb754..ad6a7be 100644
@@ -65,13 +65,14 @@ extern enum ucode_state load_microcode_amd(int cpu, u8 family, const u8 *data, s
 
 #ifdef CONFIG_MICROCODE_AMD
 extern void __init load_ucode_amd_bsp(unsigned int family);
-extern void load_ucode_amd_ap(void);
-extern int __init save_microcode_in_initrd_amd(void);
+extern void load_ucode_amd_ap(unsigned int family);
+extern int __init save_microcode_in_initrd_amd(unsigned int family);
 void reload_ucode_amd(void);
 #else
 static inline void __init load_ucode_amd_bsp(unsigned int family) {}
-static inline void load_ucode_amd_ap(void) {}
-static inline int __init save_microcode_in_initrd_amd(void) { return -EINVAL; }
+static inline void load_ucode_amd_ap(unsigned int family) {}
+static inline int __init
+save_microcode_in_initrd_amd(unsigned int family) { return -EINVAL; }
 void reload_ucode_amd(void) {}
 #endif
 
arch/x86/kernel/cpu/microcode/amd.c +3 -3
index 8cb20e3..bb16418 100644
@@ -308,7 +308,7 @@ void __init load_ucode_amd_bsp(unsigned int family)
  * In save_microcode_in_initrd_amd() BSP's patch is copied to amd_ucode_patch,
  * which is used upon resume from suspend.
  */
-void load_ucode_amd_ap(void)
+void load_ucode_amd_ap(unsigned int family)
 {
 	struct microcode_amd *mc;
 	size_t *usize;
@@ -346,7 +346,7 @@ static void __init get_bsp_sig(void)
 		smp_call_function_single(bsp, collect_cpu_sig_on_bsp, NULL, 1);
 }
 #else
-void load_ucode_amd_ap(void)
+void load_ucode_amd_ap(unsigned int family)
 {
 	struct equiv_cpu_entry *eq;
 	struct microcode_amd *mc;
@@ -395,7 +395,7 @@ void load_ucode_amd_ap(void)
 }
 #endif
 
-int __init save_microcode_in_initrd_amd(void)
+int __init save_microcode_in_initrd_amd(unsigned int family)
 {
 	unsigned long cont;
 	int retval = 0;
arch/x86/kernel/cpu/microcode/core.c +2 -2
index 55a2b24..b67145d 100644
@@ -169,7 +169,7 @@ void load_ucode_ap(void)
 		break;
 	case X86_VENDOR_AMD:
 		if (family >= 0x10)
-			load_ucode_amd_ap();
+			load_ucode_amd_ap(family);
 		break;
 	default:
 		break;
@@ -187,7 +187,7 @@ static int __init save_microcode_in_initrd(void)
 		break;
 	case X86_VENDOR_AMD:
 		if (c->x86 >= 0x10)
-			return save_microcode_in_initrd_amd();
+			return save_microcode_in_initrd_amd(c->x86);
 		break;
 	default:
 		break;
author maintainer
#13 lore raw

PATCH 7/12 x86/microcode: Issue the debug printk on resume only on success

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Move it after the patch application function which also checks whether we were successful.

---
 arch/x86/kernel/cpu/microcode/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +2 -2
index b67145dcfdaf..a18ff7547fa9 100644
@@ -460,11 +460,11 @@ static void microcode_fini_cpu(int cpu)
 
 static enum ucode_state microcode_resume_cpu(int cpu)
 {
-	pr_debug("CPU%d updated upon resume\n", cpu);
-
 	if (apply_microcode_on_target(cpu))
 		return UCODE_ERROR;
 
+	pr_debug("CPU%d updated upon resume\n", cpu);
+
 	return UCODE_OK;
 }
 
Signature · 1 line
2.10.0
#14 lore raw

[tip:x86/microcode] x86/microcode: Issue the debug printk on resume only on success

x86/microcode: Issue the debug printk on resume only on success
Commit-ID:  6b14b81899a2e1e5dd0d089f2a41a6118929658d
Gitweb:     http://git.kernel.org/tip/6b14b81899a2e1e5dd0d089f2a41a6118929658d
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:17 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:58 +0200

x86/microcode: Issue the debug printk on resume only on success

Move it after the patch application function which also checks whether we were successful.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/cpu/microcode/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +2 -2
index b67145d..a18ff75 100644
@@ -460,11 +460,11 @@ static void microcode_fini_cpu(int cpu)
 
 static enum ucode_state microcode_resume_cpu(int cpu)
 {
-	pr_debug("CPU%d updated upon resume\n", cpu);
-
 	if (apply_microcode_on_target(cpu))
 		return UCODE_ERROR;
 
+	pr_debug("CPU%d updated upon resume\n", cpu);
+
 	return UCODE_OK;
 }
 
author maintainer
#15 lore raw

PATCH 8/12 x86/microcode: Collect CPU info on resume

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

We need to reread the CPU's microcode revision after resume because applied microcode gets "forgotten" depending on the sleep state.

---
 arch/x86/kernel/cpu/microcode/core.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/cpu/microcode/core.c +3 -0
index a18ff7547fa9..f737039d59b2 100644
@@ -498,6 +498,9 @@ static enum ucode_state microcode_update_cpu(int cpu)
 {
 	struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
 
+	/* Refresh CPU microcode revision after resume. */
+	collect_cpu_info(cpu);
+
 	if (uci->valid)
 		return microcode_resume_cpu(cpu);
 
Signature · 1 line
2.10.0
#16 lore raw

[tip:x86/microcode] x86/microcode: Collect CPU info on resume

x86/microcode: Collect CPU info on resume
Commit-ID:  7f709d0c322203e37581f6b7c91f88b4fdeca5a0
Gitweb:     http://git.kernel.org/tip/7f709d0c322203e37581f6b7c91f88b4fdeca5a0
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:18 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:58 +0200

x86/microcode: Collect CPU info on resume

We need to reread the CPU's microcode revision after resume because applied microcode gets "forgotten" depending on the sleep state.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/cpu/microcode/core.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/cpu/microcode/core.c +3 -0
index a18ff75..f737039 100644
@@ -498,6 +498,9 @@ static enum ucode_state microcode_update_cpu(int cpu)
 {
 	struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
 
+	/* Refresh CPU microcode revision after resume. */
+	collect_cpu_info(cpu);
+
 	if (uci->valid)
 		return microcode_resume_cpu(cpu);
 
author maintainer
#17 lore raw

PATCH 9/12 x86/microcode/AMD: Retract functions

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Make them all static as they're used in a single file now.

No functionality change.

---
 arch/x86/include/asm/microcode_amd.h | 21 --------------
 arch/x86/kernel/cpu/microcode/amd.c  | 53 +++++++++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 37 deletions(-)
arch/x86/include/asm/microcode_amd.h +0 -21
index ad6a7be3b1f8..3e3e20be829a 100644
@@ -40,27 +40,6 @@ struct microcode_amd {
 	unsigned int			mpb[0];
 };
 
-static inline u16 find_equiv_id(struct equiv_cpu_entry *equiv_cpu_table,
-				unsigned int sig)
-{
-	int i = 0;
-
-	if (!equiv_cpu_table)
-		return 0;
-
-	while (equiv_cpu_table[i].installed_cpu != 0) {
-		if (sig == equiv_cpu_table[i].installed_cpu)
-			return equiv_cpu_table[i].equiv_cpu;
-
-		i++;
-	}
-	return 0;
-}
-
-extern int __apply_microcode_amd(struct microcode_amd *mc_amd);
-extern int apply_microcode_amd(int cpu);
-extern enum ucode_state load_microcode_amd(int cpu, u8 family, const u8 *data, size_t size);
-
 #define PATCH_MAX_SIZE PAGE_SIZE
 
 #ifdef CONFIG_MICROCODE_AMD
arch/x86/kernel/cpu/microcode/amd.c +37 -16

77 lines not on this page · raw message

Signature · 1 line
2.10.0
#18 lore raw

[tip:x86/microcode] x86/microcode/amd: Move private inlines to .c and mark local functions static

x86/microcode/amd: Move private inlines to .c and mark local functions static
Commit-ID:  76bd11c23aaa5c4bed504bfc4cf690240759598d
Gitweb:     http://git.kernel.org/tip/76bd11c23aaa5c4bed504bfc4cf690240759598d
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:19 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:59 +0200

x86/microcode/amd: Move private inlines to .c and mark local functions static

Make them all static as they're used in a single file now.

No functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/include/asm/microcode_amd.h | 21 --------------
 arch/x86/kernel/cpu/microcode/amd.c  | 53 +++++++++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 37 deletions(-)
arch/x86/include/asm/microcode_amd.h +0 -21
index ad6a7be..3e3e20b 100644
@@ -40,27 +40,6 @@ struct microcode_amd {
 	unsigned int			mpb[0];
 };
 
-static inline u16 find_equiv_id(struct equiv_cpu_entry *equiv_cpu_table,
-				unsigned int sig)
-{
-	int i = 0;
-
-	if (!equiv_cpu_table)
-		return 0;
-
-	while (equiv_cpu_table[i].installed_cpu != 0) {
-		if (sig == equiv_cpu_table[i].installed_cpu)
-			return equiv_cpu_table[i].equiv_cpu;
-
-		i++;
-	}
-	return 0;
-}
-
-extern int __apply_microcode_amd(struct microcode_amd *mc_amd);
-extern int apply_microcode_amd(int cpu);
-extern enum ucode_state load_microcode_amd(int cpu, u8 family, const u8 *data, size_t size);
-
 #define PATCH_MAX_SIZE PAGE_SIZE
 
 #ifdef CONFIG_MICROCODE_AMD
arch/x86/kernel/cpu/microcode/amd.c +37 -16

77 lines not on this page · raw message

author maintainer
#19 lore raw

PATCH 10/12 x86/microcode/intel: Remove intel_lib.c

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Its functions are used in intel.c only now, so get rid of it. Make functions static.

No functionality change.

---
 arch/x86/include/asm/microcode_intel.h    |   4 -
 arch/x86/kernel/cpu/microcode/Makefile    |   2 +-
 arch/x86/kernel/cpu/microcode/intel.c     | 154 ++++++++++++++++++++++++-
 arch/x86/kernel/cpu/microcode/intel_lib.c | 184 ------------------------------
 4 files changed, 154 insertions(+), 190 deletions(-)
 delete mode 100644 arch/x86/kernel/cpu/microcode/intel_lib.c
arch/x86/include/asm/microcode_intel.h +0 -4
index 5e69154c9f07..195becc6f780 100644
@@ -52,10 +52,6 @@ struct extended_sigtable {
 
 #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)
 
-extern int has_newer_microcode(void *mc, unsigned int csig, int cpf, int rev);
-extern int microcode_sanity_check(void *mc, int print_err);
-extern int find_matching_signature(void *mc, unsigned int csig, int cpf);
-
 #ifdef CONFIG_MICROCODE_INTEL
 extern void __init load_ucode_intel_bsp(void);
 extern void load_ucode_intel_ap(void);
arch/x86/kernel/cpu/microcode/Makefile +1 -1
index 220b1a508513..ba12e8aa4a45 100644
@@ -1,4 +1,4 @@
 microcode-y				:= core.o
 obj-$(CONFIG_MICROCODE)			+= microcode.o
-microcode-$(CONFIG_MICROCODE_INTEL)	+= intel.o intel_lib.o
+microcode-$(CONFIG_MICROCODE_INTEL)	+= intel.o
 microcode-$(CONFIG_MICROCODE_AMD)	+= amd.o
arch/x86/kernel/cpu/microcode/intel.c +153 -1

169 lines not on this page · raw message

arch/x86/kernel/cpu/microcode/intel_lib.c deleted +0 -184

184 lines not on this page · raw message

Signature · 1 line
2.10.0
#20 lore raw

[tip:x86/microcode] x86/microcode/intel: Remove intel_lib.c

x86/microcode/intel: Remove intel_lib.c
Commit-ID:  8027923ab4df9b2bdb9d642b7dceeb135c032f5e
Gitweb:     http://git.kernel.org/tip/8027923ab4df9b2bdb9d642b7dceeb135c032f5e
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:20 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:59 +0200

x86/microcode/intel: Remove intel_lib.c

Its functions are used in intel.c only now, so get rid of it. Make functions static.

No functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/include/asm/microcode_intel.h    |   4 -
 arch/x86/kernel/cpu/microcode/Makefile    |   2 +-
 arch/x86/kernel/cpu/microcode/intel.c     | 154 ++++++++++++++++++++++++-
 arch/x86/kernel/cpu/microcode/intel_lib.c | 184 ------------------------------
 4 files changed, 154 insertions(+), 190 deletions(-)
arch/x86/include/asm/microcode_intel.h +0 -4
index 5e69154..195becc 100644
@@ -52,10 +52,6 @@ struct extended_sigtable {
 
 #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)
 
-extern int has_newer_microcode(void *mc, unsigned int csig, int cpf, int rev);
-extern int microcode_sanity_check(void *mc, int print_err);
-extern int find_matching_signature(void *mc, unsigned int csig, int cpf);
-
 #ifdef CONFIG_MICROCODE_INTEL
 extern void __init load_ucode_intel_bsp(void);
 extern void load_ucode_intel_ap(void);
arch/x86/kernel/cpu/microcode/Makefile +1 -1
index 220b1a5..ba12e8a 100644
@@ -1,4 +1,4 @@
 microcode-y				:= core.o
 obj-$(CONFIG_MICROCODE)			+= microcode.o
-microcode-$(CONFIG_MICROCODE_INTEL)	+= intel.o intel_lib.o
+microcode-$(CONFIG_MICROCODE_INTEL)	+= intel.o
 microcode-$(CONFIG_MICROCODE_AMD)	+= amd.o
arch/x86/kernel/cpu/microcode/intel.c +153 -1

169 lines not on this page · raw message

arch/x86/kernel/cpu/microcode/intel_lib.c deleted +0 -184

184 lines not on this page · raw message

author maintainer
#21 lore raw

PATCH 11/12 x86/microcode: Rework microcode loading

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Yeah, I know, I know, this is a huuge patch and reviewing it is hard.

Sorry but this is the only way I could think of in which I can rewrite the microcode patches loading procedure without breaking (knowingly) the driver.

So maybe this patch is easier to review if one looks at the files after the patch has been applied instead at the diff. Because then it becomes pretty obvious:

* The BSP-loading path - load_ucode_bsp() is working independently from the AP path now and it doesn't save any pointers or patches anymore - it solely parses the builtin or initrd microcode and applies the patch. That's it.

This fixes the CONFIG_RANDOMIZE_MEMORY offset fun more solidly.

* The AP-loading path - load_ucode_ap() then goes and scans builtin/initrd *again* for the microcode patches but it caches them this time so that we don't have to do that scan on each AP but only once.

This simplifies the code considerably.

Then, when we save the microcode from the initrd/builtin, we go and add the relevant patches to our own cache. The AMD side did do that and now the Intel side does it too. So no more pointer copying and blabla, we save the microcode patches ourselves and are independent from initrd/builtin.

This whole conversion gives us other benefits like unifying the initrd parsing into a single function: find_microcode_in_initrd() is used by both.

The diffstat speaks for itself: 456 insertions(+), 695 deletions(-)

---
 arch/x86/include/asm/microcode.h      |   1 +
 arch/x86/kernel/cpu/microcode/amd.c   | 365 +++++++++--------
 arch/x86/kernel/cpu/microcode/core.c  |  63 ++-
 arch/x86/kernel/cpu/microcode/intel.c | 714 ++++++++++------------------------
 4 files changed, 446 insertions(+), 697 deletions(-)
arch/x86/include/asm/microcode.h +1 -0
index 91595ecb3689..38711df3bcb5 100644
@@ -64,6 +64,7 @@ struct ucode_cpu_info {
 	void			*mc;
 };
 extern struct ucode_cpu_info ucode_cpu_info[];
+struct cpio_data find_microcode_in_initrd(const char *path, bool use_pa);
 
 #ifdef CONFIG_MICROCODE_INTEL
 extern struct microcode_ops * __init init_intel_microcode(void);
arch/x86/kernel/cpu/microcode/amd.c +174 -191

524 lines not on this page · raw message

arch/x86/kernel/cpu/microcode/core.c +56 -7

87 lines not on this page · raw message

arch/x86/kernel/cpu/microcode/intel.c +215 -499

969 lines not on this page · raw message

Signature · 1 line
2.10.0
#22 lore raw
x86/microcode: Rework microcode loading
Commit-ID:  06b8534cb72837379b3a4781ab252df3d37c2669
Gitweb:     http://git.kernel.org/tip/06b8534cb72837379b3a4781ab252df3d37c2669
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:21 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:59 +0200

x86/microcode: Rework microcode loading

Yeah, I know, I know, this is a huuge patch and reviewing it is hard.

Sorry but this is the only way I could think of in which I can rewrite the microcode patches loading procedure without breaking (knowingly) the driver.

So maybe this patch is easier to review if one looks at the files after the patch has been applied instead at the diff. Because then it becomes pretty obvious:

* The BSP-loading path - load_ucode_bsp() is working independently from the AP path now and it doesn't save any pointers or patches anymore - it solely parses the builtin or initrd microcode and applies the patch. That's it.

This fixes the CONFIG_RANDOMIZE_MEMORY offset fun more solidly.

* The AP-loading path - load_ucode_ap() then goes and scans builtin/initrd *again* for the microcode patches but it caches them this time so that we don't have to do that scan on each AP but only once.

This simplifies the code considerably.

Then, when we save the microcode from the initrd/builtin, we go and add the relevant patches to our own cache. The AMD side did do that and now the Intel side does it too. So no more pointer copying and blabla, we save the microcode patches ourselves and are independent from initrd/builtin.

This whole conversion gives us other benefits like unifying the initrd parsing into a single function: find_microcode_in_initrd() is used by both.

The diffstat speaks for itself: 456 insertions(+), 695 deletions(-)

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/include/asm/microcode.h      |   1 +
 arch/x86/kernel/cpu/microcode/amd.c   | 365 +++++++++--------
 arch/x86/kernel/cpu/microcode/core.c  |  63 ++-
 arch/x86/kernel/cpu/microcode/intel.c | 714 ++++++++++------------------------
 4 files changed, 446 insertions(+), 697 deletions(-)
arch/x86/include/asm/microcode.h +1 -0
index 91595ec..38711df 100644
@@ -64,6 +64,7 @@ struct ucode_cpu_info {
 	void			*mc;
 };
 extern struct ucode_cpu_info ucode_cpu_info[];
+struct cpio_data find_microcode_in_initrd(const char *path, bool use_pa);
 
 #ifdef CONFIG_MICROCODE_INTEL
 extern struct microcode_ops * __init init_intel_microcode(void);
arch/x86/kernel/cpu/microcode/amd.c +174 -191

524 lines not on this page · raw message

arch/x86/kernel/cpu/microcode/core.c +56 -7

87 lines not on this page · raw message

arch/x86/kernel/cpu/microcode/intel.c +215 -499

969 lines not on this page · raw message

author maintainer
#23 lore raw

PATCH 12/12 x86/microcode: Bump driver version, update copyrights

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Let's increment that number finally: it is long overdue.

---
 arch/x86/kernel/cpu/microcode/amd.c  | 1 +
 arch/x86/kernel/cpu/microcode/core.c | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -0
index 0dd8db1213d3..6f353bdb3a25 100644
@@ -5,6 +5,7 @@
  *  CPUs and later.
  *
  *  Copyright (C) 2008-2011 Advanced Micro Devices Inc.
+ *	          2013-2016 Borislav Petkov <[email protected]>
  *
  *  Author: Peter Oruba <[email protected]>
  *
arch/x86/kernel/cpu/microcode/core.c +3 -3
index dd3d64f07364..6996413c78c3 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2000-2006 Tigran Aivazian <[email protected]>
  *	      2006	Shaohua Li <[email protected]>
- *	      2013-2015	Borislav Petkov <[email protected]>
+ *	      2013-2016	Borislav Petkov <[email protected]>
  *
  * X86 CPU microcode early update for Linux:
  *
@@ -41,7 +41,7 @@
 #include <asm/cmdline.h>
 #include <asm/setup.h>
 
-#define MICROCODE_VERSION	"2.01"
+#define DRIVER_VERSION	"2.2"
 
 static struct microcode_ops	*microcode_ops;
 static bool dis_ucode_ldr;
@@ -703,7 +703,7 @@ int __init microcode_init(void)
 	cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/microcode:online",
 				  mc_cpu_online, mc_cpu_down_prep);
 
-	pr_info("Microcode Update Driver: v%s.", MICROCODE_VERSION);
+	pr_info("Microcode Update Driver: v%s.", DRIVER_VERSION);
 
 	return 0;
 
Signature · 1 line
2.10.0
#24 lore raw

[tip:x86/microcode] x86/microcode: Bump driver version, update copyrights

x86/microcode: Bump driver version, update copyrights
Commit-ID:  14cfbe55c75ada9abd2d9cad97dafb4206c5f9e2
Gitweb:     http://git.kernel.org/tip/14cfbe55c75ada9abd2d9cad97dafb4206c5f9e2
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 25 Oct 2016 11:55:22 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 25 Oct 2016 12:28:59 +0200

x86/microcode: Bump driver version, update copyrights

Let's increment that number finally: it is long overdue.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/cpu/microcode/amd.c  | 1 +
 arch/x86/kernel/cpu/microcode/core.c | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -0
index 0dd8db1..6f353bd 100644
@@ -5,6 +5,7 @@
  *  CPUs and later.
  *
  *  Copyright (C) 2008-2011 Advanced Micro Devices Inc.
+ *	          2013-2016 Borislav Petkov <[email protected]>
  *
  *  Author: Peter Oruba <[email protected]>
  *
arch/x86/kernel/cpu/microcode/core.c +3 -3
index dd3d64f..6996413 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2000-2006 Tigran Aivazian <[email protected]>
  *	      2006	Shaohua Li <[email protected]>
- *	      2013-2015	Borislav Petkov <[email protected]>
+ *	      2013-2016	Borislav Petkov <[email protected]>
  *
  * X86 CPU microcode early update for Linux:
  *
@@ -41,7 +41,7 @@
 #include <asm/cmdline.h>
 #include <asm/setup.h>
 
-#define MICROCODE_VERSION	"2.01"
+#define DRIVER_VERSION	"2.2"
 
 static struct microcode_ops	*microcode_ops;
 static bool dis_ucode_ldr;
@@ -703,7 +703,7 @@ int __init microcode_init(void)
 	cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/microcode:online",
 				  mc_cpu_online, mc_cpu_down_prep);
 
-	pr_info("Microcode Update Driver: v%s.", MICROCODE_VERSION);
+	pr_info("Microcode Update Driver: v%s.", DRIVER_VERSION);
 
 	return 0;