Skip to content

Commit bc22001

Browse files
liu.xuemei1@zte.com.cnalistair23
authored andcommitted
migration: Fix migration failure when aia is configured as aplic-imsic
Address an error in migration when aia is configured as 'aplic-imsic' in riscv kvm vm by adding riscv_aplic_state_needed() and riscv_imsic_state_needed() to determine whether the corresponding sates are needed. Previously, the fields in the vmsds of 'riscv_aplic' and 'riscv_imsic' can only be initialized under certain special conditions in commit 95a97b3. However, the corresponding ses of these vmsds are inserted into the savevm_state.handlers unconditionally. This led to migration failure characterized by uninitialized fields when save vm state: qemu-system-riscv64: ../migration/vmstate.c:433: vmstate_save_state_v: Assertion 'first_elem || !n_elems || !size' failed. Fixes: 95a97b3 ("target/riscv: update APLIC and IMSIC to support KVM AIA") Signed-off-by: Xuemei Liu <liu.xuemei1@zte.com.cn> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20250616150034827wuHs_ffe3Qm8cqFXT7HeW@zte.com.cn> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
1 parent b5092b3 commit bc22001

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

hw/intc/riscv_aplic.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,18 @@ static const Property riscv_aplic_properties[] = {
962962
DEFINE_PROP_BOOL("mmode", RISCVAPLICState, mmode, 0),
963963
};
964964

965+
static bool riscv_aplic_state_needed(void *opaque)
966+
{
967+
RISCVAPLICState *aplic = opaque;
968+
969+
return riscv_use_emulated_aplic(aplic->msimode);
970+
}
971+
965972
static const VMStateDescription vmstate_riscv_aplic = {
966973
.name = "riscv_aplic",
967-
.version_id = 2,
968-
.minimum_version_id = 2,
974+
.version_id = 3,
975+
.minimum_version_id = 3,
976+
.needed = riscv_aplic_state_needed,
969977
.fields = (const VMStateField[]) {
970978
VMSTATE_UINT32(domaincfg, RISCVAPLICState),
971979
VMSTATE_UINT32(mmsicfgaddr, RISCVAPLICState),

hw/intc/riscv_imsic.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,16 @@ static const Property riscv_imsic_properties[] = {
398398
DEFINE_PROP_UINT32("num-irqs", RISCVIMSICState, num_irqs, 0),
399399
};
400400

401+
static bool riscv_imsic_state_needed(void *opaque)
402+
{
403+
return !kvm_irqchip_in_kernel();
404+
}
405+
401406
static const VMStateDescription vmstate_riscv_imsic = {
402407
.name = "riscv_imsic",
403-
.version_id = 1,
404-
.minimum_version_id = 1,
408+
.version_id = 2,
409+
.minimum_version_id = 2,
410+
.needed = riscv_imsic_state_needed,
405411
.fields = (const VMStateField[]) {
406412
VMSTATE_VARRAY_UINT32(eidelivery, RISCVIMSICState,
407413
num_pages, 0,

0 commit comments

Comments
 (0)