linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: microcode: fix return value for microcode late loading
@ 2020-04-14  9:55 Mihai Carabas
  2020-04-14 16:22 ` Peter Zijlstra
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mihai Carabas @ 2020-04-14  9:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mihai Carabas, Borislav Petkov, Thomas Gleixner, Ingo Molnar,
	x86, H. Peter Anvin

The return value from stop_machine might not be consistent.

stop_machine_cpuslocked returns:
- zero if all functions have returned 0
- a non-zero value if at least one of the functions returned
a non-zero value

There is no way to know if it is negative or positive. So make
__reload_late return 0 on success, or negative otherwise.

Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
---
 arch/x86/kernel/cpu/microcode/core.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 7019d4b..336003e 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -545,8 +545,7 @@ static int __wait_for_cpus(atomic_t *t, long long timeout)
 /*
  * Returns:
  * < 0 - on error
- *   0 - no update done
- *   1 - microcode was updated
+ *   0 - success (no update done or microcode was updated)
  */
 static int __reload_late(void *info)
 {
@@ -573,11 +572,9 @@ static int __reload_late(void *info)
 	else
 		goto wait_for_siblings;
 
-	if (err > UCODE_NFOUND) {
+	if (err >= UCODE_NFOUND) {
 		pr_warn("Error reloading microcode on CPU %d\n", cpu);
 		ret = -1;
-	} else if (err == UCODE_UPDATED || err == UCODE_OK) {
-		ret = 1;
 	}
 
 wait_for_siblings:
@@ -608,7 +605,7 @@ static int microcode_reload_late(void)
 	atomic_set(&late_cpus_out, 0);
 
 	ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
-	if (ret > 0)
+	if (ret == 0)
 		microcode_check();
 
 	pr_info("Reload completed, microcode revision: 0x%x\n", boot_cpu_data.microcode);
@@ -649,7 +646,7 @@ static ssize_t reload_store(struct device *dev,
 put:
 	put_online_cpus();
 
-	if (ret >= 0)
+	if (ret == 0)
 		ret = size;
 
 	return ret;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: microcode: fix return value for microcode late loading
  2020-04-14  9:55 [PATCH] x86: microcode: fix return value for microcode late loading Mihai Carabas
@ 2020-04-14 16:22 ` Peter Zijlstra
  2020-04-17 15:08 ` Borislav Petkov
  2020-04-21 19:28 ` [PATCH v2] " Mihai Carabas
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2020-04-14 16:22 UTC (permalink / raw)
  To: Mihai Carabas
  Cc: linux-kernel, Borislav Petkov, Thomas Gleixner, Ingo Molnar, x86,
	H. Peter Anvin

On Tue, Apr 14, 2020 at 12:55:35PM +0300, Mihai Carabas wrote:
> The return value from stop_machine might not be consistent.
> 
> stop_machine_cpuslocked returns:
> - zero if all functions have returned 0
> - a non-zero value if at least one of the functions returned
> a non-zero value
> 
> There is no way to know if it is negative or positive. So make
> __reload_late return 0 on success, or negative otherwise.
> 
> Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>

Isn't the right fix to disable late-loading?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: microcode: fix return value for microcode late loading
  2020-04-14  9:55 [PATCH] x86: microcode: fix return value for microcode late loading Mihai Carabas
  2020-04-14 16:22 ` Peter Zijlstra
@ 2020-04-17 15:08 ` Borislav Petkov
  2020-04-21 19:28 ` [PATCH v2] " Mihai Carabas
  2 siblings, 0 replies; 5+ messages in thread
From: Borislav Petkov @ 2020-04-17 15:08 UTC (permalink / raw)
  To: Mihai Carabas
  Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, x86, H. Peter Anvin

On Tue, Apr 14, 2020 at 12:55:35PM +0300, Mihai Carabas wrote:
> The return value from stop_machine might not be consistent.
> 
> stop_machine_cpuslocked returns:
> - zero if all functions have returned 0
> - a non-zero value if at least one of the functions returned
> a non-zero value
> 
> There is no way to know if it is negative or positive. So make
> __reload_late return 0 on success, or negative otherwise.
> 
> Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
> ---
>  arch/x86/kernel/cpu/microcode/core.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
> index 7019d4b..336003e 100644
> --- a/arch/x86/kernel/cpu/microcode/core.c
> +++ b/arch/x86/kernel/cpu/microcode/core.c
> @@ -545,8 +545,7 @@ static int __wait_for_cpus(atomic_t *t, long long timeout)
>  /*
>   * Returns:
>   * < 0 - on error
> - *   0 - no update done
> - *   1 - microcode was updated
> + *   0 - success (no update done or microcode was updated)
>   */
>  static int __reload_late(void *info)
>  {
> @@ -573,11 +572,9 @@ static int __reload_late(void *info)
>  	else
>  		goto wait_for_siblings;
>  
> -	if (err > UCODE_NFOUND) {
> +	if (err >= UCODE_NFOUND) {

It is not an error if no microcode was found.

>  		pr_warn("Error reloading microcode on CPU %d\n", cpu);
			^^^^^^^^^^

>  		ret = -1;

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] x86: microcode: fix return value for microcode late loading
  2020-04-14  9:55 [PATCH] x86: microcode: fix return value for microcode late loading Mihai Carabas
  2020-04-14 16:22 ` Peter Zijlstra
  2020-04-17 15:08 ` Borislav Petkov
@ 2020-04-21 19:28 ` Mihai Carabas
  2020-04-22 18:04   ` [tip: x86/microcode] x86/microcode: Fix " tip-bot2 for Mihai Carabas
  2 siblings, 1 reply; 5+ messages in thread
From: Mihai Carabas @ 2020-04-21 19:28 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mihai Carabas, Borislav Petkov, Thomas Gleixner, Ingo Molnar,
	x86, H. Peter Anvin

The return value from stop_machine might not be consistent.

stop_machine_cpuslocked returns:
- zero if all functions have returned 0
- a non-zero value if at least one of the functions returned
a non-zero value

There is no way to know if it is negative or positive. So make
__reload_late return 0 on success, or negative otherwise.

Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
---
Changes in v2:
- do not print anything on UCODE_NFOUND as microcode not found
is not an error

 arch/x86/kernel/cpu/microcode/core.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 7019d4b..a2ae3da 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -545,8 +545,7 @@ static int __wait_for_cpus(atomic_t *t, long long timeout)
 /*
  * Returns:
  * < 0 - on error
- *   0 - no update done
- *   1 - microcode was updated
+ *   0 - success (no update done or microcode was updated)
  */
 static int __reload_late(void *info)
 {
@@ -576,8 +575,8 @@ static int __reload_late(void *info)
 	if (err > UCODE_NFOUND) {
 		pr_warn("Error reloading microcode on CPU %d\n", cpu);
 		ret = -1;
-	} else if (err == UCODE_UPDATED || err == UCODE_OK) {
-		ret = 1;
+	} else if (err == UCODE_NFOUND) {
+		ret = -1;
 	}
 
 wait_for_siblings:
@@ -608,7 +607,7 @@ static int microcode_reload_late(void)
 	atomic_set(&late_cpus_out, 0);
 
 	ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
-	if (ret > 0)
+	if (ret == 0)
 		microcode_check();
 
 	pr_info("Reload completed, microcode revision: 0x%x\n", boot_cpu_data.microcode);
@@ -649,7 +648,7 @@ static ssize_t reload_store(struct device *dev,
 put:
 	put_online_cpus();
 
-	if (ret >= 0)
+	if (ret == 0)
 		ret = size;
 
 	return ret;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip: x86/microcode] x86/microcode: Fix return value for microcode late loading
  2020-04-21 19:28 ` [PATCH v2] " Mihai Carabas
@ 2020-04-22 18:04   ` tip-bot2 for Mihai Carabas
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Mihai Carabas @ 2020-04-22 18:04 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Mihai Carabas, Borislav Petkov, x86, LKML

The following commit has been merged into the x86/microcode branch of tip:

Commit-ID:     9adbf3c609af92a57a73000a3cb8f4c2d307dfa3
Gitweb:        https://git.kernel.org/tip/9adbf3c609af92a57a73000a3cb8f4c2d307dfa3
Author:        Mihai Carabas <mihai.carabas@oracle.com>
AuthorDate:    Tue, 21 Apr 2020 22:28:38 +03:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Wed, 22 Apr 2020 19:55:50 +02:00

x86/microcode: Fix return value for microcode late loading

The return value from stop_machine() might not be consistent.

stop_machine_cpuslocked() returns:
- zero if all functions have returned 0.
- a non-zero value if at least one of the functions returned
a non-zero value.

There is no way to know if it is negative or positive. So make
__reload_late() return 0 on success or negative otherwise.

 [ bp: Unify ret val check and touch up. ]

Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/1587497318-4438-1-git-send-email-mihai.carabas@oracle.com
---
 arch/x86/kernel/cpu/microcode/core.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 7019d4b..baec68b 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -545,8 +545,7 @@ static int __wait_for_cpus(atomic_t *t, long long timeout)
 /*
  * Returns:
  * < 0 - on error
- *   0 - no update done
- *   1 - microcode was updated
+ *   0 - success (no update done or microcode was updated)
  */
 static int __reload_late(void *info)
 {
@@ -573,11 +572,11 @@ static int __reload_late(void *info)
 	else
 		goto wait_for_siblings;
 
-	if (err > UCODE_NFOUND) {
-		pr_warn("Error reloading microcode on CPU %d\n", cpu);
+	if (err >= UCODE_NFOUND) {
+		if (err == UCODE_ERROR)
+			pr_warn("Error reloading microcode on CPU %d\n", cpu);
+
 		ret = -1;
-	} else if (err == UCODE_UPDATED || err == UCODE_OK) {
-		ret = 1;
 	}
 
 wait_for_siblings:
@@ -608,7 +607,7 @@ static int microcode_reload_late(void)
 	atomic_set(&late_cpus_out, 0);
 
 	ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
-	if (ret > 0)
+	if (ret == 0)
 		microcode_check();
 
 	pr_info("Reload completed, microcode revision: 0x%x\n", boot_cpu_data.microcode);
@@ -649,7 +648,7 @@ static ssize_t reload_store(struct device *dev,
 put:
 	put_online_cpus();
 
-	if (ret >= 0)
+	if (ret == 0)
 		ret = size;
 
 	return ret;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-22 18:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-14  9:55 [PATCH] x86: microcode: fix return value for microcode late loading Mihai Carabas
2020-04-14 16:22 ` Peter Zijlstra
2020-04-17 15:08 ` Borislav Petkov
2020-04-21 19:28 ` [PATCH v2] " Mihai Carabas
2020-04-22 18:04   ` [tip: x86/microcode] x86/microcode: Fix " tip-bot2 for Mihai Carabas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).