All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3 0/2] x86/microcode/amd: early loading fixes
@ 2013-06-08  2:22 Jacob Shin
  2013-06-08  2:22 ` [PATCH V3 1/2] x86/microcode/amd: make find_ucode_in_initrd() __init Jacob Shin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jacob Shin @ 2013-06-08  2:22 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Ingo Molnar, Thomas Gleixner, Yinghai Lu,
	Henrique de Moraes Holschuh, Borislav Petkov, Andreas Herrmann,
	x86, linux-kernel, Jacob Shin

This patchset addreses two problems with early loading on AMD.

First, feedback from Yinghai that find_ucode_in_initrd() should be
marked __init:
  https://lkml.org/lkml/2013/6/4/695

And second, feedback from Henrique that Intel early loading supports
multiple microcode firmware concatenated together, whereas the current
AMD implementation lacks this support:
  https://lkml.org/lkml/2013/5/31/4

V3:
* style fix -- reduce multiple if statements into a single one

V2:
* test for !initrd_start before using it
* use __pa() instead of __pa_nodebug() on AP load
* fixed calculation of start offset and size of the microcode container file

Jacob Shin (2):
  x86/microcode/amd: make find_ucode_in_initrd() __init
  x86/microcode/amd: allow multiple families' bin files appended
    together

 arch/x86/kernel/microcode_amd_early.c |  170 ++++++++++++++++++++++++---------
 1 file changed, 125 insertions(+), 45 deletions(-)

-- 
1.7.9.5



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V3 1/2] x86/microcode/amd: make find_ucode_in_initrd() __init
  2013-06-08  2:22 [PATCH V3 0/2] x86/microcode/amd: early loading fixes Jacob Shin
@ 2013-06-08  2:22 ` Jacob Shin
  2013-06-08  2:22 ` [PATCH V3 2/2] x86/microcode/amd: allow multiple families' bin files appended together Jacob Shin
  2013-06-12 19:31 ` [PATCH V3 0/2] x86/microcode/amd: early loading fixes Jacob Shin
  2 siblings, 0 replies; 9+ messages in thread
From: Jacob Shin @ 2013-06-08  2:22 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Ingo Molnar, Thomas Gleixner, Yinghai Lu,
	Henrique de Moraes Holschuh, Borislav Petkov, Andreas Herrmann,
	x86, linux-kernel, Jacob Shin

Change find_ucode_in_initrd() to __init and only let BSP call it
during cold boot. This is the right thing to do because only BSP will
see initrd loaded by the boot loader. APs will offset into
initrd_start to find the microcode patch binary.

Reported-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Jacob Shin <jacob.shin@amd.com>
---
 arch/x86/kernel/microcode_amd_early.c |  102 ++++++++++++++++++++++-----------
 1 file changed, 69 insertions(+), 33 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd_early.c b/arch/x86/kernel/microcode_amd_early.c
index 9618805..c783248 100644
--- a/arch/x86/kernel/microcode_amd_early.c
+++ b/arch/x86/kernel/microcode_amd_early.c
@@ -9,6 +9,7 @@
  */
 
 #include <linux/earlycpio.h>
+#include <linux/initrd.h>
 
 #include <asm/cpu.h>
 #include <asm/setup.h>
@@ -16,40 +17,59 @@
 
 static bool ucode_loaded;
 static u32 ucode_new_rev;
+static unsigned long ucode_offset;
+static size_t ucode_size;
 
 /*
  * Microcode patch container file is prepended to the initrd in cpio format.
  * See Documentation/x86/early-microcode.txt
  */
-static __cpuinitdata char ucode_path[] = "kernel/x86/microcode/AuthenticAMD.bin";
+static __initdata char ucode_path[] = "kernel/x86/microcode/AuthenticAMD.bin";
 
-static struct cpio_data __cpuinit find_ucode_in_initrd(void)
+static struct cpio_data __init find_ucode_in_initrd(void)
 {
 	long offset = 0;
+	char *path;
+	void *start;
+	size_t size;
+	unsigned long *uoffset;
+	size_t *usize;
 	struct cpio_data cd;
 
 #ifdef CONFIG_X86_32
+	struct boot_params *p;
+
 	/*
 	 * On 32-bit, early load occurs before paging is turned on so we need
 	 * to use physical addresses.
 	 */
-	if (!(read_cr0() & X86_CR0_PG)) {
-		struct boot_params *p;
-		p  = (struct boot_params *)__pa_nodebug(&boot_params);
-		cd = find_cpio_data((char *)__pa_nodebug(ucode_path),
-			(void *)p->hdr.ramdisk_image, p->hdr.ramdisk_size,
-			&offset);
-	} else
+	p       = (struct boot_params *)__pa_nodebug(&boot_params);
+	path    = (char *)__pa_nodebug(ucode_path);
+	start   = (void *)p->hdr.ramdisk_image;
+	size    = p->hdr.ramdisk_size;
+	uoffset = (unsigned long *)__pa_nodebug(&ucode_offset);
+	usize   = (size_t *)__pa_nodebug(&ucode_size);
+#else
+	path    = ucode_path;
+	start   = (void *)(boot_params.hdr.ramdisk_image + PAGE_OFFSET);
+	size    = boot_params.hdr.ramdisk_size;
+	uoffset = &ucode_offset;
+	usize   = &ucode_size;
 #endif
-		cd = find_cpio_data(ucode_path,
-			(void *)(boot_params.hdr.ramdisk_image + PAGE_OFFSET),
-			boot_params.hdr.ramdisk_size, &offset);
+
+	cd = find_cpio_data(path, start, size, &offset);
+	if (!cd.data)
+		return cd;
 
 	if (*(u32 *)cd.data != UCODE_MAGIC) {
 		cd.data = NULL;
 		cd.size = 0;
+		return cd;
 	}
 
+	*uoffset = (u8 *)cd.data - (u8 *)start;
+	*usize   = cd.size;
+
 	return cd;
 }
 
