qemu: command: Support arm 32-on-64 KVM with -cpu aarch64=off

qemu 2.3.0 added the -cpu host,aarch64=off option, which allows using
qemu-system-aarch64 KVM to run armv7l VMs.

Add a capabilities check for it, wire it up in qemu_command, and test
the command line generation.
This commit is contained in:
Cole Robinson 2015-05-21 18:18:20 -04:00
parent 65a0b334f9
commit 29ce1693fa
6 changed files with 75 additions and 0 deletions

View File

@ -284,6 +284,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
"aes-key-wrap",
"dea-key-wrap",
"pci-serial",
"aarch64-off",
);
@ -3283,6 +3284,12 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
if (qemuCaps->version >= 2002000)
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_VMPORT_OPT);
/* -cpu ...,aarch64=off supported in v2.3.0 and onwards. But it
isn't detectable via qmp at this point */
if (qemuCaps->arch == VIR_ARCH_AARCH64 &&
qemuCaps->version >= 2003000)
virQEMUCapsSet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF);
if (virQEMUCapsProbeQMPCommands(qemuCaps, mon) < 0)
goto cleanup;
if (virQEMUCapsProbeQMPEvents(qemuCaps, mon) < 0)

View File

@ -228,6 +228,7 @@ typedef enum {
QEMU_CAPS_AES_KEY_WRAP = 186, /* -machine aes_key_wrap */
QEMU_CAPS_DEA_KEY_WRAP = 187, /* -machine dea_key_wrap */
QEMU_CAPS_DEVICE_PCI_SERIAL = 188, /* -device pci-serial */
QEMU_CAPS_CPU_AARCH64_OFF = 189, /* -cpu ...,aarch64=off */
QEMU_CAPS_LAST, /* this must always be the last item */
} virQEMUCapsFlags;

View File

@ -7021,6 +7021,19 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
}
virBufferAddLit(buf, "host");
if (def->os.arch == VIR_ARCH_ARMV7L &&
host->arch == VIR_ARCH_AARCH64) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("QEMU binary does not support CPU "
"host-passthrough for armv7l on "
"aarch64 host"));
goto cleanup;
}
virBufferAddLit(buf, ",aarch64=off");
}
if (ARCH_IS_PPC64(def->os.arch) &&
cpu->mode == VIR_CPU_MODE_HOST_MODEL &&
def->cpu->model != NULL) {

View File

@ -0,0 +1,10 @@
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
/usr/bin/qemu-system-aarch64 -S -M virt -cpu host,aarch64=off -m 1024 -smp 1 \
-nographic -nodefconfig -nodefaults \
-monitor unix:/tmp/test-monitor,server,nowait \
-boot c -kernel /arm.kernel -initrd /arm.initrd \
-append 'console=ttyAMA0,115200n8 rw root=/dev/vda rootwait physmap.enabled=0' \
-usb -drive file=/arm.raw,if=none,id=drive-virtio-disk0 \
-device virtio-blk-device,drive=drive-virtio-disk0,id=virtio-disk0 \
-device virtio-net-device,vlan=0,id=net0,mac=52:54:00:09:a4:37 \
-net user,vlan=0,name=hostnet0 -serial pty

View File

@ -0,0 +1,35 @@
<domain type="kvm">
<name>armtest</name>
<uuid>496d7ea8-9739-544b-4ebd-ef08be936e6a</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch="armv7l" machine="virt">hvm</type>
<kernel>/arm.kernel</kernel>
<initrd>/arm.initrd</initrd>
<cmdline>console=ttyAMA0,115200n8 rw root=/dev/vda rootwait physmap.enabled=0</cmdline>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<cpu mode='host-passthrough'/>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-aarch64</emulator>
<disk type='file' device='disk'>
<source file='/arm.raw'/>
<target dev='vda' bus='virtio'/>
</disk>
<interface type='user'>
<mac address='52:54:00:09:a4:37'/>
<model type='virtio'/>
</interface>
<console type='pty'/>
</devices>
</domain>

View File

@ -1552,6 +1552,15 @@ mymain(void)
DO_TEST("aarch64-gic", QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE,
QEMU_CAPS_KVM);
driver.caps->host.cpu->arch = VIR_ARCH_AARCH64;
DO_TEST("aarch64-kvm-32-on-64", QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE,
QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DEVICE_VIRTIO_MMIO,
QEMU_CAPS_KVM, QEMU_CAPS_CPU_HOST, QEMU_CAPS_CPU_AARCH64_OFF);
DO_TEST_FAILURE("aarch64-kvm-32-on-64", QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE,
QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DEVICE_VIRTIO_MMIO,
QEMU_CAPS_KVM, QEMU_CAPS_CPU_HOST);
driver.caps->host.cpu->arch = cpuDefault->arch;
DO_TEST("kvm-pit-device", QEMU_CAPS_KVM_PIT_TICK_POLICY);
DO_TEST("kvm-pit-delay", QEMU_CAPS_NO_KVM_PIT);
DO_TEST("kvm-pit-device", QEMU_CAPS_NO_KVM_PIT,