Skip to contentSkip to conversation

Add Kconfig option to remove microcode loading support

PATCH Superseded Alejandro Vallejo 3 participants 17 messages Jan 13

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add Kconfig option to remove microcode loading support

Hi,

One more day, one more revision. Same as v2 with feedback addressed.

v1: https://lore.kernel.org/xen-devel/[email protected]/
v2: https://lore.kernel.org/xen-devel/[email protected]/
pipeline (green):

    https://gitlab.com/xen-project/people/agvallejo/xen/-/pipelines/2260019646

Cheers,
Alejandro

Alejandro Vallejo (4):
x86/ucode: Fix typo s/mitigiated/mitigated/ x86/ucode: Rename UCODE_SCAN_DEFAULT to MICROCODE_SCAN_DEFAULT
earlycpio: lib-ify earlycpio.c
x86/ucode: Add Kconfig option to remove microcode loading

 automation/gitlab-ci/build.yaml        |  2 +-
 docs/admin-guide/microcode-loading.rst |  2 ++
 docs/misc/efi.pandoc                   |  2 ++
 docs/misc/xen-command-line.pandoc      |  4 ++--
 docs/misra/exclude-list.json           |  8 ++++----
 xen/arch/x86/Kconfig                   | 16 +++++++++++++++-
 xen/arch/x86/cpu/microcode/amd.c       | 22 ++++++++++++----------
 xen/arch/x86/cpu/microcode/core.c      | 17 +++++++++++++----
 xen/arch/x86/cpu/microcode/intel.c     | 11 +++++++----
 xen/arch/x86/cpu/microcode/private.h   |  2 ++
 xen/arch/x86/efi/efi-boot.h            |  3 ++-
 xen/arch/x86/platform_hypercall.c      | 22 +++++++++++++++-------
 xen/common/Makefile                    |  2 +-
 xen/lib/Makefile                       |  1 +
 xen/{common => lib}/earlycpio.c        |  0
 15 files changed, 79 insertions(+), 35 deletions(-)
 rename xen/{common => lib}/earlycpio.c (100%)

base-commit: a2a34d76643e49ccc949296c9a45888034e50b55

Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/4 x86/ucode: Fix typo s/mitigiated/mitigated/

Not a functional change.

---
v3:
* No changes

---
 xen/arch/x86/cpu/microcode/amd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/cpu/microcode/amd.c +3 -3
index 2760ace921..71b041c84b 100644
@@ -101,7 +101,7 @@ static const struct patch_digest {
 } patch_digests[] = {
 #include "amd-patch-digests.c"
 };
