Commit Graph

449 Commits

Author SHA1 Message Date
Pekka Enberg 4508ee7398 kvm: Enable Linux kernel PCI probing
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 25af6674f2 kvm: Add some more ioport emulation
This patch adds some more ioport emulation code so that I can boot a Linux
kernel cleanly with "--ioport-debug" command line option enabled.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 15c2b0a0a4 bios: clean predefined bios area early
otherwise say EBDA area could have some trash
values gotten from malloc.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Pekka Enberg c2d4a49fa4 kvm: Use proper segment + offset in e820 bios
This patch fixes E820 BIOS emulation on AMD CPUs that, unlike Intel ones,
require proper 16-bit segment/offset addressing in virtualized 16-bit mode.

Reported-by: Asias He <asias.hejun@gmail.com>
Tested-by: Asias He <asias.hejun@gmail.com>
Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg c89b656f19 kvm: Exclude BIOS object files from header deps
This patch fixes build error reported by Asias.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 547f3082e2 kvm: Clean header dependency files
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg d5a8f2ff09 kvm: Fix Makefile header dependencies
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 5dac1f893c kvm: Update bios .gitignore list
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 1e1b38189c kvm: Clear performance monitoring CPUID flags
Commit 3d446cf17faefd621c0842b58c92a50bd307eec7 ("kvm__setup_cpuid: use
KVM_GET_SUPPORTED_CPUID to simplify cpuid setup") causes the following errors
to be printed on host kernel dmesg:

[  775.134693] kvm: 2882: cpu0 unhandled rdmsr: 0x345
[  775.143130] kvm: 2882: cpu0 unhandled wrmsr: 0x40 data 0
[  775.143136] kvm: 2882: cpu0 unhandled wrmsr: 0x60 data 0
[  775.143141] kvm: 2882: cpu0 unhandled wrmsr: 0x41 data 0
[  775.143146] kvm: 2882: cpu0 unhandled wrmsr: 0x61 data 0
[  775.143150] kvm: 2882: cpu0 unhandled wrmsr: 0x42 data 0
[  775.143155] kvm: 2882: cpu0 unhandled wrmsr: 0x62 data 0
[  775.143159] kvm: 2882: cpu0 unhandled wrmsr: 0x43 data 0
[  775.143164] kvm: 2882: cpu0 unhandled wrmsr: 0x63 data 0

As explained by Cyrill Gorcunov, these MSR accesses come from Linux performance
events subsystems which is not supported by our little hypervisor. Therefore,
clear the performance monitoring CPUID flags to let guest kernels know about
that.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg bcae38c8ac kvm: Use sizeof instead of magic number
The 'ecx' register contains size of copied data. Use sizeof(struct e820_entry)
instead of a magic number to make it obvious from the code.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg ca82361e44 kvm: Cleanup BIOS setup code
This patch cleans up BIOS setup code by introducing struct irq_handler and
switching to more declarative setup.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov b654218805 kvm, bios: Make e820 map to look similar the real one
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Pekka Enberg 9266831741 kvm: Remove unused outb() function from e820.c
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 28ce0d664b kvm, bios: BIOS code redesign
Instead of keeping bios code in various bin junks make
it to host in one binary blob. This blob gets copied
to a predefined place at startup and IVT handlers set
as appropriate.

Also we need to generate header file which will contain
BIOS tourine offsets for symbols being used.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Pekka Enberg 307a9af02d kvm: Use -Werror for building the thing
It's easy to miss warnings so use -Werror. We're a shiny new userspace project
so there's no reason not to use it.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 8cc7d24b4f kvm: Use 32-bit operand size prefix for rdfs8()
E820 memory map resides in EBDA region which starts at address 0x9fc00 which
doesn't fit in 16 bits. Therefore, use 'addr32' operand size prefix to fix the
following error:

  bios/e820.c: Assembler messages:
  bios/e820.c:14: Warning: 654336 shortened to 64512

Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 2346d461f0 kvm: Fix load_bzimage for flat binaries
We must not die if load_bzimage() fails because we want to fall-back to loading
flat binaries.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg b487c53e37 kvm: Fix usage command line format
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 7ada9b6b0e kvm: Check for read() return value in load_bzimage()
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 34649df9e8 kvm: Fix VM support check for unrecognized CPUs
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 52191c02dc kvm: Use -Os optimization for GCC
GCC generates unreadable machine code with default optimization level.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Asias He bb988cf5b9 kvm__setup_cpuid: use KVM_GET_SUPPORTED_CPUID to simplify cpuid setup
Let kernel setup "struct kvm_cpuid2" for us!

https://kerneltrap.org/mailarchive/linux-kernel/2010/4/27/4563640
Avi Kivity:
'''
No.  KVM_GET_CPUID2 reads what was set by KVM_SET_CPUID, as modified by
the guest executing the cpuid instruction.  KVM_GET_SUPPORTED_CPUID
tells userspace which bits are supported by the host cpu and kvm.

The API for KVM_GET_SUPPORTED_CPUID returns all cpuid leaves supported
in one go, IIRC.
'''
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 192a99d1d7 kvm: Add --mem= option
Which allow an user to specify the amount of memory
he would like to provide for kernel.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 6e7b99ee3f bios: No need for sti at int15 irq exit
iret will restore eflags anyway

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 505d225a04 bios: Don't clobber 32bit registers
To be on safe side we better to save whole 32bit
of appropriate registers. Even in real mode.

At moment no code affected but it's possible in future.
Actually int15 code does touch 32bit registers but it
uses caller's stack.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Pekka Enberg 2f3976eeee kvm: BIOS E820 memory map emulation
This patch adds BIOS E820 memory map emulation to KVM.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 9292f77631 kvm, bios: Rework BIOS setup
This is a really huge rework of our primitive BIOS emulator.

The initial idea was to implement stack management in BIOS
irq handlers. In turn it ends up in re-factoring of all BIOS
code.

Some code details
-----------------

1) BIOS stack is placed at predefined constant memory address.
2) BIOS stack is only 64 bytes deep. It must be enough even for
   future irq handlers.