@@ -62,9 +82,8 @@ static struct cpio_data __cpuinit find_ucode_in_initrd(void)
  * load_microcode_amd() to save equivalent cpu table and microcode patches in
  * kernel heap memory.
  */
-static void __cpuinit apply_ucode_in_initrd(void)
+static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 {
-	struct cpio_data cd;
 	struct equiv_cpu_entry *eq;
 	u32 *header;
 	u8  *data;
@@ -78,12 +97,9 @@ static void __cpuinit apply_ucode_in_initrd(void)
 #else
 	new_rev = &ucode_new_rev;
 #endif
-	cd = find_ucode_in_initrd();
-	if (!cd.data)
-		return;
 
-	data   = cd.data;
-	left   = cd.size;
+	data   = ucode;
+	left   = size;
 	header = (u32 *)data;
 
 	/* find equiv cpu table */
@@ -129,7 +145,11 @@ static void __cpuinit apply_ucode_in_initrd(void)
 
 void __init load_ucode_amd_bsp(void)
 {
-	apply_ucode_in_initrd();
+	struct cpio_data cd = find_ucode_in_initrd();
+	if (!cd.data)
+		return;
+
+	apply_ucode_in_initrd(cd.data, cd.size);
 }
 
 #ifdef CONFIG_X86_32
@@ -145,12 +165,26 @@ u8 amd_bsp_mpb[MPB_MAX_SIZE];
 void __cpuinit load_ucode_amd_ap(void)
 {
 	struct microcode_amd *mc;
+	unsigned long *initrd;
+	unsigned long *uoffset;
+	size_t *usize;
+	void *ucode;
 
-	mc = (struct microcode_amd *)__pa_nodebug(amd_bsp_mpb);
-	if (mc->hdr.patch_id && mc->hdr.processor_rev_id)
+	mc = (struct microcode_amd *)__pa(amd_bsp_mpb);
+	if (mc->hdr.patch_id && mc->hdr.processor_rev_id) {
 		__apply_microcode_amd(mc);
-	else
-		apply_ucode_in_initrd();
+		return;
+	}
+
+	initrd  = (unsigned long *)__pa(&initrd_start);
+	uoffset = (unsigned long *)__pa(&ucode_offset);
+	usize   = (size_t *)__pa(&ucode_size);
+
+	if (!*usize || !*initrd)
+		return;
+
+	ucode = (void *)((unsigned long)__pa(*initrd) + *uoffset);
+	apply_ucode_in_initrd(ucode, *usize);
 }
 
 static void __init collect_cpu_sig_on_bsp(void *arg)
@@ -181,8 +215,13 @@ void __cpuinit load_ucode_amd_ap(void)
 	collect_cpu_info_amd_early(&cpu_data(cpu), ucode_cpu_info + cpu);
 
 	if (cpu && !ucode_loaded) {
-		struct cpio_data cd = find_ucode_in_initrd();
-		if (load_microcode_amd(0, cd.data, cd.size) != UCODE_OK)
+		void *ucode;
+
+		if (!ucode_size || !initrd_start)
+			return;
+
+		ucode = (void *)(initrd_start + ucode_offset);
+		if (load_microcode_amd(0, ucode, ucode_size) != UCODE_OK)
 			return;
 		ucode_loaded = true;
 	}
@@ -194,7 +233,7 @@ void __cpuinit load_ucode_amd_ap(void)
 int __init save_microcode_in_initrd_amd(void)
 {
 	enum ucode_state ret;
-	struct cpio_data cd;
+	void *ucode;
 #ifdef CONFIG_X86_32
 	unsigned int bsp = boot_cpu_data.cpu_index;
 	struct ucode_cpu_info *uci = ucode_cpu_info + bsp;
@@ -206,14 +245,11 @@ int __init save_microcode_in_initrd_amd(void)
 		pr_info("microcode: updated early to new patch_level=0x%08x\n",
 			ucode_new_rev);
 
-	if (ucode_loaded)
+	if (ucode_loaded || !ucode_size || !initrd_start)
 		return 0;
 
-	cd = find_ucode_in_initrd();
-	if (!cd.data)
-		return -EINVAL;
-
-	ret = load_microcode_amd(0, cd.data, cd.size);
+	ucode = (void *)(initrd_start + ucode_offset);
+	ret = load_microcode_amd(0, ucode, ucode_size);
 	if (ret != UCODE_OK)
 		return -EINVAL;
 
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH V3 2/2] x86/microcode/amd: allow multiple families' bin files appended together
  2013-06-08  2:22 [PATCH V3 0/2] x86/microcode/amd: early loading fixes Jacob Shin
  2013-06-08  2:22 ` [PATCH V3 1/2] x86/microcode/amd: make find_ucode_in_initrd() __init Jacob Shin
@ 2013-06-08  2:22 ` Jacob Shin
  2013-06-12 19:31 ` [PATCH V3 0/2] x86/microcode/amd: early loading fixes Jacob Shin
  2 siblings, 0 replies; 9+ messages in thread
From: Jacob Shin @ 2013-06-08  2:22 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Ingo Molnar, Thomas Gleixner, Yinghai Lu,
	Henrique de Moraes Holschuh, Borislav Petkov, Andreas Herrmann,
	x86, linux-kernel, Jacob Shin

Add support for parsing through multiple families' microcode patch
container binary files appended together when early loading. This is
already supported on Intel.

Reported-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Signed-off-by: Jacob Shin <jacob.shin@amd.com>
---
 arch/x86/kernel/microcode_amd_early.c |   68 +++++++++++++++++++++++++++------
 1 file changed, 56 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd_early.c b/arch/x86/kernel/microcode_amd_early.c
index c783248..1ac6e9a 100644
--- a/arch/x86/kernel/microcode_amd_early.c
+++ b/arch/x86/kernel/microcode_amd_early.c
@@ -87,15 +87,21 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 	struct equiv_cpu_entry *eq;
 	u32 *header;
 	u8  *data;
-	u16 eq_id;
+	u16 eq_id = 0;
 	int offset, left;
-	u32 rev, dummy;
+	u32 rev, eax;
 	u32 *new_rev;
+	unsigned long *uoffset;
+	size_t *usize;
 
 #ifdef CONFIG_X86_32
 	new_rev = (u32 *)__pa_nodebug(&ucode_new_rev);
+	uoffset = (unsigned long *)__pa_nodebug(&ucode_offset);
+	usize   = (size_t *)__pa_nodebug(&ucode_size);
 #else
 	new_rev = &ucode_new_rev;
+	uoffset = &ucode_offset;
+	usize   = &ucode_size;
 #endif
 
 	data   = ucode;
@@ -108,18 +114,50 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 	    header[2] == 0)                            /* size */
 		return;
 
-	eq     = (struct equiv_cpu_entry *)(data + CONTAINER_HDR_SZ);
-	offset = header[2] + CONTAINER_HDR_SZ;
-	data  += offset;
-	left  -= offset;
+	eax = cpuid_eax(0x00000001);
+
+	while (left > 0) {
+		eq = (struct equiv_cpu_entry *)(data + CONTAINER_HDR_SZ);
+
+		offset = header[2] + CONTAINER_HDR_SZ;
+		data  += offset;
+		left  -= offset;
 
-	eq_id  = find_equiv_id(eq, cpuid_eax(0x00000001));
-	if (!eq_id)
+		eq_id = find_equiv_id(eq, eax);
+		if (eq_id)
+			break;
+
+		/*
+		 * support multiple container files appended together. if this
+		 * one does not have a matching equivalent cpu entry, we fast
+		 * forward to the next container file.
+		 */
+		while (left > 0) {
+			header = (u32 *)data;
+			if (header[0] == UCODE_MAGIC &&
+			    header[1] == UCODE_EQUIV_CPU_TABLE_TYPE)
+				break;
+
+			offset = header[1] + SECTION_HDR_SIZE;
+			data  += offset;
+			left  -= offset;
+		}
+
+		/* mark where the next microcode container file starts */
+		offset    = data - (u8 *)ucode;
+		*uoffset += offset;
+		*usize   -= offset;
+		ucode     = data;
+	}
+
+	if (!eq_id) {
+		*usize = 0;
 		return;
+	}
 
 	/* find ucode and update if needed */
 
-	rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
+	rdmsr(MSR_AMD64_PATCH_LEVEL, rev, eax);
 
 	while (left > 0) {
 		struct microcode_amd *mc;
@@ -132,15 +170,21 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 		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) {
-				if (!(*new_rev))
-					*new_rev = mc->hdr.patch_id;
-				break;
+				rev = mc->hdr.patch_id;
+				*new_rev = rev;
 			}
 
 		offset  = header[1] + SECTION_HDR_SIZE;
 		data   += offset;
 		left   -= offset;
 	}
+
+	/* mark where this microcode container file ends */
+	offset  = *usize - (data - (u8 *)ucode);
+	*usize -= offset;
+
+	if (!(*new_rev))
+		*usize = 0;
 }
 
 void __init load_ucode_amd_bsp(void)
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH V3 0/2] x86/microcode/amd: early loading fixes
  2013-06-08  2:22 [PATCH V3 0/2] x86/microcode/amd: early loading fixes Jacob Shin
  2013-06-08  2:22 ` [PATCH V3 1/2] x86/microcode/amd: make find_ucode_in_initrd() __init Jacob Shin
  2013-06-08  2:22 ` [PATCH V3 2/2] x86/microcode/amd: allow multiple families' bin files appended together Jacob Shin
@ 2013-06-12 19:31 ` Jacob Shin
  2013-06-20 10:30   ` Ingo Molnar
  2 siblings, 1 reply; 9+ messages in thread
From: Jacob Shin @ 2013-06-12 19:31 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Ingo Molnar, Thomas Gleixner, Yinghai Lu,
	Henrique de Moraes Holschuh, Borislav Petkov, Andreas Herrmann,
	x86, linux-kernel

On Fri, Jun 07, 2013 at 09:22:18PM -0500, Jacob Shin wrote:
> This patchset addreses two problems with early loading on AMD.
> 
> First, feedback from Yinghai that find_ucode_in_initrd() should be
> marked __init:
>   https://lkml.org/lkml/2013/6/4/695
> 
> And second, feedback from Henrique that Intel early loading supports
> multiple microcode firmware concatenated together, whereas the current
> AMD implementation lacks this support:
>   https://lkml.org/lkml/2013/5/31/4
> 
> V3:
> * style fix -- reduce multiple if statements into a single one

Hi hpa or Yinghai, just wondering if you had the chance to look at this
V3 yet.

Thank you,


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V3 0/2] x86/microcode/amd: early loading fixes
  2013-06-12 19:31 ` [PATCH V3 0/2] x86/microcode/amd: early loading fixes Jacob Shin
@ 2013-06-20 10:30   ` Ingo Molnar
  2013-06-20 15:16     ` Jacob Shin
  0 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2013-06-20 10:30 UTC (permalink / raw)
  To: Jacob Shin
  Cc: H. Peter Anvin, Ingo Molnar, Thomas Gleixner, Yinghai Lu,
	Henrique de Moraes Holschuh, Borislav Petkov, Andreas Herrmann,
	x86, linux-kernel


* Jacob Shin <jacob.shin@amd.com> wrote:

> On Fri, Jun 07, 2013 at 09:22:18PM -0500, Jacob Shin wrote:
> > This patchset addreses two problems with early loading on AMD.
> > 
> > First, feedback from Yinghai that find_ucode_in_initrd() should be
> > marked __init:
> >   https://lkml.org/lkml/2013/6/4/695
> > 
> > And second, feedback from Henrique that Intel early loading supports
> > multiple microcode firmware concatenated together, whereas the current
> > AMD implementation lacks this support:
> >   https://lkml.org/lkml/2013/5/31/4
> > 
> > V3:
> > * style fix -- reduce multiple if statements into a single one
> 
> Hi hpa or Yinghai, just wondering if you had the chance to look at this
> V3 yet.

It appears Peter applied v2 to tip:x86/microcode two days before you sent 
v3 - please send any changes in v3 as delta patches.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V3 0/2] x86/microcode/amd: early loading fixes
  2013-06-20 10:30   ` Ingo Molnar
@ 2013-06-20 15:16     ` Jacob Shin
  2013-06-20 15:24       ` Jacob Shin
  0 siblings, 1 reply; 9+ messages in thread
From: Jacob Shin @ 2013-06-20 15:16 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: H. Peter Anvin, Ingo Molnar, Thomas Gleixner, Yinghai Lu,
	Henrique de Moraes Holschuh, Borislav Petkov, Andreas Herrmann,
	x86, linux-kernel

On Thu, Jun 20, 2013 at 12:30:53PM +0200, Ingo Molnar wrote:
> 
> * Jacob Shin <jacob.shin@amd.com> wrote:
> 
> > On Fri, Jun 07, 2013 at 09:22:18PM -0500, Jacob Shin wrote:
> > > This patchset addreses two problems with early loading on AMD.
> > > 
> > > First, feedback from Yinghai that find_ucode_in_initrd() should be
> > > marked __init:
> > >   https://lkml.org/lkml/2013/6/4/695
> > > 
> > > And second, feedback from Henrique that Intel early loading supports
> > > multiple microcode firmware concatenated together, whereas the current
> > > AMD implementation lacks this support:
> > >   https://lkml.org/lkml/2013/5/31/4
> > > 
> > > V3:
> > > * style fix -- reduce multiple if statements into a single one
> > 
> > Hi hpa or Yinghai, just wondering if you had the chance to look at this
> > V3 yet.
> 
> It appears Peter applied v2 to tip:x86/microcode two days before you sent 
> v3 - please send any changes in v3 as delta patches.

I actually recieved the tip-bot email <https://lkml.org/lkml/2013/6/12/468>
couple of days after sending out the above message, so I assumed that
V3 was committed in.

I should have read the tip-bot message thoroughly and noticed
it. Sorry about that. Here is the delta patch:

---8<---

>From 1445587da716b306f39feef46fb7150f292060c7 Mon Sep 17 00:00:00 2001
From: Jacob Shin <jacob.shin@amd.com>
Date: Thu, 20 Jun 2013 09:52:50 -0500
Subject: [PATCH] x86, microcode, amd: another early loading fixup

commit cd1c32ca969ebfd65e61312c988223bb14f09c2e is an early premature
rendition of the patch. Augment it with this delta patch to:
  * correctly mark offset and size of the matching bin file
  * use __pa instead of __pa_nodebug during AP load
  * check for !initrd_start before using it
---
 arch/x86/kernel/microcode_amd_early.c |   40 ++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd_early.c b/arch/x86/kernel/microcode_amd_early.c
index 4c593c2..1ac6e9a 100644
--- a/arch/x86/kernel/microcode_amd_early.c
+++ b/arch/x86/kernel/microcode_amd_early.c
@@ -143,13 +143,17 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 			left  -= offset;
 		}
 
-		offset = data - (u8 *)ucode;
+		/* mark where the next microcode container file starts */
+		offset    = data - (u8 *)ucode;
 		*uoffset += offset;
 		*usize   -= offset;
+		ucode     = data;
 	}
 
-	if (!eq_id)
+	if (!eq_id) {
+		*usize = 0;
 		return;
+	}
 
 	/* find ucode and update if needed */
 
@@ -166,15 +170,21 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 		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) {
-				if (!(*new_rev))
-					*new_rev = mc->hdr.patch_id;
-				break;
+				rev = mc->hdr.patch_id;
+				*new_rev = rev;
 			}
 
 		offset  = header[1] + SECTION_HDR_SIZE;
 		data   += offset;
 		left   -= offset;
 	}
+
+	/* mark where this microcode container file ends */
+	offset  = *usize - (data - (u8 *)ucode);
+	*usize -= offset;
+
+	if (!(*new_rev))
+		*usize = 0;
 }
 
 void __init load_ucode_amd_bsp(void)
@@ -204,19 +214,20 @@ void __cpuinit load_ucode_amd_ap(void)
 	size_t *usize;
 	void *ucode;
 
-	mc = (struct microcode_amd *)__pa_nodebug(amd_bsp_mpb);
+	mc = (struct microcode_amd *)__pa(amd_bsp_mpb);
 	if (mc->hdr.patch_id && mc->hdr.processor_rev_id) {
 		__apply_microcode_amd(mc);
 		return;
 	}
 
-	initrd  = (unsigned long *)__pa_nodebug(&initrd_start);
-	uoffset = (unsigned long *)__pa_nodebug(&ucode_offset);
-	usize   = (size_t *)__pa_nodebug(&ucode_size);
-	if (!*usize)
+	initrd  = (unsigned long *)__pa(&initrd_start);
+	uoffset = (unsigned long *)__pa(&ucode_offset);
+	usize   = (size_t *)__pa(&ucode_size);
+
+	if (!*usize || !*initrd)
 		return;
 
-	ucode = (void *)((unsigned long)__pa_nodebug(*initrd) + *uoffset);
+	ucode = (void *)((unsigned long)__pa(*initrd) + *uoffset);
 	apply_ucode_in_initrd(ucode, *usize);
 }
 
@@ -250,7 +261,7 @@ void __cpuinit load_ucode_amd_ap(void)
 	if (cpu && !ucode_loaded) {
 		void *ucode;
 
-		if (!ucode_size)
+		if (!ucode_size || !initrd_start)
 			return;
 
 		ucode = (void *)(initrd_start + ucode_offset);
@@ -278,10 +289,7 @@ int __init save_microcode_in_initrd_amd(void)
 		pr_info("microcode: updated early to new patch_level=0x%08x\n",
 			ucode_new_rev);
 
-	if (ucode_loaded)
-		return 0;
-
-	if (!ucode_size)
+	if (ucode_loaded || !ucode_size || !initrd_start)
 		return 0;
 
 	ucode = (void *)(initrd_start + ucode_offset);
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH V3 0/2] x86/microcode/amd: early loading fixes
  2013-06-20 15:16     ` Jacob Shin
@ 2013-06-20 15:24       ` Jacob Shin
  2013-06-26 15:37         ` Jacob Shin
  2013-06-26 22:12         ` [tip:x86/microcode] x86, microcode, amd: Another early loading fixup tip-bot for Jacob Shin
  0 siblings, 2 replies; 9+ messages in thread
From: Jacob Shin @ 2013-06-20 15:24 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: H. Peter Anvin, Ingo Molnar, Thomas Gleixner, Yinghai Lu,
	Henrique de Moraes Holschuh, Borislav Petkov, Andreas Herrmann,
	x86, linux-kernel

On Thu, Jun 20, 2013 at 10:16:16AM -0500, Jacob Shin wrote:
> On Thu, Jun 20, 2013 at 12:30:53PM +0200, Ingo Molnar wrote:
> > 
> > * Jacob Shin <jacob.shin@amd.com> wrote:
> > 
> > > On Fri, Jun 07, 2013 at 09:22:18PM -0500, Jacob Shin wrote:
> > > > This patchset addreses two problems with early loading on AMD.
> > > > 
> > > > First, feedback from Yinghai that find_ucode_in_initrd() should be
> > > > marked __init:
> > > >   https://lkml.org/lkml/2013/6/4/695
> > > > 
> > > > And second, feedback from Henrique that Intel early loading supports
> > > > multiple microcode firmware concatenated together, whereas the current
> > > > AMD implementation lacks this support:
> > > >   https://lkml.org/lkml/2013/5/31/4
> > > > 
> > > > V3:
> > > > * style fix -- reduce multiple if statements into a single one
> > > 
> > > Hi hpa or Yinghai, just wondering if you had the chance to look at this
> > > V3 yet.
> > 
> > It appears Peter applied v2 to tip:x86/microcode two days before you sent 
> > v3 - please send any changes in v3 as delta patches.
> 
> I actually recieved the tip-bot email <https://lkml.org/lkml/2013/6/12/468>
> couple of days after sending out the above message, so I assumed that
> V3 was committed in.
> 
> I should have read the tip-bot message thoroughly and noticed
> it. Sorry about that. Here is the delta patch:

Sigh :-( .. sorry, forgot to sign off. Here it is again:

---8<---

>From 1445587da716b306f39feef46fb7150f292060c7 Mon Sep 17 00:00:00 2001
From: Jacob Shin <jacob.shin@amd.com>
Date: Thu, 20 Jun 2013 09:52:50 -0500
Subject: [PATCH] x86, microcode, amd: another early loading fixup

commit cd1c32ca969ebfd65e61312c988223bb14f09c2e is an early premature
rendition of the patch. Augment it with this delta patch to:
  * correctly mark offset and size of the matching bin file
  * use __pa instead of __pa_nodebug during AP load
  * check for !initrd_start before using it

Signed-off-by: Jacob Shin <jacob.shin@amd.com>
---
 arch/x86/kernel/microcode_amd_early.c |   40 ++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd_early.c b/arch/x86/kernel/microcode_amd_early.c
index 4c593c2..1ac6e9a 100644
--- a/arch/x86/kernel/microcode_amd_early.c
+++ b/arch/x86/kernel/microcode_amd_early.c
@@ -143,13 +143,17 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 			left  -= offset;
 		}
 
-		offset = data - (u8 *)ucode;
+		/* mark where the next microcode container file starts */
+		offset    = data - (u8 *)ucode;
 		*uoffset += offset;
 		*usize   -= offset;
+		ucode     = data;
 	}
 
-	if (!eq_id)
+	if (!eq_id) {
+		*usize = 0;
 		return;
+	}
 
 	/* find ucode and update if needed */
 
@@ -166,15 +170,21 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 		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) {
-				if (!(*new_rev))
-					*new_rev = mc->hdr.patch_id;
-				break;
+				rev = mc->hdr.patch_id;
+				*new_rev = rev;
 			}
 
 		offset  = header[1] + SECTION_HDR_SIZE;
 		data   += offset;
 		left   -= offset;
 	}
+
+	/* mark where this microcode container file ends */
+	offset  = *usize - (data - (u8 *)ucode);
+	*usize -= offset;
+
+	if (!(*new_rev))
+		*usize = 0;
 }
 
 void __init load_ucode_amd_bsp(void)
@@ -204,19 +214,20 @@ void __cpuinit load_ucode_amd_ap(void)
 	size_t *usize;
 	void *ucode;
 
-	mc = (struct microcode_amd *)__pa_nodebug(amd_bsp_mpb);
+	mc = (struct microcode_amd *)__pa(amd_bsp_mpb);
 	if (mc->hdr.patch_id && mc->hdr.processor_rev_id) {
 		__apply_microcode_amd(mc);
 		return;
 	}
 
-	initrd  = (unsigned long *)__pa_nodebug(&initrd_start);
-	uoffset = (unsigned long *)__pa_nodebug(&ucode_offset);
-	usize   = (size_t *)__pa_nodebug(&ucode_size);
-	if (!*usize)
+	initrd  = (unsigned long *)__pa(&initrd_start);
+	uoffset = (unsigned long *)__pa(&ucode_offset);
+	usize   = (size_t *)__pa(&ucode_size);
+
+	if (!*usize || !*initrd)
 		return;
 
-	ucode = (void *)((unsigned long)__pa_nodebug(*initrd) + *uoffset);
+	ucode = (void *)((unsigned long)__pa(*initrd) + *uoffset);
 	apply_ucode_in_initrd(ucode, *usize);
 }
 
@@ -250,7 +261,7 @@ void __cpuinit load_ucode_amd_ap(void)
 	if (cpu && !ucode_loaded) {
 		void *ucode;
 
-		if (!ucode_size)
+		if (!ucode_size || !initrd_start)
 			return;
 
 		ucode = (void *)(initrd_start + ucode_offset);
@@ -278,10 +289,7 @@ int __init save_microcode_in_initrd_amd(void)
 		pr_info("microcode: updated early to new patch_level=0x%08x\n",
 			ucode_new_rev);
 
-	if (ucode_loaded)
-		return 0;
-
-	if (!ucode_size)
+	if (ucode_loaded || !ucode_size || !initrd_start)
 		return 0;
 
 	ucode = (void *)(initrd_start + ucode_offset);
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH V3 0/2] x86/microcode/amd: early loading fixes
  2013-06-20 15:24       ` Jacob Shin
