Skip to content

Commit 5335ba5

Browse files
committed
x86, microcode, AMD: Fix early ucode loading
The original idea to use the microcode cache for the APs doesn't pan out because we do memory allocation there very early and with IRQs disabled and we don't want to involve GFP_ATOMIC allocations. Not if it can be helped. Thus, extend the caching of the BSP patch approach to the APs and iterate over the ucode in the initrd instead of using the cache. We still save the relevant patches to it but later, right before we jettison the initrd. While at it, fix early ucode loading on 32-bit too. Signed-off-by: Borislav Petkov <[email protected]> Tested-by: Aravind Gopalakrishnan <[email protected]>
1 parent e1b43e3 commit 5335ba5

File tree

3 files changed

+170
-89
lines changed

3 files changed

+170
-89
lines changed

arch/x86/include/asm/microcode_amd.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ extern int __apply_microcode_amd(struct microcode_amd *mc_amd);
6161
extern int apply_microcode_amd(int cpu);
6262
extern enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size);
6363

64+
#define PATCH_MAX_SIZE PAGE_SIZE
65+
extern u8 amd_ucode_patch[PATCH_MAX_SIZE];
66+
6467
#ifdef CONFIG_MICROCODE_AMD_EARLY
65-
#ifdef CONFIG_X86_32
66-
#define MPB_MAX_SIZE PAGE_SIZE
67-
extern u8 amd_bsp_mpb[MPB_MAX_SIZE];
68-
#endif
6968
extern void __init load_ucode_amd_bsp(void);
7069
extern void load_ucode_amd_ap(void);
7170
extern int __init save_microcode_in_initrd_amd(void);

arch/x86/kernel/microcode_amd.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ int __apply_microcode_amd(struct microcode_amd *mc_amd)
182182
{
183183
u32 rev, dummy;
184184

185-
wrmsrl(MSR_AMD64_PATCH_LOADER, (u64)(long)&mc_amd->hdr.data_code);
185+
native_wrmsrl(MSR_AMD64_PATCH_LOADER, (u64)(long)&mc_amd->hdr.data_code);
186186

187187
/* verify patch application was successful */
188-
rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
188+
native_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
189189
if (rev != mc_amd->hdr.patch_id)
190190
return -1;
191191

@@ -332,6 +332,9 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)
332332
patch->patch_id = mc_hdr->patch_id;
333333
patch->equiv_cpu = proc_id;
334334

335+
pr_debug("%s: Added patch_id: 0x%08x, proc_id: 0x%04x\n",
336+
__func__, patch->patch_id, proc_id);
337+
335338
/* ... and add to cache. */
336339
update_cache(patch);
337340

@@ -390,9 +393,9 @@ enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size)
390393
if (cpu_data(smp_processor_id()).cpu_index == boot_cpu_data.cpu_index) {
391394
struct ucode_patch *p = find_patch(smp_processor_id());
392395
if (p) {
393-
memset(amd_bsp_mpb, 0, MPB_MAX_SIZE);
394-
memcpy(amd_bsp_mpb, p->data, min_t(u32, ksize(p->data),
395-
MPB_MAX_SIZE));
396+
memset(amd_ucode_patch, 0, PATCH_MAX_SIZE);
397+
memcpy(amd_ucode_patch, p->data, min_t(u32, ksize(p->data),
398+
PATCH_MAX_SIZE));
396399
}
397400
}
398401
#endif

0 commit comments

Comments
 (0)