Skip to content

Commit

Permalink
x86/microcode/intel: Rework intel_find_matching_signature()
Browse files Browse the repository at this point in the history
Take a cpu_signature argument and work from there. Move the match()
helper next to the callsite as there is no point for having it in
a header.

Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: Borislav Petkov (AMD) <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
KAGA-KOKO authored and bp3tk0v committed Oct 24, 2023
1 parent 11f96ac commit b7fcd99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
16 changes: 1 addition & 15 deletions arch/x86/include/asm/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,8 @@ struct cpu_signature;

void intel_collect_cpu_info(struct cpu_signature *sig);

static inline bool intel_cpu_signatures_match(unsigned int s1, unsigned int p1,
unsigned int s2, unsigned int p2)
{
if (s1 != s2)
return false;

/* Processor flags are either both 0 ... */
if (!p1 && !p2)
return true;

/* ... or they intersect. */
return p1 & p2;
}

extern u64 x86_read_arch_cap_msr(void);
int intel_find_matching_signature(void *mc, unsigned int csig, int cpf);
bool intel_find_matching_signature(void *mc, struct cpu_signature *sig);
int intel_microcode_sanity_check(void *mc, bool print_err, int hdr_type);

extern struct cpumask cpus_stop_mask;
Expand Down
31 changes: 19 additions & 12 deletions arch/x86/kernel/cpu/microcode/intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,36 @@ void intel_collect_cpu_info(struct cpu_signature *sig)
}
EXPORT_SYMBOL_GPL(intel_collect_cpu_info);

/*
* Returns 1 if update has been found, 0 otherwise.
*/
int intel_find_matching_signature(void *mc, unsigned int csig, int cpf)
static inline bool cpu_signatures_match(struct cpu_signature *s1, unsigned int sig2,
unsigned int pf2)
{
if (s1->sig != sig2)
return false;

/* Processor flags are either both 0 or they intersect. */
return ((!s1->pf && !pf2) || (s1->pf & pf2));
}

bool intel_find_matching_signature(void *mc, struct cpu_signature *sig)
{
struct microcode_header_intel *mc_hdr = mc;
struct extended_sigtable *ext_hdr;
struct extended_signature *ext_sig;
struct extended_sigtable *ext_hdr;
int i;

if (intel_cpu_signatures_match(csig, cpf, mc_hdr->sig, mc_hdr->pf))
return 1;
if (cpu_signatures_match(sig, mc_hdr->sig, mc_hdr->pf))
return true;

/* Look for ext. headers: */
if (get_totalsize(mc_hdr) <= intel_microcode_get_datasize(mc_hdr) + MC_HEADER_SIZE)
return 0;
return false;

ext_hdr = mc + intel_microcode_get_datasize(mc_hdr) + MC_HEADER_SIZE;
ext_sig = (void *)ext_hdr + EXT_HEADER_SIZE;

for (i = 0; i < ext_hdr->count; i++) {
if (intel_cpu_signatures_match(csig, cpf, ext_sig->sig, ext_sig->pf))
return 1;
if (cpu_signatures_match(sig, ext_sig->sig, ext_sig->pf))
return true;
ext_sig++;
}
return 0;
Expand Down Expand Up @@ -268,7 +275,7 @@ static __init struct microcode_intel *scan_microcode(void *data, size_t size,
intel_microcode_sanity_check(data, false, MC_HEADER_TYPE_MICROCODE) < 0)
break;

if (!intel_find_matching_signature(data, uci->cpu_sig.sig, uci->cpu_sig.pf))
if (!intel_find_matching_signature(data, &uci->cpu_sig))
continue;

/*
Expand Down Expand Up @@ -512,7 +519,7 @@ static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter)
if (cur_rev >= mc_header.rev)
continue;

if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf))
if (!intel_find_matching_signature(mc, &uci->cpu_sig))
continue;

kvfree(new_mc);
Expand Down
2 changes: 1 addition & 1 deletion drivers/platform/x86/intel/ifs/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static int image_sanity_check(struct device *dev, const struct microcode_header_

intel_collect_cpu_info(&sig);

if (!intel_find_matching_signature((void *)data, sig.sig, sig.pf)) {
if (!intel_find_matching_signature((void *)data, &sig)) {
dev_err(dev, "cpu signature, processor flags not matching\n");
return -EINVAL;
}
Expand Down

0 comments on commit b7fcd99

Please sign in to comment.