@ 2013-06-26 15:37         ` Jacob Shin
  2013-06-26 22:12         ` [tip:x86/microcode] x86, microcode, amd: Another early loading fixup tip-bot for Jacob Shin
  1 sibling, 0 replies; 9+ messages in thread
From: Jacob Shin @ 2013-06-26 15:37 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: H. Peter Anvin, Ingo Molnar, Thomas Gleixner, Yinghai Lu,
	Henrique de Moraes Holschuh, Borislav Petkov, Andreas Herrmann,
	x86, linux-kernel

On Thu, Jun 20, 2013 at 10:24:14AM -0500, Jacob Shin wrote:
> On Thu, Jun 20, 2013 at 10:16:16AM -0500, Jacob Shin wrote:
> > On Thu, Jun 20, 2013 at 12:30:53PM +0200, Ingo Molnar wrote:
> > > 
> > > * Jacob Shin <jacob.shin@amd.com> wrote:
> > > 
> > > > On Fri, Jun 07, 2013 at 09:22:18PM -0500, Jacob Shin wrote:
> > > > > This patchset addreses two problems with early loading on AMD.
> > > > > 
> > > > > First, feedback from Yinghai that find_ucode_in_initrd() should be
> > > > > marked __init:
> > > > >   https://lkml.org/lkml/2013/6/4/695
> > > > > 
> > > > > And second, feedback from Henrique that Intel early loading supports
> > > > > multiple microcode firmware concatenated together, whereas the current
> > > > > AMD implementation lacks this support:
> > > > >   https://lkml.org/lkml/2013/5/31/4
> > > > > 
> > > > > V3:
> > > > > * style fix -- reduce multiple if statements into a single one
> > > > 
> > > > Hi hpa or Yinghai, just wondering if you had the chance to look at this
> > > > V3 yet.
> > > 
> > > It appears Peter applied v2 to tip:x86/microcode two days before you sent 
> > > v3 - please send any changes in v3 as delta patches.
> > 
> > I actually recieved the tip-bot email <https://lkml.org/lkml/2013/6/12/468>
> > couple of days after sending out the above message, so I assumed that
> > V3 was committed in.
> > 
> > I should have read the tip-bot message thoroughly and noticed
> > it. Sorry about that. Here is the delta patch:
> 
> Sigh :-( .. sorry, forgot to sign off. Here it is again:
> 
> ---8<---
> 
> From 1445587da716b306f39feef46fb7150f292060c7 Mon Sep 17 00:00:00 2001
> From: Jacob Shin <jacob.shin@amd.com>
> Date: Thu, 20 Jun 2013 09:52:50 -0500
> Subject: [PATCH] x86, microcode, amd: another early loading fixup
> 
> commit cd1c32ca969ebfd65e61312c988223bb14f09c2e is an early premature
> rendition of the patch. Augment it with this delta patch to:
>   * correctly mark offset and size of the matching bin file
>   * use __pa instead of __pa_nodebug during AP load
>   * check for !initrd_start before using it
> 
> Signed-off-by: Jacob Shin <jacob.shin@amd.com>

Hi hpa, checking back to see if you had the chance to look at this
delta patch. It is needed to properly support concatenated microcode
binaries on AMD early load. (Intel already supports this).

Thank you,


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip:x86/microcode] x86, microcode, amd: Another early loading fixup
  2013-06-20 15:24       ` Jacob Shin
  2013-06-26 15:37         ` Jacob Shin
