Skip to content

Commit 164aa1c

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/microcode/intel: Rework intel_cpu_collect_info()
Nothing needs struct ucode_cpu_info. Make it take struct cpu_signature, let it return a boolean and simplify the implementation. Rename it now that the silly name clash with collect_cpu_info() is gone. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231017211722.851573238@linutronix.de
1 parent 3973718 commit 164aa1c

3 files changed

Lines changed: 14 additions & 31 deletions

File tree

arch/x86/include/asm/cpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ static inline void init_ia32_feat_ctl(struct cpuinfo_x86 *c) {}
7171

7272
extern __noendbr void cet_disable(void);
7373

74-
struct ucode_cpu_info;
74+
struct cpu_signature;
7575

76-
int intel_cpu_collect_info(struct ucode_cpu_info *uci);
76+
void intel_collect_cpu_info(struct cpu_signature *sig);
7777

7878
static inline bool intel_cpu_signatures_match(unsigned int s1, unsigned int p1,
7979
unsigned int s2, unsigned int p2)

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,36 +68,21 @@ static inline unsigned int exttable_size(struct extended_sigtable *et)
6868
return et->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE;
6969
}
7070

71-
int intel_cpu_collect_info(struct ucode_cpu_info *uci)
71+
void intel_collect_cpu_info(struct cpu_signature *sig)
7272
{
73-
unsigned int val[2];
74-
unsigned int family, model;
75-
struct cpu_signature csig = { 0 };
76-
unsigned int eax, ebx, ecx, edx;
77-
78-
memset(uci, 0, sizeof(*uci));
79-
80-
eax = 0x00000001;
81-
ecx = 0;
82-
native_cpuid(&eax, &ebx, &ecx, &edx);
83-
csig.sig = eax;
73+
sig->sig = cpuid_eax(1);
74+
sig->pf = 0;
75+
sig->rev = intel_get_microcode_revision();
8476

85-
family = x86_family(eax);
86-
model = x86_model(eax);
77+
if (x86_model(sig->sig) >= 5 || x86_family(sig->sig) > 6) {
78+
unsigned int val[2];
8779

88-
if (model >= 5 || family > 6) {
8980
/* get processor flags from MSR 0x17 */
9081
native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
91-
csig.pf = 1 << ((val[1] >> 18) & 7);
82+
sig->pf = 1 << ((val[1] >> 18) & 7);
9283
}
93-
94-
csig.rev = intel_get_microcode_revision();
95-
96-
uci->cpu_sig = csig;
97-
98-
return 0;
9984
}
100-
EXPORT_SYMBOL_GPL(intel_cpu_collect_info);
85+
EXPORT_SYMBOL_GPL(intel_collect_cpu_info);
10186

10287
/*
10388
* Returns 1 if update has been found, 0 otherwise.
@@ -391,7 +376,7 @@ static __init struct microcode_intel *get_microcode_blob(struct ucode_cpu_info *
391376
if (!(cp.data && cp.size))
392377
return NULL;
393378

394-
intel_cpu_collect_info(uci);
379+
intel_collect_cpu_info(&uci->cpu_sig);
395380

396381
return scan_microcode(cp.data, cp.size, uci, save);
397382
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static int scan_chunks_sanity_check(struct device *dev)
227227

228228
static int image_sanity_check(struct device *dev, const struct microcode_header_intel *data)
229229
{
230-
struct ucode_cpu_info uci;
230+
struct cpu_signature sig;
231231

232232
/* Provide a specific error message when loading an older/unsupported image */
233233
if (data->hdrver != MC_HEADER_TYPE_IFS) {
@@ -240,11 +240,9 @@ static int image_sanity_check(struct device *dev, const struct microcode_header_
240240
return -EINVAL;
241241
}
242242

243-
intel_cpu_collect_info(&uci);
243+
intel_collect_cpu_info(&sig);
244244

245-
if (!intel_find_matching_signature((void *)data,
246-
uci.cpu_sig.sig,
247-
uci.cpu_sig.pf)) {
245+
if (!intel_find_matching_signature((void *)data, sig.sig, sig.pf)) {
248246
dev_err(dev, "cpu signature, processor flags not matching\n");
249247
return -EINVAL;
250248
}

0 commit comments

Comments
 (0)