migration: propagate vTPM errors using Error objects
v2 cover migration: propagate vTPM errors using Error objects
Currently, when a migration of a VM with an encrypted vTPM fails on the destination host (e.g., due to a mismatch in secret values), the error message displayed on the source host is generic and unhelpful.
For example, a typical error looks like this:
"operation failed: job 'migration out' failed: Sibling indicated error 1. operation failed: job 'migration in' failed: load of migration failed:
Input/output error"
This message does not provide any specific indication of a vTPM failure. Such generic errors are logged using error_report(), which prints to the console/monitor but does not make the detailed error accessible via the QMP query-migrate command.
This series addresses the issue, by ensuring that specific TPM error messages are propagated via the QEMU Error object.
To make this possible,
- A set of functions in the call stack is changed
to incorporate an Error object as an additional parameter.
- Also, the TPM backend makes use of a new hook called post_load_with_error() that explicitly passes an Error object.
While this series focuses specifically on TPM error reporting during live migration, it lays the groundwork for broader improvements. Most methods in savevm.c that previously returned an integer now capture errors in the Error object, enabling other modules to adopt the post_load_with_error hook in the future.
One such change previously attempted:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg01727.html
The series does not necessarily have to be applied in 1 go. Each patch can be compiled and tested separately.
Resolves: https://issues.redhat.com/browse/RHEL-82826
---
Changes in v2:
- Combine the first two changes into one, focusing on passing the
Error object (errp) consistently through functions involved in
loading the VM's state. Other functions are not yet changed.
- As suggested in the review comment, add null checks for errp
before adding error messages, preventing crashes.
We also now correctly set errors when post-copy migration fails.
- In process_incoming_migration_co(), switch to error_prepend
instead of error_setg. This means we now null-check local_err in
the "fail" section before using it, preventing dereferencing issues.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]
---
Arun Menon (2):
migration: Pass Error object errp into vm state loading functions backends/tpm: Propagate vTPM error on migration failure
backends/tpm/tpm_emulator.c | 39 +++++++------ hw/display/virtio-gpu.c | 2 +- hw/pci/pci.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/spapr_vscsi.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio.c | 4 +- include/migration/vmstate.h | 3 +- migration/colo.c | 13 +++-- migration/cpr.c | 2 +- migration/migration.c | 19 ++++-- migration/savevm.c | 137 +++++++++++++++++++++++++++----------------- migration/savevm.h | 7 ++- migration/vmstate-types.c | 10 ++-- migration/vmstate.c | 44 ++++++++------ tests/unit/test-vmstate.c | 18 +++--- 18 files changed, 182 insertions(+), 128 deletions(-)
---
base-commit: 43ba160cb4bbb193560eb0d2d7decc4b5fc599fe
change-id: 20250624-propagate_tpm_error-bf4ae6c23d30
Best regards,
Signature · 1 line
Arun Menon <[email protected]>
PATCH v2 1/2 migration: Pass Error object errp into vm state loading functions
- This is an incremental step in converting vmstate loading code to report errors.
- Minimal changes to the signature and body of the following functions are done,
- vmstate_load()
- vmstate_load_state()
- vmstate_subsection_load()
- qemu_load_device_state()
- qemu_loadvm_state()
- qemu_loadvm_section_start_full()
- qemu_loadvm_section_part_end()
- qemu_loadvm_state_header()
- qemu_loadvm_state_main()
- error_report() has been replaced with error_setg(); and in places where error has been already set, error_prepend() is used to not lose information.
--- hw/display/virtio-gpu.c | 2 +- hw/pci/pci.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/spapr_vscsi.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio.c | 4 +- include/migration/vmstate.h | 2 +- migration/colo.c | 13 +++-- migration/cpr.c | 2 +- migration/migration.c | 19 ++++-- migration/savevm.c | 137 +++++++++++++++++++++++++++----------------- migration/savevm.h | 7 ++- migration/vmstate-types.c | 10 ++-- migration/vmstate.c | 40 +++++++------ tests/unit/test-vmstate.c | 18 +++--- 17 files changed, 158 insertions(+), 108 deletions(-)
hw/display/virtio-gpu.c +1 -1
@@ -1343,7 +1343,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, }/* load & apply scanout state */ -vmstate_load_state (f, &vmstate_virtio_gpu_scanouts, g,1 ); +vmstate_load_state (f, &vmstate_virtio_gpu_scanouts, g,1 ,NULL );return 0 ; }
hw/pci/pci.c +1 -1
@@ -934,7 +934,7 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)int pci_device_load (PCIDevice *s,QEMUFile *f) {int ret; - ret =vmstate_load_state (f, &vmstate_pci_device, s, s->version_id); + ret =vmstate_load_state (f, &vmstate_pci_device, s, s->version_id,NULL );/* Restore the interrupt status bit. */ pci_update_irq_status (s);return ret;
hw/s390x/virtio-ccw.c +1 -1
@@ -1136,7 +1136,7 @@ static void virtio_ccw_save_config(DeviceState *d, QEMUFile *f)static int virtio_ccw_load_config (DeviceState *d,QEMUFile *f) {VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d); -return vmstate_load_state (f, &vmstate_virtio_ccw_dev, dev,1 ); +return vmstate_load_state (f, &vmstate_virtio_ccw_dev, dev,1 ,NULL ); }static void virtio_ccw_pre_plugged (DeviceState *d,Error **errp)
hw/scsi/spapr_vscsi.c +1 -1
@@ -648,7 +648,7 @@ static void *vscsi_load_request(QEMUFile *f, SCSIRequest *sreq)assert (!req->active);memset (req,0 ,sizeof (*req)); - rc =vmstate_load_state (f, &vmstate_spapr_vscsi_req, req,1 ); + rc =vmstate_load_state (f, &vmstate_spapr_vscsi_req, req,1 ,NULL );if (rc) {fprintf (stderr,"VSCSI: failed loading request tag#%u\n" , sreq->tag);return NULL ;
hw/vfio/pci.c +1 -1
@@ -2715,7 +2715,7 @@ static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) old_addr[bar] = pdev->io_regions[bar].addr; } - ret =vmstate_load_state (f, &vmstate_vfio_pci_config, vdev,1 ); + ret =vmstate_load_state (f, &vmstate_vfio_pci_config, vdev,1 ,NULL );if (ret) {return ret; }
hw/virtio/virtio-mmio.c +1 -1
@@ -619,7 +619,7 @@ static int virtio_mmio_load_extra_state(DeviceState *opaque, QEMUFile *f) {VirtIOMMIOProxy *proxy =VIRTIO_MMIO (opaque); -return vmstate_load_state (f, &vmstate_virtio_mmio, proxy,1 ); +return vmstate_load_state (f, &vmstate_virtio_mmio, proxy,1 ,NULL ); }static bool virtio_mmio_has_extra_state (DeviceState *opaque)
hw/virtio/virtio-pci.c +1 -1
@@ -160,7 +160,7 @@ static int virtio_pci_load_extra_state(DeviceState *d, QEMUFile *f) {VirtIOPCIProxy *proxy =to_virtio_pci_proxy (d); -return vmstate_load_state (f, &vmstate_virtio_pci, proxy,1 ); +return vmstate_load_state (f, &vmstate_virtio_pci, proxy,1 ,NULL ); }static void virtio_pci_save_queue (DeviceState *d,int n,QEMUFile *f)
hw/virtio/virtio.c +2 -2
@@ -3317,14 +3317,14 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) }if (vdc->vmsd) { - ret =vmstate_load_state (f, vdc->vmsd, vdev, version_id); + ret =vmstate_load_state (f, vdc->vmsd, vdev, version_id,NULL );if (ret) {return ret; } }/* Subsections */ - ret =vmstate_load_state (f, &vmstate_virtio, vdev,1 ); + ret =vmstate_load_state (f, &vmstate_virtio, vdev,1 ,NULL );if (ret) {return ret; }
include/migration/vmstate.h +1 -1
@@ -1196,7 +1196,7 @@ extern const VMStateInfo vmstate_info_qlist; }int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque,int version_id); +void *opaque,int version_id,Error **errp);int vmstate_save_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,JSONWriter *vmdesc); int vmstate_save_state_with_err(QEMUFile *f, const VMStateDescription *vmsd,
migration/colo.c +9 -4
@@ -659,6 +659,7 @@ void migrate_start_colo_process(MigrationState *s)static void colo_incoming_process_checkpoint (MigrationIncomingState *mis,QEMUFile *fb,QIOChannelBuffer *bioc,Error **errp) { +ERRP_GUARD ();uint64_t total_size;uint64_t value;Error *local_err =NULL ;
@@ -686,11 +687,13 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,bql_lock ();cpu_synchronize_all_states (); - ret =qemu_loadvm_state_main (mis->from_src_file, mis); + ret =qemu_loadvm_state_main (mis->from_src_file, mis, &local_err);bql_unlock ();if (ret <0 ) { -error_setg (errp,"Load VM's live state (ram) error" ); +if (local_err !=NULL ) { +error_prepend (errp,"Load VM's live state (ram) error" ); + }return ; }
@@ -729,9 +732,11 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,bql_lock (); vmstate_loading = true;colo_flush_ram_cache (); - ret =qemu_load_device_state (fb); + ret =qemu_load_device_state (fb, &local_err);if (ret <0 ) { -error_setg (errp,"COLO: load device state failed" ); +if (*errp !=NULL ) { +error_prepend (errp,"COLO: load device state failed" ); + } vmstate_loading = false;bql_unlock ();return ;
migration/cpr.c +1 -1
@@ -235,7 +235,7 @@ int cpr_state_load(MigrationChannel *channel, Error **errp)return -ENOTSUP ; } - ret =vmstate_load_state (f, &vmstate_cpr_state, &cpr_state,1 ); + ret =vmstate_load_state (f, &vmstate_cpr_state, &cpr_state,1 , errp);if (ret) {error_setg (errp,"vmstate_load_state error %d" , ret);qemu_fclose (f);
migration/migration.c +13 -6
@@ -876,7 +876,7 @@ process_incoming_migration_co(void *opaque) MIGRATION_STATUS_ACTIVE); mis->loadvm_co =qemu_coroutine_self (); - ret =qemu_loadvm_state (mis->from_src_file); + ret =qemu_loadvm_state (mis->from_src_file, &local_err); mis->loadvm_co =NULL ;trace_vmstate_downtime_checkpoint ("dst-precopy-loadvm-completed" );
@@ -903,7 +903,10 @@ process_incoming_migration_co(void *opaque) }if (ret <0 ) { -error_setg (&local_err,"load of migration failed: %s" ,strerror (-ret)); +if (local_err !=NULL ) { +error_prepend (&local_err,"load of migration failed: %s: " , +strerror (-ret)); + } goto fail; }
@@ -918,15 +921,19 @@ process_incoming_migration_co(void *opaque) fail:migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_FAILED ); -migrate_set_error (s, local_err); -error_free (local_err); +if (local_err) { +migrate_set_error (s, local_err); +error_free (local_err); + }migration_incoming_state_destroy ();if (mis->exit_on_error) { WITH_QEMU_LOCK_GUARD(&s->error_mutex) { -error_report_err (s->error); - s->error =NULL ; +if (s->error) { +error_report_err (s->error); + s->error =NULL ; + } }exit (EXIT_FAILURE );
migration/savevm.c +84 -53
368 lines not on this page · raw message
migration/savevm.h +4 -3
@@ -64,10 +64,11 @@ void qemu_savevm_send_colo_enable(QEMUFile *f);void qemu_savevm_live_state (QEMUFile *f);int qemu_save_device_state (QEMUFile *f); -int qemu_loadvm_state (QEMUFile *f); +int qemu_loadvm_state (QEMUFile *f,Error **errp);void qemu_loadvm_state_cleanup (MigrationIncomingState *mis); -int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis); -int qemu_load_device_state (QEMUFile *f); +int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis, +Error **errp); +int qemu_load_device_state (QEMUFile *f,Error **errp);int qemu_loadvm_approve_switchover (void );int qemu_savevm_state_complete_precopy_non_iterable (QEMUFile *f,bool in_postcopy);
migration/vmstate-types.c +5 -5
@@ -549,7 +549,7 @@ static int get_tmp(QEMUFile *f, void *pv, size_t size,/* Writes the parent field which is at the start of the tmp */ *(void **)tmp = pv; - ret =vmstate_load_state (f, vmsd, tmp, version_id); + ret =vmstate_load_state (f, vmsd, tmp, version_id,NULL );g_free (tmp);return ret; }
@@ -649,7 +649,7 @@ static int get_qtailq(QEMUFile *f, void *pv, size_t unused_size,while (qemu_get_byte (f)) { elm =g_malloc (size); - ret =vmstate_load_state (f, vmsd, elm, version_id); + ret =vmstate_load_state (f, vmsd, elm, version_id,NULL );if (ret) {return ret; }
@@ -803,7 +803,7 @@ static int get_gtree(QEMUFile *f, void *pv, size_t unused_size, key = (void *)(uintptr_t )qemu_get_be64 (f); }else { key =g_malloc0 (key_size); - ret =vmstate_load_state (f, key_vmsd, key, version_id); + ret =vmstate_load_state (f, key_vmsd, key, version_id,NULL );if (ret) {error_report ("%s : failed to load %s (%d)" , field->name, key_vmsd->name, ret);
@@ -811,7 +811,7 @@ static int get_gtree(QEMUFile *f, void *pv, size_t unused_size, } } val =g_malloc0 (val_size); - ret =vmstate_load_state (f, val_vmsd, val, version_id); + ret =vmstate_load_state (f, val_vmsd, val, version_id,NULL );if (ret) {error_report ("%s : failed to load %s (%d)" , field->name, val_vmsd->name, ret);
@@ -892,7 +892,7 @@ static int get_qlist(QEMUFile *f, void *pv, size_t unused_size,while (qemu_get_byte (f)) { elm =g_malloc (size); - ret =vmstate_load_state (f, vmsd, elm, version_id); + ret =vmstate_load_state (f, vmsd, elm, version_id,NULL );if (ret) {error_report ("%s: failed to load %s (%d)" , field->name, vmsd->name, ret);
migration/vmstate.c +23 -17
@@ -25,7 +25,7 @@ static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, JSONWriter *vmdesc, Error **errp);static int vmstate_subsection_load (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque); +void *opaque,Error **errp);/* Whether this field should exist for either save or load the VM? */ static bool
@@ -132,23 +132,23 @@ static void vmstate_handle_alloc(void *ptr, const VMStateField *field, }int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque,int version_id) +void *opaque,int version_id,Error **errp) {const VMStateField *field = vmsd->fields;int ret =0 ;trace_vmstate_load_state (vmsd->name, version_id);if (version_id > vmsd->version_id) { -error_report ("%s: incoming version_id %d is too new " -"for local version_id %d" , - vmsd->name, version_id, vmsd->version_id); +error_setg (errp,"%s: incoming version_id %d is too new " +"for local version_id %d" , + vmsd->name, version_id, vmsd->version_id);trace_vmstate_load_state_end (vmsd->name,"too new" , -EINVAL );return -EINVAL ; }if (version_id < vmsd->minimum_version_id) { -error_report ("%s: incoming version_id %d is too old " -"for local minimum version_id %d" , - vmsd->name, version_id, vmsd->minimum_version_id); +error_setg (errp,"%s: incoming version_id %d is too old " +"for local minimum version_id %d" , + vmsd->name, version_id, vmsd->minimum_version_id);trace_vmstate_load_state_end (vmsd->name,"too old" , -EINVAL );return -EINVAL ; }
@@ -192,10 +192,12 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,if (inner_field->flags &VMS_STRUCT ) { ret =vmstate_load_state (f, inner_field->vmsd, curr_elem, - inner_field->vmsd->version_id); + inner_field->vmsd->version_id, + errp); }else if (inner_field->flags &VMS_VSTRUCT ) { ret =vmstate_load_state (f, inner_field->vmsd, curr_elem, - inner_field->struct_version_id); + inner_field->struct_version_id, + errp); }else { ret = inner_field->info->get (f, curr_elem, size, inner_field);
@@ -211,23 +213,27 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, }if (ret <0 ) {qemu_file_set_error (f, ret); -error_report ("Failed to load %s:%s" , vmsd->name, - field->name); +error_setg (errp,"Failed to load %s:%s" , vmsd->name, + field->name);trace_vmstate_load_field_error (field->name, ret);return ret; } } }else if (field->flags &VMS_MUST_EXIST ) { -error_report ("Input validation failed: %s/%s" , - vmsd->name, field->name); +error_setg (errp,"Input validation failed: %s/%s" , + vmsd->name, field->name);return -1 ; } field++; }assert (field->flags ==VMS_END ); - ret =vmstate_subsection_load (f, vmsd, opaque); + ret =vmstate_subsection_load (f, vmsd, opaque, errp);if (ret !=0 ) {qemu_file_set_error (f, ret); +if (*errp ==NULL ) { +error_setg (errp,"Load of field %s/%s failed" , + vmsd->name, field->name); + }return ret; }if (vmsd->post_load) {
@@ -566,7 +572,7 @@ vmstate_get_subsection(const VMStateDescription * const *sub, }static int vmstate_subsection_load (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque) +void *opaque,Error **errp) {trace_vmstate_subsection_load (vmsd->name);
@@ -605,7 +611,7 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,qemu_file_skip (f, len);/* idstr */ version_id =qemu_get_be32 (f); - ret =vmstate_load_state (f, sub_vmsd, opaque, version_id); + ret =vmstate_load_state (f, sub_vmsd, opaque, version_id, errp);if (ret) {trace_vmstate_subsection_load_bad (vmsd->name, idstr,"(child)" );return ret;
tests/unit/test-vmstate.c +9 -9
@@ -114,7 +114,7 @@ static int load_vmstate_one(const VMStateDescription *desc, void *obj,qemu_fclose (f); f =open_test_file (false); - ret =vmstate_load_state (f, desc, obj, version); + ret =vmstate_load_state (f, desc, obj, version,NULL );if (ret) {g_assert (qemu_file_get_error (f)); }else {
@@ -365,7 +365,7 @@ static void test_load_v1(void)QEMUFile *loading =open_test_file (false);TestStruct obj = { .b =200 , .e =500 , .f =600 }; -vmstate_load_state (loading, &vmstate_versioned, &obj,1 ); +vmstate_load_state (loading, &vmstate_versioned, &obj,1 ,NULL );g_assert (!qemu_file_get_error (loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 200);
@@ -391,7 +391,7 @@ static void test_load_v2(void)QEMUFile *loading =open_test_file (false);TestStruct obj; -vmstate_load_state (loading, &vmstate_versioned, &obj,2 ); +vmstate_load_state (loading, &vmstate_versioned, &obj,2 ,NULL ); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20); g_assert_cmpint(obj.c, ==, 30);
@@ -480,7 +480,7 @@ static void test_load_noskip(void)QEMUFile *loading =open_test_file (false);TestStruct obj = { .skip_c_e = false }; -vmstate_load_state (loading, &vmstate_skipping, &obj,2 ); +vmstate_load_state (loading, &vmstate_skipping, &obj,2 ,NULL );g_assert (!qemu_file_get_error (loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20);
@@ -504,7 +504,7 @@ static void test_load_skip(void)QEMUFile *loading =open_test_file (false);TestStruct obj = { .skip_c_e = true, .c =300 , .e =500 }; -vmstate_load_state (loading, &vmstate_skipping, &obj,2 ); +vmstate_load_state (loading, &vmstate_skipping, &obj,2 ,NULL );g_assert (!qemu_file_get_error (loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20);
@@ -773,7 +773,7 @@ static void test_load_q(void)TestQtailq tgt;QTAILQ_INIT (&tgt.q); -vmstate_load_state (fload, &vmstate_q, &tgt,1 ); +vmstate_load_state (fload, &vmstate_q, &tgt,1 ,NULL );char eof =qemu_get_byte (fload);g_assert (!qemu_file_get_error (fload)); g_assert_cmpint(tgt.i16, ==, obj_q.i16);
@@ -1127,7 +1127,7 @@ static void test_gtree_load_domain(void) fload =open_test_file (false); -vmstate_load_state (fload, &vmstate_domain, dest_domain,1 ); +vmstate_load_state (fload, &vmstate_domain, dest_domain,1 ,NULL ); eof =qemu_get_byte (fload);g_assert (!qemu_file_get_error (fload)); g_assert_cmpint(orig_domain->id, ==, dest_domain->id);
@@ -1241,7 +1241,7 @@ static void test_gtree_load_iommu(void)qemu_fclose (fsave); fload =open_test_file (false); -vmstate_load_state (fload, &vmstate_iommu, dest_iommu,1 ); +vmstate_load_state (fload, &vmstate_iommu, dest_iommu,1 ,NULL ); eof =qemu_get_byte (fload);g_assert (!qemu_file_get_error (fload)); g_assert_cmpint(orig_iommu->id, ==, dest_iommu->id);
@@ -1376,7 +1376,7 @@ static void test_load_qlist(void)qemu_fclose (fsave); fload =open_test_file (false); -vmstate_load_state (fload, &vmstate_container, dest_container,1 ); +vmstate_load_state (fload, &vmstate_container, dest_container,1 ,NULL ); eof =qemu_get_byte (fload);g_assert (!qemu_file_get_error (fload)); g_assert_cmpint(eof, ==, QEMU_VM_EOF);
Signature · 1 line
2.49.0
PATCH v2 2/2 backends/tpm: Propagate vTPM error on migration failure
In reply to Arun Menon- Introduce a new post_load_with_error() hook that will take in the Error object as a parameter.
- This error object is set if the loading of state fails.
- The error can then be retrieved using QMP command {"execute" : "query-migrate"}
--- backends/tpm/tpm_emulator.c | 39 ++++++++++++++++++++------------------- include/migration/vmstate.h | 1 + migration/vmstate.c | 4 +++- 3 files changed, 24 insertions(+), 20 deletions(-)
backends/tpm/tpm_emulator.c +20 -19
@@ -819,7 +819,8 @@ static int tpm_emulator_get_state_blobs(TPMEmulator *tpm_emu)static int tpm_emulator_set_state_blob (TPMEmulator *tpm_emu,uint32_t type,TPMSizedBuffer *tsb, -uint32_t flags) +uint32_t flags, +Error **errp) {ssize_t n;ptm_setstate pss;
@@ -838,17 +839,17 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu,/* write the header only */ if (tpm_emulator_ctrlcmd (tpm_emu,CMD_SET_STATEBLOB , &pss, offsetof(ptm_setstate, u.req.data), 0, 0) < 0) { -error_report ("tpm-emulator: could not set state blob type %d : %s" , - type,strerror (errno)); +error_setg (errp,"tpm-emulator: could not set state blob type %d : %s" , + type,strerror (errno));return -1 ; }/* now the body */ n =qemu_chr_fe_write_all (&tpm_emu->ctrl_chr, tsb->buffer, tsb->size);if (n != tsb->size) { -error_report ("tpm-emulator: Writing the stateblob (type %d) " -"failed; could not write %u bytes, but only %zd" , - type, tsb->size, n); +error_setg (errp,"tpm-emulator: Writing the stateblob (type %d) " +"failed; could not write %u bytes, but only %zd" , + type, tsb->size, n);return -1 ; }
@@ -856,17 +857,17 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu, n =qemu_chr_fe_read_all (&tpm_emu->ctrl_chr, (uint8_t *)&pss,sizeof (pss.u.resp));if (n !=sizeof (pss.u.resp)) { -error_report ("tpm-emulator: Reading response from writing stateblob " -"(type %d) failed; expected %zu bytes, got %zd" , type, -sizeof (pss.u.resp), n); +error_setg (errp,"tpm-emulator: Reading response from writing " +"stateblob (type %d) failed; expected %zu bytes, " +"got %zd" , type,sizeof (pss.u.resp), n);return -1 ; } tpm_result =be32_to_cpu (pss.u.resp.tpm_result);if (tpm_result !=0 ) { -error_report ("tpm-emulator: Setting the stateblob (type %d) failed " -"with a TPM error 0x%x %s" , type, tpm_result, -tpm_emulator_strerror (tpm_result)); +error_setg (errp,"tpm-emulator: Setting the stateblob (type %d) " +"failed with a TPM error 0x%x %s" , type, tpm_result, +tpm_emulator_strerror (tpm_result));return -1 ; }
@@ -880,7 +881,7 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu,* * Returns a negative errno code in case of error. */ -static int tpm_emulator_set_state_blobs (TPMBackend *tb) +static int tpm_emulator_set_state_blobs (TPMBackend *tb,Error **errp) {TPMEmulator *tpm_emu =TPM_EMULATOR (tb);TPMBlobBuffers *state_blobs = &tpm_emu->state_blobs;
@@ -894,13 +895,13 @@ static int tpm_emulator_set_state_blobs(TPMBackend *tb)if (tpm_emulator_set_state_blob (tpm_emu,PTM_BLOB_TYPE_PERMANENT , &state_blobs->permanent, - state_blobs->permanent_flags) <0 || + state_blobs->permanent_flags, errp) <0 ||tpm_emulator_set_state_blob (tpm_emu,PTM_BLOB_TYPE_VOLATILE , &state_blobs->volatil, - state_blobs->volatil_flags) <0 || + state_blobs->volatil_flags, errp) <0 ||tpm_emulator_set_state_blob (tpm_emu,PTM_BLOB_TYPE_SAVESTATE , &state_blobs->savestate, - state_blobs->savestate_flags) <0 ) { + state_blobs->savestate_flags, errp) <0 ) {return -EIO ; }
@@ -948,12 +949,12 @@ static void tpm_emulator_vm_state_change(void *opaque, bool running,* * Returns negative errno codes in case of error. */ -static int tpm_emulator_post_load (void *opaque,int version_id) +static int tpm_emulator_post_load (void *opaque,int version_id,Error **errp) {TPMBackend *tb = opaque;int ret; - ret =tpm_emulator_set_state_blobs (tb); + ret =tpm_emulator_set_state_blobs (tb, errp);if (ret <0 ) {return ret; }
@@ -969,7 +970,7 @@ static const VMStateDescription vmstate_tpm_emulator = { .name = "tpm-emulator", .version_id = 0, .pre_save = tpm_emulator_pre_save, - .post_load = tpm_emulator_post_load, + .post_load_with_error = tpm_emulator_post_load, .fields = (const VMStateField []) {VMSTATE_UINT32 (state_blobs.permanent_flags, TPMEmulator),VMSTATE_UINT32 (state_blobs.permanent.size, TPMEmulator),
include/migration/vmstate.h +1 -0
@@ -207,6 +207,7 @@ struct VMStateDescription {MigrationPriority priority;int (*pre_load)(void *opaque);int (*post_load)(void *opaque,int version_id); +int (*post_load_with_error)(void *opaque,int version_id,Error **errp);int (*pre_save)(void *opaque);int (*post_save)(void *opaque);bool (*needed)(void *opaque);
migration/vmstate.c +3 -1
@@ -236,7 +236,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, }return ret; } -if (vmsd->post_load) { +if (vmsd->post_load_with_error) { + ret = vmsd->post_load_with_error (opaque, version_id, errp); + }else if (vmsd->post_load) { ret = vmsd->post_load (opaque, version_id); }trace_vmstate_load_state_end (vmsd->name,"end" , ret);
Signature · 1 line
2.49.0