diff mbox series

[v4,4/4] KVM: SVM: Return -EINVAL instead of -EBUSY on attempt to re-init SEV/SEV-ES

Message ID 20240131235609.4161407-5-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series Add support for allowing zero SEV ASIDs | expand

Commit Message

Sean Christopherson Jan. 31, 2024, 11:56 p.m. UTC
Return -EINVAL instead of -EBUSY if userspace attempts KVM_SEV{,ES}_INIT
on a VM that already has SEV active.  Returning -EBUSY is nonsencial as
it's impossible to deactivate SEV without destroying the VM, i.e. the VM
isn't "busy" in any sane sense of the word, and the odds of any userspace
wanting exactly -EBUSY on a userspace bug are minuscule.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/svm/sev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Tom Lendacky Feb. 1, 2024, 4:32 p.m. UTC | #1
On 1/31/24 17:56, Sean Christopherson wrote:
> Return -EINVAL instead of -EBUSY if userspace attempts KVM_SEV{,ES}_INIT
> on a VM that already has SEV active.  Returning -EBUSY is nonsencial as
> it's impossible to deactivate SEV without destroying the VM, i.e. the VM
> isn't "busy" in any sane sense of the word, and the odds of any userspace
> wanting exactly -EBUSY on a userspace bug are minuscule.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>   arch/x86/kvm/svm/sev.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 38e40fbc7ea0..cb19b57e1031 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -259,9 +259,8 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp)
>   	if (kvm->created_vcpus)
>   		return -EINVAL;
>   
> -	ret = -EBUSY;
>   	if (unlikely(sev->active))
> -		return ret;
> +		return -EINVAL;
>   
>   	sev->active = true;
>   	sev->es_active = argp->id == KVM_SEV_ES_INIT;
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 38e40fbc7ea0..cb19b57e1031 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -259,9 +259,8 @@  static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp)
 	if (kvm->created_vcpus)
 		return -EINVAL;
 
-	ret = -EBUSY;
 	if (unlikely(sev->active))
-		return ret;
+		return -EINVAL;
 
 	sev->active = true;
 	sev->es_active = argp->id == KVM_SEV_ES_INIT;