3) To be able to place irq handlers at almost arbitrary place of
   guest memory their start address must be 16 byte aligned.
   This makes easy to compute irq routines local variables addresses.
4) To eliminate address relocations in irq handlers code we use a
   special loader script.

TODO
----

- Still needs e820 map implements, int15 is dummy at moment

P.S. Thanks H. Peter Anvin for advices.

[ penberg@cs.helsinki.fi: cleanups ]
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 27a751f4a4 Exclude .cscope from .gitignore
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov b2978d44b8 kvm, bios: Get rid of buggy int10 handler
At moment any BIOS code using which needs own stack
have to be remade. It's a bit not that easy task.

We're happily may live without int10 handler since we
switch to early_printk interface really early. And
actually we don't scan VGA memory anyway so that even
if there is something written we ignore the result.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Pekka Enberg b927116056 kvm: Cleanup struct boot_params setup
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 831fbf235e kvm: Cleanup kvm__cpu_supports_vm()
This patch cleans up kvm__cpu_supports_vm() by unifying the VMX and SVM paths.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov ae87afbf83 kvm: Check for SVM extension being supported for AMD cpus
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Asias He c78b871349 kvm: Check vmx capability using cpuid
[ penberg@cs.helsinki.fi: use host_cpuid(), cleanups ]
Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 6d7c36ceea kvm: Introduce '--kvm-dev' command line option
This patch introduces a '--kvm-dev' command line option for debugging purposes.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg b7c344e482 kvm: Introduce 'make devices' target
This patch adds a 'make devices' target to Makefile that sets up KVM device if
one does not exist in '/dev/kvm'.

Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 11e9d907bb kvm: Fix compilation warning
This patch fixes the following compilation warning:

  main.c: In function ‘main’:
  main.c:149: warning: label ‘out’ defined but not used

Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 62ef45dc93 kvm: Don't stop on ioport errors by default
This patch introduces a '--ioport-debug' option that preserves the old
stop-on-error behavior and changes the default to keep on running despite of
ioport errors. This allows Linux kernel to boot to VFS mount phase.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 3ae4f82b7c kvm: Add '--params' to usage
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg cb046752e8 kvm: Add proper 00E0 ioport handling
We use 00E0 ioport for trapping to the hypervisor. This patch cleans up
handling of the ioport to call exit() in ioport emulation handler.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg b9bc89d70f kvm: Cleanup ioport_ops table
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg aa2c2691fb kvm: Cleanup command line parsing
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 3a5c54b1a4 kvm: Use 'nopci pci=off' kernel parameters by default
As pointed out by Cyrill, use 'nopci pci=off' by default to avoid the need for
emulating PCI.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 0332e3139d kvm, cpuid: Use logical AND on bit ops
Otherwise we may push cleaned bits back.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 44677817a1 kvm, cpuid: Fill up func 0 and 4
Retun "qemu64" largest function number and set
cpu to GenueIntel, fill up cache info and rename
cpuid to host_cpuid since we may need to distinguish
which cpuid (host or guest) is called.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:39 +01:00
Cyrill Gorcunov d38ad31a8f kvm: KVM_CAP_EXT_CPUID is required
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:39 +01:00
Cyrill Gorcunov d845784715 kvm, cpuid: Fix XSTOR and VMX compatibility in cpuid
Under virtual environment we don't support XSTOR and VMX features.

Reported-by: Asias He <asias.hejun.hj@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:39 +01:00
Cyrill Gorcunov 79241bb628 kvm, tests: Use motherboard specific ports for testing
H. Peter Anvin suggested to use motherboard specific ports
for testing instead of ones well known. Thanks, Peter!

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:39 +01:00
Cyrill Gorcunov 3db4f1beb3 kvm: Add force exit from tests
To make so we write any value to port 0 and
start kvm in --dbgtest mode so we are expecting
for this exit.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:39 +01:00
Cyrill Gorcunov 339c64c83a tests/pit: Increase PIT frequency up to 1KHz
Otherwise it's too boring ;)

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:39 +01:00
Cyrill Gorcunov 7c0ec28f29 kvm: Check for HTL extension granted
We need it thought it seems it doesn't work in
all our testcases.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:39 +01:00