sev: Add Error ** to sev_kvm_init()

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>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
This commit is contained in:
David Gibson 2020-06-04 14:18:52 +10:00
parent e0292d7c62
commit c9f5aaa6bc
4 changed files with 20 additions and 19 deletions

View file

@ -2185,9 +2185,11 @@ static int kvm_init(MachineState *ms)
* encryption context. * encryption context.
*/ */
if (ms->cgs) { if (ms->cgs) {
Error *local_err = NULL;
/* FIXME handle mechanisms other than SEV */ /* FIXME handle mechanisms other than SEV */
ret = sev_kvm_init(ms->cgs); ret = sev_kvm_init(ms->cgs, &local_err);
if (ret < 0) { if (ret < 0) {
error_report_err(local_err);
goto err; goto err;
} }
} }

View file

@ -15,7 +15,7 @@
#include "qemu-common.h" #include "qemu-common.h"
#include "sysemu/sev.h" #include "sysemu/sev.h"
int sev_kvm_init(ConfidentialGuestSupport *cgs) int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
{ {
/* SEV can't be selected if it's not compiled */ /* SEV can't be selected if it's not compiled */
g_assert_not_reached(); g_assert_not_reached();

View file

@ -16,7 +16,7 @@
#include "sysemu/kvm.h" #include "sysemu/kvm.h"
int sev_kvm_init(ConfidentialGuestSupport *cgs); int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp); int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
int sev_inject_launch_secret(const char *hdr, const char *secret, int sev_inject_launch_secret(const char *hdr, const char *secret,
uint64_t gpa, Error **errp); uint64_t gpa, Error **errp);

View file

@ -662,7 +662,7 @@ sev_vm_state_change(void *opaque, int running, RunState state)
} }
} }
int sev_kvm_init(ConfidentialGuestSupport *cgs) int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
{ {
SevGuestState *sev = SEV_GUEST(cgs); SevGuestState *sev = SEV_GUEST(cgs);
char *devname; char *devname;
@ -684,13 +684,13 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs)
host_cbitpos = ebx & 0x3f; host_cbitpos = ebx & 0x3f;
if (host_cbitpos != sev->cbitpos) { if (host_cbitpos != sev->cbitpos) {
error_report("%s: cbitpos check failed, host '%d' requested '%d'", error_setg(errp, "%s: cbitpos check failed, host '%d' requested '%d'",
__func__, host_cbitpos, sev->cbitpos); __func__, host_cbitpos, sev->cbitpos);
goto err; goto err;
} }
if (sev->reduced_phys_bits < 1) { if (sev->reduced_phys_bits < 1) {
error_report("%s: reduced_phys_bits check failed, it should be >=1," error_setg(errp, "%s: reduced_phys_bits check failed, it should be >=1,"
" requested '%d'", __func__, sev->reduced_phys_bits); " requested '%d'", __func__, sev->reduced_phys_bits);
goto err; goto err;
} }
@ -700,18 +700,17 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs)
devname = object_property_get_str(OBJECT(sev), "sev-device", NULL); devname = object_property_get_str(OBJECT(sev), "sev-device", NULL);
sev->sev_fd = open(devname, O_RDWR); sev->sev_fd = open(devname, O_RDWR);
if (sev->sev_fd < 0) { if (sev->sev_fd < 0) {
error_report("%s: Failed to open %s '%s'", __func__, error_setg(errp, "%s: Failed to open %s '%s'", __func__,
devname, strerror(errno)); devname, strerror(errno));
}
g_free(devname); g_free(devname);
if (sev->sev_fd < 0) {
goto err; goto err;
} }
g_free(devname);
ret = sev_platform_ioctl(sev->sev_fd, SEV_PLATFORM_STATUS, &status, ret = sev_platform_ioctl(sev->sev_fd, SEV_PLATFORM_STATUS, &status,
&fw_error); &fw_error);
if (ret) { if (ret) {
error_report("%s: failed to get platform status ret=%d " error_setg(errp, "%s: failed to get platform status ret=%d "
"fw_error='%d: %s'", __func__, ret, fw_error, "fw_error='%d: %s'", __func__, ret, fw_error,
fw_error_to_str(fw_error)); fw_error_to_str(fw_error));
goto err; goto err;
@ -723,14 +722,14 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs)
trace_kvm_sev_init(); trace_kvm_sev_init();
ret = sev_ioctl(sev->sev_fd, KVM_SEV_INIT, NULL, &fw_error); ret = sev_ioctl(sev->sev_fd, KVM_SEV_INIT, NULL, &fw_error);
if (ret) { if (ret) {
error_report("%s: failed to initialize ret=%d fw_error=%d '%s'", error_setg(errp, "%s: failed to initialize ret=%d fw_error=%d '%s'",
__func__, ret, fw_error, fw_error_to_str(fw_error)); __func__, ret, fw_error, fw_error_to_str(fw_error));
goto err; goto err;
} }
ret = sev_launch_start(sev); ret = sev_launch_start(sev);
if (ret) { if (ret) {
error_report("%s: failed to create encryption context", __func__); error_setg(errp, "%s: failed to create encryption context", __func__);
goto err; goto err;
} }