x86/bugs: Make sure MSR_SPEC_CTRL is updated properly upon resume from S3
authorPawan Gupta <pawan.kumar.gupta@linux.intel.com>
Wed, 30 Nov 2022 15:25:51 +0000 (07:25 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 2 Dec 2022 23:45:33 +0000 (15:45 -0800)
commit66065157420c5b9b3f078f43d313c153e1ff7f83
treedc02217a2dc270e6f592cf4dff5d5720d2ef85aa
parenta1e9185d20b56af04022d2e656802254f4ea47eb
x86/bugs: Make sure MSR_SPEC_CTRL is updated properly upon resume from S3

The "force" argument to write_spec_ctrl_current() is currently ambiguous
as it does not guarantee the MSR write. This is due to the optimization
that writes to the MSR happen only when the new value differs from the
cached value.

This is fine in most cases, but breaks for S3 resume when the cached MSR
value gets out of sync with the hardware MSR value due to S3 resetting
it.

When x86_spec_ctrl_current is same as x86_spec_ctrl_base, the MSR write
is skipped. Which results in SPEC_CTRL mitigations not getting restored.

Move the MSR write from write_spec_ctrl_current() to a new function that
unconditionally writes to the MSR. Update the callers accordingly and
rename functions.

  [ bp: Rework a bit. ]

Fixes: caa0ff24d5d0 ("x86/bugs: Keep a per-CPU IA32_SPEC_CTRL value")
Suggested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/806d39b0bfec2fe8f50dc5446dff20f5bb24a959.1669821572.git.pawan.kumar.gupta@linux.intel.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/x86/include/asm/nospec-branch.h
arch/x86/kernel/cpu/bugs.c
arch/x86/kernel/process.c