When a confidential virtual machine is reset, a new guest context in the accelerator must be generated post reset. Therefore, the old accelerator guest file handle must closed and a new one created. To this end, a per-accelerator callback, "reset_vmfd" is introduced that would get called when a confidential guest is reset. Subsequent patches will introduce specific implementation of this callback for KVM accelerator.
Signed-off-by: Ani Sinha <[email protected]> --- include/accel/accel-ops.h | 1 + system/runstate.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/accel/accel-ops.h b/include/accel/accel-ops.h index 23a8c246e1..998a95ca69 100644 --- a/include/accel/accel-ops.h +++ b/include/accel/accel-ops.h @@ -23,6 +23,7 @@ struct AccelClass { AccelOpsClass *ops; int (*init_machine)(AccelState *as, MachineState *ms); + int (*reset_vmfd)(MachineState *ms); bool (*cpu_common_realize)(CPUState *cpu, Error **errp); void (*cpu_common_unrealize)(CPUState *cpu); /* get_stats: Append statistics to @buf */ diff --git a/system/runstate.c b/system/runstate.c index e3ec16ab74..f5e57fd1f7 100644 --- a/system/runstate.c +++ b/system/runstate.c @@ -42,6 +42,7 @@ #include "qapi/qapi-commands-run-state.h" #include "qapi/qapi-events-run-state.h" #include "qemu/accel.h" +#include "accel/accel-ops.h" #include "qemu/error-report.h" #include "qemu/job.h" #include "qemu/log.h" @@ -508,6 +509,8 @@ void qemu_system_reset(ShutdownCause reason) { MachineClass *mc; ResetType type; + AccelClass *ac = ACCEL_GET_CLASS(current_accel()); + int ret; mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL; @@ -520,6 +523,23 @@ void qemu_system_reset(ShutdownCause reason) default: type = RESET_TYPE_COLD; } + + /* + * different accelerators implement how to close the old file handle of + * the accelerator descriptor and create a new one here. Resetting + * file handle is necessary to create a new confidential VM context post + * VM reset. + */ + if (current_machine->cgs && reason == SHUTDOWN_CAUSE_GUEST_RESET) { + if (ac->reset_vmfd) { + ret = ac->reset_vmfd(current_machine); + if (ret < 0) { + error_report("unable to reset vmfd: %d", ret); + abort(); + } + } + } + if (mc && mc->reset) { mc->reset(current_machine, type); } else { -- 2.42.0
