Skip to contentSkip to conversation

KVM: TDX: Synthesize SHUTDOWN instead of returning -EIO on unhandled EPT violation

PATCH In review Sean Christopherson 4 participants 10 messages Sep 23 – Sep 24

Subsystems (4)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: TDX: Synthesize SHUTDOWN instead of returning -EIO on unhandled EPT violation

Synthesize a triple fault, i.e. exit to userspace with KVM_EXIT_SHUTDOWN, instead of returning -EIO from KVM_RUN if KVM encounters an EPT Violation due to a guest access to a pending page. Returning -EIO implies KVM is buggy, and most VMMs will respond by completely terminating the VM, versus rebooting the VM in response to KVM_EXIT_SHUTDOWN. I.e. give the VMM the option of trying to keep the VM (from the end user's perspective) alive.

Ideally, KVM would probably exit with KVM_EXIT_MEMORY_FAULT, but KVM would need to extend run->memory_fault so that userspace knows the fault can't be handled. This scenario specifically occurs when the guest has deliberately disabled #VEs on unaccepted memory for security purposes, i.e. the guest literally disabled the mechanism that tells it it screwed up. But, because this is fatal, and the whole point is to NOT try to fixup the fault, jumping through hoops to return MEMORY_FAULT instead of SHUTDOWN doesn't make a whole lot of sense.

Fixes e6a85781f783 ("KVM: TDX: Detect unexpected SEPT violations due to pending SPTEs")
Cc James Houghton <[email protected]>
Cc Xiaoyao Li <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Yan Zhao <[email protected]>
Cc Binbin Wu <[email protected]>
Cc Ackerley Tng <[email protected]>
Cc Vishal Annapurve <[email protected]>

---

Compile tested only.

 arch/x86/kvm/vmx/tdx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/tdx.c +2 -2
index 7173ef3fc398..eb82f739a7c0 100644
@@ -1938,8 +1938,8 @@ static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu)
 		if (tdx_is_sept_violation_unexpected_pending(vcpu)) {
 			pr_warn("Guest access before accepting 0x%llx on vCPU %d\n",
 				gpa, vcpu->vcpu_id);
-			kvm_vm_dead(vcpu->kvm);
-			return -EIO;
+			kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
+			return 1;
 		}
 		/*
 		 * Always treat SEPT violations as write faults.  Ignore the

base-commit: 30b5175943e709911702d8a9364145e911f57e3f

Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] kvm: tdx: host log spam via repeated KVM_RUN on unhandled EPT violation --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: tdx: host log spam via repeated KVM_RUN on unhandled EPT violation --

commit 8eacf1c465f7e8b6cb99f1f4dae3c4af3bcde33c
Author: Sean Christopherson <[email protected]>

KVM: TDX: Synthesize SHUTDOWN instead of returning -EIO on unhandled EPT violation

This commit synthesizes a triple fault instead of returning -EIO when KVM encounters an EPT Violation from a guest accessing a pending page. This gives userspace the option to keep the VM alive or reboot it, rather than treating the situation as a fatal KVM bug.

Quoted 4 lines
arch/x86/kvm/vmx/tdx.c +0 -0
index 7173ef3fc398e..eb82f739a7c04 100644

[ ... ]

arch/x86/kvm/vmx/tdx.c static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu) · line 1942

Quoted 8 lines
arch/x86/kvm/vmx/tdx.c +2 -2
@@ -1938,8 +1938,8 @@ static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu)
 		if (tdx_is_sept_violation_unexpected_pending(vcpu)) {
 			pr_warn("Guest access before accepting 0x%llx on vCPU %d\n",
 				gpa, vcpu->vcpu_id);
-			kvm_vm_dead(vcpu->kvm);
-			return -EIO;
+			kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
+			return 1;

[Severity: High]
Will this change allow a malicious or buggy userspace VMM to flood the host kernel log?

By replacing kvm_vm_dead() with KVM_REQ_TRIPLE_FAULT and returning 1, KVM will clear the request during vcpu_enter_guest() and exit to userspace with KVM_EXIT_SHUTDOWN. If the VMM ignores this exit and repeatedly calls KVM_RUN without resetting the vCPU, KVM will immediately re-enter the guest.

The guest will hit the exact same unexpected SEPT violation in tdx_handle_ept_violation(), triggering this unconditional pr_warn() again. This can create an infinite loop that spams dmesg.

Quoted 3 lines
arch/x86/kvm/vmx/tdx.c +0 -0
 		}
 		/*
 		 * Always treat SEPT violations as write faults.  Ignore the

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#2 lore raw
Quoted 19 lines · On Wed, Sep 23, 2026, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: tdx: host log spam via repeated KVM_RUN on unhandled EPT violation --

commit 8eacf1c465f7e8b6cb99f1f4dae3c4af3bcde33c
Author: Sean Christopherson <[email protected]>

KVM: TDX: Synthesize SHUTDOWN instead of returning -EIO on unhandled EPT violation

This commit synthesizes a triple fault instead of returning -EIO when KVM encounters an EPT Violation from a guest accessing a pending page. This gives userspace the option to keep the VM alive or reboot it, rather than treating the situation as a fatal KVM bug.

Quoted 4 lines
arch/x86/kvm/vmx/tdx.c +0 -0
index 7173ef3fc398e..eb82f739a7c04 100644

[ ... ]

Quoted 12 lines

arch/x86/kvm/vmx/tdx.c static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu) · line 1942

Quoted 8 lines
arch/x86/kvm/vmx/tdx.c +2 -2
@@ -1938,8 +1938,8 @@ static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu)
 		if (tdx_is_sept_violation_unexpected_pending(vcpu)) {
 			pr_warn("Guest access before accepting 0x%llx on vCPU %d\n",
 				gpa, vcpu->vcpu_id);
-			kvm_vm_dead(vcpu->kvm);
-			return -EIO;
+			kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
+			return 1;

[Severity: High]
Will this change allow a malicious or buggy userspace VMM to flood the host kernel log?

Well, a malicious VMM could already spam the logs, e.g. by creating a new VM or or spinning up a huge number of VMs. I.e. this is a pre-existing issue. But I agree that it should be ratelimited (or maybe converted to vcpu_debug_ratelimited()?).

Quoted 16 lines

By replacing kvm_vm_dead() with KVM_REQ_TRIPLE_FAULT and returning 1, KVM will clear the request during vcpu_enter_guest() and exit to userspace with KVM_EXIT_SHUTDOWN. If the VMM ignores this exit and repeatedly calls KVM_RUN without resetting the vCPU, KVM will immediately re-enter the guest.

The guest will hit the exact same unexpected SEPT violation in tdx_handle_ept_violation(), triggering this unconditional pr_warn() again. This can create an infinite loop that spams dmesg.

Quoted 3 lines
arch/x86/kvm/vmx/tdx.c +0 -0
 		}
 		/*
 		 * Always treat SEPT violations as write faults.  Ignore the

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw
In reply to Sean Christopherson
Quoted 6 lines · Sean Christopherson

Synthesize a triple fault, i.e. exit to userspace with KVM_EXIT_SHUTDOWN, instead of returning -EIO from KVM_RUN if KVM encounters an EPT Violation due to a guest access to a pending page.  Returning -EIO implies KVM is buggy, and most VMMs will respond by completely terminating the VM, versus rebooting the VM in response to KVM_EXIT_SHUTDOWN.  I.e. give the VMM the option of trying to keep the VM (from the end user's perspective) alive.

Why not just return KVM_EXIT_SHUTDOWN directly when the pending ept violation is detected? The synthetic triple fault makes it harder to trace what is happening. I guess there is some centralization, but harder to trace.

Quoted 20 lines

Ideally, KVM would probably exit with KVM_EXIT_MEMORY_FAULT, but KVM would need to extend run->memory_fault so that userspace knows the fault can't be handled.  This scenario specifically occurs when the guest has deliberately disabled #VEs on unaccepted memory for security purposes, i.e. the guest literally disabled the mechanism that tells it it screwed up.  But, because this is fatal, and the whole point is to NOT try to fixup the fault, jumping through hoops to return MEMORY_FAULT instead of SHUTDOWN doesn't make a whole lot of sense.

Fixes e6a85781f783 ("KVM: TDX: Detect unexpected SEPT violations due to pending SPTEs")
Cc James Houghton <[email protected]>
Cc Xiaoyao Li <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Yan Zhao <[email protected]>
Cc Binbin Wu <[email protected]>
Cc Ackerley Tng <[email protected]>
Cc Vishal Annapurve <[email protected]>
Quoted 3 lines

---

Compile tested only.

Yan, I vaguely recall you had a test that could trigger this case during the base enabling?

author maintainer
#4 lore raw
Quoted 11 lines · Rick P Edgecombe
Quoted 6 lines · Sean Christopherson

Synthesize a triple fault, i.e. exit to userspace with KVM_EXIT_SHUTDOWN, instead of returning -EIO from KVM_RUN if KVM encounters an EPT Violation due to a guest access to a pending page.  Returning -EIO implies KVM is buggy, and most VMMs will respond by completely terminating the VM, versus rebooting the VM in response to KVM_EXIT_SHUTDOWN.  I.e. give the VMM the option of trying to keep the VM (from the end user's perspective) alive.

Why not just return KVM_EXIT_SHUTDOWN directly when the pending ept violation is detected? The synthetic triple fault makes it harder to trace what is happening. I guess there is some centralization, but harder to trace.

Because it didn't even cross my mind that that's on option. :-) This would be a great opportunity to do some centralization, e.g. do the below, and then use kvm_prepare_shutdown_exit() for this case as well.

x86/kvm/svm/svm.c +1 -2
index f5aa3d7d3a10..34e5bc283479 100644
@@ -2164,7 +2164,6 @@ static int mc_interception(struct kvm_vcpu *vcpu)
 
 static int shutdown_interception(struct kvm_vcpu *vcpu)
 {
-       struct kvm_run *kvm_run = vcpu->run;
        struct vcpu_svm *svm = to_svm(vcpu);
 
 
@@ -2188,7 +2187,7 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
                kvm_vcpu_reset(vcpu, true);
        }
 
-       kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
+       kvm_prepare_shutdown_exit(vcpu);
        return 0;
 }
 
x86/kvm/vmx/tdx.c +1 -2
index 7173ef3fc398..0faa7cfd0433 100644
@@ -2091,8 +2091,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
 
        switch (exit_reason.basic) {
        case EXIT_REASON_TRIPLE_FAULT:
-               vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
-               vcpu->mmio_needed = 0;
+               kvm_prepare_shutdown_exit(vcpu);
                return 0;
        case EXIT_REASON_EXCEPTION_NMI:
                return tdx_handle_exception_nmi(vcpu);
x86/kvm/vmx/vmx.c +1 -2
index e8af5e57e1cc..5411eb7f3f26 100644
@@ -5587,8 +5587,7 @@ static __always_inline int handle_external_interrupt(struct kvm_vcpu *vcpu)
 
 static int handle_triple_fault(struct kvm_vcpu *vcpu)
 {
-       vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
-       vcpu->mmio_needed = 0;
+       kvm_prepare_shutdown_exit(vcpu);
        return 0;
 }
 
x86/kvm/x86.c +1 -2
index 1705e7be46ec..e433aa7ee603 100644
@@ -8082,8 +8082,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
                                kvm_nested_call(triple_fault)(vcpu);
 
                        if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) {
-                               vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
-                               vcpu->mmio_needed = 0;
+                               kvm_prepare_shutdown_exit(vcpu);
                                r = 0;
                                goto out;
                        }
linux/kvm_host.h +6 -0
index 284fc7d68c60..d133ad33776b 100644
@@ -2523,6 +2523,12 @@ static inline void kvm_account_pgtable_pages(void *virt, int nr)
 /* Max number of entries allowed for each kvm dirty ring */
 #define  KVM_DIRTY_RING_MAX_ENTRIES  65536
 
