Skip to content

Commit 2f34ebf

Browse files
merwickbonzini
authored andcommitted
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 f0bb276 ("hw/i386: split PCMachineState deriving X86MachineState from it") and moving the save_tsc_khz field in PCMachineClass to X86MachineClass. Fixes: f0bb276 ("hw/i386: split PCMachineState deriving X86MachineState from it") Signed-off-by: Liam Merwick <[email protected]> Reviewed-by: Darren Kenny <[email protected]> Message-Id: <[email protected]> Reviewed-by: Sergio Lopez <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 62e9dc3 commit 2f34ebf

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

hw/i386/pc.c

-1
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
21952195
/* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported
21962196
* to be used at the moment, 32K should be enough for a while. */
21972197
pcmc->acpi_data_size = 0x20000 + 0x8000;
2198-
pcmc->save_tsc_khz = true;
21992198
pcmc->linuxboot_dma_enabled = true;
22002199
pcmc->pvh_enabled = true;
22012200
assert(!mc->get_hotplug_handler);

hw/i386/pc_piix.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,10 @@ DEFINE_I440FX_MACHINE(v2_6, "pc-i440fx-2.6", NULL,
567567

568568
static void pc_i440fx_2_5_machine_options(MachineClass *m)
569569
{
570-
PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
570+
X86MachineClass *x86mc = X86_MACHINE_CLASS(m);
571571

572572
pc_i440fx_2_6_machine_options(m);
573-
pcmc->save_tsc_khz = false;
573+
x86mc->save_tsc_khz = false;
574574
m->legacy_fw_cfg_order = 1;
575575
compat_props_add(m->compat_props, hw_compat_2_5, hw_compat_2_5_len);
576576
compat_props_add(m->compat_props, pc_compat_2_5, pc_compat_2_5_len);

hw/i386/pc_q35.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ DEFINE_Q35_MACHINE(v2_6, "pc-q35-2.6", NULL,
508508

509509
static void pc_q35_2_5_machine_options(MachineClass *m)
510510
{
511-
PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
511+
X86MachineClass *x86mc = X86_MACHINE_CLASS(m);
512512

513513
pc_q35_2_6_machine_options(m);
514-
pcmc->save_tsc_khz = false;
514+
x86mc->save_tsc_khz = false;
515515
m->legacy_fw_cfg_order = 1;
516516
compat_props_add(m->compat_props, hw_compat_2_5, hw_compat_2_5_len);
517517
compat_props_add(m->compat_props, pc_compat_2_5, pc_compat_2_5_len);

hw/i386/x86.c

+1
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data)
763763
mc->get_default_cpu_node_id = x86_get_default_cpu_node_id;
764764
mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids;
765765
x86mc->compat_apic_id_mode = false;
766+
x86mc->save_tsc_khz = true;
766767
nc->nmi_monitor_handler = x86_nmi;
767768

768769
object_class_property_add(oc, X86_MACHINE_MAX_RAM_BELOW_4G, "size",

include/hw/i386/pc.h

-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ typedef struct PCMachineClass {
116116
bool enforce_aligned_dimm;
117117
bool broken_reserved_end;
118118

119-
/* TSC rate migration: */
120-
bool save_tsc_khz;
121119
/* generate legacy CPU hotplug AML */
122120
bool legacy_cpu_hotplug;
123121

include/hw/i386/x86.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ typedef struct {
3030

3131
/*< public >*/
3232

33+
/* TSC rate migration: */
34+
bool save_tsc_khz;
3335
/* Enables contiguous-apic-ID mode */
3436
bool compat_apic_id_mode;
3537
} X86MachineClass;

target/i386/machine.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,8 @@ static bool tsc_khz_needed(void *opaque)
988988
X86CPU *cpu = opaque;
989989
CPUX86State *env = &cpu->env;
990990
MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
991-
PCMachineClass *pcmc = PC_MACHINE_CLASS(mc);
992-
return env->tsc_khz && pcmc->save_tsc_khz;
991+
X86MachineClass *x86mc = X86_MACHINE_CLASS(mc);
992+
return env->tsc_khz && x86mc->save_tsc_khz;
993993
}
994994

995995
static const VMStateDescription vmstate_tsc_khz = {

0 commit comments

Comments
 (0)