[LEDE-DEV,v2,5/6] x86: add intel microcode entries to grub config

Message ID 20180417185005.5810-6-tomek_n@o2.pl
State New
Headers show
Series
  • intel-microcode: load as early as possible
Related show

Commit Message

Tomasz Maciej Nowak April 17, 2018, 6:50 p.m.
Create initrd enries for x86 images, that'll load intel microcode as
early as possible. Also restrict the late load of microcode to AMD
processors.

Signed-off-by: Tomasz Maciej Nowak <tomek_n@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(-)

Comments

Philip Prindeville April 17, 2018, 10:51 p.m. | #1
Is there a downside to forcing AMD to also do early firmware updates?



> On Apr 17, 2018, at 12:50 PM, Tomasz Maciej Nowak <tomek_n@o2.pl> wrote:
> 
> Create initrd enries for x86 images, that'll load intel microcode as
> early as possible. Also restrict the late load of microcode to AMD
> processors.
> 
> Signed-off-by: Tomasz Maciej Nowak <tomek_n@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
> 	fi
> }
> 
> diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
> index cf1e1a9edf..523c07eb75 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
> 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 3d47a95a4b..30b587bd1c 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 "OpenWrt" {
> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
> +	if [ -e /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 9ec6b2d39c..dde24b95ce 100644
> --- a/target/linux/x86/image/grub.cfg
> +++ b/target/linux/x86/image/grub.cfg
> @@ -7,6 +7,9 @@ set root='(@ROOT@)'
> 
> menuentry "OpenWrt" {
> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
> +	if [ -e /boot/intel-ucode.img ]; then
> +		initrd /boot/intel-ucode.img
> +	fi
> }
> menuentry "OpenWrt (failsafe)" {
> 	linux /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd
> -- 
> 2.17.0
>
Tomasz Maciej Nowak April 19, 2018, 9:47 a.m. | #2
W dniu 18.04.2018 o 00:51, Philip Prindeville pisze:
> Is there a downside to forcing AMD to also do early firmware updates?

AFAIK there shouldn't be any for either methods regarding AMD. I made 
also a prototype for AMD, but as there are no downsides for current 
method and I don't have any hardware to test it, it's being left out.

> 
> 
> 
>> On Apr 17, 2018, at 12:50 PM, Tomasz Maciej Nowak <tomek_n@o2.pl> wrote:
>>
>> Create initrd enries for x86 images, that'll load intel microcode as
>> early as possible. Also restrict the late load of microcode to AMD
>> processors.
>>
>> Signed-off-by: Tomasz Maciej Nowak <tomek_n@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
>> 	fi
>> }
>>
>> diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
>> index cf1e1a9edf..523c07eb75 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
>> 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 3d47a95a4b..30b587bd1c 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 "OpenWrt" {
>> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
>> +	if [ -e /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 9ec6b2d39c..dde24b95ce 100644
>> --- a/target/linux/x86/image/grub.cfg
>> +++ b/target/linux/x86/image/grub.cfg
>> @@ -7,6 +7,9 @@ set root='(@ROOT@)'
>>
>> menuentry "OpenWrt" {
>> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
>> +	if [ -e /boot/intel-ucode.img ]; then
>> +		initrd /boot/intel-ucode.img
>> +	fi
>> }
>> menuentry "OpenWrt (failsafe)" {
>> 	linux /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd
>> -- 
>> 2.17.0
>>
> 
> 
> _______________________________________________
> Lede-dev mailing list
> Lede-dev@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/lede-dev
>
Stijn Segers April 19, 2018, 10:16 p.m. | #3
Op do, 19 apr 2018 om 11:47 , schreef Tomasz Maciej Nowak 
<tomek_n@o2.pl>:
> W dniu 18.04.2018 o 00:51, Philip Prindeville pisze:
> > Is there a downside to forcing AMD to also do early firmware 
> updates?
> 
> AFAIK there shouldn't be any for either methods regarding AMD. I made
> also a prototype for AMD, but as there are no downsides for current
> method and I don't have any hardware to test it, it's being left out.

Hi Tomasz,

I have an AMD system I can test on, so if you can provide a 'generic' 
patch, I'd be happy to try it.

Cheers

Stijn


> 
> >
> >
> >
> >> On Apr 17, 2018, at 12:50 PM, Tomasz Maciej Nowak <tomek_n@o2.pl> 
> wrote:
> >>
> >> Create initrd enries for x86 images, that'll load intel microcode 
> as
> >> early as possible. Also restrict the late load of microcode to AMD
> >> processors.
> >>
> >> Signed-off-by: Tomasz Maciej Nowak <tomek_n@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
> >> 	fi
> >> }
> >>
> >> diff --git a/target/linux/x86/image/Makefile 
> b/target/linux/x86/image/Makefile
> >> index cf1e1a9edf..523c07eb75 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
> >> 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 3d47a95a4b..30b587bd1c 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 "OpenWrt" {
> >> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
> >> +	if [ -e /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 9ec6b2d39c..dde24b95ce 100644
> >> --- a/target/linux/x86/image/grub.cfg
> >> +++ b/target/linux/x86/image/grub.cfg
> >> @@ -7,6 +7,9 @@ set root='(@ROOT@)'
> >>
> >> menuentry "OpenWrt" {
> >> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
> >> +	if [ -e /boot/intel-ucode.img ]; then
> >> +		initrd /boot/intel-ucode.img
> >> +	fi
> >> }
> >> menuentry "OpenWrt (failsafe)" {
> >> 	linux /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd
> >> --
> >> 2.17.0
> >>
> >
> >
> > _______________________________________________
> > Lede-dev mailing list
> > Lede-dev@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/lede-dev
> >
> 
> --
> TMN
> 
> _______________________________________________
> Lede-dev mailing list
> Lede-dev@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/lede-dev
Tomasz Maciej Nowak April 24, 2018, 12:56 p.m. | #4
Hi Stijn.

Go ahead and test it. Had to convert Makefile to use cpio instead of
$(LINUX_DIR)/usr/gen_init_cpio, because gen_init_cpio is built after
packages. The packaging of microcode follows loosely what's in
Documentation/x86/microcode.txt of kernel tree. This series needs to be
applied on top of 'intel-microcode: load as early as possible' series.

Tomasz Maciej Nowak (2):
  x86: add amd microcode entries to grub config
  amd64-microcode: create early load microcode image

 package/firmware/amd64-microcode/Makefile            | 10 ++++++++--
 .../x86/base-files/lib/preinit/02_load_x86_ucode     | 12 ------------
 target/linux/x86/image/grub-iso.cfg                  |  3 +++
 target/linux/x86/image/grub.cfg                      |  3 +++
 4 files changed, 14 insertions(+), 14 deletions(-)
 delete mode 100644 target/linux/x86/base-files/lib/preinit/02_load_x86_ucode

Patch

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
 	fi
 }
 
diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
index cf1e1a9edf..523c07eb75 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
 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 3d47a95a4b..30b587bd1c 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 "OpenWrt" {
 	linux /boot/vmlinuz @CMDLINE@ noinitrd
+	if [ -e /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 9ec6b2d39c..dde24b95ce 100644
--- a/target/linux/x86/image/grub.cfg
+++ b/target/linux/x86/image/grub.cfg
@@ -7,6 +7,9 @@  set root='(@ROOT@)'
 
 menuentry "OpenWrt" {
 	linux /boot/vmlinuz @CMDLINE@ noinitrd
+	if [ -e /boot/intel-ucode.img ]; then
+		initrd /boot/intel-ucode.img
+	fi
 }
 menuentry "OpenWrt (failsafe)" {
 	linux /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd