[PATCH v9 24/29] sev/i386: add support to query PLATFORM_STATUS command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The command is used to query the SEV API version and build id.

Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Cc: Richard Henderson <rth@xxxxxxxxxxx>
Cc: Eduardo Habkost <ehabkost@xxxxxxxxxx>
Signed-off-by: Brijesh Singh <brijesh.singh@xxxxxxx>
---
 target/i386/sev.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/target/i386/sev.c b/target/i386/sev.c
index 1fbc3beb1655..e3236f5bb7b6 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
-- 
2.14.3




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux