SHA256
1
0
forked from pool/qemu
qemu/0069-sev-i386-add-support-to-query-PLATF.patch

76 lines
2.0 KiB
Diff

From fea1c51414bedfc61e5ee31b15e58d638acee4fe Mon Sep 17 00:00:00 2001
From: Brijesh Singh <brijesh.singh@amd.com>
Date: Thu, 15 Feb 2018 09:03:24 -0600
Subject: [PATCH] sev/i386: add support to query PLATFORM_STATUS command
The command is used to query the SEV API version and build id.
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
[BR: FATE#322124]
Signed-off-by: Bruce Rogers <brogers@suse.com>
---
target/i386/sev.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 1fbc3beb16..e3236f5bb7 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -21,6 +21,9 @@
#include "trace.h"
#include "qapi-event.h"
+#include <sys/ioctl.h>
+#include <linux/psp-sev.h>
+
#define DEFAULT_GUEST_POLICY 0x1 /* disable debug */
#define DEFAULT_SEV_DEVICE "/dev/sev"
#define GUEST_POLICY_DBG_BIT 0x1
@@ -84,6 +87,22 @@ sev_ioctl(int cmd, void *data, int *error)
return r;
}
+static int
+sev_platform_ioctl(int cmd, void *data, int *error)
+{
+ int r;
+ struct sev_issue_cmd arg;
+
+ arg.cmd = cmd;
+ arg.data = (unsigned long)data;
+ r = ioctl(sev_fd, SEV_ISSUE_CMD, &arg);
+ if (error) {
+ *error = arg.error;
+ }
+
+ return r;
+}
+
static const char *
fw_error_to_str(int code)
{
@@ -399,6 +418,20 @@ sev_enabled(void)
void
sev_get_fw_version(uint8_t *major, uint8_t *minor, uint8_t *build)
{
+ struct sev_user_data_status status = {};
+ int r, err;
+
+ r = sev_platform_ioctl(SEV_PLATFORM_STATUS, &status, &err);
+ if (r) {
+ error_report("%s: failed to get platform status ret=%d"
+ "fw_error='%d: %s'", __func__, r, err,
+ fw_error_to_str(err));
+ return;
+ }
+
+ *major = status.api_major;
+ *minor = status.api_minor;
+ *build = status.build;
}
void