Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2128215yba; Mon, 15 Apr 2019 05:38:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyCu4YEwF2SzfnWpCaZcJtWWdnmbZtz23uHghLJIJsCJpHyk++w1QS6SBBM3pjoeTh+DcaT X-Received: by 2002:a62:205c:: with SMTP id g89mr75177911pfg.34.1555331887464; Mon, 15 Apr 2019 05:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555331887; cv=none; d=google.com; s=arc-20160816; b=JCND3KX5bxb7QC15dora0+g6OIMr1s/sM9u9yT647GEAlULFvNYC67EYUPOg8iRJ3V 1QKwC8HoRT8yh+7SlforM6FjQtRo6rFEVxp9TbYsIpoOd79OnE8FyRTA5eDlxMY2CVu2 R0OoDYX8i8huFompr+gL784VWIW5fp5E+FyR1XE9oiFH68+3fUlZWACVJUmd7FuE9ENs aVuZFUQVf6m/7XUZfKIUdtgMBxWlgis3501unJzJbxkruj4yUr1xLmUTNgZ7DwSoNqPK G0eifZAFclSxIz1vbFiuj4pDmOt0jx/TicvejZIbgwYPBnSKlvt2BFcMKa6z8LWaJPfp HOsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=/VUHw3lcqfp7H9+NcdZIMV5Y5lx0/nvmYmMsWFRqk08=; b=yeNrHE8YUQHKTchLigH3Ucuo+vf7/UChdNvO6sYMpVfM4GdlmbKosawx7V/ZlBlOwE rwx0SkKYfRTvST8prO6gkdB0YIedaLzg59h60Nrubno8JaluWPoXF3JNcy8PDDMS+f4F PDA+deg4HU4I9LJ9smc4oH2fNi3nN25cItBRaGoUKie+Y28mu5UFe+i1DCiw7zpBHtke JupMV2fIzazil6ZQTIQ8qhUi0ar9mXZ+1RoImJnc+Os/Dui4Q3dYxpOsPd1G+cEndolj iUfY97GqzRGk/Xdw8pdKbq7MOACNZAmk10oyiShFj5Kj+omEihzlH2QYupkPqncIqndN beHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hygon.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z10si44405135pgi.233.2019.04.15.05.37.51; Mon, 15 Apr 2019 05:38:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hygon.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727486AbfDOMgn (ORCPT + 99 others); Mon, 15 Apr 2019 08:36:43 -0400 Received: from [110.188.70.11] ([110.188.70.11]:28988 "EHLO spam1.hygon.cn" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727440AbfDOMgn (ORCPT ); Mon, 15 Apr 2019 08:36:43 -0400 Received: from spam1.hygon.cn (localhost [127.0.0.2] (may be forged)) by spam1.hygon.cn with ESMTP id x3FCAaXJ027058; Mon, 15 Apr 2019 20:10:36 +0800 (GMT-8) (envelope-from fenghao@hygon.cn) Received: from MK-FE.hygon.cn ([172.23.18.61]) by spam1.hygon.cn with ESMTP id x3FC7ofR026700; Mon, 15 Apr 2019 20:07:50 +0800 (GMT-8) (envelope-from fenghao@hygon.cn) Received: from cncheex02.Hygon.cn ([172.23.18.12]) by MK-FE.hygon.cn with ESMTP id x3FC7Ix1022141; Mon, 15 Apr 2019 20:07:18 +0800 (GMT-8) (envelope-from fenghao@hygon.cn) Received: from harry-Inspiron-5675.higon.com (172.23.18.44) by cncheex02.Hygon.cn (172.23.18.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1466.3; Mon, 15 Apr 2019 20:07:48 +0800 From: Hao Feng To: "'Joerg Roedel '" , "'Paolo Bonzini '" , =?UTF-8?q?=27=20Radim=20Kr=C4=8Dm=C3=A1=C5=99=20=27?= , "'Thomas Gleixner '" , "'Ingo Molnar '" , "'Borislav Petkov '" , "' H. Peter Anvin '" CC: "'Zhaohui Du '" , "'Zhiwei Ying '" , "'Wen Pu '" , Hao Feng , , , Subject: [PATCH 5/6] KVM: SVM: Add support for KVM_SEV_GM_GET_DIGEST command Date: Mon, 15 Apr 2019 20:04:27 +0800 Message-ID: <1555329868-17895-6-git-send-email-fenghao@hygon.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1555329868-17895-1-git-send-email-fenghao@hygon.cn> References: <1555329868-17895-1-git-send-email-fenghao@hygon.cn> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.23.18.44] X-ClientProxiedBy: cncheex02.Hygon.cn (172.23.18.12) To cncheex02.Hygon.cn (172.23.18.12) X-MAIL: spam1.hygon.cn x3FC7ofR026700 X-DNSRBL: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The command is used to get the key digest from SEV firmware, guest owner will check the key digest to see if the key negotiation is successful or not. Signed-off-by: Hao Feng Signed-off-by: Pu Wen --- arch/x86/kvm/svm.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index e0a791c..f8e7042 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -6946,6 +6946,75 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_gm_get_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_get_digest *data; + struct kvm_sev_gm_get_digest params; + void __user *p = NULL; + void *blob = NULL; + 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; + + /* User wants to query the blob length */ + if (!params.len) + goto cmd; + + p = (void __user *)(uintptr_t)params.uaddr; + if (p) { + if (params.len > SEV_FW_BLOB_MAX_SIZE) { + ret = -EINVAL; + goto e_free; + } + + ret = -ENOMEM; + blob = kmalloc(params.len, GFP_KERNEL); + if (!blob) + goto e_free; + + data->address = __psp_pa(blob); + data->len = params.len; + } + +cmd: + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_GM_GET_DIGEST, data, &argp->error); + + /* + * If we query the session length, FW responded with expected data. + */ + if (!params.len) + goto done; + + if (ret) + goto e_free_blob; + + if (blob) { + if (copy_to_user(p, blob, params.len)) + ret = -EFAULT; + } + +done: + params.len = data->len; + if (copy_to_user(digest, ¶ms, sizeof(params))) + ret = -EFAULT; +e_free_blob: + kfree(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; @@ -6987,6 +7056,9 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_LAUNCH_SECRET: r = sev_launch_secret(kvm, &sev_cmd); break; + case KVM_SEV_GM_GET_DIGEST: + r = sev_gm_get_digest(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; -- 2.7.4