Skip to content

Commit 599288e

Browse files
KAGA-KOKOgregkh
authored andcommitted
x86/bugs: Expose x86_spec_ctrl_base directly
commit fa8ac49 upstream x86_spec_ctrl_base is the system wide default value for the SPEC_CTRL MSR. x86_spec_ctrl_get_default() returns x86_spec_ctrl_base and was intended to prevent modification to that variable. Though the variable is read only after init and globaly visible already. Remove the function and export the variable instead. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ea99935 commit 599288e

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

arch/x86/include/asm/nospec-branch.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,7 @@ enum spectre_v2_mitigation {
217217
SPECTRE_V2_IBRS,
218218
};
219219

220-
/*
221-
* The Intel specification for the SPEC_CTRL MSR requires that we
222-
* preserve any already set reserved bits at boot time (e.g. for
223-
* future additions that this kernel is not currently aware of).
224-
* We then set any additional mitigation bits that we want
225-
* ourselves and always use this as the base for SPEC_CTRL.
226-
* We also use this when handling guest entry/exit as below.
227-
*/
228220
extern void x86_spec_ctrl_set(u64);
229-
extern u64 x86_spec_ctrl_get_default(void);
230221

231222
/* The Speculative Store Bypass disable variants */
232223
enum ssb_mitigation {
@@ -278,6 +269,9 @@ static inline void indirect_branch_prediction_barrier(void)
278269
alternative_msr_write(MSR_IA32_PRED_CMD, val, X86_FEATURE_USE_IBPB);
279270
}
280271

272+
/* The Intel SPEC CTRL MSR base value cache */
273+
extern u64 x86_spec_ctrl_base;
274+
281275
/*
282276
* With retpoline, we must use IBRS to restrict branch prediction
283277
* before calling into firmware.
@@ -286,7 +280,7 @@ static inline void indirect_branch_prediction_barrier(void)
286280
*/
287281
#define firmware_restrict_branch_speculation_start() \
288282
do { \
289-
u64 val = x86_spec_ctrl_get_default() | SPEC_CTRL_IBRS; \
283+
u64 val = x86_spec_ctrl_base | SPEC_CTRL_IBRS; \
290284
\
291285
preempt_disable(); \
292286
alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \
@@ -295,7 +289,7 @@ do { \
295289

296290
#define firmware_restrict_branch_speculation_end() \
297291
do { \
298-
u64 val = x86_spec_ctrl_get_default(); \
292+
u64 val = x86_spec_ctrl_base; \
299293
\
300294
alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \
301295
X86_FEATURE_USE_IBRS_FW); \

arch/x86/include/asm/spec-ctrl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl)
4747
extern u64 x86_amd_ls_cfg_base;
4848
extern u64 x86_amd_ls_cfg_ssbd_mask;
4949

50-
/* The Intel SPEC CTRL MSR base value cache */
51-
extern u64 x86_spec_ctrl_base;
52-
5350
static inline u64 ssbd_tif_to_spec_ctrl(u64 tifn)
5451
{
5552
BUILD_BUG_ON(TIF_SSBD < SPEC_CTRL_SSBD_SHIFT);

arch/x86/kernel/cpu/bugs.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static void __init ssb_select_mitigation(void);
3535
* writes to SPEC_CTRL contain whatever reserved bits have been set.
3636
*/
3737
u64 __ro_after_init x86_spec_ctrl_base;
38+
EXPORT_SYMBOL_GPL(x86_spec_ctrl_base);
3839

3940
/*
4041
* The vendor and possibly platform specific bits which can be modified in
@@ -140,16 +141,6 @@ void x86_spec_ctrl_set(u64 val)
140141
}
141142
EXPORT_SYMBOL_GPL(x86_spec_ctrl_set);
142143

143-
u64 x86_spec_ctrl_get_default(void)
144-
{
145-
u64 msrval = x86_spec_ctrl_base;
146-
147-
if (static_cpu_has(X86_FEATURE_SPEC_CTRL))
148-
msrval |= ssbd_tif_to_spec_ctrl(current_thread_info()->flags);
149-
return msrval;
150-
}
151-
EXPORT_SYMBOL_GPL(x86_spec_ctrl_get_default);
152-
153144
void
154145
x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)
155146
{

0 commit comments

Comments
 (0)