Skip to content

Commit 6758034

Browse files
committed
x86/process/64: Make save_fsgs_for_kvm() ready for FSGSBASE
save_fsgs_for_kvm() is invoked via vcpu_enter_guest() kvm_x86_ops.prepare_guest_switch(vcpu) vmx_prepare_switch_to_guest() save_fsgs_for_kvm() with preemption disabled, but interrupts enabled. The upcoming FSGSBASE based GS safe needs interrupts to be disabled. This could be done in the helper function, but that function is also called from switch_to() which has interrupts disabled already. Disable interrupts inside save_fsgs_for_kvm() and rename the function to current_save_fsgs() so it can be invoked from other places. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 58edfd2 commit 6758034

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

arch/x86/include/asm/processor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,8 @@ static inline unsigned long cpu_kernelmode_gs_base(int cpu)
457457
DECLARE_PER_CPU(unsigned int, irq_count);
458458
extern asmlinkage void ignore_sysret(void);
459459

460-
#if IS_ENABLED(CONFIG_KVM)
461460
/* Save actual FS/GS selectors and bases to current->thread */
462-
void save_fsgs_for_kvm(void);
463-
#endif
461+
void current_save_fsgs(void);
464462
#else /* X86_64 */
465463
#ifdef CONFIG_STACKPROTECTOR
466464
/*

arch/x86/kernel/process_64.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,21 @@ static __always_inline void save_fsgs(struct task_struct *task)
240240
save_base_legacy(task, task->thread.gsindex, GS);
241241
}
242242

243-
#if IS_ENABLED(CONFIG_KVM)
244243
/*
245244
* While a process is running,current->thread.fsbase and current->thread.gsbase
246-
* may not match the corresponding CPU registers (see save_base_legacy()). KVM
247-
* wants an efficient way to save and restore FSBASE and GSBASE.
248-
* When FSGSBASE extensions are enabled, this will have to use RD{FS,GS}BASE.
245+
* may not match the corresponding CPU registers (see save_base_legacy()).
249246
*/
250-
void save_fsgs_for_kvm(void)
247+
void current_save_fsgs(void)
251248
{
249+
unsigned long flags;
250+
251+
/* Interrupts need to be off for FSGSBASE */
252+
local_irq_save(flags);
252253
save_fsgs(current);
254+
local_irq_restore(flags);
253255
}
254-
EXPORT_SYMBOL_GPL(save_fsgs_for_kvm);
256+
#if IS_ENABLED(CONFIG_KVM)
257+
EXPORT_SYMBOL_GPL(current_save_fsgs);
255258
#endif
256259

257260
static __always_inline void loadseg(enum which_selector which,

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu)
11721172

11731173
gs_base = cpu_kernelmode_gs_base(cpu);
11741174
if (likely(is_64bit_mm(current->mm))) {
1175-
save_fsgs_for_kvm();
1175+
current_save_fsgs();
11761176
fs_sel = current->thread.fsindex;
11771177
gs_sel = current->thread.gsindex;
11781178
fs_base = current->thread.fsbase;

0 commit comments

Comments
 (0)