Skip to contentSkip to conversation

Some fixes and cleanups for microcode

PATCH Applied Ashok Raj 5 participants 30 messages Jan 9, 2023 – Jan 21, 2023

Subsystems (2)

v4 of 5 Applied Latest is v5 →

lore
Share & tools
lore

Ashok Raj

author
#0 lore raw

v4 cover Some fixes and cleanups for microcode

Hi Boris,

Here is a followup after v3[1] with all comments addressed.

Please review and apply.

Changes since v3:

Tony, Ingo
- Display clear message when microcode load fails.

Boris
- Changed function names microcode_store_cpu_caps() -> store_cpu_caps().
- Fix commit logs
- Document new parameter to microcode_check()

Dave Hansen
- Fix commit log
- Change parameter names from generic to something that's meaningful.

[1] https://lore.kernel.org/lkml/[email protected]/

Ashok Raj (6):
x86/microcode: Add a parameter to microcode_check() to store CPU
capabilities
x86/microcode/core: Take a snapshot before and after applying
microcode
x86/microcode: Display revisions only when update is successful x86/microcode/intel: Use a plain revision argument for
print_ucode_rev()
x86/microcode/intel: Print old and new rev during early boot x86/microcode/intel: Print when early microcode loading fails

 arch/x86/include/asm/processor.h      |  3 +-
 arch/x86/kernel/cpu/common.c          | 48 ++++++++++++++++++-------
 arch/x86/kernel/cpu/microcode/core.c  | 20 ++++++++---
 arch/x86/kernel/cpu/microcode/intel.c | 52 +++++++++++++--------------
 4 files changed, 77 insertions(+), 46 deletions(-)

base-commit: b7bfaa761d760e72a969d116517eaa12e404c262
prerequisite-patch-id: 450e9658e9f802a2f3f784ba18267bc47ee878b8

Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v4 1/6 x86/microcode: Add a parameter to microcode_check() to store CPU capabilities

Add a parameter to store CPU capabilities before performing a microcode update so that the code later can compare CPU capabilities before and after performing the update.

Cc Tony Luck <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Alison Schofield <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Ingo Molnar <[email protected]>

---
Changes since V3

Boris:
- Fix commit log to drop "next patch".
- Add documentation to new parameter to microcode_check()

---
 arch/x86/include/asm/processor.h     |  2 +-
 arch/x86/kernel/cpu/common.c         | 21 +++++++++++++--------
 arch/x86/kernel/cpu/microcode/core.c |  3 ++-
 3 files changed, 16 insertions(+), 10 deletions(-)
arch/x86/include/asm/processor.h +1 -1
index 4e35c66edeb7..f256a4ddd25d 100644
@@ -697,7 +697,7 @@ bool xen_set_default_idle(void);
 #endif
 
 void __noreturn stop_this_cpu(void *dummy);
-void microcode_check(void);
+void microcode_check(struct cpuinfo_x86 *prev_info);
 
 enum l1tf_mitigations {
 	L1TF_MITIGATION_OFF,
arch/x86/kernel/cpu/common.c +13 -8
index 9cfca3d7d0e2..0f5a173d0871 100644
@@ -2297,30 +2297,35 @@ void cpu_init_secondary(void)
 #endif
 
 #ifdef CONFIG_MICROCODE_LATE_LOADING
-/*
+/**
+ * microcode_check() - Check if any CPU capabilities changed after an update.
+ * @prev_info:	CPU capabilities stored before an update.
+ *
  * The microcode loader calls this upon late microcode load to recheck features,
  * only when microcode has been updated. Caller holds microcode_mutex and CPU
  * hotplug lock.
+ *
+ * Return: None
  */
-void microcode_check(void)
+void microcode_check(struct cpuinfo_x86 *prev_info)
 {
-	struct cpuinfo_x86 info;
-
 	perf_check_microcode();
 
 	/* Reload CPUID max function as it might've changed. */
-	info.cpuid_level = cpuid_eax(0);
+	prev_info->cpuid_level = cpuid_eax(0);
 
 	/*
 	 * Copy all capability leafs to pick up the synthetic ones so that
 	 * memcmp() below doesn't fail on that. The ones coming from CPUID will
 	 * get overwritten in get_cpu_cap().
 	 */
-	memcpy(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability));
+	memcpy(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
+	       sizeof(prev_info->x86_capability));
 
-	get_cpu_cap(&info);
+	get_cpu_cap(prev_info);
 
-	if (!memcmp(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability)))
+	if (!memcmp(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
+		    sizeof(prev_info->x86_capability)))
 		return;
 
 	pr_warn("x86/CPU: CPU features have changed after loading microcode, but might not take effect.\n");
arch/x86/kernel/cpu/microcode/core.c +2 -1
index c4cd7328177b..e39d83be794b 100644
@@ -439,6 +439,7 @@ static int __reload_late(void *info)
 static int microcode_reload_late(void)
 {
 	int old = boot_cpu_data.microcode, ret;
+	struct cpuinfo_x86 prev_info;
 
 	pr_err("Attempting late microcode loading - it is dangerous and taints the kernel.\n");
 	pr_err("You should switch to early loading, if possible.\n");
@@ -448,7 +449,7 @@ static int microcode_reload_late(void)
 
 	ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
 	if (ret == 0)
-		microcode_check();
+		microcode_check(&prev_info);
 
 	pr_info("Reload completed, microcode revision: 0x%x -> 0x%x\n",
 		old, boot_cpu_data.microcode);
Signature · 1 line
2.34.1
merge bot Applied
#2 lore raw

[tip: x86/microcode] x86/microcode: Add a parameter to microcode_check() to store CPU capabilities

The following commit has been merged into the x86/microcode branch of tip:

The following commit has been merged into the x86/microcode branch of tip:

Commit-ID:     ab31c74455c64e69342ddab21fd9426fcbfefde7
Gitweb:        https://git.kernel.org/tip/ab31c74455c64e69342ddab21fd9426fcbfefde7
Author:        Ashok Raj <[email protected]>
AuthorDate:    Mon, 09 Jan 2023 07:35:50 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Fri, 20 Jan 2023 21:45:13 +01:00

x86/microcode: Add a parameter to microcode_check() to store CPU capabilities

Add a parameter to store CPU capabilities before performing a microcode update so that CPU capabilities can be compared before and after update.

[ bp: Massage. ]

---
 arch/x86/include/asm/processor.h     |  2 +-
 arch/x86/kernel/cpu/common.c         | 21 +++++++++++++--------
 arch/x86/kernel/cpu/microcode/core.c |  3 ++-
 3 files changed, 16 insertions(+), 10 deletions(-)
arch/x86/include/asm/processor.h +1 -1
index 4e35c66..f256a4d 100644
@@ -697,7 +697,7 @@ bool xen_set_default_idle(void);
 #endif
 
 void __noreturn stop_this_cpu(void *dummy);
-void microcode_check(void);
+void microcode_check(struct cpuinfo_x86 *prev_info);
 
 enum l1tf_mitigations {
 	L1TF_MITIGATION_OFF,
arch/x86/kernel/cpu/common.c +13 -8
index 9cfca3d..0f5a173 100644
@@ -2297,30 +2297,35 @@ void cpu_init_secondary(void)
 #endif
 
 #ifdef CONFIG_MICROCODE_LATE_LOADING
-/*
+/**
+ * microcode_check() - Check if any CPU capabilities changed after an update.
+ * @prev_info:	CPU capabilities stored before an update.
+ *
  * The microcode loader calls this upon late microcode load to recheck features,
  * only when microcode has been updated. Caller holds microcode_mutex and CPU
  * hotplug lock.
+ *
+ * Return: None
  */
-void microcode_check(void)
+void microcode_check(struct cpuinfo_x86 *prev_info)
 {
-	struct cpuinfo_x86 info;
-
 	perf_check_microcode();
 
 	/* Reload CPUID max function as it might've changed. */
-	info.cpuid_level = cpuid_eax(0);
+	prev_info->cpuid_level = cpuid_eax(0);
 
 	/*
 	 * Copy all capability leafs to pick up the synthetic ones so that
 	 * memcmp() below doesn't fail on that. The ones coming from CPUID will
 	 * get overwritten in get_cpu_cap().
 	 */
-	memcpy(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability));
+	memcpy(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
+	       sizeof(prev_info->x86_capability));
 
-	get_cpu_cap(&info);
+	get_cpu_cap(prev_info);
 
-	if (!memcmp(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability)))
+	if (!memcmp(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
+		    sizeof(prev_info->x86_capability)))
 		return;
 
 	pr_warn("x86/CPU: CPU features have changed after loading microcode, but might not take effect.\n");
arch/x86/kernel/cpu/microcode/core.c +2 -1
index 99abb31..dc5dfba 100644
@@ -438,6 +438,7 @@ wait_for_siblings:
 static int microcode_reload_late(void)
 {
 	int old = boot_cpu_data.microcode, ret;
+	struct cpuinfo_x86 prev_info;
 
 	pr_err("Attempting late microcode loading - it is dangerous and taints the kernel.\n");
 	pr_err("You should switch to early loading, if possible.\n");
@@ -447,7 +448,7 @@ static int microcode_reload_late(void)
 
 	ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
 	if (ret == 0)
-		microcode_check();
+		microcode_check(&prev_info);
 
 	pr_info("Reload completed, microcode revision: 0x%x -> 0x%x\n",
 		old, boot_cpu_data.microcode);
author
#3 lore raw

PATCH v4 2/6 x86/microcode/core: Take a snapshot before and after applying microcode

In reply to Ashok Raj

The kernel caches features about each CPU's features at boot in an x86_capability[] structure. The microcode update takes one snapshot and compares it with the saved copy at boot.

However, the capabilities in the boot copy can be turned off as a result of certain command line parameters or configuration restrictions. This can cause a mismatch when comparing the values before and after the microcode update.

microcode_check() is called after an update to report any previously cached CPUID bits might have changed due to the update.

store_cpu_caps() basically stores the original CPU reported values and not the OS modified values. This will avoid giving a false warning even when no capabilities have changed.

Ignore the capabilities recorded at boot. Take a new snapshot before the update and compare with a snapshot after the update to eliminate the false warning.

Fixes 1008c52c09dc ("x86/CPU: Add a microcode loader callback")
Cc Tony Luck <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Alison Schofield <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Ingo Molnar <[email protected]>

---
Changes since V3:
- Boris
- Change function from microcode_store_cpu_caps -> store_cpu_caps
- Split comments in store_cpu_caps().

- Dave Hansen
- Change parameters names to something meaninful.
- Cleaned up some commit log.

Changes since V2:

- Boris
- Keep microcode_check() inside cpu/common.c and not bleed get_cpu_caps() outside of core code.

- Thomas
- Commit log changes.

---
 arch/x86/include/asm/processor.h     |  1 +
 arch/x86/kernel/cpu/common.c         | 39 ++++++++++++++++++++--------
 arch/x86/kernel/cpu/microcode/core.c |  7 +++++
 3 files changed, 36 insertions(+), 11 deletions(-)
arch/x86/include/asm/processor.h +1 -0
index f256a4ddd25d..a77dee6a2bf2 100644
@@ -698,6 +698,7 @@ bool xen_set_default_idle(void);
 
 void __noreturn stop_this_cpu(void *dummy);
 void microcode_check(struct cpuinfo_x86 *prev_info);
+void store_cpu_caps(struct cpuinfo_x86 *info);
 
 enum l1tf_mitigations {
 	L1TF_MITIGATION_OFF,
arch/x86/kernel/cpu/common.c +28 -11
index 0f5a173d0871..f5c6feed6c26 100644
@@ -2297,6 +2297,29 @@ void cpu_init_secondary(void)
 #endif
 
 #ifdef CONFIG_MICROCODE_LATE_LOADING
+/**
+ * store_cpu_caps() - Store a snapshot of CPU capabilities
+ *
+ * Returns: None
+ */
+void store_cpu_caps(struct cpuinfo_x86 *curr_info)
+{
+	/* Reload CPUID max function as it might've changed. */
+	curr_info->cpuid_level = cpuid_eax(0);
+
+	/*
+	 * Copy all capability leafs to pick up the synthetic ones
+	 */
+	memcpy(&curr_info->x86_capability, &boot_cpu_data.x86_capability,
+	       sizeof(curr_info->x86_capability));
+
+	/*
+	 * Capabilities copied from BSP will get overwritten
+	 * with the snapshot below
+	 */
+	get_cpu_cap(curr_info);
+}
+
 /**
  * microcode_check() - Check if any CPU capabilities changed after an update.
  * @prev_info:	CPU capabilities stored before an update.
@@ -2309,22 +2332,16 @@ void cpu_init_secondary(void)
  */
 void microcode_check(struct cpuinfo_x86 *prev_info)
 {
-	perf_check_microcode();
+	struct cpuinfo_x86 curr_info;
 
-	/* Reload CPUID max function as it might've changed. */
-	prev_info->cpuid_level = cpuid_eax(0);
+	perf_check_microcode();
 
 	/*
-	 * Copy all capability leafs to pick up the synthetic ones so that
-	 * memcmp() below doesn't fail on that. The ones coming from CPUID will
-	 * get overwritten in get_cpu_cap().
+	 * Get a snapshot of CPU capabilities
 	 */
-	memcpy(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
-	       sizeof(prev_info->x86_capability));
-
-	get_cpu_cap(prev_info);
+	store_cpu_caps(&curr_info);
 
-	if (!memcmp(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
+	if (!memcmp(&prev_info->x86_capability, &curr_info.x86_capability,
 		    sizeof(prev_info->x86_capability)))
 		return;
 
arch/x86/kernel/cpu/microcode/core.c +7 -0
index e39d83be794b..bb943a91a364 100644
@@ -447,6 +447,13 @@ static int microcode_reload_late(void)
 	atomic_set(&late_cpus_in,  0);
 	atomic_set(&late_cpus_out, 0);
 
+	/*
+	 * Take a snapshot before the microcode update, so we can compare
+	 * them after the update is successful to check for any bits
+	 * changed.
+	 */
+	store_cpu_caps(&prev_info);
+
 	ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
 	if (ret == 0)
 		microcode_check(&prev_info);
Signature · 1 line
2.34.1
merge bot Applied
#4 lore raw

[tip: x86/microcode] x86/microcode: Check CPU capabilities after late microcode update correctly

The following commit has been merged into the x86/microcode branch of tip:

The following commit has been merged into the x86/microcode branch of tip:

Commit-ID:     c0dd9245aa9e25a697181f6085692272c9ec61bc
Gitweb:        https://git.kernel.org/tip/c0dd9245aa9e25a697181f6085692272c9ec61bc
Author:        Ashok Raj <[email protected]>
AuthorDate:    Mon, 09 Jan 2023 07:35:51 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Sat, 21 Jan 2023 14:53:20 +01:00

x86/microcode: Check CPU capabilities after late microcode update correctly

The kernel caches each CPU's feature bits at boot in an x86_capability[] structure. However, the capabilities in the BSP's copy can be turned off as a result of certain command line parameters or configuration restrictions, for example the SGX bit. This can cause a mismatch when comparing the values before and after the microcode update.

Another example is X86_FEATURE_SRBDS_CTRL which gets added only after microcode update:

--- cpuid.before 2023-01-21 14:54:15.652000747 +0100
+++ cpuid.after 2023-01-21 14:54:26.632001024 +0100
@@ -10,7 +10,7 @@ CPU:

      0x00000004 0x04: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
      0x00000005 0x00: eax=0x00000040 ebx=0x00000040 ecx=0x00000003 edx=0x11142120
      0x00000006 0x00: eax=0x000027f7 ebx=0x00000002 ecx=0x00000001 edx=0x00000000

- 0x00000007 0x00: eax=0x00000000 ebx=0x029c6fbf ecx=0x40000000 edx=0xbc002400
+ 0x00000007 0x00: eax=0x00000000 ebx=0x029c6fbf ecx=0x40000000 edx=0xbc002e00
^^^

and which proves for a gazillionth time that late loading is a bad bad idea.

microcode_check() is called after an update to report any previously cached CPUID bits which might have changed due to the update.

Therefore, store the cached CPU caps before the update and compare them with the CPU caps after the microcode update has succeeded.

Thus, the comparison is done between the CPUID *hardware* bits before and after the upgrade instead of using the cached, possibly runtime modified values in BSP's boot_cpu_data copy.

As a result, false warnings about CPUID bits changes are avoided.

[ bp:
- Massage.
- Add SRBDS_CTRL example.
- Add kernel-doc.
- Incorporate forgotten review feedback from dhansen. ]

Fixes 1008c52c09dc ("x86/CPU: Add a microcode loader callback")
---
 arch/x86/include/asm/processor.h     |  1 +-
 arch/x86/kernel/cpu/common.c         | 36 +++++++++++++++++----------
 arch/x86/kernel/cpu/microcode/core.c |  6 +++++-
 3 files changed, 30 insertions(+), 13 deletions(-)
arch/x86/include/asm/processor.h +1 -0
index f256a4d..a77dee6 100644
@@ -698,6 +698,7 @@ bool xen_set_default_idle(void);
 
 void __noreturn stop_this_cpu(void *dummy);
 void microcode_check(struct cpuinfo_x86 *prev_info);
+void store_cpu_caps(struct cpuinfo_x86 *info);
 
 enum l1tf_mitigations {
 	L1TF_MITIGATION_OFF,
arch/x86/kernel/cpu/common.c +23 -13
index 0f5a173..5ff73ba 100644
@@ -2298,6 +2298,25 @@ void cpu_init_secondary(void)
 
 #ifdef CONFIG_MICROCODE_LATE_LOADING
 /**
+ * store_cpu_caps() - Store a snapshot of CPU capabilities
+ * @curr_info: Pointer where to store it
+ *
+ * Returns: None
+ */
+void store_cpu_caps(struct cpuinfo_x86 *curr_info)
+{
+	/* Reload CPUID max function as it might've changed. */
+	curr_info->cpuid_level = cpuid_eax(0);
+
+	/* Copy all capability leafs and pick up the synthetic ones. */
+	memcpy(&curr_info->x86_capability, &boot_cpu_data.x86_capability,
+	       sizeof(curr_info->x86_capability));
+
+	/* Get the hardware CPUID leafs */
+	get_cpu_cap(curr_info);
+}
+
+/**
  * microcode_check() - Check if any CPU capabilities changed after an update.
  * @prev_info:	CPU capabilities stored before an update.
  *
@@ -2309,22 +2328,13 @@ void cpu_init_secondary(void)
  */
 void microcode_check(struct cpuinfo_x86 *prev_info)
 {
-	perf_check_microcode();
-
-	/* Reload CPUID max function as it might've changed. */
-	prev_info->cpuid_level = cpuid_eax(0);
+	struct cpuinfo_x86 curr_info;
 
-	/*
-	 * Copy all capability leafs to pick up the synthetic ones so that
-	 * memcmp() below doesn't fail on that. The ones coming from CPUID will
-	 * get overwritten in get_cpu_cap().
-	 */
-	memcpy(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
-	       sizeof(prev_info->x86_capability));
+	perf_check_microcode();
 
-	get_cpu_cap(prev_info);
+	store_cpu_caps(&curr_info);
 
-	if (!memcmp(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
+	if (!memcmp(&prev_info->x86_capability, &curr_info.x86_capability,
 		    sizeof(prev_info->x86_capability)))
 		return;
 
arch/x86/kernel/cpu/microcode/core.c +6 -0
index dc5dfba..8ec38c1 100644
@@ -446,6 +446,12 @@ static int microcode_reload_late(void)
 	atomic_set(&late_cpus_in,  0);
 	atomic_set(&late_cpus_out, 0);
 
+	/*
+	 * Take a snapshot before the microcode update in order to compare and
+	 * check whether any bits changed after an update.
+	 */
+	store_cpu_caps(&prev_info);
+
 	ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
 	if (ret == 0)
 		microcode_check(&prev_info);
author
#5 lore raw

PATCH v4 3/6 x86/microcode: Display revisions only when update is successful

In reply to Ashok Raj

Right now, microcode loading failures and successes print the same message "Reloading completed". This is misleading to users.

Display the updated revision number only if an update was successful. Display "Reload completed" only if the update was successful, otherwise report the update failed.

Fixes 9bd681251b7c ("x86/microcode: Announce reload operation's completion")
Cc Tony Luck <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Alison Schofield <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Ingo Molnar <[email protected]>

---
Changes since V3:

Tony, Ingo
- Print clear message if the update was successful or not.

---
 arch/x86/kernel/cpu/microcode/core.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +8 -4
index bb943a91a364..d7cbc83df9b6 100644
@@ -455,11 +455,15 @@ static int microcode_reload_late(void)
 	store_cpu_caps(&prev_info);
 
 	ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
-	if (ret == 0)
-		microcode_check(&prev_info);
 
-	pr_info("Reload completed, microcode revision: 0x%x -> 0x%x\n",
-		old, boot_cpu_data.microcode);
+	if (ret == 0) {
+		pr_info("Reload completed, microcode revision: 0x%x -> 0x%x\n",
+			old, boot_cpu_data.microcode);
+		microcode_check(&prev_info);
+	} else {
+		pr_info("Reload failed, current microcode revision: 0x%x\n",
+			boot_cpu_data.microcode);
+	}
 
 	return ret;
 }
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH v4 4/6 x86/microcode/intel: Use a plain revision argument for print_ucode_rev()

In reply to Ashok Raj

print_ucode_rev() takes a struct ucode_cpu_info argument. The sole purpose of it is to print the microcode revision.

The only available ucode_cpu_info always describes the currently loaded microcode revision. After a microcode update is successful, this is the new revision, or on failure it is the original revision.

Subsequent changes need to print both the original and new revision, but the original version will be cached in a plain integer, which makes the code inconsistent.

Replace the struct ucode_cpu_info argument with a plain integer which contains the revision number and adjust the call sites accordingly.

No functional change.

Cc Tony Luck <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Alison Schofield <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Ingo Molnar <[email protected]>

---
Changes since V1:

Thomas:
- Updated commit log as suggested
- Remove the line break after static void before print_ucode_info

---
 arch/x86/kernel/cpu/microcode/intel.c | 31 ++++++++-------------------
 1 file changed, 9 insertions(+), 22 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +9 -22
index 6bebc46ad8b1..1d709b72cfd0 100644
@@ -310,13 +310,10 @@ static bool load_builtin_intel_microcode(struct cpio_data *cp)
 /*
  * Print ucode update info.
  */
-static void
-print_ucode_info(struct ucode_cpu_info *uci, unsigned int date)
+static void print_ucode_info(unsigned int new_rev, unsigned int date)
 {
 	pr_info_once("microcode updated early to revision 0x%x, date = %04x-%02x-%02x\n",
-		     uci->cpu_sig.rev,
-		     date & 0xffff,
-		     date >> 24,
+		     new_rev, date & 0xffff, date >> 24,
 		     (date >> 16) & 0xff);
 }
 
@@ -334,7 +331,7 @@ void show_ucode_info_early(void)
 
 	if (delay_ucode_info) {
 		intel_cpu_collect_info(&uci);
-		print_ucode_info(&uci, current_mc_date);
+		print_ucode_info(uci.cpu_sig.rev. current_mc_date);
 		delay_ucode_info = 0;
 	}
 }
@@ -343,33 +340,23 @@ void show_ucode_info_early(void)
  * At this point, we can not call printk() yet. Delay printing microcode info in
  * show_ucode_info_early() until printk() works.
  */
-static void print_ucode(struct ucode_cpu_info *uci)
+static void print_ucode(int new_rev, int date)
 {
 	struct microcode_intel *mc;
 	int *delay_ucode_info_p;
 	int *current_mc_date_p;
 
-	mc = uci->mc;
-	if (!mc)
-		return;
-
 	delay_ucode_info_p = (int *)__pa_nodebug(&delay_ucode_info);
 	current_mc_date_p = (int *)__pa_nodebug(&current_mc_date);
 
 	*delay_ucode_info_p = 1;
-	*current_mc_date_p = mc->hdr.date;
+	*current_mc_date_p = date;
 }
 #else
 
-static inline void print_ucode(struct ucode_cpu_info *uci)
+static inline void print_ucode(int new_rev, int date)
 {
-	struct microcode_intel *mc;
-
-	mc = uci->mc;
-	if (!mc)
-		return;
-
-	print_ucode_info(uci, mc->hdr.date);
+	print_ucode_info(new_rev, date);
 }
 #endif
 
@@ -409,9 +396,9 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
 	uci->cpu_sig.rev = rev;
 
 	if (early)
-		print_ucode(uci);
+		print_ucode(uci->cpu_sig.rev, mc->hdr.date);
 	else
-		print_ucode_info(uci, mc->hdr.date);
+		print_ucode_info(uci->cpu_sig.rev, mc->hdr.date);
 
 	return 0;
 }
Signature · 1 line
2.34.1
maintainer
#7 lore raw

Re: [PATCH v4 4/6] x86/microcode/intel: Use a plain revision argument for print_ucode_rev()

Quoted 11 lines · Ashok Raj
arch/x86/kernel/cpu/microcode/intel.c +1 -1
@@ -343,33 +340,23 @@ void show_ucode_info_early(void)
  * At this point, we can not call printk() yet. Delay printing microcode info in
  * show_ucode_info_early() until printk() works.
  */
-static void print_ucode(struct ucode_cpu_info *uci)
+static void print_ucode(int new_rev, int date)
 {
 	struct microcode_intel *mc;
 	int *delay_ucode_info_p;
 	int *current_mc_date_p;
 

arch/x86/kernel/cpu/microcode/intel.c void show_ucode_info_early(void) · line 353

Quoted 10 lines
arch/x86/kernel/cpu/microcode/intel.c +1 -5
-	mc = uci->mc;
-	if (!mc)
-		return;
-
 	delay_ucode_info_p = (int *)__pa_nodebug(&delay_ucode_info);
 	current_mc_date_p = (int *)__pa_nodebug(&current_mc_date);
 
 	*delay_ucode_info_p = 1;
-	*current_mc_date_p = mc->hdr.date;
+	*current_mc_date_p = date;

Here's how I know you haven't tested this on 32-bit:

arch/x86/kernel/cpu/microcode/intel.c: In function ‘print_ucode’:
arch/x86/kernel/cpu/microcode/intel.c:344:33: error: unused variable ‘mc’ [-Werror=unused-variable]
344 | struct microcode_intel *mc;
| ^~
cc1: all warnings being treated as errors
make[5]: *** [scripts/Makefile.build:252: arch/x86/kernel/cpu/microcode/intel.o] Error 1 make[4]: *** [scripts/Makefile.build:504: arch/x86/kernel/cpu/microcode] Error 2 make[3]: *** [scripts/Makefile.build:504: arch/x86/kernel/cpu] Error 2
make[2]: *** [scripts/Makefile.build:504: arch/x86/kernel] Error 2
make[1]: *** [scripts/Makefile.build:504: arch/x86] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:2008: .] Error 2

Testing is overrated, right?

The maintainers can do that, ofc.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#8 lore raw

Re: [PATCH v4 4/6] x86/microcode/intel: Use a plain revision argument for print_ucode_rev()

In reply to Ashok Raj

arch/x86/kernel/cpu/microcode/intel.c void show_ucode_info_early(void) · line 334

Quoted 6 lines · Ashok Raj
arch/x86/kernel/cpu/microcode/intel.c +1 -1
@@ -334,7 +331,7 @@ void show_ucode_info_early(void)
 
 	if (delay_ucode_info) {
 		intel_cpu_collect_info(&uci);
-		print_ucode_info(&uci, current_mc_date);
+		print_ucode_info(uci.cpu_sig.rev. current_mc_date);

You must be kidding:

arch/x86/kernel/cpu/microcode/intel.c: In function ‘show_ucode_info_early’:
arch/x86/kernel/cpu/microcode/intel.c:332:49: error: request for member ‘current_mc_date’ in something not a structure or union
332 | print_ucode_info(uci.cpu_sig.rev. current_mc_date);
| ^
arch/x86/kernel/cpu/microcode/intel.c:332:17: error: too few arguments to function ‘print_ucode_info’

  332 |                 print_ucode_info(uci.cpu_sig.rev. current_mc_date);
      |                 ^~~~~~~~~~~~~~~~
arch/x86/kernel/cpu/microcode/intel.c:311:13: note: declared here
  311 | static void print_ucode_info(unsigned int new_rev, unsigned int date)
      |             ^~~~~~~~~~~~~~~~

arch/x86/kernel/cpu/microcode/intel.c: In function ‘print_ucode’:
arch/x86/kernel/cpu/microcode/intel.c:343:33: error: unused variable ‘mc’ [-Werror=unused-variable]
343 | struct microcode_intel *mc;
| ^~
cc1: all warnings being treated as errors
make[5]: *** [scripts/Makefile.build:252: arch/x86/kernel/cpu/microcode/intel.o] Error 1 make[4]: *** [scripts/Makefile.build:504: arch/x86/kernel/cpu/microcode] Error 2 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:504: arch/x86/kernel/cpu] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:504: arch/x86/kernel] Error 2
make[1]: *** [scripts/Makefile.build:504: arch/x86] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:2008: .] Error 2

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#9 lore raw

Re: [PATCH v4 4/6] x86/microcode/intel: Use a plain revision argument for print_ucode_rev()

Quoted 9 lines · Borislav Petkov

arch/x86/kernel/cpu/microcode/intel.c void show_ucode_info_early(void) · line 334

Quoted 6 lines · Ashok Raj
arch/x86/kernel/cpu/microcode/intel.c +1 -1
@@ -334,7 +331,7 @@ void show_ucode_info_early(void)
 
 	if (delay_ucode_info) {
 		intel_cpu_collect_info(&uci);
-		print_ucode_info(&uci, current_mc_date);
+		print_ucode_info(uci.cpu_sig.rev. current_mc_date);

You must be kidding:

Oversight completely.. Apologize. I remember seeing them but unfortunately I ended up fixing the issue in patch5 instead of patch4.

Quoted 11 lines

arch/x86/kernel/cpu/microcode/intel.c: In function ‘show_ucode_info_early’:
arch/x86/kernel/cpu/microcode/intel.c:332:49: error: request for member ‘current_mc_date’ in something not a structure or union
332 | print_ucode_info(uci.cpu_sig.rev. current_mc_date);
| ^
arch/x86/kernel/cpu/microcode/intel.c:332:17: error: too few arguments to function ‘print_ucode_info’

  332 |                 print_ucode_info(uci.cpu_sig.rev. current_mc_date);
      |                 ^~~~~~~~~~~~~~~~
arch/x86/kernel/cpu/microcode/intel.c:311:13: note: declared here
  311 | static void print_ucode_info(unsigned int new_rev, unsigned int date)
      |             ^~~~~~~~~~~~~~~~
Quoted 4 lines

arch/x86/kernel/cpu/microcode/intel.c: In function ‘print_ucode’:
arch/x86/kernel/cpu/microcode/intel.c:343:33: error: unused variable ‘mc’ [-Werror=unused-variable]
343 | struct microcode_intel *mc;
| ^~

I fixed in patch6 instead of this patch, my bad.

I updated my build to have CONFIG_WERROR, i had that accidently turned off in one of my configs.

I have fixed up the right version and can repost if there are no additional comments.

Cheers,
Ashok

maintainer
#10 lore raw

Re: [PATCH v4 4/6] x86/microcode/intel: Use a plain revision argument for print_ucode_rev()

Quoted 2 lines · Ashok Raj

I updated my build to have CONFIG_WERROR, i had that accidently turned off in one of my configs.

You need to build every patch for bisection purposes, obviously. In addition CONFIG_ERROR.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#11 lore raw

PATCH v4 5/6 x86/microcode/intel: Print old and new rev during early boot

In reply to Ashok Raj

Make early loading message to match late loading messages. Print both old and new revisions.

This is helpful to know what the BIOS loaded revision is before an early update.

New dmesg log is shown below.

microcode: early update: 0x2b000041 -> 0x2b000070 date = 2000-01-01

Cache the early BIOS revision before the microcode update and change the print_ucode_info() so it prints both the old and new revision in the same format as microcode_reload_late().

Cc Tony Luck <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Alison Schofield <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Ingo Molnar <[email protected]>

---
Updates since V1:

Thomas: Commit log updates as suggested.

---
 arch/x86/kernel/cpu/microcode/intel.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +15 -10
index 1d709b72cfd0..f24300830ed7 100644
@@ -310,10 +310,10 @@ static bool load_builtin_intel_microcode(struct cpio_data *cp)
 /*
  * Print ucode update info.
  */
-static void print_ucode_info(unsigned int new_rev, unsigned int date)
+static void print_ucode_info(int old_rev, int new_rev, unsigned int date)
 {
-	pr_info_once("microcode updated early to revision 0x%x, date = %04x-%02x-%02x\n",
-		     new_rev, date & 0xffff, date >> 24,
+	pr_info_once("early update: 0x%x -> 0x%x, date = %04x-%02x-%02x\n",
+		     old_rev, new_rev, date & 0xffff, date >> 24,
 		     (date >> 16) & 0xff);
 }
 
@@ -321,6 +321,7 @@ static void print_ucode_info(unsigned int new_rev, unsigned int date)
 
 static int delay_ucode_info;
 static int current_mc_date;
+static int early_old_rev;
 
 /*
  * Print early updated ucode info after printk works. This is delayed info dump.
@@ -331,7 +332,7 @@ void show_ucode_info_early(void)
 
 	if (delay_ucode_info) {
 		intel_cpu_collect_info(&uci);
-		print_ucode_info(uci.cpu_sig.rev. current_mc_date);
+		print_ucode_info(early_old_rev, uci.cpu_sig.rev, current_mc_date);
 		delay_ucode_info = 0;
 	}
 }
@@ -340,30 +341,33 @@ void show_ucode_info_early(void)
  * At this point, we can not call printk() yet. Delay printing microcode info in
  * show_ucode_info_early() until printk() works.
  */
-static void print_ucode(int new_rev, int date)
+static void print_ucode(int old_rev, int new_rev, int date)
 {
 	struct microcode_intel *mc;
 	int *delay_ucode_info_p;
 	int *current_mc_date_p;
+	int *early_old_rev_p;
 
 	delay_ucode_info_p = (int *)__pa_nodebug(&delay_ucode_info);
 	current_mc_date_p = (int *)__pa_nodebug(&current_mc_date);
+	early_old_rev_p = (int *)__pa_nodebug(&early_old_rev);
 
 	*delay_ucode_info_p = 1;
 	*current_mc_date_p = date;
+	*early_old_rev_p = old_rev;
 }
 #else
 
-static inline void print_ucode(int new_rev, int date)
+static inline void print_ucode(int old_rev, int new_rev, int date)
 {
-	print_ucode_info(new_rev, date);
+	print_ucode_info(old_rev, new_rev, date);
 }
 #endif
 
 static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
 {
 	struct microcode_intel *mc;
-	u32 rev;
+	u32 rev, old_rev;
 
 	mc = uci->mc;
 	if (!mc)
@@ -389,6 +393,7 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
 	/* write microcode via MSR 0x79 */
 	native_wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc->bits);
 
+	old_rev = rev;
 	rev = intel_get_microcode_revision();
 	if (rev != mc->hdr.rev)
 		return -1;
@@ -396,9 +401,9 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
 	uci->cpu_sig.rev = rev;
 
 	if (early)
-		print_ucode(uci->cpu_sig.rev, mc->hdr.date);
+		print_ucode(old_rev, uci->cpu_sig.rev, mc->hdr.date);
 	else
-		print_ucode_info(uci->cpu_sig.rev, mc->hdr.date);
+		print_ucode_info(old_rev, uci->cpu_sig.rev, mc->hdr.date);
 
 	return 0;
 }
Signature · 1 line
2.34.1
author
#12 lore raw

PATCH v4 6/6 x86/microcode/intel: Print when early microcode loading fails

In reply to Ashok Raj

Currently when early microcode loading fails there is no way for the user to know that the update failed.

Store the failed status and pass it to print_ucode_info() so that early loading failures are captured in dmesg.

Cc Tony Luck <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Alison Schofield <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Ingo Molnar <[email protected]>

---
Changes since V1:

Thomas: Fix commit log as suggested.

---
 arch/x86/kernel/cpu/microcode/intel.c | 28 +++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +16 -12
index f24300830ed7..0cdff9ed2a4e 100644
@@ -310,11 +310,11 @@ static bool load_builtin_intel_microcode(struct cpio_data *cp)
 /*
  * Print ucode update info.
  */
-static void print_ucode_info(int old_rev, int new_rev, unsigned int date)
+static void print_ucode_info(bool failed, int old_rev, int new_rev, unsigned int date)
 {
-	pr_info_once("early update: 0x%x -> 0x%x, date = %04x-%02x-%02x\n",
+	pr_info_once("early update: 0x%x -> 0x%x, date = %04x-%02x-%02x %s\n",
 		     old_rev, new_rev, date & 0xffff, date >> 24,
-		     (date >> 16) & 0xff);
+		     (date >> 16) & 0xff, failed ? "FAILED" : "");
 }
 
 #ifdef CONFIG_X86_32
@@ -322,6 +322,7 @@ static void print_ucode_info(int old_rev, int new_rev, unsigned int date)
 static int delay_ucode_info;
 static int current_mc_date;
 static int early_old_rev;
+static bool early_failed;
 
 /*
  * Print early updated ucode info after printk works. This is delayed info dump.
@@ -332,7 +333,7 @@ void show_ucode_info_early(void)
 
 	if (delay_ucode_info) {
 		intel_cpu_collect_info(&uci);
-		print_ucode_info(early_old_rev, uci.cpu_sig.rev, current_mc_date);
+		print_ucode_info(early_failed, early_old_rev, uci.cpu_sig.rev, current_mc_date);
 		delay_ucode_info = 0;
 	}
 }
@@ -341,26 +342,28 @@ void show_ucode_info_early(void)
  * At this point, we can not call printk() yet. Delay printing microcode info in
  * show_ucode_info_early() until printk() works.
  */
-static void print_ucode(int old_rev, int new_rev, int date)
+static void print_ucode(bool failed, int old_rev, int new_rev, int date)
 {
-	struct microcode_intel *mc;
 	int *delay_ucode_info_p;
 	int *current_mc_date_p;
 	int *early_old_rev_p;
+	bool *early_failed_p;
 
 	delay_ucode_info_p = (int *)__pa_nodebug(&delay_ucode_info);
 	current_mc_date_p = (int *)__pa_nodebug(&current_mc_date);
 	early_old_rev_p = (int *)__pa_nodebug(&early_old_rev);
+	early_failed_p = (bool *)__pa_nodebug(&early_failed);
 
 	*delay_ucode_info_p = 1;
 	*current_mc_date_p = date;
 	*early_old_rev_p = old_rev;
+	*early_failed_p = failed;
 }
 #else
 
-static inline void print_ucode(int old_rev, int new_rev, int date)
+static inline void print_ucode(bool failed, int old_rev, int new_rev, int date)
 {
-	print_ucode_info(old_rev, new_rev, date);
+	print_ucode_info(failed, old_rev, new_rev, date);
 }
 #endif
 
@@ -368,6 +371,7 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
 {
 	struct microcode_intel *mc;
 	u32 rev, old_rev;
+	int retval = 0;
 
 	mc = uci->mc;
 	if (!mc)
@@ -396,16 +400,16 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
 	old_rev = rev;
 	rev = intel_get_microcode_revision();
 	if (rev != mc->hdr.rev)
-		return -1;
+		retval = -1;
 
 	uci->cpu_sig.rev = rev;
 
 	if (early)
-		print_ucode(old_rev, uci->cpu_sig.rev, mc->hdr.date);
+		print_ucode(retval, old_rev, mc->hdr.rev, mc->hdr.date);
 	else
-		print_ucode_info(old_rev, uci->cpu_sig.rev, mc->hdr.date);
+		print_ucode_info(retval, old_rev, uci->cpu_sig.rev, mc->hdr.date);
 
-	return 0;
+	return retval;
 }
 
 int __init save_microcode_in_initrd_intel(void)
Signature · 1 line
2.34.1
maintainer
#13 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 2 lines · Ashok Raj

Currently when early microcode loading fails there is no way for the user to know that the update failed.

Of course there is - there's no early update message in dmesg.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#14 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Ashok Raj

Currently when early microcode loading fails there is no way for the user to know that the update failed.

Of course there is - there's no early update message in dmesg.

Sorry Boris, didn't comprehend.

Without user making some additional steps to check the revision in the default location and the current rev reported to find the update failed.

Maybe that's what you meant.

#15 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 11 lines · Ashok Raj
Quoted 4 lines · Borislav Petkov
Quoted 2 lines · Ashok Raj

Currently when early microcode loading fails there is no way for the user to know that the update failed.

Of course there is - there's no early update message in dmesg.

Sorry Boris, didn't comprehend.

Without user making some additional steps to check the revision in the default location and the current rev reported to find the update failed.

Maybe that's what you meant.

I think a better changelog might help here. The original was a bit too absolute. There is, as Boris pointed out, a way to tell if a failure occurred. But, that method is a bit unfriendly to our users.

--

When early microcode loading succeeds, the kernel prints a message via print_ucode_info() that starts with 'early update:'. If loading fails, apply_microcode_early() returns before that message is printed. This means that users must know to go looking for that message. They can infer a early microcode loading failure if they do not see the message.

That's not great for users. Instead of expecting them to infer this, be more explicit about it. Instead of bailing out and returning from apply_microcode_early(), stash the error code off and plumb it down to print_ucode_info().

This ensures that a message of some kind is printed on all early loads:
successes *and* failures. This should make it easier for our hapless users to figure out when a failure occurred.

maintainer
#16 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 3 lines · Dave Hansen

This ensures that a message of some kind is printed on all early loads:
successes *and* failures. This should make it easier for our hapless users to figure out when a failure occurred.

I'm still not convinced. When something doesn't happen in the kernel, we don't always say "It didn't happen". We don't say anything.

So I don't like all those talkative drivers for no good reason. If there wasn't an update message, then no update happened. That's it.

And the current microcode revision is in /proc/cpuinfo.

If you wanna know why the update didn't happen, then you start adding debug printks and trying things but then you're clearly not a user so you know what you're doing.

And the log buffer can get overwritten sooner or later depending on its size so any message can disappear.

So what's the point of this pointless exercise in verbosity?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#17 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Dave Hansen

This ensures that a message of some kind is printed on all early loads:
successes *and* failures. This should make it easier for our hapless users to figure out when a failure occurred.

I'm still not convinced. When something doesn't happen in the kernel, we don't always say "It didn't happen". We don't say anything.

Well, we have an awful lot of pr_warn()'s in the kernel that talk about something that was tried and failed.

Quoted 2 lines

So I don't like all those talkative drivers for no good reason. If there wasn't an update message, then no update happened. That's it.

I actually kinda like the inverse.

The common (boring) case where an update was needed and was successful. It's the one we don't need to tell users about at all. It barely deserves a message. Users expect that if there's an early update available, it'll get attempted, it will be successful and the kernel won't say much.

The time we need to spam dmesg is when something upends user expectations and they might need to go do something. An early loading failure is exactly the place where they want to know. They want to know if they're running with known CPU bugs that would have been fixed by the early update, or if they somehow have a botched early loading image.

So, if I had to pick either:

* Print on failure
or
* Print on success

I'd pick failure. But, considering that we're already printing on success, I'm OK doing both.

maintainer
#18 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 2 lines · Dave Hansen

Well, we have an awful lot of pr_warn()'s in the kernel that talk about something that was tried and failed.

Well, is microcode loading failure worth to warn about?

What if there's no microcode for that CPU?

Now imagine in that case you issue a warning and then you get all those bugzillas opened:

"Heeey, is my CPU broken, it says it cannot load microcode"

I sure don't want to be on the receiving end of this.

I don't think you wanna be there either.

Quoted 7 lines

I actually kinda like the inverse.

The common (boring) case where an update was needed and was successful. It's the one we don't need to tell users about at all. It barely deserves a message. Users expect that if there's an early update available, it'll get attempted, it will be successful and the kernel won't say much.

No argument there.

Quoted 5 lines

The time we need to spam dmesg is when something upends user expectations and they might need to go do something. An early loading failure is exactly the place where they want to know. They want to know if they're running with known CPU bugs that would have been fixed by the early update

No, we already warn about that in the CPU mitigations code.

Quoted 1 line

or if they somehow have a botched early loading image.

If you can pick apart from this here:

        /* write microcode via MSR 0x79 */
        native_wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc->bits);

what type of failure it is, then sure, let's warn.

But we should not warn just for every revision mismatch in there...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#19 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Dave Hansen

Well, we have an awful lot of pr_warn()'s in the kernel that talk about something that was tried and failed.

Well, is microcode loading failure worth to warn about?

Is it not?

Quoted 2 lines

What if there's no microcode for that CPU?

If there is no microcode, we don't print anything. So what's loaded in the CPU is the latest version. When we have something we can always tell if its successful or not.

Its not a microcode file in initrd, but a matching microcode to load. If none is found, nothing to worry about.

We just agreed to show both failed and success for late-load. Doing this is consistent with that isn't it?

https://lore.kernel.org/lkml/[email protected]/

Ingo's:
https://lore.kernel.org/lkml/Y7k9DNz%2F%[email protected]/

Should we treat early loading differently?

Cheers,
Ashok

maintainer
#20 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 1 line · Ashok Raj

We just agreed to show both failed and success for late-load.

Did you read the part you snipped about getting false/misleading bug reports? I doubt it, as usual.

If you all Intel folks want to deal with people asking why is there a warning message about microcode not loading successfully, I don't mind forwarding you all those messages. I sure ain't going to deal with them.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#21 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 9 lines · Borislav Petkov
Quoted 1 line · Ashok Raj

We just agreed to show both failed and success for late-load.

Did you read the part you snipped about getting false/misleading bug reports? I doubt it, as usual.

If you all Intel folks want to deal with people asking why is there a warning message about microcode not loading successfully, I don't mind forwarding you all those messages. I sure ain't going to deal with them.

TBH, there is nothing to hide from a microcode loading failure. If user sees that a loading failed, it could be maybe due to corrupted files and its best to know and update to proper file vs running without the latest microcode file always.

#22 lore raw

RE: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

In reply to Ashok Raj
Quoted 10 lines

If there is no microcode, we don't print anything. So what's loaded in the CPU is the latest version. When we have something we can always tell if its successful or not.

Its not a microcode file in initrd, but a matching microcode to load. If none is found, nothing to worry about.

We just agreed to show both failed and success for late-load. Doing this is consistent with that isn't it?

Quoted 6 lines

https://lore.kernel.org/lkml/[email protected]/

Ingo's:
https://lore.kernel.org/lkml/Y7k9DNz%2F%[email protected]/

Should we treat early loading differently?

Getting a better set of messages from early microcode update would be a "nice-to-have" feature. But if there is no agreement on what those messages should look like, perhaps just skip this part for now.

Then Ashok can move on to the real issue of allowing LATE_LOAD for a microcode that supports the new "minrev" header field.

-Tony

author
#23 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Hi Boris,

Quoted 15 lines · Tony Luck
Quoted 15 lines

If there is no microcode, we don't print anything. So what's loaded in the CPU is the latest version. When we have something we can always tell if its successful or not.

Its not a microcode file in initrd, but a matching microcode to load. If none is found, nothing to worry about.

We just agreed to show both failed and success for late-load. Doing this is consistent with that isn't it?

https://lore.kernel.org/lkml/[email protected]/

Ingo's:
https://lore.kernel.org/lkml/Y7k9DNz%2F%[email protected]/

Quoted 9 lines
Quoted 1 line

Should we treat early loading differently?

Getting a better set of messages from early microcode update would be a "nice-to-have" feature. But if there is no agreement on what those messages should look like, perhaps just skip this part for now.

Then Ashok can move on to the real issue of allowing LATE_LOAD for a microcode that supports the new "minrev" header field.

If this is the one blocking this series, as Tony proposed, its not worth loosing sleep over this.

Would you recommend resubmitting a new set with the fixes for the interim patch compile failures (for 32bit) and drop this last patch?

If you have any other comments would be great to hear now before I repost a new series to capture everything that's need to be addressed.

As always you can change commit logs to your satisfaction, I try, but its still not as perfect as how you like to see them.

Cheers,
Ashok

maintainer
#24 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 2 lines · Ashok Raj

Would you recommend resubmitting a new set with the fixes for the interim patch compile failures (for 32bit) and drop this last patch?

Sure.

Quoted 2 lines

If you have any other comments would be great to hear now before I repost a new series to capture everything that's need to be addressed.

No, no more comments.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#25 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 11 lines · Borislav Petkov
Quoted 2 lines · Ashok Raj

Would you recommend resubmitting a new set with the fixes for the interim patch compile failures (for 32bit) and drop this last patch?

Sure.

Quoted 2 lines

If you have any other comments would be great to hear now before I repost a new series to capture everything that's need to be addressed.

No, no more comments.

Great, light at the end of the tunnel!

I have posted v5.

https://lore.kernel.org/lkml/[email protected]/

#26 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

In reply to Ashok Raj
Quoted 2 lines · Ashok Raj

We just agreed to show both failed and success for late-load. Doing this is consistent with that isn't it?

Well, I kinda proposed that and you agreed. I don't think Boris ever agreed, though.

author
#27 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

In reply to Dave Hansen
Quoted 11 lines · Dave Hansen
Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Dave Hansen

This ensures that a message of some kind is printed on all early loads:
successes *and* failures. This should make it easier for our hapless users to figure out when a failure occurred.

I'm still not convinced. When something doesn't happen in the kernel, we don't always say "It didn't happen". We don't say anything.

Well, we have an awful lot of pr_warn()'s in the kernel that talk about something that was tried and failed.

Quoted 7 lines
Quoted 2 lines

So I don't like all those talkative drivers for no good reason. If there wasn't an update message, then no update happened. That's it.

I actually kinda like the inverse.

The common (boring) case where an update was needed and was successful. It's the one we don't need to tell users about at all. It barely

I think its useful to know what microcode was loaded at FIT from BIOS and what its updated to from initrd. We have been telling about successful updates, no good reason to nuke that.

We added successful and failures on late-loads, so its better to be consistent for both early and late.

Quoted 10 lines

deserves a message. Users expect that if there's an early update available, it'll get attempted, it will be successful and the kernel won't say much.

The time we need to spam dmesg is when something upends user expectations and they might need to go do something. An early loading failure is exactly the place where they want to know. They want to know if they're running with known CPU bugs that would have been fixed by the early update, or if they somehow have a botched early loading image.

Quoted 8 lines

So, if I had to pick either:

* Print on failure
or
* Print on success

I'd pick failure. But, considering that we're already printing on success, I'm OK doing both.

That sounds good, lets do on both.

#28 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

In reply to Ashok Raj
Quoted 2 lines · Ashok Raj
arch/x86/kernel/cpu/microcode/intel.c +1 -1
-static void print_ucode(int old_rev, int new_rev, int date)
+static void print_ucode(bool failed, int old_rev, int new_rev, int date)

...

Quoted 6 lines
arch/x86/kernel/cpu/microcode/intel.c +1 -1
 	if (rev != mc->hdr.rev)
-		return -1;
+		retval = -1;
 
 	uci->cpu_sig.rev = rev;
 

arch/x86/kernel/cpu/microcode/intel.c static int apply_microcode_early(struct ucode_cpu_info *uci, bool early) · line 413

Quoted 10 lines
arch/x86/kernel/cpu/microcode/intel.c +3 -3
 	if (early)
-		print_ucode(old_rev, uci->cpu_sig.rev, mc->hdr.date);
+		print_ucode(retval, old_rev, mc->hdr.rev, mc->hdr.date);
 	else
-		print_ucode_info(old_rev, uci->cpu_sig.rev, mc->hdr.date);
+		print_ucode_info(retval, old_rev, uci->cpu_sig.rev, mc->hdr.date);
 
-	return 0;
+	return retval;
 }

I'm generally not a _huge_ fan of having an 'int' implicitly cast to a bool. The:

print_ucode_info(retval, ...

Line could be right or wrong based on what the retval is logically. This, on the other hand:

	bool failed = false;
	...
	if (rev != mc->hdr.rev) {
		retval = -1;
		failed = true;
	}
	...
	print_ucode_info(failed, old_rev, uci->cpu_sig.rev, ...

*Clearly* and unambiguously matches up with:

static void print_ucode(bool failed, int old_rev, ...

author
#29 lore raw

Re: [PATCH v4 6/6] x86/microcode/intel: Print when early microcode loading fails

Quoted 38 lines · Dave Hansen
Quoted 2 lines · Ashok Raj
arch/x86/kernel/cpu/microcode/intel.c +1 -1
-static void print_ucode(int old_rev, int new_rev, int date)
+static void print_ucode(bool failed, int old_rev, int new_rev, int date)

...

Quoted 6 lines
arch/x86/kernel/cpu/microcode/intel.c +1 -1
 	if (rev != mc->hdr.rev)
-		return -1;
+		retval = -1;
 
 	uci->cpu_sig.rev = rev;
 

arch/x86/kernel/cpu/microcode/intel.c static int apply_microcode_early(struct ucode_cpu_info *uci, bool early) · line 413

Quoted 10 lines
arch/x86/kernel/cpu/microcode/intel.c +3 -3
 	if (early)
-		print_ucode(old_rev, uci->cpu_sig.rev, mc->hdr.date);
+		print_ucode(retval, old_rev, mc->hdr.rev, mc->hdr.date);
 	else
-		print_ucode_info(old_rev, uci->cpu_sig.rev, mc->hdr.date);
+		print_ucode_info(retval, old_rev, uci->cpu_sig.rev, mc->hdr.date);
 
-	return 0;
+	return retval;
 }

I'm generally not a _huge_ fan of having an 'int' implicitly cast to a bool. The:

print_ucode_info(retval, ...

Line could be right or wrong based on what the retval is logically. This, on the other hand:

	bool failed = false;
	...
	if (rev != mc->hdr.rev) {
		retval = -1;
		failed = true;
	}
	...
	print_ucode_info(failed, old_rev, uci->cpu_sig.rev, ...
Quoted 3 lines

*Clearly* and unambiguously matches up with:

static void print_ucode(bool failed, int old_rev, ...

Yes, it makes good sense.. I'll fix up next update including the commit log that you called out.