Skip to contentSkip to conversation

x86, microcode, AMD: Fix early loading

PATCH In review Borislav Petkov 2 participants 7 messages Dec 5, 2013 – Dec 6, 2013

Subsystems (2)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

cover x86, microcode, AMD: Fix early loading

From: Borislav Petkov <[email protected]>

A couple of openSUSE bugzillas made me look at the early ucode loading on AMD.

The problem is, we're doing memory allocation too early with IRQs disabled and we really want to avoid that. Also, 32-bit has other problems like calling rd/wrmsr*/cpuid functions at their virtual addresses while paging is not enabled yet. Bah.

So, fix that by *always* using the initrd image handed in from the bootloader and cache the ucode patches only late, right before the initrd is jettisoned. This avoids the allocation issue completely. While at it, take care of the 32-bit issues too.

Testing on 32-bit and 64-bit passes here.

@Kim: I'd appreciate it if you guys ran those patches too, by creating an early ucode initrd as it is described in Documentation/x86/early-microcode.txt.

Thanks.

Borislav Petkov (4):
x86, ramdisk: Export relocated ramdisk VA x86, microcode: Share native MSR accessing variants x86, microcode, AMD: Fix early ucode loading x86, microcode: Move to a proper location

 arch/x86/include/asm/microcode.h                   |  15 ++
 arch/x86/include/asm/microcode_amd.h               |   7 +-
 arch/x86/include/asm/setup.h                       |   3 +-
 arch/x86/kernel/Makefile                           |   9 -
 arch/x86/kernel/cpu/Makefile                       |   1 +
 arch/x86/kernel/cpu/microcode/Makefile             |  11 +
 .../{microcode_amd.c => cpu/microcode/amd.c}       |  13 +-
 .../microcode/amd_early.c}                         | 239 ++++++++++++++-------
 .../{microcode_core.c => cpu/microcode/core.c}     |   0
 .../microcode/core_early.c}                        |   0
 .../{microcode_intel.c => cpu/microcode/intel.c}   |   0
 .../microcode/intel_early.c}                       |  10 -
 .../microcode/intel_lib.c}                         |   0
 arch/x86/kernel/setup.c                            |  19 +-
 14 files changed, 209 insertions(+), 118 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/microcode/Makefile
 rename arch/x86/kernel/{microcode_amd.c => cpu/microcode/amd.c} (96%)
 rename arch/x86/kernel/{microcode_amd_early.c => cpu/microcode/amd_early.c} (55%)
 rename arch/x86/kernel/{microcode_core.c => cpu/microcode/core.c} (100%)
 rename arch/x86/kernel/{microcode_core_early.c => cpu/microcode/core_early.c} (100%)
 rename arch/x86/kernel/{microcode_intel.c => cpu/microcode/intel.c} (100%)
 rename arch/x86/kernel/{microcode_intel_early.c => cpu/microcode/intel_early.c} (98%)
 rename arch/x86/kernel/{microcode_intel_lib.c => cpu/microcode/intel_lib.c} (100%)
Signature · 1 line
1.8.4
author maintainer
#1 lore raw

PATCH 1/4 x86, ramdisk: Export relocated ramdisk VA

From: Borislav Petkov <[email protected]>

The ramdisk can possibly get relocated if the whole image is not mapped. And since we're going over it in the microcode loader and fishing out the relevant microcode patches, we want to access it at its new location. Thus, export it.

---
 arch/x86/include/asm/setup.h |  3 ++-
 arch/x86/kernel/setup.c      | 19 ++++++++++---------
 2 files changed, 12 insertions(+), 10 deletions(-)
arch/x86/include/asm/setup.h +2 -1
index 59bcf4e22418..d62c9f809bc5 100644
@@ -3,7 +3,6 @@
 
 #include <uapi/asm/setup.h>
 
-
 #define COMMAND_LINE_SIZE 2048
 
 #include <linux/linkage.h>
