@@ -55,7 +55,9 @@ struct cont_desc {
55
55
};
56
56
57
57
static u32 ucode_new_rev ;
58
- static u8 amd_ucode_patch [PATCH_MAX_SIZE ];
58
+
59
+ /* One blob per node. */
60
+ static u8 amd_ucode_patch [MAX_NUMNODES ][PATCH_MAX_SIZE ];
59
61
60
62
/*
61
63
* Microcode patch container file is prepended to the initrd in cpio
@@ -330,8 +332,9 @@ static size_t parse_container(u8 *ucode, size_t size, struct cont_desc *desc)
330
332
ret = verify_patch (x86_family (desc -> cpuid_1_eax ), buf , size , & patch_size , true);
331
333
if (ret < 0 ) {
332
334
/*
333
- * Patch verification failed, skip to the next
334
- * container, if there's one:
335
+ * Patch verification failed, skip to the next container, if
336
+ * there is one. Before exit, check whether that container has
337
+ * found a patch already. If so, use it.
335
338
*/
336
339
goto out ;
337
340
} else if (ret > 0 ) {
@@ -350,6 +353,7 @@ static size_t parse_container(u8 *ucode, size_t size, struct cont_desc *desc)
350
353
size -= patch_size + SECTION_HDR_SIZE ;
351
354
}
352
355
356
+ out :
353
357
/*
354
358
* If we have found a patch (desc->mc), it means we're looking at the
355
359
* container which has a patch for this CPU so return 0 to mean, @ucode
@@ -364,7 +368,6 @@ static size_t parse_container(u8 *ucode, size_t size, struct cont_desc *desc)
364
368
return 0 ;
365
369
}
366
370
367
- out :
368
371
return orig_size - size ;
369
372
}
370
373
@@ -414,8 +417,7 @@ static int __apply_microcode_amd(struct microcode_amd *mc)
414
417
*
415
418
* Returns true if container found (sets @desc), false otherwise.
416
419
*/
417
- static bool
418
- apply_microcode_early_amd (u32 cpuid_1_eax , void * ucode , size_t size , bool save_patch )
420
+ static bool early_apply_microcode (u32 cpuid_1_eax , void * ucode , size_t size , bool save_patch )
419
421
{
420
422
struct cont_desc desc = { 0 };
421
423
u8 (* patch )[PATCH_MAX_SIZE ];
@@ -428,7 +430,7 @@ apply_microcode_early_amd(u32 cpuid_1_eax, void *ucode, size_t size, bool save_p
428
430
patch = (u8 (* )[PATCH_MAX_SIZE ])__pa_nodebug (& amd_ucode_patch );
429
431
#else
430
432
new_rev = & ucode_new_rev ;
431
- patch = & amd_ucode_patch ;
433
+ patch = & amd_ucode_patch [ 0 ] ;
432
434
#endif
433
435
434
436
desc .cpuid_1_eax = cpuid_1_eax ;
@@ -481,7 +483,7 @@ static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)
481
483
return false;
482
484
}
483
485
484
- static void __load_ucode_amd (unsigned int cpuid_1_eax , struct cpio_data * ret )
486
+ static void find_blobs_in_containers (unsigned int cpuid_1_eax , struct cpio_data * ret )
485
487
{
486
488
struct ucode_cpu_info * uci ;
487
489
struct cpio_data cp ;
@@ -511,11 +513,11 @@ void __init load_ucode_amd_bsp(unsigned int cpuid_1_eax)
511
513
{
512
514
struct cpio_data cp = { };
513
515
514
- __load_ucode_amd (cpuid_1_eax , & cp );
516
+ find_blobs_in_containers (cpuid_1_eax , & cp );
515
517
if (!(cp .data && cp .size ))
516
518
return ;
517
519
518
- apply_microcode_early_amd (cpuid_1_eax , cp .data , cp .size , true);
520
+ early_apply_microcode (cpuid_1_eax , cp .data , cp .size , true);
519
521
}
520
522
521
523
void load_ucode_amd_ap (unsigned int cpuid_1_eax )
@@ -546,15 +548,14 @@ void load_ucode_amd_ap(unsigned int cpuid_1_eax)
546
548
}
547
549
}
548
550
549
- __load_ucode_amd (cpuid_1_eax , & cp );
551
+ find_blobs_in_containers (cpuid_1_eax , & cp );
550
552
if (!(cp .data && cp .size ))
551
553
return ;
552
554
553
- apply_microcode_early_amd (cpuid_1_eax , cp .data , cp .size , false);
555
+ early_apply_microcode (cpuid_1_eax , cp .data , cp .size , false);
554
556
}
555
557
556
- static enum ucode_state
557
- load_microcode_amd (bool save , u8 family , const u8 * data , size_t size );
558
+ static enum ucode_state load_microcode_amd (u8 family , const u8 * data , size_t size );
558
559
559
560
int __init save_microcode_in_initrd_amd (unsigned int cpuid_1_eax )
560
561
{
@@ -572,19 +573,19 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)
572
573
if (!desc .mc )
573
574
return - EINVAL ;
574
575
575
- ret = load_microcode_amd (true, x86_family (cpuid_1_eax ), desc .data , desc .size );
576
+ ret = load_microcode_amd (x86_family (cpuid_1_eax ), desc .data , desc .size );
576
577
if (ret > UCODE_UPDATED )
577
578
return - EINVAL ;
578
579
579
580
return 0 ;
580
581
}
581
582
582
- void reload_ucode_amd (void )
583
+ void reload_ucode_amd (unsigned int cpu )
583
584
{
584
- struct microcode_amd * mc ;
585
585
u32 rev , dummy __always_unused ;
586
+ struct microcode_amd * mc ;
586
587
587
- mc = (struct microcode_amd * )amd_ucode_patch ;
588
+ mc = (struct microcode_amd * )amd_ucode_patch [ cpu_to_node ( cpu )] ;
588
589
589
590
rdmsr (MSR_AMD64_PATCH_LEVEL , rev , dummy );
590
591
@@ -816,6 +817,7 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover,
816
817
return 0 ;
817
818
}
818
819
820
+ /* Scan the blob in @data and add microcode patches to the cache. */
819
821
static enum ucode_state __load_microcode_amd (u8 family , const u8 * data ,
820
822
size_t size )
821
823
{
@@ -850,9 +852,10 @@ static enum ucode_state __load_microcode_amd(u8 family, const u8 *data,
850
852
return UCODE_OK ;
851
853
}
852
854
853
- static enum ucode_state
854
- load_microcode_amd (bool save , u8 family , const u8 * data , size_t size )
855
+ static enum ucode_state load_microcode_amd (u8 family , const u8 * data , size_t size )
855
856
{
857
+ struct cpuinfo_x86 * c ;
858
+ unsigned int nid , cpu ;
856
859
struct ucode_patch * p ;
857
860
enum ucode_state ret ;
858
861
@@ -865,22 +868,22 @@ load_microcode_amd(bool save, u8 family, const u8 *data, size_t size)
865
868
return ret ;
866
869
}
867
870
868
- p = find_patch (0 );
869
- if (!p ) {
870
- return ret ;
871
- } else {
872
- if (boot_cpu_data .microcode >= p -> patch_id )
873
- return ret ;
871
+ for_each_node (nid ) {
872
+ cpu = cpumask_first (cpumask_of_node (nid ));
873
+ c = & cpu_data (cpu );
874
874
875
- ret = UCODE_NEW ;
876
- }
875
+ p = find_patch (cpu );
876
+ if (!p )
877
+ continue ;
877
878
878
- /* save BSP's matching patch for early load */
879
- if (!save )
880
- return ret ;
879
+ if (c -> microcode >= p -> patch_id )
880
+ continue ;
881
881
882
- memset (amd_ucode_patch , 0 , PATCH_MAX_SIZE );
883
- memcpy (amd_ucode_patch , p -> data , min_t (u32 , p -> size , PATCH_MAX_SIZE ));
882
+ ret = UCODE_NEW ;
883
+
884
+ memset (& amd_ucode_patch [nid ], 0 , PATCH_MAX_SIZE );
885
+ memcpy (& amd_ucode_patch [nid ], p -> data , min_t (u32 , p -> size , PATCH_MAX_SIZE ));
886
+ }
884
887
885
888
return ret ;
886
889
}
@@ -905,14 +908,9 @@ static enum ucode_state request_microcode_amd(int cpu, struct device *device)
905
908
{
906
909
char fw_name [36 ] = "amd-ucode/microcode_amd.bin" ;
907
910
struct cpuinfo_x86 * c = & cpu_data (cpu );
908
- bool bsp = c -> cpu_index == boot_cpu_data .cpu_index ;
909
911
enum ucode_state ret = UCODE_NFOUND ;
910
912
const struct firmware * fw ;
911
913
912
- /* reload ucode container only on the boot cpu */
913
- if (!bsp )
914
- return UCODE_OK ;
915
-
916
914
if (c -> x86 >= 0x15 )
917
915
snprintf (fw_name , sizeof (fw_name ), "amd-ucode/microcode_amd_fam%.2xh.bin" , c -> x86 );
918
916
@@ -925,7 +923,7 @@ static enum ucode_state request_microcode_amd(int cpu, struct device *device)
925
923
if (!verify_container (fw -> data , fw -> size , false))
926
924
goto fw_release ;
927
925
928
- ret = load_microcode_amd (bsp , c -> x86 , fw -> data , fw -> size );
926
+ ret = load_microcode_amd (c -> x86 , fw -> data , fw -> size );
929
927
930
928
fw_release :
931
929
release_firmware (fw );
0 commit comments