kvm tools: include arch uapi/asm directories in include path

Architectures such as ARM and powerpc place asm/kvm.h under
arch/$ARCH/include/uapi/asm, so ensure that this is part of the C
include path.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: only enable LTO if supported by GCC

Commit 99423f12db2a ("kvm tools: enable LTO") unconditionally enabled
link-time-optimisations when building kvmtool. Unfortunately, passing
-flto to a GCC without support for the option, results in a fatal build
error:

  cc1: error: LTO support has not been enabled in this configuration

This patch adds a check to the kvm tools Makefile so that LTO is only
enabled if the host compiler supports it.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: avoid linking dynamically against libbfd

Linking dynamically against libbfd results in a non-portable application
binary and is generally frowned upon by distributions: Debian forbids it
explicitly and on Gentoo, it results in a failure at run-time:

  ./lkvm: error while loading shared libraries: libbfd-2.22.so: cannot
  open shared object file: No such file or directory

Avoid these problems by linking statically instead.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: specify compiler by name when overriding make default

GNU make defaults "$(CC)" to "cc", which breaks compilation when we try
to execute $(CROSS_COMPILE)-cc.

This patch copies what the top-level kernel Makefile does, by specifying
"gcc" directly when overriding the $CC environment variable.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: don't pass -Wcast-align to the compiler

GCC 4.7 with -Wcast-align will warn for code like the following:

	bar = (struct foo *)(char *)(0);

which is exactly the sort of code generated by container_of. In
combination with -Werror, this breaks the build.

This patch removes the option from the kvmtool Makefile.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: die if init_list__init returns failure

If init_list__init returns failure when initialising kvm tool, we can't
rely on our structures being fully initialised, so die rather than try
to continue and fail gracefully later on.

This prevents a SEGV when kvm is not available on the host:

  Error: '/dev/kvm' not found. Please make sure your kernel has CONFIG_KVM enabled and that the KVM modules are loaded.
  Warning: Failed init: kvm__init

Segmentation fault

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: make _FDT macro usable by other architectures

The _FDT macro is useful when generating device trees for a guest, so
make it available to other architectures.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: virtio-mmio: use subsys_id instead of pci device ID

The virtio MMIO code attempts to map PCI device IDs to virtio MMIO
device IDs by subtracting 0x1000 and adding 1, however this conversion
only works for NET and BLK devices.

This patch uses the subsys_id (which is actually the virtio device ID
for virtio-mmio devices) instead of the PCI device ID when populating
the mmio device header.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: virtio: add dummy set_size_vq implementations

When a guest kernel initialises a virtio device using an MMIO transport,
it attempts to set the size of the virtual queue. For devices that expect
a PCI transport, this is not the case and, as such, our console, 9p and
rng virtio devices do not set a pointer for this function and subsequently
SEGV.

This patch adds a dummy implementation of the function to avoid the fatal
signal.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
kvm tools: allow arch to specify default virtio transport

Some architectures may provide only a restricted PCI implementation and
therefore prefer MMIO as the transport for virtio devices.

This patch allows the arch backend to specify the default virtio
transport. Some devices (e.g. net) allow the transport to be overriden
by the user and are left alone by this change.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>