* [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes
@ 2019-07-25 11:49 Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 1/3] KVM: nVMX: do not use dangling shadow VMCS after guest reset Vitaly Kuznetsov
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2019-07-25 11:49 UTC (permalink / raw)
To: stable; +Cc: kvm, linux-kernel, Paolo Bonzini, Radim Krčmář
Few patches were recently marked for stable@ but commits are not
backportable as-is and require a few tweaks. Here is 5.1 stable backport.
[PATCH2 of the series applies as-is, I have it here for completeness]
Jan Kiszka (1):
KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested
Paolo Bonzini (2):
KVM: nVMX: do not use dangling shadow VMCS after guest reset
Revert "kvm: x86: Use task structs fpu field for user"
arch/x86/include/asm/kvm_host.h | 7 ++++---
arch/x86/kvm/vmx/nested.c | 10 +++++++++-
arch/x86/kvm/x86.c | 4 ++--
3 files changed, 15 insertions(+), 6 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH stable-5.1 1/3] KVM: nVMX: do not use dangling shadow VMCS after guest reset
2019-07-25 11:49 [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Vitaly Kuznetsov
@ 2019-07-25 11:49 ` Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 2/3] KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested Vitaly Kuznetsov
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2019-07-25 11:49 UTC (permalink / raw)
To: stable; +Cc: kvm, linux-kernel, Paolo Bonzini, Radim Krčmář
From: Paolo Bonzini <pbonzini@redhat.com>
[ Upstream commit 88dddc11a8d6b09201b4db9d255b3394d9bc9e57 ]
If a KVM guest is reset while running a nested guest, free_nested will
disable the shadow VMCS execution control in the vmcs01. However,
on the next KVM_RUN vmx_vcpu_run would nevertheless try to sync
the VMCS12 to the shadow VMCS which has since been freed.
This causes a vmptrld of a NULL pointer on my machime, but Jan reports
the host to hang altogether. Let's see how much this trivial patch fixes.
Reported-by: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Liran Alon <liran.alon@oracle.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/vmx/nested.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 4ca834d22169..3f48006a43ec 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -184,6 +184,7 @@ static void vmx_disable_shadow_vmcs(struct vcpu_vmx *vmx)
{
vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_SHADOW_VMCS);
vmcs_write64(VMCS_LINK_POINTER, -1ull);
+ vmx->nested.need_vmcs12_sync = false;
}
static inline void nested_release_evmcs(struct kvm_vcpu *vcpu)
@@ -1328,6 +1329,9 @@ static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx)
u64 field_value;
struct vmcs *shadow_vmcs = vmx->vmcs01.shadow_vmcs;
+ if (WARN_ON(!shadow_vmcs))
+ return;
+
preempt_disable();
vmcs_load(shadow_vmcs);
@@ -1366,6 +1370,9 @@ static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx)
u64 field_value = 0;
struct vmcs *shadow_vmcs = vmx->vmcs01.shadow_vmcs;
+ if (WARN_ON(!shadow_vmcs))
+ return;
+
vmcs_load(shadow_vmcs);
for (q = 0; q < ARRAY_SIZE(fields); q++) {
@@ -4340,7 +4347,6 @@ static inline void nested_release_vmcs12(struct kvm_vcpu *vcpu)
/* copy to memory all shadowed fields in case
they were modified */
copy_shadow_to_vmcs12(vmx);
- vmx->nested.need_vmcs12_sync = false;
vmx_disable_shadow_vmcs(vmx);
}
vmx->nested.posted_intr_nv = -1;
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH stable-5.1 2/3] KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested
2019-07-25 11:49 [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 1/3] KVM: nVMX: do not use dangling shadow VMCS after guest reset Vitaly Kuznetsov
@ 2019-07-25 11:49 ` Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 3/3] Revert "kvm: x86: Use task structs fpu field for user" Vitaly Kuznetsov
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2019-07-25 11:49 UTC (permalink / raw)
To: stable; +Cc: kvm, linux-kernel, Paolo Bonzini, Radim Krčmář
From: Jan Kiszka <jan.kiszka@siemens.com>
[ Upstream commit cf64527bb33f6cec2ed50f89182fc4688d0056b6 ]
Letting this pend may cause nested_get_vmcs12_pages to run against an
invalid state, corrupting the effective vmcs of L1.
This was triggerable in QEMU after a guest corruption in L2, followed by
a L1 reset.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
Cc: stable@vger.kernel.org
Fixes: 7f7f1ba33cf2 ("KVM: x86: do not load vmcs12 pages while still in SMM")
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/vmx/nested.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 3f48006a43ec..f78975d4a7fa 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -212,6 +212,8 @@ static void free_nested(struct kvm_vcpu *vcpu)
if (!vmx->nested.vmxon && !vmx->nested.smm.vmxon)
return;
+ kvm_clear_request(KVM_REQ_GET_VMCS12_PAGES, vcpu);
+
vmx->nested.vmxon = false;
vmx->nested.smm.vmxon = false;
free_vpid(vmx->nested.vpid02);
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH stable-5.1 3/3] Revert "kvm: x86: Use task structs fpu field for user"
2019-07-25 11:49 [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 1/3] KVM: nVMX: do not use dangling shadow VMCS after guest reset Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 2/3] KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested Vitaly Kuznetsov
@ 2019-07-25 11:49 ` Vitaly Kuznetsov
2019-07-25 15:48 ` [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Paolo Bonzini
2019-07-26 13:49 ` Greg KH
4 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2019-07-25 11:49 UTC (permalink / raw)
To: stable; +Cc: kvm, linux-kernel, Paolo Bonzini, Radim Krčmář
From: Paolo Bonzini <pbonzini@redhat.com>
[ Upstream commit ec269475cba7bcdd1eb8fdf8e87f4c6c81a376fe ]
This reverts commit 240c35a3783ab9b3a0afaba0dde7291295680a6b
("kvm: x86: Use task structs fpu field for user", 2018-11-06).
The commit is broken and causes QEMU's FPU state to be destroyed
when KVM_RUN is preempted.
Fixes: 240c35a3783a ("kvm: x86: Use task structs fpu field for user")
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/include/asm/kvm_host.h | 7 ++++---
arch/x86/kvm/x86.c | 4 ++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index c79abe7ca093..564729a4a25c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -609,15 +609,16 @@ struct kvm_vcpu_arch {
/*
* QEMU userspace and the guest each have their own FPU state.
- * In vcpu_run, we switch between the user, maintained in the
- * task_struct struct, and guest FPU contexts. While running a VCPU,
- * the VCPU thread will have the guest FPU context.
+ * In vcpu_run, we switch between the user and guest FPU contexts.
+ * While running a VCPU, the VCPU thread will have the guest FPU
+ * context.
*
* Note that while the PKRU state lives inside the fpu registers,
* it is switched out separately at VMENTER and VMEXIT time. The
* "guest_fpu" state here contains the guest FPU context, with the
* host PRKU bits.
*/
+ struct fpu user_fpu;
struct fpu *guest_fpu;
u64 xcr0;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 37028ea85d4c..aede8fa2ea9a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8172,7 +8172,7 @@ static int complete_emulated_mmio(struct kvm_vcpu *vcpu)
static void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
{
preempt_disable();
- copy_fpregs_to_fpstate(¤t->thread.fpu);
+ copy_fpregs_to_fpstate(&vcpu->arch.user_fpu);
/* PKRU is separately restored in kvm_x86_ops->run. */
__copy_kernel_to_fpregs(&vcpu->arch.guest_fpu->state,
~XFEATURE_MASK_PKRU);
@@ -8185,7 +8185,7 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
{
preempt_disable();
copy_fpregs_to_fpstate(vcpu->arch.guest_fpu);
- copy_kernel_to_fpregs(¤t->thread.fpu.state);
+ copy_kernel_to_fpregs(&vcpu->arch.user_fpu.state);
preempt_enable();
++vcpu->stat.fpu_reload;
trace_kvm_fpu(0);
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes
2019-07-25 11:49 [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Vitaly Kuznetsov
` (2 preceding siblings ...)
2019-07-25 11:49 ` [PATCH stable-5.1 3/3] Revert "kvm: x86: Use task structs fpu field for user" Vitaly Kuznetsov
@ 2019-07-25 15:48 ` Paolo Bonzini
2019-07-26 13:49 ` Greg KH
4 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2019-07-25 15:48 UTC (permalink / raw)
To: Vitaly Kuznetsov, stable; +Cc: kvm, linux-kernel, Radim Krčmář
On 25/07/19 13:49, Vitaly Kuznetsov wrote:
> Few patches were recently marked for stable@ but commits are not
> backportable as-is and require a few tweaks. Here is 5.1 stable backport.
>
> [PATCH2 of the series applies as-is, I have it here for completeness]
>
> Jan Kiszka (1):
> KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested
>
> Paolo Bonzini (2):
> KVM: nVMX: do not use dangling shadow VMCS after guest reset
> Revert "kvm: x86: Use task structs fpu field for user"
>
> arch/x86/include/asm/kvm_host.h | 7 ++++---
> arch/x86/kvm/vmx/nested.c | 10 +++++++++-
> arch/x86/kvm/x86.c | 4 ++--
> 3 files changed, 15 insertions(+), 6 deletions(-)
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes
2019-07-25 11:49 [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Vitaly Kuznetsov
` (3 preceding siblings ...)
2019-07-25 15:48 ` [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Paolo Bonzini
@ 2019-07-26 13:49 ` Greg KH
4 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2019-07-26 13:49 UTC (permalink / raw)
To: Vitaly Kuznetsov
Cc: stable, kvm, linux-kernel, Paolo Bonzini, Radim Krčmář
On Thu, Jul 25, 2019 at 01:49:35PM +0200, Vitaly Kuznetsov wrote:
> Few patches were recently marked for stable@ but commits are not
> backportable as-is and require a few tweaks. Here is 5.1 stable backport.
>
> [PATCH2 of the series applies as-is, I have it here for completeness]
>
> Jan Kiszka (1):
> KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested
>
> Paolo Bonzini (2):
> KVM: nVMX: do not use dangling shadow VMCS after guest reset
> Revert "kvm: x86: Use task structs fpu field for user"
All now applied, thanks!
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-07-26 13:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-25 11:49 [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 1/3] KVM: nVMX: do not use dangling shadow VMCS after guest reset Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 2/3] KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested Vitaly Kuznetsov
2019-07-25 11:49 ` [PATCH stable-5.1 3/3] Revert "kvm: x86: Use task structs fpu field for user" Vitaly Kuznetsov
2019-07-25 15:48 ` [PATCH stable-5.1 0/3] KVM: x86: FPU and nested VMX guest reset fixes Paolo Bonzini
2019-07-26 13:49 ` Greg KH
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).