From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 604B6C47091 for ; Wed, 15 Dec 2021 16:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244121AbhLOPr6 (ORCPT ); Wed, 15 Dec 2021 10:47:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:29805 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244101AbhLOPr5 (ORCPT ); Wed, 15 Dec 2021 10:47:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639583277; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=prBQp9dTKIRBw4z7Uj86elfBkm/Guna1cZpwNeo2Vh8=; b=OATNBiyfFzxah7x3/pzTJzRoE8V5bTcHJNtg/WN9dCoeMtR29oIUkxc7y+xlHk4yDCZice gdIidP+0K76I+/5EXsgmkNhLB759ZtfSNxB2zVZa6ocSu2RcehM1T+M/xvwfNHX1XJTFkq wComxK7NuAfzubs/1NUoUXN/HW5rem0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-341-eG32FGKZOtqkWObp6a-9NQ-1; Wed, 15 Dec 2021 10:47:54 -0500 X-MC-Unique: eG32FGKZOtqkWObp6a-9NQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89F1381EE62; Wed, 15 Dec 2021 15:47:51 +0000 (UTC) Received: from starship (unknown [10.40.192.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24F7579590; Wed, 15 Dec 2021 15:47:46 +0000 (UTC) Message-ID: <0271da9d3a7494d9e7439d4b8d6d9c857c83a45e.camel@redhat.com> Subject: Re: [PATCH 11/15] KVM: VMX: Update vmcs.GUEST_CR3 only when the guest CR3 is dirty From: Maxim Levitsky To: Lai Jiangshan , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini Cc: Lai Jiangshan , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Date: Wed, 15 Dec 2021 17:47:45 +0200 In-Reply-To: <20211108124407.12187-12-jiangshanlai@gmail.com> References: <20211108124407.12187-1-jiangshanlai@gmail.com> <20211108124407.12187-12-jiangshanlai@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, 2021-11-08 at 20:44 +0800, Lai Jiangshan wrote: > From: Lai Jiangshan > > When vcpu->arch.cr3 is changed, it is marked dirty, so vmcs.GUEST_CR3 > can be updated only when kvm_register_is_dirty(vcpu, VCPU_EXREG_CR3). > > Signed-off-by: Lai Jiangshan > --- > arch/x86/kvm/vmx/vmx.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index d94e51e9c08f..38b65b97fb7b 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -3126,9 +3126,9 @@ static void vmx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, > > if (!enable_unrestricted_guest && !is_paging(vcpu)) > guest_cr3 = to_kvm_vmx(kvm)->ept_identity_map_addr; > - else if (test_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail)) > + else if (kvm_register_is_dirty(vcpu, VCPU_EXREG_CR3)) > guest_cr3 = vcpu->arch.cr3; > - else /* vmcs01.GUEST_CR3 is already up-to-date. */ > + else /* vmcs.GUEST_CR3 is already up-to-date. */ > update_guest_cr3 = false; > vmx_ept_load_pdptrs(vcpu); > } else { I just bisected this patch to break booting a VM with ept=1 but unrestricted_guest=0 (I needed to re-test unrestricted_guest=0 bug related to SMM, but didn't want to boot without EPT. With ept=0,the VM boots with this patch applied). Reverting this patch on top of kvm/queue also works. Best regards, Maxim levitsky