public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/5] x86, AMD: saved applied, not loaded microcode for reloading on resume
@ 2013-07-23 21:02 Torsten Kaiser
  0 siblings, 0 replies; only message in thread
From: Torsten Kaiser @ 2013-07-23 21:02 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Borislav Petkov,
	Jacob Shin, Johannes Hirte, linux-kernel

* 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().

Signed-off-by: Torsten Kaiser <just.for.lkml@googlemail.com>

---

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

--- a/arch/x86/kernel/microcode_amd.c	2013-07-23 19:43:30.359517091 +0200
+++ b/arch/x86/kernel/microcode_amd.c	2013-07-23 20:05:04.469506188 +0200
@@ -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;
 }
 
--- a/arch/x86/kernel/microcode_amd_early.c	2013-07-23 20:00:04.889508712 +0200
+++ b/arch/x86/kernel/microcode_amd_early.c	2013-07-23 20:05:14.969506099 +0200
@@ -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;
 			}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-07-23 21:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-23 21:02 [PATCH 4/5] x86, AMD: saved applied, not loaded microcode for reloading on resume Torsten Kaiser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox