KVM: SEV: Update SEV-ES shutdown intercepts with more metadata
PATCH 1/1 KVM: SEV: Update SEV-ES shutdown intercepts with more metadata
Currently if an SEV-ES VM shuts down userspace sees KVM_RUN struct with only the INVALID_ARGUMENT. This is a very limited amount of information to debug the situation. Instead KVM can return a KVM_SYSTEM_EVENT_SEV_TERM to alert userspace the VM is shutting down and is not usable any further. This latter point can be enforced using the kvm_vm_dead() functionality.
---
I am not sure if this is the right path forward maybe just returning KVM_EXIT_SHUTDOWN is better. But the current behavior is very unhelpful.
---
arch/x86/kvm/svm/svm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/x86/kvm/svm/svm.c +7 -3
@@ -2131,12 +2131,16 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)* The VM save area has already been encrypted so it * cannot be reinitialized - just terminate. */ -if (sev_es_guest (vcpu->kvm)) -return -EINVAL ; +if (sev_es_guest (vcpu->kvm)) { + vcpu->run->exit_reason =KVM_EXIT_SYSTEM_EVENT ; + vcpu->run->system_event.type =KVM_SYSTEM_EVENT_SEV_TERM ; +kvm_vm_dead (vcpu->kvm); +return 0 ; + }/* * VMCB is undefined after a SHUTDOWN intercept. INIT the vCPU to put -* the VMCB in a known good state. Unfortuately, KVM doesn't have +* the VMCB in a known good state. Unfortunately, KVM doesn't have * KVM_MP_STATE_SHUTDOWN and can't add it without potentially breaking * userspace. At a platform view, INIT is acceptable behavior as * there exist bare metal platforms that automatically INIT the CPU
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Sean Christopherson
maintainerQuoted 6 lines · Peter Gonda
Currently if an SEV-ES VM shuts down userspace sees
KVM_RUNstruct with only theINVALID_ARGUMENT. This is a very limited amount of information to debug the situation. Instead KVM can return aKVM_SYSTEM_EVENT_SEV_TERMto alert userspace the VM is shutting down and is not usable any further. This latter point can be enforced using thekvm_vm_dead()functionality.
Add the kvm_vm_dead() thing in a separate patch. If we want to actually harden KVM against consuming a garbage VMSA then we do need to mark the VM dead, but on the other hand that will block _all_ KVM ioctls(), which will make debug even harder.
Quoted 10 lines
Signed-off-by Peter Gonda <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Sean Christopherson <[email protected]>Cc Tom Lendacky <[email protected]>Cc Joerg Roedel <[email protected]>Cc Borislav Petkov <[email protected]>
Quoted 4 lines
---
I am not sure if this is the right path forward maybe just returning
KVM_EXIT_SHUTDOWNis better. But the current behavior is very unhelpful.
Ya, KVM_EXIT_SHUTDOWN is better, we should leave KVM_SYSTEM_EVENT_SEV_TERM to explicit "requests" from the guest.
Quoted 9 lines · Sean Christopherson
Quoted 6 lines · Peter Gonda
Currently if an SEV-ES VM shuts down userspace sees
KVM_RUNstruct with only theINVALID_ARGUMENT. This is a very limited amount of information to debug the situation. Instead KVM can return aKVM_SYSTEM_EVENT_SEV_TERMto alert userspace the VM is shutting down and is not usable any further. This latter point can be enforced using thekvm_vm_dead()functionality.
Quoted 4 lines
Add the
kvm_vm_dead()thing in a separate patch. If we want to actually harden KVM against consuming a garbage VMSA then we do need to mark the VM dead, but on the other hand that will block _all_ KVMioctls(), which will make debug even harder.
Will do. Do we have better functionality for just blocking running the vCPU?
Quoted 11 lines
Quoted 11 lines
Signed-off-by Peter Gonda <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Sean Christopherson <[email protected]>Cc Tom Lendacky <[email protected]>Cc Joerg Roedel <[email protected]>Cc Borislav Petkov <[email protected]>
Quoted 7 lines
Quoted 4 lines
---
I am not sure if this is the right path forward maybe just returning
KVM_EXIT_SHUTDOWNis better. But the current behavior is very unhelpful.Ya,
KVM_EXIT_SHUTDOWNis better, we should leaveKVM_SYSTEM_EVENT_SEV_TERMto explicit "requests" from the guest.
Sounds good to me. I'll send a V2 that just updates to KVM_EXIT_SHUTDOWN.