@ 2013-06-26 22:12         ` tip-bot for Jacob Shin
  1 sibling, 0 replies; 9+ messages in thread
From: tip-bot for Jacob Shin @ 2013-06-26 22:12 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, jacob.shin, tglx, hpa

Commit-ID:  9608d33b8210c993af4430d661a6474946480c9b
Gitweb:     http://git.kernel.org/tip/9608d33b8210c993af4430d661a6474946480c9b
Author:     Jacob Shin <jacob.shin@amd.com>
AuthorDate: Thu, 20 Jun 2013 09:52:50 -0500
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Wed, 26 Jun 2013 14:55:37 -0700

x86, microcode, amd: Another early loading fixup

commit cd1c32ca969ebfd65e61312c988223bb14f09c2e is an early premature
rendition of the patch. Augment it with this delta patch to:
  * correctly mark offset and size of the matching bin file
  * use __pa instead of __pa_nodebug during AP load
  * check for !initrd_start before using it

Signed-off-by: Jacob Shin <jacob.shin@amd.com>
Link: http://lkml.kernel.org/r/20130620152414.GA6676@jshin-Toonie
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/kernel/microcode_amd_early.c | 40 +++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd_early.c b/arch/x86/kernel/microcode_amd_early.c
index 4c593c2..1ac6e9a 100644
--- a/arch/x86/kernel/microcode_amd_early.c
+++ b/arch/x86/kernel/microcode_amd_early.c
@@ -143,13 +143,17 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 			left  -= offset;
 		}
 
-		offset = data - (u8 *)ucode;
+		/* mark where the next microcode container file starts */
+		offset    = data - (u8 *)ucode;
 		*uoffset += offset;
 		*usize   -= offset;
+		ucode     = data;
 	}
 
-	if (!eq_id)
+	if (!eq_id) {
+		*usize = 0;
 		return;
+	}
 
 	/* find ucode and update if needed */
 
@@ -166,15 +170,21 @@ static void __cpuinit apply_ucode_in_initrd(void *ucode, size_t size)
 		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) {
-				if (!(*new_rev))
-					*new_rev = mc->hdr.patch_id;
-				break;
+				rev = mc->hdr.patch_id;
+				*new_rev = rev;
 			}
 
 		offset  = header[1] + SECTION_HDR_SIZE;
 		data   += offset;
 		left   -= offset;
 	}
+
+	/* mark where this microcode container file ends */
+	offset  = *usize - (data - (u8 *)ucode);
+	*usize -= offset;
+
+	if (!(*new_rev))
+		*usize = 0;
 }
 
 void __init load_ucode_amd_bsp(void)
@@ -204,19 +214,20 @@ void __cpuinit load_ucode_amd_ap(void)
 	size_t *usize;
 	void *ucode;
 
-	mc = (struct microcode_amd *)__pa_nodebug(amd_bsp_mpb);
+	mc = (struct microcode_amd *)__pa(amd_bsp_mpb);
 	if (mc->hdr.patch_id && mc->hdr.processor_rev_id) {
 		__apply_microcode_amd(mc);
 		return;
 	}
 
-	initrd  = (unsigned long *)__pa_nodebug(&initrd_start);
-	uoffset = (unsigned long *)__pa_nodebug(&ucode_offset);
-	usize   = (size_t *)__pa_nodebug(&ucode_size);
-	if (!*usize)
+	initrd  = (unsigned long *)__pa(&initrd_start);
+	uoffset = (unsigned long *)__pa(&ucode_offset);
+	usize   = (size_t *)__pa(&ucode_size);
+
+	if (!*usize || !*initrd)
 		return;
 
-	ucode = (void *)((unsigned long)__pa_nodebug(*initrd) + *uoffset);
+	ucode = (void *)((unsigned long)__pa(*initrd) + *uoffset);
 	apply_ucode_in_initrd(ucode, *usize);
 }
 
@@ -250,7 +261,7 @@ void __cpuinit load_ucode_amd_ap(void)
 	if (cpu && !ucode_loaded) {
 		void *ucode;
 
-		if (!ucode_size)
+		if (!ucode_size || !initrd_start)
 			return;
 
 		ucode = (void *)(initrd_start + ucode_offset);
@@ -278,10 +289,7 @@ int __init save_microcode_in_initrd_amd(void)
 		pr_info("microcode: updated early to new patch_level=0x%08x\n",
 			ucode_new_rev);
 
-	if (ucode_loaded)
-		return 0;
-
-	if (!ucode_size)
+	if (ucode_loaded || !ucode_size || !initrd_start)
 		return 0;
 
 	ucode = (void *)(initrd_start + ucode_offset);

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-06-26 22:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-08  2:22 [PATCH V3 0/2] x86/microcode/amd: early loading fixes Jacob Shin
2013-06-08  2:22 ` [PATCH V3 1/2] x86/microcode/amd: make find_ucode_in_initrd() __init Jacob Shin
2013-06-08  2:22 ` [PATCH V3 2/2] x86/microcode/amd: allow multiple families' bin files appended together Jacob Shin
2013-06-12 19:31 ` [PATCH V3 0/2] x86/microcode/amd: early loading fixes Jacob Shin
2013-06-20 10:30   ` Ingo Molnar
2013-06-20 15:16     ` Jacob Shin
2013-06-20 15:24       ` Jacob Shin
2013-06-26 15:37         ` Jacob Shin
2013-06-26 22:12         ` [tip:x86/microcode] x86, microcode, amd: Another early loading fixup tip-bot for Jacob Shin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.