+static inline void kvm_prepare_shutdown_exit(struct kvm_vcpu *vcpu)
+{
+       vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
+       vcpu->mmio_needed = false;
+}
+
 static inline void kvm_prepare_memory_fault_exit(struct kvm_vcpu *vcpu,
                                                 gpa_t gpa, gpa_t size,
                                                 bool is_write, bool is_exec,
#5 lore raw
Quoted 9 lines · Sean Christopherson
Quoted 8 lines · Rick P Edgecombe
Quoted 6 lines · Sean Christopherson

Synthesize a triple fault, i.e. exit to userspace with KVM_EXIT_SHUTDOWN, instead of returning -EIO from KVM_RUN if KVM encounters an EPT Violation due to a guest access to a pending page.  Returning -EIO implies KVM is buggy, and most VMMs will respond by completely terminating the VM, versus rebooting the VM in response to KVM_EXIT_SHUTDOWN.  I.e. give the VMM the option of trying to keep the VM (from the end user's perspective) alive.

Quoted 7 lines
Quoted 3 lines

Why not just return KVM_EXIT_SHUTDOWN directly when the pending ept violation is detected? The synthetic triple fault makes it harder to trace what is happening. I guess there is some centralization, but harder to trace.

Because it didn't even cross my mind that that's on option. :-) This would be a great opportunity to do some centralization, e.g. do the below, and then use kvm_prepare_shutdown_exit() for this case as well.

Ah! Ok. Well, yea then. I'd think it would be better to do it that way. Clean up seems reasonable to me except...

Quoted 14 lines
x86/kvm/svm/svm.c +0 -1
index f5aa3d7d3a10..34e5bc283479 100644
@@ -2164,7 +2164,6 @@ static int mc_interception(struct kvm_vcpu *vcpu)
 
 static int shutdown_interception(struct kvm_vcpu *vcpu)
 {
-       struct kvm_run *kvm_run = vcpu->run;
        struct vcpu_svm *svm = to_svm(vcpu);
 
 

x86/kvm/svm/svm.c static int shutdown_interception(struct kvm_vcpu *vcpu) · line 2190

Quoted 5 lines
x86/kvm/svm/svm.c +1 -1
@@ -2188,7 +2187,7 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
                kvm_vcpu_reset(vcpu, true);
        }
 
-       kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
+       kvm_prepare_shutdown_exit(vcpu);

This path grows a vcpu->mmio_needed = false. It probably is ok, but a functional change.

Quoted 63 lines
x86/kvm/svm/svm.c +0 -0
        return 0;
 }
 
