32 Commits

Author SHA1 Message Date
Andre Przywara
15542bab78 avoid casts when initializing structures
Due to our kernel heritage we have code in kvmtool that relies on
the (still) implicit -std=gnu89 compiler switch.
It turns out that this just affects some structure initialization,
where we currently provide a cast to the type, which upsets GCC for
anything beyond -std=gnu89 (for instance gnu99 or gnu11).
We do need the casts when initializing structures that are not
assigned to the same type, so we put it there explicitly.

This allows us to compile with all the three GNU standards GCC
currently supports: gnu89/90, gnu99 and gnu11.
GCC threatens people with moving to gnu11 as the new default standard,
so lets fix this better sooner than later.
(Compiling without GNU extensions still breaks and I don't bother to
fix that without very good reasons.)

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:47 +01:00
Andreas Herrmann
c8058b8837 kvmtool: Fix compile error on MIPS
When including asm-generic/types.h instead of asm/types.h it results
in conflicting types for __s64 et al (at least with my
toolchain). Other header files are including asm/types.h
(e.g. include/kvm/ioport.h) and types defined there don't necessarily
match the types defined in asm-generic/types.h.

Signed-off-by: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-16 18:25:33 +01:00
Andre Przywara
2006613929 kvmtool: remove unneeded EXPORT_SYMBOL from iovec.c
In util/iovec.c we reference EXPORT_SYMBOL, which is only useful
within the kernel. To get rid of the dummy include file, simply
remove those lines.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 17:54:09 +01:00
Andre Przywara
f23171ca13 kvmtool: remove reference to <asm/types.h> from BIOS include files
For x86 the files that become the BIOS blob are compiled with -m32.
Although we avoid including any system libraries, we use some headers
from /usr/include, which asks for trouble if compiling on a x86-64
multiarch system (Debian/Ubuntu). Without 32-bit compat headers
installed there, the compiler will not find the right files.
However as the BIOS code is actually a self-contained binary without
any relationship to the Linux userland, it should not use or rely
on Linux system headers.
Replace includes of linux/types.h in BIOS code with asm/bios/types.h,
which simply contains the u{8,16,32,64} data types needed by the code.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 17:54:09 +01:00
Andre Przywara
c6cb7c7573 kvmtool: 9p: teach kvmtool about kuid_t and kgid_t
The 9p kernel code uses separate types for uid_t and gid_t. To avoid
changing too much code needlessly, copy over the kernel definitions
from uidgid.h into 9p.h.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Andre Przywara
fbb8a81d1a kvmtool: list.h: get rid of poison.h include
The special Linux poison bits do not make sense in userland, so
just replace them with NULL to spot bogus accesses.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Andre Przywara
f65dd17d8d kvmtool: arm/arm64: Copy some Linux architecture specific headers
The ARM part requires psci.h, which is pretty recent, so older
distributions might not carry it. This pulls in sizes.h, which is not
an uapi header, but quite convenient and not really Linux specific.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Andre Przywara
a08bb43a0c kvmtool: Copy Linux' up-to-date virtio headers
Some distributions with an older uapi header copy do not have all the
definitions that we need (Ubuntu 12.04 comes to mind).
So copy the latest versions from the Linux tree to override the system
header versions.
Also include virtio_mmio.h, which is technically not an uapi header,
but is used in such a way. QEMU has actually a copy of these
definitions in its own header file, so our approach should even be
better.
Those files are from a Linux v4.1-rc6 source tree, but the virtio-1.0
updates have been left out. kvmtool implements only the older version
of virtio.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Andre Przywara
fe8e6c1c18 kvmtool: Copy Linux' linux/9p.h header file
This file includes 9P protocol definitions which we need.
Copy them from a recent Linux tree.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Andre Przywara
304dcb6425 kvmtool: Copy Linux' up-to-date uapi/kvm.h
The uapi copy of kvm.h is usually outdated, so copy over a fresh copy
from the Linux v4.1-rc6 source tree. This exercise should later be
repeated when new kvmtool code requires this.
It seems to be common practise in QEMU to do so.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Andre Przywara
75bfd03cd2 kvmtool: Copy some bits from Linux' byteorder.h
Instead of moving the whole include file in, we just copy the needed
definitions from byteorder/generic.h into the kvmtool headers.
This avoids needless clutter of the include directory.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Andre Przywara
c093730099 kvmtool: Copy Linux' rbtree implementation
This is not really Linux specific, just a neat implementation
used by kvmtool, too.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Andre Przywara
7e841c883d kvmtool: Copy some helper header files from the Linux tree
Copy some non-Linux specific header files over to the kvmtool
directory. This includes generic helpers like stringify and list
definitions.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-01 16:40:11 +01:00
Sasha Levin
d8f361774a kvm tools: steal iovec handling routines from the kernel
They're hidden inside net/core/iovec.c. It'd be nice to just link to that
but they're not too generic and come with tons of net/ specific code we
don't want. So we just copy over the relevant parts.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Will Deacon
5bc1304080 kvm tools: don't bother including linux/compiler.h
linux/compiler.h will never give us a definition for __compiler_offsetof
because __KERNEL__ isn't defined, so just use the simple definition that
we have already.

This patch removes the redundant code.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Ingo Molnar
8682490069 kvm tools: Port to v3.7-rc1
There were a number of changes that caused problems:

 - UAPI conversion

 - the old version of the rbtree-augmented API got removed, I
   updated the implementation to the new API

 - lib/rbtree.c wants a 'true' definition

Lightly tested: it boots a v3.7-rc1 defconfig+kvmconfig kernel.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Asias He
a67da3beff kvm tools: Add initial virtio-scsi support
This patch brings virito-scsi support to kvm tool.

With the introduce of tcm_vhost (vhost-scsi)

   tcm_vhost: Initial merge for vhost level target fabric driver

we can implement virito-scsi by simply having vhost-scsi to handle the
SCSI command.

Howto use:
1) Setup the tcm_vhost target through /sys/kernel/config

   [Stefan Hajnoczi, Thanks for the script to setup tcm_vhost]

   ** Setup wwpn and tpgt
   $ wwpn="naa.0"
   $ tpgt=/sys/kernel/config/target/vhost/$wwpn/tpgt_0
   $ nexus=$tpgt/nexus
   $ mkdir -p $tpgt
   $ echo -n $wwpn > $nexus

   ** Setup lun using /dev/ram
   $ n=0
   $ lun=$tpgt/lun/lun_${n}
   $ data=/sys/kernel/config/target/core/iblock_0/data_${n}
   $ ram=/dev/ram${n}
   $ mkdir -p $lun
   $ mkdir -p $data
   $ echo -n udev_path=${ram} > $data/control
   $ echo -n 1 > $data/enable
   $ ln -s $data $lun

2) Run kvm tool with the new disk option '-d scsi:$wwpn:$tpgt', e.g
   $ lkvm run -k /boot/bzImage -d ~/img/sid.img -d scsi:naa.0:0

Signed-off-by: Asias He <asias.hejun@gmail.com>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Pekka Enberg
085d5c7a9d kvm tools: Fix build breakage due to <linux/stddef.h> changes
Commit 2084c24 ("do not export kernel's NULL #define to userspace") broken KVM
tool build:

  FYI:

   CC       framebuffer.o
  In file included from include/kvm/framebuffer.h:5:0,
                from framebuffer.c:1:
  ../../include/linux/list.h: In function ‘INIT_HLIST_NODE’:
  ../../include/linux/list.h:572:12: error: ‘NULL’ undeclared (first use in this function)
  ../../include/linux/list.h:572:12: note: each undeclared identifier is reported only once for each function it appears in
  ../../include/linux/list.h: In function ‘hlist_move_list’:
  ../../include/linux/list.h:657:15: error: ‘NULL’ undeclared (first use in this function)
  make: *** [framebuffer.o] Error 1

  due to this upstream commit:

   2084c24a8141 do not export kernel's NULL #define to userspace

Fix that.

Reported-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Wanlong Gao
7095a9052c kvm tools: prevent the redefined error
In file included from ../../include/linux/stddef.h:4:0,
                 from ../../include/linux/list.h:5,
                 from include/kvm/framebuffer.h:5,
                 from builtin-run.c:8:
include/linux/compiler.h:8:0: error: "__attribute_const__" redefined [-Werror]
/usr/include/sys/cdefs.h:226:0: note: this is the location of the previous definition
cc1: all warnings being treated as errors

make: *** [builtin-run.o] Error 1

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Lan Tianyu
f9b8c3a634 kvm tools: Use kernel error check functions
Add compiler.h file to support using kernel error check funciotns(e.g
ERR_PTR, PTR_ERR and so on).

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Matt Evans
d4e7505ce7 kvm tools: Get correct 64-bit types on PPC64 and link appropriately
kvmtool's types.h includes <asm/types.h>, which by default on PPC64 brings in
int-l64.h; define __SANE_USERSPACE_TYPES__ to get LL64 types.

This patch also adds CFLAGS to the final link, so that any -m64 is obeyed
when linking, too.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:49 +01:00
Cyrill Gorcunov
70f44c742f kvm tools: Fix absence of notrace definition
Ingo reported a build breakage caused by absence of 'notrace' definition. Fix
it by adding compiler.h into own headers set.

Reported-by: Ingo Molnar <mingo@elte.hu>
Tested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Sasha Levin
e358b4fbdb kvm tools: Add interval red-black tree helper
Interval rb-tree allows to directly store interval ranges
and quickly lookup an overlap with a single point or a range.

The helper is based on the kernel rb-tree implementation
(located in <linux/rbtree.h>) which alows for the augmention
of the classical rb-tree to be used as an interval tree.

Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Sasha Levin
c383fe9c00 kvm tools: Introduce IRQ registry
Instead of having static definitions of devices, Use a
dynamic registry of pci devices.

The structure is a rbtree which holds device types (net,
blk, etc). Each device entry holds a list of IRQ lines
associated with that device (pin).

Devices dynamically register upon initialization, and receive
a set of: device id, irq pin and irq line.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Sasha Levin
3fdf659d95 kvm tools: Abolishment of uint*_t types
Clean uint*_t type from the code.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Ingo Molnar
2caa836dc7 kvm tools: Fix 32-bit build of the asm/system.h include
Provide wrappers and other environmental dependencies that the
asm/system.h header file from hell needs to build fine in user-space.

Sidenote: right now alternative() defaults to the compatible, slightly
slower barrier instructions that work on all x86 systems.

If this ever shows up in profiles then kvm could provide an alternatives
patching machinery as well. Right now those instructions are emitted
into special sections and then discarded by the linker harmlessly.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Sasha Levin
c1b3d8d86e kvm tools: Add kernel headers required for using list
Adds kernel headers so that <linux/list.h> (and others) could be included
directly.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Prasad Joshi
86835ced6d kvm tools: Add QCOW version 1 read-only support
The patch only implements the basic read-only support for QCOW version 1
images.  Many of the QCOW features are not implemented:

 - write
 - image creation
 - snapshot
 - copy-on-write
 - encryption

The code is based on the following QCOW 1 image format specification:

  http://people.gnome.org/~markmc/qcow-image-format-version-1.html

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Ingo Molnar
a2a002f91b kvm tools: Fix 64-bit assumptions and type uglinesses
Make the MIN_RAM_SIZE_MB constant 64-bit on 32-bit systems as well, otherwise
we get this build failure:

  kvm-run.c: In function ‘kvm_cmd_run’:
  kvm-run.c:119: error: format ‘%lu’ expects type ‘long unsigned int’, but argument 2 has type ‘u64’

Also adjust affected printf format string - this necessiates the use of
the sane Linux definition of u64 instead of the brain-dead int64_t
variant.

That also allows (and necessiates) the removal of the ugly PRIu64 format
string hackery. Friends don't let friends use PRI* hackeries! :-)

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Prasad Joshi
98ee79f433 kvm tools: Use code from perf for argument processing
- parse-options.[ch] has argument processing code.

- types.h: Additional types for argument processing.

- strbuf.[ch]: Added a function prefixcmp to compare string prefix

Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Pekka Enberg
20c64ecabe kvm: Remove duplicate headers
We're in the kernel source tree now so remove duplicate headers.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg
886c5381fc kvm: Add KVM ABI headers
This patch adds KVM ABI headers to the source tree. We can no longer include
<linux/kvm.h> directly because someone added a "#warning" to <linux/types.h>
that prevents kernel header inclusion from userspace.

We can switch back to using kernel headers if we ever make it to Linux
mainline.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:40 +01:00