Skip to content

Commit c0a717f

Browse files
committed
x86, microcode, AMD: Fix ucode patch stashing on 32-bit
Save the patch while we're running on the BSP instead of later, before the initrd has been jettisoned. More importantly, on 32-bit we need to access the physical address instead of the virtual. This way we actually do find it on the APs instead of having to go through the initrd each time. Tested-by: Richard Hendershot <rshendershot@mchsi.com> Fixes: 5335ba5 ("x86, microcode, AMD: Fix early ucode loading") Cc: <stable@vger.kernel.org> # v3.13+ Signed-off-by: Borislav Petkov <bp@suse.de>
1 parent 85be07c commit c0a717f

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

‎arch/x86/kernel/cpu/microcode/amd_early.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ static size_t compute_container_size(u8 *data, u32 total_size)
108108
* load_microcode_amd() to save equivalent cpu table and microcode patches in
109109
* kernel heap memory.
110110
*/
111-
static void apply_ucode_in_initrd(void *ucode, size_t size)
111+
static void apply_ucode_in_initrd(void *ucode, size_t size, bool save_patch)
112112
{
113113
struct equiv_cpu_entry *eq;
114114
size_t *cont_sz;
115115
u32 *header;
116116
u8 *data, **cont;
117+
u8 (*patch)[PATCH_MAX_SIZE];
117118
u16 eq_id = 0;
118119
int offset, left;
119120
u32 rev, eax, ebx, ecx, edx;
@@ -123,10 +124,12 @@ static void apply_ucode_in_initrd(void *ucode, size_t size)
123124
new_rev = (u32 *)__pa_nodebug(&ucode_new_rev);
124125
cont_sz = (size_t *)__pa_nodebug(&container_size);
125126
cont = (u8 **)__pa_nodebug(&container);
127+
patch = (u8 (*)[PATCH_MAX_SIZE])__pa_nodebug(&amd_ucode_patch);
126128
#else
127129
new_rev = &ucode_new_rev;
128130
cont_sz = &container_size;
129131
cont = &container;
132+
patch = &amd_ucode_patch;
130133
#endif
131134

132135
data = ucode;
@@ -213,9 +216,9 @@ static void apply_ucode_in_initrd(void *ucode, size_t size)
213216
rev = mc->hdr.patch_id;
214217
*new_rev = rev;
215218

216-
/* save ucode patch */
217-
memcpy(amd_ucode_patch, mc,
218-
min_t(u32, header[1], PATCH_MAX_SIZE));
219+
if (save_patch)
220+
memcpy(patch, mc,
221+
min_t(u32, header[1], PATCH_MAX_SIZE));
219222
}
220223
}
221224

@@ -246,7 +249,7 @@ void __init load_ucode_amd_bsp(void)
246249
*data = cp.data;
247250
*size = cp.size;
248251

249-
apply_ucode_in_initrd(cp.data, cp.size);
252+
apply_ucode_in_initrd(cp.data, cp.size, true);
250253
}
251254

252255
#ifdef CONFIG_X86_32
@@ -263,7 +266,7 @@ void load_ucode_amd_ap(void)
263266
size_t *usize;
264267
void **ucode;
265268

266-
mc = (struct microcode_amd *)__pa(amd_ucode_patch);
269+
mc = (struct microcode_amd *)__pa_nodebug(amd_ucode_patch);
267270
if (mc->hdr.patch_id && mc->hdr.processor_rev_id) {
268271
__apply_microcode_amd(mc);
269272
return;
@@ -275,7 +278,7 @@ void load_ucode_amd_ap(void)
275278
if (!*ucode || !*usize)
276279
return;
277280

278-
apply_ucode_in_initrd(*ucode, *usize);
281+
apply_ucode_in_initrd(*ucode, *usize, false);
279282
}
280283

281284
static void __init collect_cpu_sig_on_bsp(void *arg)
@@ -339,14 +342,15 @@ void load_ucode_amd_ap(void)
339342
* AP has a different equivalence ID than BSP, looks like
340343
* mixed-steppings silicon so go through the ucode blob anew.
341344
*/
342-
apply_ucode_in_initrd(ucode_cpio.data, ucode_cpio.size);
345+
apply_ucode_in_initrd(ucode_cpio.data, ucode_cpio.size, false);
343346
}
344347
}
345348
#endif
346349

347350
int __init save_microcode_in_initrd_amd(void)
348351
{
349352
unsigned long cont;
353+
int retval = 0;
350354
enum ucode_state ret;
351355
u8 *cont_va;
352356
u32 eax;
@@ -387,7 +391,7 @@ int __init save_microcode_in_initrd_amd(void)
387391

388392
ret = load_microcode_amd(eax, container, container_size);
389393
if (ret != UCODE_OK)
390-
return -EINVAL;
394+
retval = -EINVAL;
391395

392396
/*
393397
* This will be freed any msec now, stash patches for the current
@@ -396,5 +400,5 @@ int __init save_microcode_in_initrd_amd(void)
396400
container = NULL;
397401
container_size = 0;
398402

399-
return 0;
403+
return retval;
400404
}

0 commit comments

Comments
 (0)