mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 07:03:28 -04:00
KVM: SEV: use mutex guard in snp_handle_guest_req()
Simplify the error paths in snp_handle_guest_req() by using a mutex guard, allowing early return instead of using gotos. Signed-off-by: Carlos López <clopez@suse.de> Link: https://patch.msgid.link/20260120201013.3931334-8-clopez@suse.de Link: https://patch.msgid.link/20260310234829.2608037-20-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
committed by
Sean Christopherson
parent
84841f3941
commit
f09b7f4af9
@@ -4171,12 +4171,10 @@ static int snp_handle_guest_req(struct vcpu_svm *svm, gpa_t req_gpa, gpa_t resp_
|
||||
if (!is_sev_snp_guest(&svm->vcpu))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&sev->guest_req_mutex);
|
||||
guard(mutex)(&sev->guest_req_mutex);
|
||||
|
||||
if (kvm_read_guest(kvm, req_gpa, sev->guest_req_buf, PAGE_SIZE)) {
|
||||
ret = -EIO;
|
||||
goto out_unlock;
|
||||
}
|
||||
if (kvm_read_guest(kvm, req_gpa, sev->guest_req_buf, PAGE_SIZE))
|
||||
return -EIO;
|
||||
|
||||
data.gctx_paddr = __psp_pa(sev->snp_context);
|
||||
data.req_paddr = __psp_pa(sev->guest_req_buf);
|
||||
@@ -4189,21 +4187,16 @@ static int snp_handle_guest_req(struct vcpu_svm *svm, gpa_t req_gpa, gpa_t resp_
|
||||
*/
|
||||
ret = sev_issue_cmd(kvm, SEV_CMD_SNP_GUEST_REQUEST, &data, &fw_err);
|
||||
if (ret && !fw_err)
|
||||
goto out_unlock;
|
||||
return ret;
|
||||
|
||||
if (kvm_write_guest(kvm, resp_gpa, sev->guest_resp_buf, PAGE_SIZE)) {
|
||||
ret = -EIO;
|
||||
goto out_unlock;
|
||||
}
|
||||
if (kvm_write_guest(kvm, resp_gpa, sev->guest_resp_buf, PAGE_SIZE))
|
||||
return -EIO;
|
||||
|
||||
/* No action is requested *from KVM* if there was a firmware error. */
|
||||
svm_vmgexit_no_action(svm, SNP_GUEST_ERR(0, fw_err));
|
||||
|
||||
ret = 1; /* resume guest */
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&sev->guest_req_mutex);
|
||||
return ret;
|
||||
/* resume guest */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int snp_req_certs_err(struct vcpu_svm *svm, u32 vmm_error)
|
||||
|
||||
Reference in New Issue
Block a user