@@ -29,6 +28,8 @@
 #include <asm/bootparam.h>
 #include <asm/x86_init.h>
 
+extern u64 relocated_ramdisk;
+
 /* Interrupt control for vSMPowered x86_64 systems */
 #ifdef CONFIG_X86_64
 void vsmp_init(void);
arch/x86/kernel/setup.c +10 -9
index f97cf4dd4b76..488e93e763c8 100644
@@ -295,6 +295,8 @@ static void __init reserve_brk(void)
 	_brk_start = 0;
 }
 
+u64 relocated_ramdisk;
+
 #ifdef CONFIG_BLK_DEV_INITRD
 
 static u64 __init get_ramdisk_image(void)
@@ -321,25 +323,24 @@ static void __init relocate_initrd(void)
 	u64 ramdisk_image = get_ramdisk_image();
 	u64 ramdisk_size  = get_ramdisk_size();
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);
-	u64 ramdisk_here;
 	unsigned long slop, clen, mapaddr;
 	char *p, *q;
 
 	/* We need to move the initrd down into directly mapped mem */
-	ramdisk_here = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
-						 area_size, PAGE_SIZE);
+	relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
+						   area_size, PAGE_SIZE);
 
-	if (!ramdisk_here)
+	if (!relocated_ramdisk)
 		panic("Cannot find place for new RAMDISK of size %lld\n",
-			 ramdisk_size);
+		      ramdisk_size);
 
 	/* Note: this includes all the mem currently occupied by
 	   the initrd, we rely on that fact to keep the data intact. */
-	memblock_reserve(ramdisk_here, area_size);
-	initrd_start = ramdisk_here + PAGE_OFFSET;
+	memblock_reserve(relocated_ramdisk, area_size);
+	initrd_start = relocated_ramdisk + PAGE_OFFSET;
 	initrd_end   = initrd_start + ramdisk_size;
 	printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-			 ramdisk_here, ramdisk_here + ramdisk_size - 1);
+	       relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
 
 	q = (char *)initrd_start;
 
@@ -363,7 +364,7 @@ static void __init relocate_initrd(void)
 	printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
 		" [mem %#010llx-%#010llx]\n",
 		ramdisk_image, ramdisk_image + ramdisk_size - 1,
-		ramdisk_here, ramdisk_here + ramdisk_size - 1);
+		relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
 }
 
 static void __init early_reserve_initrd(void)
Signature · 1 line
1.8.4
author maintainer
#2 lore raw

PATCH 2/4 x86, microcode: Share native MSR accessing variants

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

We want to use those in AMD's early loading path too. Also, add a native_wrmsrl variant.

---
 arch/x86/include/asm/microcode.h        | 15 +++++++++++++++
 arch/x86/kernel/microcode_intel_early.c | 10 ----------
 2 files changed, 15 insertions(+), 10 deletions(-)
arch/x86/include/asm/microcode.h +15 -0
index f98bd6625318..b59827e76529 100644
@@ -1,6 +1,21 @@
 #ifndef _ASM_X86_MICROCODE_H
 #define _ASM_X86_MICROCODE_H
 
+#define native_rdmsr(msr, val1, val2)			\
+do {							\
+	u64 __val = native_read_msr((msr));		\
+	(void)((val1) = (u32)__val);			\
+	(void)((val2) = (u32)(__val >> 32));		\
+} while (0)
+
+#define native_wrmsr(msr, low, high)			\
+	native_write_msr(msr, low, high)
+
+#define native_wrmsrl(msr, val)				\
+	native_write_msr((msr),				\
+			 (u32)((u64)(val)),		\
+			 (u32)((u64)(val) >> 32))
+
 struct cpu_signature {
 	unsigned int sig;
 	unsigned int pf;
arch/x86/kernel/microcode_intel_early.c +0 -10
index 1575deb2e636..18f739129e72 100644
@@ -365,16 +365,6 @@ out:
 	return state;
 }
 
-#define native_rdmsr(msr, val1, val2)		\
-do {						\
-	u64 __val = native_read_msr((msr));	\
-	(void)((val1) = (u32)__val);		\
-	(void)((val2) = (u32)(__val >> 32));	\
-} while (0)
-
-#define native_wrmsr(msr, low, high)		\
-	native_write_msr(msr, low, high);
-
 static int collect_cpu_info_early(struct ucode_cpu_info *uci)
 {
 	unsigned int val[2];
Signature · 1 line
1.8.4
author maintainer
#3 lore raw

PATCH 3/4 x86, microcode, AMD: Fix early ucode loading

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

The original idea to use the microcode cache for the APs doesn't pan out because we do memory allocation there very early and with IRQs disabled and we don't want to involve GFP_ATOMIC allocations. Not if it can be helped.

Thus, extend the caching of the BSP patch approach to the APs and iterate over the ucode in the initrd instead of using the cache. We still save the relevant patches to it but later, right before we jettison the initrd.

While at it, fix early ucode loading on 32-bit too.

---
 arch/x86/include/asm/microcode_amd.h  |   7 +-
 arch/x86/kernel/microcode_amd.c       |  13 +-
 arch/x86/kernel/microcode_amd_early.c | 239 ++++++++++++++++++++++------------
 3 files changed, 170 insertions(+), 89 deletions(-)
arch/x86/include/asm/microcode_amd.h +3 -4
index 4c019179a57d..b7b10b82d3e5 100644
@@ -61,11 +61,10 @@ extern int __apply_microcode_amd(struct microcode_amd *mc_amd);
 extern int apply_microcode_amd(int cpu);
 extern enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size);
 
+#define PATCH_MAX_SIZE PAGE_SIZE
+extern u8 amd_ucode_patch[PATCH_MAX_SIZE];
+
 #ifdef CONFIG_MICROCODE_AMD_EARLY
-#ifdef CONFIG_X86_32
-#define MPB_MAX_SIZE PAGE_SIZE
-extern u8 amd_bsp_mpb[MPB_MAX_SIZE];
-#endif
 extern void __init load_ucode_amd_bsp(void);
 extern void load_ucode_amd_ap(void);
 extern int __init save_microcode_in_initrd_amd(void);
arch/x86/kernel/microcode_amd.c +8 -5
index c3d4cc972eca..4a6ff747aaad 100644
@@ -182,10 +182,10 @@ int __apply_microcode_amd(struct microcode_amd *mc_amd)
 {
 	u32 rev, dummy;
 
-	wrmsrl(MSR_AMD64_PATCH_LOADER, (u64)(long)&mc_amd->hdr.data_code);
+	native_wrmsrl(MSR_AMD64_PATCH_LOADER, (u64)(long)&mc_amd->hdr.data_code);
 
 	/* verify patch application was successful */
-	rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
+	native_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
 	if (rev != mc_amd->hdr.patch_id)
 		return -1;
 
@@ -332,6 +332,9 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)
 	patch->patch_id  = mc_hdr->patch_id;
 	patch->equiv_cpu = proc_id;
 
+	pr_debug("%s: Added patch_id: 0x%08x, proc_id: 0x%04x\n",
+		 __func__, patch->patch_id, proc_id);
+
 	/* ... and add to cache. */
 	update_cache(patch);
 
@@ -390,9 +393,9 @@ enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size)
 	if (cpu_data(smp_processor_id()).cpu_index == boot_cpu_data.cpu_index) {
 		struct ucode_patch *p = find_patch(smp_processor_id());
 		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));
+			memset(amd_ucode_patch, 0, PATCH_MAX_SIZE);
+			memcpy(amd_ucode_patch, p->data, min_t(u32, ksize(p->data),
+							       PATCH_MAX_SIZE));
 		}
 	}
 #endif
arch/x86/kernel/microcode_amd_early.c +159 -80

410 lines not on this page · raw message

Signature · 1 line
1.8.4
author maintainer
#4 lore raw

PATCH 4/4 x86, microcode: Move to a proper location

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

We've grown a bunch of microcode loader files all prefixed with "microcode_". They should be under cpu/ because this is strictly CPU-related functionality so do that and drop the prefix since they're in their own directory now which gives that prefix. :)

---
 arch/x86/kernel/Makefile                                      |  9 ---------
 arch/x86/kernel/cpu/Makefile                                  |  1 +
 arch/x86/kernel/cpu/microcode/Makefile                        | 11 +++++++++++
 arch/x86/kernel/{microcode_amd.c => cpu/microcode/amd.c}      |  0
 .../{microcode_amd_early.c => cpu/microcode/amd_early.c}      |  0
 arch/x86/kernel/{microcode_core.c => cpu/microcode/core.c}    |  0
 .../{microcode_core_early.c => cpu/microcode/core_early.c}    |  0
 arch/x86/kernel/{microcode_intel.c => cpu/microcode/intel.c}  |  0
 .../{microcode_intel_early.c => cpu/microcode/intel_early.c}  |  0
 .../{microcode_intel_lib.c => cpu/microcode/intel_lib.c}      |  0
 10 files changed, 12 insertions(+), 9 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/microcode/Makefile
 rename arch/x86/kernel/{microcode_amd.c => cpu/microcode/amd.c} (100%)
 rename arch/x86/kernel/{microcode_amd_early.c => cpu/microcode/amd_early.c} (100%)
 rename arch/x86/kernel/{microcode_core.c => cpu/microcode/core.c} (100%)
 rename arch/x86/kernel/{microcode_core_early.c => cpu/microcode/core_early.c} (100%)
 rename arch/x86/kernel/{microcode_intel.c => cpu/microcode/intel.c} (100%)
 rename arch/x86/kernel/{microcode_intel_early.c => cpu/microcode/intel_early.c} (100%)
 rename arch/x86/kernel/{microcode_intel_lib.c => cpu/microcode/intel_lib.c} (100%)
arch/x86/kernel/Makefile +0 -9
index 9b0a34e2cd79..4d0094dbb6c9 100644
@@ -91,15 +91,6 @@ obj-$(CONFIG_PARAVIRT_CLOCK)	+= pvclock.o
 
 obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
 
-obj-$(CONFIG_MICROCODE_EARLY)		+= microcode_core_early.o
-obj-$(CONFIG_MICROCODE_INTEL_EARLY)	+= microcode_intel_early.o
-obj-$(CONFIG_MICROCODE_INTEL_LIB)	+= microcode_intel_lib.o
-microcode-y				:= microcode_core.o
-microcode-$(CONFIG_MICROCODE_INTEL)	+= microcode_intel.o
-microcode-$(CONFIG_MICROCODE_AMD)	+= microcode_amd.o
-obj-$(CONFIG_MICROCODE_AMD_EARLY)	+= microcode_amd_early.o
-obj-$(CONFIG_MICROCODE)			+= microcode.o
-
 obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 
 obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
arch/x86/kernel/cpu/Makefile +1 -0
index 6359506a19ee..7fd54f09b011 100644
@@ -42,6 +42,7 @@ endif
 
 obj-$(CONFIG_X86_MCE)			+= mcheck/
 obj-$(CONFIG_MTRR)			+= mtrr/
+obj-$(CONFIG_MICROCODE)			+= microcode/
 
 obj-$(CONFIG_X86_LOCAL_APIC)		+= perfctr-watchdog.o perf_event_amd_ibs.o
 
