platform/kernel/linux-amlogic.git
14 years agoKVM: x86 emulator: implement RDTSC (opcode 0F 31)
Avi Kivity [Wed, 18 Aug 2010 15:54:34 +0000 (18:54 +0300)]
KVM: x86 emulator: implement RDTSC (opcode 0F 31)

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: remove SrcImplicit
Avi Kivity [Wed, 18 Aug 2010 15:53:43 +0000 (18:53 +0300)]
KVM: x86 emulator: remove SrcImplicit

Useless.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: implement IMUL REG, R/M (opcode 0F AF)
Avi Kivity [Wed, 18 Aug 2010 15:31:43 +0000 (18:31 +0300)]
KVM: x86 emulator: implement IMUL REG, R/M (opcode 0F AF)

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: implement IMUL REG, R/M, imm8 (opcode 6B)
Avi Kivity [Wed, 18 Aug 2010 15:25:25 +0000 (18:25 +0300)]
KVM: x86 emulator: implement IMUL REG, R/M, imm8 (opcode 6B)

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: implement RET imm16 (opcode C2)
Avi Kivity [Wed, 18 Aug 2010 12:12:09 +0000 (15:12 +0300)]
KVM: x86 emulator: implement RET imm16 (opcode C2)

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: add SrcImmU16 operand type
Avi Kivity [Wed, 18 Aug 2010 12:11:24 +0000 (15:11 +0300)]
KVM: x86 emulator: add SrcImmU16 operand type

Used for RET NEAR instructions.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: implement CALL FAR (FF /3)
Avi Kivity [Wed, 18 Aug 2010 11:51:45 +0000 (14:51 +0300)]
KVM: x86 emulator: implement CALL FAR (FF /3)

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: implement DAS (opcode 2F)
Avi Kivity [Wed, 18 Aug 2010 11:16:35 +0000 (14:16 +0300)]
KVM: x86 emulator: implement DAS (opcode 2F)

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: Use a register for ____emulate_2op() destination
Avi Kivity [Mon, 16 Aug 2010 14:50:56 +0000 (17:50 +0300)]
KVM: x86 emulator: Use a register for ____emulate_2op() destination

Most x86 two operand instructions allow the destination to be a memory operand,
but IMUL (for example) requires that the destination be a register.  Change
____emulate_2op() to take a register for both source and destination so we
can invoke IMUL.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: pass destination type to ____emulate_2op()
Avi Kivity [Mon, 16 Aug 2010 14:49:52 +0000 (17:49 +0300)]
KVM: x86 emulator: pass destination type to ____emulate_2op()

We'll need it later so we can use a register for the destination.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: add LOOP/LOOPcc instruction emulation
Wei Yongjun [Wed, 18 Aug 2010 08:38:21 +0000 (16:38 +0800)]
KVM: x86 emulator: add LOOP/LOOPcc instruction emulation

Add LOOP/LOOPcc instruction emulation (opcode 0xe0~0xe2).

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: add CBW/CWDE/CDQE instruction emulation
Wei Yongjun [Wed, 18 Aug 2010 08:43:13 +0000 (16:43 +0800)]
KVM: x86 emulator: add CBW/CWDE/CDQE instruction emulation

Add CBW/CWDE/CDQE instruction emulation.(opcode 0x98)
Used by FreeBSD's boot loader.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: fix REPZ/REPNZ termination condition
Avi Kivity [Tue, 17 Aug 2010 08:22:17 +0000 (11:22 +0300)]
KVM: x86 emulator: fix REPZ/REPNZ termination condition

EFLAGS.ZF needs to be checked after each iteration, not before.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: implement SCAS (opcodes AE, AF)
Avi Kivity [Tue, 17 Aug 2010 08:20:37 +0000 (11:20 +0300)]
KVM: x86 emulator: implement SCAS (opcodes AE, AF)

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: fix INTn emulation not pushing EFLAGS and CS
Avi Kivity [Tue, 17 Aug 2010 08:17:51 +0000 (11:17 +0300)]
KVM: x86 emulator: fix INTn emulation not pushing EFLAGS and CS

emulate_push() only schedules a push; it doesn't actually push anything.
Call writeback() to flush out the write.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: remove dup code of in/out instruction
Wei Yongjun [Fri, 6 Aug 2010 03:46:12 +0000 (11:46 +0800)]
KVM: x86 emulator: remove dup code of in/out instruction

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: change OUT instruction to use dst instead of src
Wei Yongjun [Fri, 6 Aug 2010 03:45:12 +0000 (11:45 +0800)]
KVM: x86 emulator: change OUT instruction to use dst instead of src

Change OUT instruction to use dst instead of src, so we can
reuse those code for all out instructions.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: introduce DstImmUByte for dst operand decode
Wei Yongjun [Fri, 6 Aug 2010 03:36:51 +0000 (11:36 +0800)]
KVM: x86 emulator: introduce DstImmUByte for dst operand decode

Introduce DstImmUByte for dst operand decode, which
will be used for out instruction.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: remove useless label from x86_emulate_insn()
Wei Yongjun [Fri, 6 Aug 2010 07:36:36 +0000 (15:36 +0800)]
KVM: x86 emulator: remove useless label from x86_emulate_insn()

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: add setcc instruction emulation
Wei Yongjun [Fri, 6 Aug 2010 09:10:07 +0000 (17:10 +0800)]
KVM: x86 emulator: add setcc instruction emulation

Add setcc instruction emulation (opcode 0x0f 0x90~0x9f)

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86: explain 'no-kvmclock' kernel parameter
Jiri Kosina [Mon, 16 Aug 2010 15:51:20 +0000 (17:51 +0200)]
KVM: x86: explain 'no-kvmclock' kernel parameter

no-kvmclock kernel parameter is missing its explanation in
Documentation/kernel-parameters.txt. Add it.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: add XADD instruction emulation
Wei Yongjun [Tue, 17 Aug 2010 01:19:34 +0000 (09:19 +0800)]
KVM: x86 emulator: add XADD instruction emulation

Add XADD instruction emulation (opcode 0x0f 0xc0~0xc1)

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: put register operand write back to a function
Wei Yongjun [Tue, 17 Aug 2010 01:17:30 +0000 (09:17 +0800)]
KVM: x86 emulator: put register operand write back to a function

Introduce function write_register_operand() to write back the
register operand.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: fix leakage of error page in kvmppc_patch_dcbz()
Wei Yongjun [Tue, 17 Aug 2010 02:08:52 +0000 (10:08 +0800)]
KVM: PPC: fix leakage of error page in kvmppc_patch_dcbz()

Add kvm_release_page_clean() after is_error_page() to avoid
leakage of error page.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Separate emulation context initialization in a separate function
Mohammed Gamal [Sun, 15 Aug 2010 21:47:01 +0000 (00:47 +0300)]
KVM: Separate emulation context initialization in a separate function

The code for initializing the emulation context is duplicated at two
locations (emulate_instruction() and kvm_task_switch()). Separate it
in a separate function and call it from there.

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: add bsf/bsr instruction emulation
Wei Yongjun [Tue, 10 Aug 2010 05:48:22 +0000 (13:48 +0800)]
KVM: x86 emulator: add bsf/bsr instruction emulation

Add bsf/bsr instruction emulation (opcode 0x0f 0xbc~0xbd)

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: Fix emulate_grp3 return values
Mohammed Gamal [Sun, 8 Aug 2010 18:11:38 +0000 (21:11 +0300)]
KVM: x86 emulator: Fix emulate_grp3 return values

This patch lets emulate_grp3() return X86EMUL_* return codes instead
of hardcoded ones.

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: Add unary mul, imul, div, and idiv instructions
Mohammed Gamal [Sun, 8 Aug 2010 18:11:37 +0000 (21:11 +0300)]
KVM: x86 emulator: Add unary mul, imul, div, and idiv instructions

This adds unary mul, imul, div, and idiv instructions (group 3 r/m 4-7).

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: mask group 8 instruction as BitOp
Wei Yongjun [Mon, 9 Aug 2010 03:39:14 +0000 (11:39 +0800)]
KVM: x86 emulator: mask group 8 instruction as BitOp

Mask group 8 instruction as BitOp, so we can share the
code for adjust the source operand.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: do not adjust the address for immediate source
Wei Yongjun [Mon, 9 Aug 2010 03:37:37 +0000 (11:37 +0800)]
KVM: x86 emulator: do not adjust the address for immediate source

