Skip to content

Commit 65391fe

Browse files
committed
KVM: VMX: Add host MSR read/write helpers to consolidate preemption handling
Add host MSR read/write helpers to consolidate preemption handling to prepare for adding FRED RSP0 access functions without duplicating the preemption handling code. Signed-off-by: Xin Li (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent a1f2418 commit 65391fe

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,22 +1344,35 @@ static void vmx_prepare_switch_to_host(struct vcpu_vmx *vmx)
13441344
}
13451345

13461346
#ifdef CONFIG_X86_64
1347-
static u64 vmx_read_guest_kernel_gs_base(struct vcpu_vmx *vmx)
1347+
static u64 vmx_read_guest_host_msr(struct vcpu_vmx *vmx, u32 msr, u64 *cache)
13481348
{
13491349
preempt_disable();
13501350
if (vmx->vt.guest_state_loaded)
1351-
rdmsrq(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base);
1351+
*cache = read_msr(msr);
13521352
preempt_enable();
1353-
return vmx->msr_guest_kernel_gs_base;
1353+
return *cache;
13541354
}
13551355

1356-
static void vmx_write_guest_kernel_gs_base(struct vcpu_vmx *vmx, u64 data)
1356+
static void vmx_write_guest_host_msr(struct vcpu_vmx *vmx, u32 msr, u64 data,
1357+
u64 *cache)
13571358
{
13581359
preempt_disable();
13591360
if (vmx->vt.guest_state_loaded)
1360-
wrmsrq(MSR_KERNEL_GS_BASE, data);
1361+
wrmsrns(msr, data);
13611362
preempt_enable();
1362-
vmx->msr_guest_kernel_gs_base = data;
1363+
*cache = data;
1364+
}
1365+
1366+
static u64 vmx_read_guest_kernel_gs_base(struct vcpu_vmx *vmx)
1367+
{
1368+
return vmx_read_guest_host_msr(vmx, MSR_KERNEL_GS_BASE,
1369+
&vmx->msr_guest_kernel_gs_base);
1370+
}
1371+
1372+
static void vmx_write_guest_kernel_gs_base(struct vcpu_vmx *vmx, u64 data)
1373+
{
1374+
vmx_write_guest_host_msr(vmx, MSR_KERNEL_GS_BASE, data,
1375+
&vmx->msr_guest_kernel_gs_base);
13631376
}
13641377
#endif
13651378

0 commit comments

Comments
 (0)