Comment 3 for bug 1243287

Revision history for this message
Manoj Iyer (manjo) wrote : Re: [cloud-init][ARM][SAUCY] fails to boot cloud-image due to host kvm fail

The real reason for failure turns out is that cloud-init calls dmidecode in DataSourceAltCloud. In dmidecode we mmap() /dev/mem and try to memcpy() the contents to another memory location. Host kvm dies when you try to memcpy()/memmove() from the address that mmap() returned. The same code on a native arm system, mmap() fails and returns a -1. NOTE: We can open() and read() /dev/mem. Dmidecode is able to use either mmap() or just open() and read(), this is controlled by a #define USE_MMAP at compile time. But mmap() /dev/mem under kvm mmio seems to be doing bad things. Dmidecode does not print anything useful on ARM, at least the ones that don't have SMBIOS or use BIOS even. Many of tools call dmidecode, and this can cause problems if you run these tools on a cloud instance. I sent a patch upstream to dmidecode debian devel and waiting on comments.

Open /dev/mem and mmap() on native arm system vs kvm cloud instance behaves differently.

===== Native ARM Midway system =====
ubuntu@m10:~$ sudo ./testmmap
opened /dev/mem O_RDONLY
return from mmap() for PROT_READ = ffffffff
return from mmap() for PROT_READ | PROT_WRITE = ffffffff
closing /dev/mem
opened /dev/mem O_RDWR
return from mmap() for PROT_READ = ffffffff
return from mmap() for PROT_READ|PROT_WRITE = ffffffff
===========================================

===== KVM Instance on Midway System =========
ubuntu@cloudimg:~$ sudo ./testmmap
sudo: unable to resolve host cloudimg
opened /dev/mem O_RDONLY
return from mmap() for PROT_READ = b6eb1000
return from mmap() for PROT_READ | PROT_WRITE = ffffffff
closing /dev/mem
opened /dev/mem O_RDWR
return from mmap() for PROT_READ = b6ea1000
return from mmap() for PROT_READ|PROT_WRITE = b6e91000
trying to copy from srcaddr=0xb6e91000 to destaddr = 0x68d008 len = 0x10000
bytes
error: kvm run failed Function not implemented
ubuntu@m10:~/cloud-image$
=================================================

mmap() is returning with an address in the KVM instance, the address looks like
a valid address but if you try to copy from that address using
memcpy()/mmemove() you will kill kvm. I would expect mmap() to behave the same
on native and KVM instance.

You can find this testcase in:
http://kernel.ubuntu.com/~manjo/cloud-image-saucy/testmmap.c