x86/kvm/vmx/tdx.c +1 -2
index 7173ef3fc398..0faa7cfd0433 100644
@@ -2091,8 +2091,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
 
        switch (exit_reason.basic) {
        case EXIT_REASON_TRIPLE_FAULT:
-               vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
-               vcpu->mmio_needed = 0;
+               kvm_prepare_shutdown_exit(vcpu);
                return 0;
        case EXIT_REASON_EXCEPTION_NMI:
                return tdx_handle_exception_nmi(vcpu);
x86/kvm/vmx/vmx.c +1 -2
index e8af5e57e1cc..5411eb7f3f26 100644
@@ -5587,8 +5587,7 @@ static __always_inline int handle_external_interrupt(struct kvm_vcpu *vcpu)
 
 static int handle_triple_fault(struct kvm_vcpu *vcpu)
 {
-       vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
-       vcpu->mmio_needed = 0;
+       kvm_prepare_shutdown_exit(vcpu);
        return 0;
 }
 
x86/kvm/x86.c +1 -2
index 1705e7be46ec..e433aa7ee603 100644
@@ -8082,8 +8082,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
                                kvm_nested_call(triple_fault)(vcpu);
 
                        if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) {
-                               vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
-                               vcpu->mmio_needed = 0;
+                               kvm_prepare_shutdown_exit(vcpu);
                                r = 0;
                                goto out;
                        }
