Skip to contentSkip to conversation

Nitpick at the error message's output

PATCH In review Hyman Huang 1 participant 4 messages Jan 7, 2024 – Jan 15, 2024

lore
Share & tools
lore
#2 lore raw

PATCH v2 2/2 i386/sev: Nitpick at the error message's output

In reply to Hyman Huang

The incorrect error message was produced as a result of the return number being disregarded on the sev_kvm_init failure path.

For instance, when a user's failure to launch a SEV guest is caused by an incorrect IOCTL, the following message is reported:

kvm: sev_kvm_init: failed to initialize ret=-25 fw_error=0
kvm: failed to initialize kvm: Operation not permitted

While the error message's accurate output should be:

kvm: sev_kvm_init: failed to initialize ret=-25 fw_error=0
kvm: failed to initialize kvm: Inappropriate ioctl for device

Fix this by returning the return number directly on the failure path.

Message-Id: <c5033954155dfe256f650fc9ca2084c688356317.1704469721.git.yong.huang@smartx.com>

---
 target/i386/sev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/sev.c +1 -1
index 96eff73001..3fef8cf163 100644
@@ -1023,7 +1023,7 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
 err:
     sev_guest = NULL;
     ram_block_discard_disable(false);
-    return -1;
+    return ret;
 }
 
 int
Signature · 1 line
2.39.1
#0 lore raw

v2 cover Nitpick at the error message's output

v2:
- rebase on master
- add a commit to sort the error message so that an explanation error number can be returned on all failure paths

Hyman Huang (2):
i386/sev: Sort the error message
i386/sev: Nitpick at the error message's output

 target/i386/sev.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH v2 1/2 i386/sev: Sort the error message

Prior to giving the caller the return number(in the next commit), sorting the error message:
1. report the error number on the ram_block_discard_disable failure path
2. report the error number on the syscall "open" failure path
3. report EINVAL when a prerequisite check fails or the command line is invalid

---
 target/i386/sev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
target/i386/sev.c +6 -2
index 9a71246682..96eff73001 100644
@@ -923,7 +923,7 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
     ret = ram_block_discard_disable(true);
     if (ret) {
         error_report("%s: cannot disable RAM discard", __func__);
-        return -1;
+        return ret;
     }
 
     sev_guest = sev;
@@ -940,6 +940,7 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
     if (host_cbitpos != sev->cbitpos) {
         error_setg(errp, "%s: cbitpos check failed, host '%d' requested '%d'",
                    __func__, host_cbitpos, sev->cbitpos);
+        ret = -EINVAL;
         goto err;
     }
 
@@ -952,11 +953,12 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
         error_setg(errp, "%s: reduced_phys_bits check failed,"
                    " it should be in the range of 1 to 63, requested '%d'",
                    __func__, sev->reduced_phys_bits);
+        ret = -EINVAL;
         goto err;
     }
 
     devname = object_property_get_str(OBJECT(sev), "sev-device", NULL);
-    sev->sev_fd = open(devname, O_RDWR);
+    ret = sev->sev_fd = open(devname, O_RDWR);
     if (sev->sev_fd < 0) {
         error_setg(errp, "%s: Failed to open %s '%s'", __func__,
                    devname, strerror(errno));
@@ -981,6 +983,7 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
         if (!kvm_kernel_irqchip_allowed()) {
             error_report("%s: SEV-ES guests require in-kernel irqchip support",
                          __func__);
+            ret = -EINVAL;
             goto err;
         }
 
@@ -988,6 +991,7 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
             error_report("%s: guest policy requires SEV-ES, but "
                          "host SEV-ES support unavailable",
                          __func__);
+            ret = -EINVAL;
             goto err;
         }
         cmd = KVM_SEV_ES_INIT;
Signature · 1 line
2.39.1
author
#3 lore raw
In reply to Hyman Huang

Ping

Quoted 16 lines · Hyman Huang

v2:
- rebase on master
- add a commit to sort the error message so that an explanation error number can be returned on all failure paths

Hyman Huang (2):
i386/sev: Sort the error message
i386/sev: Nitpick at the error message's output

 target/i386/sev.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

--
2.39.1

Signature · 1 line
Best regards