arch/x86/kernel/cpu/microcode/Makefile new file +11 -0
new file mode 100644
index 000000000000..817fec409267
@@ -0,0 +1,11 @@
+obj-$(CONFIG_MICROCODE_EARLY)		+= core_early.o
+obj-$(CONFIG_MICROCODE_INTEL_EARLY)	+= intel_early.o
+obj-$(CONFIG_MICROCODE_INTEL_LIB)	+= intel_lib.o
+microcode-y				:= core.o
+microcode-$(CONFIG_MICROCODE_INTEL)	+= intel.o
+microcode-$(CONFIG_MICROCODE_AMD)	+= amd.o
+obj-$(CONFIG_MICROCODE_AMD_EARLY)	+= amd_early.o
+obj-$(CONFIG_MICROCODE)			+= microcode.o
+
+
+
arch/x86/kernel/cpu/microcode/amd.c renamed from arch/x86/kernel/microcode_amd.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_amd.c
rename to arch/x86/kernel/cpu/microcode/amd.c
arch/x86/kernel/cpu/microcode/amd_early.c renamed from arch/x86/kernel/microcode_amd_early.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_amd_early.c
rename to arch/x86/kernel/cpu/microcode/amd_early.c
arch/x86/kernel/cpu/microcode/core.c renamed from arch/x86/kernel/microcode_core.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_core.c
rename to arch/x86/kernel/cpu/microcode/core.c
arch/x86/kernel/cpu/microcode/core_early.c renamed from arch/x86/kernel/microcode_core_early.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_core_early.c
rename to arch/x86/kernel/cpu/microcode/core_early.c
arch/x86/kernel/cpu/microcode/intel.c renamed from arch/x86/kernel/microcode_intel.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_intel.c
rename to arch/x86/kernel/cpu/microcode/intel.c
arch/x86/kernel/cpu/microcode/intel_early.c renamed from arch/x86/kernel/microcode_intel_early.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_intel_early.c
rename to arch/x86/kernel/cpu/microcode/intel_early.c
arch/x86/kernel/cpu/microcode/intel_lib.c renamed from arch/x86/kernel/microcode_intel_lib.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_intel_lib.c
rename to arch/x86/kernel/cpu/microcode/intel_lib.c
Signature · 1 line
1.8.4
author maintainer
#5 lore raw

PATCH 4/4 x86, microcode: Move to a proper location

From: Borislav Petkov <[email protected]>
Subject: [PATCH -v1.1 4/4] x86, microcode: Move to a proper location

We've grown a bunch of microcode loader files all prefixed with "microcode_". They should be under cpu/ because this is strictly CPU-related functionality so do that and drop the prefix since they're in their own directory now which gives that prefix. :)

While at it, drop MICROCODE_INTEL_LIB config item and stash the functionality under CONFIG_MICROCODE_INTEL as it was its only user.

---
 arch/x86/Kconfig                                                 | 4 ----
 arch/x86/kernel/Makefile                                         | 9 ---------
 arch/x86/kernel/cpu/Makefile                                     | 1 +
 arch/x86/kernel/cpu/microcode/Makefile                           | 7 +++++++
 arch/x86/kernel/{microcode_amd.c => cpu/microcode/amd.c}         | 0
 .../kernel/{microcode_amd_early.c => cpu/microcode/amd_early.c}  | 0
 arch/x86/kernel/{microcode_core.c => cpu/microcode/core.c}       | 0
 .../{microcode_core_early.c => cpu/microcode/core_early.c}       | 0
 arch/x86/kernel/{microcode_intel.c => cpu/microcode/intel.c}     | 0
 .../{microcode_intel_early.c => cpu/microcode/intel_early.c}     | 0
 .../kernel/{microcode_intel_lib.c => cpu/microcode/intel_lib.c}  | 0
 11 files changed, 8 insertions(+), 13 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/microcode/Makefile
 rename arch/x86/kernel/{microcode_amd.c => cpu/microcode/amd.c} (100%)
 rename arch/x86/kernel/{microcode_amd_early.c => cpu/microcode/amd_early.c} (100%)
 rename arch/x86/kernel/{microcode_core.c => cpu/microcode/core.c} (100%)
 rename arch/x86/kernel/{microcode_core_early.c => cpu/microcode/core_early.c} (100%)
 rename arch/x86/kernel/{microcode_intel.c => cpu/microcode/intel.c} (100%)
 rename arch/x86/kernel/{microcode_intel_early.c => cpu/microcode/intel_early.c} (100%)
 rename arch/x86/kernel/{microcode_intel_lib.c => cpu/microcode/intel_lib.c} (100%)
