Commit 84841f39 authored by Carlos López's avatar Carlos López Committed by Sean Christopherson
Browse files

KVM: SEV: use mutex guard in sev_mem_enc_unregister_region()



Simplify the error paths in sev_mem_enc_unregister_region() by using a
mutex guard, allowing early return instead of using gotos.

Signed-off-by: default avatarCarlos López <clopez@suse.de>
Link: https://patch.msgid.link/20260120201013.3931334-7-clopez@suse.de
Link: https://patch.msgid.link/20260310234829.2608037-19-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 63e56d84
Loading
Loading
Loading
Loading
+5 −15
Original line number Diff line number Diff line
@@ -2811,35 +2811,25 @@ int sev_mem_enc_unregister_region(struct kvm *kvm,
				  struct kvm_enc_region *range)
{
	struct enc_region *region;
	int ret;

	/* If kvm is mirroring encryption context it isn't responsible for it */
	if (is_mirroring_enc_context(kvm))
		return -EINVAL;

	mutex_lock(&kvm->lock);
	guard(mutex)(&kvm->lock);

	if (!sev_guest(kvm)) {
		ret = -ENOTTY;
		goto failed;
	}
	if (!sev_guest(kvm))
		return -ENOTTY;

	region = find_enc_region(kvm, range);
	if (!region) {
		ret = -EINVAL;
		goto failed;
	}
	if (!region)
		return -EINVAL;

	sev_writeback_caches(kvm);

	__unregister_enc_region_locked(kvm, region);

	mutex_unlock(&kvm->lock);
	return 0;

failed:
	mutex_unlock(&kvm->lock);
	return ret;
}

int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)