The command is used to query the current SEV guest status. We use this
command to query the guest policy for QMP query-sev command.

Cc: Paolo Bonzini <pbonz...@redhat.com>
Cc: Richard Henderson <r...@twiddle.net>
Cc: Eduardo Habkost <ehabk...@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.si...@amd.com>
---
 target/i386/sev.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/target/i386/sev.c b/target/i386/sev.c
index 6df5db3eb2d7..2713e3591d40 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -418,6 +418,22 @@ sev_get_fw_version(uint8_t *major, uint8_t *minor, uint8_t 
*build)
 void
 sev_get_policy(uint32_t *policy)
 {
+    struct kvm_sev_guest_status status = {};
+    int r, err;
+
+    if (current_sev_guest_state == SEV_STATE_UNINIT) {
+        return;
+    }
+
+    r = sev_ioctl(KVM_SEV_GUEST_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;
+    }
+
+    *policy = status.policy;
 }
 
 static int
-- 
2.14.3


Reply via email to