arch/x86/Kconfig +0 -4
index c84cf90ca693..cb3a8602b67a 100644
@@ -1111,10 +1111,6 @@ config MICROCODE_OLD_INTERFACE
 	def_bool y
 	depends on MICROCODE
 
-config MICROCODE_INTEL_LIB
-	def_bool y
-	depends on MICROCODE_INTEL
-
 config MICROCODE_INTEL_EARLY
 	def_bool n
 
arch/x86/kernel/Makefile +0 -9
index 9b0a34e2cd79..4d0094dbb6c9 100644
@@ -91,15 +91,6 @@ obj-$(CONFIG_PARAVIRT_CLOCK)	+= pvclock.o
 
 obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
 
-obj-$(CONFIG_MICROCODE_EARLY)		+= microcode_core_early.o
-obj-$(CONFIG_MICROCODE_INTEL_EARLY)	+= microcode_intel_early.o
-obj-$(CONFIG_MICROCODE_INTEL_LIB)	+= microcode_intel_lib.o
-microcode-y				:= microcode_core.o
-microcode-$(CONFIG_MICROCODE_INTEL)	+= microcode_intel.o
-microcode-$(CONFIG_MICROCODE_AMD)	+= microcode_amd.o
-obj-$(CONFIG_MICROCODE_AMD_EARLY)	+= microcode_amd_early.o
-obj-$(CONFIG_MICROCODE)			+= microcode.o
-
 obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 
 obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
arch/x86/kernel/cpu/Makefile +1 -0
index 6359506a19ee..7fd54f09b011 100644
@@ -42,6 +42,7 @@ endif
 
 obj-$(CONFIG_X86_MCE)			+= mcheck/
 obj-$(CONFIG_MTRR)			+= mtrr/
+obj-$(CONFIG_MICROCODE)			+= microcode/
 
 obj-$(CONFIG_X86_LOCAL_APIC)		+= perfctr-watchdog.o perf_event_amd_ibs.o
 
arch/x86/kernel/cpu/microcode/Makefile new file +7 -0
new file mode 100644
index 000000000000..285c85427c32
@@ -0,0 +1,7 @@
+microcode-y				:= core.o
+obj-$(CONFIG_MICROCODE)			+= microcode.o
+microcode-$(CONFIG_MICROCODE_INTEL)	+= intel.o intel_lib.o
+microcode-$(CONFIG_MICROCODE_AMD)	+= amd.o
+obj-$(CONFIG_MICROCODE_EARLY)		+= core_early.o
+obj-$(CONFIG_MICROCODE_INTEL_EARLY)	+= intel_early.o
+obj-$(CONFIG_MICROCODE_AMD_EARLY)	+= amd_early.o
arch/x86/kernel/cpu/microcode/amd.c renamed from arch/x86/kernel/microcode_amd.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_amd.c
rename to arch/x86/kernel/cpu/microcode/amd.c
arch/x86/kernel/cpu/microcode/amd_early.c renamed from arch/x86/kernel/microcode_amd_early.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_amd_early.c
rename to arch/x86/kernel/cpu/microcode/amd_early.c
arch/x86/kernel/cpu/microcode/core.c renamed from arch/x86/kernel/microcode_core.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_core.c
rename to arch/x86/kernel/cpu/microcode/core.c
arch/x86/kernel/cpu/microcode/core_early.c renamed from arch/x86/kernel/microcode_core_early.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_core_early.c
rename to arch/x86/kernel/cpu/microcode/core_early.c
arch/x86/kernel/cpu/microcode/intel.c renamed from arch/x86/kernel/microcode_intel.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_intel.c
rename to arch/x86/kernel/cpu/microcode/intel.c
arch/x86/kernel/cpu/microcode/intel_early.c renamed from arch/x86/kernel/microcode_intel_early.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_intel_early.c
rename to arch/x86/kernel/cpu/microcode/intel_early.c
arch/x86/kernel/cpu/microcode/intel_lib.c renamed from arch/x86/kernel/microcode_intel_lib.c +0 -0
similarity index 100%
rename from arch/x86/kernel/microcode_intel_lib.c
rename to arch/x86/kernel/cpu/microcode/intel_lib.c
Signature · 8 lines
1.8.4

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#6 lore raw
In reply to Borislav Petkov