linux/kvm_host.h +6 -0
index 284fc7d68c60..d133ad33776b 100644
@@ -2523,6 +2523,12 @@ static inline void kvm_account_pgtable_pages(void *virt, int nr)
 /* Max number of entries allowed for each kvm dirty ring */
 #define  KVM_DIRTY_RING_MAX_ENTRIES  65536
 
+static inline void kvm_prepare_shutdown_exit(struct kvm_vcpu *vcpu)
+{
+       vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
+       vcpu->mmio_needed = false;
+}
+
 static inline void kvm_prepare_memory_fault_exit(struct kvm_vcpu *vcpu,
                                                 gpa_t gpa, gpa_t size,
                                                 bool is_write, bool is_exec,
#6 lore raw
In reply to Sean Christopherson
Quoted 6 lines · Sean Christopherson

Synthesize a triple fault, i.e. exit to userspace with KVM_EXIT_SHUTDOWN, instead of returning -EIO from KVM_RUN if KVM encounters an EPT Violation due to a guest access to a pending page. Returning -EIO implies KVM is buggy, and most VMMs will respond by completely terminating the VM, versus rebooting the VM in response to KVM_EXIT_SHUTDOWN. I.e. give the VMM the option of trying to keep the VM (from the end user's perspective) alive.

But reboot isn't good, neither.

I still think a new specific exit reason[1] would be better, as I suggested before.

[1] https://lore.kernel.org/kvm/[email protected]/

Quoted 43 lines

Ideally, KVM would probably exit with KVM_EXIT_MEMORY_FAULT, but KVM would need to extend run->memory_fault so that userspace knows the fault can't be handled. This scenario specifically occurs when the guest has deliberately disabled #VEs on unaccepted memory for security purposes, i.e. the guest literally disabled the mechanism that tells it it screwed up. But, because this is fatal, and the whole point is to NOT try to fixup the fault, jumping through hoops to return MEMORY_FAULT instead of SHUTDOWN doesn't make a whole lot of sense.

Fixes e6a85781f783 ("KVM: TDX: Detect unexpected SEPT violations due to pending SPTEs")
Cc James Houghton <[email protected]>
Cc Xiaoyao Li <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Yan Zhao <[email protected]>
Cc Binbin Wu <[email protected]>
Cc Ackerley Tng <[email protected]>
Cc Vishal Annapurve <[email protected]>

---

Compile tested only.

 arch/x86/kvm/vmx/tdx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/tdx.c +2 -2
index 7173ef3fc398..eb82f739a7c0 100644
@@ -1938,8 +1938,8 @@ static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu)
 		if (tdx_is_sept_violation_unexpected_pending(vcpu)) {
 			pr_warn("Guest access before accepting 0x%llx on vCPU %d\n",
 				gpa, vcpu->vcpu_id);
-			kvm_vm_dead(vcpu->kvm);
-			return -EIO;
+			kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
+			return 1;
 		}
 		/*
 		 * Always treat SEPT violations as write faults.  Ignore the

base-commit: 30b5175943e709911702d8a9364145e911f57e3f

author maintainer
#7 lore raw
Quoted 8 lines · Xiaoyao Li
Quoted 6 lines · Sean Christopherson

Synthesize a triple fault, i.e. exit to userspace with KVM_EXIT_SHUTDOWN, instead of returning -EIO from KVM_RUN if KVM encounters an EPT Violation due to a guest access to a pending page. Returning -EIO implies KVM is buggy, and most VMMs will respond by completely terminating the VM, versus rebooting the VM in response to KVM_EXIT_SHUTDOWN. I.e. give the VMM the option of trying to keep the VM (from the end user's perspective) alive.

Quoted 5 lines

But reboot isn't good, neither.

I still think a new specific exit reason[1] would be better, as I suggested before.

[1] https://lore.kernel.org/kvm/[email protected]

Doh, I completely forgot about that patch. *sigh*

I actually thought KVM_EXIT_MEMORY_FAULT this time around, but I was worried that it would confuse a VMM. And practically speaking, the VMM can't do anything other than print some diagnostic details and try to reboot the VM, because the guest has very deliberately opted out of #VEs.

An alternative to KVM_EXIT_SHUTDOWN would be

  vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
  vcpu->run->system_event.type = KVM_SYSTEM_EVENT_TDX_FATAL;
  vcpu->run->system_event.ndata = 1;
  vcpu->run->system_event.data[0] = gpa;

So that the VMM could log the guilty GPA. Though I'm not sure I like overloading an explicit guest event.

As for KVM_EXIT_GUEST_ERROR, I don't see the point. As above, the VMM can't do anything other than reboot the VM. I doubt Linux-as-a-guest will ever support an interface that allows recovering from this situation, because again, the entire point is treat unaccepted accesses as fatal conditions.

All in all, I think my vote is still for SHUTDOWN.

#8 lore raw
Quoted 32 lines · Sean Christopherson
Quoted 8 lines · Xiaoyao Li
Quoted 6 lines · Sean Christopherson

Synthesize a triple fault, i.e. exit to userspace with KVM_EXIT_SHUTDOWN, instead of returning -EIO from KVM_RUN if KVM encounters an EPT Violation due to a guest access to a pending page. Returning -EIO implies KVM is buggy, and most VMMs will respond by completely terminating the VM, versus rebooting the VM in response to KVM_EXIT_SHUTDOWN. I.e. give the VMM the option of trying to keep the VM (from the end user's perspective) alive.

Quoted 5 lines

But reboot isn't good, neither.

I still think a new specific exit reason[1] would be better, as I suggested before.

[1] https://lore.kernel.org/kvm/[email protected]

Doh, I completely forgot about that patch. *sigh*

I actually thought KVM_EXIT_MEMORY_FAULT this time around, but I was worried that it would confuse a VMM. And practically speaking, the VMM can't do anything other than print some diagnostic details and try to reboot the VM, because the guest has very deliberately opted out of #VEs.

An alternative to KVM_EXIT_SHUTDOWN would be

  vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
  vcpu->run->system_event.type = KVM_SYSTEM_EVENT_TDX_FATAL;
  vcpu->run->system_event.ndata = 1;
  vcpu->run->system_event.data[0] = gpa;

So that the VMM could log the guilty GPA. Though I'm not sure I like overloading an explicit guest event.

Quoted 6 lines

As for KVM_EXIT_GUEST_ERROR, I don't see the point. As above, the VMM can't do anything other than reboot the VM. I doubt Linux-as-a-guest will ever support an interface that allows recovering from this situation, because again, the entire point is treat unaccepted accesses as fatal conditions.

All in all, I think my vote is still for SHUTDOWN.

My concern is that userspace cannot differentiate between triple fault and accessing a pending page if we return KVM_EXIT_SHUTDOWN. It's not friendly for debugging.

author maintainer
#9 lore raw
Quoted 38 lines · Xiaoyao Li
Quoted 37 lines · Sean Christopherson
Quoted 8 lines · Xiaoyao Li
Quoted 6 lines · Sean Christopherson

Synthesize a triple fault, i.e. exit to userspace with KVM_EXIT_SHUTDOWN, instead of returning -EIO from KVM_RUN if KVM encounters an EPT Violation due to a guest access to a pending page. Returning -EIO implies KVM is buggy, and most VMMs will respond by completely terminating the VM, versus rebooting the VM in response to KVM_EXIT_SHUTDOWN. I.e. give the VMM the option of trying to keep the VM (from the end user's perspective) alive.

Quoted 5 lines

But reboot isn't good, neither.

I still think a new specific exit reason[1] would be better, as I suggested before.

[1] https://lore.kernel.org/kvm/[email protected]

Doh, I completely forgot about that patch. *sigh*

I actually thought KVM_EXIT_MEMORY_FAULT this time around, but I was worried that it would confuse a VMM. And practically speaking, the VMM can't do anything other than print some diagnostic details and try to reboot the VM, because the guest has very deliberately opted out of #VEs.

An alternative to KVM_EXIT_SHUTDOWN would be

  vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
  vcpu->run->system_event.type = KVM_SYSTEM_EVENT_TDX_FATAL;
  vcpu->run->system_event.ndata = 1;
  vcpu->run->system_event.data[0] = gpa;

So that the VMM could log the guilty GPA. Though I'm not sure I like overloading an explicit guest event.

As for KVM_EXIT_GUEST_ERROR, I don't see the point. As above, the VMM can't do anything other than reboot the VM. I doubt Linux-as-a-guest will ever support an interface that allows recovering from this situation, because again, the entire point is treat unaccepted accesses as fatal conditions.

Quoted 5 lines
Quoted 1 line

All in all, I think my vote is still for SHUTDOWN.

My concern is that userspace cannot differentiate between triple fault and accessing a pending page if we return KVM_EXIT_SHUTDOWN. It's not friendly for debugging.

Hmm, I disagree. It's not friendly for *triage* given a bug report from a third party, but for actual debug, I doubt it will matter since the exact exit reason is available with trace_kvm_exit().

And for triage, IMO this scenario isn't interesting enough to warrant special treatment. There are myriad ways to end up in triple fault, i.e. why the guest ended up in a shutdown scenario is never going to be something that can fully debugged given only run->exit_reason. E.g. if the guest did not opt out of #VEs for this scenario, then it's not at all difficult to imagine scenarios where accessing unaccepted memory leads to a triple fault.