From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753465AbdK2Ist (ORCPT ); Wed, 29 Nov 2017 03:48:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53866 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752663AbdK2Iss (ORCPT ); Wed, 29 Nov 2017 03:48:48 -0500 Subject: Re: [PATCH] KVM: VMX: Cache IA32_DEBUGCTL in memory To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li , Jim Mattson References: <1511935673-7371-1-git-send-email-wanpeng.li@hotmail.com> From: Paolo Bonzini Message-ID: <5ce1fb8a-05e1-3122-9194-73194a851da4@redhat.com> Date: Wed, 29 Nov 2017 09:48:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1511935673-7371-1-git-send-email-wanpeng.li@hotmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 29 Nov 2017 08:48:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/11/2017 07:07, Wanpeng Li wrote: > From: Wanpeng Li > > MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT, so it is saved/restored > each time during world switch. Jim from Google pointed out that > when running schbench in L2, vmx_vcpu_run will occupy 4% cpu time, > and the 25% of vmx_vcpu_run cpu time is occupied by get_debugctlmsr(). > This patch caches the host IA32_DEBUGCTL MSR and saves/restores > the host IA32_DEBUGCTL msr when guest/host switches to avoid to > save/restore each time during world switch. > > Suggested-by: Jim Mattson > Cc: Jim Mattson > Cc: Paolo Bonzini > Cc: Radim Krčmář > Signed-off-by: Wanpeng Li The update_debugctlmsr should stay in vmx_vcpu_run so that tracing features work correctly. However, the get_debugctlmsr indeed can be moved to vmx_vcpu_load. > --- > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/vmx.c | 11 +++++------ > 2 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 63d34bc..c904250 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -619,6 +619,7 @@ struct kvm_vcpu_arch { > unsigned long dr7; > unsigned long eff_db[KVM_NR_DB_REGS]; > unsigned long guest_debug_dr7; > + unsigned long debugctlmsr; Please rename to host_debugctlmsr and place it in struct vcpu_vmx. Thanks, Paolo > u64 msr_platform_info; > u64 msr_misc_features_enables; > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 8c7e816..b167bba 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -2326,6 +2326,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > > vmx_vcpu_pi_load(vcpu, cpu); > vmx->host_pkru = read_pkru(); > + vcpu->arch.debugctlmsr = get_debugctlmsr(); > } > > static void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu) > @@ -2347,6 +2348,9 @@ static void vmx_vcpu_put(struct kvm_vcpu *vcpu) > vmx_vcpu_pi_put(vcpu); > > __vmx_load_host_state(to_vmx(vcpu)); > + /* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */ > + if (vcpu->arch.debugctlmsr) > + update_debugctlmsr(vcpu->arch.debugctlmsr); > } > > static bool emulation_required(struct kvm_vcpu *vcpu) > @@ -9346,7 +9350,7 @@ static void vmx_arm_hv_timer(struct kvm_vcpu *vcpu) > static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) > { > struct vcpu_vmx *vmx = to_vmx(vcpu); > - unsigned long debugctlmsr, cr3, cr4; > + unsigned long cr3, cr4; > > /* Record the guest's net vcpu time for enforced NMI injections. */ > if (unlikely(!enable_vnmi && > @@ -9399,7 +9403,6 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) > __write_pkru(vcpu->arch.pkru); > > atomic_switch_perf_msrs(vmx); > - debugctlmsr = get_debugctlmsr(); > > vmx_arm_hv_timer(vcpu); > > @@ -9509,10 +9512,6 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) > #endif > ); > > - /* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */ > - if (debugctlmsr) > - update_debugctlmsr(debugctlmsr); > - > #ifndef CONFIG_X86_64 > /* > * The sysexit path does not restore ds/es, so we must set them to >