Lai Jiangshan [Tue, 20 Dec 2011 09:08:51 +0000 (17:08 +0800)]
kvm tools: add kvm_ipc__send() and kvm_ipc__send_msg()
Current code write the sock manually. There is nothing constrains the format of
the written data is expect. Use kvm_ipc__send() and kvm_ipc__send_msg() for
such constraint.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Cyrill Gorcunov [Sun, 18 Dec 2011 20:24:56 +0000 (00:24 +0400)]
kvm tools: Make kvm__arch_setup_firmware to return error code
If some of subsequent calls fails we better to return error
code instead of dying with a message. This is a first step
in getting rid of number of die() calls we have in code.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Cyrill Gorcunov [Sun, 18 Dec 2011 15:16:09 +0000 (19:16 +0400)]
kvm tools: Define __compiletime_error helper
To eliminate compile errors like
| CC builtin-run.o
| In file included from ../../arch/x86/include/asm/system.h:7:0,
| from include/kvm/barrier.h:13,
| from builtin-run.c:16:
| ../../arch/x86/include/asm/cmpxchg.h:11:13: error: no previous prototype for ‘__xchg_wrong_size’ [-Werror=missing-prototypes]
| ../../arch/x86/include/asm/cmpxchg.h: In function ‘__xchg_wrong_size’:
| ../../arch/x86/include/asm/cmpxchg.h:12:2: error: expected declaration specifiers before ‘__compiletime_error’
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Wanlong Gao [Sat, 17 Dec 2011 12:17:19 +0000 (20:17 +0800)]
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>
Lai Jiangshan [Fri, 16 Dec 2011 09:12:08 +0000 (17:12 +0800)]
kvm-tools: fix wrong "./lkvm list -i"
because the program name is changed, "./lkvm list -i" can't work now.
This fix just remove the test:
1) this test is not reliable.
2) the target process can respond for "get_pid()", it must be
kvm-tool. (at least it is more reliable)
Acked-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Lai Jiangshan [Fri, 16 Dec 2011 09:12:05 +0000 (17:12 +0800)]
kvm-tools: write the sandbox command exactly as expect
sandbox.sh is a shell script, it will translate its meta
chars to anather things.
example(before this patch applied):
./lkvm sandbox -- echo 'success; please try again!'
it fails with:
/virt/sandbox.sh: line 3: please: command not found
Acked-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Thu, 15 Dec 2011 07:13:41 +0000 (18:13 +1100)]
kvm tools: Fix running with --initrd and no real discs/rootfs
It's useful to boot with no -d and no implicit 9p root, with --initrd.
Since commit eaf720b285947a6f4e29174d0eba1899de31d8ab, we die() failing
to create the 2nd stage custom rootfs. This patch doesn't try to set up
a custom rootfs by default if user specifies an initrd on the commandline.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Thu, 8 Dec 2011 06:57:09 +0000 (17:57 +1100)]
PPC: Add __SANE_USERSPACE_TYPES__ to asm/types.h for LL64
PPC64 uses long long for u64 in the kernel, but powerpc's asm/types.h
prevents 64-bit userland from seeing this definition, instead defaulting
to u64 == long in userspace. Some user programs (e.g. kvmtool) may actually
want LL64, so this patch adds a check for __SANE_USERSPACE_TYPES__ so that,
if defined, int-ll64.h is included instead.
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Wed, 14 Dec 2011 02:06:44 +0000 (13:06 +1100)]
kvm tools: Fix alaising errors in LINT assignment
I'm getting this on x86-32, gcc 4.4.3:
CC x86/kvm-cpu.o
cc1: warnings being treated as errors
x86/kvm-cpu.c: In function ‘kvm_cpu__set_lint’:
x86/kvm-cpu.c:89: error: dereferencing pointer ‘lapic’ does break strict-aliasing rules
x86/kvm-cpu.c:88: error: dereferencing pointer ‘lapic’ does break strict-aliasing rules
x86/kvm-cpu.c:83: note: initialized from here
make: *** [x86/kvm-cpu.o] Error 1
Removing the nasty aliasing seems to be a good way to go.
Acked-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Thu, 15 Dec 2011 05:06:57 +0000 (16:06 +1100)]
kvm tools: Remove KVM_NR_CPUS
The KVM_NR_CPUS define is only really used to statically size the global
kvm_cpus array, which can just as easily be allocated on startup. There is
some checking of the -c <nr cpus> value given against NR_CPUs but this is
later again checked against a dynamically-determined limit from
KVM_CAP_MAX_VCPUS anyway. The hardwired limit is arbitrary and not strictly
necessary.
This patch removes the #define, replacing the statically-sized array with
a malloc; the array is kvm->nrcpus+1 in size so that any iterator can halt
at the end (this is done in kvm_cpu__reboot, which doesn't have access to
a struct kvm* and therefore kvm->nrcpus).
An unused #define in x86/mptable.c is also removed.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Sasha Levin [Wed, 14 Dec 2011 13:11:21 +0000 (15:11 +0200)]
kvm tools: Don't always coalesce MMIOs
Coalescing MMIOs is only required when we really want avoid having to exit
to userspace for every MMIO write, usually it's not the case so no reason
to coalesce every MMIO zone (I was also pretty sure it didn't always coalesce
zones)..
Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Tue, 13 Dec 2011 07:00:26 +0000 (18:00 +1100)]
kvm tools: Add initial SPAPR PPC64 architecture support
This patch adds a new arch directory, powerpc, basic file structure, register
setup and where necessary stubs out arch-specific functions (e.g. interrupts,
runloop exits) that later patches will provide. The target is an
SPAPR-compliant PPC64 machine (i.e. pSeries); there is no support for PPC32 or
'bare metal' PPC64 guests as yet. Subsequent patches implement the hcalls and
RTAS required to boot SPAPR pSeries kernels.
Memory is mapped from hugetlbfs (as that is currently required by upstream PPC64
HV-mode KVM). The mapping of a VRMA region is yet to be implemented; this is
only necessary on processors that don't support VRMA, e.g. <= P6. Work is
therefore needed to get this going on pre-P7 CPUs.
Processor state is set up as a guest kernel would expect (both primary and
secondaries), and SMP is fully supported.
Finally, support is added for simply loading flat binary kernels (plus initrd).
(bzImages are not used on PPC, and this series does not add zImage support or an
ELF loader.) The intention is to later support loading firmware such as SLOF.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
On 14/12/11 11:03, David Evensky wrote:
> On an x86 32bit system (and using the 32bit CodeSourcery toolchain on
> a x86_64 system) I get:
>
> evensky@machine:~/.../linux-kvm/tools/kvm$ make
> CC util/util.o
> util/util.c: In function 'mmap_hugetlbfs':
> util/util.c:93:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
> util/util.c:99:7: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'int' [-Werror=format]
> cc1: all warnings being treated as errors
>
> make: *** [util/util.o] Error 1
Fixes the build.
Reported-by: David Evensky <evensky@dancer.ca.sandia.gov> Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Different architectures will deal with MMIO exits differently. For example,
KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesised by steering
into windows in PCI bridges on other architectures.
This patch calls arch-specific kvm_cpu__emulate_io() and kvm_cpu__emulate_mmio()
from the main runloop's IO and MMIO exit handlers. For x86, these directly
call kvm__emulate_io() and kvm__emulate_mmio() but other architectures will
perform some address munging before passing on the call.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Tue, 13 Dec 2011 06:21:46 +0000 (17:21 +1100)]
kvm tools: Add ability to map guest RAM from hugetlbfs
Add a --hugetlbfs commandline option to give a path to hugetlbfs-map guest
memory (down in kvm__arch_init()). For x86, guest memory is a normal
ANON mmap() if this option is not provided, otherwise a hugetlbfs mmap.
This maps directly from a hugetlbfs temp file rather than using something
like MADV_HUGEPAGES so that, if the user asks for hugepages, we definitely
are using hugepages. (This is particularly useful for architectures that
don't yet support KVM without hugepages, so we definitely need to use
them for the whole of guest RAM.)
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Sasha Levin [Mon, 5 Dec 2011 14:16:36 +0000 (16:16 +0200)]
kvm tools: Add 'kvm sandbox'
This patch adds 'kvm sandbox' which is a wrapper on top of 'kvm run' which
allows the user to easily specify sandboxed command to run in a custom
rootfs guest.
Sasha Levin [Mon, 5 Dec 2011 14:16:34 +0000 (16:16 +0200)]
kvm tools: Allow easily sandboxing applications within a guest
This patch adds a '--sandbox' argument when used in conjuction with a custom
rootfs, it allows running a script or an executable in the guest environment
by using executables and other files from the host.
This is useful when testing code that might cause problems on the host, or
to automate kernel testing since it's now easy to link a kvm tools test
script with 'git bisect run'.
Sasha Levin [Mon, 5 Dec 2011 14:16:32 +0000 (16:16 +0200)]
kvm tools: Split custom rootfs init into two stages
Currently custom rootfs init is built along with the main KVM tools executable
and is copied into custom rootfs directories when they are created with
'kvm setup'. The problem there is that if the init code changes, they have
to be manually copied to custom rootfs directories.
Instead, this patch splits init process into two parts. One part that simply
handles mounts, and passes it to stage 2 of the init.
Stage 2 really sits along in the code tree, and does all the heavy lifting.
This allows us to make init changes in the code tree and have it automatically
be updated in custom rootfs guests without having to copy files over manua
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
[ penberg@kernel.org: fix 'make check' breakage in Makefile ] Signed-off-by: Pekka Enberg <penberg@kernel.org>
Sasha Levin [Sat, 10 Dec 2011 20:40:43 +0000 (22:40 +0200)]
kvm tools: Free up the MSI-X PBA BAR
Free up the BAR to make space for the new virtio BARs. It isn't required
to have the PBA and the table in the separate BARs, and uniting them will
just give us extra BARs to play with.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Thomas Gleixner [Sat, 10 Dec 2011 20:27:26 +0000 (21:27 +0100)]
kvm tools: serial: Make it work with non rt guests as well
Sasha reported, that a non RT guest reports "too much work for irq 4"
with the previous serial overhaul.
The reason is, that the new code allows unlimited tx transfers, which
triggers the sanity check in the 8250.c interrupt handler.
Limit the consecutive TX chars to 16 and let the guest kernel escape
from the 8250 interrupt handler. Set the TEMT/THRE bits in the
periodic serial console update.
Reported-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Thomas Gleixner [Sat, 10 Dec 2011 13:27:57 +0000 (13:27 +0000)]
kvm tool: serial: Fix interrupt handling
The interrupt injection of the serial emulation is completely
broken. It's just doing random toggling of the interrupt line, which
can lead to complete console hangs.
The real hardware asserts the interrupt line when a condition
(RX/TX/Status) is met and the corresponding interrupt is enabled in
the IER. It's deasserted when the condition is cleared or the
corresponding interrupt is disabled in the IER.
So the correct emulation just needs to check after each state change
in the LSR or the IER which bits in the IIR need to be set and update
the interrupt line accordingly. To avoid setting the same state over
and over keep an internal state of the last set interrupt line state
and only update via the kvm ioctl when the new state differs.
Rename serial8250__inject_interrupts() to serial8250__update_consoles()
which reflects what the function really is about.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:55:54 +0000 (17:55 +1100)]
kvm tools: Arch-specific define for PCI MMIO allocation area
pci_get_io_space_block() used to grab addresses from
KVM_32BIT_GAP_START + 0x1000000, which is x86-specific. Create a new define,
KVM_PCI_MMIO_AREA, to specify a bus address these allocations can come from.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This allows config space access in a more natural manner than clunky x86 IO ports,
and is useful for other architectures. Internally, the x86 IO port access uses
these new config space interfaces.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:55:36 +0000 (17:55 +1100)]
kvm tools: Endian-sanitise pci.h and PCI device setup
vesa, pci-shmem and virtio-pci devices need to set up config space with
little-endian conversions (as config space is LE). The pci_config_address
bitfield also needs to be reversed when building on BE systems.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:55:16 +0000 (17:55 +1100)]
kvm tools: Perform CPU and firmware setup after devices are added
Currently some devices (in this case kbd, fb, vesa) are initialised after
CPU/firmware setup. On some platforms (e.g. PPC) kvm__arch_setup_firmware() may
be making a device tree. Any devices added after this point will be missed!
Tiny refactor of builtin-run.c, moving timer start, firmware setup, cpu init
to occur last.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:54:43 +0000 (17:54 +1100)]
kvm tools: Allow load_flat_binary() to load an initrd alongside
This patch passes the initrd fd and commandline to load_flat_binary(), which may
be used to load both the kernel & an initrd (stashing or inserting the
commandline as appropriate) in the same way that load_bzimage() does. This is
especially useful when load_bzimage() is unused for a particular
architecture. :-)
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
term_getc()'s int c has one byte written into it (at its lowest address) by
read_in_full(). This is expected to be the least significant byte, but that
isn't the case on BE! Use correct type, unsigned char. A similar issue exists
in term_getc_iov(), which needs to write a char to the iov rather than an int.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:54:20 +0000 (17:54 +1100)]
kvm tools: Add CONSOLE_HV term type and allow it to be selected
This patch paves the way for adding a hypervisor console, useful on systems that
support one out of the box yet don't have either serial port or virtio console
support (e.g. kernels expecting POWER SPAPR).
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:54:15 +0000 (17:54 +1100)]
kvm tools: Move arch-specific cmdline init into kvm__arch_set_cmdline()
Different systems will want different base kernel commandlines, e.g. non-x86
systems probably don't need noapic, i8042.* etc., so set the commandline up in
arch-specific code. Then, if the resulting commandline is empty, don't strcat a
space onto the front.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:54:11 +0000 (17:54 +1100)]
kvm tools: Add kvm__arch_periodic_poll()
Currently, the SIGALRM handler calls device poll functions (for serial, virtio
console) directly. Which devices are present and which require polling is a
system-specific decision, so create a new function called from common code &
move the x86-specific poll calls into it.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:54:06 +0000 (17:54 +1100)]
kvm tools: Fix KVM_RUN exit code check
kvm_cpu__run() currently die()s if KVM_RUN returns non-zero. Some architectures
may return positive values in non-error cases, whereas real errors are always
negative return values. Check for those instead.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Matt Evans [Fri, 9 Dec 2011 06:54:01 +0000 (17:54 +1100)]
kvm tools: Don't die if KVM_CAP_NR_VCPUS isn't available
We die() if we can't read KVM_CAP_NR_VCPUS, but the API docs suggest to assume
the value 4 in this case. This is pertinent to PPC KVM, which currently
does not support this CAP.
Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>