Skip to contentSkip to conversation

x86, AMD: saved applied, not loaded microcode for reloading on resume

PATCH In review Torsten Kaiser 1 participant 1 message Jul 23, 2013 x86

lore
Share & tools
lore
#0 lore raw

PATCH 4/5 x86, AMD: saved applied, not loaded microcode for reloading on resume

* Save the amd_bsp_mpb on apply, not on load. Otherwise someone could later load an older microcode file via load_microcode_amd() that would overwrite amd_bsp_mpb, but would not be applied to the CPUs
(apply_microcode_amd() checks the current patchlevel, but the copy code in load_microcode_adm() did not. If somehow cleanup() gets called and
clears pcache find_patch() could return return older patches then the currently installed microcode)
* Save the amd_bsp_mpb on every update. Otherwise, if someone would update the microcode after offlining the BSP, these updates would not get saved and would be lost on resume.
* apply_ucode_in_initrd() now also needs to save amd_bsp_mbp, because load_microcode_amd() its no longer doing this and its not using apply_microcode_amd().

---

Removing this hunk from load_microcode_amd() also allows me to kill the cpu parameter for that function in the next patch...

arch/x86/kernel/microcode_amd.c +6 -11
@@ -228,6 +228,12 @@ int apply_microcode_amd(int cpu)
 	pr_info("CPU%d: new patch_level=0x%08x\n", cpu,
 		mc_amd->hdr.patch_id);
 
+#if defined(CONFIG_MICROCODE_AMD_EARLY) && defined(CONFIG_X86_32)
+	/* save applied patch for early load */
+	memset(amd_bsp_mpb, 0, MPB_MAX_SIZE);
+	memcpy(amd_bsp_mpb, p->data, min_t(u32, ksize(p->data), MPB_MAX_SIZE));
+#endif
+
 	uci->cpu_sig.rev = mc_amd->hdr.patch_id;
 	c->microcode = mc_amd->hdr.patch_id;
 
@@ -385,17 +391,6 @@ enum ucode_state load_microcode_amd(int
 	if (ret != UCODE_OK)
 		cleanup();
 
-#if defined(CONFIG_MICROCODE_AMD_EARLY) && defined(CONFIG_X86_32)
-	/* save BSP's matching patch for early load */
-	if (cpu_data(cpu).cpu_index == boot_cpu_data.cpu_index) {
-		struct ucode_patch *p = find_patch(cpu);
-		if (p) {
-			memset(amd_bsp_mpb, 0, MPB_MAX_SIZE);
-			memcpy(amd_bsp_mpb, p->data, min_t(u32, ksize(p->data),
-							   MPB_MAX_SIZE));
-		}
-	}
-#endif
 	return ret;
 }
 
arch/x86/kernel/microcode_amd_early.c +7 -0
@@ -170,6 +170,13 @@ static void apply_ucode_in_initrd(void *
 		mc = (struct microcode_amd *)(data + SECTION_HDR_SIZE);
 		if (eq_id == mc->hdr.processor_rev_id && rev < mc->hdr.patch_id)
 			if (__apply_microcode_amd(mc) == 0) {
+#ifdef CONFIG_X86_32
+				/* save applied patch for early load */
+				memset((void *)__pa(amd_bsp_mpb), 0,
+					MPB_MAX_SIZE);
+				memcpy((void *)__pa(amd_bsp_mpb), mc,
+					min_t(u32, header[1], MPB_MAX_SIZE));
+#endif
 				rev = mc->hdr.patch_id;
 				*new_rev = rev;
 			}