linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes
@ 2019-11-11 23:37 Sean Christopherson
  2019-11-11 23:37 ` [PATCH 4.14 STABLE 1/2] kvm: mmu: Don't read PDPTEs when paging is not enabled Sean Christopherson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sean Christopherson @ 2019-11-11 23:37 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman; +Cc: Paolo Bonzini, Junaid Shahid, linux-kernel

The primary goal is to land patch 2/2 (from Paolo), which fixes a reported
crash when running 64-bit KVM guests on systems without unrestricted guest
support.

Attempting to cherry-pick Paolo's patch revealed that a similar PAE bug
fix from Junaid was also missing.  Grab Junaid's patch as a prerequisite,
even though it will effectively be overwritten, so that Paolo's upstream
fix can be applied without modification (sans the vmx.c split in 5.x).

Junaid Shahid (1):
  kvm: mmu: Don't read PDPTEs when paging is not enabled

Paolo Bonzini (1):
  KVM: x86: introduce is_pae_paging

 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(-)

-- 
2.24.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 4.14 STABLE 1/2] kvm: mmu: Don't read PDPTEs when paging is not enabled
  2019-11-11 23:37 [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes Sean Christopherson
@ 2019-11-11 23:37 ` Sean Christopherson
  2019-11-11 23:37 ` [PATCH 4.14 STABLE 2/2] KVM: x86: introduce is_pae_paging Sean Christopherson
  2019-11-13  1:14 ` [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes Sasha Levin
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2019-11-11 23:37 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman; +Cc: Paolo Bonzini, Junaid Shahid, linux-kernel

From: Junaid Shahid <junaids@google.com>

Upstream commit d35b34a9a70edae7ef923f100e51b8b5ae9fe899.

kvm should not attempt to read guest PDPTEs when CR0.PG = 0 and
CR4.PAE = 1.

Signed-off-by: Junaid Shahid <junaids@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/x86.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4927d0f5be13..801e7faba728 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -619,7 +619,7 @@ bool pdptrs_changed(struct kvm_vcpu *vcpu)
 	gfn_t gfn;
 	int r;
 
-	if (is_long_mode(vcpu) || !is_pae(vcpu))
+	if (is_long_mode(vcpu) || !is_pae(vcpu) || !is_paging(vcpu))
 		return false;
 
 	if (!test_bit(VCPU_EXREG_PDPTR,
@@ -7751,7 +7751,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
 		kvm_update_cpuid(vcpu);
 
 	idx = srcu_read_lock(&vcpu->kvm->srcu);
-	if (!is_long_mode(vcpu) && is_pae(vcpu)) {
+	if (!is_long_mode(vcpu) && is_pae(vcpu) && is_paging(vcpu)) {
 		load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu));
 		mmu_reset_needed = 1;
 	}
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4.14 STABLE 2/2] KVM: x86: introduce is_pae_paging
  2019-11-11 23:37 [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes Sean Christopherson
  2019-11-11 23:37 ` [PATCH 4.14 STABLE 1/2] kvm: mmu: Don't read PDPTEs when paging is not enabled Sean Christopherson
@ 2019-11-11 23:37 ` Sean Christopherson
  2019-11-13  1:14 ` [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes Sasha Levin
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2019-11-11 23:37 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman; +Cc: Paolo Bonzini, Junaid Shahid, linux-kernel

From: Paolo Bonzini <pbonzini@redhat.com>

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 <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[sean: backport to 4.x; handle vmx.c split in 5.x, call out the bugfix]
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 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 02c0326dc259..532598637b24 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -4476,7 +4476,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]);
@@ -4488,7 +4488,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);
@@ -10914,8 +10914,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 801e7faba728..ddab027a0370 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -619,7 +619,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,
@@ -848,8 +848,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;
 
 	vcpu->arch.cr3 = cr3;
@@ -7751,7 +7751,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
 		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 c88305d997b0..68eb0d03e5fc 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -94,6 +94,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);
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes
  2019-11-11 23:37 [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes Sean Christopherson
  2019-11-11 23:37 ` [PATCH 4.14 STABLE 1/2] kvm: mmu: Don't read PDPTEs when paging is not enabled Sean Christopherson
  2019-11-11 23:37 ` [PATCH 4.14 STABLE 2/2] KVM: x86: introduce is_pae_paging Sean Christopherson
@ 2019-11-13  1:14 ` Sasha Levin
  2 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2019-11-13  1:14 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: stable, Greg Kroah-Hartman, Paolo Bonzini, Junaid Shahid, linux-kernel

On Mon, Nov 11, 2019 at 03:37:16PM -0800, Sean Christopherson wrote:
>The primary goal is to land patch 2/2 (from Paolo), which fixes a reported
>crash when running 64-bit KVM guests on systems without unrestricted guest
>support.
>
>Attempting to cherry-pick Paolo's patch revealed that a similar PAE bug
>fix from Junaid was also missing.  Grab Junaid's patch as a prerequisite,
>even though it will effectively be overwritten, so that Paolo's upstream
>fix can be applied without modification (sans the vmx.c split in 5.x).
>
>Junaid Shahid (1):
>  kvm: mmu: Don't read PDPTEs when paging is not enabled
>
>Paolo Bonzini (1):
>  KVM: x86: introduce is_pae_paging
>
> 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(-)

Queued up for 4.14, thank you.

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-13  1:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11 23:37 [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes Sean Christopherson
2019-11-11 23:37 ` [PATCH 4.14 STABLE 1/2] kvm: mmu: Don't read PDPTEs when paging is not enabled Sean Christopherson
2019-11-11 23:37 ` [PATCH 4.14 STABLE 2/2] KVM: x86: introduce is_pae_paging Sean Christopherson
2019-11-13  1:14 ` [PATCH 4.14 STABLE 0/2] KVM: x86: PAE related bug fixes Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).