From: Paolo Bonzini <pbonzini@redhat.com>
To: Kai Huang <kai.huang@linux.intel.com>,
guangrong.xiao@linux.intel.com, kvm@vger.kernel.org
Subject: Re: [v2] KVM: VMX: Fix commit which broke PML
Date: Wed, 4 Nov 2015 13:00:15 +0100 [thread overview]
Message-ID: <5639F34F.9070206@redhat.com> (raw)
In-Reply-To: <1446615965-3898-1-git-send-email-kai.huang@linux.intel.com>
On 04/11/2015 06:46, Kai Huang wrote:
> I found PML was broken since below commit:
>
> commit feda805fe7c4ed9cf78158e73b1218752e3b4314
> Author: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> 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 <guangrong.xiao@linux.intel.com>
> [Rewrite to use vmcs_set_secondary_exec_control. - Paolo]
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> 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 <kai.huang@linux.intel.com>
>
> ---
>
> 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
next prev parent reply other threads:[~2015-11-04 12:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 5:46 [v2] KVM: VMX: Fix commit which broke PML Kai Huang
2015-11-04 12:00 ` Paolo Bonzini [this message]
2015-11-05 2:04 ` Kai Huang
2015-11-05 8:20 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5639F34F.9070206@redhat.com \
--to=pbonzini@redhat.com \
--cc=guangrong.xiao@linux.intel.com \
--cc=kai.huang@linux.intel.com \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox