Skip to contentSkip to conversation

tip, x86-microcode: simplify 'struct ucode_cpu_info' and related functional logic

PATCH In review dimm 1 participant 1 message Nov 25, 2009 x86

lore
Share & tools
lore

dimm

author
#0 lore raw

PATCH 1/2 tip, x86-microcode: simplify 'struct ucode_cpu_info' and related functional logic

From: Dmitry Adamushko <[email protected]>
Subject: x86-microcode: drop "cpu_sig" caching

Simplify 'struct ucode_cpu_info' and related functional logic. Always retrieve the current "cpu_sig" when required. This way we don't need to maintain corner cases which may lead to having non up-to-date versions of "cpu_sig".

 arch/x86/include/asm/microcode.h  |    2 -
 arch/x86/kernel/microcode_amd.c   |   15 +++++----
 arch/x86/kernel/microcode_core.c  |   61 +++++++++++-------------------------
 arch/x86/kernel/microcode_intel.c |   15 +++++----
 4 files changed, 37 insertions(+), 56 deletions(-)
CC Ingo Molnar <[email protected]>
CC Andreas Mohr <[email protected]>

---

arch/x86/include/asm/microcode.h +0 -2
index c24ca9a..0be7c00 100644
@@ -33,8 +33,6 @@ struct microcode_ops {
 };
 
 struct ucode_cpu_info {
-	struct cpu_signature	cpu_sig;
-	int			valid;
 	void			*mc;
 };
 extern struct ucode_cpu_info ucode_cpu_info[];
arch/x86/kernel/microcode_amd.c +9 -6
index 63123d9..7d006e4 100644
@@ -147,7 +147,6 @@ static int apply_microcode_amd(int cpu)
 	}
 
 	pr_info("microcode: CPU%d: updated (new patch_level=0x%x)\n", cpu, rev);
-	uci->cpu_sig.rev = rev;
 
 	return 0;
 }
@@ -236,14 +235,18 @@ static enum ucode_state
 generic_load_microcode(int cpu, const u8 *data, size_t size)
 {
 	struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+	struct cpu_signature cpu_sig;
 	const u8 *ucode_ptr = data;
-	void *new_mc = NULL;
-	void *mc;
-	int new_rev = uci->cpu_sig.rev;
-	unsigned int leftover;
+	void *new_mc = NULL, *mc;
+	unsigned int leftover, new_rev;
 	unsigned long offset;
 	enum ucode_state state = UCODE_OK;
 
+	if (collect_cpu_info_amd(cpu, &cpu_sig))
+		return UCODE_ERROR;
+
+	new_rev = cpu_sig.rev;
+
 	offset = install_equiv_cpu_table(ucode_ptr);
 	if (!offset) {
 		pr_err("microcode: failed to create equivalent cpu table\n");
@@ -279,7 +282,7 @@ generic_load_microcode(int cpu, const u8 *data, size_t size)
 			uci->mc = new_mc;
 			pr_debug("microcode: CPU%d found a matching microcode "
 				 "update with version 0x%x (current=0x%x)\n",
-				 cpu, new_rev, uci->cpu_sig.rev);
+				 cpu, new_rev, cpu_sig.rev);
 		} else {
 			vfree(new_mc);
 			state = UCODE_ERROR;
arch/x86/kernel/microcode_core.c +19 -42

125 lines not on this page · raw message

arch/x86/kernel/microcode_intel.c +9 -6
index 0d334dd..6589765 100644
@@ -339,8 +339,6 @@ static int apply_microcode(int cpu)
 		mc_intel->hdr.date >> 24,
 		(mc_intel->hdr.date >> 16) & 0xff);
 
-	uci->cpu_sig.rev = val[1];
-
 	return 0;
 }
 
@@ -348,11 +346,16 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 				int (*get_ucode_data)(void *, const void *, size_t))
 {
 	struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+	struct cpu_signature cpu_sig;
 	u8 *ucode_ptr = data, *new_mc = NULL, *mc;
-	int new_rev = uci->cpu_sig.rev;
-	unsigned int leftover = size;
+	unsigned int leftover = size, new_rev;
 	enum ucode_state state = UCODE_OK;
 
+	if (collect_cpu_info(cpu, &cpu_sig))
+		return UCODE_ERROR;
+
+	new_rev = cpu_sig.rev;
+
 	while (leftover) {
 		struct microcode_header_intel mc_header;
 		unsigned int mc_size;
@@ -377,7 +380,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 			break;
 		}
 
-		if (get_matching_microcode(&uci->cpu_sig, mc, new_rev)) {
+		if (get_matching_microcode(&cpu_sig, mc, new_rev)) {
 			if (new_mc)
 				vfree(new_mc);
 			new_rev = mc_header.rev;
@@ -407,7 +410,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
 
 	pr_debug("microcode: CPU%d found a matching microcode update with"
 		 " version 0x%x (current=0x%x)\n",
-			cpu, new_rev, uci->cpu_sig.rev);
+			cpu, new_rev, cpu_sig.rev);
 out:
 	return state;
 }