Boris,
I will take a look at it.

--kim

-----Original Message-----
From: Borislav Petkov [mailto:[email protected]]
Sent: Thursday, December 05, 2013 3:32 PM
To: X86 ML
Cc: LKML; Borislav Petkov; Naru, Kim; Thomas Renninger
Subject: [PATCH 0/4] x86, microcode, AMD: Fix early loading

From: Borislav Petkov <[email protected]>

A couple of openSUSE bugzillas made me look at the early ucode loading on AMD.

The problem is, we're doing memory allocation too early with IRQs disabled and we really want to avoid that. Also, 32-bit has other problems like calling rd/wrmsr*/cpuid functions at their virtual addresses while paging is not enabled yet. Bah.

So, fix that by *always* using the initrd image handed in from the bootloader and cache the ucode patches only late, right before the initrd is jettisoned. This avoids the allocation issue completely. While at it, take care of the 32-bit issues too.

Testing on 32-bit and 64-bit passes here.

@Kim: I'd appreciate it if you guys ran those patches too, by creating an early ucode initrd as it is described in Documentation/x86/early-microcode.txt.

Thanks.

Borislav Petkov (4):
x86, ramdisk: Export relocated ramdisk VA x86, microcode: Share native MSR accessing variants x86, microcode, AMD: Fix early ucode loading x86, microcode: Move to a proper location

 arch/x86/include/asm/microcode.h                   |  15 ++
 arch/x86/include/asm/microcode_amd.h               |   7 +-
 arch/x86/include/asm/setup.h                       |   3 +-
 arch/x86/kernel/Makefile                           |   9 -
 arch/x86/kernel/cpu/Makefile                       |   1 +
 arch/x86/kernel/cpu/microcode/Makefile             |  11 +
 .../{microcode_amd.c => cpu/microcode/amd.c}       |  13 +-
 .../microcode/amd_early.c}                         | 239 ++++++++++++++-------
 .../{microcode_core.c => cpu/microcode/core.c}     |   0
 .../microcode/core_early.c}                        |   0
 .../{microcode_intel.c => cpu/microcode/intel.c}   |   0
 .../microcode/intel_early.c}                       |  10 -
 .../microcode/intel_lib.c}                         |   0
 arch/x86/kernel/setup.c                            |  19 +-
 14 files changed, 209 insertions(+), 118 deletions(-)  create mode 100644 arch/x86/kernel/cpu/microcode/Makefile
 rename arch/x86/kernel/{microcode_amd.c => cpu/microcode/amd.c} (96%)  rename arch/x86/kernel/{microcode_amd_early.c => cpu/microcode/amd_early.c} (55%)  rename arch/x86/kernel/{microcode_core.c => cpu/microcode/core.c} (100%)  rename arch/x86/kernel/{microcode_core_early.c => cpu/microcode/core_early.c} (100%)  rename arch/x86/kernel/{microcode_intel.c => cpu/microcode/intel.c} (100%)  rename arch/x86/kernel/{microcode_intel_early.c => cpu/microcode/intel_early.c} (98%)  rename arch/x86/kernel/{microcode_intel_lib.c => cpu/microcode/intel_lib.c} (100%)

--
1.8.4