Skip to contentSkip to conversation

coretemp: fix reading of microcode revision

PATCH Applied Jan Beulich 5 participants 14 messages Oct 7, 2010 – Oct 11, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coretemp: fix reading of microcode revision

According to the documentation, simply reading the respective MSR isn't sufficient: It should be written with zeros, cpuid(1) be executed, and then read (see arch/x86/kernel/cpu/intel.c for an example).

---
 drivers/hwmon/coretemp.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/hwmon/coretemp.c +16 -2
@@ -292,6 +292,15 @@ static int __devinit get_tjmax(struct cp
 	}
 }
 
+static void __devinit get_ucode_rev_on_cpu(void *edx)
+{
+	u32 eax;
+
+	wrmsr(MSR_IA32_UCODE_REV, 0, 0);
+	sync_core();
+	rdmsr(MSR_IA32_UCODE_REV, eax, *(u32 *)edx);
+}
+
 static int __devinit coretemp_probe(struct platform_device *pdev)
 {
 	struct coretemp_data *data;
@@ -327,8 +336,13 @@ static int __devinit coretemp_probe(stru
 
 	if ((c->x86_model = 0xe) && (c->x86_mask < 0xc)) {
 		/* check for microcode update */
-		rdmsr_on_cpu(data->id, MSR_IA32_UCODE_REV, &eax, &edx);
-		if (edx < 0x39) {
+		err = smp_call_function_single(data->id, get_ucode_rev_on_cpu,
+					       &edx, 1);
+		if (err)
+			dev_warn(&pdev->dev,
+				 "Cannot determine microcode revision "
+				 "of the CPU!\n");
+		else if (edx < 0x39) {
 			err = -ENODEV;
 			dev_err(&pdev->dev,
 				"Errata AE18 not fixed, update BIOS or "

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw
Quoted 33 lines · Jan Beulich

According to the documentation, simply reading the respective MSR isn't sufficient: It should be written with zeros, cpuid(1) be executed, and then read (see arch/x86/kernel/cpu/intel.c for an example).

---
 drivers/hwmon/coretemp.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/hwmon/coretemp.c +9 -0
@@ -292,6 +292,15 @@ static int __devinit get_tjmax(struct cp
 	}
 }
 
+static void __devinit get_ucode_rev_on_cpu(void *edx)
+{
+	u32 eax;
+
+	wrmsr(MSR_IA32_UCODE_REV, 0, 0);
+	sync_core();
+	rdmsr(MSR_IA32_UCODE_REV, eax, *(u32 *)edx);
+}
+
 static int __devinit coretemp_probe(struct platform_device *pdev)
 {
 	struct coretemp_data *data;
@@ -327,8 +336,13 @@ static int __devinit coretemp_probe(stru
 

drivers/hwmon/coretemp.c static int __devinit coretemp_probe(stru · line 344

Quoted 10 lines
drivers/hwmon/coretemp.c +6 -2
 	if ((c->x86_model = 0xe) && (c->x86_mask < 0xc)) {
 		/* check for microcode update */
-		rdmsr_on_cpu(data->id, MSR_IA32_UCODE_REV, &eax, &edx);
-		if (edx < 0x39) {
+		err = smp_call_function_single(data->id, get_ucode_rev_on_cpu,
+					       &edx, 1);
+		if (err)
+			dev_warn(&pdev->dev,
+				 "Cannot determine microcode revision "
+				 "of the CPU!\n");

When err, need to call dev_err and go to exit_free. This error handling should be same as edx < 0x39 case.

drivers/hwmon/coretemp.c static int __devinit coretemp_probe(stru · line 348

Quoted 5 lines
drivers/hwmon/coretemp.c +1 -0
+		else if (edx < 0x39) {
 			err = -ENODEV;
 			dev_err(&pdev->dev,
 				"Errata AE18 not fixed, update BIOS or "

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw
In reply to Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Fenghua Yu
Quoted 2 lines · Jan Beulich
(quoted diff) +0 -0
@@ -327,8 +336,13 @@ static int __devinit coretemp_probe(stru
 
Quoted 14 lines

drivers/hwmon/coretemp.c static int __devinit coretemp_probe(stru · line 344

Quoted 10 lines
drivers/hwmon/coretemp.c +6 -2
 	if ((c->x86_model = 0xe) && (c->x86_mask < 0xc)) {
 		/* check for microcode update */
-		rdmsr_on_cpu(data->id, MSR_IA32_UCODE_REV, &eax, &edx);
-		if (edx < 0x39) {
+		err = smp_call_function_single(data->id, get_ucode_rev_on_cpu,
+					       &edx, 1);
+		if (err)
+			dev_warn(&pdev->dev,
+				 "Cannot determine microcode revision "
+				 "of the CPU!\n");

When err, need to call dev_err and go to exit_free. This error handling should
be same as edx < 0x39 case.

Hmm, not sure - I'd prefer to consider the machine usable in this (theoretical only anyway) case.

Jan

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw
In reply to Jan Beulich

Hi Jan,

Quoted 19 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Fenghua Yu
Quoted 2 lines · Jan Beulich
(quoted diff) +0 -0
@@ -327,8 +336,13 @@ static int __devinit coretemp_probe(stru
 
Quoted 14 lines

drivers/hwmon/coretemp.c static int __devinit coretemp_probe(stru · line 344

Quoted 10 lines
drivers/hwmon/coretemp.c +6 -2
 	if ((c->x86_model = 0xe) && (c->x86_mask < 0xc)) {
 		/* check for microcode update */
-		rdmsr_on_cpu(data->id, MSR_IA32_UCODE_REV, &eax, &edx);
-		if (edx < 0x39) {
+		err = smp_call_function_single(data->id, get_ucode_rev_on_cpu,
+					       &edx, 1);
+		if (err)
+			dev_warn(&pdev->dev,
+				 "Cannot determine microcode revision "
+				 "of the CPU!\n");

When err, need to call dev_err and go to exit_free. This error handling should
be same as edx < 0x39 case.

Quoted 2 lines

Hmm, not sure - I'd prefer to consider the machine usable in this (theoretical only anyway) case.

I tend to prefer Fenghua's approach, sorry. If a bad microcode revision is so wrong that we fail the probe when we see it, then a failure to determine the microcode revision should lead to the same result. As always, missing monitoring information is preferable to unreliable monitoring information.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw

PATCH 1/1 coretemp: fix reading of microcode revision

In reply to Jan Beulich

According to the documentation, simply reading the respective MSR isn't sufficient: It should be written with zeros, cpuid(1) be executed, and then read (see arch/x86/kernel/cpu/intel.c for an example).

v2: Fail probe when microcode revision cannot be determined, but is needed to check for proper operation.

Cc Fenghua Yu <[email protected]>
Cc Chen Gong <[email protected]>
Cc Jean Delvare <[email protected]>
---
 drivers/hwmon/coretemp.c |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/hwmon/coretemp.c +18 -2
@@ -292,6 +292,15 @@ static int __devinit get_tjmax(struct cp
 	}
 }
 
+static void __devinit get_ucode_rev_on_cpu(void *edx)
+{
+	u32 eax;
+
+	wrmsr(MSR_IA32_UCODE_REV, 0, 0);
+	sync_core();
+	rdmsr(MSR_IA32_UCODE_REV, eax, *(u32 *)edx);
+}
+
 static int __devinit coretemp_probe(struct platform_device *pdev)
 {
 	struct coretemp_data *data;
@@ -327,8 +336,15 @@ static int __devinit coretemp_probe(stru
 
 	if ((c->x86_model = 0xe) && (c->x86_mask < 0xc)) {
 		/* check for microcode update */
-		rdmsr_on_cpu(data->id, MSR_IA32_UCODE_REV, &eax, &edx);
-		if (edx < 0x39) {
+		err = smp_call_function_single(data->id, get_ucode_rev_on_cpu,
+					       &edx, 1);
+		if (err) {
+			dev_err(&pdev->dev,
+				"Cannot determine microcode revision of "
+				"CPU#%u (%d)!\n", data->id, err);
+			err = -ENODEV;
+			goto exit_free;
+		} else if (edx < 0x39) {
 			err = -ENODEV;
 			dev_err(&pdev->dev,
 				"Errata AE18 not fixed, update BIOS or "

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#5 lore raw
In reply to Jan Beulich
Quoted 20 lines · Jean Delvare
Quoted 19 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Fenghua Yu

drivers/hwmon/coretemp.c static int __devinit coretemp_probe(stru · line 344

Quoted 12 lines · Jan Beulich
drivers/hwmon/coretemp.c +6 -2
@@ -327,8 +336,13 @@ static int __devinit coretemp_probe(stru
 
 	if ((c->x86_model = 0xe) && (c->x86_mask < 0xc)) {
 		/* check for microcode update */
-		rdmsr_on_cpu(data->id, MSR_IA32_UCODE_REV, &eax, &edx);
-		if (edx < 0x39) {
+		err = smp_call_function_single(data->id, get_ucode_rev_on_cpu,
+					       &edx, 1);
+		if (err)
+			dev_warn(&pdev->dev,
+				 "Cannot determine microcode revision "
+				 "of the CPU!\n");

When err, need to call dev_err and go to exit_free. This error handling should
be same as edx < 0x39 case.

Quoted 8 lines
Quoted 2 lines

Hmm, not sure - I'd prefer to consider the machine usable in this (theoretical only anyway) case.

I tend to prefer Fenghua's approach, sorry. If a bad microcode revision is so wrong that we fail the probe when we see it, then a failure to determine the microcode revision should lead to the same result. As always, missing monitoring information is preferable to unreliable monitoring information.

That is correct. On a related note, this is the second place in the kernel that needs to determine the microcode revision. Shouldn't we have this as common arch-specific code?

The nasty thing about microcode revisions is that they can increase at any point in time (although we CAN get notified of it), but I don't think we ensure that they cannot go BACK after suspend/resume cycles.

Signature · 9 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#6 lore raw

Re: [lm-sensors] [PATCH] coretemp: fix reading of microcode

In reply to Jan Beulich

I still think this should be common code shared with microcode_intel.

Signature · 9 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#7 lore raw
In reply to Jan Beulich

On Fri, Oct 08, 2010 at 08:33:22AM -0400, Henrique de Moraes Holschuh wrote:
[ ... ]

Quoted 5 lines

The nasty thing about microcode revisions is that they can increase at any point in time (although we CAN get notified of it), but I don't think we ensure that they cannot go BACK after suspend/resume cycles.

Not sure if it would be worthwhile dealing with that. This sounds a lot like "let's try to make the OS's life miserable", and you end up with a lot of nasty code trying to deal with such situations. Next would be to try to verify if the microcode is really the version it claims to be, or if someone hacked it.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#8 lore raw
In reply to Jan Beulich
Quoted 5 lines · Guenter Roeck

On Fri, Oct 08, 2010 at 08:33:22AM -0400, Henrique de Moraes Holschuh wrote:
[ ... ]

Quoted 3 lines

The nasty thing about microcode revisions is that they can increase at any point in time (although we CAN get notified of it), but I don't think we ensure that they cannot go BACK after suspend/resume cycles.

Actually, I just checked the code and we do. There are some misleading comments on top of microcode_intel.c.

Signature · 9 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#9 lore raw

Re: [lm-sensors] [PATCH] coretemp: fix reading of microcode

In reply to Jan Beulich
Quoted 44 lines · Jan Beulich

According to the documentation, simply reading the respective MSR isn't sufficient: It should be written with zeros, cpuid(1) be executed, and then read (see arch/x86/kernel/cpu/intel.c for an example).

v2: Fail probe when microcode revision cannot be determined, but is needed to check for proper operation.

Cc Fenghua Yu <[email protected]>
Cc Chen Gong <[email protected]>
Cc Jean Delvare <[email protected]>
---
 drivers/hwmon/coretemp.c |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/hwmon/coretemp.c +11 -2
@@ -292,6 +292,15 @@ static int __devinit get_tjmax(struct cp
 	}
 }
 
+static void __devinit get_ucode_rev_on_cpu(void *edx)
+{
+	u32 eax;
+
+	wrmsr(MSR_IA32_UCODE_REV, 0, 0);
+	sync_core();
+	rdmsr(MSR_IA32_UCODE_REV, eax, *(u32 *)edx);
+}
+
 static int __devinit coretemp_probe(struct platform_device *pdev)
 {
 	struct coretemp_data *data;
@@ -327,8 +336,15 @@ static int __devinit coretemp_probe(stru
 
 	if ((c->x86_model = 0xe) && (c->x86_mask < 0xc)) {
 		/* check for microcode update */
-		rdmsr_on_cpu(data->id, MSR_IA32_UCODE_REV, &eax, &edx);
-		if (edx < 0x39) {
+		err = smp_call_function_single(data->id, get_ucode_rev_on_cpu,
+					       &edx, 1);

drivers/hwmon/coretemp.c static int __devinit coretemp_probe(stru · line 350

Quoted 10 lines
drivers/hwmon/coretemp.c +7 -0
+		if (err) {
+			dev_err(&pdev->dev,
+				"Cannot determine microcode revision of "
+				"CPU#%u (%d)!\n", data->id, err);
+			err = -ENODEV;
+			goto exit_free;
+		} else if (edx < 0x39) {
 			err = -ENODEV;
 			dev_err(&pdev->dev,
 				"Errata AE18 not fixed, update BIOS or "

Do we have a conclusion on this ? Looks like no one Acked it, and there was a suggestion to provice a generic piece of code to retrieve the ucode version. Turns out the ucode revision is already available via ucode_cpu_info[cpu].cpu_sig.rev unless I am missing something.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#10 lore raw

Re: [lm-sensors] [PATCH] coretemp: fix reading of microcode

In reply to Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Guenter Roeck

Turns out the ucode revision is already available via ucode_cpu_info[cpu].cpu_sig.rev
unless I am missing something.

But you're not suggesting to make coretemp.ko depend on microcode.ko, are you?

Jan

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#11 lore raw

Re: [lm-sensors] [PATCH] coretemp: fix reading of microcode

In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Guenter Roeck

Turns out the ucode revision is already available via ucode_cpu_info[cpu].cpu_sig.rev
unless I am missing something.

But you're not suggesting to make coretemp.ko depend on microcode.ko, are you?

I am not really suggesting anything. Personally, I think the code is just fine as it is. I would just like someone to Ack it before I would want to apply it, and I happened to notice the above while I was looking for other places where the microcode version is retrieved.

On the contrary, the added dependency (which I had not realized) would be a good argument against using ucode_cpu_info[].

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

Acked-by on v1 1/1
#12 lore raw

Re: [lm-sensors] [PATCH] coretemp: fix reading of microcode

In reply to Jan Beulich
Quoted 14 lines · Guenter Roeck
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Guenter Roeck

Turns out the ucode revision is already available via ucode_cpu_info[cpu].cpu_sig.rev
unless I am missing something.

But you're not suggesting to make coretemp.ko depend on microcode.ko, are you?

I am not really suggesting anything. Personally, I think the code is just fine as it is. I would just like someone to Ack it before I would want to apply it, and I happened to notice the above while I was looking for other places where the microcode version is retrieved.

Quoted 5 lines

On the contrary, the added dependency (which I had not realized) would be a good argument against using ucode_cpu_info[].

Guenter

---
We can apply Jan's clean v2 patch for coretemp.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#13 lore raw

Re: [lm-sensors] [PATCH] coretemp: fix reading of microcode

In reply to Jan Beulich
Quoted 15 lines · Fenghua Yu
Quoted 14 lines · Guenter Roeck
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Guenter Roeck

Turns out the ucode revision is already available via ucode_cpu_info[cpu].cpu_sig.rev
unless I am missing something.

But you're not suggesting to make coretemp.ko depend on microcode.ko, are you?

I am not really suggesting anything. Personally, I think the code is just fine as it is. I would just like someone to Ack it before I would want to apply it, and I happened to notice the above while I was looking for other places where the microcode version is retrieved.

Quoted 7 lines
Quoted 5 lines

On the contrary, the added dependency (which I had not realized) would be a good argument against using ucode_cpu_info[].

Guenter

Applied.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors