x86/microcode: Fixes for builtin vs initrd loading; cleanups
Subsystems (5)
Borislav Petkov
maintainercover x86/microcode: Fixes for builtin vs initrd loading; cleanups
From: Borislav Petkov <[email protected]>
Hi,
the first two are fixes resulting from people enabling builtin microcode and reporting issues. The result is a much more robust loading of early microcode by checking for builtin microcode first and then the one supplied by the initrd.
The rest are cleanups.
Pile has been tested on everything here and by the bug reporters.
@tip guys: 2/9 is CC:stable. Please route accordingly.
Please apply,
thanks.
Borislav Petkov (9):
x86/microcode: Fix loading precedence
x86/microcode: Fix suspend to RAM with builtin microcode lib/cpio: Make find_cpio_data()'s offset arg optional x86/microcode: Get rid of find_cpio_data()'s dummy offset arg x86/microcode: Propagate save_microcode_in_initrd() retval x86/microcode/intel: Rename load_microcode_early() to
find_microcode_patch()
x86/microcode/intel: Unexport save_mc_for_early() x86/microcode/AMD: Make amd_ucode_patch static Documentation/microcode: Document some aspects for more clarity
Documentation/x86/early-microcode.txt | 5 +- arch/x86/include/asm/microcode.h | 26 ---- arch/x86/include/asm/microcode_amd.h | 1 - arch/x86/include/asm/microcode_intel.h | 5 - arch/x86/kernel/cpu/microcode/amd.c | 33 ++--- arch/x86/kernel/cpu/microcode/core.c | 9 +- arch/x86/kernel/cpu/microcode/intel.c | 227 ++++++++++++++++++++------------- arch/x86/mm/init.c | 7 - lib/earlycpio.c | 5 +- 9 files changed, 169 insertions(+), 149 deletions(-)
Signature · 1 line
2.7.3
Borislav Petkov
maintainerPATCH 1/9 x86/microcode: Fix loading precedence
From: Borislav Petkov <[email protected]>
So it can happen that even with builtin microcode, CONFIG_BLK_DEV_INITRD=y gets forgotten enabled.
Or, even with that disabled, an initrd image gets supplied by the boot loader, by omission or is simply forgotten there. And since we do look at boot_params.hdr.ramdisk_* to know whether we have received an initrd, we might get puzzled.
So let's just make the loader look for builtin microcode first and if found, ignore the ramdisk image.
If no builtin found, it falls back to scanning the supplied initrd, of course.
For that, we move all the initrd scanning in a separate __scan_microcode_initrd() function and fall back to it only if load_builtin_intel_microcode() has failed.
--- arch/x86/include/asm/microcode.h | 24 ----- arch/x86/kernel/cpu/microcode/amd.c | 28 +++--- arch/x86/kernel/cpu/microcode/intel.c | 183 ++++++++++++++++++++++------------ 3 files changed, 133 insertions(+), 102 deletions(-)
arch/x86/include/asm/microcode.h +0 -24
@@ -145,28 +145,4 @@ static inline bool get_builtin_firmware(struct cpio_data *cd, const char *name) { return false; }#endif -static inline unsigned long get_initrd_start (void ) -{ -#ifdef CONFIG_BLK_DEV_INITRD -return initrd_start; -#else -return 0 ; -#endif -} - -static inline unsigned long get_initrd_start_addr (void ) -{ -#ifdef CONFIG_BLK_DEV_INITRD -#ifdef CONFIG_X86_32 -unsigned long *initrd_start_p = (unsigned long *)__pa_nodebug (&initrd_start); - -return (unsigned long )__pa_nodebug (*initrd_start_p); -#else -return get_initrd_start (); -#endif -#else /* CONFIG_BLK_DEV_INITRD */ -return 0 ; -#endif -} -#endif /* _ASM_X86_MICROCODE_H */
arch/x86/kernel/cpu/microcode/amd.c +16 -12
@@ -61,19 +61,20 @@ static u16 this_equiv_id;static struct cpio_data ucode_cpio; -/* -* Microcode patch container file is prepended to the initrd in cpio format. -* See Documentation/x86/early-microcode.txt -*/ -static __initdata char ucode_path[] ="kernel/x86/microcode/AuthenticAMD.bin" ; -static struct cpio_data __init find_ucode_in_initrd (void ) { +#ifdef CONFIG_BLK_DEV_INITRD long offset =0 ;char *path;void *start;size_t size; +/* +* Microcode patch container file is prepended to the initrd in cpio +* format. See Documentation/x86/early-microcode.txt +*/ +static __initdata char ucode_path[] ="kernel/x86/microcode/AuthenticAMD.bin" ; +#ifdef CONFIG_X86_32 struct boot_params *p;
@@ -89,9 +90,12 @@ static struct cpio_data __init find_ucode_in_initrd(void) path = ucode_path; start = (void *)(boot_params.hdr.ramdisk_image +PAGE_OFFSET ); size = boot_params.hdr.ramdisk_size; -#endif +#endif /* !CONFIG_X86_32 */ return find_cpio_data (path, start, size, &offset); +#else +return (struct cpio_data ){NULL ,0 ,"" }; +#endif }static size_t compute_container_size (u8 *data,u32 total_size)
@@ -289,11 +293,11 @@ void __init load_ucode_amd_bsp(unsigned int family) size = &ucode_cpio.size;#endif - cp =find_ucode_in_initrd (); -if (!cp.data) { -if (!load_builtin_amd_microcode (&cp, family)) -return ; - } +if (!load_builtin_amd_microcode (&cp, family)) + cp =find_ucode_in_initrd (); + +if (!(cp.data && cp.size)) +return ; *data = cp.data; *size = cp.size;
arch/x86/kernel/cpu/microcode/intel.c +117 -66
248 lines not on this page · raw message
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode: Fix loading precedence
x86/microcode: Fix loading precedence
Commit-ID: 6c5456474e7f0b63be66d44b0595001e2a8b44d5 Gitweb: http://git.kernel.org/tip/6c5456474e7f0b63be66d44b0595001e2a8b44d5 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:42 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:19 +0200
x86/microcode: Fix loading precedence
So it can happen that even with builtin microcode, CONFIG_BLK_DEV_INITRD=y gets forgotten enabled.
Or, even with that disabled, an initrd image gets supplied by the boot loader, by omission or is simply forgotten there. And since we do look at boot_params.hdr.ramdisk_* to know whether we have received an initrd, we might get puzzled.
So let's just make the loader look for builtin microcode first and if found, ignore the ramdisk image.
If no builtin found, it falls back to scanning the supplied initrd, of course.
For that, we move all the initrd scanning in a separate __scan_microcode_initrd() function and fall back to it only if load_builtin_intel_microcode() has failed.
--- arch/x86/include/asm/microcode.h | 24 ----- arch/x86/kernel/cpu/microcode/amd.c | 28 +++--- arch/x86/kernel/cpu/microcode/intel.c | 183 ++++++++++++++++++++++------------ 3 files changed, 133 insertions(+), 102 deletions(-)
arch/x86/include/asm/microcode.h +0 -24
@@ -145,28 +145,4 @@ static inline bool get_builtin_firmware(struct cpio_data *cd, const char *name) { return false; }#endif -static inline unsigned long get_initrd_start (void ) -{ -#ifdef CONFIG_BLK_DEV_INITRD -return initrd_start; -#else -return 0 ; -#endif -} - -static inline unsigned long get_initrd_start_addr (void ) -{ -#ifdef CONFIG_BLK_DEV_INITRD -#ifdef CONFIG_X86_32 -unsigned long *initrd_start_p = (unsigned long *)__pa_nodebug (&initrd_start); - -return (unsigned long )__pa_nodebug (*initrd_start_p); -#else -return get_initrd_start (); -#endif -#else /* CONFIG_BLK_DEV_INITRD */ -return 0 ; -#endif -} -#endif /* _ASM_X86_MICROCODE_H */
arch/x86/kernel/cpu/microcode/amd.c +16 -12
@@ -61,19 +61,20 @@ static u16 this_equiv_id;static struct cpio_data ucode_cpio; -/* -* Microcode patch container file is prepended to the initrd in cpio format. -* See Documentation/x86/early-microcode.txt -*/ -static __initdata char ucode_path[] ="kernel/x86/microcode/AuthenticAMD.bin" ; -static struct cpio_data __init find_ucode_in_initrd (void ) { +#ifdef CONFIG_BLK_DEV_INITRD long offset =0 ;char *path;void *start;size_t size; +/* +* Microcode patch container file is prepended to the initrd in cpio +* format. See Documentation/x86/early-microcode.txt +*/ +static __initdata char ucode_path[] ="kernel/x86/microcode/AuthenticAMD.bin" ; +#ifdef CONFIG_X86_32 struct boot_params *p;
@@ -89,9 +90,12 @@ static struct cpio_data __init find_ucode_in_initrd(void) path = ucode_path; start = (void *)(boot_params.hdr.ramdisk_image +PAGE_OFFSET ); size = boot_params.hdr.ramdisk_size; -#endif +#endif /* !CONFIG_X86_32 */ return find_cpio_data (path, start, size, &offset); +#else +return (struct cpio_data ){NULL ,0 ,"" }; +#endif }static size_t compute_container_size (u8 *data,u32 total_size)
@@ -289,11 +293,11 @@ void __init load_ucode_amd_bsp(unsigned int family) size = &ucode_cpio.size;#endif - cp =find_ucode_in_initrd (); -if (!cp.data) { -if (!load_builtin_amd_microcode (&cp, family)) -return ; - } +if (!load_builtin_amd_microcode (&cp, family)) + cp =find_ucode_in_initrd (); + +if (!(cp.data && cp.size)) +return ; *data = cp.data; *size = cp.size;
arch/x86/kernel/cpu/microcode/intel.c +117 -66
248 lines not on this page · raw message
Borislav Petkov
maintainerPATCH 2/9 x86/microcode: Fix suspend to RAM with builtin microcode
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Usually, after we have found the proper microcode blob for the current machine, we stash it away for later use with save_microcode_in_initrd().
However, with builtin microcode which doesn't come from the initrd, we don't call that function because CONFIG_BLK_DEV_INITRD=n and even if set, we don't have a valid initrd.
In order to fix this, let's make save_microcode_in_initrd() an fs_initcall which runs before rootfs_initcall() as this was the time it was called previously through:
rootfs_initcall(populate_rootfs)
|-> free_initrd()
|-> free_initrd_mem()
|-> save_microcode_in_initrd()Also, we make it run independently from initrd functionality being present or not.
And since it is called in the microcode loader only now, we can also make it static.
--- arch/x86/include/asm/microcode.h | 2 -- arch/x86/kernel/cpu/microcode/core.c | 3 ++- arch/x86/mm/init.c | 7 ------- 3 files changed, 2 insertions(+), 10 deletions(-)
arch/x86/include/asm/microcode.h +0 -2
@@ -133,13 +133,11 @@ static inline unsigned int x86_cpuid_family(void)#ifdef CONFIG_MICROCODE extern void __init load_ucode_bsp (void );extern void load_ucode_ap (void ); -extern int __init save_microcode_in_initrd (void );void reload_early_microcode (void );extern bool get_builtin_firmware (struct cpio_data *cd,const char *name);#else static inline void __init load_ucode_bsp (void ) { }static inline void load_ucode_ap (void ) { } -static inline int __init save_microcode_in_initrd (void ) {return 0 ; }static inline void reload_early_microcode (void ) { }static inline bool get_builtin_firmware (struct cpio_data *cd,const char *name) {return false; }
arch/x86/kernel/cpu/microcode/core.c +2 -1
@@ -175,7 +175,7 @@ void load_ucode_ap(void) } } -int __init save_microcode_in_initrd (void ) +static int __init save_microcode_in_initrd (void ) {struct cpuinfo_x86 *c = &boot_cpu_data;
@@ -691,4 +691,5 @@ int __init microcode_init(void)return error; } +fs_initcall (save_microcode_in_initrd);late_initcall (microcode_init);
arch/x86/mm/init.c +0 -7
@@ -696,13 +696,6 @@ void free_initmem(void)void __init free_initrd_mem (unsigned long start,unsigned long end) {/* -* Remember, initrd memory may contain microcode or other useful things. -* Before we lose initrd mem, we need to find a place to hold them -* now that normal virtual memory is enabled. -*/ -save_microcode_in_initrd (); - -/* * end could be not aligned, and We can not align that, * decompresser could be confused by aligned initrd_end * We already reserve the end partial page before in
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode: Fix suspend to RAM with builtin microcode
x86/microcode: Fix suspend to RAM with builtin microcode
Commit-ID: 4b703305d98bf7350d4b2953ee39a3aa2eeb1778 Gitweb: http://git.kernel.org/tip/4b703305d98bf7350d4b2953ee39a3aa2eeb1778 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:43 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:19 +0200
x86/microcode: Fix suspend to RAM with builtin microcode
Usually, after we have found the proper microcode blob for the current machine, we stash it away for later use with save_microcode_in_initrd().
However, with builtin microcode which doesn't come from the initrd, we don't call that function because CONFIG_BLK_DEV_INITRD=n and even if set, we don't have a valid initrd.
In order to fix this, let's make save_microcode_in_initrd() an fs_initcall which runs before rootfs_initcall() as this was the time it was called previously through:
rootfs_initcall(populate_rootfs)
|-> free_initrd()
|-> free_initrd_mem()
|-> save_microcode_in_initrd()Also, we make it run independently from initrd functionality being present or not.
And since it is called in the microcode loader only now, we can also make it static.
--- arch/x86/include/asm/microcode.h | 2 -- arch/x86/kernel/cpu/microcode/core.c | 3 ++- arch/x86/mm/init.c | 7 ------- 3 files changed, 2 insertions(+), 10 deletions(-)
arch/x86/include/asm/microcode.h +0 -2
@@ -133,13 +133,11 @@ static inline unsigned int x86_cpuid_family(void)#ifdef CONFIG_MICROCODE extern void __init load_ucode_bsp (void );extern void load_ucode_ap (void ); -extern int __init save_microcode_in_initrd (void );void reload_early_microcode (void );extern bool get_builtin_firmware (struct cpio_data *cd,const char *name);#else static inline void __init load_ucode_bsp (void ) { }static inline void load_ucode_ap (void ) { } -static inline int __init save_microcode_in_initrd (void ) {return 0 ; }static inline void reload_early_microcode (void ) { }static inline bool get_builtin_firmware (struct cpio_data *cd,const char *name) {return false; }
arch/x86/kernel/cpu/microcode/core.c +2 -1
@@ -175,7 +175,7 @@ void load_ucode_ap(void) } } -int __init save_microcode_in_initrd (void ) +static int __init save_microcode_in_initrd (void ) {struct cpuinfo_x86 *c = &boot_cpu_data;
@@ -691,4 +691,5 @@ int __init microcode_init(void)return error; } +fs_initcall (save_microcode_in_initrd);late_initcall (microcode_init);
arch/x86/mm/init.c +0 -7
@@ -696,13 +696,6 @@ void free_initmem(void)void __init free_initrd_mem (unsigned long start,unsigned long end) {/* -* Remember, initrd memory may contain microcode or other useful things. -* Before we lose initrd mem, we need to find a place to hold them -* now that normal virtual memory is enabled. -*/ -save_microcode_in_initrd (); - -/* * end could be not aligned, and We can not align that, * decompresser could be confused by aligned initrd_end * We already reserve the end partial page before in
Borislav Petkov
maintainerPATCH 3/9 lib/cpio: Make find_cpio_data()'s offset arg optional
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Some callers don't use it so make it optional.
--- lib/earlycpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/earlycpio.c +4 -1
@@ -125,7 +125,10 @@ struct cpio_data find_cpio_data(const char *path, void *data,if ((ch[C_MODE ] &0170000 ) ==0100000 && ch[C_NAMESIZE ] >= mypathsize && !memcmp (p, path, mypathsize)) { - *nextoff = (long )nptr - (long )data; + +if (nextoff) + *nextoff = (long )nptr - (long )data; +if (ch[C_NAMESIZE ] - mypathsize >=MAX_CPIO_FILE_NAME ) { pr_warn( "File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] lib/cpio: Make find_cpio_data()'s offset arg optional
lib/cpio: Make find_cpio_data()'s offset arg optional
Commit-ID: 7557933e6b99d381c19b196901ed537b00f6d121 Gitweb: http://git.kernel.org/tip/7557933e6b99d381c19b196901ed537b00f6d121 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:44 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:19 +0200
lib/cpio: Make find_cpio_data()'s offset arg optional
Some callers don't use it so make it optional.
--- lib/earlycpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/earlycpio.c +4 -1
@@ -125,7 +125,10 @@ struct cpio_data find_cpio_data(const char *path, void *data,if ((ch[C_MODE ] &0170000 ) ==0100000 && ch[C_NAMESIZE ] >= mypathsize && !memcmp (p, path, mypathsize)) { - *nextoff = (long )nptr - (long )data; + +if (nextoff) + *nextoff = (long )nptr - (long )data; +if (ch[C_NAMESIZE ] - mypathsize >=MAX_CPIO_FILE_NAME ) { pr_warn( "File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
Borislav Petkov
maintainerPATCH 4/9 x86/microcode: Get rid of find_cpio_data()'s dummy offset arg
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
The microcode loader doesn't use it and now that that arg has been made optional in find_cpio_data(), get rid of it here.
No functionality change.
--- arch/x86/kernel/cpu/microcode/amd.c | 3 +-- arch/x86/kernel/cpu/microcode/intel.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -2
@@ -64,7 +64,6 @@ static struct cpio_data ucode_cpio;static struct cpio_data __init find_ucode_in_initrd (void ) {#ifdef CONFIG_BLK_DEV_INITRD -long offset =0 ;char *path;void *start;size_t size;
@@ -92,7 +91,7 @@ static struct cpio_data __init find_ucode_in_initrd(void) size = boot_params.hdr.ramdisk_size;#endif /* !CONFIG_X86_32 */ -return find_cpio_data (path, start, size, &offset); +return find_cpio_data (path, start, size,NULL );#else return (struct cpio_data ){NULL ,0 ,"" };#endif
arch/x86/kernel/cpu/microcode/intel.c +1 -2
@@ -685,7 +685,6 @@ static __init enum ucode_state __scan_microcode_initrd(struct cpio_data *cd, struct ucode_blobs *blbp) { #ifdef CONFIG_BLK_DEV_INITRD - long offset = 0; static __initdata char ucode_name[] = "kernel/x86/microcode/GenuineIntel.bin";char *p =IS_ENABLED (CONFIG_X86_32 ) ? (char *)__pa_nodebug (ucode_name) : ucode_name;
@@ -716,7 +715,7 @@ __scan_microcode_initrd(struct cpio_data *cd, struct ucode_blobs *blbp) }# endif - *cd =find_cpio_data (p, (void *)start, size, &offset); + *cd =find_cpio_data (p, (void *)start, size,NULL );if (cd->data) { blbp->start = start; blbp->valid = true;
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode: Get rid of find_cpio_data()'s dummy offset arg
x86/microcode: Get rid of find_cpio_data()'s dummy offset arg
Commit-ID: 852ad5b94524fd76d49944b9db0a93f7c9ee5814 Gitweb: http://git.kernel.org/tip/852ad5b94524fd76d49944b9db0a93f7c9ee5814 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:45 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:19 +0200
x86/microcode: Get rid of find_cpio_data()'s dummy offset arg
The microcode loader doesn't use it and now that that arg has been made optional in find_cpio_data(), get rid of it here.
No functionality change.
--- arch/x86/kernel/cpu/microcode/amd.c | 3 +-- arch/x86/kernel/cpu/microcode/intel.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -2
@@ -64,7 +64,6 @@ static struct cpio_data ucode_cpio;static struct cpio_data __init find_ucode_in_initrd (void ) {#ifdef CONFIG_BLK_DEV_INITRD -long offset =0 ;char *path;void *start;size_t size;
@@ -92,7 +91,7 @@ static struct cpio_data __init find_ucode_in_initrd(void) size = boot_params.hdr.ramdisk_size;#endif /* !CONFIG_X86_32 */ -return find_cpio_data (path, start, size, &offset); +return find_cpio_data (path, start, size,NULL );#else return (struct cpio_data ){NULL ,0 ,"" };#endif
arch/x86/kernel/cpu/microcode/intel.c +1 -2
@@ -685,7 +685,6 @@ static __init enum ucode_state __scan_microcode_initrd(struct cpio_data *cd, struct ucode_blobs *blbp) { #ifdef CONFIG_BLK_DEV_INITRD - long offset = 0; static __initdata char ucode_name[] = "kernel/x86/microcode/GenuineIntel.bin";char *p =IS_ENABLED (CONFIG_X86_32 ) ? (char *)__pa_nodebug (ucode_name) : ucode_name;
@@ -716,7 +715,7 @@ __scan_microcode_initrd(struct cpio_data *cd, struct ucode_blobs *blbp) }# endif - *cd =find_cpio_data (p, (void *)start, size, &offset); + *cd =find_cpio_data (p, (void *)start, size,NULL );if (cd->data) { blbp->start = start; blbp->valid = true;
Borislav Petkov
maintainerPATCH 5/9 x86/microcode: Propagate save_microcode_in_initrd() retval
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Will be used in a later patch. No functionality change.
--- arch/x86/kernel/cpu/microcode/core.c | 6 +++--- arch/x86/kernel/cpu/microcode/intel.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +3 -3
@@ -182,17 +182,17 @@ static int __init save_microcode_in_initrd(void)switch (c->x86_vendor) {case X86_VENDOR_INTEL :if (c->x86 >=6 ) -save_microcode_in_initrd_intel (); +return save_microcode_in_initrd_intel ();break ;case X86_VENDOR_AMD :if (c->x86 >=0x10 ) -save_microcode_in_initrd_amd (); +return save_microcode_in_initrd_amd ();break ;default :break ; } -return 0 ; +return -EINVAL ; }void reload_early_microcode (void )
arch/x86/kernel/cpu/microcode/intel.c +2 -2
@@ -675,8 +675,8 @@ int __init save_microcode_in_initrd_intel(void) ret =save_microcode (&mc_saved_data, mc_saved, count);if (ret)pr_err ("Cannot save microcode patches from initrd.\n" ); - -show_saved_mc (); +else +show_saved_mc ();return ret; }
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode: Propagate save_microcode_in_initrd() retval
x86/microcode: Propagate save_microcode_in_initrd() retval
Commit-ID: fa6788b8c681ffe0a1bf9f99dddc2c447069241c Gitweb: http://git.kernel.org/tip/fa6788b8c681ffe0a1bf9f99dddc2c447069241c Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:46 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:20 +0200
x86/microcode: Propagate save_microcode_in_initrd() retval
Will be used in a later patch. No functionality change.
--- arch/x86/kernel/cpu/microcode/core.c | 6 +++--- arch/x86/kernel/cpu/microcode/intel.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +3 -3
@@ -182,17 +182,17 @@ static int __init save_microcode_in_initrd(void)switch (c->x86_vendor) {case X86_VENDOR_INTEL :if (c->x86 >=6 ) -save_microcode_in_initrd_intel (); +return save_microcode_in_initrd_intel ();break ;case X86_VENDOR_AMD :if (c->x86 >=0x10 ) -save_microcode_in_initrd_amd (); +return save_microcode_in_initrd_amd ();break ;default :break ; } -return 0 ; +return -EINVAL ; }void reload_early_microcode (void )
arch/x86/kernel/cpu/microcode/intel.c +2 -2
@@ -675,8 +675,8 @@ int __init save_microcode_in_initrd_intel(void) ret =save_microcode (&mc_saved_data, mc_saved, count);if (ret)pr_err ("Cannot save microcode patches from initrd.\n" ); - -show_saved_mc (); +else +show_saved_mc ();return ret; }
Borislav Petkov
maintainerPATCH 6/9 x86/microcode/intel: Rename load_microcode_early() to find_microcode_patch()
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
This function does exactly that: it goes through the previously saved array of microcode blobs and finds the proper one for the current CPU. Rename it accordingly.
No functionality change.
--- arch/x86/kernel/cpu/microcode/intel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +5 -5
@@ -58,7 +58,7 @@ static struct ucode_blobs { } blobs;static enum ucode_state -load_microcode_early (struct microcode_intel **saved, +find_microcode_patch (struct microcode_intel **saved,unsigned int num_saved,struct ucode_cpu_info *uci) {struct microcode_intel *ucode_ptr, *new_mc =NULL ;
@@ -127,13 +127,13 @@ load_microcode(struct mc_saved_data *mcs, unsigned long *mc_ptrs,if (!mcs->mc_saved) {copy_ptrs (mc_saved_tmp, mc_ptrs, offset, count); -return load_microcode_early (mc_saved_tmp, count, uci); +return find_microcode_patch (mc_saved_tmp, count, uci); }else {#ifdef CONFIG_X86_32 microcode_phys (mc_saved_tmp, mcs); -return load_microcode_early (mc_saved_tmp, count, uci); +return find_microcode_patch (mc_saved_tmp, count, uci);#else -return load_microcode_early (mcs->mc_saved, count, uci); +return find_microcode_patch (mcs->mc_saved, count, uci);#endif } }
@@ -834,7 +834,7 @@ void reload_ucode_intel(void)collect_cpu_info_early (&uci); - ret =load_microcode_early (mc_saved_data.mc_saved, + ret =find_microcode_patch (mc_saved_data.mc_saved, mc_saved_data.num_saved, &uci);if (ret !=UCODE_OK )return ;
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode/intel: Rename load_microcode_early() to find_microcode_patch()
x86/microcode/intel: Rename load_microcode_early() to find_microcode_patch()
Commit-ID: 9198251af1554c21fae8e43a940a8bed435ee1b3 Gitweb: http://git.kernel.org/tip/9198251af1554c21fae8e43a940a8bed435ee1b3 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:47 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:20 +0200
x86/microcode/intel: Rename load_microcode_early() to find_microcode_patch()
This function does exactly that: it goes through the previously saved array of microcode blobs and finds the proper one for the current CPU. Rename it accordingly.
No functionality change.
--- arch/x86/kernel/cpu/microcode/intel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +5 -5
@@ -58,7 +58,7 @@ static struct ucode_blobs { } blobs;static enum ucode_state -load_microcode_early (struct microcode_intel **saved, +find_microcode_patch (struct microcode_intel **saved,unsigned int num_saved,struct ucode_cpu_info *uci) {struct microcode_intel *ucode_ptr, *new_mc =NULL ;
@@ -127,13 +127,13 @@ load_microcode(struct mc_saved_data *mcs, unsigned long *mc_ptrs,if (!mcs->mc_saved) {copy_ptrs (mc_saved_tmp, mc_ptrs, offset, count); -return load_microcode_early (mc_saved_tmp, count, uci); +return find_microcode_patch (mc_saved_tmp, count, uci); }else {#ifdef CONFIG_X86_32 microcode_phys (mc_saved_tmp, mcs); -return load_microcode_early (mc_saved_tmp, count, uci); +return find_microcode_patch (mc_saved_tmp, count, uci);#else -return load_microcode_early (mcs->mc_saved, count, uci); +return find_microcode_patch (mcs->mc_saved, count, uci);#endif } }
@@ -834,7 +834,7 @@ void reload_ucode_intel(void)collect_cpu_info_early (&uci); - ret =load_microcode_early (mc_saved_data.mc_saved, + ret =find_microcode_patch (mc_saved_data.mc_saved, mc_saved_data.num_saved, &uci);if (ret !=UCODE_OK )return ;
Borislav Petkov
maintainerPATCH 7/9 x86/microcode/intel: Unexport save_mc_for_early()
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
It is used only in intel.c, drop the CONFIG_HOTPLUG_CPU ifdeffery from the header and turn it into a void function because its return value wasn't being used anyway.
No functionality change.
--- arch/x86/include/asm/microcode_intel.h | 5 ----- arch/x86/kernel/cpu/microcode/intel.c | 15 ++++++--------- 2 files changed, 6 insertions(+), 14 deletions(-)
arch/x86/include/asm/microcode_intel.h +0 -5
@@ -70,9 +70,4 @@ static inline int __init save_microcode_in_initrd_intel(void) { return -EINVAL;static inline void reload_ucode_intel (void ) {}#endif -#ifdef CONFIG_HOTPLUG_CPU -extern int save_mc_for_early (u8 *mc); -#else -static inline int save_mc_for_early (u8 *mc) {return 0 ; } -#endif #endif /* _ASM_X86_MICROCODE_INTEL_H */
arch/x86/kernel/cpu/microcode/intel.c +6 -9
@@ -456,8 +456,6 @@ static void show_saved_mc(void)#endif } -#ifdef CONFIG_HOTPLUG_CPU -static DEFINE_MUTEX (x86_cpu_microcode_mutex);/* * Save this mc into mc_saved_data. So it will be loaded early when a CPU is * hot added or resumes.
@@ -465,14 +463,16 @@ static DEFINE_MUTEX(x86_cpu_microcode_mutex);* Please make sure this mc should be a valid microcode patch before calling * this function. */ -int save_mc_for_early (u8 *mc) +static void save_mc_for_early (u8 *mc) { +#ifdef CONFIG_HOTPLUG_CPU +static DEFINE_MUTEX (x86_cpu_microcode_mutex); +struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT ];unsigned int mc_saved_count_init;unsigned int num_saved;struct microcode_intel **mc_saved; -int ret =0 ; -int i; +int ret, i;/* * Hold hotplug lock so mc_saved_data is not accessed by a CPU in
@@ -515,11 +515,8 @@ int save_mc_for_early(u8 *mc) out:mutex_unlock (&x86_cpu_microcode_mutex); - - return ret; -} -EXPORT_SYMBOL_GPL (save_mc_for_early);#endif +}static bool __init load_builtin_intel_microcode (struct cpio_data *cp) {
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode/intel: Unexport save_mc_for_early()
x86/microcode/intel: Unexport save_mc_for_early()
Commit-ID: 0c5fa827f1130d05858f158022c21e9e7e5cff92 Gitweb: http://git.kernel.org/tip/0c5fa827f1130d05858f158022c21e9e7e5cff92 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:48 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:20 +0200
x86/microcode/intel: Unexport save_mc_for_early()
It is used only in intel.c, drop the CONFIG_HOTPLUG_CPU ifdeffery from the header and turn it into a void function because its return value wasn't being used anyway.
No functionality change.
--- arch/x86/include/asm/microcode_intel.h | 5 ----- arch/x86/kernel/cpu/microcode/intel.c | 15 ++++++--------- 2 files changed, 6 insertions(+), 14 deletions(-)
arch/x86/include/asm/microcode_intel.h +0 -5
@@ -70,9 +70,4 @@ static inline int __init save_microcode_in_initrd_intel(void) { return -EINVAL;static inline void reload_ucode_intel (void ) {}#endif -#ifdef CONFIG_HOTPLUG_CPU -extern int save_mc_for_early (u8 *mc); -#else -static inline int save_mc_for_early (u8 *mc) {return 0 ; } -#endif #endif /* _ASM_X86_MICROCODE_INTEL_H */
arch/x86/kernel/cpu/microcode/intel.c +6 -9
@@ -456,8 +456,6 @@ static void show_saved_mc(void)#endif } -#ifdef CONFIG_HOTPLUG_CPU -static DEFINE_MUTEX (x86_cpu_microcode_mutex);/* * Save this mc into mc_saved_data. So it will be loaded early when a CPU is * hot added or resumes.
@@ -465,14 +463,16 @@ static DEFINE_MUTEX(x86_cpu_microcode_mutex);* Please make sure this mc should be a valid microcode patch before calling * this function. */ -int save_mc_for_early (u8 *mc) +static void save_mc_for_early (u8 *mc) { +#ifdef CONFIG_HOTPLUG_CPU +static DEFINE_MUTEX (x86_cpu_microcode_mutex); +struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT ];unsigned int mc_saved_count_init;unsigned int num_saved;struct microcode_intel **mc_saved; -int ret =0 ; -int i; +int ret, i;/* * Hold hotplug lock so mc_saved_data is not accessed by a CPU in
@@ -515,11 +515,8 @@ int save_mc_for_early(u8 *mc) out:mutex_unlock (&x86_cpu_microcode_mutex); - - return ret; -} -EXPORT_SYMBOL_GPL (save_mc_for_early);#endif +}static bool __init load_builtin_intel_microcode (struct cpio_data *cp) {
Borislav Petkov
maintainerPATCH 8/9 x86/microcode/AMD: Make amd_ucode_patch static
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
It is used only in amd.c now.
No functionality change.
--- arch/x86/include/asm/microcode_amd.h | 1 - arch/x86/kernel/cpu/microcode/amd.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
arch/x86/include/asm/microcode_amd.h +0 -1
@@ -62,7 +62,6 @@ extern int apply_microcode_amd(int cpu);extern enum ucode_state load_microcode_amd (int cpu,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 extern void __init load_ucode_amd_bsp (unsigned int family);
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -56,7 +56,7 @@ static u8 *container;static size_t container_size;static u32 ucode_new_rev; -u8 amd_ucode_patch[PATCH_MAX_SIZE ]; +static u8 amd_ucode_patch[PATCH_MAX_SIZE ];static u16 this_equiv_id;static struct cpio_data ucode_cpio;
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode/AMD: Make amd_ucode_patch[] static
x86/microcode/AMD: Make amd_ucode_patch[] static
Commit-ID: a13004a2449c56a83d5816e81d850ea92b6837c2 Gitweb: http://git.kernel.org/tip/a13004a2449c56a83d5816e81d850ea92b6837c2 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:49 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:20 +0200
x86/microcode/AMD: Make amd_ucode_patch[] static
It is used only in amd.c now.
No functionality change.
--- arch/x86/include/asm/microcode_amd.h | 1 - arch/x86/kernel/cpu/microcode/amd.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
arch/x86/include/asm/microcode_amd.h +0 -1
@@ -62,7 +62,6 @@ extern int apply_microcode_amd(int cpu);extern enum ucode_state load_microcode_amd (int cpu,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 extern void __init load_ucode_amd_bsp (unsigned int family);
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -56,7 +56,7 @@ static u8 *container;static size_t container_size;static u32 ucode_new_rev; -u8 amd_ucode_patch[PATCH_MAX_SIZE ]; +static u8 amd_ucode_patch[PATCH_MAX_SIZE ];static u16 this_equiv_id;static struct cpio_data ucode_cpio;
Borislav Petkov
maintainerPATCH 9/9 Documentation/microcode: Document some aspects for more clarity
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Document that builtin microcode is 64-bit only. Also, improve/add comments to places.
--- Documentation/x86/early-microcode.txt | 5 ++++- arch/x86/kernel/cpu/microcode/intel.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-)
Documentation/x86/early-microcode.txt +4 -1
@@ -45,7 +45,10 @@ Builtin microcode ================= We can also load builtin microcode supplied through the regular firmware -builtin method CONFIG_FIRMWARE_IN_KERNEL. Here's an example: +builtin method CONFIG_FIRMWARE_IN_KERNEL. Only 64-bit is currently +supported. + +Here's an example: CONFIG_FIRMWARE_IN_KERNEL=y CONFIG_EXTRA_FIRMWARE="intel-ucode/06-3a-09 amd-ucode/microcode_amd_fam15h.bin"
arch/x86/kernel/cpu/microcode/intel.c +9 -7
@@ -40,9 +40,13 @@#include <asm/msr.h> /* -* Temporary microcode blobs pointers storage. We note here the pointers to -* microcode blobs we've got from whatever storage (detached initrd, builtin). -* Later on, we put those into final storage mc_saved_data.mc_saved. +* Temporary microcode blobs pointers storage. We note here during early load +* the pointers to microcode blobs we've got from whatever storage (detached +* initrd, builtin). Later on, we put those into final storage +* mc_saved_data.mc_saved. +* +* Important: those are offsets from the beginning of initrd or absolute +* addresses within the kernel image when built-in. */ static unsigned long mc_tmp_ptrs[MAX_UCODE_COUNT ];
@@ -57,6 +61,7 @@ static struct ucode_blobs {bool valid; } blobs; +/* Go through saved patches and find the one suitable for the current CPU. */ static enum ucode_state find_microcode_patch (struct microcode_intel **saved,unsigned int num_saved,struct ucode_cpu_info *uci)
@@ -466,6 +471,7 @@ static void show_saved_mc(void)static void save_mc_for_early (u8 *mc) {#ifdef CONFIG_HOTPLUG_CPU +/* Synchronization during CPU hotplug. */ static DEFINE_MUTEX (x86_cpu_microcode_mutex);struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT ];
@@ -474,10 +480,6 @@ static void save_mc_for_early(u8 *mc)struct microcode_intel **mc_saved;int ret, i; -/* -* Hold hotplug lock so mc_saved_data is not accessed by a CPU in -* hotplug. -*/ mutex_lock (&x86_cpu_microcode_mutex); mc_saved_count_init = mc_saved_data.num_saved;
Signature · 1 line
2.7.3
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] Documentation/microcode: Document some aspects for more clarity
Documentation/microcode: Document some aspects for more clarity
Commit-ID: 9f3cc2a0772d7744d1d7195d39ac4794af622fe6 Gitweb: http://git.kernel.org/tip/9f3cc2a0772d7744d1d7195d39ac4794af622fe6 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Jun 2016 17:10:50 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 8 Jun 2016 11:04:20 +0200
Documentation/microcode: Document some aspects for more clarity
Document that builtin microcode is 64-bit only. Also, improve/add comments to places.
--- Documentation/x86/early-microcode.txt | 5 ++++- arch/x86/kernel/cpu/microcode/intel.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-)
Documentation/x86/early-microcode.txt +4 -1
@@ -45,7 +45,10 @@ Builtin microcode ================= We can also load builtin microcode supplied through the regular firmware -builtin method CONFIG_FIRMWARE_IN_KERNEL. Here's an example: +builtin method CONFIG_FIRMWARE_IN_KERNEL. Only 64-bit is currently +supported. + +Here's an example: CONFIG_FIRMWARE_IN_KERNEL=y CONFIG_EXTRA_FIRMWARE="intel-ucode/06-3a-09 amd-ucode/microcode_amd_fam15h.bin"
arch/x86/kernel/cpu/microcode/intel.c +9 -7
@@ -40,9 +40,13 @@#include <asm/msr.h> /* -* Temporary microcode blobs pointers storage. We note here the pointers to -* microcode blobs we've got from whatever storage (detached initrd, builtin). -* Later on, we put those into final storage mc_saved_data.mc_saved. +* Temporary microcode blobs pointers storage. We note here during early load +* the pointers to microcode blobs we've got from whatever storage (detached +* initrd, builtin). Later on, we put those into final storage +* mc_saved_data.mc_saved. +* +* Important: those are offsets from the beginning of initrd or absolute +* addresses within the kernel image when built-in. */ static unsigned long mc_tmp_ptrs[MAX_UCODE_COUNT ];
@@ -57,6 +61,7 @@ static struct ucode_blobs {bool valid; } blobs; +/* Go through saved patches and find the one suitable for the current CPU. */ static enum ucode_state find_microcode_patch (struct microcode_intel **saved,unsigned int num_saved,struct ucode_cpu_info *uci)
@@ -466,6 +471,7 @@ static void show_saved_mc(void)static void save_mc_for_early (u8 *mc) {#ifdef CONFIG_HOTPLUG_CPU +/* Synchronization during CPU hotplug. */ static DEFINE_MUTEX (x86_cpu_microcode_mutex);struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT ];
@@ -474,10 +480,6 @@ static void save_mc_for_early(u8 *mc)struct microcode_intel **mc_saved;int ret, i; -/* -* Hold hotplug lock so mc_saved_data is not accessed by a CPU in -* hotplug. -*/ mutex_lock (&x86_cpu_microcode_mutex); mc_saved_count_init = mc_saved_data.num_saved;