When running QEMU without -cpu parameter, the user usually wants a sane default. So far, we're using the qemu64/qemu32 CPU type, which basically means "the maximum TCG can emulate".
That's a really good default when using TCG, but when running with KVM we much rather want a default saying "the maximum KVM can support". Fortunately we already have such a CPU type. It's called "host". All we need to do is to select it by default when not getting a -cpu passed in. This fixes a lot of subtile breakage in the GNU toolchain (libgmp) which hicks up on QEMU's non-existent CPU models. Signed-off-by: Alexander Graf <ag...@suse.de> --- v1 -> v2: - add fallback code for old versions, so we don't break -M pc-xxx --- hw/pc_piix.c | 40 +++++++++++++++++++++++++++++++++------- 1 files changed, 33 insertions(+), 7 deletions(-) diff --git a/hw/pc_piix.c b/hw/pc_piix.c index 166c2fc..67f6ec9 100644 --- a/hw/pc_piix.c +++ b/hw/pc_piix.c @@ -79,7 +79,8 @@ static void pc_init1(MemoryRegion *system_memory, const char *initrd_filename, const char *cpu_model, int pci_enabled, - int kvmclock_enabled) + int kvmclock_enabled, + int may_cpu_host) { int i; ram_addr_t below_4g_mem_size, above_4g_mem_size; @@ -101,6 +102,9 @@ static void pc_init1(MemoryRegion *system_memory, MemoryRegion *rom_memory; DeviceState *dev; + if (!cpu_model && kvm_enabled() && may_cpu_host) { + cpu_model = "host"; + } pc_cpus_init(cpu_model); if (kvmclock_enabled) { @@ -261,7 +265,21 @@ static void pc_init_pci(ram_addr_t ram_size, get_system_io(), ram_size, boot_device, kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 1, 1); + initrd_filename, cpu_model, 1, 1, 1); +} + +static void pc_init_pci_oldcpu(ram_addr_t ram_size, + const char *boot_device, + const char *kernel_filename, + const char *kernel_cmdline, + const char *initrd_filename, + const char *cpu_model) +{ + pc_init1(get_system_memory(), + get_system_io(), + ram_size, boot_device, + kernel_filename, kernel_cmdline, + initrd_filename, cpu_model, 1, 1, 0); } static void pc_init_pci_no_kvmclock(ram_addr_t ram_size, @@ -275,7 +293,7 @@ static void pc_init_pci_no_kvmclock(ram_addr_t ram_size, get_system_io(), ram_size, boot_device, kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 1, 0); + initrd_filename, cpu_model, 1, 0, 0); } static void pc_init_isa(ram_addr_t ram_size, @@ -291,7 +309,7 @@ static void pc_init_isa(ram_addr_t ram_size, get_system_io(), ram_size, boot_device, kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 0, 1); + initrd_filename, cpu_model, 0, 1, 0); } #ifdef CONFIG_XEN @@ -312,8 +330,8 @@ static void pc_xen_hvm_init(ram_addr_t ram_size, } #endif -static QEMUMachine pc_machine_v1_0 = { - .name = "pc-1.0", +static QEMUMachine pc_machine_v1_1 = { + .name = "pc-1.1", .alias = "pc", .desc = "Standard PC", .init = pc_init_pci, @@ -321,10 +339,17 @@ static QEMUMachine pc_machine_v1_0 = { .is_default = 1, }; +static QEMUMachine pc_machine_v1_0 = { + .name = "pc-1.0", + .desc = "Standard PC", + .init = pc_init_pci_oldcpu, + .max_cpus = 255, +}; + static QEMUMachine pc_machine_v0_14 = { .name = "pc-0.14", .desc = "Standard PC", - .init = pc_init_pci, + .init = pc_init_pci_oldcpu, .max_cpus = 255, .compat_props = (GlobalProperty[]) { { @@ -571,6 +596,7 @@ static QEMUMachine xenfv_machine = { static void pc_machine_init(void) { + qemu_register_machine(&pc_machine_v1_1); qemu_register_machine(&pc_machine_v1_0); qemu_register_machine(&pc_machine_v0_14); qemu_register_machine(&pc_machine_v0_13); -- 1.6.0.2