yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-target-i386-sev-provide-proper-error-reporting-for-q.patch

be904d
From 8789f2662c6ddacc5472a803d253b94d93c6e9f0 Mon Sep 17 00:00:00 2001
be904d
From: Paolo Bonzini <pbonzini@redhat.com>
be904d
Date: Fri, 31 Jul 2020 18:08:34 -0400
be904d
Subject: [PATCH 2/4] target/i386: sev: provide proper error reporting for
be904d
 query-sev-capabilities
be904d
MIME-Version: 1.0
be904d
Content-Type: text/plain; charset=UTF-8
be904d
Content-Transfer-Encoding: 8bit
be904d
be904d
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
be904d
Message-id: <20200731180835.86786-2-pbonzini@redhat.com>
be904d
Patchwork-id: 98123
be904d
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 1/2] target/i386: sev: provide proper error reporting for query-sev-capabilities
be904d
Bugzilla: 1689341
be904d
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
be904d
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
be904d
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
be904d
be904d
The query-sev-capabilities was reporting errors through error_report;
be904d
change it to use Error** so that the cause of the failure is clearer.
be904d
be904d
Reviewed-by: Eric Blake <eblake@redhat.com>
be904d
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
be904d
Cherry picked from commit e4f6278557148151e77260b872b41bcd7ceb4737
be904d
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
be904d
---
be904d
 target/i386/monitor.c  | 10 +---------
be904d
 target/i386/sev-stub.c |  3 ++-
be904d
 target/i386/sev.c      | 18 +++++++++---------
be904d
 target/i386/sev_i386.h |  2 +-
be904d
 4 files changed, 13 insertions(+), 20 deletions(-)
be904d
be904d
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
be904d
index 9fb4d641d5..cfd8075e4f 100644
be904d
--- a/target/i386/monitor.c
be904d
+++ b/target/i386/monitor.c
be904d
@@ -727,13 +727,5 @@ SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
be904d
 
be904d
 SevCapability *qmp_query_sev_capabilities(Error **errp)
be904d
 {
be904d
-    SevCapability *data;
be904d
-
be904d
-    data = sev_get_capabilities();
be904d
-    if (!data) {
be904d
-        error_setg(errp, "SEV feature is not available");
be904d
-        return NULL;
be904d
-    }
be904d
-
be904d
-    return data;
be904d
+    return sev_get_capabilities(errp);
be904d
 }
be904d
diff --git a/target/i386/sev-stub.c b/target/i386/sev-stub.c
be904d
index e5ee13309c..88e3f39a1e 100644
be904d
--- a/target/i386/sev-stub.c
be904d
+++ b/target/i386/sev-stub.c
be904d
@@ -44,7 +44,8 @@ char *sev_get_launch_measurement(void)
be904d
     return NULL;
be904d
 }
be904d
 
be904d
-SevCapability *sev_get_capabilities(void)
be904d
+SevCapability *sev_get_capabilities(Error **errp)
be904d
 {
be904d
+    error_setg(errp, "SEV is not available in this QEMU");
be904d
     return NULL;
be904d
 }
be904d
diff --git a/target/i386/sev.c b/target/i386/sev.c
be904d
index 024bb24e51..054f2d846a 100644
be904d
--- a/target/i386/sev.c
be904d
+++ b/target/i386/sev.c
be904d
@@ -453,7 +453,7 @@ sev_get_info(void)
be904d
 
be904d
 static int
be904d
 sev_get_pdh_info(int fd, guchar **pdh, size_t *pdh_len, guchar **cert_chain,
be904d
-                 size_t *cert_chain_len)
be904d
+                 size_t *cert_chain_len, Error **errp)
be904d
 {
be904d
     guchar *pdh_data = NULL;
be904d
     guchar *cert_chain_data = NULL;
be904d
@@ -464,8 +464,8 @@ sev_get_pdh_info(int fd, guchar **pdh, size_t *pdh_len, guchar **cert_chain,
be904d
     r = sev_platform_ioctl(fd, SEV_PDH_CERT_EXPORT, &export, &err;;
be904d
     if (r < 0) {
be904d
         if (err != SEV_RET_INVALID_LEN) {
be904d
-            error_report("failed to export PDH cert ret=%d fw_err=%d (%s)",
be904d
-                         r, err, fw_error_to_str(err));
be904d
+            error_setg(errp, "failed to export PDH cert ret=%d fw_err=%d (%s)",
be904d
+                       r, err, fw_error_to_str(err));
be904d
             return 1;
be904d
         }
be904d
     }
be904d
@@ -477,8 +477,8 @@ sev_get_pdh_info(int fd, guchar **pdh, size_t *pdh_len, guchar **cert_chain,
be904d
 
be904d
     r = sev_platform_ioctl(fd, SEV_PDH_CERT_EXPORT, &export, &err;;
be904d
     if (r < 0) {
be904d
-        error_report("failed to export PDH cert ret=%d fw_err=%d (%s)",
be904d
-                     r, err, fw_error_to_str(err));
be904d
+        error_setg(errp, "failed to export PDH cert ret=%d fw_err=%d (%s)",
be904d
+                   r, err, fw_error_to_str(err));
be904d
         goto e_free;
be904d
     }
be904d
 
be904d
@@ -495,7 +495,7 @@ e_free:
be904d
 }
be904d
 
be904d
 SevCapability *
be904d
-sev_get_capabilities(void)
be904d
+sev_get_capabilities(Error **errp)
be904d
 {
be904d
     SevCapability *cap = NULL;
be904d
     guchar *pdh_data = NULL;
be904d
@@ -506,13 +506,13 @@ sev_get_capabilities(void)
be904d
 
be904d
     fd = open(DEFAULT_SEV_DEVICE, O_RDWR);
be904d
     if (fd < 0) {
be904d
-        error_report("%s: Failed to open %s '%s'", __func__,
be904d
-                     DEFAULT_SEV_DEVICE, strerror(errno));
be904d
+        error_setg_errno(errp, errno, "Failed to open %s",
be904d
+                         DEFAULT_SEV_DEVICE);
be904d
         return NULL;
be904d
     }
be904d
 
be904d
     if (sev_get_pdh_info(fd, &pdh_data, &pdh_len,
be904d
-                         &cert_chain_data, &cert_chain_len)) {
be904d
+                         &cert_chain_data, &cert_chain_len, errp)) {
be904d
         goto out;
be904d
     }
be904d
 
be904d
diff --git a/target/i386/sev_i386.h b/target/i386/sev_i386.h
be904d
index 8ada9d385d..1e073342ba 100644
be904d
--- a/target/i386/sev_i386.h
be904d
+++ b/target/i386/sev_i386.h
be904d
@@ -38,7 +38,7 @@ extern SevInfo *sev_get_info(void);
be904d
 extern uint32_t sev_get_cbit_position(void);
be904d
 extern uint32_t sev_get_reduced_phys_bits(void);
be904d
 extern char *sev_get_launch_measurement(void);
be904d
-extern SevCapability *sev_get_capabilities(void);
be904d
+extern SevCapability *sev_get_capabilities(Error **errp);
be904d
 
be904d
 typedef struct QSevGuestInfo QSevGuestInfo;
be904d
 typedef struct QSevGuestInfoClass QSevGuestInfoClass;
be904d
-- 
be904d
2.27.0
be904d