Skip to content

Commit 42a7f6e

Browse files
committed
Merge tag 'x86_microcode_for_v6.6_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 microcode loading updates from Borislav Petkov: "The first, cleanup part of the microcode loader reorg tglx has been working on. The other part wasn't fully ready in time so it will follow on later. This part makes the loader core code as it is practically enabled on pretty much every baremetal machine so there's no need to have the Kconfig items. In addition, there are cleanups which prepare for future feature enablement" * tag 'x86_microcode_for_v6.6_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/microcode: Remove remaining references to CONFIG_MICROCODE_AMD x86/microcode/intel: Remove pointless mutex x86/microcode/intel: Remove debug code x86/microcode: Move core specific defines to local header x86/microcode/intel: Rename get_datasize() since its used externally x86/microcode: Make reload_early_microcode() static x86/microcode: Include vendor headers into microcode.h x86/microcode/intel: Move microcode functions out of cpu/intel.c x86/microcode: Hide the config knob x86/mm: Remove unused microcode.h include x86/microcode: Remove microcode_mutex x86/microcode/AMD: Rip out static buffers
2 parents f31f663 + 4d2b748 commit 42a7f6e

File tree

15 files changed

+470
-652
lines changed

15 files changed

+470
-652
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,44 +1308,8 @@ config X86_REBOOTFIXUPS
13081308
Say N otherwise.
13091309

13101310
config MICROCODE
1311-
bool "CPU microcode loading support"
1312-
default y
1311+
def_bool y
13131312
depends on CPU_SUP_AMD || CPU_SUP_INTEL
1314-
help
1315-
If you say Y here, you will be able to update the microcode on
1316-
Intel and AMD processors. The Intel support is for the IA32 family,
1317-
e.g. Pentium Pro, Pentium II, Pentium III, Pentium 4, Xeon etc. The
1318-
AMD support is for families 0x10 and later. You will obviously need
1319-
the actual microcode binary data itself which is not shipped with
1320-
the Linux kernel.
1321-
1322-
The preferred method to load microcode from a detached initrd is described
1323-
in Documentation/arch/x86/microcode.rst. For that you need to enable
1324-
CONFIG_BLK_DEV_INITRD in order for the loader to be able to scan the
1325-
initrd for microcode blobs.
1326-
1327-
In addition, you can build the microcode into the kernel. For that you
1328-
need to add the vendor-supplied microcode to the CONFIG_EXTRA_FIRMWARE
1329-
config option.
1330-
1331-
config MICROCODE_INTEL
1332-
bool "Intel microcode loading support"
1333-
depends on CPU_SUP_INTEL && MICROCODE
1334-
default MICROCODE
1335-
help
1336-
This options enables microcode patch loading support for Intel
1337-
processors.
1338-
1339-
For the current Intel microcode data package go to
1340-
<https://downloadcenter.intel.com> and search for
1341-
'Linux Processor Microcode Data File'.
1342-
1343-
config MICROCODE_AMD
1344-
bool "AMD microcode loading support"
1345-
depends on CPU_SUP_AMD && MICROCODE
1346-
help
1347-
If you select this option, microcode patch loading support for AMD
1348-
processors will be enabled.
13491313

13501314
config MICROCODE_LATE_LOADING
13511315
bool "Late microcode loading (DANGEROUS)"

arch/x86/configs/i386_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ CONFIG_HYPERVISOR_GUEST=y
3333
CONFIG_PARAVIRT=y
3434
CONFIG_NR_CPUS=8
3535
CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS=y
36-
CONFIG_MICROCODE_AMD=y
3736
CONFIG_X86_MSR=y
3837
CONFIG_X86_CPUID=y
3938
CONFIG_X86_CHECK_BIOS_CORRUPTION=y

arch/x86/configs/x86_64_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ CONFIG_SMP=y
3131
CONFIG_HYPERVISOR_GUEST=y
3232
CONFIG_PARAVIRT=y
3333
CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS=y
34-
CONFIG_MICROCODE_AMD=y
3534
CONFIG_X86_MSR=y
3635
CONFIG_X86_CPUID=y
3736
CONFIG_NUMA=y

arch/x86/include/asm/microcode.h

Lines changed: 51 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -2,138 +2,83 @@
22
#ifndef _ASM_X86_MICROCODE_H
33
#define _ASM_X86_MICROCODE_H
44

5-
#include <asm/cpu.h>
6-
#include <linux/earlycpio.h>
7-
#include <linux/initrd.h>
8-
#include <asm/microcode_amd.h>
9-
10-
struct ucode_patch {
11-
struct list_head plist;
12-
void *data; /* Intel uses only this one */
13-
unsigned int size;
14-
u32 patch_id;
15-
u16 equiv_cpu;
16-
};
17-
18-
extern struct list_head microcode_cache;
19-
205
struct cpu_signature {
216
unsigned int sig;
227
unsigned int pf;
238
unsigned int rev;
249
};
2510

26-
struct device;
27-
28-
enum ucode_state {
29-
UCODE_OK = 0,
30-
UCODE_NEW,
31-
UCODE_UPDATED,
32-
UCODE_NFOUND,
33-
UCODE_ERROR,
11+
struct ucode_cpu_info {
12+
struct cpu_signature cpu_sig;
13+
void *mc;
3414
};
3515

36-
struct microcode_ops {
37-
enum ucode_state (*request_microcode_fw) (int cpu, struct device *);
38-
39-
void (*microcode_fini_cpu) (int cpu);
16+
#ifdef CONFIG_MICROCODE
17+
void load_ucode_bsp(void);
18+
void load_ucode_ap(void);
19+
void microcode_bsp_resume(void);
20+
#else
21+
static inline void load_ucode_bsp(void) { }
22+
static inline void load_ucode_ap(void) { }
23+
static inline void microcode_bsp_resume(void) { }
24+
#endif
4025

41-
/*
42-
* The generic 'microcode_core' part guarantees that
43-
* the callbacks below run on a target cpu when they
44-
* are being called.
45-
* See also the "Synchronization" section in microcode_core.c.
46-
*/
47-
enum ucode_state (*apply_microcode) (int cpu);
48-
int (*collect_cpu_info) (int cpu, struct cpu_signature *csig);
26+
#ifdef CONFIG_CPU_SUP_INTEL
27+
/* Intel specific microcode defines. Public for IFS */
28+
struct microcode_header_intel {
29+
unsigned int hdrver;
30+
unsigned int rev;
31+
unsigned int date;
32+
unsigned int sig;
33+
unsigned int cksum;
34+
unsigned int ldrver;
35+
unsigned int pf;
36+
unsigned int datasize;
37+
unsigned int totalsize;
38+
unsigned int metasize;
39+
unsigned int reserved[2];
4940
};
5041

51-
struct ucode_cpu_info {
52-
struct cpu_signature cpu_sig;
53-
void *mc;
42+
struct microcode_intel {
43+
struct microcode_header_intel hdr;
44+
unsigned int bits[];
5445
};
55-
extern struct ucode_cpu_info ucode_cpu_info[];
56-
struct cpio_data find_microcode_in_initrd(const char *path, bool use_pa);
5746

58-
#ifdef CONFIG_MICROCODE_INTEL
59-
extern struct microcode_ops * __init init_intel_microcode(void);
60-
#else
61-
static inline struct microcode_ops * __init init_intel_microcode(void)
62-
{
63-
return NULL;
64-
}
65-
#endif /* CONFIG_MICROCODE_INTEL */
47+
#define DEFAULT_UCODE_DATASIZE (2000)
48+
#define MC_HEADER_SIZE (sizeof(struct microcode_header_intel))
49+
#define MC_HEADER_TYPE_MICROCODE 1
50+
#define MC_HEADER_TYPE_IFS 2
6651

67-
#ifdef CONFIG_MICROCODE_AMD
68-
extern struct microcode_ops * __init init_amd_microcode(void);
69-
extern void __exit exit_amd_microcode(void);
70-
#else
71-
static inline struct microcode_ops * __init init_amd_microcode(void)
52+
static inline int intel_microcode_get_datasize(struct microcode_header_intel *hdr)
7253
{
73-
return NULL;
54+
return hdr->datasize ? : DEFAULT_UCODE_DATASIZE;
7455
}
75-
static inline void __exit exit_amd_microcode(void) {}
76-
#endif
7756

78-
#define MAX_UCODE_COUNT 128
79-
80-
#define QCHAR(a, b, c, d) ((a) + ((b) << 8) + ((c) << 16) + ((d) << 24))
81-
#define CPUID_INTEL1 QCHAR('G', 'e', 'n', 'u')
82-
#define CPUID_INTEL2 QCHAR('i', 'n', 'e', 'I')
83-
#define CPUID_INTEL3 QCHAR('n', 't', 'e', 'l')
84-
#define CPUID_AMD1 QCHAR('A', 'u', 't', 'h')
85-
#define CPUID_AMD2 QCHAR('e', 'n', 't', 'i')
86-
#define CPUID_AMD3 QCHAR('c', 'A', 'M', 'D')
87-
88-
#define CPUID_IS(a, b, c, ebx, ecx, edx) \
89-
(!((ebx ^ (a))|(edx ^ (b))|(ecx ^ (c))))
90-
91-
/*
92-
* In early loading microcode phase on BSP, boot_cpu_data is not set up yet.
93-
* x86_cpuid_vendor() gets vendor id for BSP.
94-
*
95-
* In 32 bit AP case, accessing boot_cpu_data needs linear address. To simplify
96-
* coding, we still use x86_cpuid_vendor() to get vendor id for AP.
97-
*
98-
* x86_cpuid_vendor() gets vendor information directly from CPUID.
99-
*/
100-
static inline int x86_cpuid_vendor(void)
57+
static inline u32 intel_get_microcode_revision(void)
10158
{
102-
u32 eax = 0x00000000;
103-
u32 ebx, ecx = 0, edx;
59+
u32 rev, dummy;
10460

105-
native_cpuid(&eax, &ebx, &ecx, &edx);
61+
native_wrmsrl(MSR_IA32_UCODE_REV, 0);
10662

107-
if (CPUID_IS(CPUID_INTEL1, CPUID_INTEL2, CPUID_INTEL3, ebx, ecx, edx))
108-
return X86_VENDOR_INTEL;
63+
/* As documented in the SDM: Do a CPUID 1 here */
64+
native_cpuid_eax(1);
10965

110-
if (CPUID_IS(CPUID_AMD1, CPUID_AMD2, CPUID_AMD3, ebx, ecx, edx))
111-
return X86_VENDOR_AMD;
66+
/* get the current revision from MSR 0x8B */
67+
native_rdmsr(MSR_IA32_UCODE_REV, dummy, rev);
11268

113-
return X86_VENDOR_UNKNOWN;
69+
return rev;
11470
}
11571

116-
static inline unsigned int x86_cpuid_family(void)
117-
{
118-
u32 eax = 0x00000001;
119-
u32 ebx, ecx = 0, edx;
120-
121-
native_cpuid(&eax, &ebx, &ecx, &edx);
72+
void show_ucode_info_early(void);
12273

123-
return x86_family(eax);
124-
}
74+
#else /* CONFIG_CPU_SUP_INTEL */
75+
static inline void show_ucode_info_early(void) { }
76+
#endif /* !CONFIG_CPU_SUP_INTEL */
12577

126-
#ifdef CONFIG_MICROCODE
127-
extern void __init load_ucode_bsp(void);
128-
extern void load_ucode_ap(void);
129-
void reload_early_microcode(unsigned int cpu);
130-
extern bool initrd_gone;
131-
void microcode_bsp_resume(void);
132-
#else
133-
static inline void __init load_ucode_bsp(void) { }
134-
static inline void load_ucode_ap(void) { }
135-
static inline void reload_early_microcode(unsigned int cpu) { }
136-
static inline void microcode_bsp_resume(void) { }
78+
#ifdef CONFIG_CPU_SUP_AMD
79+
void amd_check_microcode(void);
80+
#else /* CONFIG_CPU_SUP_AMD */
81+
static inline void amd_check_microcode(void) {}
13782
#endif
13883

13984
#endif /* _ASM_X86_MICROCODE_H */

arch/x86/include/asm/microcode_amd.h

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)