x86/microcode/amd: Use cached microcode for early loading
Subsystems (2)
cover x86/microcode/amd: Use cached microcode for early loading
When Borislav applied the microcode overhaul series:
https://lore.kernel.org/all/[email protected]/
he partially reverted patch 15:
https://lore.kernel.org/all/20231006132617.GOZSAK+YCEwVsEuUdr@fat_crate.local/
to keep AMD suspend/resume working.
After looking at this in detail it turned out that AMD does not use the microcode cache for the early loading during AP bringup and tries to find the microcode in builtin/initrd.
That in turn requires to have a CPU hotplug callback for late hotplug which ensures that the microcode is updated. That's actually too late as CPUID bits are evaluated already before that callback is invoked.
The reason why this was done is the horrible 32bit hack which invoked the early loader before paging is enabled.
That's gone now which in turn allows to remove all this by initializing the microcode cache before the APs are brought up and use the microcode cache for early loading on APs during boot, manual hotplug and resume.
This gets finally rid of the hotplug callback and the ugly initrd_gone hackery which was required to make the post init AP loader work.
The series applies on top of:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/microcode
Thanks,
tglx
--- amd.c | 34 +++++++++++++++++++++------------- core.c | 44 +++----------------------------------------- internal.h | 4 ---- 3 files changed, 24 insertions(+), 58 deletions(-)
PATCH 1/5 x86/microcode/amd: Use correct per CPU ucode_cpu_info
find_blobs_in_containers() is invoked on every CPU but overwrites uncoditionally ucode_cpu_info of CPU0.
Fix this by using the proper CPU data and move the assignment into the call site apply_ucode_from_containers() so that the function can be reused.
--- arch/x86/kernel/cpu/microcode/amd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +3 -3
@@ -503,9 +503,6 @@ static void find_blobs_in_containers(unsif (!get_builtin_microcode (&cp,x86_family (cpuid_1_eax))) cp =find_microcode_in_initrd (ucode_path); -/* Needed in load_microcode_amd() */ - ucode_cpu_info->cpu_sig.sig = cpuid_1_eax; - *ret = cp; }
@@ -513,6 +510,9 @@ static void apply_ucode_from_containers( {struct cpio_data cp = { }; +/* Needed in load_microcode_amd() */ + ucode_cpu_info[smp_processor_id ()].cpu_sig.sig = cpuid_1_eax; +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return ;
[tip: x86/microcode] x86/microcode/amd: Use correct per CPU ucode_cpu_info
The following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: 8c4ac53f1d8bcb3bd4b5c2f338eb068f505d6816 Gitweb: https://git.kernel.org/tip/8c4ac53f1d8bcb3bd4b5c2f338eb068f505d6816 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:41 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 10 Oct 2023 19:39:32 +02:00
x86/microcode/amd: Use correct per CPU ucode_cpu_info
find_blobs_in_containers() is invoked on every CPU but overwrites unconditionally ucode_cpu_info of CPU0.
Fix this by using the proper CPU data and move the assignment into the call site apply_ucode_from_containers() so that the function can be reused.
--- arch/x86/kernel/cpu/microcode/amd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +3 -3
@@ -503,9 +503,6 @@ static void find_blobs_in_containers(unsigned int cpuid_1_eax, struct cpio_dataif (!get_builtin_microcode (&cp,x86_family (cpuid_1_eax))) cp =find_microcode_in_initrd (ucode_path); -/* Needed in load_microcode_amd() */ - ucode_cpu_info->cpu_sig.sig = cpuid_1_eax; - *ret = cp; }
@@ -513,6 +510,9 @@ static void apply_ucode_from_containers(unsigned int cpuid_1_eax) {struct cpio_data cp = { }; +/* Needed in load_microcode_amd() */ + ucode_cpu_info[smp_processor_id ()].cpu_sig.sig = cpuid_1_eax; +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return ;
[tip: x86/microcode] x86/microcode/amd: Use correct per CPU ucode_cpu_info
In reply to Thomas GleixnerThe following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: e0dd49a0eb690820e9d0eef0ad7b6ae435cf6549 Gitweb: https://git.kernel.org/tip/e0dd49a0eb690820e9d0eef0ad7b6ae435cf6549 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:41 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Thu, 19 Oct 2023 15:40:00 +02:00
x86/microcode/amd: Use correct per CPU ucode_cpu_info
find_blobs_in_containers() is invoked on every CPU but overwrites unconditionally ucode_cpu_info of CPU0.
Fix this by using the proper CPU data and move the assignment into the call site apply_ucode_from_containers() so that the function can be reused.
--- arch/x86/kernel/cpu/microcode/amd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +3 -3
@@ -503,9 +503,6 @@ static void find_blobs_in_containers(unsigned int cpuid_1_eax, struct cpio_dataif (!get_builtin_microcode (&cp,x86_family (cpuid_1_eax))) cp =find_microcode_in_initrd (ucode_path); -/* Needed in load_microcode_amd() */ - ucode_cpu_info->cpu_sig.sig = cpuid_1_eax; - *ret = cp; }
@@ -513,6 +510,9 @@ static void apply_ucode_from_containers(unsigned int cpuid_1_eax) {struct cpio_data cp = { }; +/* Needed in load_microcode_amd() */ + ucode_cpu_info[smp_processor_id ()].cpu_sig.sig = cpuid_1_eax; +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return ;
[tip: x86/microcode] x86/microcode/amd: Use correct per CPU ucode_cpu_info
In reply to Thomas GleixnerThe following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: ecfd41089348fa4cc767dc588367e9fdf8cb6b9d Gitweb: https://git.kernel.org/tip/ecfd41089348fa4cc767dc588367e9fdf8cb6b9d Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:41 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 24 Oct 2023 15:05:54 +02:00
x86/microcode/amd: Use correct per CPU ucode_cpu_info
find_blobs_in_containers() is invoked on every CPU but overwrites unconditionally ucode_cpu_info of CPU0.
Fix this by using the proper CPU data and move the assignment into the call site apply_ucode_from_containers() so that the function can be reused.
--- arch/x86/kernel/cpu/microcode/amd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +3 -3
@@ -503,9 +503,6 @@ static void find_blobs_in_containers(unsigned int cpuid_1_eax, struct cpio_dataif (!get_builtin_microcode (&cp,x86_family (cpuid_1_eax))) cp =find_microcode_in_initrd (ucode_path); -/* Needed in load_microcode_amd() */ - ucode_cpu_info->cpu_sig.sig = cpuid_1_eax; - *ret = cp; }
@@ -513,6 +510,9 @@ static void apply_ucode_from_containers(unsigned int cpuid_1_eax) {struct cpio_data cp = { }; +/* Needed in load_microcode_amd() */ + ucode_cpu_info[smp_processor_id ()].cpu_sig.sig = cpuid_1_eax; +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return ;
PATCH 2/5 x86/microcode/amd: Cache builtin microcode too
In reply to Thomas Gleixnersave_microcode_in_initrd_amd() fails to cache builtin microcode and only scans initrd.
Use find_blobs_in_containers() instead which covers both.
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -533,7 +533,7 @@ int __init save_microcode_in_initrd_amd(enum ucode_state ret;struct cpio_data cp; - cp =find_microcode_in_initrd (ucode_path); +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return -EINVAL ;
[tip: x86/microcode] x86/microcode/amd: Cache builtin microcode too
The following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: a983f3245ac2178cb697996e19d1fadee9648bfb Gitweb: https://git.kernel.org/tip/a983f3245ac2178cb697996e19d1fadee9648bfb Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:43 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 10 Oct 2023 19:44:59 +02:00
x86/microcode/amd: Cache builtin microcode too
save_microcode_in_initrd_amd() fails to cache builtin microcode and only scans initrd.
Use find_blobs_in_containers() instead which covers both.
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -533,7 +533,7 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)enum ucode_state ret;struct cpio_data cp; - cp =find_microcode_in_initrd (ucode_path); +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return -EINVAL ;
[tip: x86/microcode] x86/microcode/amd: Cache builtin microcode too
In reply to Thomas GleixnerThe following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: 78f52b9b8ac34713cb352a90d12fc82d2e8128e3 Gitweb: https://git.kernel.org/tip/78f52b9b8ac34713cb352a90d12fc82d2e8128e3 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:43 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Thu, 19 Oct 2023 15:44:35 +02:00
x86/microcode/amd: Cache builtin microcode too
save_microcode_in_initrd_amd() fails to cache builtin microcode and only scans initrd.
Use find_blobs_in_containers() instead which covers both.
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -533,7 +533,7 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)enum ucode_state ret;struct cpio_data cp; - cp =find_microcode_in_initrd (ucode_path); +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return -EINVAL ;
[tip: x86/microcode] x86/microcode/amd: Cache builtin microcode too
In reply to Thomas GleixnerThe following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: d419d28261e72e1c9ec418711b3da41df2265139 Gitweb: https://git.kernel.org/tip/d419d28261e72e1c9ec418711b3da41df2265139 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:43 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 24 Oct 2023 15:05:54 +02:00
x86/microcode/amd: Cache builtin microcode too
save_microcode_in_initrd_amd() fails to cache builtin microcode and only scans initrd.
Use find_blobs_in_containers() instead which covers both.
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -533,7 +533,7 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)enum ucode_state ret;struct cpio_data cp; - cp =find_microcode_in_initrd (ucode_path); +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return -EINVAL ;
PATCH 3/5 x86/microcode/amd: Cache builtin/initrd microcode early
In reply to Thomas GleixnerThere is no reason to scan builtin/initrd microcode on each AP.
Cache the builtin/initrd microcode in an early initcall so that the early AP loader can utilize the cache.
The existing fs initcall which invoked save_microcode_in_initrd_amd() is still required to maintain the initrd_gone flag. Rename it accordingly. This will be removed once the AP loader code is converted to use the cache.
--- arch/x86/kernel/cpu/microcode/amd.c | 8 +++++++- arch/x86/kernel/cpu/microcode/core.c | 20 ++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +7 -1
@@ -527,12 +527,17 @@ void load_ucode_amd_early(unsigned int cstatic enum ucode_state load_microcode_amd (u8 family,const u8 *data,size_t size); -int __init save_microcode_in_initrd_amd (unsigned int cpuid_1_eax) +static int __init save_microcode_in_initrd (void ) { +unsigned int cpuid_1_eax =native_cpuid_eax (1 ); +struct cpuinfo_x86 *c = &boot_cpu_data;struct cont_desc desc = {0 };enum ucode_state ret;struct cpio_data cp; +if (c->x86_vendor !=X86_VENDOR_AMD || c->x86 <0x10 ) +return 0 ; +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return -EINVAL ;
@@ -549,6 +554,7 @@ int __init save_microcode_in_initrd_amd(return 0 ; } +early_initcall (save_microcode_in_initrd);/* * a small, trivial cache of per-family ucode patches
arch/x86/kernel/cpu/microcode/core.c +4 -16
@@ -185,24 +185,13 @@ void load_ucode_ap(void) } } -static int __init save_microcode_in_initrd (void ) +/* Temporary workaround until find_microcode_in_initrd() is __init */ +static int __init mark_initrd_gone (void ) { -struct cpuinfo_x86 *c = &boot_cpu_data; -int ret = -EINVAL ; - -switch (c->x86_vendor) { -case X86_VENDOR_AMD : -if (c->x86 >=0x10 ) - ret =save_microcode_in_initrd_amd (cpuid_eax (1 )); -break ; -default : -break ; - } - initrd_gone = true; - -return ret; +return 0 ; } +fs_initcall (mark_initrd_gone);struct cpio_data find_microcode_in_initrd (const char *path) {
@@ -895,5 +884,4 @@ static int __init microcode_init(void)return error; } -fs_initcall (save_microcode_in_initrd);late_initcall (microcode_init);
[tip: x86/microcode] x86/microcode/amd: Cache builtin/initrd microcode early
The following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: 924acbaab3d99de9b141568a7bb2fc0bb553c116 Gitweb: https://git.kernel.org/tip/924acbaab3d99de9b141568a7bb2fc0bb553c116 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:44 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 10 Oct 2023 19:48:59 +02:00
x86/microcode/amd: Cache builtin/initrd microcode early
There is no reason to scan builtin/initrd microcode on each AP.
Cache the builtin/initrd microcode in an early initcall so that the early AP loader can utilize the cache.
The existing fs initcall which invoked save_microcode_in_initrd_amd() is still required to maintain the initrd_gone flag. Rename it accordingly. This will be removed once the AP loader code is converted to use the cache.
--- arch/x86/kernel/cpu/microcode/amd.c | 8 +++++++- arch/x86/kernel/cpu/microcode/core.c | 20 ++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +7 -1
@@ -527,12 +527,17 @@ void load_ucode_amd_early(unsigned int cpuid_1_eax)static enum ucode_state load_microcode_amd (u8 family,const u8 *data,size_t size); -int __init save_microcode_in_initrd_amd (unsigned int cpuid_1_eax) +static int __init save_microcode_in_initrd (void ) { +unsigned int cpuid_1_eax =native_cpuid_eax (1 ); +struct cpuinfo_x86 *c = &boot_cpu_data;struct cont_desc desc = {0 };enum ucode_state ret;struct cpio_data cp; +if (c->x86_vendor !=X86_VENDOR_AMD || c->x86 <0x10 ) +return 0 ; +find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))return -EINVAL ;
@@ -549,6 +554,7 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)return 0 ; } +early_initcall (save_microcode_in_initrd);/* * a small, trivial cache of per-family ucode patches
arch/x86/kernel/cpu/microcode/core.c +4 -16
@@ -185,24 +185,13 @@ void load_ucode_ap(void) } } -static int __init save_microcode_in_initrd (void ) +/* Temporary workaround until find_microcode_in_initrd() is __init */ +static int __init mark_initrd_gone (void ) { -struct cpuinfo_x86 *c = &boot_cpu_data; -int ret = -EINVAL ; - -switch (c->x86_vendor) { -case X86_VENDOR_AMD : -if (c->x86 >=0x10 ) - ret =save_microcode_in_initrd_amd (cpuid_eax (1 )); -break ; -default : -break ; - } - initrd_gone = true; - -return ret; +return 0 ; } +fs_initcall (mark_initrd_gone);struct cpio_data find_microcode_in_initrd (const char *path) {
@@ -895,5 +884,4 @@ static int __init microcode_init(void)return error; } -fs_initcall (save_microcode_in_initrd);late_initcall (microcode_init);
PATCH 4/5 x86/microcode/amd: Use cached microcode for AP load
In reply to Thomas GleixnerNow that the microcode cache is initialized before the APs are brought up, there is no point to scan builtin/initrd microcode during AP loading.
Convert the AP loader to utilize the cache, which in turn makes the CPU hotplug callback which applies the microcode after initrd/builtin is gone obsolete as the early loading during late hotplug operations including the resume path depends now only on the cache.
--- arch/x86/kernel/cpu/microcode/amd.c | 20 +++++++++++--------- arch/x86/kernel/cpu/microcode/core.c | 15 ++------------- arch/x86/kernel/cpu/microcode/internal.h | 2 -- 3 files changed, 13 insertions(+), 24 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +11 -9
@@ -496,7 +496,7 @@ static bool get_builtin_microcode(structreturn false; } -static void find_blobs_in_containers (unsigned int cpuid_1_eax,struct cpio_data *ret) +static void __init find_blobs_in_containers (unsigned int cpuid_1_eax,struct cpio_data *ret) {struct cpio_data cp;
@@ -506,12 +506,12 @@ static void find_blobs_in_containers(uns *ret = cp; } -static void apply_ucode_from_containers (unsigned int cpuid_1_eax) +void __init load_ucode_amd_bsp (unsigned int cpuid_1_eax) {struct cpio_data cp = { };/* Needed in load_microcode_amd() */ - ucode_cpu_info[smp_processor_id ()].cpu_sig.sig = cpuid_1_eax; + ucode_cpu_info[0 ].cpu_sig.sig = cpuid_1_eax;find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))
@@ -520,11 +520,6 @@ static void apply_ucode_from_containers(early_apply_microcode (cpuid_1_eax, cp.data, cp.size); } -void load_ucode_amd_early (unsigned int cpuid_1_eax) -{ -return apply_ucode_from_containers (cpuid_1_eax); -} -static enum ucode_state load_microcode_amd (u8 family,const u8 *data,size_t size);static int __init save_microcode_in_initrd (void )
@@ -608,7 +603,6 @@ static struct ucode_patch *find_patch(unstruct ucode_cpu_info *uci = ucode_cpu_info + cpu;u16 equiv_id; - equiv_id =find_equiv_id (&equiv_table, uci->cpu_sig.sig);if (!equiv_id)return NULL ;
@@ -710,6 +704,14 @@ static enum ucode_state apply_microcode_return ret; } +void load_ucode_amd_ap (unsigned int cpuid_1_eax) +{ +unsigned int cpu =smp_processor_id (); + + ucode_cpu_info[cpu].cpu_sig.sig = cpuid_1_eax; +apply_microcode_amd (cpu); +} +static size_t install_equiv_cpu_table (const u8 *buf,size_t buf_size) {u32 equiv_tbl_len;
arch/x86/kernel/cpu/microcode/core.c +2 -13
@@ -159,7 +159,7 @@ void __init load_ucode_bsp(void)if (intel)load_ucode_intel_bsp ();else -load_ucode_amd_early (cpuid_1_eax); +load_ucode_amd_bsp (cpuid_1_eax); }void load_ucode_ap (void )
@@ -178,7 +178,7 @@ void load_ucode_ap(void)break ;case X86_VENDOR_AMD :if (x86_family (cpuid_1_eax) >=0x10 ) -load_ucode_amd_early (cpuid_1_eax); +load_ucode_amd_ap (cpuid_1_eax);break ;default :break ;
@@ -789,15 +789,6 @@ static struct syscore_ops mc_syscore_ops .resume = microcode_bsp_resume, }; -static int mc_cpu_starting (unsigned int cpu) -{ -enum ucode_state err = microcode_ops->apply_microcode (cpu); - -pr_debug ("%s: CPU%d, err: %d\n" , __func__, cpu, err); - -return err ==UCODE_ERROR ; -} -static int mc_cpu_online (unsigned int cpu) {struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
@@ -870,8 +861,6 @@ static int __init microcode_init(void) }register_syscore_ops (&mc_syscore_ops); -cpuhp_setup_state_nocalls (CPUHP_AP_MICROCODE_LOADER ,"x86/microcode:starting" , - mc_cpu_starting,NULL );cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"x86/microcode:online" , mc_cpu_online, mc_cpu_down_prep);
arch/x86/kernel/cpu/microcode/internal.h +0 -2
@@ -95,7 +95,6 @@ extern bool initrd_gone;#ifdef CONFIG_CPU_SUP_AMD void load_ucode_amd_bsp (unsigned int family);void load_ucode_amd_ap (unsigned int family); -void load_ucode_amd_early (unsigned int cpuid_1_eax);int save_microcode_in_initrd_amd (unsigned int family);void reload_ucode_amd (unsigned int cpu);struct microcode_ops *init_amd_microcode (void );
@@ -103,7 +102,6 @@ void exit_amd_microcode(void);#else /* CONFIG_CPU_SUP_AMD */ static inline void load_ucode_amd_bsp (unsigned int family) { }static inline void load_ucode_amd_ap (unsigned int family) { } -static inline void load_ucode_amd_early (unsigned int family) { }static inline int save_microcode_in_initrd_amd (unsigned int family) {return -EINVAL ; }static inline void reload_ucode_amd (unsigned int cpu) { }static inline struct microcode_ops *init_amd_microcode (void ) {return NULL ; }
[tip: x86/microcode] x86/microcode/amd: Use cached microcode for AP load
The following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: 1c9faa6577b3230ba62a51dc504d841b5ef630de Gitweb: https://git.kernel.org/tip/1c9faa6577b3230ba62a51dc504d841b5ef630de Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:45 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 10 Oct 2023 21:16:47 +02:00
x86/microcode/amd: Use cached microcode for AP load
Now that the microcode cache is initialized before the APs are brought up, there is no point in scanning builtin/initrd microcode during AP loading.
Convert the AP loader to utilize the cache, which in turn makes the CPU hotplug callback which applies the microcode after initrd/builtin is gone, obsolete as the early loading during late hotplug operations including the resume path depends now only on the cache.
--- arch/x86/kernel/cpu/microcode/amd.c | 20 +++++++++++--------- arch/x86/kernel/cpu/microcode/core.c | 15 ++------------- arch/x86/kernel/cpu/microcode/internal.h | 2 -- 3 files changed, 13 insertions(+), 24 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +11 -9
@@ -496,7 +496,7 @@ static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)return false; } -static void find_blobs_in_containers (unsigned int cpuid_1_eax,struct cpio_data *ret) +static void __init find_blobs_in_containers (unsigned int cpuid_1_eax,struct cpio_data *ret) {struct cpio_data cp;
@@ -506,12 +506,12 @@ static void find_blobs_in_containers(unsigned int cpuid_1_eax, struct cpio_data *ret = cp; } -static void apply_ucode_from_containers (unsigned int cpuid_1_eax) +void __init load_ucode_amd_bsp (unsigned int cpuid_1_eax) {struct cpio_data cp = { };/* Needed in load_microcode_amd() */ - ucode_cpu_info[smp_processor_id ()].cpu_sig.sig = cpuid_1_eax; + ucode_cpu_info[0 ].cpu_sig.sig = cpuid_1_eax;find_blobs_in_containers (cpuid_1_eax, &cp);if (!(cp.data && cp.size))
@@ -520,11 +520,6 @@ static void apply_ucode_from_containers(unsigned int cpuid_1_eax)early_apply_microcode (cpuid_1_eax, cp.data, cp.size); } -void load_ucode_amd_early (unsigned int cpuid_1_eax) -{ -return apply_ucode_from_containers (cpuid_1_eax); -} -static enum ucode_state load_microcode_amd (u8 family,const u8 *data,size_t size);static int __init save_microcode_in_initrd (void )
@@ -608,7 +603,6 @@ static struct ucode_patch *find_patch(unsigned int cpu)struct ucode_cpu_info *uci = ucode_cpu_info + cpu;u16 equiv_id; - equiv_id =find_equiv_id (&equiv_table, uci->cpu_sig.sig);if (!equiv_id)return NULL ;
@@ -710,6 +704,14 @@ out:return ret; } +void load_ucode_amd_ap (unsigned int cpuid_1_eax) +{ +unsigned int cpu =smp_processor_id (); + + ucode_cpu_info[cpu].cpu_sig.sig = cpuid_1_eax; +apply_microcode_amd (cpu); +} +static size_t install_equiv_cpu_table (const u8 *buf,size_t buf_size) {u32 equiv_tbl_len;
arch/x86/kernel/cpu/microcode/core.c +2 -13
@@ -159,7 +159,7 @@ void __init load_ucode_bsp(void)if (intel)load_ucode_intel_bsp ();else -load_ucode_amd_early (cpuid_1_eax); +load_ucode_amd_bsp (cpuid_1_eax); }void load_ucode_ap (void )
@@ -178,7 +178,7 @@ void load_ucode_ap(void)break ;case X86_VENDOR_AMD :if (x86_family (cpuid_1_eax) >=0x10 ) -load_ucode_amd_early (cpuid_1_eax); +load_ucode_amd_ap (cpuid_1_eax);break ;default :break ;
@@ -789,15 +789,6 @@ static struct syscore_ops mc_syscore_ops = { .resume = microcode_bsp_resume, }; -static int mc_cpu_starting (unsigned int cpu) -{ -enum ucode_state err = microcode_ops->apply_microcode (cpu); - -pr_debug ("%s: CPU%d, err: %d\n" , __func__, cpu, err); - -return err ==UCODE_ERROR ; -} -static int mc_cpu_online (unsigned int cpu) {struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
@@ -870,8 +861,6 @@ static int __init microcode_init(void) }register_syscore_ops (&mc_syscore_ops); -cpuhp_setup_state_nocalls (CPUHP_AP_MICROCODE_LOADER ,"x86/microcode:starting" , - mc_cpu_starting,NULL );cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"x86/microcode:online" , mc_cpu_online, mc_cpu_down_prep);
arch/x86/kernel/cpu/microcode/internal.h +0 -2
@@ -95,7 +95,6 @@ extern bool initrd_gone;#ifdef CONFIG_CPU_SUP_AMD void load_ucode_amd_bsp (unsigned int family);void load_ucode_amd_ap (unsigned int family); -void load_ucode_amd_early (unsigned int cpuid_1_eax);int save_microcode_in_initrd_amd (unsigned int family);void reload_ucode_amd (unsigned int cpu);struct microcode_ops *init_amd_microcode (void );
@@ -103,7 +102,6 @@ void exit_amd_microcode(void);#else /* CONFIG_CPU_SUP_AMD */ static inline void load_ucode_amd_bsp (unsigned int family) { }static inline void load_ucode_amd_ap (unsigned int family) { } -static inline void load_ucode_amd_early (unsigned int family) { }static inline int save_microcode_in_initrd_amd (unsigned int family) {return -EINVAL ; }static inline void reload_ucode_amd (unsigned int cpu) { }static inline struct microcode_ops *init_amd_microcode (void ) {return NULL ; }
PATCH 5/5 x86/microcode: Mop up early loading leftovers
In reply to Thomas GleixnerGet rid of the initrd_gone hack which was required to keep find_microcode_in_initrd() functional after init.
As find_microcode_in_initrd() is now only used during init, mark it accordingly.
--- arch/x86/kernel/cpu/microcode/core.c | 17 +---------------- arch/x86/kernel/cpu/microcode/internal.h | 2 -- 2 files changed, 1 insertion(+), 18 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +1 -16
@@ -49,8 +49,6 @@ static bool dis_ucode_ldr = true;bool force_minrev =IS_ENABLED (CONFIG_MICROCODE_LATE_FORCE_MINREV );module_param (force_minrev, bool,S_IRUSR |S_IWUSR ); -bool initrd_gone; -/* * Synchronization. *
@@ -185,15 +183,7 @@ void load_ucode_ap(void) } } -/* Temporary workaround until find_microcode_in_initrd() is __init */ -static int __init mark_initrd_gone (void ) -{ - initrd_gone = true; -return 0 ; -} -fs_initcall (mark_initrd_gone); - -struct cpio_data find_microcode_in_initrd (const char *path) +struct cpio_data __init find_microcode_in_initrd (const char *path) {#ifdef CONFIG_BLK_DEV_INITRD unsigned long start =0 ;
@@ -224,12 +214,7 @@ struct cpio_data find_microcode_in_initr* has the virtual address of the beginning of the initrd. It also * possibly relocates the ramdisk. In either case, initrd_start contains * the updated address so use that instead. -* -* initrd_gone is for the hotplug case where we've thrown out initrd -* already. */ -if (initrd_gone) -return (struct cpio_data ){NULL ,0 ,"" };if (initrd_start) start = initrd_start;
arch/x86/kernel/cpu/microcode/internal.h +0 -2
@@ -90,8 +90,6 @@ static inline unsigned int x86_cpuid_famreturn x86_family (eax); } -extern bool initrd_gone; -#ifdef CONFIG_CPU_SUP_AMD void load_ucode_amd_bsp (unsigned int family);void load_ucode_amd_ap (unsigned int family);
[tip: x86/microcode] x86/microcode: Mop up early loading leftovers
The following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: 7edf8316660ee2966b8aed03a63d44496731f505 Gitweb: https://git.kernel.org/tip/7edf8316660ee2966b8aed03a63d44496731f505 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 10 Oct 2023 17:08:46 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 10 Oct 2023 21:17:58 +02:00
x86/microcode: Mop up early loading leftovers
Get rid of the initrd_gone hack which was required to keep find_microcode_in_initrd() functional after init.
As find_microcode_in_initrd() is now only used during init, mark it accordingly.
--- arch/x86/kernel/cpu/microcode/core.c | 17 +---------------- arch/x86/kernel/cpu/microcode/internal.h | 2 -- 2 files changed, 1 insertion(+), 18 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +1 -16
@@ -49,8 +49,6 @@ static bool dis_ucode_ldr = true;bool force_minrev =IS_ENABLED (CONFIG_MICROCODE_LATE_FORCE_MINREV );module_param (force_minrev, bool,S_IRUSR |S_IWUSR ); -bool initrd_gone; -/* * Synchronization. *
@@ -185,15 +183,7 @@ void load_ucode_ap(void) } } -/* Temporary workaround until find_microcode_in_initrd() is __init */ -static int __init mark_initrd_gone (void ) -{ - initrd_gone = true; -return 0 ; -} -fs_initcall (mark_initrd_gone); - -struct cpio_data find_microcode_in_initrd (const char *path) +struct cpio_data __init find_microcode_in_initrd (const char *path) {#ifdef CONFIG_BLK_DEV_INITRD unsigned long start =0 ;
@@ -224,12 +214,7 @@ struct cpio_data find_microcode_in_initrd(const char *path)* has the virtual address of the beginning of the initrd. It also * possibly relocates the ramdisk. In either case, initrd_start contains * the updated address so use that instead. -* -* initrd_gone is for the hotplug case where we've thrown out initrd -* already. */ -if (initrd_gone) -return (struct cpio_data ){NULL ,0 ,"" };if (initrd_start) start = initrd_start;
arch/x86/kernel/cpu/microcode/internal.h +0 -2
@@ -90,8 +90,6 @@ static inline unsigned int x86_cpuid_family(void)return x86_family (eax); } -extern bool initrd_gone; -#ifdef CONFIG_CPU_SUP_AMD void load_ucode_amd_bsp (unsigned int family);void load_ucode_amd_ap (unsigned int family);