The command is used to send guest owner's key digest to SEV firmware, firmware will check the key digest to see if the key negotiation is successful or not. Signed-off-by: Hao Feng <fenghao@xxxxxxxx> Signed-off-by: Pu Wen <puwen@xxxxxxxx> --- arch/x86/kvm/svm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index f8e7042..4dbdccf 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -7015,6 +7015,50 @@ static int sev_gm_get_digest(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_gm_verify_digest(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + void __user *digest = (void __user *)(uintptr_t)argp->data; + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_gm_verify_digest *data = NULL; + struct kvm_sev_gm_verify_digest params; + void *digest_blob = NULL; + int *error = &argp->error; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, digest, sizeof(params))) + return -EFAULT; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + if (params.uaddr) { + digest_blob = psp_copy_user_blob(params.uaddr, params.len); + if (IS_ERR(digest_blob)) { + ret = PTR_ERR(digest_blob); + goto e_free; + } + + data->address = __psp_pa(digest_blob); + data->len = params.len; + } + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_GM_VERIFY_DIGEST, data, error); + if (ret) + goto e_free_digest; + +e_free_digest: + kfree(digest_blob); +e_free: + kfree(data); + + return ret; +} + static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -7059,6 +7103,9 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_GM_GET_DIGEST: r = sev_gm_get_digest(kvm, &sev_cmd); break; + case KVM_SEV_GM_VERIFY_DIGEST: + r = sev_gm_verify_digest(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; -- 2.7.4