W dniu 24.11.2018 o 14:15, Hauke Mehrtens pisze:
> On 11/20/18 5:20 PM, Tomasz Maciej Nowak wrote:
>> Create initrd enries for x86 images, that'll load intel microcode as
>> early as possible. To achieve that the test module for grub is enabled
>> which provides shell-like conditionals. Also restrict the late load of
>> microcode to AMD processors.
>>
>> Signed-off-by: Tomasz Maciej Nowak <tome...@o2.pl>
>> ---
>>  target/linux/x86/base-files/lib/preinit/02_load_x86_ucode | 6 ++++--
>>  target/linux/x86/image/Makefile                           | 4 ++--
>>  target/linux/x86/image/grub-iso.cfg                       | 3 +++
>>  target/linux/x86/image/grub.cfg                           | 3 +++
>>  4 files changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode 
>> b/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
>> index fb309c75c1..d3a23e24b2 100644
>> --- a/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
>> +++ b/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
>> @@ -2,8 +2,10 @@
>>  # Copyright (C) 2018 OpenWrt.org
>>  
>>  do_load_x86_ucode() {
>> -    if [ -e "/sys/devices/system/cpu/microcode/reload" ]; then
>> -            echo 1 > /sys/devices/system/cpu/microcode/reload
>> +    if grep -q AuthenticAMD /proc/cpuinfo; then
>> +            if [ -e "/sys/devices/system/cpu/microcode/reload" ]; then
>> +                    echo 1 > /sys/devices/system/cpu/microcode/reload
>> +            fi
> 
> Are we sure that the early loading always works on Intel systems?

Yes, it does. If the kernel options regarding loading microcode are enabled, 
which in our case are, kernel always scans memory for it. You might want to 
check a better explanation written here: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/Documentation/x86/microcode.txt

> What happens when we try to load the microcode here again?

If the microcode loaded early has the same version or newer - nothing.
If the version loaded early was older, it will update the microcode if the one 
being in /lib/firmware/intel-ucode is newer. This is the output:

[tomek@vaio-vpcz1 ~]$ dmesg | grep -i microcode
[    0.000000] microcode: microcode updated early to revision 0x4, date = 
2013-06-28
[    0.902645] microcode: sig=0x20655, pf=0x10, revision=0x4
[    0.902689] microcode: Microcode Update Driver: v2.2.
[    8.221820] microcode: updated to revision 0x7, date = 2018-04-23
[    8.222165] x86/CPU: CPU features have changed after loading microcode, but 
might not take effect.

> 
>>      fi
>>  }
>>  
>> diff --git a/target/linux/x86/image/Makefile 
>> b/target/linux/x86/image/Makefile
>> index dbf8a8594b..f8c3700d32 100644
>> --- a/target/linux/x86/image/Makefile
>> +++ b/target/linux/x86/image/Makefile
>> @@ -9,8 +9,8 @@ include $(INCLUDE_DIR)/image.mk
>>  
>>  export PATH=$(TARGET_PATH):/sbin
>>  
>> -GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos 
>> reboot serial vga
>> -GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls 
>> part_msdos reboot serial vga
>> +GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos 
>> reboot serial test vga
>> +GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls 
>> part_msdos reboot serial test vga
> 
> Is test needed to support "if"?
> 
>>  GRUB_TERMINALS =
>>  GRUB_SERIAL_CONFIG =
>>  GRUB_TERMINAL_CONFIG =
>> diff --git a/target/linux/x86/image/grub-iso.cfg 
>> b/target/linux/x86/image/grub-iso.cfg
>> index 9c59bdf6d4..5d128aa3aa 100644
>> --- a/target/linux/x86/image/grub-iso.cfg
>> +++ b/target/linux/x86/image/grub-iso.cfg
>> @@ -7,4 +7,7 @@ set root='(cd)'
>>  
>>  menuentry "@TITLE@" {
>>      linux /boot/vmlinuz @CMDLINE@ noinitrd
>> +    if [ -s /boot/intel-ucode.img ]; then
>> +            initrd /boot/intel-ucode.img
>> +    fi
>>  }
>> diff --git a/target/linux/x86/image/grub.cfg 
>> b/target/linux/x86/image/grub.cfg
>> index dedfa0a636..a665686863 100644
>> --- a/target/linux/x86/image/grub.cfg
>> +++ b/target/linux/x86/image/grub.cfg
>> @@ -7,6 +7,9 @@ set root='(@ROOT@)'
>>  
>>  menuentry "@TITLE@" {
>>      linux /boot/vmlinuz @CMDLINE@ noinitrd
>> +    if [ -s /boot/intel-ucode.img ]; then
>> +            initrd /boot/intel-ucode.img
>> +    fi
>>  }
>>  menuentry "@TITLE@ (failsafe)" {
>>      linux /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd
>>
> 
> 

-- 
TMN

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to