Skip to contentSkip to conversation

KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested

PATCH Applied Jan Kiszka 3 participants 6 messages Jul 21, 2019 – Jul 22, 2019

Subsystems (3)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested

From: Jan Kiszka <[email protected]>

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.

---

And another gremlin. I'm afraid there is at least one more because vmport access from L2 is still failing in QEMU. This is just another fallout from that. At least the host seems stable now.

 arch/x86/kvm/vmx/nested.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +2 -0
index 0f1378789bd0..4cdab4b4eff1 100644
@@ -220,6 +220,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.16.4

Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

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.

Good catch.

This would have been more easily diagnosed in case free_nested() would NULL cached_vmcs12 and cached_shadow_vmcs12 after kfree() and add to get_vmcs12() & get_shadow_vmcs12() a relevant BUG_ON() call.

I would submit such a patch separately.

-Liran

Quoted 24 lines

---

And another gremlin. I'm afraid there is at least one more because vmport access from L2 is still failing in QEMU. This is just another fallout from that. At least the host seems stable now.

arch/x86/kvm/vmx/nested.c | 2 ++

1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +2 -1
index 0f1378789bd0..4cdab4b4eff1 100644
@@ -220,6 +220,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.16.4

author
#2 lore raw
Quoted 12 lines · Liran Alon
Quoted 12 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

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.

Quoted 7 lines
Quoted 1 line

Good catch.

This would have been more easily diagnosed in case free_nested() would NULL cached_vmcs12 and cached_shadow_vmcs12 after kfree() and add to get_vmcs12() & get_shadow_vmcs12() a relevant BUG_ON() call.

The NULL'ifying makes sense, patch follows. But the helpers are too often called unconditionally, thus cause false positives when adding the BUG_ON.

Jan

Quoted 29 lines

I would submit such a patch separately.

-Liran

Quoted 24 lines

---

And another gremlin. I'm afraid there is at least one more because vmport access from L2 is still failing in QEMU. This is just another fallout from that. At least the host seems stable now.

arch/x86/kvm/vmx/nested.c | 2 ++

1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +2 -1
index 0f1378789bd0..4cdab4b4eff1 100644
@@ -220,6 +220,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.16.4

#3 lore raw
Quoted 19 lines · Jan Kiszka
Quoted 14 lines · Liran Alon
Quoted 13 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

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.

Quoted 8 lines
Quoted 5 lines

Good catch.

This would have been more easily diagnosed in case free_nested() would NULL cached_vmcs12 and cached_shadow_vmcs12 after kfree() and add to get_vmcs12() & get_shadow_vmcs12() a relevant BUG_ON() call.

The NULL'ifying makes sense, patch follows. But the helpers are too often called unconditionally, thus cause false positives when adding the BUG_ON.

How would having a BUG_ON(!cached_vmcs12) on get_vmcs12() will cause false positive? I don’t see any legit case it is called and return NULL.

-Liran

Quoted 32 lines

Jan

Quoted 29 lines

I would submit such a patch separately.

-Liran

Quoted 24 lines

---

And another gremlin. I'm afraid there is at least one more because vmport access from L2 is still failing in QEMU. This is just another fallout from that. At least the host seems stable now.

arch/x86/kvm/vmx/nested.c | 2 ++

1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +2 -1
index 0f1378789bd0..4cdab4b4eff1 100644
@@ -220,6 +220,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.16.4

maintainer
#4 lore raw
Quoted 2 lines · Liran Alon

How would having a BUG_ON(!cached_vmcs12) on get_vmcs12() will cause false positive? I don’t see any legit case it is called and return NULL.

For example, vmx_read_l1_tsc_offset and vmx_write_l1_tsc_offset call it unconditionally, but then only use it if is_guest_mode(vcpu).

Paolo

maintainer Applied
#5 lore raw
In reply to Jan Kiszka
Quoted 32 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

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.

---

And another gremlin. I'm afraid there is at least one more because vmport access from L2 is still failing in QEMU. This is just another fallout from that. At least the host seems stable now.

 arch/x86/kvm/vmx/nested.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +2 -1
index 0f1378789bd0..4cdab4b4eff1 100644
@@ -220,6 +220,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);
--
Quoted 2 lines

2.16.4

Queued, thanks.

Paolo