Linux kvm guest freeze under Debian

If you run uniprocessor Linux guests using kvm virtualization under Linux Debian as host, you may hit the issue with kvm-clock clocksource causing freezes described here and here.

The issue is difficult to track down; search engines do not help with the most obvious query “kvm linux guest freeze”; the actual bugs cited above are filed with redhat bugzilla and not on any of the three separate bug trackers referenced by the kvm project (the kernel’s bug trackerQemu’s launchpad tracker and the obsolete sourceforge bug tracker). To complicate things further, there is a seemingly unrelated issue with SMP guests.

For all these reasons, I have put together here a thorough description of the symptoms and the cure.

The issue: the guests will freeze after some time (1 h – 48 h)  from boot, even if there is nothing going on in any of them. Launching more than one guest in a short sequence is more likely to make them all hang within 1 to 60 min. You can see the kvm process corresponding to the frozen guest takes 100% CPU on the host; they will not respond to ssh, ACPI shutdown/restart, the only way to get rid of them is to kill the process in the host. Even the libvirt daemon does not respond and will need to be force restarted, for example with this script:

service libvirt-bin stop
`ps aux | grep libvirt | grep -v kvm | grep -v grep | awk '{ print "kill -9 " $2; }'`
service libvirt-bin start

Host: The problem occurred on a single-CPU server with an Intel Xeon 2-core CPU and on a similar machine with a 4-core Intel Xeon, both with hardware virtualization support (VT-x) enabled.

Host OS: Linux Debian 6.0 Squeeze AMD64 with 2.6.32-5-amd64 kernel.

Host kvm version: The kvm package from Debian 6.0 Squeeze (version 0.12.5).

Guest OS: Linux Debian 5 Lenny to Debian 7 Wheezy, both x86 and AMD64. Windows guests do not suffer from this problem.

Qemu command line used to start the guests, something like:

/usr/bin/kvm -S -M pc-0.12 -cpu qemu32 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -name deb6_32_dev -uuid ... -nodefaults -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/deb6_32_dev.monitor,server,nowait -mon chardev=monitor,mode=readline -rtc base=utc -boot c -drive file=/dev/...,if=none,id=drive-virtio-disk0,boot=on,format=raw -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0 -drive if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -device virtio-net-pci,vlan=0,id=net0,mac=...,bus=pci.0,addr=0x3 -net tap,fd=48,vlan=0,name=hostnet0 -chardev pty,id=serial0 -device isa-serial,chardev=serial0 -usb -device usb-tablet,id=input0 -vnc -k it -vga vmware -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

Troubleshooting tricks you could try (with no success): The problem does not go away if kvm is started with the -no-kvm-irqchip switch and it is also there if kvm is started with the -no-kvm switch (freezes only take longer to occur). There is nothing relevant in the libvirt logs, nothing on the guest console, nothing in the guest dmesg, no particular process active when the freeze occur. The strace output for the kvm processes always shows something like this as last system call:

futex(0x858560, FUTEX_WAIT_PRIVATE, 2, NULL <unfinished ...>

The solution: Set the guest clock source to acpi_pm rather than kvm-clock. This is best accomplished at boot via kernel parameters passed by grub. With grub2 (the default for Debian 6 Squeeze and 7 Wheezy), modify the /etc/default/grub file replacing this line:




Then run update-grub to update the actual configuration file /boot/grub/grub.cfg and reboot.

With legacy grub (the default with Debian 5 Lenny), edit the /boot/grub/, changing the following line in the Default Options section:

# kopt=root=/dev/hda1 ro


# kopt=root=/dev/hda1 ro clocksource=acpi_pm

but do this without uncommenting it ! Then run update-grub and reboot.

After doing these changes, verify that the correct clock source is active in each guest, by issuing:

cat /sys/devices/system/clocksource/clocksource0/current_clocksource

you should get:


Good luck !

About paolog

homo technologicus cynicus
This entry was posted in Howtos and tagged . Bookmark the permalink.

4 Responses to Linux kvm guest freeze under Debian

  1. eurekafag says:

    Thanks, you’ve saved me a lot of time! My windows guest with 4 virtual cores works ok but debian guest with 1 core behave strange after suspending/resuming. I can’t ssh to it, some programs work in tty1 but nothing starts in Xvnc, browsing with graphical file manager results in its freeze and so on. Somehow I noticed that clock doesn’t tick in guest. I have current date/time as RPROMPT and it didn’t change at all and date command confirmed it. So I googled a bit and found your post. After setting acpi_pm as the clocksource the guest instantly unfreezed (without any reboot) and started working. It’s not that big problem because rebooting the host doesn’t happen often but anyway that was a bit frustrating.

  2. Peter says:

    very cool, seems to do the trick; thank you!
    I’m running squeeze on squeeze, hung 3 of 4 times during boot;
    would you mind posting how you tracked this down?
    after checking the logs but before starting strace I tried your solution 🙂 otherwise … no idea

  3. paolog says:

    The issues caused by kvm-clock clocksource are reported in and mentioned above; some trial and error helped – systematically checking logs and strace didnt’d !

  4. Pingback: Installare KVM su Debian - Hostingwebitalia - Server dedicati , VPS , servizi hosting e cloud hosting | Hostingwebitalia - Server dedicati , VPS , servizi hosting e cloud hosting

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti-Spam Quiz: