[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[for-5.2 v4 06/10] host trust limitation: Add Error ** to HostTrustLimit
From: |
David Gibson |
Subject: |
[for-5.2 v4 06/10] host trust limitation: Add Error ** to HostTrustLimitation::kvm_init |
Date: |
Fri, 24 Jul 2020 12:57:40 +1000 |
This allows failures to be reported richly and idiomatically.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/kvm/kvm-all.c | 4 +++-
include/exec/host-trust-limitation.h | 2 +-
target/i386/sev.c | 31 ++++++++++++++--------------
3 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 4b6402c12c..3f98c6be7c 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2164,9 +2164,11 @@ static int kvm_init(MachineState *ms)
if (ms->htl) {
HostTrustLimitationClass *htlc =
HOST_TRUST_LIMITATION_GET_CLASS(ms->htl);
+ Error *local_err = NULL;
- ret = htlc->kvm_init(ms->htl);
+ ret = htlc->kvm_init(ms->htl, &local_err);
if (ret < 0) {
+ error_report_err(local_err);
goto err;
}
}
diff --git a/include/exec/host-trust-limitation.h
b/include/exec/host-trust-limitation.h
index fc30ea3f78..d93b537280 100644
--- a/include/exec/host-trust-limitation.h
+++ b/include/exec/host-trust-limitation.h
@@ -30,7 +30,7 @@
typedef struct HostTrustLimitationClass {
InterfaceClass parent;
- int (*kvm_init)(HostTrustLimitation *);
+ int (*kvm_init)(HostTrustLimitation *, Error **);
int (*encrypt_data)(HostTrustLimitation *, uint8_t *, uint64_t);
} HostTrustLimitationClass;
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 8e3c9dcc2c..0d06976da5 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -626,7 +626,7 @@ sev_vm_state_change(void *opaque, int running, RunState
state)
}
}
-static int sev_kvm_init(HostTrustLimitation *htl)
+static int sev_kvm_init(HostTrustLimitation *htl, Error **errp)
{
SevGuestState *sev = SEV_GUEST(htl);
char *devname;
@@ -648,14 +648,14 @@ static int sev_kvm_init(HostTrustLimitation *htl)
host_cbitpos = ebx & 0x3f;
if (host_cbitpos != sev->cbitpos) {
- error_report("%s: cbitpos check failed, host '%d' requested '%d'",
- __func__, host_cbitpos, sev->cbitpos);
+ error_setg(errp, "%s: cbitpos check failed, host '%d' requested '%d'",
+ __func__, host_cbitpos, sev->cbitpos);
goto err;
}
if (sev->reduced_phys_bits < 1) {
- error_report("%s: reduced_phys_bits check failed, it should be >=1,"
- " requested '%d'", __func__, sev->reduced_phys_bits);
+ error_setg(errp, "%s: reduced_phys_bits check failed, it should be
>=1,"
+ " requested '%d'", __func__, sev->reduced_phys_bits);
goto err;
}
@@ -664,20 +664,19 @@ static int sev_kvm_init(HostTrustLimitation *htl)
devname = object_property_get_str(OBJECT(sev), "sev-device", NULL);
sev->sev_fd = open(devname, O_RDWR);
if (sev->sev_fd < 0) {
- error_report("%s: Failed to open %s '%s'", __func__,
- devname, strerror(errno));
- }
- g_free(devname);
- if (sev->sev_fd < 0) {
+ error_setg(errp, "%s: Failed to open %s '%s'", __func__,
+ devname, strerror(errno));
+ g_free(devname);
goto err;
}
+ g_free(devname);
ret = sev_platform_ioctl(sev->sev_fd, SEV_PLATFORM_STATUS, &status,
&fw_error);
if (ret) {
- error_report("%s: failed to get platform status ret=%d "
- "fw_error='%d: %s'", __func__, ret, fw_error,
- fw_error_to_str(fw_error));
+ error_setg(errp, "%s: failed to get platform status ret=%d "
+ "fw_error='%d: %s'", __func__, ret, fw_error,
+ fw_error_to_str(fw_error));
goto err;
}
sev->build_id = status.build;
@@ -687,14 +686,14 @@ static int sev_kvm_init(HostTrustLimitation *htl)
trace_kvm_sev_init();
ret = sev_ioctl(sev->sev_fd, KVM_SEV_INIT, NULL, &fw_error);
if (ret) {
- error_report("%s: failed to initialize ret=%d fw_error=%d '%s'",
- __func__, ret, fw_error, fw_error_to_str(fw_error));
+ error_setg(errp, "%s: failed to initialize ret=%d fw_error=%d '%s'",
+ __func__, ret, fw_error, fw_error_to_str(fw_error));
goto err;
}
ret = sev_launch_start(sev);
if (ret) {
- error_report("%s: failed to create encryption context", __func__);
+ error_setg(errp, "%s: failed to create encryption context", __func__);
goto err;
}
--
2.26.2
- [for-5.2 v4 00/10] Generalize memory encryption models, David Gibson, 2020/07/23
- [for-5.2 v4 02/10] host trust limitation: Handle memory encryption via interface, David Gibson, 2020/07/23
- [for-5.2 v4 04/10] host trust limitation: Rework the "memory-encryption" property, David Gibson, 2020/07/23
- [for-5.2 v4 06/10] host trust limitation: Add Error ** to HostTrustLimitation::kvm_init,
David Gibson <=
- [for-5.2 v4 07/10] spapr: Add PEF based host trust limitation, David Gibson, 2020/07/23
- [for-5.2 v4 03/10] host trust limitation: Move side effect out of machine_set_memory_encryption(), David Gibson, 2020/07/23
- [for-5.2 v4 01/10] host trust limitation: Introduce new host trust limitation interface, David Gibson, 2020/07/23
- [for-5.2 v4 10/10] s390: Recognize host-trust-limitation option, David Gibson, 2020/07/23
- [for-5.2 v4 09/10] host trust limitation: Alter virtio default properties for protected guests, David Gibson, 2020/07/23
- [for-5.2 v4 08/10] spapr: PEF: block migration, David Gibson, 2020/07/23
- [for-5.2 v4 05/10] host trust limitation: Decouple kvm_memcrypt_*() helpers from KVM, David Gibson, 2020/07/23