Skip to content

Commit 5af05b8

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
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. 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 a7939f0 commit 5af05b8

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)
496496
return false;
497497
}
498498

499-
static void find_blobs_in_containers(unsigned int cpuid_1_eax, struct cpio_data *ret)
499+
static void __init find_blobs_in_containers(unsigned int cpuid_1_eax, struct cpio_data *ret)
500500
{
501501
struct cpio_data cp;
502502

@@ -506,12 +506,12 @@ static void find_blobs_in_containers(unsigned int cpuid_1_eax, struct cpio_data
506506
*ret = cp;
507507
}
508508

509-
static void apply_ucode_from_containers(unsigned int cpuid_1_eax)
509+
void __init load_ucode_amd_bsp(unsigned int cpuid_1_eax)
510510
{
511511
struct cpio_data cp = { };
512512

513513
/* Needed in load_microcode_amd() */
514-
ucode_cpu_info[smp_processor_id()].cpu_sig.sig = cpuid_1_eax;
514+
ucode_cpu_info[0].cpu_sig.sig = cpuid_1_eax;
515515

516516
find_blobs_in_containers(cpuid_1_eax, &cp);
517517
if (!(cp.data && cp.size))
@@ -520,11 +520,6 @@ static void apply_ucode_from_containers(unsigned int cpuid_1_eax)
520520
early_apply_microcode(cpuid_1_eax, cp.data, cp.size);
521521
}
522522

523-
void load_ucode_amd_early(unsigned int cpuid_1_eax)
524-
{
525-
return apply_ucode_from_containers(cpuid_1_eax);
526-
}
527-
528523
static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size);
529524

530525
static int __init save_microcode_in_initrd(void)
@@ -608,7 +603,6 @@ static struct ucode_patch *find_patch(unsigned int cpu)
608603
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
609604
u16 equiv_id;
610605

611-
612606
equiv_id = find_equiv_id(&equiv_table, uci->cpu_sig.sig);
613607
if (!equiv_id)
614608
return NULL;
@@ -710,6 +704,14 @@ static enum ucode_state apply_microcode_amd(int cpu)
710704
return ret;
711705
}
712706

707+
void load_ucode_amd_ap(unsigned int cpuid_1_eax)
708+
{
709+
unsigned int cpu = smp_processor_id();
710+
711+
ucode_cpu_info[cpu].cpu_sig.sig = cpuid_1_eax;
712+
apply_microcode_amd(cpu);
713+
}
714+
713715
static size_t install_equiv_cpu_table(const u8 *buf, size_t buf_size)
714716
{
715717
u32 equiv_tbl_len;

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void __init load_ucode_bsp(void)
154154
if (intel)
155155
load_ucode_intel_bsp();
156156
else
157-
load_ucode_amd_early(cpuid_1_eax);
157+
load_ucode_amd_bsp(cpuid_1_eax);
158158
}
159159

160160
void load_ucode_ap(void)
@@ -173,7 +173,7 @@ void load_ucode_ap(void)
173173
break;
174174
case X86_VENDOR_AMD:
175175
if (x86_family(cpuid_1_eax) >= 0x10)
176-
load_ucode_amd_early(cpuid_1_eax);
176+
load_ucode_amd_ap(cpuid_1_eax);
177177
break;
178178
default:
179179
break;
@@ -494,15 +494,6 @@ static struct syscore_ops mc_syscore_ops = {
494494
.resume = microcode_bsp_resume,
495495
};
496496

497-
static int mc_cpu_starting(unsigned int cpu)
498-
{
499-
enum ucode_state err = microcode_ops->apply_microcode(cpu);
500-
501-
pr_debug("%s: CPU%d, err: %d\n", __func__, cpu, err);
502-
503-
return err == UCODE_ERROR;
504-
}
505-
506497
static int mc_cpu_online(unsigned int cpu)
507498
{
508499
struct device *dev = get_cpu_device(cpu);
@@ -590,8 +581,6 @@ static int __init microcode_init(void)
590581
schedule_on_each_cpu(setup_online_cpu);
591582

592583
register_syscore_ops(&mc_syscore_ops);
593-
cpuhp_setup_state_nocalls(CPUHP_AP_MICROCODE_LOADER, "x86/microcode:starting",
594-
mc_cpu_starting, NULL);
595584
cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/microcode:online",
596585
mc_cpu_online, mc_cpu_down_prep);
597586

arch/x86/kernel/cpu/microcode/internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,13 @@ extern bool initrd_gone;
9191
#ifdef CONFIG_CPU_SUP_AMD
9292
void load_ucode_amd_bsp(unsigned int family);
9393
void load_ucode_amd_ap(unsigned int family);
94-
void load_ucode_amd_early(unsigned int cpuid_1_eax);
9594
int save_microcode_in_initrd_amd(unsigned int family);
9695
void reload_ucode_amd(unsigned int cpu);
9796
struct microcode_ops *init_amd_microcode(void);
9897
void exit_amd_microcode(void);
9998
#else /* CONFIG_CPU_SUP_AMD */
10099
static inline void load_ucode_amd_bsp(unsigned int family) { }
101100
static inline void load_ucode_amd_ap(unsigned int family) { }
102-
static inline void load_ucode_amd_early(unsigned int family) { }
103101
static inline int save_microcode_in_initrd_amd(unsigned int family) { return -EINVAL; }
104102
static inline void reload_ucode_amd(unsigned int cpu) { }
105103
static inline struct microcode_ops *init_amd_microcode(void) { return NULL; }

0 commit comments

Comments
 (0)