Skip to content

Commit 6f059e6

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/microcode: Clarify the late load logic
reload_store() is way too complicated. Split the inner workings out and make the following enhancements: - Taint the kernel only when the microcode was actually updated. If. e.g. the rendezvous fails, then nothing happened and there is no reason for tainting. - Return useful error codes Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Nikolay Borisov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 634ac23 commit 6f059e6

File tree

1 file changed

+19
-22
lines changed
  • arch/x86/kernel/cpu/microcode

1 file changed

+19
-22
lines changed

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,11 @@ static int microcode_reload_late(void)
362362
pr_info("Reload succeeded, microcode revision: 0x%x -> 0x%x\n",
363363
old, boot_cpu_data.microcode);
364364
microcode_check(&prev_info);
365+
add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
365366
} else {
366367
pr_info("Reload failed, current microcode revision: 0x%x\n",
367368
boot_cpu_data.microcode);
368369
}
369-
370370
return ret;
371371
}
372372

@@ -399,40 +399,37 @@ static bool ensure_cpus_are_online(void)
399399
return true;
400400
}
401401

402+
static int ucode_load_late_locked(void)
403+
{
404+
if (!ensure_cpus_are_online())
405+
return -EBUSY;
406+
407+
switch (microcode_ops->request_microcode_fw(0, &microcode_pdev->dev)) {
408+
case UCODE_NEW:
409+
return microcode_reload_late();
410+
case UCODE_NFOUND:
411+
return -ENOENT;
412+
default:
413+
return -EBADFD;
414+
}
415+
}
416+
402417
static ssize_t reload_store(struct device *dev,
403418
struct device_attribute *attr,
404419
const char *buf, size_t size)
405420
{
406-
enum ucode_state tmp_ret = UCODE_OK;
407-
int bsp = boot_cpu_data.cpu_index;
408421
unsigned long val;
409-
ssize_t ret = 0;
422+
ssize_t ret;
410423

411424
ret = kstrtoul(buf, 0, &val);
412425
if (ret || val != 1)
413426
return -EINVAL;
414427

415428
cpus_read_lock();
416-
417-
if (!ensure_cpus_are_online()) {
418-
ret = -EBUSY;
419-
goto put;
420-
}
421-
422-
tmp_ret = microcode_ops->request_microcode_fw(bsp, &microcode_pdev->dev);
423-
if (tmp_ret != UCODE_NEW)
424-
goto put;
425-
426-
ret = microcode_reload_late();
427-
put:
429+
ret = ucode_load_late_locked();
428430
cpus_read_unlock();
429431

430-
if (ret == 0)
431-
ret = size;
432-
433-
add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
434-
435-
return ret;
432+
return ret ? : size;
436433
}
437434

438435
static DEVICE_ATTR_WO(reload);

0 commit comments

Comments
 (0)