Save and restore the KVM SBI state as a vmstate subsection, so that a guest using SBI STA keeps working after live migration. Only the STA shmem address (shmem_lo and shmem_hi) is saved for now; other SBI state can be appended to kvm_sbi_state as it is added.
Signed-off-by: Wang Yechao <[email protected]> --- target/riscv/machine.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 0de06e9588..b8cdca79cc 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -318,6 +318,23 @@ static const VMStateDescription vmstate_kvm_mp_state = { VMSTATE_END_OF_LIST() } }; + +static bool kvm_sbi_state_needed(void *opaque) +{ + return kvm_enabled(); +} + +static const VMStateDescription vmstate_kvm_sbi_state = { + .name = "cpu/kvm-sbi-state", + .version_id = 1, + .minimum_version_id = 1, + .needed = kvm_sbi_state_needed, + .fields = (const VMStateField[]) { + VMSTATE_UINT64(env.kvm_sbi_sta.shmem_lo, RISCVCPU), + VMSTATE_UINT64(env.kvm_sbi_sta.shmem_hi, RISCVCPU), + VMSTATE_END_OF_LIST() + } +}; #endif static bool debug_needed(void *opaque) @@ -645,6 +662,7 @@ const VMStateDescription vmstate_riscv_cpu = { &vmstate_kvm_timer_frequency, &vmstate_kvmtimer, &vmstate_kvm_mp_state, + &vmstate_kvm_sbi_state, #endif &vmstate_envcfg, &vmstate_debug, -- 2.27.0
