Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp396944ybc; Tue, 12 Nov 2019 03:14:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxAAVk/+rRII2d6In9cL0KVUug1oLj/cT3iNy+V5gHgEs22V14iyPdYL+PBGKRbV/6nq6Th X-Received: by 2002:a17:906:c801:: with SMTP id cx1mr28033872ejb.266.1573557262345; Tue, 12 Nov 2019 03:14:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573557262; cv=none; d=google.com; s=arc-20160816; b=yTq5U7fFbtf6atrgik66g6ftIwIx1YcFCGQfO70LC2uHVNPb8NQWA9p8vkzH9XcnK+ mitnqHkt/hXn3WeAR+wtCaLLv/CF2Sr381kLw1BgDm3umruKBEM8Jio/UtF+Cn+MUMNg jTn1g0gF5GqArxQHZuAYqoSC9SFORR81SMLe5WfM4ze0ABUg2KJ11d5tzw4XtB8h1rJA lGYv5sEbzEKbIHPhyd++G2e3B6WeZXovHNFJFLJaa6x/W0zJnL/4YNHL8xl26QnM5lqs /j/wL3r5xwsRWkOv0jlUW4+E9719zpYrKrL0a4Usz9fXfoLRiUVSciTrNf2wDsNabDAu +qJw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=TAe9qhabEyxe18CNSqXvNbSWF+EQqgyNeooarfeKHUs=; b=rp99LPSCe0LlC0q9TzuCO6e6mmzECzmHi0i+YXAbwZMzoQJCAG7zEJs4uBnjF+x1A0 OOnDGL0cMIU6q9r5O5D0RNkr25QSj/vhKcygVVZ0sQU1/2p/VoMoDBnO+Vb1IrZ3dHmU zzufunUdf2oF9Nou1PewUbswuDKcTW5+7yaMkvg/J7XwoNZSvAABWn5aCcvE0m8dcbCw Mi59k+SOQerw49P6+5AFYt5p9dTvx8W5ZxtrNaRELin30IGuh3NNxuY6Atv6m4eJVGll 5WhztyzLYO0GSH5MH0GcynrTSKdWWozL4eg6t7KbFFOMDq9eEE0I6M8ehWpHVl09zzrn U+cw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si12552614edn.49.2019.11.12.03.13.57; Tue, 12 Nov 2019 03:14:22 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727186AbfKLLKt (ORCPT + 99 others); Tue, 12 Nov 2019 06:10:49 -0500 Received: from proxmox-new.maurer-it.com ([212.186.127.180]:33524 "EHLO proxmox-new.maurer-it.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727180AbfKLLKp (ORCPT ); Tue, 12 Nov 2019 06:10:45 -0500 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3B811467A0; Tue, 12 Nov 2019 12:10:44 +0100 (CET) Subject: Re: [PATCH 4.19 STABLE] KVM: x86: introduce is_pae_paging To: Sean Christopherson , stable@vger.kernel.org, Greg Kroah-Hartman Cc: Paolo Bonzini , linux-kernel@vger.kernel.org References: <20191111225423.29309-1-sean.j.christopherson@intel.com> From: Thomas Lamprecht Message-ID: <4d382b90-34d8-5a4d-1f62-b9dcb479e2ed@proxmox.com> Date: Tue, 12 Nov 2019 12:10:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:71.0) Gecko/20100101 Thunderbird/71.0 MIME-Version: 1.0 In-Reply-To: <20191111225423.29309-1-sean.j.christopherson@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/11/19 11:54 PM, Sean Christopherson wrote: > From: Paolo Bonzini > > Upstream commit bf03d4f9334728bf7c8ffc7de787df48abd6340e. > > Checking for 32-bit PAE is quite common around code that fiddles with > the PDPTRs. Add a function to compress all checks into a single > invocation. > > Moving to the common helper also fixes a subtle bug in kvm_set_cr3() > where it fails to check is_long_mode() and results in KVM incorrectly > attempting to load PDPTRs for a 64-bit guest. > > Reviewed-by: Sean Christopherson > Signed-off-by: Paolo Bonzini > [sean: backport to 4.x; handle vmx.c split in 5.x, call out the bugfix] > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx.c | 7 +++---- > arch/x86/kvm/x86.c | 8 ++++---- > arch/x86/kvm/x86.h | 5 +++++ > 3 files changed, 12 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 6f7b3acdab26..83acaed244ba 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -5181,7 +5181,7 @@ static void ept_load_pdptrs(struct kvm_vcpu *vcpu) > (unsigned long *)&vcpu->arch.regs_dirty)) > return; > > - if (is_paging(vcpu) && is_pae(vcpu) && !is_long_mode(vcpu)) { > + if (is_pae_paging(vcpu)) { > vmcs_write64(GUEST_PDPTR0, mmu->pdptrs[0]); > vmcs_write64(GUEST_PDPTR1, mmu->pdptrs[1]); > vmcs_write64(GUEST_PDPTR2, mmu->pdptrs[2]); > @@ -5193,7 +5193,7 @@ static void ept_save_pdptrs(struct kvm_vcpu *vcpu) > { > struct kvm_mmu *mmu = vcpu->arch.walk_mmu; > > - if (is_paging(vcpu) && is_pae(vcpu) && !is_long_mode(vcpu)) { > + if (is_pae_paging(vcpu)) { > mmu->pdptrs[0] = vmcs_read64(GUEST_PDPTR0); > mmu->pdptrs[1] = vmcs_read64(GUEST_PDPTR1); > mmu->pdptrs[2] = vmcs_read64(GUEST_PDPTR2); > @@ -12021,8 +12021,7 @@ static int nested_vmx_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3, bool ne > * If PAE paging and EPT are both on, CR3 is not used by the CPU and > * must not be dereferenced. > */ > - if (!is_long_mode(vcpu) && is_pae(vcpu) && is_paging(vcpu) && > - !nested_ept) { > + if (is_pae_paging(vcpu) && !nested_ept) { > if (!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) { > *entry_failure_code = ENTRY_FAIL_PDPTE; > return 1; > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 6ae8a013af31..b9b87fb75ac0 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -633,7 +633,7 @@ bool pdptrs_changed(struct kvm_vcpu *vcpu) > gfn_t gfn; > int r; > > - if (is_long_mode(vcpu) || !is_pae(vcpu) || !is_paging(vcpu)) > + if (!is_pae_paging(vcpu)) > return false; > > if (!test_bit(VCPU_EXREG_PDPTR, > @@ -884,8 +884,8 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) > if (is_long_mode(vcpu) && > (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 63))) > return 1; > - else if (is_pae(vcpu) && is_paging(vcpu) && > - !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) > + else if (is_pae_paging(vcpu) && > + !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) > return 1; > > kvm_mmu_new_cr3(vcpu, cr3, skip_tlb_flush); > @@ -8312,7 +8312,7 @@ static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) > kvm_update_cpuid(vcpu); > > idx = srcu_read_lock(&vcpu->kvm->srcu); > - if (!is_long_mode(vcpu) && is_pae(vcpu) && is_paging(vcpu)) { > + if (is_pae_paging(vcpu)) { > load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu)); > mmu_reset_needed = 1; > } > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index 3a91ea760f07..608e5f8c5d0a 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -139,6 +139,11 @@ static inline int is_paging(struct kvm_vcpu *vcpu) > return likely(kvm_read_cr0_bits(vcpu, X86_CR0_PG)); > } > > +static inline bool is_pae_paging(struct kvm_vcpu *vcpu) > +{ > + return !is_long_mode(vcpu) && is_pae(vcpu) && is_paging(vcpu); > +} > + > static inline u32 bit(int bitno) > { > return 1 << (bitno & 31); > Thanks for the fast and good answer and the backport, made things more clear here. Cannot reproduce the issues with that patch anymore Tested-by: Thomas Lamprecht