adjust the dst address for a register source but not adjust the
address for an immediate source.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: fix negative bit offset BitOp instruction emulation
Wei Yongjun [Mon, 9 Aug 2010 03:34:56 +0000 (11:34 +0800)]
KVM: x86 emulator: fix negative bit offset BitOp instruction emulation

If bit offset operands is a negative number, BitOp instruction
will return wrong value. This patch fix it.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: Add stc instruction (opcode 0xf9)
Mohammed Gamal [Thu, 5 Aug 2010 12:42:49 +0000 (15:42 +0300)]
KVM: x86 emulator: Add stc instruction (opcode 0xf9)

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: using SrcOne for instruction d0/d1 decoding
Wei Yongjun [Wed, 4 Aug 2010 07:38:59 +0000 (15:38 +0800)]
KVM: x86 emulator: using SrcOne for instruction d0/d1 decoding

Using SrcOne for instruction d0/d1 decoding.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: disable writeback when decode dest operand
Wei Yongjun [Wed, 4 Aug 2010 07:38:18 +0000 (15:38 +0800)]
KVM: x86 emulator: disable writeback when decode dest operand

This patch change to disable writeback when decode dest
operand if the dest type is ImplicitOps or not specified.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: use SrcAcc to simplify stos decoding
Wei Yongjun [Wed, 4 Aug 2010 07:36:53 +0000 (15:36 +0800)]
KVM: x86 emulator: use SrcAcc to simplify stos decoding

Use SrcAcc to simplify stos decoding.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce)
Mohammed Gamal [Wed, 4 Aug 2010 11:38:06 +0000 (14:38 +0300)]
KVM: x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce)

This adds support for int instructions to the emulator.

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: Allow accessing IDT via emulator ops
Mohammed Gamal [Wed, 4 Aug 2010 02:44:24 +0000 (05:44 +0300)]
KVM: x86 emulator: Allow accessing IDT via emulator ops

The patch adds a new member get_idt() to x86_emulate_ops.
It also adds a function to get the idt in order to be used by the emulator.

This is needed for real mode interrupt injection and the emulation of int
instructions.

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: simplify two-byte opcode check
Wei Yongjun [Thu, 5 Aug 2010 08:34:39 +0000 (16:34 +0800)]
KVM: x86 emulator: simplify two-byte opcode check

Two-byte opcode always start with 0x0F and the decode flags
of opcode 0xF0 is always 0, so remove dup check.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Move KVM trampolines before __end_interrupts
Alexander Graf [Thu, 29 Jul 2010 13:04:22 +0000 (15:04 +0200)]
KVM: PPC: Move KVM trampolines before __end_interrupts

When using a relocatable kernel we need to make sure that the trampline code
and the interrupt handlers are both copied to low memory. The only way to do
this reliably is to put them in the copied section.

This patch should make relocated kernels work with KVM.

KVM-Stable-Tag
Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Make long relocations be ulong
Alexander Graf [Thu, 29 Jul 2010 13:04:21 +0000 (15:04 +0200)]
KVM: PPC: Make long relocations be ulong

On Book3S KVM we directly expose some asm pointers to C code as
variables. These need to be relocated and thus break on relocatable
kernels.

To make sure we can at least build, let's mark them as long instead
of u32 where 64bit relocations don't work.

This fixes the following build error:

WARNING: 2 bad relocations^M
c000000000008590 R_PPC64_ADDR32    .text+0x4000000000008460^M
c000000000008594 R_PPC64_ADDR32    .text+0x4000000000008598^M

Please keep in mind that actually using KVM on a relocated kernel
might still break. This only fixes the compile problem.

Reported-by: Subrata Modak <subrata@linux.vnet.ibm.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Use MSR_DR for external load_up
Alexander Graf [Thu, 29 Jul 2010 13:04:20 +0000 (15:04 +0200)]
KVM: PPC: Use MSR_DR for external load_up

Book3S_32 requires MSR_DR to be disabled during load_up_xxx while on Book3S_64
it's supposed to be enabled. I misread the code and disabled it in both cases,
potentially breaking the PS3 which has a really small RMA.

This patch makes KVM work on the PS3 again.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Add book3s_32 tlbie flush acceleration
Alexander Graf [Thu, 29 Jul 2010 13:04:19 +0000 (15:04 +0200)]
KVM: PPC: Add book3s_32 tlbie flush acceleration

