diff mbox

[RFC,v1,24/28] KVM: SVM: add SEV_LAUNCH_FINISH command

Message ID 147190853894.9523.16890031242057232592.stgit@brijesh-build-machine (mailing list archive)
State New, archived
Headers show

Commit Message

Brijesh Singh Aug. 22, 2016, 11:28 p.m. UTC
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@amd.com>
---
 arch/x86/kvm/svm.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Paolo Bonzini Oct. 13, 2016, 11:16 a.m. UTC | #1
On 23/08/2016 01:28, Brijesh Singh wrote:
> +
> +	/* 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);
> +

Do you need another call to sev_init_vmcb here?

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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(&params, 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;
 	}