-static bool __ro_after_init entrysign_mitigiated_in_firmware;
+static bool __ro_after_init entrysign_mitigated_in_firmware;
 
 static int cf_check cmp_patch_id(const void *key, const void *elem)
 {
@@ -127,7 +127,7 @@ static bool check_digest(const struct container_microcode *mc)
      * the digest of the patch against a list of known provenance.
      */
     if ( boot_cpu_data.family < 0x17 || boot_cpu_data.family > 0x1a ||
-         entrysign_mitigiated_in_firmware || !opt_digest_check )
+         entrysign_mitigated_in_firmware || !opt_digest_check )
         return true;
 
     pd = bsearch(&patch->patch_id, patch_digests, ARRAY_SIZE(patch_digests),
@@ -676,7 +676,7 @@ void __init amd_check_entrysign(void)
      */
     if ( (uint8_t)curr_rev >= fixed_rev )
     {
-        entrysign_mitigiated_in_firmware = true;
+        entrysign_mitigated_in_firmware = true;
         return;
     }
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/4 x86/ucode: Rename UCODE_SCAN_DEFAULT to MICROCODE_SCAN_DEFAULT

In reply to Alejandro Vallejo

We'd rather have the full spelling in Kconfig. Adjusts every other reference to the name too.

Not a functional change.

---
v3:
* New patch. Previously integrated in larger patch.

---
 automation/gitlab-ci/build.yaml   | 2 +-
 docs/misc/xen-command-line.pandoc | 2 +-
 xen/arch/x86/Kconfig              | 2 +-
 xen/arch/x86/cpu/microcode/core.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
automation/gitlab-ci/build.yaml +1 -1
index a6fc55c2d5..b69bad9202 100644
@@ -310,7 +310,7 @@ alpine-3.18-gcc-debug:
       CONFIG_ARGO=y
       CONFIG_UBSAN=y
       CONFIG_UBSAN_FATAL=y
-      CONFIG_UCODE_SCAN_DEFAULT=y
+      CONFIG_MICROCODE_SCAN_DEFAULT=y
       CONFIG_XHCI=y
 
 debian-13-x86_64-gcc-debug:
docs/misc/xen-command-line.pandoc +1 -1
index 50d7edb248..15f7a315a4 100644
@@ -2773,7 +2773,7 @@ microcode in the cpio name space must be:
   - on AMD  : kernel/x86/microcode/AuthenticAMD.bin
 When using xen.efi, the `ucode=<filename>` config file setting takes
 precedence over `scan`. The default value for `scan` is set with
-`CONFIG_UCODE_SCAN_DEFAULT`.
+`CONFIG_MICROCODE_SCAN_DEFAULT`.
 
 'nmi' determines late loading is performed in NMI handler or just in
 stop_machine context. In NMI handler, even NMIs are blocked, which is
xen/arch/x86/Kconfig +1 -1
index c808c989fc..d5705e4bff 100644
@@ -331,7 +331,7 @@ config REQUIRE_NX
 	  was unavailable. However, if enabled, Xen will no longer boot on
 	  any CPU which is lacking NX support.
 
-config UCODE_SCAN_DEFAULT
+config MICROCODE_SCAN_DEFAULT
 	bool "Scan for microcode by default"
 	help
 	  During boot, Xen can scan the multiboot images for a CPIO archive
xen/arch/x86/cpu/microcode/core.c +1 -1
index fe47c3a6c1..dabdb95b4c 100644
@@ -101,7 +101,7 @@ static struct microcode_patch *microcode_cache;
  * location we require that they are not both active together.
  */
 static int __initdata opt_mod_idx;
-static bool __initdata opt_scan = IS_ENABLED(CONFIG_UCODE_SCAN_DEFAULT);
+static bool __initdata opt_scan = IS_ENABLED(CONFIG_MICROCODE_SCAN_DEFAULT);
 bool __ro_after_init opt_digest_check = true;
 
 /*
Signature · 1 line
2.43.0
#4 lore raw

PATCH v3 3/4 earlycpio: lib-ify earlycpio.c

In reply to Alejandro Vallejo

It's only used for microcode loading on x86. By lib-ifying it we can make it go away automatically when microcode loading becomes an optional feature in follow-up patches.

---
v3:
* New patch. Subsumes earlier conditionalisation of earlycpio.c on CONFIG_MICROCODE_LOADING.

---
 docs/misra/exclude-list.json    | 8 ++++----
 xen/common/Makefile             | 2 +-
 xen/lib/Makefile                | 1 +
 xen/{common => lib}/earlycpio.c | 0
 4 files changed, 6 insertions(+), 5 deletions(-)
 rename xen/{common => lib}/earlycpio.c (100%)
docs/misra/exclude-list.json +4 -4
index 388397dd3b..2b874dfd3b 100644
@@ -121,10 +121,6 @@
             "rel_path": "common/bunzip2.c",
             "comment": "Imported from Linux, ignore for now"
         },
-        {
-            "rel_path": "common/earlycpio.c",
-            "comment": "Imported from Linux, ignore for now"
-        },
         {
             "rel_path": "common/gzip/*",
             "comment": "Imported from Linux, ignore for now"
@@ -225,6 +221,10 @@
             "rel_path": "include/xen/decompress.h",
             "comment": "Imported from Linux, ignore for now"
         },
+        {
+            "rel_path": "lib/earlycpio.c",
+            "comment": "Imported from Linux, ignore for now"
+        },
         {
             "rel_path": "lib/find-next-bit.c",
             "comment": "Imported from Linux, ignore for now"
xen/common/Makefile +1 -1
index 92c97d641e..4fc0c15088 100644
@@ -65,7 +65,7 @@ obj-y += wait.o
 obj-bin-y += warning.init.o
 obj-y += xmalloc_tlsf.o
 
-obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd earlycpio,$(n).init.o)
+obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd,$(n).init.o)
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o xlat.o)
 
xen/lib/Makefile +1 -0
index efca830d92..60cfda4dfc 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/
 lib-y += bsearch.o
 lib-y += ctors.o
 lib-y += ctype.o
+lib-y += earlycpio.o
 lib-y += find-next-bit.o
 lib-y += generic-ffsl.o
 lib-y += generic-flsl.o
xen/lib/earlycpio.c renamed from xen/common/earlycpio.c +0 -0
similarity index 100%
rename from xen/common/earlycpio.c
rename to xen/lib/earlycpio.c
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v3 3/4] earlycpio: lib-ify earlycpio.c

Quoted 33 lines · Alejandro Vallejo

It's only used for microcode loading on x86. By lib-ifying it we can make it go away automatically when microcode loading becomes an optional feature in follow-up patches.

---
v3:
* New patch. Subsumes earlier conditionalisation of earlycpio.c on CONFIG_MICROCODE_LOADING.

---
 docs/misra/exclude-list.json    | 8 ++++----
 xen/common/Makefile             | 2 +-
 xen/lib/Makefile                | 1 +
 xen/{common => lib}/earlycpio.c | 0
 4 files changed, 6 insertions(+), 5 deletions(-)
 rename xen/{common => lib}/earlycpio.c (100%)
docs/misra/exclude-list.json +0 -4
index 388397dd3b..2b874dfd3b 100644
@@ -121,10 +121,6 @@
             "rel_path": "common/bunzip2.c",
             "comment": "Imported from Linux, ignore for now"
         },
-        {
-            "rel_path": "common/earlycpio.c",
-            "comment": "Imported from Linux, ignore for now"
-        },
         {
             "rel_path": "common/gzip/*",
             "comment": "Imported from Linux, ignore for now"

docs/misra/exclude-list.json line 230

Quoted 10 lines
docs/misra/exclude-list.json +4 -0
@@ -225,6 +221,10 @@
             "rel_path": "include/xen/decompress.h",
             "comment": "Imported from Linux, ignore for now"
         },
+        {
+            "rel_path": "lib/earlycpio.c",
+            "comment": "Imported from Linux, ignore for now"
+        },
         {
             "rel_path": "lib/find-next-bit.c",
             "comment": "Imported from Linux, ignore for now"

Honestly, I think this needs simply dropping.  "ignore for now" isn't going to cut it with any competent evaluators.

By libryfing it, it's no longer part of the AMD target build, but it does want covering by *-allcode.

Given that you noticed it for v2, I presume there's something in the file that Eclair doesn't like?

xen/lib/earlycpio.c

Quoted 29 lines
xen/common/Makefile +1 -1
index 92c97d641e..4fc0c15088 100644
@@ -65,7 +65,7 @@ obj-y += wait.o
 obj-bin-y += warning.init.o
 obj-y += xmalloc_tlsf.o
 
-obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd earlycpio,$(n).init.o)
+obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd,$(n).init.o)
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o xlat.o)
 
xen/lib/Makefile +1 -0
index efca830d92..60cfda4dfc 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/
 lib-y += bsearch.o
 lib-y += ctors.o
 lib-y += ctype.o
+lib-y += earlycpio.o
 lib-y += find-next-bit.o
 lib-y += generic-ffsl.o
 lib-y += generic-flsl.o
xen/lib/earlycpio.c renamed from xen/common/earlycpio.c +0 -0
similarity index 100%
rename from xen/common/earlycpio.c
rename to xen/lib/earlycpio.c

What's wrong with .init here?  There's only a single string which will end up unmerged so I'm not worried on this side of things, but we now have series doing safety things getting tangled with .init and I want to get it fixed.

~Andrew

#6 lore raw

Re: [PATCH v3 3/4] earlycpio: lib-ify earlycpio.c

Quoted 39 lines · Andrew Cooper
Quoted 38 lines · Alejandro Vallejo

It's only used for microcode loading on x86. By lib-ifying it we can make it go away automatically when microcode loading becomes an optional feature in follow-up patches.

---
v3:
* New patch. Subsumes earlier conditionalisation of earlycpio.c on CONFIG_MICROCODE_LOADING.

---
 docs/misra/exclude-list.json    | 8 ++++----
 xen/common/Makefile             | 2 +-
 xen/lib/Makefile                | 1 +
 xen/{common => lib}/earlycpio.c | 0
 4 files changed, 6 insertions(+), 5 deletions(-)
 rename xen/{common => lib}/earlycpio.c (100%)
docs/misra/exclude-list.json +2 -4
index 388397dd3b..2b874dfd3b 100644
@@ -121,10 +121,6 @@
             "rel_path": "common/bunzip2.c",
             "comment": "Imported from Linux, ignore for now"
         },
-        {
-            "rel_path": "common/earlycpio.c",
-            "comment": "Imported from Linux, ignore for now"
-        },
         {
             "rel_path": "common/gzip/*",
             "comment": "Imported from Linux, ignore for now"
@@ -225,6 +221,10 @@
             "rel_path": "include/xen/decompress.h",
             "comment": "Imported from Linux, ignore for now"
         },
+        {
+            "rel_path": "lib/earlycpio.c",
Quoted 8 lines

docs/misra/exclude-list.json line 230

Quoted 5 lines
docs/misra/exclude-list.json +2 -0
+            "comment": "Imported from Linux, ignore for now"
+        },
         {
             "rel_path": "lib/find-next-bit.c",
             "comment": "Imported from Linux, ignore for now"

Honestly, I think this needs simply dropping.  "ignore for now" isn't going to cut it with any competent evaluators.

That would depend on justifications and such. But regardless clearing the exclusion list is a different matter aside from removing microcode loading.

Quoted 6 lines

By libryfing it, it's no longer part of the AMD target build, but it does want covering by *-allcode.

Given that you noticed it for v2, I presume there's something in the file that Eclair doesn't like?

I didn't run Eclair on it. It's ignored as part of common, and the build fails in CI if the file in common is absent. That's how I noticed it.

I'd rather not gate this particular change on earlycpio playing ball with Eclair.

Quoted 27 lines
Quoted 27 lines
xen/common/Makefile +1 -1
index 92c97d641e..4fc0c15088 100644
@@ -65,7 +65,7 @@ obj-y += wait.o
 obj-bin-y += warning.init.o
 obj-y += xmalloc_tlsf.o
 
-obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd earlycpio,$(n).init.o)
+obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd,$(n).init.o)
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o xlat.o)
 
xen/lib/Makefile +1 -0
index efca830d92..60cfda4dfc 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/
 lib-y += bsearch.o
 lib-y += ctors.o
 lib-y += ctype.o
+lib-y += earlycpio.o
 lib-y += find-next-bit.o
 lib-y += generic-ffsl.o
 lib-y += generic-flsl.o
xen/lib/earlycpio.c renamed from xen/common/earlycpio.c +0 -0
Quoted 8 lines
Quoted 3 lines

similarity index 100%
rename from xen/common/earlycpio.c
rename to xen/lib/earlycpio.c

What's wrong with .init here?  There's only a single string which will end up unmerged so I'm not worried on this side of things, but we now have series doing safety things getting tangled with .init and I want to get it fixed.

.init.o doesn't work with lib-y; only obj-y, obj-bin-y and extra-y. See below:

  $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS-y += -DINIT_SECTIONS_ONLY

[snip]

  non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y))

[snip]

  $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): $(obj)/%.init.o: $(obj)/%.o FORCE
  	$(call if_changed,obj_init_o)

That's just what I eyeballed. There might be more hidden elsewhere.

It might want fixing, specially if something like libfdt is to turn into a library. But it's just not relevant for this particular change where the single contained function is already __init.

Cheers,
Alejandro

#7 lore raw

Re: [PATCH v3 3/4] earlycpio: lib-ify earlycpio.c

Quoted 53 lines · Alejandro Vallejo
Quoted 38 lines · Andrew Cooper
Quoted 37 lines · Alejandro Vallejo

It's only used for microcode loading on x86. By lib-ifying it we can make it go away automatically when microcode loading becomes an optional feature in follow-up patches.

---
v3:
* New patch. Subsumes earlier conditionalisation of earlycpio.c on CONFIG_MICROCODE_LOADING.

---
 docs/misra/exclude-list.json    | 8 ++++----
 xen/common/Makefile             | 2 +-
 xen/lib/Makefile                | 1 +
 xen/{common => lib}/earlycpio.c | 0
 4 files changed, 6 insertions(+), 5 deletions(-)
 rename xen/{common => lib}/earlycpio.c (100%)
docs/misra/exclude-list.json +1 -4
index 388397dd3b..2b874dfd3b 100644
@@ -121,10 +121,6 @@
             "rel_path": "common/bunzip2.c",
             "comment": "Imported from Linux, ignore for now"
         },
-        {
-            "rel_path": "common/earlycpio.c",
-            "comment": "Imported from Linux, ignore for now"
-        },
         {
             "rel_path": "common/gzip/*",
             "comment": "Imported from Linux, ignore for now"
@@ -225,6 +221,10 @@
             "rel_path": "include/xen/decompress.h",
             "comment": "Imported from Linux, ignore for now"
         },
+        {
Quoted 8 lines

docs/misra/exclude-list.json line 230

Quoted 6 lines
docs/misra/exclude-list.json +3 -0
+            "rel_path": "lib/earlycpio.c",
+            "comment": "Imported from Linux, ignore for now"
+        },
         {
             "rel_path": "lib/find-next-bit.c",
             "comment": "Imported from Linux, ignore for now"

Honestly, I think this needs simply dropping.  "ignore for now" isn't going to cut it with any competent evaluators.

That would depend on justifications and such. But regardless clearing the exclusion list is a different matter aside from removing microcode loading.

Quoted 3 lines

By libryfing it, it's no longer part of the AMD target build, but it does want covering by *-allcode.

Quoted 7 lines
Quoted 2 lines

Given that you noticed it for v2, I presume there's something in the file that Eclair doesn't like?

I didn't run Eclair on it. It's ignored as part of common, and the build fails in CI if the file in common is absent. That's how I noticed it.

I'd rather not gate this particular change on earlycpio playing ball with Eclair.

I'm explicitly not gating it.  *-allcode is non-blocking, but I want earlycpio being scanned.

Simply omitting the second hunk should do this, and not explode the AMD target build.  (Once this patch is reordered to the end of the series.)

Quoted 44 lines
Quoted 26 lines
Quoted 26 lines
xen/common/Makefile +1 -1
index 92c97d641e..4fc0c15088 100644
@@ -65,7 +65,7 @@ obj-y += wait.o
 obj-bin-y += warning.init.o
 obj-y += xmalloc_tlsf.o
 
-obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd earlycpio,$(n).init.o)
+obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd,$(n).init.o)
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o xlat.o)
 
xen/lib/Makefile +1 -0
index efca830d92..60cfda4dfc 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/
 lib-y += bsearch.o
 lib-y += ctors.o
 lib-y += ctype.o
+lib-y += earlycpio.o
 lib-y += find-next-bit.o
 lib-y += generic-ffsl.o
 lib-y += generic-flsl.o
Quoted 8 lines

xen/lib/earlycpio.c

Quoted 4 lines
xen/lib/earlycpio.c renamed from xen/common/earlycpio.c +0 -0
similarity index 100%
rename from xen/common/earlycpio.c
rename to xen/lib/earlycpio.c

What's wrong with .init here?  There's only a single string which will end up unmerged so I'm not worried on this side of things, but we now have series doing safety things getting tangled with .init and I want to get it fixed.

.init.o doesn't work with lib-y; only obj-y, obj-bin-y and extra-y. See below:

  $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS-y += -DINIT_SECTIONS_ONLY

[snip]

  non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y))

[snip]

Quoted 8 lines
  $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): $(obj)/%.init.o: $(obj)/%.o FORCE
  	$(call if_changed,obj_init_o)

That's just what I eyeballed. There might be more hidden elsewhere.

It might want fixing, specially if something like libfdt is to turn into a library. But it's just not relevant for this particular change where the single contained function is already __init.

*.init.o does two things:

1) For things we can tag, check everything is tagged
2) For things we can't tag with __section(), such as string literals, move them into .init

Fixing lib init properly should just be a case of sprinkling lib-y through those places you mention.  If you want me to do the patch then fine, but I want it fixed rather than keeping on going around in circles.

~Andrew

#8 lore raw

Re: [PATCH v3 3/4] earlycpio: lib-ify earlycpio.c

Quoted 56 lines · Andrew Cooper
Quoted 55 lines · Alejandro Vallejo
Quoted 38 lines · Andrew Cooper
Quoted 37 lines · Alejandro Vallejo

It's only used for microcode loading on x86. By lib-ifying it we can make it go away automatically when microcode loading becomes an optional feature in follow-up patches.

---
v3:
* New patch. Subsumes earlier conditionalisation of earlycpio.c on CONFIG_MICROCODE_LOADING.

---
 docs/misra/exclude-list.json    | 8 ++++----
 xen/common/Makefile             | 2 +-
 xen/lib/Makefile                | 1 +
 xen/{common => lib}/earlycpio.c | 0
 4 files changed, 6 insertions(+), 5 deletions(-)
 rename xen/{common => lib}/earlycpio.c (100%)
docs/misra/exclude-list.json +1 -4
index 388397dd3b..2b874dfd3b 100644
@@ -121,10 +121,6 @@
             "rel_path": "common/bunzip2.c",
             "comment": "Imported from Linux, ignore for now"
         },
-        {
-            "rel_path": "common/earlycpio.c",
-            "comment": "Imported from Linux, ignore for now"
-        },
         {
             "rel_path": "common/gzip/*",
             "comment": "Imported from Linux, ignore for now"
@@ -225,6 +221,10 @@
             "rel_path": "include/xen/decompress.h",
             "comment": "Imported from Linux, ignore for now"
         },
+        {
Quoted 8 lines

docs/misra/exclude-list.json line 230

Quoted 6 lines
docs/misra/exclude-list.json +3 -0
+            "rel_path": "lib/earlycpio.c",
+            "comment": "Imported from Linux, ignore for now"
+        },
         {
             "rel_path": "lib/find-next-bit.c",
             "comment": "Imported from Linux, ignore for now"

Honestly, I think this needs simply dropping.  "ignore for now" isn't going to cut it with any competent evaluators.

That would depend on justifications and such. But regardless clearing the exclusion list is a different matter aside from removing microcode loading.

Quoted 5 lines

By libryfing it, it's no longer part of the AMD target build, but it does want covering by *-allcode.

Given that you noticed it for v2, I presume there's something in the file that Eclair doesn't like?

Quoted 8 lines
Quoted 5 lines

I didn't run Eclair on it. It's ignored as part of common, and the build fails in CI if the file in common is absent. That's how I noticed it.

I'd rather not gate this particular change on earlycpio playing ball with Eclair.

I'm explicitly not gating it.  *-allcode is non-blocking, but I want earlycpio being scanned.

In fairness to Alejandro - you're asking for an entirely unrelated change. If it was really just ...

Quoted 2 lines

Simply omitting the second hunk should do this, and not explode the AMD target build.  (Once this patch is reordered to the end of the series.)

... this, then probably okay(ish). But afaict MICROCODE_LOADING needs to then be turned off for *-amd, which patch 4 doesn't do (yet) afaics.

Jan

#9 lore raw

Re: [PATCH v3 3/4] earlycpio: lib-ify earlycpio.c

In reply to Andrew Cooper
Quoted 123 lines · Andrew Cooper
Quoted 53 lines · Alejandro Vallejo
Quoted 38 lines · Andrew Cooper
Quoted 37 lines · Alejandro Vallejo

It's only used for microcode loading on x86. By lib-ifying it we can make it go away automatically when microcode loading becomes an optional feature in follow-up patches.

---
v3:
* New patch. Subsumes earlier conditionalisation of earlycpio.c on CONFIG_MICROCODE_LOADING.

---
 docs/misra/exclude-list.json    | 8 ++++----
 xen/common/Makefile             | 2 +-
 xen/lib/Makefile                | 1 +
 xen/{common => lib}/earlycpio.c | 0
 4 files changed, 6 insertions(+), 5 deletions(-)
 rename xen/{common => lib}/earlycpio.c (100%)
docs/misra/exclude-list.json +1 -4
index 388397dd3b..2b874dfd3b 100644
@@ -121,10 +121,6 @@
             "rel_path": "common/bunzip2.c",
             "comment": "Imported from Linux, ignore for now"
         },
-        {
-            "rel_path": "common/earlycpio.c",
-            "comment": "Imported from Linux, ignore for now"
-        },
         {
             "rel_path": "common/gzip/*",
             "comment": "Imported from Linux, ignore for now"
@@ -225,6 +221,10 @@
             "rel_path": "include/xen/decompress.h",
             "comment": "Imported from Linux, ignore for now"
         },
+        {
Quoted 8 lines

docs/misra/exclude-list.json line 230

Quoted 6 lines
docs/misra/exclude-list.json +3 -0
+            "rel_path": "lib/earlycpio.c",
+            "comment": "Imported from Linux, ignore for now"
+        },
         {
             "rel_path": "lib/find-next-bit.c",
             "comment": "Imported from Linux, ignore for now"

Honestly, I think this needs simply dropping.  "ignore for now" isn't going to cut it with any competent evaluators.

That would depend on justifications and such. But regardless clearing the exclusion list is a different matter aside from removing microcode loading.

Quoted 3 lines

By libryfing it, it's no longer part of the AMD target build, but it does want covering by *-allcode.

Quoted 7 lines
Quoted 2 lines

Given that you noticed it for v2, I presume there's something in the file that Eclair doesn't like?

I didn't run Eclair on it. It's ignored as part of common, and the build fails in CI if the file in common is absent. That's how I noticed it.

I'd rather not gate this particular change on earlycpio playing ball with Eclair.

I'm explicitly not gating it.  *-allcode is non-blocking, but I want earlycpio being scanned.

Simply omitting the second hunk should do this, and not explode the AMD target build.  (Once this patch is reordered to the end of the series.)

Quoted 44 lines
Quoted 26 lines
Quoted 26 lines
xen/common/Makefile +1 -1
index 92c97d641e..4fc0c15088 100644
@@ -65,7 +65,7 @@ obj-y += wait.o
 obj-bin-y += warning.init.o
 obj-y += xmalloc_tlsf.o
 
-obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd earlycpio,$(n).init.o)
+obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd,$(n).init.o)
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o xlat.o)
 
xen/lib/Makefile +1 -0
index efca830d92..60cfda4dfc 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/
 lib-y += bsearch.o
 lib-y += ctors.o
 lib-y += ctype.o
+lib-y += earlycpio.o
 lib-y += find-next-bit.o
 lib-y += generic-ffsl.o
 lib-y += generic-flsl.o
Quoted 8 lines

xen/lib/earlycpio.c

Quoted 4 lines
xen/lib/earlycpio.c renamed from xen/common/earlycpio.c +0 -0
similarity index 100%
rename from xen/common/earlycpio.c
rename to xen/lib/earlycpio.c

What's wrong with .init here?  There's only a single string which will end up unmerged so I'm not worried on this side of things, but we now have series doing safety things getting tangled with .init and I want to get it fixed.

.init.o doesn't work with lib-y; only obj-y, obj-bin-y and extra-y. See below:

  $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS-y += -DINIT_SECTIONS_ONLY

[snip]

  non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y))

[snip]

Quoted 8 lines
  $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): $(obj)/%.init.o: $(obj)/%.o FORCE
  	$(call if_changed,obj_init_o)

That's just what I eyeballed. There might be more hidden elsewhere.

It might want fixing, specially if something like libfdt is to turn into a library. But it's just not relevant for this particular change where the single contained function is already __init.

*.init.o does two things:

Quoted 8 lines

1) For things we can tag, check everything is tagged
2) For things we can't tag with __section(), such as string literals, move them into .init

Fixing lib init properly should just be a case of sprinkling lib-y through those places you mention.  If you want me to do the patch then fine, but I want it fixed rather than keeping on going around in circles.

I can do it, but I'll make a new series to deal with that independently of this if that's alright. Feel free to leave this patch uncommitted until then.

I care far more about the next patch going in.

Cheers,
Alejandro

#10 lore raw

PATCH v3 4/4 x86/ucode: Add Kconfig option to remove microcode loading

In reply to Alejandro Vallejo

Amend docs to reflect ucode= command/stanza depend on MICROCODE_LOADING being set.

The new MICROCODE_OP() is a conditional setter for the microcode_ops struct. By using IS_ENABLED() there ratehr than ifdef we allow DCE to remove all statics no longer used when microcode loading is disabled without tagging them with __maybe_unused.

---
v3:
* Moved MICROCODE_SCAN_DEFAULT to a separate patch
* Added doc change to admin-guide
* Added Andrew's suggestion for Kconfig help text
* Inlined can_apply_microcode() macro in core.c
* Kept the platform-ops, gating them on CONFIG_MICROCODE_LOADING through the new MICROCODE_OP() macro.

---
 docs/admin-guide/microcode-loading.rst |  2 ++
 docs/misc/efi.pandoc                   |  2 ++
 docs/misc/xen-command-line.pandoc      |  2 +-
 xen/arch/x86/Kconfig                   | 14 ++++++++++++++
 xen/arch/x86/cpu/microcode/amd.c       | 16 +++++++++-------
 xen/arch/x86/cpu/microcode/core.c      | 15 ++++++++++++---
 xen/arch/x86/cpu/microcode/intel.c     | 11 +++++++----
 xen/arch/x86/cpu/microcode/private.h   |  2 ++
 xen/arch/x86/efi/efi-boot.h            |  3 ++-
 xen/arch/x86/platform_hypercall.c      | 22 +++++++++++++++-------
 10 files changed, 66 insertions(+), 23 deletions(-)
docs/admin-guide/microcode-loading.rst +2 -0
index a07e25802f..148bc8559b 100644
@@ -23,6 +23,8 @@ TSX errata which necessitated disabling the feature entirely), or the addition
 of brand new features (e.g. the Spectre v2 controls to work around speculative
 execution vulnerabilities).
 
+Microcode loading support in Xen is controlled by the
+``CONFIG_MICROCODE_LOADING`` Kconfig option.
 
 Boot time microcode loading
 ---------------------------
docs/misc/efi.pandoc +2 -0
index 11c1ac3346..c3fb1f3a30 100644
@@ -104,6 +104,8 @@ Specifies an XSM module to load.
 
 Specifies a CPU microcode blob to load. (x86 only)
 
+Only available when Xen is compiled with CONFIG_MICROCODE_LOADING.
+
 ###`dtb=<filename>`
 
 Specifies a device tree file to load.  The platform firmware may provide a
docs/misc/xen-command-line.pandoc +1 -1
index 15f7a315a4..866fa2f951 100644
@@ -2748,7 +2748,7 @@ performance.
 ### ucode
 > `= List of [ <integer> | scan=<bool>, nmi=<bool>, digest-check=<bool> ]`
 
-    Applicability: x86
+    Applicability: x86 with CONFIG_MICROCODE_LOADING active
     Default: `scan` is selectable via Kconfig, `nmi,digest-check`
 
 Controls for CPU microcode loading. For early loading, this parameter can
xen/arch/x86/Kconfig +14 -0
index d5705e4bff..61f58aa829 100644
@@ -331,8 +331,22 @@ config REQUIRE_NX
 	  was unavailable. However, if enabled, Xen will no longer boot on
 	  any CPU which is lacking NX support.
 
+config MICROCODE_LOADING
+	bool "Microcode loading"
+	default y
+	help
+	  Microcode updates for CPUs fix errata and provide new functionality for
+	  software to work around bugs, such as the speculative execution
+	  vulnerabilities. It is common for OSes to carry updated microcode as
+	  software tends to get updated more frequently than firmware.
+
+	  For embedded environments where a full firmware/software stack is being
+	  provided, it might not be necessary for Xen to need to load microcode
+	  itself.
+
 config MICROCODE_SCAN_DEFAULT
 	bool "Scan for microcode by default"
+	depends on MICROCODE_LOADING
 	help
 	  During boot, Xen can scan the multiboot images for a CPIO archive
 	  containing CPU microcode to be loaded, which is Linux's mechanism for
xen/arch/x86/cpu/microcode/amd.c +9 -7
index 71b041c84b..86706a21a6 100644
@@ -561,11 +561,11 @@ static const char __initconst amd_cpio_path[] =
     "kernel/x86/microcode/AuthenticAMD.bin";
 
 static const struct microcode_ops __initconst_cf_clobber amd_ucode_ops = {
-    .cpu_request_microcode            = cpu_request_microcode,
+    .cpu_request_microcode            = MICROCODE_OP(cpu_request_microcode),
     .collect_cpu_info                 = collect_cpu_info,
-    .apply_microcode                  = apply_microcode,
-    .compare                          = amd_compare,
-    .cpio_path                        = amd_cpio_path,
+    .apply_microcode                  = MICROCODE_OP(apply_microcode),
+    .compare                          = MICROCODE_OP(amd_compare),
+    .cpio_path                        = MICROCODE_OP(amd_cpio_path),
 };
 
 void __init ucode_probe_amd(struct microcode_ops *ops)
@@ -574,7 +574,8 @@ void __init ucode_probe_amd(struct microcode_ops *ops)
      * The Entrysign vulnerability (SB-7033, CVE-2024-36347) affects Zen1-5
      * CPUs.  Taint Xen if digest checking is turned off.
      */
-    if ( boot_cpu_data.family >= 0x17 && boot_cpu_data.family <= 0x1a &&
+    if ( IS_ENABLED(CONFIG_MICROCODE_LOADING) &&
+         boot_cpu_data.family >= 0x17 && boot_cpu_data.family <= 0x1a &&
          !opt_digest_check )
     {
         printk(XENLOG_WARNING
@@ -614,8 +615,9 @@ void __init amd_check_entrysign(void)
     unsigned int curr_rev;
     uint8_t fixed_rev;
 
-    if ( boot_cpu_data.vendor != X86_VENDOR_AMD ||
-         boot_cpu_data.family < 0x17 ||
+    if ( !IS_ENABLED(CONFIG_MICROCODE_LOADING)  ||
+         boot_cpu_data.vendor != X86_VENDOR_AMD ||
+         boot_cpu_data.family < 0x17            ||
          boot_cpu_data.family > 0x1a )
         return;
 
xen/arch/x86/cpu/microcode/core.c +12 -3
index dabdb95b4c..efaf808f1a 100644
@@ -58,7 +58,7 @@
  */
 #define MICROCODE_UPDATE_TIMEOUT_US 1000000
 
-static bool __initdata ucode_mod_forced;
+static bool __initdata __maybe_unused ucode_mod_forced;
 static unsigned int nr_cores;
 
 /*
@@ -104,6 +104,7 @@ static int __initdata opt_mod_idx;
 static bool __initdata opt_scan = IS_ENABLED(CONFIG_MICROCODE_SCAN_DEFAULT);
 bool __ro_after_init opt_digest_check = true;
 
+#ifdef CONFIG_MICROCODE_LOADING
 /*
  * Used by the EFI path only, when xen.cfg identifies an explicit microcode
  * file.  Overrides ucode=<int>|scan on the regular command line.
@@ -162,6 +163,7 @@ static int __init cf_check parse_ucode(const char *s)
     return rc;
 }
 custom_param("ucode", parse_ucode);
+#endif /* CONFIG_MICROCODE_LOADING */
 
 static struct microcode_ops __ro_after_init ucode_ops;
 
@@ -469,7 +471,7 @@ struct ucode_buf {
     char buffer[];
 };
 
-static long cf_check ucode_update_hcall_cont(void *data)
+static long cf_check __maybe_unused ucode_update_hcall_cont(void *data)
 {
     struct microcode_patch *patch = NULL;
     int ret, result;
@@ -613,6 +615,7 @@ static long cf_check ucode_update_hcall_cont(void *data)
     return ret;
 }
 
+#ifdef CONFIG_MICROCODE_LOADING
 int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
                        unsigned long len, unsigned int flags)
 {
@@ -645,6 +648,7 @@ int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
      */
     return continue_hypercall_on_cpu(0, ucode_update_hcall_cont, buffer);
 }
+#endif /* CONFIG_MICROCODE_LOADING */
 
 /* Load a cached update to current cpu */
 int microcode_update_one(void)
@@ -658,7 +662,7 @@ int microcode_update_one(void)
     if ( ucode_ops.collect_cpu_info )
         alternative_vcall(ucode_ops.collect_cpu_info);
 
-    if ( !ucode_ops.apply_microcode )
+    if ( !IS_ENABLED(CONFIG_MICROCODE_LOADING) || !ucode_ops.apply_microcode )
         return -EOPNOTSUPP;
 
     spin_lock(&microcode_mutex);
@@ -678,6 +682,7 @@ int microcode_update_one(void)
  */
 static int __initdata early_mod_idx = -1;
 
+#ifdef CONFIG_MICROCODE_LOADING
 static int __init cf_check microcode_init_cache(void)
 {
     struct boot_info *bi = &xen_boot_info;
@@ -734,6 +739,7 @@ static int __init cf_check microcode_init_cache(void)
     return rc;
 }
 presmp_initcall(microcode_init_cache);
+#endif /* CONFIG_MICROCODE_LOADING */
 
 /*
  * There are several tasks:
@@ -898,6 +904,9 @@ int __init early_microcode_init(struct boot_info *bi)
 
     printk(XENLOG_INFO "BSP microcode revision: 0x%08x\n", this_cpu(cpu_sig).rev);
 
+    if ( !IS_ENABLED(CONFIG_MICROCODE_LOADING) )
+        return -ENODEV;
+
     /*
      * Some hypervisors deliberately report a microcode revision of -1 to
      * mean that they will not accept microcode updates.
xen/arch/x86/cpu/microcode/intel.c +7 -4
index 281993e725..ba99f4ffdc 100644
@@ -408,17 +408,20 @@ static const char __initconst intel_cpio_path[] =
     "kernel/x86/microcode/GenuineIntel.bin";
 
 static const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = {
-    .cpu_request_microcode            = cpu_request_microcode,
+    .cpu_request_microcode            = MICROCODE_OP(cpu_request_microcode),
     .collect_cpu_info                 = collect_cpu_info,
-    .apply_microcode                  = apply_microcode,
-    .compare                          = intel_compare,
-    .cpio_path                        = intel_cpio_path,
+    .apply_microcode                  = MICROCODE_OP(apply_microcode),
+    .compare                          = MICROCODE_OP(intel_compare),
+    .cpio_path                        = MICROCODE_OP(intel_cpio_path),
 };
 
 void __init ucode_probe_intel(struct microcode_ops *ops)
 {
     *ops = intel_ucode_ops;
 
+    if ( !IS_ENABLED(CONFIG_MICROCODE_LOADING) )
+        return;
+
     if ( !can_load_microcode() )
         ops->apply_microcode = NULL;
 }
xen/arch/x86/cpu/microcode/private.h +2 -0
index e6c965dc99..1167b79db1 100644
@@ -93,4 +93,6 @@ void ucode_probe_intel(struct microcode_ops *ops);
 static inline void ucode_probe_intel(struct microcode_ops *ops) {}
 #endif
 
+#define MICROCODE_OP(x) (IS_ENABLED(CONFIG_MICROCODE_LOADING) ? (x) : NULL)
+
 #endif /* ASM_X86_MICROCODE_PRIVATE_H */
xen/arch/x86/efi/efi-boot.h +2 -1
index 0194720003..42a2c46b5e 100644
@@ -295,7 +295,8 @@ static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image,
 {
     union string name;
 
-    if ( read_section(image, L"ucode", &ucode, NULL) )
+    if ( !IS_ENABLED(CONFIG_MICROCODE_LOADING) ||
+         read_section(image, L"ucode", &ucode, NULL) )
         return;
 
     name.s = get_value(&cfg, section, "ucode");
xen/arch/x86/platform_hypercall.c +15 -7
index 79bb99e0b6..a55060e662 100644
@@ -309,22 +309,30 @@ ret_t do_platform_op(
 
     case XENPF_microcode_update:
     {
-        XEN_GUEST_HANDLE(const_void) data;
+        ret = -EOPNOTSUPP;
+        if ( IS_ENABLED(CONFIG_MICROCODE_LOADING) )
+        {
+            XEN_GUEST_HANDLE(const_void) data;
 
-        guest_from_compat_handle(data, op->u.microcode.data);
+            guest_from_compat_handle(data, op->u.microcode.data);
+            ret = ucode_update_hcall(data, op->u.microcode.length, 0);
+        }
 
-        ret = ucode_update_hcall(data, op->u.microcode.length, 0);
         break;
     }
 
     case XENPF_microcode_update2:
     {
-        XEN_GUEST_HANDLE(const_void) data;
+        ret = -EOPNOTSUPP;
+        if ( IS_ENABLED(CONFIG_MICROCODE_LOADING) )
+        {
+            XEN_GUEST_HANDLE(const_void) data;
 
-        guest_from_compat_handle(data, op->u.microcode2.data);
+            guest_from_compat_handle(data, op->u.microcode2.data);
+            ret = ucode_update_hcall(data, op->u.microcode2.length,
+                                     op->u.microcode2.flags);
+        }
 
-        ret = ucode_update_hcall(data, op->u.microcode2.length,
-                                 op->u.microcode2.flags);
         break;
     }
 
Signature · 1 line
2.43.0
Reviewed-by on v3 4/4
#11 lore raw

Re: [PATCH v3 4/4] x86/ucode: Add Kconfig option to remove microcode loading

Quoted 5 lines · Alejandro Vallejo

Amend docs to reflect ucode= command/stanza depend on MICROCODE_LOADING being set.

The new MICROCODE_OP() is a conditional setter for the microcode_ops struct. By using IS_ENABLED() there ratehr than ifdef we allow DCE to

rather

Quoted 4 lines

remove all statics no longer used when microcode loading is disabled without tagging them with __maybe_unused.

more minor points, all of which I can fix on commit.

AFAICT, this can be reordered with the earlycpuio patch 3 ?

docs/misc/efi.pandoc Specifies an XSM module to load. · line 107

Quoted 9 lines
docs/misc/efi.pandoc +1 -0
index 11c1ac3346..c3fb1f3a30 100644
@@ -104,6 +104,8 @@ Specifies an XSM module to load.
 
 Specifies a CPU microcode blob to load. (x86 only)
 
+Only available when Xen is compiled with CONFIG_MICROCODE_LOADING.

enabled.

Quoted 9 lines
docs/misc/efi.pandoc +1 -0
+
 ###`dtb=<filename>`
 
 Specifies a device tree file to load.  The platform firmware may provide a
docs/misc/xen-command-line.pandoc +0 -0
index 15f7a315a4..866fa2f951 100644

docs/misc/xen-command-line.pandoc performance. · line 2752

Quoted 6 lines
docs/misc/xen-command-line.pandoc +1 -1
@@ -2748,7 +2748,7 @@ performance.
 ### ucode
 > `= List of [ <integer> | scan=<bool>, nmi=<bool>, digest-check=<bool> ]`
 
-    Applicability: x86
+    Applicability: x86 with CONFIG_MICROCODE_LOADING active
     Default: `scan` is selectable via Kconfig, `nmi,digest-check`

This isn't actually how we provide such information.  It's usually a sentence in the first paragraph.

(quoted diff) +0 -0

b/docs/misc/xen-command-line.pandoc
index 50d7edb2488e..5b6ff94f441a 100644

docs/misc/xen-command-line.pandoc +0 -0
@@ -2751,9 +2751,10 @@ performance.

     Applicability: x86
     Default: scan is selectable via Kconfig, nmi,digest-check
-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. +Controls for CPU microcode loading, available when CONFIG_MICROCODE_LOADING
+is enabled.  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.

 '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

which is the re-wrapped version of inserting ', available when CONFIG_MICROCODE_LOADING is enabled'.

Quoted 8 lines
xen/arch/x86/cpu/microcode/amd.c +0 -0
index 71b041c84b..86706a21a6 100644
@@ -561,11 +561,11 @@ static const char __initconst amd_cpio_path[] =
     "kernel/x86/microcode/AuthenticAMD.bin";
 
 static const struct microcode_ops __initconst_cf_clobber amd_ucode_ops = {

xen/arch/x86/cpu/microcode/amd.c static const char __initconst amd_cpio_path[] = · line 569

Quoted 10 lines
xen/arch/x86/cpu/microcode/amd.c +4 -4
-    .cpu_request_microcode            = cpu_request_microcode,
+    .cpu_request_microcode            = MICROCODE_OP(cpu_request_microcode),
     .collect_cpu_info                 = collect_cpu_info,
-    .apply_microcode                  = apply_microcode,
-    .compare                          = amd_compare,
-    .cpio_path                        = amd_cpio_path,
+    .apply_microcode                  = MICROCODE_OP(apply_microcode),
+    .compare                          = MICROCODE_OP(amd_compare),
+    .cpio_path                        = MICROCODE_OP(amd_cpio_path),
 };

Reordering cpu_request_microcode and collect_cpu_info like before makes this easier to read.

xen/arch/x86/cpu/microcode/private.h void ucode_probe_intel(struct microcode_ops *ops); · line 97

Quoted 10 lines
xen/arch/x86/cpu/microcode/private.h +2 -0
index e6c965dc99..1167b79db1 100644
@@ -93,4 +93,6 @@ void ucode_probe_intel(struct microcode_ops *ops);
 static inline void ucode_probe_intel(struct microcode_ops *ops) {}
 #endif
 
+#define MICROCODE_OP(x) (IS_ENABLED(CONFIG_MICROCODE_LOADING) ? (x) : NULL)
+

This wants /* Aids dead-code elimination of the static hooks */

and wants to be up beside struct microcode_ops.

Quoted 32 lines
xen/arch/x86/platform_hypercall.c +11 -5
index 79bb99e0b6..a55060e662 100644
@@ -309,22 +309,30 @@ ret_t do_platform_op(
 
     case XENPF_microcode_update:
     {
-        XEN_GUEST_HANDLE(const_void) data;
+        ret = -EOPNOTSUPP;
+        if ( IS_ENABLED(CONFIG_MICROCODE_LOADING) )
+        {
+            XEN_GUEST_HANDLE(const_void) data;
 
-        guest_from_compat_handle(data, op->u.microcode.data);
+            guest_from_compat_handle(data, op->u.microcode.data);
+            ret = ucode_update_hcall(data, op->u.microcode.length, 0);
+        }
 
-        ret = ucode_update_hcall(data, op->u.microcode.length, 0);
         break;
     }
 
     case XENPF_microcode_update2:
     {
-        XEN_GUEST_HANDLE(const_void) data;
+        ret = -EOPNOTSUPP;
+        if ( IS_ENABLED(CONFIG_MICROCODE_LOADING) )
+        {
+            XEN_GUEST_HANDLE(const_void) data;
 
-        guest_from_compat_handle(data, op->u.microcode2.data);

xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 338

Quoted 10 lines
xen/arch/x86/platform_hypercall.c +4 -2
+            guest_from_compat_handle(data, op->u.microcode2.data);
+            ret = ucode_update_hcall(data, op->u.microcode2.length,
+                                     op->u.microcode2.flags);
+        }
 
-        ret = ucode_update_hcall(data, op->u.microcode2.length,
-                                 op->u.microcode2.flags);
         break;
     }
 

Both these hunks will be smaller as:

    ret = -EOPNOTSUPP;
    if ( !IS_ENABLED(CONFIG_MICROCODE_LOADING) )
        break;

and that's the preferred style too.

Otherwise, Reviewed-by: Andrew Cooper <[email protected]> and I can fix all of these con commit.

AFAICT, this can be reordered with the earlycpio patch 3 ?

~Andrew

#12 lore raw

Re: [PATCH v3 4/4] x86/ucode: Add Kconfig option to remove microcode loading

In reply to Alejandro Vallejo

xen/arch/x86/cpu/microcode/core.c struct ucode_buf { · line 477

Quoted 9 lines · Alejandro Vallejo
xen/arch/x86/cpu/microcode/core.c +1 -1
@@ -469,7 +471,7 @@ struct ucode_buf {
     char buffer[];
 };
 
-static long cf_check ucode_update_hcall_cont(void *data)
+static long cf_check __maybe_unused ucode_update_hcall_cont(void *data)
 {
     struct microcode_patch *patch = NULL;
     int ret, result;

Why this change when ...

xen/arch/x86/cpu/microcode/core.c static long cf_check ucode_update_hcall_cont(void *data) · line 618

Quoted 5 lines
xen/arch/x86/cpu/microcode/core.c +1 -0
@@ -613,6 +615,7 @@ static long cf_check ucode_update_hcall_cont(void *data)
     return ret;
 }
 
+#ifdef CONFIG_MICROCODE_LOADING

... this can simply be moved up accordingly? After all ...

xen/arch/x86/cpu/microcode/core.c int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf, · line 649

Quoted 6 lines
xen/arch/x86/cpu/microcode/core.c +0 -0
 int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
                        unsigned long len, unsigned int flags)
 {
@@ -645,6 +648,7 @@ int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
      */
     return continue_hypercall_on_cpu(0, ucode_update_hcall_cont, buffer);

... this is the only user of that other function.

Quoted 6 lines
xen/arch/x86/cpu/microcode/intel.c +0 -0
@@ -408,17 +408,20 @@ static const char __initconst intel_cpio_path[] =
     "kernel/x86/microcode/GenuineIntel.bin";
 
 static const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = {

xen/arch/x86/cpu/microcode/intel.c static const char __initconst intel_cpio_path[] = · line 416

Quoted 10 lines
xen/arch/x86/cpu/microcode/intel.c +4 -4
-    .cpu_request_microcode            = cpu_request_microcode,
+    .cpu_request_microcode            = MICROCODE_OP(cpu_request_microcode),
     .collect_cpu_info                 = collect_cpu_info,
-    .apply_microcode                  = apply_microcode,
-    .compare                          = intel_compare,
-    .cpio_path                        = intel_cpio_path,
+    .apply_microcode                  = MICROCODE_OP(apply_microcode),
+    .compare                          = MICROCODE_OP(intel_compare),
+    .cpio_path                        = MICROCODE_OP(intel_cpio_path),
 };

While I appreciate the intention with MICROCODE_OP(), I'm not really happy with function pointer members left in place just for them to be NULL everywhere. What if a call site remains unguarded? With PV guests that would be a privilege escalation XSA.

Jan

#13 lore raw

Re: [PATCH v3 4/4] x86/ucode: Add Kconfig option to remove microcode loading

Quoted 21 lines · Jan Beulich

xen/arch/x86/cpu/microcode/core.c struct ucode_buf { · line 477

Quoted 9 lines · Alejandro Vallejo
xen/arch/x86/cpu/microcode/core.c +1 -1
@@ -469,7 +471,7 @@ struct ucode_buf {
     char buffer[];
 };
 
-static long cf_check ucode_update_hcall_cont(void *data)
+static long cf_check __maybe_unused ucode_update_hcall_cont(void *data)
 {
     struct microcode_patch *patch = NULL;
     int ret, result;

Why this change when ...

xen/arch/x86/cpu/microcode/core.c static long cf_check ucode_update_hcall_cont(void *data) · line 618

Quoted 5 lines
xen/arch/x86/cpu/microcode/core.c +1 -0
@@ -613,6 +615,7 @@ static long cf_check ucode_update_hcall_cont(void *data)
     return ret;
 }
 
+#ifdef CONFIG_MICROCODE_LOADING

... this can simply be moved up accordingly? After all ...

Quoted 8 lines

xen/arch/x86/cpu/microcode/core.c int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf, · line 649

Quoted 6 lines
xen/arch/x86/cpu/microcode/core.c +0 -0
 int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
                        unsigned long len, unsigned int flags)
 {
@@ -645,6 +648,7 @@ int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
      */
     return continue_hypercall_on_cpu(0, ucode_update_hcall_cont, buffer);

... this is the only user of that other function.

To minimise the scope of the ifdef. It's hard to know where things start/end when they cover several functions. This way it's (imo) clearer.

I don't mind much though.

Quoted 6 lines
Quoted 6 lines
xen/arch/x86/cpu/microcode/intel.c +0 -0
@@ -408,17 +408,20 @@ static const char __initconst intel_cpio_path[] =
     "kernel/x86/microcode/GenuineIntel.bin";
 
Quoted 16 lines

xen/arch/x86/cpu/microcode/intel.c static const char __initconst intel_cpio_path[] = · line 416

Quoted 11 lines
xen/arch/x86/cpu/microcode/intel.c +4 -4
 static const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = {
-    .cpu_request_microcode            = cpu_request_microcode,
+    .cpu_request_microcode            = MICROCODE_OP(cpu_request_microcode),
     .collect_cpu_info                 = collect_cpu_info,
-    .apply_microcode                  = apply_microcode,
-    .compare                          = intel_compare,
-    .cpio_path                        = intel_cpio_path,
+    .apply_microcode                  = MICROCODE_OP(apply_microcode),
+    .compare                          = MICROCODE_OP(intel_compare),
+    .cpio_path                        = MICROCODE_OP(intel_cpio_path),
 };

While I appreciate the intention with MICROCODE_OP(), I'm not really happy with function pointer members left in place just for them to be NULL everywhere. What if a call site remains unguarded? With PV guests that would be a privilege escalation XSA.

I see where you're coming from, but these are already NULL if microcode loading is not exposed by the underlying hypervisor (if any), or is blocked by hardware in Intel, so arguably that worry is orthogonal to this.

Also, only a privileged domain can perform late microcode loading, so the XSM check would prevent any such XSA from coming to pass. dom0 crashing the system on a bad hypercall (while wrong) would just be unfortunate, not a security issue, as far as I can tell.

I could indeed get rid of it all. But that'd cause a sea a ifdefs anywhere the fields are accessed, which is contrary to the current intent of relying on DCE for readability.

Cheers,
Alejandro

#14 lore raw

Re: [PATCH v3 4/4] x86/ucode: Add Kconfig option to remove microcode loading

Quoted 20 lines · Alejandro Vallejo
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/cpu/microcode/intel.c +0 -0
@@ -408,17 +408,20 @@ static const char __initconst intel_cpio_path[] =
     "kernel/x86/microcode/GenuineIntel.bin";
 
Quoted 15 lines

xen/arch/x86/cpu/microcode/intel.c static const char __initconst intel_cpio_path[] = · line 416

Quoted 11 lines
xen/arch/x86/cpu/microcode/intel.c +4 -4
 static const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = {
-    .cpu_request_microcode            = cpu_request_microcode,
+    .cpu_request_microcode            = MICROCODE_OP(cpu_request_microcode),
     .collect_cpu_info                 = collect_cpu_info,
-    .apply_microcode                  = apply_microcode,
-    .compare                          = intel_compare,
-    .cpio_path                        = intel_cpio_path,
+    .apply_microcode                  = MICROCODE_OP(apply_microcode),
+    .compare                          = MICROCODE_OP(intel_compare),
+    .cpio_path                        = MICROCODE_OP(intel_cpio_path),
 };

While I appreciate the intention with MICROCODE_OP(), I'm not really happy with function pointer members left in place just for them to be NULL everywhere. What if a call site remains unguarded? With PV guests that would be a privilege escalation XSA.

Quoted 3 lines

I see where you're coming from, but these are already NULL if microcode loading is not exposed by the underlying hypervisor (if any), or is blocked by hardware in Intel, so arguably that worry is orthogonal to this.

Also because they're cf_clobber, the calls are turned into UDs.  We won't follow a function pointer to 0.

~Andrew

#15 lore raw

Re: [PATCH v3 4/4] x86/ucode: Add Kconfig option to remove microcode loading

Quoted 21 lines · Andrew Cooper
Quoted 20 lines · Alejandro Vallejo
Quoted 20 lines
Quoted 6 lines
xen/arch/x86/cpu/microcode/intel.c +0 -0
@@ -408,17 +408,20 @@ static const char __initconst intel_cpio_path[] =
     "kernel/x86/microcode/GenuineIntel.bin";
 
 static const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = {

xen/arch/x86/cpu/microcode/intel.c static const char __initconst intel_cpio_path[] = · line 416

Quoted 10 lines
xen/arch/x86/cpu/microcode/intel.c +4 -4
-    .cpu_request_microcode            = cpu_request_microcode,
+    .cpu_request_microcode            = MICROCODE_OP(cpu_request_microcode),
     .collect_cpu_info                 = collect_cpu_info,
-    .apply_microcode                  = apply_microcode,
-    .compare                          = intel_compare,
-    .cpio_path                        = intel_cpio_path,
+    .apply_microcode                  = MICROCODE_OP(apply_microcode),
+    .compare                          = MICROCODE_OP(intel_compare),
+    .cpio_path                        = MICROCODE_OP(intel_cpio_path),
 };

While I appreciate the intention with MICROCODE_OP(), I'm not really happy with function pointer members left in place just for them to be NULL everywhere. What if a call site remains unguarded? With PV guests that would be a privilege escalation XSA.

Quoted 6 lines
Quoted 3 lines

I see where you're coming from, but these are already NULL if microcode loading is not exposed by the underlying hypervisor (if any), or is blocked by hardware in Intel, so arguably that worry is orthogonal to this.

Also because they're cf_clobber, the calls are turned into UDs.  We won't follow a function pointer to 0.

Hmm, yes, the alternative patching will guarantee that. That hasn't got anything to do with cf_clobber though, I don't think.

Jan

#16 lore raw

Re: [PATCH v3 4/4] x86/ucode: Add Kconfig option to remove microcode loading

In reply to Alejandro Vallejo
Quoted 59 lines · Alejandro Vallejo
Quoted 21 lines · Jan Beulich

xen/arch/x86/cpu/microcode/core.c struct ucode_buf { · line 477

Quoted 9 lines · Alejandro Vallejo
xen/arch/x86/cpu/microcode/core.c +1 -1
@@ -469,7 +471,7 @@ struct ucode_buf {
     char buffer[];
 };
 
-static long cf_check ucode_update_hcall_cont(void *data)
+static long cf_check __maybe_unused ucode_update_hcall_cont(void *data)
 {
     struct microcode_patch *patch = NULL;
     int ret, result;

Why this change when ...

xen/arch/x86/cpu/microcode/core.c static long cf_check ucode_update_hcall_cont(void *data) · line 618

Quoted 5 lines
xen/arch/x86/cpu/microcode/core.c +1 -0
@@ -613,6 +615,7 @@ static long cf_check ucode_update_hcall_cont(void *data)
     return ret;
 }
 
+#ifdef CONFIG_MICROCODE_LOADING

... this can simply be moved up accordingly? After all ...

Quoted 8 lines

xen/arch/x86/cpu/microcode/core.c int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf, · line 649

Quoted 6 lines
xen/arch/x86/cpu/microcode/core.c +0 -0
 int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
                        unsigned long len, unsigned int flags)
 {
@@ -645,6 +648,7 @@ int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
      */
     return continue_hypercall_on_cpu(0, ucode_update_hcall_cont, buffer);

... this is the only user of that other function.

To minimise the scope of the ifdef. It's hard to know where things start/end when they cover several functions. This way it's (imo) clearer.

I don't mind much though.

Quoted 6 lines
Quoted 6 lines
xen/arch/x86/cpu/microcode/intel.c +0 -0
@@ -408,17 +408,20 @@ static const char __initconst intel_cpio_path[] =
     "kernel/x86/microcode/GenuineIntel.bin";
 
Quoted 16 lines

xen/arch/x86/cpu/microcode/intel.c static const char __initconst intel_cpio_path[] = · line 416

Quoted 11 lines
xen/arch/x86/cpu/microcode/intel.c +4 -4
 static const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = {
-    .cpu_request_microcode            = cpu_request_microcode,
+    .cpu_request_microcode            = MICROCODE_OP(cpu_request_microcode),
     .collect_cpu_info                 = collect_cpu_info,
-    .apply_microcode                  = apply_microcode,
-    .compare                          = intel_compare,
-    .cpio_path                        = intel_cpio_path,
+    .apply_microcode                  = MICROCODE_OP(apply_microcode),
+    .compare                          = MICROCODE_OP(intel_compare),
+    .cpio_path                        = MICROCODE_OP(intel_cpio_path),
 };

While I appreciate the intention with MICROCODE_OP(), I'm not really happy with function pointer members left in place just for them to be NULL everywhere. What if a call site remains unguarded? With PV guests that would be a privilege escalation XSA.

Quoted 3 lines

I see where you're coming from, but these are already NULL if microcode loading is not exposed by the underlying hypervisor (if any), or is blocked by hardware in Intel, so arguably that worry is orthogonal to this.

Yes and no. Paths taken differ between what we have now and what we will have when your work has gone in.

Quoted 4 lines

Also, only a privileged domain can perform late microcode loading, so the XSM check would prevent any such XSA from coming to pass. dom0 crashing the system on a bad hypercall (while wrong) would just be unfortunate, not a security issue, as far as I can tell.

Okay, together with Andrew's response it wouldn't be calls through NULL, so perhaps indeed not an XSA. The hypercall being Dom0-only I am, however, less convinced would necessarily matter here. We interact with remote CPUs, after all, and hence having one which happens to run a PV DomU call through NULL would still be in need of an XSA.

Jan