On Book3s_32 the tlbie instruction flushed effective addresses by the mask
0x0ffff000. This is pretty hard to reflect with a hash that hashes ~0xfff, so
to speed up that target we should also keep a special hash around for it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: correctly check gfn_to_pfn() return value
Gleb Natapov [Thu, 29 Jul 2010 13:04:18 +0000 (15:04 +0200)]
KVM: PPC: correctly check gfn_to_pfn() return value

On failure gfn_to_pfn returns bad_page so use correct function to check
for that.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: RCU'ify the Book3s MMU
Alexander Graf [Thu, 29 Jul 2010 13:04:17 +0000 (15:04 +0200)]
KVM: PPC: RCU'ify the Book3s MMU

So far we've been running all code without locking of any sort. This wasn't
really an issue because I didn't see any parallel access to the shadow MMU
code coming.

But then I started to implement dirty bitmapping to MOL which has the video
code in its own thread, so suddenly we had the dirty bitmap code run in
parallel to the shadow mmu code. And with that came trouble.

So I went ahead and made the MMU modifying functions as parallelizable as
I could think of. I hope I didn't screw up too much RCU logic :-). If you
know your way around RCU and locking and what needs to be done when, please
take a look at this patch.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Book3S_32 MMU debug compile fixes
Alexander Graf [Thu, 29 Jul 2010 13:04:16 +0000 (15:04 +0200)]
KVM: PPC: Book3S_32 MMU debug compile fixes

Due to previous changes, the Book3S_32 guest MMU code didn't compile properly
when enabling debugging.

This patch repairs the broken code paths, making it possible to define DEBUG_MMU
and friends again.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Add get_pvinfo interface to query hypercall instructions
Alexander Graf [Thu, 29 Jul 2010 12:48:08 +0000 (14:48 +0200)]
KVM: PPC: Add get_pvinfo interface to query hypercall instructions

We need to tell the guest the opcodes that make up a hypercall through
interfaces that are controlled by userspace. So we need to add a call
for userspace to allow it to query those opcodes so it can pass them
on.

This is required because the hypercall opcodes can change based on
the hypervisor conditions. If we're running in hardware accelerated
hypervisor mode, a hypercall looks different from when we're running
without hardware acceleration.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Add Documentation about PV interface
Alexander Graf [Thu, 29 Jul 2010 12:48:07 +0000 (14:48 +0200)]
KVM: PPC: Add Documentation about PV interface

We just introduced a new PV interface that screams for documentation. So here
it is - a shiny new and awesome text file describing the internal works of
the PPC KVM paravirtual interface.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: PV wrteei
Alexander Graf [Thu, 29 Jul 2010 12:48:06 +0000 (14:48 +0200)]
KVM: PPC: PV wrteei

On BookE the preferred way to write the EE bit is the wrteei instruction. It
already encodes the EE bit in the instruction.

So in order to get BookE some speedups as well, let's also PV'nize thati
instruction.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: PV mtmsrd L=0 and mtmsr
Alexander Graf [Thu, 29 Jul 2010 12:48:05 +0000 (14:48 +0200)]
KVM: PPC: PV mtmsrd L=0 and mtmsr

There is also a form of mtmsr where all bits need to be addressed. While the
PPC64 Linux kernel behaves resonably well here, on PPC32 we do not have an
L=1 form. It does mtmsr even for simple things like only changing EE.

So we need to hook into that one as well and check for a mask of bits that we
deem safe to change from within guest context.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: PV mtmsrd L=1
Alexander Graf [Thu, 29 Jul 2010 12:48:04 +0000 (14:48 +0200)]
KVM: PPC: PV mtmsrd L=1

The PowerPC ISA has a special instruction for mtmsr that only changes the EE
and RI bits, namely the L=1 form.

Since that one is reasonably often occuring and simple to implement, let's
go with this first. Writing EE=0 is always just a store. Doing EE=1 also
requires us to check for pending interrupts and if necessary exit back to the
hypervisor.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: PV assembler helpers
Alexander Graf [Thu, 29 Jul 2010 12:48:03 +0000 (14:48 +0200)]
KVM: PPC: PV assembler helpers

When we hook an instruction we need to make sure we don't clobber any of
the registers at that point. So we write them out to scratch space in the
magic page. To make sure we don't fall into a race with another piece of
hooked code, we need to disable interrupts.

