Skip to content

Commit 0177669

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/microcode/intel: Cleanup code further
Sanitize the microcode scan loop, fixup printks and move the loading function for builtin microcode next to the place where it is used and mark it __init. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231002115902.389400871@linutronix.de
1 parent 6b07202 commit 0177669

1 file changed

Lines changed: 32 additions & 44 deletions

File tree

  • arch/x86/kernel/cpu/microcode

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

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static const char ucode_path[] = "kernel/x86/microcode/GenuineIntel.bin";
3636
static struct microcode_intel *intel_ucode_patch __read_mostly;
3737

3838
/* last level cache size per core */
39-
static int llc_size_per_core __ro_after_init;
39+
static unsigned int llc_size_per_core __ro_after_init;
4040

4141
/* microcode format is extended from prescott processors */
4242
struct extended_signature {
@@ -294,29 +294,6 @@ static struct microcode_intel *scan_microcode(void *data, size_t size,
294294
return patch;
295295
}
296296

297-
static bool load_builtin_intel_microcode(struct cpio_data *cp)
298-
{
299-
unsigned int eax = 1, ebx, ecx = 0, edx;
300-
struct firmware fw;
301-
char name[30];
302-
303-
if (IS_ENABLED(CONFIG_X86_32))
304-
return false;
305-
306-
native_cpuid(&eax, &ebx, &ecx, &edx);
307-
308-
sprintf(name, "intel-ucode/%02x-%02x-%02x",
309-
x86_family(eax), x86_model(eax), x86_stepping(eax));
310-
311-
if (firmware_request_builtin(&fw, name)) {
312-
cp->size = fw.size;
313-
cp->data = (void *)fw.data;
314-
return true;
315-
}
316-
317-
return false;
318-
}
319-
320297
static int apply_microcode_early(struct ucode_cpu_info *uci)
321298
{
322299
struct microcode_intel *mc;
@@ -360,6 +337,28 @@ static int apply_microcode_early(struct ucode_cpu_info *uci)
360337
return 0;
361338
}
362339

340+
static bool load_builtin_intel_microcode(struct cpio_data *cp)
341+
{
342+
unsigned int eax = 1, ebx, ecx = 0, edx;
343+
struct firmware fw;
344+
char name[30];
345+
346+
if (IS_ENABLED(CONFIG_X86_32))
347+
return false;
348+
349+
native_cpuid(&eax, &ebx, &ecx, &edx);
350+
351+
sprintf(name, "intel-ucode/%02x-%02x-%02x",
352+
x86_family(eax), x86_model(eax), x86_stepping(eax));
353+
354+
if (firmware_request_builtin(&fw, name)) {
355+
cp->size = fw.size;
356+
cp->data = (void *)fw.data;
357+
return true;
358+
}
359+
return false;
360+
}
361+
363362
int __init save_microcode_in_initrd_intel(void)
364363
{
365364
struct ucode_cpu_info uci;
@@ -432,25 +431,16 @@ void load_ucode_intel_ap(void)
432431
apply_microcode_early(&uci);
433432
}
434433

435-
/* Accessor for microcode pointer */
436-
static struct microcode_intel *ucode_get_patch(void)
437-
{
438-
return intel_ucode_patch;
439-
}
440-
441434
void reload_ucode_intel(void)
442435
{
443-
struct microcode_intel *p;
444436
struct ucode_cpu_info uci;
445437

446438
intel_cpu_collect_info(&uci);
447439

448-
p = ucode_get_patch();
449-
if (!p)
440+
uci.mc = intel_ucode_patch;
441+
if (!uci.mc)
450442
return;
451443

452-
uci.mc = p;
453-
454444
apply_microcode_early(&uci);
455445
}
456446

@@ -488,8 +478,7 @@ static enum ucode_state apply_microcode_intel(int cpu)
488478
if (WARN_ON(raw_smp_processor_id() != cpu))
489479
return UCODE_ERROR;
490480

491-
/* Look for a newer patch in our cache: */
492-
mc = ucode_get_patch();
481+
mc = intel_ucode_patch;
493482
if (!mc) {
494483
mc = uci->mc;
495484
if (!mc)
@@ -680,18 +669,17 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
680669
}
681670

682671
static struct microcode_ops microcode_intel_ops = {
683-
.request_microcode_fw = request_microcode_fw,
684-
.collect_cpu_info = collect_cpu_info,
685-
.apply_microcode = apply_microcode_intel,
672+
.request_microcode_fw = request_microcode_fw,
673+
.collect_cpu_info = collect_cpu_info,
674+
.apply_microcode = apply_microcode_intel,
686675
};
687676

688-
static int __init calc_llc_size_per_core(struct cpuinfo_x86 *c)
677+
static __init void calc_llc_size_per_core(struct cpuinfo_x86 *c)
689678
{
690679
u64 llc_size = c->x86_cache_size * 1024ULL;
691680

692681
do_div(llc_size, c->x86_max_cores);
693-
694-
return (int)llc_size;
682+
llc_size_per_core = (unsigned int)llc_size;
695683
}
696684

697685
struct microcode_ops * __init init_intel_microcode(void)
@@ -704,7 +692,7 @@ struct microcode_ops * __init init_intel_microcode(void)
704692
return NULL;
705693
}
706694

707-
llc_size_per_core = calc_llc_size_per_core(c);
695+
calc_llc_size_per_core(c);
708696

709697
return &microcode_intel_ops;
710698
}

0 commit comments

Comments
 (0)