[PATCH v7 24/26] sev: 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: kvm@xxxxxxxxxxxxxxx
Signed-off-by: Brijesh Singh <brijesh.singh@xxxxxxx>
---
 accel/kvm/sev.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/accel/kvm/sev.c b/accel/kvm/sev.c
index 7b57575e2f93..186834364eed 100644
--- a/accel/kvm/sev.c
+++ b/accel/kvm/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
@@ -91,6 +94,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)
 {
@@ -380,6 +399,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