[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <147190853894.9523.16890031242057232592.stgit@brijesh-build-machine>
Date: Mon, 22 Aug 2016 19:28:59 -0400
From: Brijesh Singh <brijesh.singh@....com>
To: <simon.guinot@...uanux.org>, <linux-efi@...r.kernel.org>,
<brijesh.singh@....com>, <kvm@...r.kernel.org>,
<rkrcmar@...hat.com>, <matt@...eblueprint.co.uk>,
<linus.walleij@...aro.org>, <linux-mm@...ck.org>,
<paul.gortmaker@...driver.com>, <hpa@...or.com>,
<dan.j.williams@...el.com>, <aarcange@...hat.com>,
<sfr@...b.auug.org.au>, <andriy.shevchenko@...ux.intel.com>,
<herbert@...dor.apana.org.au>, <bhe@...hat.com>,
<xemul@...allels.com>, <joro@...tes.org>, <x86@...nel.org>,
<mingo@...hat.com>, <msalter@...hat.com>,
<ross.zwisler@...ux.intel.com>, <bp@...e.de>, <dyoung@...hat.com>,
<thomas.lendacky@....com>, <jroedel@...e.de>,
<keescook@...omium.org>, <toshi.kani@....com>,
<mathieu.desnoyers@...icios.com>, <devel@...uxdriverproject.org>,
<tglx@...utronix.de>, <mchehab@...nel.org>,
<iamjoonsoo.kim@....com>, <labbott@...oraproject.org>,
<tony.luck@...el.com>, <alexandre.bounine@....com>,
<kuleshovmail@...il.com>, <linux-kernel@...r.kernel.org>,
<mcgrof@...nel.org>, <linux-crypto@...r.kernel.org>,
<pbonzini@...hat.com>, <akpm@...ux-foundation.org>,
<davem@...emloft.net>
Subject: [RFC PATCH v1 24/28] KVM: SVM: add SEV_LAUNCH_FINISH command
The command is used for finializing the guest launch into SEV mode.
For more information see [1], section 6.3
[1] http://support.amd.com/TechDocs/55766_SEV-KM%20API_Spec.pdf
Signed-off-by: Brijesh Singh <brijesh.singh@....com>
---
arch/x86/kvm/svm.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index c78bdc6..60cc0f7 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -5497,6 +5497,79 @@ err_1:
return ret;
}
+static int sev_launch_finish(struct kvm *kvm,
+ struct kvm_sev_launch_finish __user *argp,
+ int *psp_ret)
+{
+ int i, ret;
+ void *mask = NULL;
+ int buffer_len, len;
+ struct kvm_vcpu *vcpu;
+ struct psp_data_launch_finish *finish;
+ struct kvm_sev_launch_finish params;
+
+ if (!kvm_sev_guest())
+ return -EINVAL;
+
+ /* Get the parameters from the user */
+ if (copy_from_user(¶ms, argp, sizeof(*argp)))
+ return -EFAULT;
+
+ buffer_len = sizeof(*finish) + (sizeof(u64) * params.vcpu_count);
+ finish = kzalloc(buffer_len, GFP_KERNEL);
+ if (!finish)
+ return -ENOMEM;
+
+ /* copy the vcpu mask from user */
+ if (params.vcpu_mask_length && params.vcpu_mask_addr) {
+ ret = -ENOMEM;
+ mask = (void *) get_zeroed_page(GFP_KERNEL);
+ if (!mask)
+ goto err_1;
+
+ len = min_t(size_t, PAGE_SIZE, params.vcpu_mask_length);
+ ret = -EFAULT;
+ if (copy_from_user(mask, (uint8_t*)params.vcpu_mask_addr, len))
+ goto err_2;
+ finish->vcpus.state_mask_addr = __psp_pa(mask);
+ }
+
+ finish->handle = kvm_sev_handle();
+ finish->hdr.buffer_len = buffer_len;
+ finish->vcpus.state_count = params.vcpu_count;
+ finish->vcpus.state_length = params.vcpu_length;
+ kvm_for_each_vcpu(i, vcpu, kvm) {
+ finish->vcpus.state_addr[i] =
+ to_svm(vcpu)->vmcb_pa | sme_me_mask;
+ if (i == params.vcpu_count)
+ break;
+ }
+
+ /* launch finish */
+ ret = psp_guest_launch_finish(finish, psp_ret);
+ if (ret) {
+ printk(KERN_ERR "SEV: LAUNCH_FINISH ret=%d (%#010x)\n",
+ ret, *psp_ret);
+ goto err_2;
+ }
+
+ /* Iterate through each vcpus and set SEV KVM_SEV_FEATURE bit in
+ * KVM_CPUID_FEATURE to indicate that SEV is enabled on this vcpu
+ */
+ kvm_for_each_vcpu(i, vcpu, kvm)
+ svm_cpuid_update(vcpu);
+
+ /* copy the measurement for user */
+ if (copy_to_user(argp->measurement, finish->measurement, 32))
+ ret = -EFAULT;
+
+err_2:
+ free_page((unsigned long)mask);
+err_1:
+ kfree(finish);
+ return ret;
+}
+
static int amd_sev_issue_cmd(struct kvm *kvm,
struct kvm_sev_issue_cmd __user *user_data)
{
@@ -5517,6 +5590,11 @@ static int amd_sev_issue_cmd(struct kvm *kvm,
&arg.ret_code);
break;
}
+ case KVM_SEV_LAUNCH_FINISH: {
+ r = sev_launch_finish(kvm, (void *)arg.opaque,
+ &arg.ret_code);
+ break;
+ }
default:
break;
}
Powered by blists - more mailing lists