From patchwork Thu Nov 5 02:04:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 7556711 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 87C70BF90C for ; Thu, 5 Nov 2015 02:08:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 836442082F for ; Thu, 5 Nov 2015 02:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4872F20837 for ; Thu, 5 Nov 2015 02:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030824AbbKECIN (ORCPT ); Wed, 4 Nov 2015 21:08:13 -0500 Received: from mga02.intel.com ([134.134.136.20]:30555 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030342AbbKECIM (ORCPT ); Wed, 4 Nov 2015 21:08:12 -0500 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 04 Nov 2015 18:08:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,245,1444719600"; d="scan'208";a="594251853" Received: from kai-desktop.bj.intel.com (HELO [10.238.135.54]) ([10.238.135.54]) by FMSMGA003.fm.intel.com with ESMTP; 04 Nov 2015 18:08:10 -0800 Subject: Re: [v2] KVM: VMX: Fix commit which broke PML To: Paolo Bonzini , guangrong.xiao@linux.intel.com, kvm@vger.kernel.org References: <1446615965-3898-1-git-send-email-kai.huang@linux.intel.com> <5639F34F.9070206@redhat.com> From: Kai Huang Message-ID: <563AB91F.6080802@linux.intel.com> Date: Thu, 5 Nov 2015 10:04:15 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <5639F34F.9070206@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Paolo, Thanks for applying! I am really sorry that I forgot to delete the line that clears SECONDARY_EXEC_ENABLE_PML bit in vmx_disable_pml, which is renamed to vmx_destroy_pml_buffer now. It won't impact functionality but to make the function consistent, would you also do below? Sorry for such negligence! Thanks, -Kai On 11/04/2015 08:00 PM, Paolo Bonzini wrote: > > On 04/11/2015 06:46, Kai Huang wrote: >> I found PML was broken since below commit: >> >> commit feda805fe7c4ed9cf78158e73b1218752e3b4314 >> Author: Xiao Guangrong >> Date: Wed Sep 9 14:05:55 2015 +0800 >> >> KVM: VMX: unify SECONDARY_VM_EXEC_CONTROL update >> >> Unify the update in vmx_cpuid_update() >> >> Signed-off-by: Xiao Guangrong >> [Rewrite to use vmcs_set_secondary_exec_control. - Paolo] >> Signed-off-by: Paolo Bonzini >> >> The reason is in above commit vmx_cpuid_update calls vmx_secondary_exec_control, >> in which currently SECONDARY_EXEC_ENABLE_PML bit is cleared unconditionally (as >> PML is enabled in creating vcpu). Therefore if vcpu_cpuid_update is called after >> vcpu is created, PML will be disabled unexpectedly while log-dirty code still >> thinks PML is used. >> >> Fix this by clearing SECONDARY_EXEC_ENABLE_PML in vmx_secondary_exec_control >> only when PML is not supported or not enabled (!enable_pml). This is more >> reasonable as PML is currently either always enabled or disabled. With this >> explicit updating SECONDARY_EXEC_ENABLE_PML in vmx_enable{disable}_pml is not >> needed so also rename vmx_enable{disable}_pml to vmx_create{destroy}_pml_buffer. >> >> Signed-off-by: Kai Huang >> >> --- >> >> v1->v2: Fix this by following Paolo's suggestion. It's better to not to clear >> SECONDARY_EXEC_ENABLE_PML in vmx_secondary_exec_control unconditionally but only >> clear it when PML is not supported or enabled. >> >> --- >> arch/x86/kvm/vmx.c | 15 +++++++-------- >> 1 file changed, 7 insertions(+), 8 deletions(-) >> >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> index 2ac11641..89f4fa2 100644 >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -4718,8 +4718,9 @@ static u32 vmx_secondary_exec_control(struct vcpu_vmx *vmx) >> a current VMCS12 >> */ >> exec_control &= ~SECONDARY_EXEC_SHADOW_VMCS; >> - /* PML is enabled/disabled in creating/destorying vcpu */ >> - exec_control &= ~SECONDARY_EXEC_ENABLE_PML; >> + >> + if (!enable_pml) >> + exec_control &= ~SECONDARY_EXEC_ENABLE_PML; >> >> /* Currently, we allow L1 guest to directly run pcommit instruction. */ >> exec_control &= ~SECONDARY_EXEC_PCOMMIT; >> @@ -7804,7 +7805,7 @@ static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2) >> *info2 = vmcs_read32(VM_EXIT_INTR_INFO); >> } >> >> -static int vmx_enable_pml(struct vcpu_vmx *vmx) >> +static int vmx_create_pml_buffer(struct vcpu_vmx *vmx) >> { >> struct page *pml_pg; >> >> @@ -7817,12 +7818,10 @@ static int vmx_enable_pml(struct vcpu_vmx *vmx) >> vmcs_write64(PML_ADDRESS, page_to_phys(vmx->pml_pg)); >> vmcs_write16(GUEST_PML_INDEX, PML_ENTITY_NUM - 1); >> >> - vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_ENABLE_PML); >> - >> return 0; >> } >> >> -static void vmx_disable_pml(struct vcpu_vmx *vmx) >> +static void vmx_destroy_pml_buffer(struct vcpu_vmx *vmx) >> { >> ASSERT(vmx->pml_pg); >> __free_page(vmx->pml_pg); >> @@ -8706,7 +8705,7 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu) >> struct vcpu_vmx *vmx = to_vmx(vcpu); >> >> if (enable_pml) >> - vmx_disable_pml(vmx); >> + vmx_destroy_pml_buffer(vmx); >> free_vpid(vmx->vpid); >> leave_guest_mode(vcpu); >> vmx_load_vmcs01(vcpu); >> @@ -8790,7 +8789,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) >> * for the guest, etc. >> */ >> if (enable_pml) { >> - err = vmx_enable_pml(vmx); >> + err = vmx_create_pml_buffer(vmx); >> if (err) >> goto free_vmcs; >> } >> > > Applied, thanks! > > Paolo > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 89f4fa2..ef4ca76 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -7826,8 +7826,6 @@ static void vmx_destroy_pml_buffer(struct vcpu_vmx *vmx) ASSERT(vmx->pml_pg); __free_page(vmx->pml_pg); vmx->pml_pg = NULL; - - vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_ENABLE_PML); }