diff mbox

[RFC,v1,25/28] KVM: SVM: add KVM_SEV_GUEST_STATUS command

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

Commit Message

Brijesh Singh Aug. 22, 2016, 11:29 p.m. UTC
The command is used to query the SEV guest status.

For more information see [1], section 6.10

[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 |   41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 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
diff mbox

Patch

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 60cc0f7..63e7d15 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -5570,6 +5570,42 @@  err_1:
 	return ret;
 }
 
+static int sev_guest_status(struct kvm *kvm,
+			    struct kvm_sev_guest_status __user *argp,
+			    int *psp_ret)
+{
+	int ret;
+	struct kvm_sev_guest_status params;
+	struct psp_data_guest_status *status;
+
+	if (!kvm_sev_guest())
+		return -ENOTTY;
+
+	if (copy_from_user(&params, argp, sizeof(*argp)))
+		return -EFAULT;
+
+	status = kzalloc(sizeof(*status), GFP_KERNEL);
+	if (!status)
+		return -ENOMEM;
+
+	status->hdr.buffer_len = sizeof(*status);
+	status->handle = kvm_sev_handle();
+	ret = psp_guest_status(status, psp_ret);
+	if (ret) {
+		printk(KERN_ERR "SEV: GUEST_STATUS ret=%d (%#010x)\n",
+			ret, *psp_ret);
+		goto err_1;
+	}
+	params.policy = status->policy;
+	params.state = status->state;
+
+	if (copy_to_user(argp, &params, sizeof(*argp)))
+		ret = -EFAULT;
+err_1:
+	kfree(status);
+	return ret;
+}
+
 static int amd_sev_issue_cmd(struct kvm *kvm,
 			     struct kvm_sev_issue_cmd __user *user_data)
 {
@@ -5595,6 +5631,11 @@  static int amd_sev_issue_cmd(struct kvm *kvm,
 					&arg.ret_code);
 		break;
 	}
+	case KVM_SEV_GUEST_STATUS: {
+		r = sev_guest_status(kvm, (void *)arg.opaque,
+					&arg.ret_code);
+		break;
+	}
 	default:
 		break;
 	}