From: Alejandro Vallejo <alejandro.vallejo@cloud.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Alejandro Vallejo" <alejandro.vallejo@cloud.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>
Subject: [PATCH v3 2/5] x86/microcode: Create per-vendor microcode_ops builders
Date: Thu, 15 Jun 2023 16:48:31 +0100 [thread overview]
Message-ID: <20230615154834.959-3-alejandro.vallejo@cloud.com> (raw)
In-Reply-To: <20230615154834.959-1-alejandro.vallejo@cloud.com>
Replace the ucode_ops assignments in core.c for per-vendor calls.
This is in preparation for another patch that adds Intel-specific
conditions.
While moving the code around, also remove the family check on Intel, as
microcode loading is present on every Intel 64 machine.
Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
---
v3:
* Subsumes v2/patch1
* Removes previous long comment on rationale for skipping family checks (Jan/Andrew)
* Isolates vendor-specific code in ${VENDOR}.c (Jan, from v2/patch4)
---
xen/arch/x86/cpu/microcode/amd.c | 16 ++++++++++------
xen/arch/x86/cpu/microcode/core.c | 10 +++-------
xen/arch/x86/cpu/microcode/intel.c | 13 +++++++------
xen/arch/x86/cpu/microcode/private.h | 19 ++++++++++++++++++-
4 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c
index a9a5557835..7c9f311454 100644
--- a/xen/arch/x86/cpu/microcode/amd.c
+++ b/xen/arch/x86/cpu/microcode/amd.c
@@ -432,9 +432,13 @@ static struct microcode_patch *cf_check cpu_request_microcode(
return patch;
}
-const struct microcode_ops __initconst_cf_clobber amd_ucode_ops = {
- .cpu_request_microcode = cpu_request_microcode,
- .collect_cpu_info = collect_cpu_info,
- .apply_microcode = apply_microcode,
- .compare_patch = compare_patch,
-};
+void __init amd_get_ucode_ops(struct microcode_ops *ops)
+{
+ if ( boot_cpu_data.x86 < 0x10 )
+ return;
+
+ ops->cpu_request_microcode = cpu_request_microcode;
+ ops->collect_cpu_info = collect_cpu_info;
+ ops->apply_microcode = apply_microcode;
+ ops->compare_patch = compare_patch;
+}
diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c
index df7e1df870..530e3e8267 100644
--- a/xen/arch/x86/cpu/microcode/core.c
+++ b/xen/arch/x86/cpu/microcode/core.c
@@ -845,19 +845,15 @@ static int __init early_microcode_update_cpu(void)
int __init early_microcode_init(unsigned long *module_map,
const struct multiboot_info *mbi)
{
- const struct cpuinfo_x86 *c = &boot_cpu_data;
int rc = 0;
- switch ( c->x86_vendor )
+ switch ( boot_cpu_data.x86_vendor )
{
case X86_VENDOR_AMD:
- if ( c->x86 >= 0x10 )
- ucode_ops = amd_ucode_ops;
+ amd_get_ucode_ops(&ucode_ops);
break;
-
case X86_VENDOR_INTEL:
- if ( c->x86 >= 6 )
- ucode_ops = intel_ucode_ops;
+ intel_get_ucode_ops(&ucode_ops);
break;
}
diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/intel.c
index 8d4d6574aa..a99e402b98 100644
--- a/xen/arch/x86/cpu/microcode/intel.c
+++ b/xen/arch/x86/cpu/microcode/intel.c
@@ -385,9 +385,10 @@ static struct microcode_patch *cf_check cpu_request_microcode(
return patch;
}
-const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = {
- .cpu_request_microcode = cpu_request_microcode,
- .collect_cpu_info = collect_cpu_info,
- .apply_microcode = apply_microcode,
- .compare_patch = compare_patch,
-};
+void __init intel_get_ucode_ops(struct microcode_ops *ops)
+{
+ ops->cpu_request_microcode = cpu_request_microcode;
+ ops->collect_cpu_info = collect_cpu_info;
+ ops->apply_microcode = apply_microcode;
+ ops->compare_patch = compare_patch;
+}
diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microcode/private.h
index 626aeb4d08..13f0c7fb8e 100644
--- a/xen/arch/x86/cpu/microcode/private.h
+++ b/xen/arch/x86/cpu/microcode/private.h
@@ -60,6 +60,23 @@ struct microcode_ops {
const struct microcode_patch *new, const struct microcode_patch *old);
};
-extern const struct microcode_ops amd_ucode_ops, intel_ucode_ops;
+/**
+ * Retrieve the vendor-specific microcode management handlers
+ *
+ * Note that this is not an static set of handlers and may change from
+ * system to system depending on the presence of certain runtime features.
+ * even for the same
+ *
+ * - If the system has no microcode facilities, no handler is set.
+ * - If the system has unrestricted microcode facilities, all handlers
+ * are set
+ * - If the system has microcode facilities, but they can't be used to
+ * update the revision, then all handlers except for apply_microcode()
+ * are set
+ *
+ * @param[out] ops Set of vendor-specific microcode handlers to overwrite
+ */
+void intel_get_ucode_ops(struct microcode_ops *ops);
+void amd_get_ucode_ops(struct microcode_ops *ops);
#endif /* ASM_X86_MICROCODE_PRIVATE_H */
--
2.34.1
next prev parent reply other threads:[~2023-06-15 15:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-15 15:48 [PATCH v2 0/5] Prevent attempting updates known to fail Alejandro Vallejo
2023-06-15 15:48 ` [PATCH v3 1/5] x86/microcode: Allow reading microcode revision even if it can't be updated Alejandro Vallejo
2023-06-19 15:37 ` Jan Beulich
2023-06-19 15:49 ` Andrew Cooper
2023-06-19 15:58 ` Jan Beulich
2023-06-19 16:06 ` Andrew Cooper
2023-06-19 16:10 ` Jan Beulich
2023-06-20 9:53 ` Jan Beulich
2023-06-15 15:48 ` Alejandro Vallejo [this message]
2023-06-19 15:45 ` [PATCH v3 2/5] x86/microcode: Create per-vendor microcode_ops builders Jan Beulich
2023-06-22 14:34 ` Alejandro Vallejo
2023-06-15 15:48 ` [PATCH v3 3/5] x86/microcode: Ignore microcode loading interface for revision = -1 Alejandro Vallejo
2023-06-19 15:47 ` Jan Beulich
2023-06-15 15:48 ` [PATCH v3 4/5] x86: Read MSR_ARCH_CAPS immediately after early_microcode_init() Alejandro Vallejo
2023-06-19 15:57 ` Jan Beulich
2023-06-22 14:55 ` Alejandro Vallejo
2023-06-22 15:20 ` Jan Beulich
2023-06-15 15:48 ` [PATCH v3 5/5] x86/microcode: Disable microcode update handler if DIS_MCU_UPDATE is set Alejandro Vallejo
2023-06-20 9:51 ` Jan Beulich
2023-06-22 15:05 ` Alejandro Vallejo
2023-06-15 15:56 ` [PATCH v2 0/5] Prevent attempting updates known to fail Alejandro Vallejo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230615154834.959-3-alejandro.vallejo@cloud.com \
--to=alejandro.vallejo@cloud.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.