Received: by 10.223.164.202 with SMTP id h10csp4113002wrb; Wed, 29 Nov 2017 00:53:06 -0800 (PST) X-Google-Smtp-Source: AGs4zMbYxAhAv95KdvbKTt+I7uZq9FqyUT8cpNvevwoFkohrFVghgZ/+hzblRhTZEC+t1w89efQc X-Received: by 10.98.194.71 with SMTP id l68mr2165039pfg.221.1511945586822; Wed, 29 Nov 2017 00:53:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511945586; cv=none; d=google.com; s=arc-20160816; b=KXO+isKduogguzua8sQQ9vS530uWQTDIxm/SNVnA/TBhbHUGM2x0QaF7atlSdM8/LY RXuj5mD9XrSWQIxBEejzfYaGFBsYjyUGW+qlZkksA7dehzSWQEM0EEJc6qRgSZJbSNWd +J68+9d9wVwg7Z/li50myrCMvWqdAxf3tII4xeFwXz0aXEVisn+1hMwtiPGjr97yLWDX t7q50jE0XCnueOsx6ize0YxjzAdiwZmHtvGniS0LI9Cko5SE0LaL6cNuA24CFIlXFjhE TskULtOQoh9w2OW2VexCZGbdFMlf+5+bc7intCQsu+81QUpHFePss5Ab9hCYzknUAAIp MVlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=yfumnV53mlOZH6CEA6zXkcmKGKesKQDPswk2OtzUXm4=; b=xE4AnI5i8BtzIiKIws0+ab+b/6ADxNgy0uyMARxeL2lXMS4VwpuE4VNMbt0gCbVLiA ddJtUyf7+VzF70U41q+I/YZbFfFyMH6Qt91i5ycTsdJncuR0uDzI9WCuDYT+JyyCyXUI 1zc0m4wttRdXsDIxN9YVgObPZ+FBaKlfU/qQxVvxmt4BCKLsHQFdI/t2bJ3IinqQMaM2 d0L0Vaszi1rGxgSv3+aB8Z4FYWsd2L7Gb1gBWEOdCHoBqzVVOrkQ+bc5Aek2YKU/+xYV n05L7whdr0DqNoUqMU5NWG1QvwxwX8I5R77YlBqMCpIvlFV7Tvi2KQu69cbyMQ+YUaqY u+/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nVv6dMVi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h6si909927pll.530.2017.11.29.00.52.56; Wed, 29 Nov 2017 00:53:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nVv6dMVi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753613AbdK2IwC (ORCPT + 71 others); Wed, 29 Nov 2017 03:52:02 -0500 Received: from mail-ot0-f196.google.com ([74.125.82.196]:40642 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751826AbdK2IwA (ORCPT ); Wed, 29 Nov 2017 03:52:00 -0500 Received: by mail-ot0-f196.google.com with SMTP id e74so2389921ote.7; Wed, 29 Nov 2017 00:52:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=yfumnV53mlOZH6CEA6zXkcmKGKesKQDPswk2OtzUXm4=; b=nVv6dMVi9U7lwnc6gFR8aRxIClRdvJvuHIUKcVzfAYgaLb314IpI+fbfBxp8m7zVCD Q94DclmTwTE+b6U13q1hNIjdoDQ/eisvN6wW6584sRagtmtiIjq0KKSM48AFbD9Tsb4E MRz+aMycu5SEvfiynOMwaZ1vvDOK6VVarbHdNfgI7CObXmrGtgIlajVZDVgCmEPSyMV3 Jj9EXJ4wW6MLuMeix7OR9Ai5WX9mn+yvxYs8uMx7qfcNglZH0IqUjInJGn5QScZiZx0R M5tGOn3CnXkiJgZLjWlJFd+Kk/flHq6NXOgKFnbUHXP2BkvocmgXphqhQmCwOxbHrTTn KQnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=yfumnV53mlOZH6CEA6zXkcmKGKesKQDPswk2OtzUXm4=; b=HlE4kehMHQJwGBWqsp0+YFIxPy/9AosoiQE31KOeB+sO3buMndfDvhGewCUYUQ5Jfx RSZpSsY4iYs2Jyt7mBrzRpH1X6A3pTObF2kF1Il1KGZMqfU4wOm7sf0kgbDN6yet5LRj U89O9YXMPNivlqy76kQGNbpW9LBlBALhvkWBHe3RJBYu+ZD95Nmie3wxG/5iz4m962+I SSilPjtBwYU/oZ/S9vg6IyioL8q/lWvGo8b4i/ynNwNP3MEax9GXUOBTcJO8jmGbxbmk bcDPgr5CCCCCHOMC7+ptsnmY9mkp9rhFN8eCCZF7M0lLPrSVm8DICeO/HN/PRSDGwSS4 TtJA== X-Gm-Message-State: AJaThX5ZH25nH9DOIGSTtgcmXsrHP1HBarXVW61b7fAT2QCXvrFbrY/y lWZ9Cl7kaRss4F7jIYXqpI59bAicD5MTJIsklpY= X-Received: by 10.157.53.93 with SMTP id l29mr1603433ote.69.1511945520241; Wed, 29 Nov 2017 00:52:00 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.209.8 with HTTP; Wed, 29 Nov 2017 00:51:59 -0800 (PST) In-Reply-To: <5ce1fb8a-05e1-3122-9194-73194a851da4@redhat.com> References: <1511935673-7371-1-git-send-email-wanpeng.li@hotmail.com> <5ce1fb8a-05e1-3122-9194-73194a851da4@redhat.com> From: Wanpeng Li Date: Wed, 29 Nov 2017 16:51:59 +0800 Message-ID: Subject: Re: [PATCH] KVM: VMX: Cache IA32_DEBUGCTL in memory To: Paolo Bonzini Cc: "linux-kernel@vger.kernel.org" , kvm , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li , Jim Mattson Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-29 16:48 GMT+08:00 Paolo Bonzini : > 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=C4=8Dm=C3=A1=C5=99 >> 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 The tracing can't run except vCPU is schedule out, so why update_debugctlmsr should stay in vmx_vcpu_run? Regards, Wanpeng Li > 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, i= nt cpu) >> >> vmx_vcpu_pi_load(vcpu, cpu); >> vmx->host_pkru =3D read_pkru(); >> + vcpu->arch.debugctlmsr =3D 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 =3D 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 =3D get_debugctlmsr(); >> >> vmx_arm_hv_timer(vcpu); >> >> @@ -9509,10 +9512,6 @@ static void __noclone vmx_vcpu_run(struct kvm_vcp= u *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 >> > From 1585389637077957966@xxx Wed Nov 29 08:49:38 +0000 2017 X-GM-THRID: 1585379526281584765 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread