hw/i386: Move save_tsc_khz from PCMachineClass to X86MachineClass
PATCH v2 1/1 hw/i386: Move save_tsc_khz from PCMachineClass to X86MachineClass
Attempting to migrate a VM using the microvm machine class results in the source QEMU aborting with the following message/backtrace:
target/i386/machine.c:955:tsc_khz_needed: Object 0x555556608fa0 is not an instance of type generic-pc-machine
abort()object_class_dynamic_cast_assert()vmstate_save_state_v()vmstate_save_state()vmstate_save()qemu_savevm_state_complete_precopy()migration_thread()migration_thread()migration_thread()qemu_thread_start()start_thread()clone()
The access to the machine class returned by MACHINE_GET_CLASS() in tsc_khz_needed() is crashing as it is trying to dereference a different type of machine class object (TYPE_PC_MACHINE) to that of this microVM.
This can be resolved by extending the changes in the following commit f0bb276bf8d5 ("hw/i386: split PCMachineState deriving X86MachineState from it") and moving the save_tsc_khz field in PCMachineClass to X86MachineClass.
---
v1 -> v2 - fix SHA1 of patch being referenced.
hw/i386/pc.c | 1 - hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- hw/i386/x86.c | 1 + include/hw/i386/pc.h | 2 -- include/hw/i386/x86.h | 2 ++ target/i386/machine.c | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-)
hw/i386/pc.c +0 -1
@@ -2195,7 +2195,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)/* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported * to be used at the moment, 32K should be enough for a while. */ pcmc->acpi_data_size =0x20000 +0x8000 ; - pcmc->save_tsc_khz = true; pcmc->linuxboot_dma_enabled = true; pcmc->pvh_enabled = true;assert (!mc->get_hotplug_handler);
hw/i386/pc_piix.c +2 -2
@@ -567,10 +567,10 @@ DEFINE_I440FX_MACHINE(v2_6, "pc-i440fx-2.6", NULL,static void pc_i440fx_2_5_machine_options (MachineClass *m) { -PCMachineClass *pcmc =PC_MACHINE_CLASS (m); +X86MachineClass *x86mc =X86_MACHINE_CLASS (m);pc_i440fx_2_6_machine_options (m); - pcmc->save_tsc_khz = false; + x86mc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;compat_props_add (m->compat_props, hw_compat_2_5, hw_compat_2_5_len);compat_props_add (m->compat_props, pc_compat_2_5, pc_compat_2_5_len);
hw/i386/pc_q35.c +2 -2
@@ -508,10 +508,10 @@ DEFINE_Q35_MACHINE(v2_6, "pc-q35-2.6", NULL,static void pc_q35_2_5_machine_options (MachineClass *m) { -PCMachineClass *pcmc =PC_MACHINE_CLASS (m); +X86MachineClass *x86mc =X86_MACHINE_CLASS (m);pc_q35_2_6_machine_options (m); - pcmc->save_tsc_khz = false; + x86mc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;compat_props_add (m->compat_props, hw_compat_2_5, hw_compat_2_5_len);compat_props_add (m->compat_props, pc_compat_2_5, pc_compat_2_5_len);
hw/i386/x86.c +1 -0
@@ -763,6 +763,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) mc->get_default_cpu_node_id = x86_get_default_cpu_node_id; mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids; x86mc->compat_apic_id_mode = false; + x86mc->save_tsc_khz = true; nc->nmi_monitor_handler = x86_nmi; object_class_property_add(oc, X86_MACHINE_MAX_RAM_BELOW_4G, "size",
include/hw/i386/pc.h +0 -2
@@ -116,8 +116,6 @@ typedef struct PCMachineClass {bool enforce_aligned_dimm;bool broken_reserved_end; -/* TSC rate migration: */ -bool save_tsc_khz;/* generate legacy CPU hotplug AML */ bool legacy_cpu_hotplug;
include/hw/i386/x86.h +2 -0
@@ -30,6 +30,8 @@ typedef struct {/*< public >*/ +/* TSC rate migration: */ +bool save_tsc_khz;/* Enables contiguous-apic-ID mode */ bool compat_apic_id_mode; } X86MachineClass;
target/i386/machine.c +2 -2
@@ -988,8 +988,8 @@ static bool tsc_khz_needed(void *opaque)X86CPU *cpu = opaque;CPUX86State *env = &cpu->env;MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); -PCMachineClass *pcmc =PC_MACHINE_CLASS (mc); -return env->tsc_khz && pcmc->save_tsc_khz; +X86MachineClass *x86mc =X86_MACHINE_CLASS (mc); +return env->tsc_khz && x86mc->save_tsc_khz; }static const VMStateDescription vmstate_tsc_khz = {
Signature · 1 line
1.8.3.1
Quoted 132 lines · Liam Merwick
Attempting to migrate a VM using the microvm machine class results in the source QEMU aborting with the following message/backtrace:
target/i386/machine.c:955:tsc_khz_needed: Object
0x555556608fa0is not an instance of type generic-pc-machine
abort()object_class_dynamic_cast_assert()vmstate_save_state_v()vmstate_save_state()vmstate_save()qemu_savevm_state_complete_precopy()migration_thread()migration_thread()migration_thread()qemu_thread_start()start_thread()clone()The access to the machine class returned by
MACHINE_GET_CLASS()intsc_khz_needed()is crashing as it is trying to dereference a different type of machine class object (TYPE_PC_MACHINE) to that of this microVM.This can be resolved by extending the changes in the following commit
f0bb276bf8d5("hw/i386: split PCMachineState deriving X86MachineState from it") and moving thesave_tsc_khzfield in PCMachineClass to X86MachineClass.Fixes f0bb276bf8d5 ("hw/i386: split PCMachineState deriving X86MachineState from it")Signed-off-by Liam Merwick <[email protected]>Reviewed-by Darren Kenny <[email protected]>---
v1 -> v2 - fix SHA1 of patch being referenced.
hw/i386/pc.c | 1 - hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- hw/i386/x86.c | 1 + include/hw/i386/pc.h | 2 -- include/hw/i386/x86.h | 2 ++ target/i386/machine.c | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-)hw/i386/pc.c +0
-1@@ -2195,7 +2195,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)/* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported * to be used at the moment, 32K should be enough for a while. */ pcmc->acpi_data_size =0x20000 +0x8000 ; - pcmc->save_tsc_khz = true; pcmc->linuxboot_dma_enabled = true; pcmc->pvh_enabled = true;assert (!mc->get_hotplug_handler);hw/i386/pc_piix.c +2
-2@@ -567,10 +567,10 @@ DEFINE_I440FX_MACHINE(v2_6, "pc-i440fx-2.6", NULL,static void pc_i440fx_2_5_machine_options (MachineClass *m) { -PCMachineClass *pcmc =PC_MACHINE_CLASS (m); +X86MachineClass *x86mc =X86_MACHINE_CLASS (m);pc_i440fx_2_6_machine_options (m); - pcmc->save_tsc_khz = false; + x86mc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;compat_props_add (m->compat_props, hw_compat_2_5, hw_compat_2_5_len);compat_props_add (m->compat_props, pc_compat_2_5, pc_compat_2_5_len);hw/i386/pc_q35.c +2
-2@@ -508,10 +508,10 @@ DEFINE_Q35_MACHINE(v2_6, "pc-q35-2.6", NULL,static void pc_q35_2_5_machine_options (MachineClass *m) { -PCMachineClass *pcmc =PC_MACHINE_CLASS (m); +X86MachineClass *x86mc =X86_MACHINE_CLASS (m);pc_q35_2_6_machine_options (m); - pcmc->save_tsc_khz = false; + x86mc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;compat_props_add (m->compat_props, hw_compat_2_5, hw_compat_2_5_len);compat_props_add (m->compat_props, pc_compat_2_5, pc_compat_2_5_len);hw/i386/x86.c +1
-0@@ -763,6 +763,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) mc->get_default_cpu_node_id = x86_get_default_cpu_node_id; mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids; x86mc->compat_apic_id_mode = false; + x86mc->save_tsc_khz = true; nc->nmi_monitor_handler = x86_nmi; object_class_property_add(oc, X86_MACHINE_MAX_RAM_BELOW_4G, "size",include/hw/i386/pc.h +0
-2@@ -116,8 +116,6 @@ typedef struct PCMachineClass {bool enforce_aligned_dimm;bool broken_reserved_end; -/* TSC rate migration: */ -bool save_tsc_khz;/* generate legacy CPU hotplug AML */ bool legacy_cpu_hotplug;include/hw/i386/x86.h +2
-0@@ -30,6 +30,8 @@ typedef struct {/*< public >*/ +/* TSC rate migration: */ +bool save_tsc_khz;/* Enables contiguous-apic-ID mode */ bool compat_apic_id_mode; } X86MachineClass;target/i386/machine.c +0
-0
target/i386/machine.c static bool tsc_khz_needed(void *opaque) · line 995
Quoted 10 lines
target/i386/machine.c +2
-2@@ -988,8 +988,8 @@ static bool tsc_khz_needed(void *opaque)X86CPU *cpu = opaque;CPUX86State *env = &cpu->env;MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); -PCMachineClass *pcmc =PC_MACHINE_CLASS (mc); -return env->tsc_khz && pcmc->save_tsc_khz; +X86MachineClass *x86mc =X86_MACHINE_CLASS (mc); +return env->tsc_khz && x86mc->save_tsc_khz; }static const VMStateDescription vmstate_tsc_khz = {
LGTM, thanks.
Paolo Bonzini
AppliedQuoted 23 lines · Liam Merwick
Attempting to migrate a VM using the microvm machine class results in the source QEMU aborting with the following message/backtrace:
target/i386/machine.c:955:tsc_khz_needed: Object
0x555556608fa0is not an instance of type generic-pc-machine
abort()object_class_dynamic_cast_assert()vmstate_save_state_v()vmstate_save_state()vmstate_save()qemu_savevm_state_complete_precopy()migration_thread()migration_thread()migration_thread()qemu_thread_start()start_thread()clone()The access to the machine class returned by
MACHINE_GET_CLASS()intsc_khz_needed()is crashing as it is trying to dereference a different type of machine class object (TYPE_PC_MACHINE) to that of this microVM.
Quoted 7 lines
This can be resolved by extending the changes in the following commit
f0bb276bf8d5("hw/i386: split PCMachineState deriving X86MachineState from it") and moving thesave_tsc_khzfield in PCMachineClass to X86MachineClass.Fixes f0bb276bf8d5 ("hw/i386: split PCMachineState deriving X86MachineState from it")Signed-off-by Liam Merwick <[email protected]>Reviewed-by Darren Kenny <[email protected]>
Queued, thanks.
Paolo
Quoted 112 lines
v1 -> v2 - fix SHA1 of patch being referenced.
hw/i386/pc.c | 1 - hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- hw/i386/x86.c | 1 + include/hw/i386/pc.h | 2 -- include/hw/i386/x86.h | 2 ++ target/i386/machine.c | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-)hw/i386/pc.c +0
-1@@ -2195,7 +2195,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)/* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported * to be used at the moment, 32K should be enough for a while. */ pcmc->acpi_data_size =0x20000 +0x8000 ; - pcmc->save_tsc_khz = true; pcmc->linuxboot_dma_enabled = true; pcmc->pvh_enabled = true;assert (!mc->get_hotplug_handler);hw/i386/pc_piix.c +2
-2@@ -567,10 +567,10 @@ DEFINE_I440FX_MACHINE(v2_6, "pc-i440fx-2.6", NULL,static void pc_i440fx_2_5_machine_options (MachineClass *m) { -PCMachineClass *pcmc =PC_MACHINE_CLASS (m); +X86MachineClass *x86mc =X86_MACHINE_CLASS (m);pc_i440fx_2_6_machine_options (m); - pcmc->save_tsc_khz = false; + x86mc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;compat_props_add (m->compat_props, hw_compat_2_5, hw_compat_2_5_len);compat_props_add (m->compat_props, pc_compat_2_5, pc_compat_2_5_len);hw/i386/pc_q35.c +2
-2@@ -508,10 +508,10 @@ DEFINE_Q35_MACHINE(v2_6, "pc-q35-2.6", NULL,static void pc_q35_2_5_machine_options (MachineClass *m) { -PCMachineClass *pcmc =PC_MACHINE_CLASS (m); +X86MachineClass *x86mc =X86_MACHINE_CLASS (m);pc_q35_2_6_machine_options (m); - pcmc->save_tsc_khz = false; + x86mc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;compat_props_add (m->compat_props, hw_compat_2_5, hw_compat_2_5_len);compat_props_add (m->compat_props, pc_compat_2_5, pc_compat_2_5_len);hw/i386/x86.c +1
-0@@ -763,6 +763,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) mc->get_default_cpu_node_id = x86_get_default_cpu_node_id; mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids; x86mc->compat_apic_id_mode = false; + x86mc->save_tsc_khz = true; nc->nmi_monitor_handler = x86_nmi; object_class_property_add(oc, X86_MACHINE_MAX_RAM_BELOW_4G, "size",include/hw/i386/pc.h +0
-2@@ -116,8 +116,6 @@ typedef struct PCMachineClass {bool enforce_aligned_dimm;bool broken_reserved_end; -/* TSC rate migration: */ -bool save_tsc_khz;/* generate legacy CPU hotplug AML */ bool legacy_cpu_hotplug;include/hw/i386/x86.h +2
-0@@ -30,6 +30,8 @@ typedef struct {/*< public >*/ +/* TSC rate migration: */ +bool save_tsc_khz;/* Enables contiguous-apic-ID mode */ bool compat_apic_id_mode; } X86MachineClass;target/i386/machine.c +2
-2@@ -988,8 +988,8 @@ static bool tsc_khz_needed(void *opaque)X86CPU *cpu = opaque;CPUX86State *env = &cpu->env;MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); -PCMachineClass *pcmc =PC_MACHINE_CLASS (mc); -return env->tsc_khz && pcmc->save_tsc_khz; +X86MachineClass *x86mc =X86_MACHINE_CLASS (mc); +return env->tsc_khz && x86mc->save_tsc_khz; }static const VMStateDescription vmstate_tsc_khz = {