mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
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 <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com> Link: https://lore.kernel.org/r/20231002115903.145048840@linutronix.de
This commit is contained in:
parent
634ac23ad6
commit
6f059e634d
1 changed files with 19 additions and 22 deletions
|
@ -362,11 +362,11 @@ static int microcode_reload_late(void)
|
||||||
pr_info("Reload succeeded, microcode revision: 0x%x -> 0x%x\n",
|
pr_info("Reload succeeded, microcode revision: 0x%x -> 0x%x\n",
|
||||||
old, boot_cpu_data.microcode);
|
old, boot_cpu_data.microcode);
|
||||||
microcode_check(&prev_info);
|
microcode_check(&prev_info);
|
||||||
|
add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
|
||||||
} else {
|
} else {
|
||||||
pr_info("Reload failed, current microcode revision: 0x%x\n",
|
pr_info("Reload failed, current microcode revision: 0x%x\n",
|
||||||
boot_cpu_data.microcode);
|
boot_cpu_data.microcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,40 +399,37 @@ static bool ensure_cpus_are_online(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ucode_load_late_locked(void)
|
||||||
|
{
|
||||||
|
if (!ensure_cpus_are_online())
|
||||||
|
return -EBUSY;
|
||||||
|
|
||||||
|
switch (microcode_ops->request_microcode_fw(0, µcode_pdev->dev)) {
|
||||||
|
case UCODE_NEW:
|
||||||
|
return microcode_reload_late();
|
||||||
|
case UCODE_NFOUND:
|
||||||
|
return -ENOENT;
|
||||||
|
default:
|
||||||
|
return -EBADFD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t reload_store(struct device *dev,
|
static ssize_t reload_store(struct device *dev,
|
||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
const char *buf, size_t size)
|
const char *buf, size_t size)
|
||||||
{
|
{
|
||||||
enum ucode_state tmp_ret = UCODE_OK;
|
|
||||||
int bsp = boot_cpu_data.cpu_index;
|
|
||||||
unsigned long val;
|
unsigned long val;
|
||||||
ssize_t ret = 0;
|
ssize_t ret;
|
||||||
|
|
||||||
ret = kstrtoul(buf, 0, &val);
|
ret = kstrtoul(buf, 0, &val);
|
||||||
if (ret || val != 1)
|
if (ret || val != 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
cpus_read_lock();
|
cpus_read_lock();
|
||||||
|
ret = ucode_load_late_locked();
|
||||||
if (!ensure_cpus_are_online()) {
|
|
||||||
ret = -EBUSY;
|
|
||||||
goto put;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev);
|
|
||||||
if (tmp_ret != UCODE_NEW)
|
|
||||||
goto put;
|
|
||||||
|
|
||||||
ret = microcode_reload_late();
|
|
||||||
put:
|
|
||||||
cpus_read_unlock();
|
cpus_read_unlock();
|
||||||
|
|
||||||
if (ret == 0)
|
return ret ? : size;
|
||||||
ret = size;
|
|
||||||
|
|
||||||
add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEVICE_ATTR_WO(reload);
|
static DEVICE_ATTR_WO(reload);
|
||||||
|
|
Loading…
Add table
Reference in a new issue