Commit 6b072022 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Borislav Petkov (AMD)

x86/microcode/intel: Simplify and rename generic_load_microcode()

so it becomes less obfuscated and rename it because there is nothing
generic about it.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20231002115902.330295409@linutronix.de
parent b0f0bf5e
...@@ -240,19 +240,6 @@ int intel_microcode_sanity_check(void *mc, bool print_err, int hdr_type) ...@@ -240,19 +240,6 @@ int intel_microcode_sanity_check(void *mc, bool print_err, int hdr_type)
} }
EXPORT_SYMBOL_GPL(intel_microcode_sanity_check); EXPORT_SYMBOL_GPL(intel_microcode_sanity_check);
/*
* Returns 1 if update has been found, 0 otherwise.
*/
static int has_newer_microcode(void *mc, unsigned int csig, int cpf, int new_rev)
{
struct microcode_header_intel *mc_hdr = mc;
if (mc_hdr->rev <= new_rev)
return 0;
return intel_find_matching_signature(mc, csig, cpf);
}
static void save_microcode_patch(void *data, unsigned int size) static void save_microcode_patch(void *data, unsigned int size)
{ {
struct microcode_header_intel *p; struct microcode_header_intel *p;
...@@ -559,14 +546,12 @@ static enum ucode_state apply_microcode_intel(int cpu) ...@@ -559,14 +546,12 @@ static enum ucode_state apply_microcode_intel(int cpu)
return ret; return ret;
} }
static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter) static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter)
{ {
struct ucode_cpu_info *uci = ucode_cpu_info + cpu; struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
unsigned int curr_mc_size = 0, new_mc_size = 0; unsigned int curr_mc_size = 0, new_mc_size = 0;
enum ucode_state ret = UCODE_OK; int cur_rev = uci->cpu_sig.rev;
int new_rev = uci->cpu_sig.rev;
u8 *new_mc = NULL, *mc = NULL; u8 *new_mc = NULL, *mc = NULL;
unsigned int csig, cpf;
while (iov_iter_count(iter)) { while (iov_iter_count(iter)) {
struct microcode_header_intel mc_header; struct microcode_header_intel mc_header;
...@@ -583,6 +568,7 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter) ...@@ -583,6 +568,7 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)
pr_err("error! Bad data in microcode data file (totalsize too small)\n"); pr_err("error! Bad data in microcode data file (totalsize too small)\n");
break; break;
} }
data_size = mc_size - sizeof(mc_header); data_size = mc_size - sizeof(mc_header);
if (data_size > iov_iter_count(iter)) { if (data_size > iov_iter_count(iter)) {
pr_err("error! Bad data in microcode data file (truncated file?)\n"); pr_err("error! Bad data in microcode data file (truncated file?)\n");
...@@ -605,16 +591,17 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter) ...@@ -605,16 +591,17 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)
break; break;
} }
csig = uci->cpu_sig.sig; if (cur_rev >= mc_header.rev)
cpf = uci->cpu_sig.pf; continue;
if (has_newer_microcode(mc, csig, cpf, new_rev)) {
vfree(new_mc); if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf))
new_rev = mc_header.rev; continue;
new_mc = mc;
new_mc_size = mc_size; vfree(new_mc);
mc = NULL; /* trigger new vmalloc */ cur_rev = mc_header.rev;
ret = UCODE_NEW; new_mc = mc;
} new_mc_size = mc_size;
mc = NULL;
} }
vfree(mc); vfree(mc);
...@@ -634,9 +621,9 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter) ...@@ -634,9 +621,9 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)
save_microcode_patch(new_mc, new_mc_size); save_microcode_patch(new_mc, new_mc_size);
pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n", pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n",
cpu, new_rev, uci->cpu_sig.rev); cpu, cur_rev, uci->cpu_sig.rev);
return ret; return UCODE_NEW;
} }
static bool is_blacklisted(unsigned int cpu) static bool is_blacklisted(unsigned int cpu)
...@@ -685,7 +672,7 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device) ...@@ -685,7 +672,7 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
kvec.iov_base = (void *)firmware->data; kvec.iov_base = (void *)firmware->data;
kvec.iov_len = firmware->size; kvec.iov_len = firmware->size;
iov_iter_kvec(&iter, ITER_SOURCE, &kvec, 1, firmware->size); iov_iter_kvec(&iter, ITER_SOURCE, &kvec, 1, firmware->size);
ret = generic_load_microcode(cpu, &iter); ret = parse_microcode_blobs(cpu, &iter);
release_firmware(firmware); release_firmware(firmware);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment