Thread (67 messages) 67 messages, 6 authors, 2016-10-18
STALE3534d
Revisions (9)
  1. v1 [diff vs current]
  2. v1 current
  3. v3 [diff vs current]
  4. v4 [diff vs current]
  5. v5 [diff vs current]
  6. v6 [diff vs current]
  7. v7 [diff vs current]
  8. v8 [diff vs current]
  9. v9 [diff vs current]

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

From: Brijesh Singh <hidden>
Date: 2016-08-22 23:29:13
Also in: kvm, linux-efi, lkml
Subsystem: kernel virtual machine for x86 (kvm/x86), the rest, x86 architecture (32-bit and 64-bit) · Maintainers: Sean Christopherson, Paolo Bonzini, Linus Torvalds, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help