Skip to content

Commit a7939f0

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
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. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d419d28 commit a7939f0

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

arch/x86/kernel/cpu/microcode/amd.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,17 @@ void load_ucode_amd_early(unsigned int cpuid_1_eax)
527527

528528
static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size);
529529

530-
int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)
530+
static int __init save_microcode_in_initrd(void)
531531
{
532+
unsigned int cpuid_1_eax = native_cpuid_eax(1);
533+
struct cpuinfo_x86 *c = &boot_cpu_data;
532534
struct cont_desc desc = { 0 };
533535
enum ucode_state ret;
534536
struct cpio_data cp;
535537

538+
if (dis_ucode_ldr || c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10)
539+
return 0;
540+
536541
find_blobs_in_containers(cpuid_1_eax, &cp);
537542
if (!(cp.data && cp.size))
538543
return -EINVAL;
@@ -549,6 +554,7 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)
549554

550555
return 0;
551556
}
557+
early_initcall(save_microcode_in_initrd);
552558

553559
/*
554560
* a small, trivial cache of per-family ucode patches

arch/x86/kernel/cpu/microcode/core.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,13 @@ void load_ucode_ap(void)
180180
}
181181
}
182182

183-
static int __init save_microcode_in_initrd(void)
183+
/* Temporary workaround until find_microcode_in_initrd() is __init */
184+
static int __init mark_initrd_gone(void)
184185
{
185-
struct cpuinfo_x86 *c = &boot_cpu_data;
186-
int ret = -EINVAL;
187-
188-
switch (c->x86_vendor) {
189-
case X86_VENDOR_AMD:
190-
if (c->x86 >= 0x10)
191-
ret = save_microcode_in_initrd_amd(cpuid_eax(1));
192-
break;
193-
default:
194-
break;
195-
}
196-
197186
initrd_gone = true;
198-
199-
return ret;
187+
return 0;
200188
}
189+
fs_initcall(mark_initrd_gone);
201190

202191
struct cpio_data find_microcode_in_initrd(const char *path)
203192
{
@@ -615,5 +604,4 @@ static int __init microcode_init(void)
615604
return error;
616605

617606
}
618-
fs_initcall(save_microcode_in_initrd);
619607
late_initcall(microcode_init);

0 commit comments

Comments
 (0)