]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
x86/microcode: Add loader version file in debugfs
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Wed, 8 May 2019 18:50:39 +0000 (14:50 -0400)
committerBoris Ostrovsky <boris.ostrovsky@oracle.com>
Wed, 8 May 2019 21:36:33 +0000 (17:36 -0400)
We want to be able to find out whether late microcode loader is using a
"safe" method where the system is in stop_machines() --- i.e. all cores
are pinned in kernel with interrupts disabled. This is especially
important for core siblings --- if one thread is loading microcode while
the other is executing instructions that are being patched then bad
things may happen, including MCEs.

Presense of this file indicates that we are all good. We will also
provide version value of "1".

[root@ca-virt1-0 ~]# cat /sys/kernel/debug/x86/microcode_loader_version
1
[root@ca-virt1-0 ~]#

Orabug: 29754165

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
arch/x86/kernel/cpu/microcode/core.c

index 1da1a4fffb3a9e02b4a813bbb477d47293a4ebf4..a60cb1ada21d3422450b1d17a0409318040afbc2 100644 (file)
@@ -78,6 +78,7 @@
 #include <linux/miscdevice.h>
 #include <linux/capability.h>
 #include <linux/kernel.h>
+#include <linux/debugfs.h>
 #include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
@@ -582,6 +583,26 @@ static enum ucode_state microcode_update_cpu(int cpu)
        return microcode_init_cpu(cpu, false);
 }
 
+/* 
+ * Indicates that late loading is "safe", i.e. it uses stop_machine()
+ * as opposed to simply IPI-ing cores, one-by-one without pinning them
+ * with interrupts disabled. That could case all sorts of errors.
+ * Current version is "1".
+ */
+static ssize_t loader_ver_read(struct file *file,
+                              char __user *user_buf,
+                              size_t count, loff_t *ppos)
+{
+       char buf[2] = {'1', '\n'};
+
+       return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static const struct file_operations fops_loader_ver = {
+       .read = loader_ver_read,
+       .llseek = default_llseek,
+};
+
 static int mc_device_add(struct device *dev, struct subsys_interface *sif)
 {
        int err, cpu = dev->id;
@@ -598,6 +619,10 @@ static int mc_device_add(struct device *dev, struct subsys_interface *sif)
        if (microcode_init_cpu(cpu, true) == UCODE_ERROR)
                return -EINVAL;
 
+       debugfs_create_file("microcode_loader_version",
+                           0400, arch_debugfs_dir, NULL,
+                           &fops_loader_ver);
+
        return err;
 }