[Patch v3 Part2 9/9] x86/microcode: Provide an option to override minrev enforcement
From: Ashok Raj
Date: Mon Jan 30 2023 - 16:40:42 EST
Minimum Required Revision (minrev) is enforced strictly. All new patches
will have a minrev that is not zero. But there might be a transition time
for some that need this enforcement to be relaxed.
When the override is enabled, the kernel will be tainted.
Provide a debugfs variable to override the minrev enforcement.
Signed-off-by: Ashok Raj <ashok.raj@xxxxxxxxx>
Cc: LKML <linux-kernel@xxxxxxxxxxxxxxx>
Cc: x86 <x86@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Tony Luck <tony.luck@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxx>
Cc: Alison Schofield <alison.schofield@xxxxxxxxx>
Cc: Reinette Chatre <reinette.chatre@xxxxxxxxx>
Cc: Thomas Gleixner (Intel) <tglx@xxxxxxxxxxxxx>
Cc: Tom Lendacky <thomas.lendacky@xxxxxxx>
Cc: Stefan Talpalaru <stefantalpalaru@xxxxxxxxx>
Cc: David Woodhouse <dwmw2@xxxxxxxxxxxxx>
Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>
Cc: Jonathan Corbet <corbet@xxxxxxx>
Cc: Rafael J. Wysocki <rafael@xxxxxxxxxx>
Cc: Peter Zilstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
---
arch/x86/include/asm/microcode.h | 2 ++
arch/x86/kernel/cpu/microcode/core.c | 15 +++++++++++++--
arch/x86/kernel/cpu/microcode/intel.c | 8 ++++++++
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h
index 3d48143e84a9..d82f22d50ebd 100644
--- a/arch/x86/include/asm/microcode.h
+++ b/arch/x86/include/asm/microcode.h
@@ -16,6 +16,8 @@ struct ucode_patch {
extern struct list_head microcode_cache;
+extern bool override_minrev;
+
struct cpu_signature {
unsigned int sig;
unsigned int pf;
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index be5d70396b79..dbcccbd46ab8 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -23,6 +23,7 @@
#include <linux/miscdevice.h>
#include <linux/capability.h>
#include <linux/firmware.h>
+#include <linux/debugfs.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/mutex.h>
@@ -43,7 +44,9 @@
#define DRIVER_VERSION "2.2"
static struct microcode_ops *microcode_ops;
+static struct dentry *dentry_ucode;
static bool dis_ucode_ldr = true;
+bool override_minrev;
bool initrd_gone;
@@ -494,7 +497,11 @@ static ssize_t reload_store(struct device *dev,
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");
ret = -EINVAL;
- goto put;
+
+ if (!override_minrev)
+ goto put;
+
+ pr_info("Overriding minrev\n");
}
tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev);
@@ -519,7 +526,7 @@ static ssize_t reload_store(struct device *dev,
*/
if (load_ret == 0) {
ret = size;
- if (!safe_late_load) {
+ if (!safe_late_load || override_minrev) {
add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
pr_warn("Microcode late loading tainted the kernel\n");
}
@@ -692,7 +699,11 @@ static int __init microcode_init(void)
cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/microcode:online",
mc_cpu_online, mc_cpu_down_prep);
+ dentry_ucode = debugfs_create_dir("microcode", NULL);
+ debugfs_create_bool("override_minrev", 0644, dentry_ucode, &override_minrev);
+
pr_info("Microcode Update Driver: v%s.", DRIVER_VERSION);
+ pr_info("Override minrev %s\n", override_minrev ? "enabled" : "disabled");
return 0;
diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
index 601c586be7b6..ec5a29ebee8e 100644
--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -139,6 +139,14 @@ static int is_lateload_safe(struct microcode_header_intel *mc_header)
{
struct ucode_cpu_info uci;
+ /*
+ * If minrev is bypassed via debugfs, then allow late-load.
+ */
+ if (override_minrev) {
+ pr_info("Bypassing minrev enforcement via debugfs\n");
+ return 0;
+ }
+
/*
* When late-loading, ensure the header declares a minimum revision
* required to perform a late-load.
--
2.37.2