Skip to content

Commit b7fcd99

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/microcode/intel: Rework intel_find_matching_signature()
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 <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231002115902.797820205@linutronix.de
1 parent 11f96ac commit b7fcd99

3 files changed

Lines changed: 21 additions & 28 deletions

File tree

arch/x86/include/asm/cpu.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,8 @@ struct cpu_signature;
7575

7676
void intel_collect_cpu_info(struct cpu_signature *sig);
7777

78-
static inline bool intel_cpu_signatures_match(unsigned int s1, unsigned int p1,
79-
unsigned int s2, unsigned int p2)
80-
{
81-
if (s1 != s2)
82-
return false;
83-
84-
/* Processor flags are either both 0 ... */
85-
if (!p1 && !p2)
86-
return true;
87-
88-
/* ... or they intersect. */
89-
return p1 & p2;
90-
}
91-
9278
extern u64 x86_read_arch_cap_msr(void);
93-
int intel_find_matching_signature(void *mc, unsigned int csig, int cpf);
79+
bool intel_find_matching_signature(void *mc, struct cpu_signature *sig);
9480
int intel_microcode_sanity_check(void *mc, bool print_err, int hdr_type);
9581

9682
extern struct cpumask cpus_stop_mask;

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,36 @@ void intel_collect_cpu_info(struct cpu_signature *sig)
8484
}
8585
EXPORT_SYMBOL_GPL(intel_collect_cpu_info);
8686

87-
/*
88-
* Returns 1 if update has been found, 0 otherwise.
89-
*/
90-
int intel_find_matching_signature(void *mc, unsigned int csig, int cpf)
87+
static inline bool cpu_signatures_match(struct cpu_signature *s1, unsigned int sig2,
88+
unsigned int pf2)
89+
{
90+
if (s1->sig != sig2)
91+
return false;
92+
93+
/* Processor flags are either both 0 or they intersect. */
94+
return ((!s1->pf && !pf2) || (s1->pf & pf2));
95+
}
96+
97+
bool intel_find_matching_signature(void *mc, struct cpu_signature *sig)
9198
{
9299
struct microcode_header_intel *mc_hdr = mc;
93-
struct extended_sigtable *ext_hdr;
94100
struct extended_signature *ext_sig;
101+
struct extended_sigtable *ext_hdr;
95102
int i;
96103

97-
if (intel_cpu_signatures_match(csig, cpf, mc_hdr->sig, mc_hdr->pf))
98-
return 1;
104+
if (cpu_signatures_match(sig, mc_hdr->sig, mc_hdr->pf))
105+
return true;
99106

100107
/* Look for ext. headers: */
101108
if (get_totalsize(mc_hdr) <= intel_microcode_get_datasize(mc_hdr) + MC_HEADER_SIZE)
102-
return 0;
109+
return false;
103110

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

107114
for (i = 0; i < ext_hdr->count; i++) {
108-
if (intel_cpu_signatures_match(csig, cpf, ext_sig->sig, ext_sig->pf))
109-
return 1;
115+
if (cpu_signatures_match(sig, ext_sig->sig, ext_sig->pf))
116+
return true;
110117
ext_sig++;
111118
}
112119
return 0;
@@ -268,7 +275,7 @@ static __init struct microcode_intel *scan_microcode(void *data, size_t size,
268275
intel_microcode_sanity_check(data, false, MC_HEADER_TYPE_MICROCODE) < 0)
269276
break;
270277

271-
if (!intel_find_matching_signature(data, uci->cpu_sig.sig, uci->cpu_sig.pf))
278+
if (!intel_find_matching_signature(data, &uci->cpu_sig))
272279
continue;
273280

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

515-
if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf))
522+
if (!intel_find_matching_signature(mc, &uci->cpu_sig))
516523
continue;
517524

518525
kvfree(new_mc);

drivers/platform/x86/intel/ifs/load.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static int image_sanity_check(struct device *dev, const struct microcode_header_
242242

243243
intel_collect_cpu_info(&sig);
244244

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

0 commit comments

Comments
 (0)