To make the later patches and code in general easier readable, let's introduce
a set of defines that save and restore r30, r31 and cr. Let's also define some
helpers to read the lower 32 bits of a 64 bit field on 32 bit systems.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Introduce branch patching helper
Alexander Graf [Thu, 29 Jul 2010 12:48:02 +0000 (14:48 +0200)]
KVM: PPC: Introduce branch patching helper

We will need to patch several instruction streams over to a different
code path, so we need a way to patch a single instruction with a branch
somewhere else.

This patch adds a helper to facilitate this patching.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Introduce kvm_tmp framework
Alexander Graf [Thu, 29 Jul 2010 12:48:01 +0000 (14:48 +0200)]
KVM: PPC: Introduce kvm_tmp framework

We will soon require more sophisticated methods to replace single instructions
with multiple instructions. We do that by branching to a memory region where we
write replacement code for the instruction to.

This region needs to be within 32 MB of the patched instruction though, because
that's the furthest we can jump with immediate branches.

So we keep 1MB of free space around in bss. After we're done initing we can just
tell the mm system that the unused pages are free, but until then we have enough
space to fit all our code in.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: PV tlbsync to nop
Alexander Graf [Thu, 29 Jul 2010 12:48:00 +0000 (14:48 +0200)]
KVM: PPC: PV tlbsync to nop

With our current MMU scheme we don't need to know about the tlbsync instruction.
So we can just nop it out.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: PV instructions to loads and stores
Alexander Graf [Thu, 29 Jul 2010 12:47:59 +0000 (14:47 +0200)]
KVM: PPC: PV instructions to loads and stores

Some instructions can simply be replaced by load and store instructions to
or from the magic page.

This patch replaces often called instructions that fall into the above category.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: KVM PV guest stubs
Alexander Graf [Thu, 29 Jul 2010 12:47:58 +0000 (14:47 +0200)]
KVM: PPC: KVM PV guest stubs

We will soon start and replace instructions from the text section with
other, paravirtualized versions. To ease the readability of those patches
I split out the generic looping and magic page mapping code out.

This patch still only contains stubs. But at least it loops through the
text section :).

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Generic KVM PV guest support
Alexander Graf [Thu, 29 Jul 2010 12:47:57 +0000 (14:47 +0200)]
KVM: PPC: Generic KVM PV guest support

We have all the hypervisor pieces in place now, but the guest parts are still
missing.

This patch implements basic awareness of KVM when running Linux as guest. It
doesn't do anything with it yet though.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Move kvm_guest_init out of generic code
Alexander Graf [Thu, 29 Jul 2010 12:47:56 +0000 (14:47 +0200)]
KVM: Move kvm_guest_init out of generic code

Currently x86 is the only architecture that uses kvm_guest_init(). With
PowerPC we're getting a second user, but the signature is different there
and we don't need to export it, as it uses the normal kernel init framework.

So let's move the x86 specific definition of that function over to the x86
specfic header file.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Expose magic page support to guest
Alexander Graf [Thu, 29 Jul 2010 12:47:55 +0000 (14:47 +0200)]
KVM: PPC: Expose magic page support to guest

Now that we have the shared page in place and the MMU code knows about
the magic page, we can expose that capability to the guest!

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Magic Page Book3s support
Alexander Graf [Thu, 29 Jul 2010 12:47:54 +0000 (14:47 +0200)]
KVM: PPC: Magic Page Book3s support

We need to override EA as well as PA lookups for the magic page. When the guest
tells us to project it, the magic page overrides any guest mappings.

In order to reflect that, we need to hook into all the MMU layers of KVM to
force map the magic page if necessary.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: First magic page steps
Alexander Graf [Thu, 29 Jul 2010 12:47:53 +0000 (14:47 +0200)]
KVM: PPC: First magic page steps

We will be introducing a method to project the shared page in guest context.
As soon as we're talking about this coupling, the shared page is colled magic
page.

This patch introduces simple defines, so the follow-up patches are easier to
read.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Make PAM a define
Alexander Graf [Thu, 29 Jul 2010 12:47:52 +0000 (14:47 +0200)]
KVM: PPC: Make PAM a define

On PowerPC it's very normal to not support all of the physical RAM in real mode.
To check if we're matching on the shared page or not, we need to know the limits
so we can restrain ourselves to that range.

So let's make it a define instead of open-coding it. And while at it, let's also
increase it.

Signed-off-by: Alexander Graf <agraf@suse.de>
v2 -> v3:

  - RMO -> PAM (non-magic page)
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Tell guest about pending interrupts
Alexander Graf [Thu, 29 Jul 2010 12:47:51 +0000 (14:47 +0200)]
KVM: PPC: Tell guest about pending interrupts

When the guest turns on interrupts again, it needs to know if we have an
interrupt pending for it. Because if so, it should rather get out of guest
context and get the interrupt.

So we introduce a new field in the shared page that we use to tell the guest
that there's a pending interrupt lying around.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Add PV guest scratch registers
Alexander Graf [Thu, 29 Jul 2010 12:47:50 +0000 (14:47 +0200)]
KVM: PPC: Add PV guest scratch registers

While running in hooked code we need to store register contents out because
we must not clobber any registers.

So let's add some fields to the shared page we can just happily write to.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Add PV guest critical sections
Alexander Graf [Thu, 29 Jul 2010 12:47:49 +0000 (14:47 +0200)]
KVM: PPC: Add PV guest critical sections

When running in hooked code we need a way to disable interrupts without
clobbering any interrupts or exiting out to the hypervisor.

To achieve this, we have an additional critical field in the shared page. If
that field is equal to the r1 register of the guest, it tells the hypervisor
that we're in such a critical section and thus may not receive any interrupts.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Implement hypervisor interface
Alexander Graf [Thu, 29 Jul 2010 12:47:48 +0000 (14:47 +0200)]
KVM: PPC: Implement hypervisor interface

To communicate with KVM directly we need to plumb some sort of interface
between the guest and KVM. Usually those interfaces use hypercalls.

This hypercall implementation is described in the last patch of the series
in a special documentation file. Please read that for further information.

This patch implements stubs to handle KVM PPC hypercalls on the host and
guest side alike.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Convert SPRG[0-4] to shared page
Alexander Graf [Thu, 29 Jul 2010 12:47:47 +0000 (14:47 +0200)]
KVM: PPC: Convert SPRG[0-4] to shared page

When in kernel mode there are 4 additional registers available that are
simple data storage. Instead of exiting to the hypervisor to read and
write those, we can just share them with the guest using the page.

This patch converts all users of the current field to the shared page.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Convert SRR0 and SRR1 to shared page
Alexander Graf [Thu, 29 Jul 2010 12:47:46 +0000 (14:47 +0200)]
KVM: PPC: Convert SRR0 and SRR1 to shared page

The SRR0 and SRR1 registers contain cached values of the PC and MSR
respectively. They get written to by the hypervisor when an interrupt
occurs or directly by the kernel. They are also used to tell the rfi(d)
instruction where to jump to.

Because it only gets touched on defined events that, it's very simple to
share with the guest. Hypervisor and guest both have full r/w access.

This patch converts all users of the current field to the shared page.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Convert DAR to shared page.
Alexander Graf [Thu, 29 Jul 2010 12:47:45 +0000 (14:47 +0200)]
KVM: PPC: Convert DAR to shared page.

The DAR register contains the address a data page fault occured at. This
register behaves pretty much like a simple data storage register that gets
written to on data faults. There is no hypervisor interaction required on
read or write.

This patch converts all users of the current field to the shared page.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Convert DSISR to shared page
Alexander Graf [Thu, 29 Jul 2010 12:47:44 +0000 (14:47 +0200)]
KVM: PPC: Convert DSISR to shared page

The DSISR register contains information about a data page fault. It is fully
read/write from inside the guest context and we don't need to worry about
interacting based on writes of this register.

This patch converts all users of the current field to the shared page.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Convert MSR to shared page
Alexander Graf [Thu, 29 Jul 2010 12:47:43 +0000 (14:47 +0200)]
KVM: PPC: Convert MSR to shared page

One of the most obvious registers to share with the guest directly is the
MSR. The MSR contains the "interrupts enabled" flag which the guest has to
toggle in critical sections.

So in order to bring the overhead of interrupt en- and disabling down, let's
put msr into the shared page. Keep in mind that even though you can fully read
its contents, writing to it doesn't always update all state. There are a few
safe fields that don't require hypervisor interaction. See the documentation
for a list of MSR bits that are safe to be set from inside the guest.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Introduce shared page
Alexander Graf [Thu, 29 Jul 2010 12:47:42 +0000 (14:47 +0200)]
KVM: PPC: Introduce shared page

For transparent variable sharing between the hypervisor and guest, I introduce
a shared page. This shared page will contain all the registers the guest can
read and write safely without exiting guest context.

This patch only implements the stubs required for the basic structure of the
shared page. The actual register moving follows.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: Fix nop emulation
Mohammed Gamal [Wed, 4 Aug 2010 11:41:04 +0000 (14:41 +0300)]
KVM: x86 emulator: Fix nop emulation

If a nop instruction is encountered, we jump directly to the done label.
This skip updating rip. Break from the switch case instead

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: Decode memory operands directly into a 'struct operand'
Avi Kivity [Sun, 1 Aug 2010 12:40:19 +0000 (15:40 +0300)]
KVM: x86 emulator: Decode memory operands directly into a 'struct operand'

Since modrm operand can be either register or memory, decoding it into
a 'struct operand', which can represent both, is simpler.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: change invlpg emulation to use src.mem.addr
Avi Kivity [Sun, 1 Aug 2010 12:19:22 +0000 (15:19 +0300)]
KVM: x86 emulator: change invlpg emulation to use src.mem.addr

Instead of using modrm_ea, which will soon be gone.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: switch LEA to use SrcMem decoding
Avi Kivity [Sun, 1 Aug 2010 12:13:22 +0000 (15:13 +0300)]
KVM: x86 emulator: switch LEA to use SrcMem decoding

The NoAccess flag will prevent memory from being accessed.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: add NoAccess flag for memory instructions that skip access
Avi Kivity [Sun, 1 Aug 2010 12:10:29 +0000 (15:10 +0300)]
KVM: x86 emulator: add NoAccess flag for memory instructions that skip access

Use for INVLPG, which accesses the tlb, not memory.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: use struct operand for mov reg,dr and mov dr,reg for reg op
Avi Kivity [Sun, 1 Aug 2010 11:25:22 +0000 (14:25 +0300)]
KVM: x86 emulator: use struct operand for mov reg,dr and mov dr,reg for reg op

This is an ordinary modrm source or destination; use the standard structure
representing it.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: use struct operand for mov reg,cr and mov cr,reg for reg op
Avi Kivity [Sun, 1 Aug 2010 11:25:22 +0000 (14:25 +0300)]
KVM: x86 emulator: use struct operand for mov reg,cr and mov cr,reg for reg op

This is an ordinary modrm source or destination; use the standard structure
representing it.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: mark mov cr and mov dr as 64-bit instructions in long mode
Avi Kivity [Sun, 1 Aug 2010 11:48:44 +0000 (14:48 +0300)]
KVM: x86 emulator: mark mov cr and mov dr as 64-bit instructions in long mode

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: introduce Op3264 for mov cr and mov dr instructions
Avi Kivity [Sun, 1 Aug 2010 11:46:54 +0000 (14:46 +0300)]
KVM: x86 emulator: introduce Op3264 for mov cr and mov dr instructions

The operands for these instructions are 32 bits or 64 bits, depending on
long mode, and ignoring REX prefixes, or the operand size prefix.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: simplify REX.W check
Avi Kivity [Sun, 1 Aug 2010 11:42:51 +0000 (14:42 +0300)]
KVM: x86 emulator: simplify REX.W check

(x && (x & y)) == (x & y)

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: drop use_modrm_ea
Avi Kivity [Sun, 1 Aug 2010 10:53:19 +0000 (13:53 +0300)]
KVM: x86 emulator: drop use_modrm_ea

Unused (and has never been).

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: put register operand fetch into a function
Avi Kivity [Sun, 1 Aug 2010 09:53:09 +0000 (12:53 +0300)]
KVM: x86 emulator: put register operand fetch into a function

The code is repeated three times, put it into fetch_register_operand()

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: use SrcAcc to simplify xchg decoding
Avi Kivity [Sun, 1 Aug 2010 09:41:59 +0000 (12:41 +0300)]
KVM: x86 emulator: use SrcAcc to simplify xchg decoding

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: simplify xchg decode tables
Avi Kivity [Sun, 1 Aug 2010 09:39:53 +0000 (12:39 +0300)]
KVM: x86 emulator: simplify xchg decode tables

Use X8() to avoid repetition.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: use correct type for memory address in operands
Avi Kivity [Sun, 1 Aug 2010 09:35:10 +0000 (12:35 +0300)]
KVM: x86 emulator: use correct type for memory address in operands

Currently we use a void pointer for memory addresses.  That's wrong since
these are guest virtual addresses which are not directly dereferencable by
the host.

Use the correct type, unsigned long.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: push segment override out of decode_modrm()
Avi Kivity [Sun, 1 Aug 2010 09:07:29 +0000 (12:07 +0300)]
KVM: x86 emulator: push segment override out of decode_modrm()

Let it compute modrm_seg instead, and have the caller apply it.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: SVM: Check for asid != 0 on nested vmrun
Joerg Roedel [Mon, 2 Aug 2010 14:46:45 +0000 (16:46 +0200)]
KVM: SVM: Check for asid != 0 on nested vmrun

This patch lets a nested vmrun fail if the L1 hypervisor
left the asid zero. This fixes the asid_zero unit test.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: SVM: Check for nested vmrun intercept before emulating vmrun
Joerg Roedel [Mon, 2 Aug 2010 14:46:44 +0000 (16:46 +0200)]
KVM: SVM: Check for nested vmrun intercept before emulating vmrun

This patch lets the nested vmrun fail if the L1 hypervisor
has not intercepted vmrun. This fixes the "vmrun intercept
check" unit test.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: mark page dirty only when page is really written
Xiao Guangrong [Mon, 2 Aug 2010 08:15:08 +0000 (16:15 +0800)]
KVM: MMU: mark page dirty only when page is really written

Mark page dirty only when this page is really written, it's more exacter,
and also can fix dirty page marking in speculation path

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: move bits lost judgement into a separate function
Xiao Guangrong [Mon, 2 Aug 2010 08:14:04 +0000 (16:14 +0800)]
KVM: MMU: move bits lost judgement into a separate function

Introduce spte_has_volatile_bits() function to judge whether spte
bits will miss, it's more readable and can help us to cleanup code
later

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: using kvm_set_pfn_accessed() instead of mark_page_accessed()
Xiao Guangrong [Mon, 2 Aug 2010 08:12:08 +0000 (16:12 +0800)]
KVM: MMU: using kvm_set_pfn_accessed() instead of mark_page_accessed()

It's a small cleanup that using using kvm_set_pfn_accessed() instead
of mark_page_accessed()

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: check io permissions only once for string pio
Gleb Natapov [Mon, 2 Aug 2010 09:47:51 +0000 (12:47 +0300)]
KVM: x86 emulator: check io permissions only once for string pio

Do not recheck io permission on every iteration.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: fix LMSW able to clear cr0.pe
Avi Kivity [Sun, 1 Aug 2010 15:35:24 +0000 (18:35 +0300)]
KVM: x86 emulator: fix LMSW able to clear cr0.pe

LMSW is documented not to be able to clear cr0.pe; make it so.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: don't update vcpu state if instruction is restarted
Gleb Natapov [Thu, 29 Jul 2010 12:11:52 +0000 (15:11 +0300)]
KVM: x86 emulator: don't update vcpu state if instruction is restarted

No need to update vcpu state since instruction is in the middle of the
emulation.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert some push instructions to direct decode
Avi Kivity [Thu, 29 Jul 2010 12:11:55 +0000 (15:11 +0300)]
KVM: x86 emulator: convert some push instructions to direct decode

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: allow repeat macro arguments to contain commas
Avi Kivity [Thu, 29 Jul 2010 12:11:54 +0000 (15:11 +0300)]
KVM: x86 emulator: allow repeat macro arguments to contain commas

Needed for repeating instructions with execution functions.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: move decode tables downwards
Avi Kivity [Thu, 29 Jul 2010 12:11:53 +0000 (15:11 +0300)]
KVM: x86 emulator: move decode tables downwards

So they can reference execution functions.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: move x86_decode_insn() downwards
Avi Kivity [Thu, 29 Jul 2010 12:11:52 +0000 (15:11 +0300)]
KVM: x86 emulator: move x86_decode_insn() downwards

No code changes.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>