Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751348AbeACWVB (ORCPT + 1 other); Wed, 3 Jan 2018 17:21:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:48646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751029AbeACWU7 (ORCPT ); Wed, 3 Jan 2018 17:20:59 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 679D42191E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=luto@kernel.org X-Google-Smtp-Source: ACJfBoshskacBiA3vL90hd/aHQKrooJtldjITB/UzuTNVo3N8xBxSdA8yuaOnbCaV46VUJXxa9FBkdOvwHxEpaMI0OU= MIME-Version: 1.0 In-Reply-To: <1514901591-12866-1-git-send-email-pbonzini@redhat.com> References: <1514901591-12866-1-git-send-email-pbonzini@redhat.com> From: Andy Lutomirski Date: Wed, 3 Jan 2018 14:20:38 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] KVM: x86: do not read FS/GS base MSRs when saving them To: Paolo Bonzini Cc: LKML , kvm list , Andrew Lutomirski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: > On Jan 2, 2018, at 5:59 AM, Paolo Bonzini wrote: > > The FS and userspace GS bases are available in current->thread, while the > kernel GS base is a percpu variable. Skip the expensive rdmsr and just > get the values from memory. That fsbase change is wrong: thread->fsbase is not guaranteed to be correct for current. > > Signed-off-by: Paolo Bonzini > --- > v1->v2: hide the accessor for 32-bit kernels > > arch/x86/include/asm/desc.h | 8 ++++++++ > arch/x86/include/asm/kvm_host.h | 10 ---------- > arch/x86/kernel/cpu/common.c | 1 + > arch/x86/kvm/svm.c | 2 +- > arch/x86/kvm/vmx.c | 17 +++-------------- > 5 files changed, 13 insertions(+), 25 deletions(-) > > diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h > index 4011cb03ef08..6ef8c47d0baa 100644 > --- a/arch/x86/include/asm/desc.h > +++ b/arch/x86/include/asm/desc.h > @@ -85,6 +85,14 @@ static inline phys_addr_t get_cpu_gdt_paddr(unsigned int cpu) > return per_cpu_ptr_to_phys(get_cpu_gdt_rw(cpu)); > } > > +#ifdef CONFIG_X86_64 > +/* Provide the current kernel GS base. */ > +static inline void *get_current_kernel_gs_base(void) > +{ > + return this_cpu_ptr(irq_stack_union.gs_base); > +} > +#endif This is an awful name because MSR_KERNEL_GS_BASE means the user gs base. How about calling it something like get_this_cpu_kernelmode_gs_base() or similar? > #ifdef CONFIG_X86_64 > - vmcs_writel(HOST_FS_BASE, read_msr(MSR_FS_BASE)); > - vmcs_writel(HOST_GS_BASE, read_msr(MSR_GS_BASE)); > + vmcs_writel(HOST_FS_BASE, current->thread.fsbase); That's wrong. thread->fsbase isn't kept up to date while the thread is running. You could potentially try to expose an interface to get save_base_legacy() called to update it.