Re: [Patch v3 Part2 1/9] x86/microcode: Taint kernel only if microcode loading was successful
From: Borislav Petkov
Date: Tue Jan 31 2023 - 06:50:57 EST
On Mon, Jan 30, 2023 at 01:39:47PM -0800, Ashok Raj wrote:
> arch/x86/kernel/cpu/microcode/core.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
Why all this hoopla and unrelated changes?
Why don't you simply hoist the call to ->request_microcode_fw outside of
the locked region as it doesn't have to be there and then do the usual
pattern?
---
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 14a2280fdcd2..23f4f22df581 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -481,28 +481,28 @@ static ssize_t reload_store(struct device *dev,
if (val != 1)
return size;
+ tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev);
+ if (tmp_ret != UCODE_NEW)
+ return ret;
+
cpus_read_lock();
ret = check_online_cpus();
if (ret)
- goto put;
-
- tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev);
- if (tmp_ret != UCODE_NEW)
- goto put;
+ goto unlock;
mutex_lock(µcode_mutex);
ret = microcode_reload_late();
mutex_unlock(µcode_mutex);
-put:
- cpus_read_unlock();
-
if (ret == 0)
ret = size;
add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
+unlock:
+ cpus_read_unlock();
+
return ret;
}
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette