[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • To: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 13 Jan 2026 15:08:49 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HMDPfp7rSO2Fl2qHgPd3JWOZBGjaTGgH7mazWOQEVE4=; b=N+FRfslUr0wRTsV2EqH+oR4WYv+j9g+ggCdrVvQBNW7DFpAMYTGI8WrtokufQLe2a1HoXcunPcmkgvss1fTxv3dyxQx1KnEru8E8YFnroVrdXZm2kQeQTP1293HM4ikvtUAo+yiDgGy1dtyOJG+8p2Ajqd+nG0aFg4aRXUL+PVanoOTB2zvBS5HtbSQk/QrMd0Plad9zFaBIPKM92L8In3qeF3cQaHR/2Dk2XDxlx73i8Q3Qp8rOcjDrfQsU6JJ4VgeZm/fKKJ8sFS9rYaD/5xHMJN2Zm7bvq9Ezx7fE0Hkw/DSmhSeg8E89ek+eHJX21aKEvZQmxlYhsRh4fP7Kkg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lgUJex87QsX2qpzJooBkB7xxKpKr9TZDXuTbzSUWLNEiOCT131Lbv6STmrbk0VUSnR9WLDhph1mV9NDaGvpLdBCXkPp1MKW4lVbwxC73Dh/tfcGJ2li61M/CiCrrvarPgjSExEEx/y43DCZsLeZ7ina2a8aSGpfKp648Ndodk7lxkbxGzdRMlTrDOqmWNqWUBoOeee9JZYaFhcoSGdgJ8+P+Ros3qPn7EJAnbGno+wv/JBXAcKkHRyklKoiu4wG0qCiUmsk4K+/K4SnhfiwNeu1OJZViODyq1Lb5/dir4fkbFGItC7K8e4SQ9LO3xc4LkwQ7YLTptOerTCxzPU+nJg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 13 Jan 2026 15:09:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 13/01/2026 12:21 pm, Alejandro Vallejo wrote:
> 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

> remove all statics no longer used when microcode loading is disabled
> without tagging them with __maybe_unused.
>
> Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>

Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> with a couple
more minor points, all of which I can fix on commit.

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

> diff --git a/docs/misc/efi.pandoc b/docs/misc/efi.pandoc
> index 11c1ac3346..c3fb1f3a30 100644
> --- a/docs/misc/efi.pandoc
> +++ b/docs/misc/efi.pandoc
> @@ -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.

> +
>  ###`dtb=<filename>`
>  
>  Specifies a device tree file to load.  The platform firmware may provide a
> diff --git a/docs/misc/xen-command-line.pandoc 
> b/docs/misc/xen-command-line.pandoc
> index 15f7a315a4..866fa2f951 100644
> --- a/docs/misc/xen-command-line.pandoc
> +++ b/docs/misc/xen-command-line.pandoc
> @@ -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.

diff --git a/docs/misc/xen-command-line.pandoc
b/docs/misc/xen-command-line.pandoc
index 50d7edb2488e..5b6ff94f441a 100644
--- a/docs/misc/xen-command-line.pandoc
+++ b/docs/misc/xen-command-line.pandoc
@@ -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'.

> diff --git a/xen/arch/x86/cpu/microcode/amd.c 
> b/xen/arch/x86/cpu/microcode/amd.c
> index 71b041c84b..86706a21a6 100644
> --- a/xen/arch/x86/cpu/microcode/amd.c
> +++ b/xen/arch/x86/cpu/microcode/amd.c
> @@ -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),
>  };

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

> diff --git a/xen/arch/x86/cpu/microcode/private.h 
> b/xen/arch/x86/cpu/microcode/private.h
> index e6c965dc99..1167b79db1 100644
> --- a/xen/arch/x86/cpu/microcode/private.h
> +++ b/xen/arch/x86/cpu/microcode/private.h
> @@ -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.

> diff --git a/xen/arch/x86/platform_hypercall.c 
> b/xen/arch/x86/platform_hypercall.c
> index 79bb99e0b6..a55060e662 100644
> --- a/xen/arch/x86/platform_hypercall.c
> +++ b/xen/arch/x86/platform_hypercall.c
> @@ -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;
>      }
>  


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 <andrew.cooper3@xxxxxxxxxx> and I
can fix all of these con commit.

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

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.