Skip to contentSkip to conversation

x86-microcode: refactor microcode output messages

RFC PATCH Superseded dimm 3 participants 5 messages Nov 1, 2009 – Nov 2, 2009 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

dimm

author
#0 lore raw

RFC PATCH 1/2 x86-microcode: refactor microcode output messages

Hi,

this is in response to Mike's patch "Limit the number of microcode messages".

What's about the following (yet preliminary and not thoroughly tested) approach?

patch-1:

simplify 'struct ucode_cpu_info' and related operational logic.

patch-2:

reduce a number of similar 'microcode version' messages by printing a single message for all cpus with equal microcode version, like:

(1)

[   96.589437] microcode: original microcode versions...
[   96.589451] microcode: CPU0-1: sig=0x6f2, pf=0x20, revision=0x57

(2)

[   96.603176] microcode: microcode versions after update...
[   96.603193] microcode: CPU0-1: sig=0x6f2, pf=0x20, revision=0x57

The new approach is used in microcode_init() [ i.e. when loading a module ] and microcode_write(), that's when we update all the cpus at once.

reload_for_cpu() and update-all-cpus-upon-resuming() use the old approach - a new microcode version is being reported upon applying it.

The latter might employ the similar 'report-for-all' approach as above but that would somewhat complicate the logic. Anyways, there are plenty of per-cpu messages upon system resuming so having some more update-microcode related ones won't harm that muc, I guess :-)

(Not-yet-)signed-off-by: Dmitry Adaushko <[email protected]>

Patch-1:

(quoted diff) +0 -0

b/arch/x86/include/asm/microcode.h
index ef51b50..68fd54c 100644

arch/x86/include/asm/microcode.h +0 -2
@@ -31,8 +31,6 @@ struct microcode_ops {
 };
 
 struct ucode_cpu_info {
-	struct cpu_signature	cpu_sig;
-	int			valid;
 	void			*mc;
 };
 extern struct ucode_cpu_info ucode_cpu_info[];
(quoted diff) +0 -0

b/arch/x86/kernel/microcode_amd.c
index 366baa1..c205d37 100644

arch/x86/kernel/microcode_amd.c +8 -6
@@ -156,8 +156,6 @@ static int apply_microcode_amd(int cpu)
 	printk(KERN_INFO "microcode: CPU%d: updated (new patch_level=0x%x)\n",
 	       cpu, rev);
 
-	uci->cpu_sig.rev = rev;
-
 	return 0;
 }
 
@@ -249,14 +247,18 @@ static enum ucode_state
 generic_load_microcode(int cpu, const u8 *data, size_t size)
 {
 	struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+	struct cpu_signature cpu_sig;
 	const u8 *ucode_ptr = data;
-	void *new_mc = NULL;
-	void *mc;
-	int new_rev = uci->cpu_sig.rev;
-	unsigned int leftover;
+	void *new_mc = NULL, *mc;
+	unsigned int leftover, new_rev;
 	unsigned long offset;
 	enum ucode_state state = UCODE_OK;
 
+	if (collect_cpu_info_amd(cpu, &cpu_sig))
+		return UCODE_ERROR;
+
+	new_rev = cpu_sig.rev;
+
 	offset = install_equiv_cpu_table(ucode_ptr);
 	if (!offset) {
 		printk(KERN_ERR "microcode: failed to create "
@@ -293,7 +295,7 @@ generic_load_microcode(int cpu, const u8 *data,

size_t size)
uci->mc = new_mc;
pr_debug("microcode: CPU%d found a matching microcode "
"update with version 0x%x (current=0x%x)\n",
- cpu, new_rev, uci->cpu_sig.rev);
+ cpu, new_rev, cpu_sig.rev);
} else {
vfree(new_mc);
state = UCODE_ERROR;

(quoted diff) +0 -0

b/arch/x86/kernel/microcode_core.c
index 378e9a8..b7ead3a 100644

arch/x86/kernel/microcode_core.c +0 -0
@@ -138,20 +138,6 @@ static int collect_cpu_info_on_target(int cpu,

struct cpu_signature *cpu_sig)
return ret;
}

-static int collect_cpu_info(int cpu)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
- int ret;
-
- memset(uci, 0, sizeof(*uci));
-
- ret = collect_cpu_info_on_target(cpu, &uci->cpu_sig);
- if (!ret)
- uci->valid = 1;
-
- return ret;
-}
-
struct apply_microcode_ctx {
int err;
};
@@ -182,12 +168,8 @@ static int do_microcode_update(const void __user *buf, size_t size)
int cpu;

for_each_online_cpu(cpu) {
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
enum ucode_state ustate;

- if (!uci->valid)
- continue;
-
ustate = microcode_ops->request_microcode_user(cpu, buf, size); if (ustate == UCODE_ERROR) {
error = -1;
@@ -269,23 +251,16 @@ static struct platform_device *microcode_pdev;

static int reload_for_cpu(int cpu)
{
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
- int err = 0;
+ enum ucode_state ustate;

mutex_lock(&microcode_mutex);
- if (uci->valid) {
- enum ucode_state ustate;

- ustate = microcode_ops->request_microcode_fw(cpu,
&microcode_pdev->dev);
- if (ustate == UCODE_OK)
- apply_microcode_on_target(cpu);
- else
- if (ustate == UCODE_ERROR)
- err = -EINVAL;
- }
+ ustate = microcode_ops->request_microcode_fw(cpu,
&microcode_pdev->dev);
+ if (ustate == UCODE_OK)
+ apply_microcode_on_target(cpu);
mutex_unlock(&microcode_mutex);

- return err;
+ return (ustate == UCODE_ERROR)? -EINVAL : 0;
}

static ssize_t reload_store(struct sys_device *dev,
@@ -317,17 +292,23 @@ static ssize_t reload_store(struct sys_device *dev,
static ssize_t version_show(struct sys_device *dev,
struct sysdev_attribute *attr, char *buf)
{
- struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
+ struct cpu_signature cpu_sig;

- return sprintf(buf, "0x%x\n", uci->cpu_sig.rev);
+ if (collect_cpu_info_on_target(dev->id, &cpu_sig))
+ return 0;
+
+ return sprintf(buf, "0x%x\n", cpu_sig.rev);
}

static ssize_t pf_show(struct sys_device *dev,
struct sysdev_attribute *attr, char *buf)
{
- struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
+ struct cpu_signature cpu_sig;
+
+ if (collect_cpu_info_on_target(dev->id, &cpu_sig))
+ return 0;

- return sprintf(buf, "0x%x\n", uci->cpu_sig.pf);
+ return sprintf(buf, "0x%x\n", cpu_sig.pf);
}

static SYSDEV_ATTR(reload, 0200, NULL, reload_store);
@@ -348,10 +329,7 @@ static struct attribute_group mc_attr_group = {

static void microcode_fini_cpu(int cpu)
{
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-
microcode_ops->microcode_fini_cpu(cpu);
- uci->valid = 0;
}

static enum ucode_state microcode_resume_cpu(int cpu)
@@ -369,10 +347,10 @@ static enum ucode_state microcode_resume_cpu(int cpu)

static enum ucode_state microcode_init_cpu(int cpu) {
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
enum ucode_state ustate;

- if (collect_cpu_info(cpu))
- return UCODE_ERROR;
+ memset(uci, 0, sizeof(*uci));

/* --dimm. Trigger a delayed update? */
if (system_state != SYSTEM_RUNNING)
@@ -388,19 +366,6 @@ static enum ucode_state microcode_init_cpu(int cpu)
return ustate;
}

-static enum ucode_state microcode_update_cpu(int cpu)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
- enum ucode_state ustate;
-
- if (uci->valid)
- ustate = microcode_resume_cpu(cpu);
- else
- ustate = microcode_init_cpu(cpu);
-
- return ustate;
-}
-
static int mc_sysdev_add(struct sys_device *sys_dev)
{
int err, cpu = sys_dev->id;
@@ -450,7 +415,7 @@ static int mc_sysdev_resume(struct sys_device *dev)
*/
WARN_ON(cpu != 0);

- if (uci->valid && uci->mc)
+ if (uci->mc)
microcode_ops->apply_microcode(cpu);

return 0;
@@ -472,7 +437,10 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
switch (action) {
case CPU_ONLINE:
case CPU_ONLINE_FROZEN:
- microcode_update_cpu(cpu);
+ if (action == CPU_ONLINE_FROZEN)
+ microcode_resume_cpu(cpu);
+ else
+ microcode_init_cpu(cpu);
case CPU_DOWN_FAILED:
case CPU_DOWN_FAILED_FROZEN:
pr_debug("microcode: CPU%d added\n", cpu);

(quoted diff) +0 -0

b/arch/x86/kernel/microcode_intel.c
index 0d334dd..6589765 100644

arch/x86/kernel/microcode_intel.c +0 -2
@@ -339,8 +339,6 @@ static int apply_microcode(int cpu)
 		mc_intel->hdr.date >> 24,
 		(mc_intel->hdr.date >> 16) & 0xff);
 
-	uci->cpu_sig.rev = val[1];
-
 	return 0;
 }
 
@@ -348,11 +346,16 @@ static enum ucode_state generic_load_microcode(int

cpu, void *data, size_t size,
int (*get_ucode_data)(void *, const void *, size_t))
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+ struct cpu_signature cpu_sig;
u8 *ucode_ptr = data, *new_mc = NULL, *mc;
- int new_rev = uci->cpu_sig.rev;
- unsigned int leftover = size;
+ unsigned int leftover = size, new_rev;
enum ucode_state state = UCODE_OK;

+ if (collect_cpu_info(cpu, &cpu_sig))
+ return UCODE_ERROR;
+
+ new_rev = cpu_sig.rev;
+
while (leftover) {
struct microcode_header_intel mc_header; unsigned int mc_size;
@@ -377,7 +380,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
break;
}

- if (get_matching_microcode(&uci->cpu_sig, mc, new_rev)) {
+ if (get_matching_microcode(&cpu_sig, mc, new_rev)) {
if (new_mc)
vfree(new_mc);
new_rev = mc_header.rev;
@@ -407,7 +410,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,

pr_debug("microcode: CPU%d found a matching microcode update with"
" version 0x%x (current=0x%x)\n",
- cpu, new_rev, uci->cpu_sig.rev);
+ cpu, new_rev, cpu_sig.rev);
out:
return state;
}

author
#1 lore raw

RFC PATCH 2/2 x86-microcode: refactor microcode output messages

patch-2: see the summary in the 1st message.

summarize_cpu_info() perhaps require some more polishing.

(Not-yet-)signed-off-by: Dmitry Adaushko <[email protected]>

arch/x86/include/asm/microcode.h +3 -1
index 68fd54c..38011a3 100644
@@ -26,8 +26,10 @@ struct microcode_ops {
 	 * are being called.
 	 * See also the "Synchronization" section in microcode_core.c.
 	 */
-	int (*apply_microcode) (int cpu);
+	int (*apply_microcode) (int cpu, int verbose);
 	int (*collect_cpu_info) (int cpu, struct cpu_signature *csig);
+
+	int (*version_snprintf) (char *buf, int len, struct cpu_signature *csig);
 };
 
 struct ucode_cpu_info {
arch/x86/kernel/microcode_amd.c +9 -4
index c205d37..0928fb3 100644
@@ -81,10 +81,14 @@ static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig)
 		return -1;
 	}
 	rdmsr(MSR_AMD64_PATCH_LEVEL, csig->rev, dummy);
-	printk(KERN_INFO "microcode: CPU%d: patch_level=0x%x\n", cpu, csig->rev);
 	return 0;
 }
 
+static int version_snprintf(char *buf, int len, struct cpu_signature *csig)
+{
+	return snprintf(buf, len, "patch_level=0x%x\n", csig->rev);
+}
+
 static int get_matching_microcode(int cpu, void *mc, int rev)
 {
 	struct microcode_header_amd *mc_header = mc;
@@ -129,7 +133,7 @@ static int get_matching_microcode(int cpu, void *mc, int rev)
 	return 1;
 }
 
-static int apply_microcode_amd(int cpu)
+static int apply_microcode_amd(int cpu, int verbose)
 {
 	u32 rev, dummy;
 	int cpu_num = raw_smp_processor_id();
@@ -153,8 +157,8 @@ static int apply_microcode_amd(int cpu)
 		return -1;
 	}
 
-	printk(KERN_INFO "microcode: CPU%d: updated (new patch_level=0x%x)\n",
-	       cpu, rev);
+	if (verbose)
+		printk(KERN_INFO "microcode: CPU%d: updated (new patch_level=0x%x)\n", cpu, rev);
 
 	return 0;
 }
@@ -347,6 +351,7 @@ static struct microcode_ops microcode_amd_ops = {
 	.request_microcode_fw             = request_microcode_fw,
 	.collect_cpu_info                 = collect_cpu_info_amd,
 	.apply_microcode                  = apply_microcode_amd,
+	.version_snprintf		  = version_snprintf,
 	.microcode_fini_cpu               = microcode_fini_cpu_amd,
 };
 
arch/x86/kernel/microcode_core.c +95 -12

189 lines not on this page · raw message

arch/x86/kernel/microcode_intel.c +14 -9
index 6589765..96c5cf5 100644
@@ -165,12 +165,14 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)
 	/* get the current revision from MSR 0x8B */
 	rdmsr(MSR_IA32_UCODE_REV, val[0], csig->rev);
 
-	printk(KERN_INFO "microcode: CPU%d sig=0x%x, pf=0x%x, revision=0x%x\n",
-			cpu_num, csig->sig, csig->pf, csig->rev);
-
 	return 0;
 }
 
+static int version_snprintf(char *buf, int len, struct cpu_signature *csig)
+{
+	return snprintf(buf, len, "sig=0x%x, pf=0x%x, revision=0x%x\n", csig->sig, csig->pf, csig->rev);
+}
+
 static inline int update_match_cpu(struct cpu_signature *csig, int sig, int pf)
 {
 	return (!sigmatch(sig, csig->sig, pf, csig->pf)) ? 0 : 1;
@@ -297,7 +299,7 @@ get_matching_microcode(struct cpu_signature *cpu_sig, void *mc, int rev)
 	return 0;
 }
 
-static int apply_microcode(int cpu)
+static int apply_microcode(int cpu, int verbose)
 {
 	struct microcode_intel *mc_intel;
 	struct ucode_cpu_info *uci;
@@ -332,12 +334,14 @@ static int apply_microcode(int cpu)
 			cpu_num, mc_intel->hdr.rev);
 		return -1;
 	}
-	printk(KERN_INFO "microcode: CPU%d updated to revision "
+
+	if (verbose)
+		printk(KERN_INFO "microcode: CPU%d updated to revision "
 			 "0x%x, date = %04x-%02x-%02x \n",
-		cpu_num, val[1],
-		mc_intel->hdr.date & 0xffff,
-		mc_intel->hdr.date >> 24,
-		(mc_intel->hdr.date >> 16) & 0xff);
+			cpu_num, val[1],
+			mc_intel->hdr.date & 0xffff,
+			mc_intel->hdr.date >> 24,
+			(mc_intel->hdr.date >> 16) & 0xff);
 
 	return 0;
 }
@@ -468,6 +472,7 @@ static struct microcode_ops microcode_intel_ops = {
 	.request_microcode_fw             = request_microcode_fw,
 	.collect_cpu_info                 = collect_cpu_info,
 	.apply_microcode                  = apply_microcode,
+	.version_snprintf		  = version_snprintf,
 	.microcode_fini_cpu               = microcode_fini_cpu,
 };
 
#2 lore raw
In reply to dimm
Quoted 9 lines · dimm

Hi,

this is in response to Mike's patch "Limit the number of microcode messages".

What's about the following (yet preliminary and not thoroughly tested) approach?

Hmm, patch-1 doesn't apply:

patching file arch/x86/include/asm/microcode.h patching file arch/x86/kernel/microcode_amd.c Hunk #1 succeeded at 152 (offset -4 lines). Hunk #2 succeeded at 240 (offset -7 lines).
patch: **** malformed patch at line 99: size_t size)

Quoted 9 lines

patch-1:

simplify 'struct ucode_cpu_info' and related operational logic.

patch-2:

reduce a number of similar 'microcode version' messages by printing a single message for all cpus with equal microcode version, like:

Would be useful on systems with many cores.

On AMD multi-socket systems often you have the same CPU revisions and thus you'd like to have similar ucode on all cores. Hence there is a high chance that your code would reduce the amount of microcode log messages during boot.

I'd like to test it but would need patches that do apply ...

Thanks,
Andreas

#3 lore raw
Quoted 36 lines · Andreas Herrmann
Quoted 8 lines · dimm

Hi,

this is in response to Mike's patch "Limit the number of microcode messages".

What's about the following (yet preliminary and not thoroughly tested) approach?

Hmm, patch-1 doesn't apply:

patching file arch/x86/include/asm/microcode.h patching file arch/x86/kernel/microcode_amd.c Hunk #1 succeeded at 152 (offset -4 lines). Hunk #2 succeeded at 240 (offset -7 lines).
patch: **** malformed patch at line 99: size_t size)

Quoted 9 lines

patch-1:

simplify 'struct ucode_cpu_info' and related operational logic.

patch-2:

reduce a number of similar 'microcode version' messages by printing a single message for all cpus with equal microcode version, like:

Would be useful on systems with many cores.

On AMD multi-socket systems often you have the same CPU revisions and thus you'd like to have similar ucode on all cores. Hence there is a high chance that your code would reduce the amount of microcode log messages during boot.

Quoted 5 lines

I'd like to test it but would need patches that do apply ...

Thanks,
Andreas

I will test it here as well.

Thanks,
Mike

#4 lore raw
In reply to Andreas Herrmann

2009/11/2 Andreas Herrmann <[email protected]>:

Quoted 11 lines · dimm
Quoted 9 lines

Hi,

this is in response to Mike's patch "Limit the number of microcode messages".

What's about the following (yet preliminary and not thoroughly tested) approach?

Quoted 7 lines

Hmm, patch-1 doesn't apply:

patching file arch/x86/include/asm/microcode.h patching file arch/x86/kernel/microcode_amd.c Hunk #1 succeeded at 152 (offset -4 lines). Hunk #2 succeeded at 240 (offset -7 lines).
patch: **** malformed patch at line 99: size_t size)

Hmm, maybe my mailer has got it inlined wrongly... whatever, sorry for that, I'll resend the patches later today.

Quoted 3 lines

[ ... ]

I'd like to test it but would need patches that do apply ...

Great, I'll send the patches later today.

Quoted 4 lines

Thanks,
Andreas

Signature · 1 line
-- Dmitry