Skip to content

Commit e0c2306

Browse files
amlutobonzini
authored andcommitted
x86/kvm/vmx: Don't fetch the TSS base from the GDT
The current CPU's TSS base is a foregone conclusion, so there's no need to parse it out of the segment tables. This should save a couple cycles (as STR is surely microcoded and poorly optimized) but, more importantly, it's a cleanup and it means that segment_base() will never be called on 64-bit kernels. Cc: Thomas Garnier <thgarnie@google.com> Cc: Jim Mattson <jmattson@google.com> Cc: Radim Krčmář <rkrcmar@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 4f53ab1 commit e0c2306

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

arch/x86/kvm/vmx.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,13 +2086,6 @@ static unsigned long segment_base(u16 selector)
20862086
return v;
20872087
}
20882088

2089-
static inline unsigned long kvm_read_tr_base(void)
2090-
{
2091-
u16 tr;
2092-
asm("str %0" : "=g"(tr));
2093-
return segment_base(tr);
2094-
}
2095-
20962089
static void vmx_save_host_state(struct kvm_vcpu *vcpu)
20972090
{
20982091
struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -2292,10 +2285,11 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
22922285

22932286
/*
22942287
* Linux uses per-cpu TSS and GDT, so set these when switching
2295-
* processors.
2288+
* processors. See 22.2.4.
22962289
*/
2297-
vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
2298-
vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
2290+
vmcs_writel(HOST_TR_BASE,
2291+
(unsigned long)this_cpu_ptr(&cpu_tss));
2292+
vmcs_writel(HOST_GDTR_BASE, gdt->address);
22992293

23002294
rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23012295
vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */

0 commit comments

Comments
 (0)