From: Boris Ostrovsky Date: Wed, 8 May 2019 18:50:39 +0000 (-0400) Subject: x86/microcode: Add loader version file in debugfs X-Git-Tag: v4.1.12-124.31.3~171 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=04349cdec537de48763fe5e03b5077364fc1a4bc;p=users%2Fjedix%2Flinux-maple.git x86/microcode: Add loader version file in debugfs 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 Reviewed-by: Konrad Rzeszutek Wilk Tested-by: Konrad Rzeszutek Wilk --- diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 1da1a4fffb3a..a60cb1ada21d 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -78,6 +78,7 @@ #include #include #include +#include #include #include #include @@ -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; }