x86/microcode: Support builtin CPU microcode
v2 cover x86/microcode: Support builtin CPU microcode
The main goal of this patch series is to add support for builtin microcode. Towards that end, the series starts with a few improvements for the documentation and parsing of the ucode= Xen command line parameter that controls early loading of microcode (Patches 1--3), and follows with the main builtin suppot (Patch 4).
Changes in v2:
- An earlier version of Patch 4 was submitted in isolation. Refer to the patch itself for details regarding the relevant changes.
- Patches 1--3 are additions.
Eslam Elnikety (4):
x86/microcode: Improve documentation and parsing for ucode= x86/microcode: avoid unnecessary xmalloc/memcpy of ucode data x86/microcode: use const qualifier for microcode buffer x86/microcode: Support builtin CPU microcode
docs/admin-guide/microcode-loading.rst | 31 ++++++ docs/misc/xen-command-line.pandoc | 26 +++-- xen/arch/x86/Kconfig | 30 ++++++ xen/arch/x86/Makefile | 1 + xen/arch/x86/microcode.c | 139 ++++++++++++++----------- xen/arch/x86/microcode/Makefile | 46 ++++++++ xen/arch/x86/xen.lds.S | 12 +++ 7 files changed, 221 insertions(+), 64 deletions(-) create mode 100644 xen/arch/x86/microcode/Makefile
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/4 x86/microcode: Improve documentation and parsing for ucode=
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using <integer> | scan along xen.efi. With that, Xen can explicitly ignore those named options when using EFI. As an added benefit, we get a straightfoward parsing of the ucode parameter. While at it, simplify the logic in microcode_grab_module().
Update the command line documentation for consistency. Also, drop the leading comment for parse_ucode_param. (No practical use for it given this commit).
--- docs/misc/xen-command-line.pandoc | 18 ++++++++--- xen/arch/x86/microcode.c | 51 ++++++++++++++----------------- 2 files changed, 36 insertions(+), 33 deletions(-)
docs/misc/xen-command-line.pandoc +13 -5
@@ -2128,7 +2128,13 @@ logic applies: ### ucode (x86) > `= List of [ <integer> | scan=<bool>, nmi=<bool> ]` -Specify how and where to find CPU microcode update blob. + Applicability: x86 + Default: `nmi` + +Controls for CPU microcode loading. For early loading, this parameter can +specify how and where to find the microcode update blob. For late loading, +this parameter specifies if the update happens within a NMI handler or in +a stop_machine context. 'integer' specifies the CPU microcode update blob module index. When positive, this specifies the n-th module (in the GrUB entry, zero based) to be used
@@ -2136,10 +2142,7 @@ for updating CPU micrcode. When negative, counting starts at the end of the modules in the GrUB entry (so with the blob commonly being last, one could specify `ucode=-1`). Note that the value of zero is not valid here (entry zero, i.e. the first module, is always the Dom0 kernel -image). Note further that use of this option has an unspecified effect -when used with xen.efi (there the concept of modules doesn't exist, and -the blob gets specified via the `ucode=<filename>` config file/section -entry; see [EFI configuration file description](efi.html)). +image). 'scan' instructs the hypervisor to scan the multiboot images for an cpio image that contains microcode. Depending on the platform the blob with the
@@ -2151,6 +2154,11 @@ microcode in the cpio name space must be: stop_machine context. In NMI handler, even NMIs are blocked, which is considered safer. The default value is `true`. +Note: When booting via EFI, both options 'integer' and 'scan' are ignored. +Here, the concept of modules does not exist. The microcode update blob for +early loading gets specified via the `ucode=<filename>` config file/section +entry; see [EFI configuration file description](efi.html)). + ### unrestricted_guest (Intel) > `= <boolean>`
xen/arch/x86/microcode.c +23 -28
85 lines not on this page · raw message
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.
... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
Quoted 2 lines
As an added benefit,
we get a straightfoward parsing of the ucode parameter.
It's a single if() you eliminate - for me this doesn't make it meaningfully more straightforward.
Quoted 4 lines
docs/misc/xen-command-line.pandoc +0
-0@@ -2128,7 +2128,13 @@ logic applies: ### ucode (x86)
docs/misc/xen-command-line.pandoc logic applies: · line 2137
Quoted 10 lines
docs/misc/xen-command-line.pandoc +7
-1> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]` -Specify how and where to find CPU microcode update blob. + Applicability: x86 + Default: `nmi` + +Controls for CPU microcode loading. For early loading, this parameter can +specify how and where to find the microcode update blob. For late loading, +this parameter specifies if the update happens within a NMI handler or in +a stop_machine context.
It's always stop_machine context, isn't it? I also don't think this implementation detail belongs here.
xen/arch/x86/microcode.c line 63
Quoted 8 lines
xen/arch/x86/microcode.c +1
-1@@ -60,7 +60,7 @@static module_t __initdata ucode_mod;static signed int __initdata ucode_mod_idx; -static bool_t __initdata ucode_mod_forced; +static signed int __initdata ucode_mod_efi_idx;
I don't see anything negative be put into here - should be unsigned int then.
xen/arch/x86/microcode.c static struct microcode_patch *microcode_cache; · line 108
Quoted 7 lines
xen/arch/x86/microcode.c +1
-2@@ -105,16 +105,10 @@ static struct microcode_patch *microcode_cache;void __init microcode_set_module (unsigned int idx) { - ucode_mod_idx = idx; - ucode_mod_forced =1 ; + ucode_mod_efi_idx = idx;
Is it guaranteed (now and forever) that the index passed in is non-zero? You changes to microcode_grab_module() imply so, but just looking at the call site of the function I can't convince myself this is the case. _If_ it is (thought to be) guaranteed, then I think you at least want to ASSERT() here, perhaps with a comment.
xen/arch/x86/microcode.c static struct microcode_patch *microcode_cache; · line 111
Quoted 9 lines
xen/arch/x86/microcode.c +1
-6} -/* -* The format is '[<integer>|scan=<bool>, nmi=<bool>]'. Both options are -* optional. If the EFI has forced which of the multiboot payloads is to be -* used, only nmi=<bool> is parsed. -*/ -static int __init parse_ucode (const char *s) +static int __init parse_ucode_param (const char *s)
Any particular reason for the renaming? The function name was quite fine imo.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.
Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.
With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
Quoted 6 lines
Quoted 2 lines
As an added benefit,
we get a straightfoward parsing of the ucode parameter.It's a single
if()you eliminate - for me this doesn't make it meaningfully more straightforward.
As we decouple ucode_mod_idx and ucode_mod_efi_idx, the parsing of the ucode= just follows the pattern "[ <integer> | scan=<bool>, nmi=<bool> ]" and it does not have to cater for corner cases. In either case, if you strongly disagree with the wording, I can drop that sentence.
Quoted 6 lines
Quoted 6 lines
docs/misc/xen-command-line.pandoc +0
-0@@ -2128,7 +2128,13 @@ logic applies: ### ucode (x86) > `= List of [ <integer> | scan=<bool>, nmi=<bool> ]`
Quoted 12 lines
docs/misc/xen-command-line.pandoc logic applies: · line 2137
Quoted 8 lines
docs/misc/xen-command-line.pandoc +7
-1-Specify how and where to find CPU microcode update blob. + Applicability: x86 + Default: `nmi` + +Controls for CPU microcode loading. For early loading, this parameter can +specify how and where to find the microcode update blob. For late loading, +this parameter specifies if the update happens within a NMI handler or in +a stop_machine context.It's always
stop_machinecontext, isn't it? I also don't think this implementation detail belongs here.
Needs a better wording indeed. Let me know if you have particular suggestions, and I will incorporate in v3.
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/microcode.c +0
-0@@ -60,7 +60,7 @@
Quoted 8 lines
xen/arch/x86/microcode.c line 63
Quoted 4 lines
xen/arch/x86/microcode.c +1
-1static module_t __initdata ucode_mod;static signed int __initdata ucode_mod_idx; -static bool_t __initdata ucode_mod_forced; +static signed int __initdata ucode_mod_efi_idx;I don't see anything negative be put into here - should be unsigned int then.
Correct! The type just carried over from the coupling with ucode_mod_idx. Will adjust in v3.
Quoted 15 lines
xen/arch/x86/microcode.c static struct microcode_patch *microcode_cache; · line 108
Quoted 7 lines
xen/arch/x86/microcode.c +1
-2@@ -105,16 +105,10 @@ static struct microcode_patch *microcode_cache;void __init microcode_set_module (unsigned int idx) { - ucode_mod_idx = idx; - ucode_mod_forced =1 ; + ucode_mod_efi_idx = idx;Is it guaranteed (now and forever) that the index passed in is non-zero? You changes to
microcode_grab_module()imply so, but just looking at the call site of the function I can't convince myself this is the case. _If_ it is (thought to be) guaranteed, then I think you at least want toASSERT()here, perhaps with a comment.
For x86, it seems we have that guarantee (given that we must have a dom0). Right?
Quoted 13 lines
xen/arch/x86/microcode.c static struct microcode_patch *microcode_cache; · line 111
Quoted 9 lines
xen/arch/x86/microcode.c +1
-6} -/* -* The format is '[<integer>|scan=<bool>, nmi=<bool>]'. Both options are -* optional. If the EFI has forced which of the multiboot payloads is to be -* used, only nmi=<bool> is parsed. -*/ -static int __init parse_ucode (const char *s) +static int __init parse_ucode_param (const char *s)Any particular reason for the renaming? The function name was quite fine imo.
To me, "parse_ucode" is a misnomer.
Thanks for your comments, Jan.
-- Eslam
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Quoted 16 lines · Eslam Elnikety
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
Quoted 7 lines
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
But isn't it rather that ucode=scan could (and hence perhaps should) also have its value on EFI?
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
As an added benefit,
we get a straightfoward parsing of the ucode parameter.It's a single
if()you eliminate - for me this doesn't make it meaningfully more straightforward.As we decouple
ucode_mod_idxanducode_mod_efi_idx, the parsing of the ucode= just follows the pattern "[ <integer> | scan=<bool>, nmi=<bool> ]" and it does not have to cater for corner cases. In either case, if you strongly disagree with the wording, I can drop that sentence.
Well, what I don't like is giving the impression that things have been worse than they actually are.
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
docs/misc/xen-command-line.pandoc +0
-0@@ -2128,7 +2128,13 @@ logic applies: ### ucode (x86) > `= List of [ <integer> | scan=<bool>, nmi=<bool> ]`Quoted 12 lines
docs/misc/xen-command-line.pandoc logic applies: · line 2137
Quoted 8 lines
docs/misc/xen-command-line.pandoc +7
-1-Specify how and where to find CPU microcode update blob. + Applicability: x86 + Default: `nmi` + +Controls for CPU microcode loading. For early loading, this parameter can +specify how and where to find the microcode update blob. For late loading, +this parameter specifies if the update happens within a NMI handler or in +a stop_machine context.It's always
stop_machinecontext, isn't it? I also don't think this implementation detail belongs here.
Quoted 2 lines
Needs a better wording indeed. Let me know if you have particular suggestions, and I will incorporate in v3.
Just drop everything from "or" onwards?
Quoted 16 lines
Quoted 15 lines
docs/misc/xen-command-line.pandoc static struct microcode_patch *microcode_cache; · line 108
Quoted 7 lines
docs/misc/xen-command-line.pandoc +1
-2@@ -105,16 +105,10 @@ static struct microcode_patch *microcode_cache; void __init microcode_set_module(unsigned int idx) { - ucode_mod_idx = idx; - ucode_mod_forced = 1; + ucode_mod_efi_idx = idx;Is it guaranteed (now and forever) that the index passed in is non-zero? You changes to
microcode_grab_module()imply so, but just looking at the call site of the function I can't convince myself this is the case. _If_ it is (thought to be) guaranteed, then I think you at least want toASSERT()here, perhaps with a comment.
Quoted 2 lines
For x86, it seems we have that guarantee (given that we must have a dom0). Right?
For fully bringing up the system - yes. But there's no reason to have a Dom0 if all you're after is testing early Xen boot. There'll be a panic() in the case, but there shouldn't be anything breaking proper behavior prior to this point.
Quoted 14 lines
Quoted 13 lines
docs/misc/xen-command-line.pandoc static struct microcode_patch *microcode_cache; · line 111
Quoted 9 lines
docs/misc/xen-command-line.pandoc +1
-6} -/* - * The format is '[<integer>|scan=<bool>, nmi=<bool>]'. Both options are - * optional. If the EFI has forced which of the multiboot payloads is to be - * used, only nmi=<bool> is parsed. - */ -static int __init parse_ucode(const char *s) +static int __init parse_ucode_param(const char *s)Any particular reason for the renaming? The function name was quite fine imo.
Quoted 1 line
To me, "
parse_ucode" is a misnomer.
Well, parse_"ucode= isn't a valid identifier. parse_ucode is what results when stripping everything that makes it invalid. I can see the ambiguity with parsing actual ucode, but the context here makes it pretty clear what the function is about. Personally I'd prefer such unnecessary renames to be avoided.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Picking this up again after the break. Apologies for the delay.
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Eslam Elnikety
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.
Quoted 6 lines
Quoted 2 lines
With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
But isn't it rather that ucode=scan could (and hence perhaps should) also have its value on EFI?
I do not see "ucode=scan" applicable in anyway in the case of EFI. In EFI, there are not "modules" to scan through, but rather the efi config points exactly to the microcode blob.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 4 lines
docs/misc/xen-command-line.pandoc +0
-0@@ -2128,7 +2128,13 @@ logic applies: ### ucode (x86)docs/misc/xen-command-line.pandoc logic applies: · line 2137
Quoted 10 lines
docs/misc/xen-command-line.pandoc +7
-1> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]` -Specify how and where to find CPU microcode update blob. + Applicability: x86 + Default: `nmi` + +Controls for CPU microcode loading. For early loading, this parameter can +specify how and where to find the microcode update blob. For late loading, +this parameter specifies if the update happens within a NMI handler or in +a stop_machine context.It's always
stop_machinecontext, isn't it? I also don't think this implementation detail belongs here.
Quoted 5 lines
Quoted 2 lines
Needs a better wording indeed. Let me know if you have particular suggestions, and I will incorporate in v3.
Just drop everything from "or" onwards?
Ack
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
docs/misc/xen-command-line.pandoc static struct microcode_patch *microcode_cache; · line 108
Quoted 7 lines
docs/misc/xen-command-line.pandoc +1
-2@@ -105,16 +105,10 @@ static struct microcode_patch *microcode_cache; void __init microcode_set_module(unsigned int idx) { - ucode_mod_idx = idx; - ucode_mod_forced = 1; + ucode_mod_efi_idx = idx;Is it guaranteed (now and forever) that the index passed in is non-zero? You changes to
microcode_grab_module()imply so, but just looking at the call site of the function I can't convince myself this is the case. _If_ it is (thought to be) guaranteed, then I think you at least want toASSERT()here, perhaps with a comment.
Quoted 8 lines
Quoted 2 lines
For x86, it seems we have that guarantee (given that we must have a dom0). Right?
For fully bringing up the system - yes. But there's no reason to have a Dom0 if all you're after is testing early Xen boot. There'll be a
panic()in the case, but there shouldn't be anything breaking proper behavior prior to this point.
That's a valid point indeed. v3 will handle index being zero.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
docs/misc/xen-command-line.pandoc static struct microcode_patch *microcode_cache; · line 111
Quoted 9 lines
docs/misc/xen-command-line.pandoc +1
-6} -/* - * The format is '[<integer>|scan=<bool>, nmi=<bool>]'. Both options are - * optional. If the EFI has forced which of the multiboot payloads is to be - * used, only nmi=<bool> is parsed. - */ -static int __init parse_ucode(const char *s) +static int __init parse_ucode_param(const char *s)Any particular reason for the renaming? The function name was quite fine imo.
Quoted 7 lines
Quoted 1 line
To me, "
parse_ucode" is a misnomer.Well, parse_"ucode= isn't a valid identifier.
parse_ucodeis what results when stripping everything that makes it invalid. I can see the ambiguity with parsing actual ucode, but the context here makes it pretty clear what the function is about. Personally I'd prefer such unnecessary renames to be avoided.
Ack
-- Eslam
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Quoted 26 lines · Eslam Elnikety
Quoted 25 lines · Jan Beulich
Quoted 23 lines · Eslam Elnikety
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
Quoted 7 lines
Quoted 3 lines
But isn't it rather that ucode=scan could (and hence perhaps should) also have its value on EFI?
I do not see "ucode=scan" applicable in anyway in the case of EFI. In EFI, there are not "modules" to scan through, but rather the efi config points exactly to the microcode blob.
What would be wrong with the EFI code to also inspect whatever has been specified with ramdisk= if there was no ucode= ?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Eslam Elnikety
Quoted 28 lines · Jan Beulich
Quoted 16 lines · Eslam Elnikety
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
Quoted 7 lines
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
But isn't it rather that ucode=scan could (and hence perhaps should) also have its value on EFI?
Quoted 9 lines
Quoted 3 lines
I do not see "ucode=scan" applicable in anyway in the case of EFI. In EFI, there are not "modules" to scan through, but rather the efi config points exactly to the microcode blob.
What would be wrong with the EFI code to also inspect whatever has been specified with ramdisk= if there was no ucode= ?
Jan
I see, interesting. This sounds like a legitimate use case indeed. I wonder, would I be breaking anything if I simply allow the existing code that iterates over modules to kick in when ucode=scan irrespective of EFI or legacy boot? Also, it seems to me that the ucode= specified by efi.cfg would take precedence over the ucode=scan. Do not you think?
Eslam
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Quoted 36 lines · Eslam Elnikety
Quoted 35 lines · Jan Beulich
Quoted 33 lines · Eslam Elnikety
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Eslam Elnikety
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.Quoted 6 lines
Quoted 2 lines
With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
But isn't it rather that ucode=scan could (and hence perhaps should) also have its value on EFI?
I do not see "ucode=scan" applicable in anyway in the case of EFI. In EFI, there are not "modules" to scan through, but rather the efi config points exactly to the microcode blob.
Quoted 7 lines
Quoted 2 lines
What would be wrong with the EFI code to also inspect whatever has been specified with ramdisk= if there was no ucode= ?
I see, interesting. This sounds like a legitimate use case indeed. I wonder, would I be breaking anything if I simply allow the existing code that iterates over modules to kick in when ucode=scan irrespective of EFI or legacy boot?
I don't think so, no, but it would need double checking (and mentioning in the description and/or documentation).
Quoted 2 lines
Also, it seems to me that the ucode= specified by
efi.cfg would take precedence over the ucode=scan. Do not you think?
I guess we need to settle on what we want to take precedence and then make sure code also behaves this way. But yes, I think ucode= from the .cfg should supersede ucode=scan on the command line. A possibly useful adjustment to this might be to distinguish whether the ucode=scan was in a specific .cfg section while the ucode= was in [global] (i.e. sort of a default), in which case maybe the ucode=scan should win. Thoughts?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Quoted 59 lines · Jan Beulich
Quoted 36 lines · Eslam Elnikety
Quoted 35 lines · Jan Beulich
Quoted 33 lines · Eslam Elnikety
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Eslam Elnikety
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.Quoted 6 lines
Quoted 2 lines
With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
But isn't it rather that ucode=scan could (and hence perhaps should) also have its value on EFI?
I do not see "ucode=scan" applicable in anyway in the case of EFI. In EFI, there are not "modules" to scan through, but rather the efi config points exactly to the microcode blob.
Quoted 7 lines
Quoted 2 lines
What would be wrong with the EFI code to also inspect whatever has been specified with ramdisk= if there was no ucode= ?
I see, interesting. This sounds like a legitimate use case indeed. I wonder, would I be breaking anything if I simply allow the existing code that iterates over modules to kick in when ucode=scan irrespective of EFI or legacy boot?
I don't think so, no, but it would need double checking (and mentioning in the description and/or documentation).
Quoted 2 lines
Also, it seems to me that the ucode= specified by
efi.cfg would take precedence over the ucode=scan. Do not you think?I guess we need to settle on what we want to take precedence and then make sure code also behaves this way. But yes, I think ucode= from the .cfg should supersede ucode=scan on the command line. A possibly useful adjustment to this might be to distinguish whether the ucode=scan was in a specific .cfg section while the ucode= was in [global] (i.e. sort of a default), in which case maybe the ucode=scan should win. Thoughts?
Quoted 2 lines
Jan
I think any ucode= in the EFI .cfg ought to supersede the ucode=scan. The semantics are simpler in this case, rather than having to worry about where exactly the ucode= was specified in the EFI .cfg. With that, an administrator would default to using ucode=scan on the commandline to load the ramdisk microcode, and a ucode= in .cfg would be an explicit signal to use different microcode.
Eslam
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
Quoted 60 lines · Eslam Elnikety
Quoted 59 lines · Jan Beulich
Quoted 36 lines · Eslam Elnikety
Quoted 35 lines · Jan Beulich
Quoted 33 lines · Eslam Elnikety
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Eslam Elnikety
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.Quoted 6 lines
Quoted 2 lines
With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
But isn't it rather that ucode=scan could (and hence perhaps should) also have its value on EFI?
I do not see "ucode=scan" applicable in anyway in the case of EFI. In EFI, there are not "modules" to scan through, but rather the efi config points exactly to the microcode blob.
Quoted 7 lines
Quoted 2 lines
What would be wrong with the EFI code to also inspect whatever has been specified with ramdisk= if there was no ucode= ?
I see, interesting. This sounds like a legitimate use case indeed. I wonder, would I be breaking anything if I simply allow the existing code that iterates over modules to kick in when ucode=scan irrespective of EFI or legacy boot?
I don't think so, no, but it would need double checking (and mentioning in the description and/or documentation).
Quoted 2 lines
Also, it seems to me that the ucode= specified by
efi.cfg would take precedence over the ucode=scan. Do not you think?I guess we need to settle on what we want to take precedence and then make sure code also behaves this way. But yes, I think ucode= from the .cfg should supersede ucode=scan on the command line. A possibly useful adjustment to this might be to distinguish whether the ucode=scan was in a specific .cfg section while the ucode= was in [global] (i.e. sort of a default), in which case maybe the ucode=scan should win. Thoughts?
Quoted 7 lines
Quoted 2 lines
Jan
I think any ucode= in the EFI .cfg ought to supersede the ucode=scan. The semantics are simpler in this case, rather than having to worry about where exactly the ucode= was specified in the EFI .cfg. With that, an administrator would default to using ucode=scan on the commandline to load the ramdisk microcode, and a ucode= in .cfg would be an explicit signal to use different microcode.
Eslam
So that happens to be the existing behaviour already :)
I was under the impression that ucode=scan was simply ignored under EFI. That's not the case. It is only ignored if ucode=<filename> is specified in the EFI config. In other words, what we had just discussed above is already the case. This clearly needs spelling out in the documentation, which is the first patch in the "x86/microcode: Improve documentation and code" series I have sent just now.
Cheers,
Eslam
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and parsing for ucode=
In reply to Jan BeulichQuoted 40 lines · Jan Beulich
Quoted 39 lines · Eslam Elnikety
Quoted 37 lines · Jan Beulich
Quoted 26 lines · Eslam Elnikety
Quoted 25 lines · Jan Beulich
Quoted 23 lines · Eslam Elnikety
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Eslam Elnikety
Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using
<integer> | scanalong xen.efi.Quoted 9 lines
I guess "unspecified effect" in the doc was pretty pointless - such options have been ignored before; in fact ...
Quoted 2 lines
With that, Xen can explicitly
ignore those named options when using EFI.... I don't see things becoming any more explicit (not even parsing the options was quite explicit to me).
I agree that those options have been ignored so far in the case of EFI. The documentation contradicts that however. The documentation:
* says <integer> has unspecified effect.
* does not mention anything about scan being ignored.With this patch, it is explicit in code and in documentation that both options are ignored in case of EFI.
Quoted 7 lines
Quoted 3 lines
But isn't it rather that ucode=scan could (and hence perhaps should) also have its value on EFI?
I do not see "ucode=scan" applicable in anyway in the case of EFI. In EFI, there are not "modules" to scan through, but rather the efi config points exactly to the microcode blob.
What would be wrong with the EFI code to also inspect whatever has been specified with ramdisk= if there was no ucode= ?
Quoted 7 lines
Quoted 4 lines
I see, interesting. This sounds like a legitimate use case indeed. I wonder, would I be breaking anything if I simply allow the existing code that iterates over modules to kick in when ucode=scan irrespective of EFI or legacy boot?
I don't think so, no, but it would need double checking (and mentioning in the description and/or documentation).
Originally I wanted to have 'ucode=scan' be the default choice. That would have been the easiest choice.
Quoted 12 lines
Quoted 3 lines
Also, it seems to me that the ucode= specified by
efi.cfg would take precedence over the ucode=scan. Do not you think?I guess we need to settle on what we want to take precedence and then make sure code also behaves this way. But yes, I think ucode= from the .cfg should supersede ucode=scan on the command line. A possibly useful adjustment to this might be to distinguish whether the ucode=scan was in a specific .cfg section while the ucode= was in [global] (i.e. sort of a default), in which case maybe the ucode=scan should win. Thoughts?
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/4 x86/microcode: avoid unnecessary xmalloc/memcpy of ucode data
In reply to Eslam ElniketyWhen using ucode=scan and if a matching module is found, the microcode payload is maintained in an xmalloc()'d region. This is unnecessary since the bootmap would just do. Remove the xmalloc and xfree on the microcode module scan path.
This commit also does away with the restriction on the microcode module size limit. The concern that a large microcode module would consume too much memory preventing guests launch is misplaced since this is all the init path. While having such safeguards is valuable, this should apply across the board for all early/late microcode loading. Having it just on the scan path is confusing.
Looking forward, we are a bit closer (i.e., one xmalloc down) to pulling the early microcode loading of the BSP a bit earlier in the early boot process. This commit is the low hanging fruit. There is still a sizable amount of work to get there as there are still a handful of xmalloc in microcode_{amd,intel}.c.
First, there are xmallocs on the path of finding a matching microcode update. Similar to the commit at hand, searching through the microcode blob can be done on the already present buffer with no need to xmalloc any further. Even better, do the filtering in microcode.c before requesting the microcode update on all CPUs. The latter requires careful restructuring and exposing the arch-specific logic for iterating over patches and declaring a match.
Second, there are xmallocs for the microcode cache. Here, we would need to ensure that the cache corresponding to the BSP gets xmalloc()'d and populated after the fact.
--- xen/arch/x86/microcode.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-)
xen/arch/x86/microcode.c +4 -28
@@ -138,11 +138,6 @@ static int __init parse_ucode_param(const char *s) }custom_param ("ucode" , parse_ucode_param); -/* -* 8MB ought to be enough. -*/ -#define MAX_EARLY_CPIO_MICROCODE (8 << 20) -void __init microcode_scan_module (unsigned long *module_map,const multiboot_info_t *mbi)
@@ -187,31 +182,12 @@ void __init microcode_scan_module( cd =find_cpio_data (p, _blob_start, _blob_size, &offset/* ignore */ );if ( cd.data ) { -/* -* This is an arbitrary check - it would be sad if the blob -* consumed most of the memory and did not allow guests -* to launch. -*/ -if ( cd.size >MAX_EARLY_CPIO_MICROCODE ) - { -printk ("Multiboot %d microcode payload too big! (%ld, we can do %d)\n" , - i, cd.size,MAX_EARLY_CPIO_MICROCODE ); - goto err; - } - ucode_blob.size = cd.size; - ucode_blob.data =xmalloc_bytes (cd.size); -if ( !ucode_blob.data ) - cd.data =NULL ; -else -memcpy (ucode_blob.data, cd.data, cd.size); + ucode_blob.size = cd.size; + ucode_blob.data = cd.data; +break ; }bootstrap_map (NULL ); -if ( cd.data ) -break ; } -return ; -err: -bootstrap_map (NULL ); } void __init microcode_grab_module( unsigned long *module_map,
@@ -725,7 +701,7 @@ static int __init microcode_init(void)*/ if ( ucode_blob.size ) { -xfree (ucode_blob.data); +bootstrap_map (NULL ); ucode_blob.size =0 ; ucode_blob.data =NULL ; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/4] x86/microcode: avoid unnecessary xmalloc/memcpy of ucode data
xen/arch/x86/microcode.c static int __init microcode_init(void) · line 704
Quoted 6 lines · Eslam Elnikety
xen/arch/x86/microcode.c +1
-1@@ -725,7 +701,7 @@ static int __init microcode_init(void)*/ if ( ucode_blob.size ) { -xfree (ucode_blob.data); +bootstrap_map (NULL );
As much as I like the change, I wholeheartedly disagree with this aspect of it: You make it largely unpredictable when the boot mappings will go away - it becomes entirely dependent upon link order. And of course we really want these mappings to be gone, the very latest (I think), by the time we start bringing up APs (but generally the sooner the better). This is (one of?) the main reason(s) why it hadn't been done this way to begin with. The alternative is more complicated (set up a proper, long term mapping), but it's going to be more clean (including the mapping then also being suitable to post-boot CPU onlining).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/4] x86/microcode: avoid unnecessary xmalloc/memcpy of ucode data
Quoted 10 lines · Jan Beulich
xen/arch/x86/microcode.c static int __init microcode_init(void) · line 704
Quoted 6 lines · Eslam Elnikety
xen/arch/x86/microcode.c +1
-1@@ -725,7 +701,7 @@ static int __init microcode_init(void)*/ if ( ucode_blob.size ) { -xfree (ucode_blob.data); +bootstrap_map (NULL );As much as I like the change, I wholeheartedly disagree with this aspect of it: You make it largely unpredictable when the boot
Quoted 9 lines
mappings will go away - it becomes entirely dependent upon link order. And of course we really want these mappings to be gone, the very latest (I think), by the time we start bringing up APs (but generally the sooner the better). This is (one of?) the main reason(s) why it hadn't been done this way to begin with. The alternative is more complicated (set up a proper, long term mapping), but it's going to be more clean (including the mapping then also being suitable to post-boot CPU onlining).
This change is an improvement on the current status. We get to avoid xmalloc/memcpy in the case of a successful ucode=scan. The problematic aspect you highlight is anyway there regardless of this patch (ref. to the "else if ( ucode_mod.mod_end )" in microcode_init). The proper, long term mapping would be a welcome change, but is otherwise independent of this patch imo.
Thanks,
Eslam
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Acked-byRe: [Xen-devel] [PATCH v2 2/4] x86/microcode: avoid unnecessary xmalloc/memcpy of ucode data
Quoted 21 lines · Eslam Elnikety
Quoted 10 lines · Jan Beulich
xen/arch/x86/microcode.c static int __init microcode_init(void) · line 704
Quoted 6 lines · Eslam Elnikety
xen/arch/x86/microcode.c +1
-1@@ -725,7 +701,7 @@ static int __init microcode_init(void)*/ if ( ucode_blob.size ) { -xfree (ucode_blob.data); +bootstrap_map (NULL );As much as I like the change, I wholeheartedly disagree with this aspect of it: You make it largely unpredictable when the boot
Quoted 9 lines
mappings will go away - it becomes entirely dependent upon link order. And of course we really want these mappings to be gone, the very latest (I think), by the time we start bringing up APs (but generally the sooner the better). This is (one of?) the main reason(s) why it hadn't been done this way to begin with. The alternative is more complicated (set up a proper, long term mapping), but it's going to be more clean (including the mapping then also being suitable to post-boot CPU onlining).
Quoted 4 lines
This change is an improvement on the current status. We get to avoid xmalloc/memcpy in the case of a successful ucode=scan. The problematic aspect you highlight is anyway there regardless of this patch (ref. to the "else if ( ucode_mod.mod_end )" in
microcode_init).
Hmm, fair point. I'm not a fan of making a bad situation worse, but I think it's acceptable here:
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/4] x86/microcode: avoid unnecessary xmalloc/memcpy of ucode data
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Eslam Elnikety
Quoted 18 lines · Jan Beulich
xen/arch/x86/microcode.c static int __init microcode_init(void) · line 704
Quoted 6 lines · Eslam Elnikety
xen/arch/x86/microcode.c +1
-1@@ -725,7 +701,7 @@ static int __init microcode_init(void)*/ if ( ucode_blob.size ) { -xfree (ucode_blob.data); +bootstrap_map (NULL );As much as I like the change, I wholeheartedly disagree with this aspect of it: You make it largely unpredictable when the boot mappings will go away - it becomes entirely dependent upon link order. And of course we really want these mappings to be gone, the very latest (I think), by the time we start bringing up APs (but generally the sooner the better). This is (one of?) the main reason(s) why it hadn't been done this way to begin with. The alternative is more complicated (set up a proper, long term mapping), but it's going to be more clean (including the mapping then also being suitable to post-boot CPU onlining).
Quoted 7 lines
Quoted 4 lines
This change is an improvement on the current status. We get to avoid xmalloc/memcpy in the case of a successful ucode=scan. The problematic aspect you highlight is anyway there regardless of this patch (ref. to the "else if ( ucode_mod.mod_end )" in
microcode_init).Hmm, fair point. I'm not a fan of making a bad situation worse, but I think it's acceptable here:
Acked-by Jan Beulich <[email protected]>
Specifically relevant to this conversation is point 2 of
https://lore.kernel.org/xen-devel/[email protected]/
where having dynamic bootmap mappings seems pointless when all we're doing is mapping RAM below 4G.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 3/4 x86/microcode: use const qualifier for microcode buffer
In reply to Eslam ElniketyThe buffer holding the microcode bits should be marked as const.
--- xen/arch/x86/microcode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/microcode.c +2 -2
@@ -86,7 +86,7 @@ static enum {* memory. */ struct ucode_mod_blob { -void *data; +const void *data;size_t size; };
@@ -744,7 +744,7 @@ int microcode_update_one(bool start_update)int __init early_microcode_update_cpu (void ) {int rc =0 ; -void *data =NULL ; +const void *data =NULL ;size_t len;struct microcode_patch *patch;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 3/4] x86/microcode: use const qualifier for microcode buffer
Quoted 3 lines · Eslam Elnikety
The buffer holding the microcode bits should be marked as const.
Signed-off-by Eslam Elnikety <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 4/4 x86/microcode: Support builtin CPU microcode
In reply to Eslam ElniketyXen relies on boot modules to perform early microcode updates. This commit adds another mode, namely "builtin" via the BUILTIN_UCODE config parameter. If set, the Xen image itself will contain the microcode updates. Upon boot, Xen inspects its image for microcode blobs and performs the update.
A Xen image with builtin microcode will, by default, attempt the microcode update. Disabling the builtin microcode update can be done via the Xen command line parameter 'ucode=no-builtin'. Moreover, the microcode provided via other options (such as 'ucode=<integer>|scan' or 'ucode=<filename>' config when booting via EFI) takes precedence over the builtin one.
---
Changes in v2:
- Allow for ucode=<integer>|scan,{no-}builtin and detail the model. Reflect those changes onto microcode.c and docs/misc/xen-command-line.pandoc
- Add documentation to the existing docs/admin-guide/microcode-loading.rst
- Build on Patches 1--3 to avoid xmalloc/memcpy for the builtin microcode
- Work configuration in order to specify the individual microcode blobs to use for the builtin microcode, and rework the microcode/Makefile accordingly
--- docs/admin-guide/microcode-loading.rst | 31 +++++++++++++++ docs/misc/xen-command-line.pandoc | 10 ++++- xen/arch/x86/Kconfig | 30 +++++++++++++++ xen/arch/x86/Makefile | 1 + xen/arch/x86/microcode.c | 52 ++++++++++++++++++++++++++ xen/arch/x86/microcode/Makefile | 46 +++++++++++++++++++++++ xen/arch/x86/xen.lds.S | 12 ++++++ 7 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 xen/arch/x86/microcode/Makefile
docs/admin-guide/microcode-loading.rst +31 -0
@@ -104,6 +104,37 @@ The ``ucode=scan`` command line option will cause Xen to search through all modules to find any CPIO archives, and search the archive for the applicable file. Xen will stop searching at the first match. +Loading microcode built within the Xen image +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Xen can bundle microcode updates within its image. This support is conditional +on the build configuration BUILTIN_UCODE being enabled. Builtin microcode is +useful to ensure that, by default, a minimum microcode patch level will be +applied to the underlying CPU. + +To use microcode updates available on the build system as builtin, +use BUILTIN_UCODE_DIR to refer to the directory containing the firmware updates +and specify the individual microcode patches via either BUILTIN_UCODE_AMD or +BUILTIN_UCODE_INTEL for AMD microcode or INTEL microcode, respectively. For +instance, the configuration below is suitable for a build system which has a +``/lib/firmware/`` directory which, in turn, includes the individual microcode +patches ``amd-ucode/microcode_amd_fam15h.bin``, ``intel-ucode/06-3a-09``, and +``intel-ucode/06-2f-02``. + + CONFIG_BUILTIN_UCODE=y + CONFIG_BUILTIN_UCODE_DIR="/lib/firmware/" + CONFIG_BUILTIN_UCODE_AMD="amd-ucode/microcode_amd_fam15h.bin" + CONFIG_BUILTIN_UCODE_INTEL="intel-ucode/06-3a-09 intel-ucode/06-2f-02" + +Alternatively, CONFIG_BUILTIN_UCODE_{AMD,INTEL} can directly point to the +concatenation of the individual microcode blobs. For instance, assuming that +``amd-ucode/AuthenticAMD.bin`` and ``intel-ucode/GenuineIntel.bin`` hold +multiple microcode updates for AMD and INTEL, respectively, you may use the +configuration below. + + CONFIG_BUILTIN_UCODE_AMD="amd-ucode/AuthenticAMD.bin" + CONFIG_BUILTIN_UCODE_INTEL="intel-ucode/GenuineIntel.bin" + Run time microcode loading --------------------------
docs/misc/xen-command-line.pandoc +8 -2
@@ -2126,10 +2126,10 @@ logic applies: active by default. ### ucode (x86) -> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]` +> `= List of [ <integer> | scan=<bool>, builtin=<bool>, nmi=<bool> ]` Applicability: x86 - Default: `nmi` + Default: `nmi` if BUILTIN_UCODE is not enabled, `builtin,nmi` otherwise Controls for CPU microcode loading. For early loading, this parameter can specify how and where to find the microcode update blob. For late loading,
@@ -2150,6 +2150,12 @@ microcode in the cpio name space must be: - on Intel: kernel/x86/microcode/GenuineIntel.bin - on AMD : kernel/x86/microcode/AuthenticAMD.bin +'builtin' instructs the hypervisor to use the builtin microcode update. This +option is available only if option BUILTIN_UCODE is enabled at build. The +default value is `true`. If a microcode is provided via other options (such +as 'integer', 'scan', or `ucode=<filename>` config when booting via EFI), +the provided microcode takes precedence over the builtin one. + 'nmi' determines late loading is performed in NMI handler or just in stop_machine context. In NMI handler, even NMIs are blocked, which is considered safer. The default value is `true`.
xen/arch/x86/Kconfig +30 -0
@@ -218,6 +218,36 @@ config MEM_SHARING bool "Xen memory sharing support" if EXPERT = "y" depends on HVM +config BUILTIN_UCODE + bool "Support for Builtin Microcode" + ---help--- + Include the CPU microcode update in the Xen image itself. With this + support, Xen can update the CPU microcode upon boot using the builtin + microcode, with no need for an additional microcode boot modules. + + If unsure, say N. + +config BUILTIN_UCODE_DIR + string "Directory containing microcode updates" + default "/lib/firmware/" + depends on BUILTIN_UCODE + ---help--- + The directory containing the microcode blobs. + +config BUILTIN_UCODE_AMD + string "AMD microcode updates" + default "" + depends on BUILTIN_UCODE + ---help--- + AMD builtin microcode; space-sparated, relative to BUILTIN_UCODE_DIR. + +config BUILTIN_UCODE_INTEL + string "INTEL microcode updates" + default "" + depends on BUILTIN_UCODE + ---help--- + INTEL builtin microcode; space-sparated, relative to BUILTIN_UCODE_DIR. + endmenu source "common/Kconfig"
xen/arch/x86/Makefile +1 -0
@@ -3,6 +3,7 @@ subdir-y += cpu subdir-y += genapic subdir-$(CONFIG_GUEST) += guest subdir-$(CONFIG_HVM) += hvm +subdir-$(CONFIG_BUILTIN_UCODE) += microcode subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile subdir-$(CONFIG_PV) += pv
xen/arch/x86/microcode.c +52 -0
77 lines not on this page · raw message
xen/arch/x86/microcode/Makefile new file +46 -0
46 lines not on this page · raw message
xen/arch/x86/xen.lds.S +12 -0
@@ -265,6 +265,18 @@ SECTIONS *(SORT(.data.vpci.*)) __end_vpci_array = .; #endif + +#if defined(CONFIG_BUILTIN_UCODE) + . = ALIGN(POINTER_ALIGN); + __builtin_amd_ucode_start = .; + *(.builtin_amd_ucode) + __builtin_amd_ucode_end = .; + + . = ALIGN(POINTER_ALIGN); + __builtin_intel_ucode_start = .; + *(.builtin_intel_ucode) + __builtin_intel_ucode_end = .; +#endif } :text . = ALIGN(SECTION_ALIGN);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 37 lines · Eslam Elnikety
Xen relies on boot modules to perform early microcode updates. This commit adds another mode, namely "builtin" via the
BUILTIN_UCODEconfig parameter. If set, the Xen image itself will contain the microcode updates. Upon boot, Xen inspects its image for microcode blobs and performs the update.A Xen image with builtin microcode will, by default, attempt the microcode update. Disabling the builtin microcode update can be done via the Xen command line parameter 'ucode=no-builtin'. Moreover, the microcode provided via other options (such as 'ucode=<integer>|scan' or 'ucode=<filename>' config when booting via EFI) takes precedence over the builtin one.
Signed-off-by Eslam Elnikety <[email protected]>---
Changes in v2:
- Allow for ucode=<integer>|scan,{no-}builtin and detail the model. Reflect those changes ontomicrocode.cand docs/misc/xen-command-line.pandoc
- Add documentation to the existingdocs/admin-guide/microcode-loading.rst
- Build on Patches 1--3 to avoid xmalloc/memcpy for the builtin microcode
- Work configuration in order to specify the individual microcode blobs to use for the builtin microcode, and rework the microcode/Makefile accordingly--- docs/admin-guide/microcode-loading.rst | 31 +++++++++++++++ docs/misc/xen-command-line.pandoc | 10 ++++- xen/arch/x86/Kconfig | 30 +++++++++++++++ xen/arch/x86/Makefile | 1 + xen/arch/x86/microcode.c | 52 ++++++++++++++++++++++++++ xen/arch/x86/microcode/Makefile | 46 +++++++++++++++++++++++ xen/arch/x86/xen.lds.S | 12 ++++++ 7 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 xen/arch/x86/microcode/Makefiledocs/admin-guide/microcode-loading.rst +0
-0
docs/admin-guide/microcode-loading.rst The ``ucode=scan`` command line option will cause Xen to search through all · line 107
Quoted 4 lines
docs/admin-guide/microcode-loading.rst +1
-0@@ -104,6 +104,37 @@ The ``ucode=scan`` command line option will cause Xen to search through all modules to find any CPIO archives, and search the archive for the applicable file. Xen will stop searching at the first match. +Loading microcode built within the Xen image
I think either s/within/into/ or e.g. s/built/contained/.
Quoted 10 lines
docs/admin-guide/microcode-loading.rst +10
-0+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Xen can bundle microcode updates within its image. This support is conditional +on the build configuration BUILTIN_UCODE being enabled. Builtin microcode is +useful to ensure that, by default, a minimum microcode patch level will be +applied to the underlying CPU. + +To use microcode updates available on the build system as builtin, +use BUILTIN_UCODE_DIR to refer to the directory containing the firmware updates +and specify the individual microcode patches via either BUILTIN_UCODE_AMD or
docs/admin-guide/microcode-loading.rst The ``ucode=scan`` command line option will cause Xen to search through all · line 127
Quoted 10 lines
docs/admin-guide/microcode-loading.rst +10
-0+BUILTIN_UCODE_INTEL for AMD microcode or INTEL microcode, respectively. For +instance, the configuration below is suitable for a build system which has a +``/lib/firmware/`` directory which, in turn, includes the individual microcode +patches ``amd-ucode/microcode_amd_fam15h.bin``, ``intel-ucode/06-3a-09``, and +``intel-ucode/06-2f-02``. + + CONFIG_BUILTIN_UCODE=y + CONFIG_BUILTIN_UCODE_DIR="/lib/firmware/" + CONFIG_BUILTIN_UCODE_AMD="amd-ucode/microcode_amd_fam15h.bin" + CONFIG_BUILTIN_UCODE_INTEL="intel-ucode/06-3a-09 intel-ucode/06-2f-02"
Rather than a blank as separator, the more conventional one on Unix and alike would be : I think. Of course ideally there wouldn't be any restriction at all on the characters usable here for file names.
Quoted 4 lines
xen/arch/x86/Kconfig +0
-0@@ -218,6 +218,36 @@ config MEM_SHARING bool "Xen memory sharing support" if EXPERT = "y"
xen/arch/x86/Kconfig config MEM_SHARING · line 228
Quoted 10 lines
xen/arch/x86/Kconfig +8
-0depends on HVM +config BUILTIN_UCODE + bool "Support for Builtin Microcode" + ---help--- + Include the CPU microcode update in the Xen image itself. With this + support, Xen can update the CPU microcode upon boot using the builtin + microcode, with no need for an additional microcode boot modules. + + If unsure, say N.
I continue to be unconvinced that this separate option is needed. Albeit compared to the v1 approach I will agree that handling would become more complicated without.
Quoted 10 lines
xen/arch/x86/Kconfig +10
-0+config BUILTIN_UCODE_DIR + string "Directory containing microcode updates" + default "/lib/firmware/" + depends on BUILTIN_UCODE + ---help--- + The directory containing the microcode blobs. + +config BUILTIN_UCODE_AMD + string "AMD microcode updates" + default ""
xen/arch/x86/Kconfig config MEM_SHARING · line 249
Quoted 10 lines
xen/arch/x86/Kconfig +10
-0+ depends on BUILTIN_UCODE + ---help--- + AMD builtin microcode; space-sparated, relative to BUILTIN_UCODE_DIR. + +config BUILTIN_UCODE_INTEL + string "INTEL microcode updates" + default "" + depends on BUILTIN_UCODE + ---help--- + INTEL builtin microcode; space-sparated, relative to BUILTIN_UCODE_DIR.
I don't think Intel is commonly spelled all uppercase.
I further think you want to mention further constraints (beyond the separator to use): DIR would probably better be an absolute path, it's ambiguous (right here, i.e. without looking at the implementation) whether a trailing slash needs including), the individual blobs may include paths, and it's ambiguous again what them having a leading slash would mean (I think it would be better if it was "absolute or relative to BUILTIN_UCODE_DIR").
Also a spelling nit: "separated".
xen/arch/x86/microcode.c static struct ucode_mod_blob __initdata ucode_blob; · line 105
Quoted 12 lines
xen/arch/x86/microcode.c +6
-0@@ -97,6 +97,14 @@ static struct ucode_mod_blob __initdata ucode_blob;*/ static bool_t __initdata ucode_scan; +#ifdef CONFIG_BUILTIN_UCODE +/* builtin is the default when BUILTIN_UCODE is set */ +static bool __initdata ucode_builtin = true; + +extern const char __builtin_intel_ucode_start[], __builtin_intel_ucode_end[]; +extern const char __builtin_amd_ucode_start[], __builtin_amd_ucode_end[];
While we do use plain char elsewhere for similar purposes, I think this is bad practice. It would better be unsigned char or uint8_t.
Quoted 21 lines
xen/arch/x86/microcode.c +17
-0@@ -208,6 +220,40 @@ void __init microcode_grab_module( ucode_mod = mod[ucode_mod_idx]; else if ( ucode_scan ) microcode_scan_module(module_map, mbi); + +#ifdef CONFIG_BUILTIN_UCODE +/* +* Do not use the builtin microcode if: +* (a) builtin has been explicitly turned off (e.g., ucode=no-builtin) +* (b) a microcode module has been specified or a scan is successful +*/ +if ( !ucode_builtin || ucode_mod.mod_end || ucode_blob.size ) + { + ucode_builtin = false; +return ; + } + +/* Set ucode_start/_end to the proper blob */ +if ( boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) + { + ucode_blob.size = __builtin_amd_ucode_end - __builtin_amd_ucode_start;
xen/arch/x86/microcode.c void __init microcode_grab_module( · line 249
Quoted 10 lines
xen/arch/x86/microcode.c +10
-0+ ucode_blob.data = __builtin_amd_ucode_start; + } +else if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) + { + ucode_blob.size = __builtin_intel_ucode_end - + __builtin_intel_ucode_start; + ucode_blob.data = __builtin_intel_ucode_start; + } +else +return ;
"switch ( boot_cpu_data.x86_vendor )" please.
xen/arch/x86/microcode.c void __init microcode_grab_module( · line 253
Quoted 3 lines
xen/arch/x86/microcode.c +3
-0+if ( !ucode_blob.size ) + { +printk ("No builtin ucode for the CPU vendor.\n" );
Please either omit "for the CPU vendor" or name the vendor. In any event please omit the full stop.
xen/arch/x86/microcode.c static int __init microcode_init(void) · line 756
Quoted 11 lines
xen/arch/x86/microcode.c +6
-0@@ -701,7 +747,13 @@ static int __init microcode_init(void)*/ if ( ucode_blob.size ) { +#ifdef CONFIG_BUILTIN_UCODE +/* No need to destroy module mappings if builtin was used */ +if ( !ucode_builtin ) +bootstrap_map (NULL ); +#else bootstrap_map (NULL ); +#endif
First of all - is there no ucode unrelated side effect of this invocation? I.e. can it safely be skipped? If yes, then I think you want to get away without #ifdef here, by having a suitably placed
#define ucode_builtin false
somewhere up the file.
Quoted 36 lines
xen/arch/x86/microcode/Makefile new file +33
-0@@ -0,0 +1,46 @@ +# Copyright (C) 2019 Amazon.com, Inc. or its affiliates. +# Author: Eslam Elnikety <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove quotes and excess spaces from configuration strings +UCODE_DIR=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_DIR))) +UCODE_AMD=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_AMD))) +UCODE_INTEL=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_INTEL))) + +# AMD and INTEL microcode blobs. Use 'wildcard' to filter for existing blobs. +amd-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_AMD))) +intel-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_INTEL))) + +ifneq ($(amd-blobs),) +obj-y += ucode_amd.o +endif + +ifneq ($(intel-blobs),) +obj-y += ucode_intel.o +endif + +ifeq ($(amd-blobs)$(intel-blobs),) +obj-y += ucode_dummy.o +endif
xen/arch/x86/microcode/Makefile line 43
Quoted 10 lines
xen/arch/x86/microcode/Makefile new file +10
-0+ +ucode_amd.o: Makefile $(amd-blobs) + cat $(amd-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_amd_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected] + +ucode_intel.o: Makefile $(intel-blobs) + cat $(intel-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_intel_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]
This can be had with a pattern rule (with the vendor being the stem) and hence without duplication, I think.
Also - is simply concatenating the blobs reliable enough? There's no build time diagnostic that the result would actually be understood at runtime.
xen/arch/x86/microcode/Makefile line 46
Quoted 2 lines
xen/arch/x86/microcode/Makefile new file +2
-0+ucode_dummy.o: Makefile + $(CC) $(CFLAGS) -c -x c /dev/null -o $@;
Since the commit message doesn't explain why this is needed, I have to ask (I guess we somewhere have a dependency on $(obj-y) not being empty). _If_ it is needed, I don't see why you need ifeq() around its use. In fact you could have
obj-y := ucode-dummy.o
right at the top of the file.
Furthermore I don't really understand why you need this in the first place. While cat won't do what you want with an empty argument list, can't you simply prepend / append /dev/null?
xen/arch/x86/xen.lds.S SECTIONS · line 270
Quoted 9 lines
xen/arch/x86/xen.lds.S +3
-0@@ -265,6 +265,18 @@ SECTIONS *(SORT(.data.vpci.*)) __end_vpci_array = .; #endif + +#if defined(CONFIG_BUILTIN_UCODE) + . = ALIGN(POINTER_ALIGN);
Why (same further down)? The alignment of both vendors' header structures is just 4 afaict.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Eslam Elnikety
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
docs/admin-guide/microcode-loading.rst +16
-0+ +Xen can bundle microcode updates within its image. This support is conditional +on the build configuration BUILTIN_UCODE being enabled. Builtin microcode is +useful to ensure that, by default, a minimum microcode patch level will be +applied to the underlying CPU. + +To use microcode updates available on the build system as builtin, +use BUILTIN_UCODE_DIR to refer to the directory containing the firmware updates +and specify the individual microcode patches via either BUILTIN_UCODE_AMD or +BUILTIN_UCODE_INTEL for AMD microcode or INTEL microcode, respectively. For +instance, the configuration below is suitable for a build system which has a +``/lib/firmware/`` directory which, in turn, includes the individual microcode +patches ``amd-ucode/microcode_amd_fam15h.bin``, ``intel-ucode/06-3a-09``, and +``intel-ucode/06-2f-02``. + + CONFIG_BUILTIN_UCODE=y
Quoted 9 lines
docs/admin-guide/microcode-loading.rst The ``ucode=scan`` command line option will cause Xen to search through all · line 127
Quoted 3 lines
docs/admin-guide/microcode-loading.rst +3
-0+ CONFIG_BUILTIN_UCODE_DIR="/lib/firmware/" + CONFIG_BUILTIN_UCODE_AMD="amd-ucode/microcode_amd_fam15h.bin" + CONFIG_BUILTIN_UCODE_INTEL="intel-ucode/06-3a-09 intel-ucode/06-2f-02"Rather than a blank as separator, the more conventional one on Unix and alike would be : I think. Of course ideally there wouldn't be any restriction at all on the characters usable here for file names.
It would be great if there is a particular convention. The blank separator is aligned with Linux way of doing builtin microcode.
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/Kconfig +0
-0@@ -218,6 +218,36 @@ config MEM_SHARING bool "Xen memory sharing support" if EXPERT = "y" depends on HVM
Quoted 13 lines
xen/arch/x86/Kconfig config MEM_SHARING · line 228
Quoted 8 lines
xen/arch/x86/Kconfig +8
-0+config BUILTIN_UCODE + bool "Support for Builtin Microcode" + ---help--- + Include the CPU microcode update in the Xen image itself. With this + support, Xen can update the CPU microcode upon boot using the builtin + microcode, with no need for an additional microcode boot modules. + + If unsure, say N.I continue to be unconvinced that this separate option is needed. Albeit compared to the v1 approach I will agree that handling would become more complicated without.
Any particular preference between the v1 vs v2 approach?
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/Kconfig +2
-0@@ -701,7 +747,13 @@ static int __init microcode_init(void) */ if ( ucode_blob.size ) { +#ifdef CONFIG_BUILTIN_UCODE + /* No need to destroy module mappings if builtin was used */
Quoted 8 lines
xen/arch/x86/Kconfig static int __init microcode_init(void) · line 756
Quoted 5 lines
xen/arch/x86/Kconfig +4
-0+ if ( !ucode_builtin ) + bootstrap_map(NULL); +#else bootstrap_map(NULL); +#endifFirst of all - is there no ucode unrelated side effect of this invocation? I.e. can it safely be skipped?
Maybe I am missing something. Are you asking if we can safely skip the bootstrap_map(NULL)? (Quoting your response on PATCH v2 2/4 "And of course we really want these mappings to be gone")
Quoted 8 lines
If yes, then I think
you want to get away without #ifdef here, by having a suitably placed#define
ucode_builtinfalsesomewhere up the file.
Agreed. That will make the code snippet more readable indeed.
Quoted 50 lines
Quoted 36 lines
xen/arch/x86/microcode/Makefile new file +33
-0@@ -0,0 +1,46 @@ +# Copyright (C) 2019 Amazon.com, Inc. or its affiliates. +# Author: Eslam Elnikety <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove quotes and excess spaces from configuration strings +UCODE_DIR=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_DIR))) +UCODE_AMD=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_AMD))) +UCODE_INTEL=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_INTEL))) + +# AMD and INTEL microcode blobs. Use 'wildcard' to filter for existing blobs. +amd-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_AMD))) +intel-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_INTEL))) + +ifneq ($(amd-blobs),) +obj-y += ucode_amd.o +endif + +ifneq ($(intel-blobs),) +obj-y += ucode_intel.o +endif + +ifeq ($(amd-blobs)$(intel-blobs),) +obj-y += ucode_dummy.o +endifxen/arch/x86/microcode/Makefile line 43
Quoted 10 lines
xen/arch/x86/microcode/Makefile new file +10
-0+ +ucode_amd.o: Makefile $(amd-blobs) + cat $(amd-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_amd_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected] + +ucode_intel.o: Makefile $(intel-blobs) + cat $(intel-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_intel_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]This can be had with a pattern rule (with the vendor being the stem) and hence without duplication, I think.
Quoted 4 lines
Also - is simply concatenating the blobs reliable enough? There's no build time diagnostic that the result would actually be understood at runtime.
Concatenation is reliable (as long as the individual microcode blobs are not malformed, and in that case the builtin is not making matters worse compared to presenting the malformed update via <integer> | scan).
Quoted 6 lines
xen/arch/x86/microcode/Makefile line 46
Quoted 2 lines
xen/arch/x86/microcode/Makefile new file +2
-0+ucode_dummy.o: Makefile + $(CC) $(CFLAGS) -c -x c /dev/null -o $@;Since the commit message doesn't explain why this is needed, I have to ask (I guess we somewhere have a dependency on $(obj-y) not being empty).
Your guess is correct. All sub-directories of xen/arch/x86 are expected to produce built_in.o. If there are not amd nor intel microcode blobs, there will be no build dependencies and the build fails preparing the built_in.o
Quoted 11 lines
_If_ it is needed, I don't see why you need
ifeq()around its use. In fact you could haveobj-y := ucode-dummy.o
right at the top of the file.
Furthermore I don't really understand why you need this in the first place. While cat won't do what you want with an empty argument list, can't you simply prepend / append
/dev/null?
To make sure we are on the same page. You are suggesting using "/dev/null" in case there are no amd/intel ucode to generate the ucode_amd/intel.o? If so, objcopy does not allow using /dev/null as input (complains about empty binary).
(I agree with your other inline suggestions that I have omitted. Those I will address in v3).
Thanks,
Eslam
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 29 lines · Eslam Elnikety
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Eslam Elnikety
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
docs/admin-guide/microcode-loading.rst +16
-0+ +Xen can bundle microcode updates within its image. This support is conditional +on the build configuration BUILTIN_UCODE being enabled. Builtin microcode is +useful to ensure that, by default, a minimum microcode patch level will be +applied to the underlying CPU. + +To use microcode updates available on the build system as builtin, +use BUILTIN_UCODE_DIR to refer to the directory containing the firmware updates +and specify the individual microcode patches via either BUILTIN_UCODE_AMD or +BUILTIN_UCODE_INTEL for AMD microcode or INTEL microcode, respectively. For +instance, the configuration below is suitable for a build system which has a +``/lib/firmware/`` directory which, in turn, includes the individual microcode +patches ``amd-ucode/microcode_amd_fam15h.bin``, ``intel-ucode/06-3a-09``, and +``intel-ucode/06-2f-02``. + + CONFIG_BUILTIN_UCODE=yQuoted 9 lines
docs/admin-guide/microcode-loading.rst The ``ucode=scan`` command line option will cause Xen to search through all · line 127
Quoted 3 lines
docs/admin-guide/microcode-loading.rst +3
-0+ CONFIG_BUILTIN_UCODE_DIR="/lib/firmware/" + CONFIG_BUILTIN_UCODE_AMD="amd-ucode/microcode_amd_fam15h.bin" + CONFIG_BUILTIN_UCODE_INTEL="intel-ucode/06-3a-09 intel-ucode/06-2f-02"Rather than a blank as separator, the more conventional one on Unix and alike would be : I think. Of course ideally there wouldn't be any restriction at all on the characters usable here for file names.
Quoted 2 lines
It would be great if there is a particular convention. The blank separator is aligned with Linux way of doing builtin microcode.
Well, this is then another area where I would question whether we really want to follow the Linux approach, but I'm not bothered enough to make less non-conventional behavior here a requirement.
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/Kconfig +0
-0@@ -218,6 +218,36 @@ config MEM_SHARING bool "Xen memory sharing support" if EXPERT = "y" depends on HVMQuoted 12 lines
xen/arch/x86/Kconfig config MEM_SHARING · line 228
Quoted 8 lines
xen/arch/x86/Kconfig +8
-0+config BUILTIN_UCODE + bool "Support for Builtin Microcode" + ---help--- + Include the CPU microcode update in the Xen image itself. With this + support, Xen can update the CPU microcode upon boot using the builtin + microcode, with no need for an additional microcode boot modules. + + If unsure, say N.I continue to be unconvinced that this separate option is needed. Albeit compared to the v1 approach I will agree that handling would become more complicated without.
Quoted 1 line
Any particular preference between the v1 vs v2 approach?
I definitely like the vendor separation.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/Kconfig +2
-0@@ -701,7 +747,13 @@ static int __init microcode_init(void) */ if ( ucode_blob.size ) { +#ifdef CONFIG_BUILTIN_UCODE + /* No need to destroy module mappings if builtin was used */Quoted 8 lines
xen/arch/x86/Kconfig static int __init microcode_init(void) · line 756
Quoted 5 lines
xen/arch/x86/Kconfig +4
-0+ if ( !ucode_builtin ) + bootstrap_map(NULL); +#else bootstrap_map(NULL); +#endifFirst of all - is there no ucode unrelated side effect of this invocation? I.e. can it safely be skipped?
Quoted 3 lines
Maybe I am missing something. Are you asking if we can safely skip the
bootstrap_map(NULL)? (Quoting your response on PATCH v2 2/4 "And of course we really want these mappings to be gone")
Yes - my point is that invoking the function here may in principle cover for other mappings. However - this is the invocation you've added in an earlier patch, isn't it? In which case omitting it should be fine. Nevertheless I don't see and harm in invoking the function, i.e. I'd rather keep the code here simple.
Quoted 50 lines
Quoted 50 lines
Quoted 36 lines
xen/arch/x86/microcode/Makefile new file +33
-0@@ -0,0 +1,46 @@ +# Copyright (C) 2019 Amazon.com, Inc. or its affiliates. +# Author: Eslam Elnikety <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove quotes and excess spaces from configuration strings +UCODE_DIR=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_DIR))) +UCODE_AMD=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_AMD))) +UCODE_INTEL=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_INTEL))) + +# AMD and INTEL microcode blobs. Use 'wildcard' to filter for existing blobs. +amd-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_AMD))) +intel-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_INTEL))) + +ifneq ($(amd-blobs),) +obj-y += ucode_amd.o +endif + +ifneq ($(intel-blobs),) +obj-y += ucode_intel.o +endif + +ifeq ($(amd-blobs)$(intel-blobs),) +obj-y += ucode_dummy.o +endifxen/arch/x86/microcode/Makefile line 43
Quoted 10 lines
xen/arch/x86/microcode/Makefile new file +10
-0+ +ucode_amd.o: Makefile $(amd-blobs) + cat $(amd-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_amd_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected] + +ucode_intel.o: Makefile $(intel-blobs) + cat $(intel-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_intel_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]This can be had with a pattern rule (with the vendor being the stem) and hence without duplication, I think.
Quoted 8 lines
Quoted 4 lines
Also - is simply concatenating the blobs reliable enough? There's no build time diagnostic that the result would actually be understood at runtime.
Concatenation is reliable (as long as the individual microcode blobs are not malformed, and in that case the builtin is not making matters worse compared to presenting the malformed update via <integer> | scan).
A malformed update found the other way is a bug in the tools constructing the respective images. A malformed built-in update is a bug in the Xen build system. The put the question
differently: Is it specified somewhere that the blobs all have to have certain properties, which the straight concatenation relies upon?
Quoted 11 lines
Quoted 6 lines
xen/arch/x86/microcode/Makefile line 46
Quoted 2 lines
xen/arch/x86/microcode/Makefile new file +2
-0+ucode_dummy.o: Makefile + $(CC) $(CFLAGS) -c -x c /dev/null -o $@;Since the commit message doesn't explain why this is needed, I have to ask (I guess we somewhere have a dependency on $(obj-y) not being empty).
Your guess is correct. All sub-directories of xen/arch/x86 are expected to produce built_in.o. If there are not amd nor intel microcode blobs, there will be no build dependencies and the build fails preparing the built_in.o
That's rather poor, but it's of course not your task to get this fixed (it shouldn't be very difficult to create an empty built_in.o for an empty $(obj-y)).
Quoted 12 lines
Quoted 11 lines
_If_ it is needed, I don't see why you need
ifeq()around its use. In fact you could haveobj-y := ucode-dummy.o
right at the top of the file.
Furthermore I don't really understand why you need this in the first place. While cat won't do what you want with an empty argument list, can't you simply prepend / append
/dev/null?
Quoted 4 lines
To make sure we are on the same page. You are suggesting using "
/dev/null" in case there are no amd/intel ucode to generate theucode_amd/intel.o? If so, objcopy does not allow using/dev/nullas input (complains about empty binary).
That's again rather poor, this time of the utility - it should be easy enough to produce an object with an empty .data (or whatever it is) section. As above - I'm fine with you keeping the logic then as is, provided you say in the description why it can't be simplified.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 185 lines · Jan Beulich
Quoted 29 lines · Eslam Elnikety
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Eslam Elnikety
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(quoted diff) +16
-0+ +Xen can bundle microcode updates within its image. This support is conditional +on the build configuration BUILTIN_UCODE being enabled. Builtin microcode is +useful to ensure that, by default, a minimum microcode patch level will be +applied to the underlying CPU. + +To use microcode updates available on the build system as builtin, +use BUILTIN_UCODE_DIR to refer to the directory containing the firmware updates +and specify the individual microcode patches via either BUILTIN_UCODE_AMD or +BUILTIN_UCODE_INTEL for AMD microcode or INTEL microcode, respectively. For +instance, the configuration below is suitable for a build system which has a +``/lib/firmware/`` directory which, in turn, includes the individual microcode +patches ``amd-ucode/microcode_amd_fam15h.bin``, ``intel-ucode/06-3a-09``, and +``intel-ucode/06-2f-02``. + + CONFIG_BUILTIN_UCODE=yQuoted 9 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ CONFIG_BUILTIN_UCODE_DIR="/lib/firmware/" + CONFIG_BUILTIN_UCODE_AMD="amd-ucode/microcode_amd_fam15h.bin" + CONFIG_BUILTIN_UCODE_INTEL="intel-ucode/06-3a-09 intel-ucode/06-2f-02"Rather than a blank as separator, the more conventional one on Unix and alike would be : I think. Of course ideally there wouldn't be any restriction at all on the characters usable here for file names.
Quoted 2 lines
It would be great if there is a particular convention. The blank separator is aligned with Linux way of doing builtin microcode.
Well, this is then another area where I would question whether we really want to follow the Linux approach, but I'm not bothered enough to make less non-conventional behavior here a requirement.
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/Kconfig +0
-0@@ -218,6 +218,36 @@ config MEM_SHARING bool "Xen memory sharing support" if EXPERT = "y" depends on HVMQuoted 12 lines
xen/arch/x86/Kconfig config MEM_SHARING · line 228
Quoted 8 lines
xen/arch/x86/Kconfig +8
-0+config BUILTIN_UCODE + bool "Support for Builtin Microcode" + ---help--- + Include the CPU microcode update in the Xen image itself. With this + support, Xen can update the CPU microcode upon boot using the builtin + microcode, with no need for an additional microcode boot modules. + + If unsure, say N.I continue to be unconvinced that this separate option is needed. Albeit compared to the v1 approach I will agree that handling would become more complicated without.
Quoted 1 line
Any particular preference between the v1 vs v2 approach?
I definitely like the vendor separation.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/Kconfig +2
-0@@ -701,7 +747,13 @@ static int __init microcode_init(void) */ if ( ucode_blob.size ) { +#ifdef CONFIG_BUILTIN_UCODE + /* No need to destroy module mappings if builtin was used */Quoted 8 lines
xen/arch/x86/Kconfig static int __init microcode_init(void) · line 756
Quoted 5 lines
xen/arch/x86/Kconfig +4
-0+ if ( !ucode_builtin ) + bootstrap_map(NULL); +#else bootstrap_map(NULL); +#endifFirst of all - is there no ucode unrelated side effect of this invocation? I.e. can it safely be skipped?
Quoted 3 lines
Maybe I am missing something. Are you asking if we can safely skip the
bootstrap_map(NULL)? (Quoting your response on PATCH v2 2/4 "And of course we really want these mappings to be gone")Yes - my point is that invoking the function here may in principle cover for other mappings. However - this is the invocation you've added in an earlier patch, isn't it? In which case omitting it should be fine. Nevertheless I don't see and harm in invoking the function, i.e. I'd rather keep the code here simple.
Quoted 50 lines
Quoted 50 lines
Quoted 36 lines
xen/arch/x86/microcode/Makefile new file +33
-0@@ -0,0 +1,46 @@ +# Copyright (C) 2019 Amazon.com, Inc. or its affiliates. +# Author: Eslam Elnikety <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove quotes and excess spaces from configuration strings +UCODE_DIR=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_DIR))) +UCODE_AMD=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_AMD))) +UCODE_INTEL=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_INTEL))) + +# AMD and INTEL microcode blobs. Use 'wildcard' to filter for existing blobs. +amd-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_AMD))) +intel-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_INTEL))) + +ifneq ($(amd-blobs),) +obj-y += ucode_amd.o +endif + +ifneq ($(intel-blobs),) +obj-y += ucode_intel.o +endif + +ifeq ($(amd-blobs)$(intel-blobs),) +obj-y += ucode_dummy.o +endifxen/arch/x86/microcode/Makefile line 43
Quoted 10 lines
xen/arch/x86/microcode/Makefile new file +10
-0+ +ucode_amd.o: Makefile $(amd-blobs) + cat $(amd-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_amd_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected] + +ucode_intel.o: Makefile $(intel-blobs) + cat $(intel-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_intel_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]This can be had with a pattern rule (with the vendor being the stem) and hence without duplication, I think.
Quoted 8 lines
Quoted 4 lines
Also - is simply concatenating the blobs reliable enough? There's no build time diagnostic that the result would actually be understood at runtime.
Concatenation is reliable (as long as the individual microcode blobs are not malformed, and in that case the builtin is not making matters worse compared to presenting the malformed update via <integer> | scan).
A malformed update found the other way is a bug in the tools constructing the respective images. A malformed built-in update is a bug in the Xen build system. The put the question
differently: Is it specified somewhere that the blobs all have to have certain properties, which the straight concatenation relies upon?Quoted 11 lines
Quoted 6 lines
xen/arch/x86/microcode/Makefile line 45
Quoted 2 lines
xen/arch/x86/microcode/Makefile new file +2
-0+ucode_dummy.o: Makefile + $(CC) $(CFLAGS) -c -x c /dev/null -o $@;Since the commit message doesn't explain why this is needed, I have to ask (I guess we somewhere have a dependency on $(obj-y) not being empty).
Your guess is correct. All sub-directories of xen/arch/x86 are expected to produce built_in.o. If there are not amd nor intel microcode blobs, there will be no build dependencies and the build fails preparing the built_in.o
That's rather poor, but it's of course not your task to get this fixed (it shouldn't be very difficult to create an empty built_in.o for an empty $(obj-y)).
Quoted 12 lines
Quoted 11 lines
_If_ it is needed, I don't see why you need
ifeq()around its use. In fact you could haveobj-y := ucode-dummy.o
right at the top of the file.
Furthermore I don't really understand why you need this in the first place. While cat won't do what you want with an empty argument list, can't you simply prepend / append
/dev/null?Quoted 4 lines
To make sure we are on the same page. You are suggesting using "
/dev/null" in case there are no amd/intel ucode to generate theucode_amd/intel.o? If so, objcopy does not allow using/dev/nullas input (complains about empty binary).
Quoted 5 lines
That's again rather poor, this time of the utility - it should be easy enough to produce an object with an empty .data (or whatever it is) section. As above - I'm fine with you keeping the logic then as is, provided you say in the description why it can't be simplified.
What about using the attached patch for including the binary files?
I wanted to post that for my hypervisor-fs series, but I think it would fit here quite nice.
Juergen
From 1181c103c4d0ee77d518ac9b168ef91adcac4405 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
To: [email protected]
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Daniel De Graaf <[email protected]>
Date: Thu, 19 Dec 2019 10:00:56 +0100
Subject: [PATCH] xen: add a generic way to include binary files as variables
Add a new script xen/tools/binfile for including a binary file at build time being usable via a pointer and a size variable in the hypervisor.
Make use of that generic tool in xsm.
--- .gitignore | 1 + xen/tools/binfile | 29 +++++++++++++++++++++++++++++ xen/xsm/flask/Makefile | 5 ++++- xen/xsm/flask/flask-policy.S | 16 ---------------- 4 files changed, 34 insertions(+), 17 deletions(-) create mode 100755 xen/tools/binfile delete mode 100644 xen/xsm/flask/flask-policy.S
.gitignore +1 -0
@@ -315,6 +315,7 @@ xen/test/livepatch/xen_replace_world.livepatch xen/tools/kconfig/.tmp_gtkcheck xen/tools/kconfig/.tmp_qtcheck xen/tools/symbols +xen/xsm/flask/flask-policy.S xen/xsm/flask/include/av_perm_to_string.h xen/xsm/flask/include/av_permissions.h xen/xsm/flask/include/class_to_string.h
xen/tools/binfile new file +29 -0
@@ -0,0 +1,29 @@ +#!/bin/sh +# usage: binfile [-i] <target-src.S> <binary-file> <varname> +# -i add to .init.rodata (default: .rodata) section + +[ "$1" = "-i" ] && { + shift + section=".init" +} + +target=$1 +binsource=$2 +varname=$3 + +cat <<EOF >$target +#include <asm/asm_defns.h> + + .section $section.rodata, "a", %progbits + + .global $varname +$varname: + .incbin "$binsource" +.Lend: + + .type $varname, %object + .size $varname, . - $varname + + .global ${varname}_size + ASM_INT(${varname}_size, .Lend - $varname) +EOF
xen/xsm/flask/Makefile +4 -1
@@ -30,6 +30,9 @@ $(AV_H_FILES): $(AV_H_DEPEND) obj-bin-$(CONFIG_XSM_FLASK_POLICY) += flask-policy.o flask-policy.o: policy.bin +flask-policy.S: $(XEN_ROOT)/xen/tools/binfile + $(XEN_ROOT)/xen/tools/binfile -i $@ policy.bin xsm_flask_init_policy + FLASK_BUILD_DIR := $(CURDIR) POLICY_SRC := $(FLASK_BUILD_DIR)/xenpolicy-$(XEN_FULLVERSION)
@@ -39,4 +42,4 @@ policy.bin: FORCE .PHONY: clean clean:: - rm -f $(ALL_H_FILES) *.o $(DEPS_RM) policy.* $(POLICY_SRC) + rm -f $(ALL_H_FILES) *.o $(DEPS_RM) policy.* $(POLICY_SRC) flask-policy.S
xen/xsm/flask/flask-policy.S deleted +0 -16
@@ -1,16 +0,0 @@ -#include <asm/asm_defns.h> - - .section .init.rodata, "a", %progbits - -/* const unsigned char xsm_flask_init_policy[] __initconst */ - .global xsm_flask_init_policy -xsm_flask_init_policy: - .incbin "policy.bin" -.Lend: - - .type xsm_flask_init_policy, %object - .size xsm_flask_init_policy, . - xsm_flask_init_policy - -/* const unsigned int __initconst xsm_flask_init_policy_size */ - .global xsm_flask_init_policy_size - ASM_INT(xsm_flask_init_policy_size, .Lend - xsm_flask_init_policy)
Signature · 1 line
2.16.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 192 lines · Jürgen Groß
Quoted 185 lines · Jan Beulich
Quoted 29 lines · Eslam Elnikety
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Eslam Elnikety
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(quoted diff) +16
-0+ +Xen can bundle microcode updates within its image. This support is conditional +on the build configuration BUILTIN_UCODE being enabled. Builtin microcode is +useful to ensure that, by default, a minimum microcode patch level will be +applied to the underlying CPU. + +To use microcode updates available on the build system as builtin, +use BUILTIN_UCODE_DIR to refer to the directory containing the firmware updates +and specify the individual microcode patches via either BUILTIN_UCODE_AMD or +BUILTIN_UCODE_INTEL for AMD microcode or INTEL microcode, respectively. For +instance, the configuration below is suitable for a build system which has a +``/lib/firmware/`` directory which, in turn, includes the individual microcode +patches ``amd-ucode/microcode_amd_fam15h.bin``, ``intel-ucode/06-3a-09``, and +``intel-ucode/06-2f-02``. + + CONFIG_BUILTIN_UCODE=yQuoted 9 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ CONFIG_BUILTIN_UCODE_DIR="/lib/firmware/" + CONFIG_BUILTIN_UCODE_AMD="amd-ucode/microcode_amd_fam15h.bin" + CONFIG_BUILTIN_UCODE_INTEL="intel-ucode/06-3a-09 intel-ucode/06-2f-02"Rather than a blank as separator, the more conventional one on Unix and alike would be : I think. Of course ideally there wouldn't be any restriction at all on the characters usable here for file names.
Quoted 2 lines
It would be great if there is a particular convention. The blank separator is aligned with Linux way of doing builtin microcode.
Well, this is then another area where I would question whether we really want to follow the Linux approach, but I'm not bothered enough to make less non-conventional behavior here a requirement.
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/Kconfig +0
-0@@ -218,6 +218,36 @@ config MEM_SHARING bool "Xen memory sharing support" if EXPERT = "y" depends on HVMQuoted 12 lines
xen/arch/x86/Kconfig config MEM_SHARING · line 228
Quoted 8 lines
xen/arch/x86/Kconfig +8
-0+config BUILTIN_UCODE + bool "Support for Builtin Microcode" + ---help--- + Include the CPU microcode update in the Xen image itself. With this + support, Xen can update the CPU microcode upon boot using the builtin + microcode, with no need for an additional microcode boot modules. + + If unsure, say N.I continue to be unconvinced that this separate option is needed. Albeit compared to the v1 approach I will agree that handling would become more complicated without.
Quoted 1 line
Any particular preference between the v1 vs v2 approach?
I definitely like the vendor separation.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/Kconfig +2
-0@@ -701,7 +747,13 @@ static int __init microcode_init(void) */ if ( ucode_blob.size ) { +#ifdef CONFIG_BUILTIN_UCODE + /* No need to destroy module mappings if builtin was used */Quoted 8 lines
xen/arch/x86/Kconfig static int __init microcode_init(void) · line 756
Quoted 5 lines
xen/arch/x86/Kconfig +4
-0+ if ( !ucode_builtin ) + bootstrap_map(NULL); +#else bootstrap_map(NULL); +#endifFirst of all - is there no ucode unrelated side effect of this invocation? I.e. can it safely be skipped?
Quoted 3 lines
Maybe I am missing something. Are you asking if we can safely skip the
bootstrap_map(NULL)? (Quoting your response on PATCH v2 2/4 "And of course we really want these mappings to be gone")Yes - my point is that invoking the function here may in principle cover for other mappings. However - this is the invocation you've added in an earlier patch, isn't it? In which case omitting it should be fine. Nevertheless I don't see and harm in invoking the function, i.e. I'd rather keep the code here simple.
Quoted 50 lines
Quoted 50 lines
Quoted 36 lines
xen/arch/x86/microcode/Makefile new file +33
-0@@ -0,0 +1,46 @@ +# Copyright (C) 2019 Amazon.com, Inc. or its affiliates. +# Author: Eslam Elnikety <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove quotes and excess spaces from configuration strings +UCODE_DIR=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_DIR))) +UCODE_AMD=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_AMD))) +UCODE_INTEL=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_INTEL))) + +# AMD and INTEL microcode blobs. Use 'wildcard' to filter for existing blobs. +amd-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_AMD))) +intel-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_INTEL))) + +ifneq ($(amd-blobs),) +obj-y += ucode_amd.o +endif + +ifneq ($(intel-blobs),) +obj-y += ucode_intel.o +endif + +ifeq ($(amd-blobs)$(intel-blobs),) +obj-y += ucode_dummy.o +endifxen/arch/x86/microcode/Makefile line 43
Quoted 10 lines
xen/arch/x86/microcode/Makefile new file +10
-0+ +ucode_amd.o: Makefile $(amd-blobs) + cat $(amd-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_amd_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected] + +ucode_intel.o: Makefile $(intel-blobs) + cat $(intel-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_intel_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]This can be had with a pattern rule (with the vendor being the stem) and hence without duplication, I think.
Quoted 8 lines
Quoted 4 lines
Also - is simply concatenating the blobs reliable enough? There's no build time diagnostic that the result would actually be understood at runtime.
Concatenation is reliable (as long as the individual microcode blobs are not malformed, and in that case the builtin is not making matters worse compared to presenting the malformed update via <integer> | scan).
A malformed update found the other way is a bug in the tools constructing the respective images. A malformed built-in update is a bug in the Xen build system. The put the question
differently: Is it specified somewhere that the blobs all have to have certain properties, which the straight concatenation relies upon?Quoted 11 lines
Quoted 6 lines
xen/arch/x86/microcode/Makefile line 45
Quoted 2 lines
xen/arch/x86/microcode/Makefile new file +2
-0+ucode_dummy.o: Makefile + $(CC) $(CFLAGS) -c -x c /dev/null -o $@;Since the commit message doesn't explain why this is needed, I have to ask (I guess we somewhere have a dependency on $(obj-y) not being empty).
Your guess is correct. All sub-directories of xen/arch/x86 are expected to produce built_in.o. If there are not amd nor intel microcode blobs, there will be no build dependencies and the build fails preparing the built_in.o
That's rather poor, but it's of course not your task to get this fixed (it shouldn't be very difficult to create an empty built_in.o for an empty $(obj-y)).
Quoted 12 lines
Quoted 11 lines
_If_ it is needed, I don't see why you need
ifeq()around its use. In fact you could haveobj-y := ucode-dummy.o
right at the top of the file.
Furthermore I don't really understand why you need this in the first place. While cat won't do what you want with an empty argument list, can't you simply prepend / append
/dev/null?Quoted 4 lines
To make sure we are on the same page. You are suggesting using "
/dev/null" in case there are no amd/intel ucode to generate theucode_amd/intel.o? If so, objcopy does not allow using/dev/nullas input (complains about empty binary).Quoted 5 lines
That's again rather poor, this time of the utility - it should be easy enough to produce an object with an empty .data (or whatever it is) section. As above - I'm fine with you keeping the logic then as is, provided you say in the description why it can't be simplified.
Quoted 4 lines
What about using the attached patch for including the binary files?
I wanted to post that for my hypervisor-fs series, but I think it would fit here quite nice.
Why not, if it can be made fit the ucode situation.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 116 lines · Jürgen Groß
Quoted 109 lines · Jan Beulich
Quoted 59 lines · Eslam Elnikety
Quoted 58 lines · Jan Beulich
Quoted 51 lines · Eslam Elnikety
xen/arch/x86/microcode/Makefile new file +4
-0@@ -0,0 +1,46 @@ +# Copyright (C) 2019 Amazon.com, Inc. or its affiliates. +# Author: Eslam Elnikety <[email protected]> +# +# This program is free software; you can redistribute it and/ormodify
+# it under the terms of the GNU General Public License as published byxen/arch/x86/microcode/Makefile new file +14
-0+# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove quotes and excess spaces from configuration strings +UCODE_DIR=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_DIR))) +UCODE_AMD=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_AMD))) +UCODE_INTEL=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_INTEL))) + +# AMD and INTEL microcode blobs. Use 'wildcard' to filter forexisting blobs.
xen/arch/x86/microcode/Makefile new file +18
-1+amd-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_AMD))) +intel-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_INTEL))) + +ifneq ($(amd-blobs),) +obj-y += ucode_amd.o +endif + +ifneq ($(intel-blobs),) +obj-y += ucode_intel.o +endif + +ifeq ($(amd-blobs)$(intel-blobs),) +obj-y += ucode_dummy.o +endif + +ucode_amd.o: Makefile $(amd-blobs) + cat $(amd-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section.data=.builtin_amd_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]
xen/arch/x86/microcode/Makefile new file +4
-1+ +ucode_intel.o: Makefile $(intel-blobs) + cat $(intel-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-sectionQuoted 2 lines
.data=.builtin_intel_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]
This can be had with a pattern rule (with the vendor being the stem) and hence without duplication, I think.
Quoted 8 lines
Quoted 4 lines
Also - is simply concatenating the blobs reliable enough? There's no build time diagnostic that the result would actually be understood at runtime.
Concatenation is reliable (as long as the individual microcode blobs are not malformed, and in that case the builtin is not making matters worse compared to presenting the malformed update via <integer> | scan).
A malformed update found the other way is a bug in the tools constructing the respective images. A malformed built-in update is a bug in the Xen build system. The put the question
differently: Is it specified somewhere that the blobs all have to have certain properties, which the straight concatenation relies upon?Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
+ucode_dummy.o:
Makefile
+ $(CC) $(CFLAGS) -c -x c/dev/null-o $@;Since the commit message doesn't explain why this is needed, I have to ask (I guess we somewhere have a dependency on $(obj-y) not being empty).
Your guess is correct. All sub-directories of xen/arch/x86 are expected to produce built_in.o. If there are not amd nor intel microcode blobs, there will be no build dependencies and the build fails preparing the built_in.o
That's rather poor, but it's of course not your task to get this fixed (it shouldn't be very difficult to create an empty built_in.o for an empty $(obj-y)).
Quoted 12 lines
Quoted 11 lines
_If_ it is needed, I don't see why you need
ifeq()around its use. In fact you could haveobj-y := ucode-dummy.o
right at the top of the file.
Furthermore I don't really understand why you need this in the first place. While cat won't do what you want with an empty argument list, can't you simply prepend / append
/dev/null?Quoted 4 lines
To make sure we are on the same page. You are suggesting using "
/dev/null" in case there are no amd/intel ucode to generate theucode_amd/intel.o? If so, objcopy does not allow using/dev/nullas input (complains about empty binary).Quoted 5 lines
That's again rather poor, this time of the utility - it should be easy enough to produce an object with an empty .data (or whatever it is) section. As above - I'm fine with you keeping the logic then as is, provided you say in the description why it can't be simplified.
Quoted 4 lines
What about using the attached patch for including the binary files?
I wanted to post that for my hypervisor-fs series, but I think it would fit here quite nice.
Thanks, Jürgen. That tool is indeed useful on its own right for flask/policies. However, it seems to me that creating a built_in.o right out of the microcode blobs is simpler and keeps the whole business contained within xen/arch/x86/microcode/.
-- Eslam
Quoted 3 lines
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 62 lines · Jan Beulich
Quoted 52 lines · Eslam Elnikety
Quoted 51 lines · Jan Beulich
Quoted 36 lines · Eslam Elnikety
xen/arch/x86/microcode/Makefile new file +33
-0@@ -0,0 +1,46 @@ +# Copyright (C) 2019 Amazon.com, Inc. or its affiliates. +# Author: Eslam Elnikety <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove quotes and excess spaces from configuration strings +UCODE_DIR=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_DIR))) +UCODE_AMD=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_AMD))) +UCODE_INTEL=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_INTEL))) + +# AMD and INTEL microcode blobs. Use 'wildcard' to filter for existing blobs. +amd-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_AMD))) +intel-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_INTEL))) + +ifneq ($(amd-blobs),) +obj-y += ucode_amd.o +endif + +ifneq ($(intel-blobs),) +obj-y += ucode_intel.o +endif + +ifeq ($(amd-blobs)$(intel-blobs),) +obj-y += ucode_dummy.o +endifxen/arch/x86/microcode/Makefile line 43
Quoted 10 lines
xen/arch/x86/microcode/Makefile new file +10
-0+ +ucode_amd.o: Makefile $(amd-blobs) + cat $(amd-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_amd_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected] + +ucode_intel.o: Makefile $(intel-blobs) + cat $(intel-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_intel_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]This can be had with a pattern rule (with the vendor being the stem) and hence without duplication, I think.
Quoted 8 lines
Quoted 4 lines
Also - is simply concatenating the blobs reliable enough? There's no build time diagnostic that the result would actually be understood at runtime.
Concatenation is reliable (as long as the individual microcode blobs are not malformed, and in that case the builtin is not making matters worse compared to presenting the malformed update via <integer> | scan).
Quoted 7 lines
A malformed update found the other way is a bug in the tools constructing the respective images. A malformed built-in update is a bug in the Xen build system. The put the question
differently: Is it specified somewhere that the blobs all have to have certain properties, which the straight concatenation relies upon?
Refer to ( https://www.kernel.org/doc/Documentation/x86/microcode.txt ). AuthenticAMD.bin and GenuineIntel.bin are both concatenations of individual microcode blobs.
Quoted 33 lines
Quoted 11 lines
Quoted 6 lines
xen/arch/x86/microcode/Makefile line 46
Quoted 2 lines
xen/arch/x86/microcode/Makefile new file +2
-0+ucode_dummy.o: Makefile + $(CC) $(CFLAGS) -c -x c /dev/null -o $@;Since the commit message doesn't explain why this is needed, I have to ask (I guess we somewhere have a dependency on $(obj-y) not being empty).
Your guess is correct. All sub-directories of xen/arch/x86 are expected to produce built_in.o. If there are not amd nor intel microcode blobs, there will be no build dependencies and the build fails preparing the built_in.o
That's rather poor, but it's of course not your task to get this fixed (it shouldn't be very difficult to create an empty built_in.o for an empty $(obj-y)).
Quoted 12 lines
Quoted 11 lines
_If_ it is needed, I don't see why you need
ifeq()around its use. In fact you could haveobj-y := ucode-dummy.o
right at the top of the file.
Furthermore I don't really understand why you need this in the first place. While cat won't do what you want with an empty argument list, can't you simply prepend / append
/dev/null?Quoted 4 lines
To make sure we are on the same page. You are suggesting using "
/dev/null" in case there are no amd/intel ucode to generate theucode_amd/intel.o? If so, objcopy does not allow using/dev/nullas input (complains about empty binary).
Quoted 5 lines
That's again rather poor, this time of the utility - it should be easy enough to produce an object with an empty .data (or whatever it is) section. As above - I'm fine with you keeping the logic then as is, provided you say in the description why it can't be simplified.
Ack. Will justify the logic in comments.
-- Eslam
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 71 lines · Eslam Elnikety
Quoted 62 lines · Jan Beulich
Quoted 52 lines · Eslam Elnikety
Quoted 51 lines · Jan Beulich
Quoted 36 lines · Eslam Elnikety
xen/arch/x86/microcode/Makefile new file +33
-0@@ -0,0 +1,46 @@ +# Copyright (C) 2019 Amazon.com, Inc. or its affiliates. +# Author: Eslam Elnikety <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove quotes and excess spaces from configuration strings +UCODE_DIR=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_DIR))) +UCODE_AMD=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_AMD))) +UCODE_INTEL=$(strip $(subst $\",,$(CONFIG_BUILTIN_UCODE_INTEL))) + +# AMD and INTEL microcode blobs. Use 'wildcard' to filter for existing blobs. +amd-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_AMD))) +intel-blobs := $(wildcard $(addprefix $(UCODE_DIR),$(UCODE_INTEL))) + +ifneq ($(amd-blobs),) +obj-y += ucode_amd.o +endif + +ifneq ($(intel-blobs),) +obj-y += ucode_intel.o +endif + +ifeq ($(amd-blobs)$(intel-blobs),) +obj-y += ucode_dummy.o +endifxen/arch/x86/microcode/Makefile line 43
Quoted 10 lines
xen/arch/x86/microcode/Makefile new file +10
-0+ +ucode_amd.o: Makefile $(amd-blobs) + cat $(amd-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_amd_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected] + +ucode_intel.o: Makefile $(intel-blobs) + cat $(intel-blobs) > [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.builtin_intel_ucode,alloc,load,readonly,data,contents [email protected] $@ + rm -f [email protected]This can be had with a pattern rule (with the vendor being the stem) and hence without duplication, I think.
Quoted 8 lines
Quoted 4 lines
Also - is simply concatenating the blobs reliable enough? There's no build time diagnostic that the result would actually be understood at runtime.
Concatenation is reliable (as long as the individual microcode blobs are not malformed, and in that case the builtin is not making matters worse compared to presenting the malformed update via <integer> | scan).
Quoted 7 lines
A malformed update found the other way is a bug in the tools constructing the respective images. A malformed built-in update is a bug in the Xen build system. The put the question
differently: Is it specified somewhere that the blobs all have to have certain properties, which the straight concatenation relies upon?
Quoted 3 lines
Refer to ( https://www.kernel.org/doc/Documentation/x86/microcode.txt ). AuthenticAMD.bin and GenuineIntel.bin are both concatenations of individual microcode blobs.
Well, yes, and from practical observations this is good enough. But observe e.g. how that paragraph starts with "Here's a crude example ...".
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel