Skip to contentSkip to conversation

target/i386/sev: Fix a segfault in sev_kvm_init

PATCH In review Srikanth Aithal 3 participants 3 messages Jan 4, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386/sev: Fix a segfault in sev_kvm_init

Propogate error code using errp in sev_kvm_init.

Before fix:
qemu-system-x86_64: sev_kvm_init: guest policy requires SEV-ES, but host SEV-ES support unavailable
27747 Segmentation fault (core dumped)

After fix:
qemu-system-x86_64: sev_kvm_init: guest policy requires SEV-ES, but host SEV-ES support unavailable
qemu-system-x86_64: failed to initialize kvm: Operation not permitted

While at it, also fix two more locations.

---
 target/i386/sev.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
target/i386/sev.c +5 -4
index 9a71246682..c0a4d5e535 100644
@@ -922,7 +922,8 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
 
     ret = ram_block_discard_disable(true);
     if (ret) {
-        error_report("%s: cannot disable RAM discard", __func__);
+        error_setg(errp, "%s: cannot disable "
+                     "RAM discard", __func__);
         return -1;
     }
 
@@ -979,13 +980,13 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
 
     if (sev_es_enabled()) {
         if (!kvm_kernel_irqchip_allowed()) {
-            error_report("%s: SEV-ES guests require in-kernel irqchip support",
-                         __func__);
+            error_setg(errp, "%s: SEV-ES guests require in-kernel "
+                         "irqchip support", __func__);
             goto err;
         }
 
         if (!(status.flags & SEV_STATUS_FLAGS_CONFIG_ES)) {
-            error_report("%s: guest policy requires SEV-ES, but "
+            error_setg(errp, "%s: guest policy requires SEV-ES, but "
                          "host SEV-ES support unavailable",
                          __func__);
             goto err;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Srikanth Aithal

Propogate error code using errp in sev_kvm_init.

Before fix:
qemu-system-x86_64: sev_kvm_init: guest policy requires SEV-ES, but host SEV-ES support unavailable
27747 Segmentation fault (core dumped)

After fix:
qemu-system-x86_64: sev_kvm_init: guest policy requires SEV-ES, but host SEV-ES support unavailable
qemu-system-x86_64: failed to initialize kvm: Operation not permitted

Quoted 7 lines

While at it, also fix two more locations.

---
  target/i386/sev.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Srikanth Aithal
Quoted 17 lines · Srikanth Aithal

Date: Thu, 4 Jan 2024 16:18:20 +0530
From: Srikanth Aithal <[email protected]>
Subject: [PATCH] target/i386/sev: Fix a segfault in sev_kvm_init
X-Mailer: git-send-email 2.34.1

Propogate error code using errp in sev_kvm_init.

Before fix:
qemu-system-x86_64: sev_kvm_init: guest policy requires SEV-ES, but host SEV-ES support unavailable
27747 Segmentation fault (core dumped)

After fix:
qemu-system-x86_64: sev_kvm_init: guest policy requires SEV-ES, but host SEV-ES support unavailable
qemu-system-x86_64: failed to initialize kvm: Operation not permitted

Quoted 7 lines

While at it, also fix two more locations.

---
 target/i386/sev.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
Quoted 36 lines
target/i386/sev.c +5 -4
index 9a71246682..c0a4d5e535 100644
@@ -922,7 +922,8 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
 
     ret = ram_block_discard_disable(true);
     if (ret) {
-        error_report("%s: cannot disable RAM discard", __func__);
+        error_setg(errp, "%s: cannot disable "
+                     "RAM discard", __func__);
         return -1;
     }
 
@@ -979,13 +980,13 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
 
     if (sev_es_enabled()) {
         if (!kvm_kernel_irqchip_allowed()) {
-            error_report("%s: SEV-ES guests require in-kernel irqchip support",
-                         __func__);
+            error_setg(errp, "%s: SEV-ES guests require in-kernel "
+                         "irqchip support", __func__);
             goto err;
         }
 
         if (!(status.flags & SEV_STATUS_FLAGS_CONFIG_ES)) {
-            error_report("%s: guest policy requires SEV-ES, but "
+            error_setg(errp, "%s: guest policy requires SEV-ES, but "
                          "host SEV-ES support unavailable",
                          __func__);
             goto err;
Signature · 1 line
2.34.1