openwrt/staging/blogic.git
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>
14 years agoKVM: x86 emulator: allow storing emulator execution function in decode tables
Avi Kivity [Thu, 29 Jul 2010 12:11:51 +0000 (15:11 +0300)]
KVM: x86 emulator: allow storing emulator execution function in decode tables

Instead of looking up the opcode twice (once for decode flags, once for
the big execution switch) look up both flags and function in the decode tables.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: store x86_emulate_ops in emulation context
Avi Kivity [Thu, 29 Jul 2010 12:11:50 +0000 (15:11 +0300)]
KVM: x86 emulator: store x86_emulate_ops in emulation context

It doesn't ever change, so we don't need to pass it around everywhere.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: move ByteOp and Dst back to bits 0:3
Avi Kivity [Thu, 29 Jul 2010 12:11:49 +0000 (15:11 +0300)]
KVM: x86 emulator: move ByteOp and Dst back to bits 0:3

Now that the group index no longer exists, the space is free.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: drop support for old-style groups
Avi Kivity [Thu, 29 Jul 2010 12:11:48 +0000 (15:11 +0300)]
KVM: x86 emulator: drop support for old-style groups

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert group 9 to new style
Avi Kivity [Thu, 29 Jul 2010 12:11:47 +0000 (15:11 +0300)]
KVM: x86 emulator: convert group 9 to new style

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert group 8 to new style
Avi Kivity [Thu, 29 Jul 2010 12:11:46 +0000 (15:11 +0300)]
KVM: x86 emulator: convert group 8 to new style

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert group 7 to new style
Avi Kivity [Thu, 29 Jul 2010 12:11:45 +0000 (15:11 +0300)]
KVM: x86 emulator: convert group 7 to new style

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert group 5 to new style
Avi Kivity [Thu, 29 Jul 2010 12:11:44 +0000 (15:11 +0300)]
KVM: x86 emulator: convert group 5 to new style

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert group 4 to new style
Avi Kivity [Thu, 29 Jul 2010 12:11:43 +0000 (15:11 +0300)]
KVM: x86 emulator: convert group 4 to new style

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert group 3 to new style
Avi Kivity [Thu, 29 Jul 2010 12:11:42 +0000 (15:11 +0300)]
KVM: x86 emulator: convert group 3 to new style

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert group 1A to new style
Avi Kivity [Thu, 29 Jul 2010 12:11:41 +0000 (15:11 +0300)]
KVM: x86 emulator: convert group 1A to new style

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: convert group 1 to new style
Avi Kivity [Thu, 29 Jul 2010 12:11:40 +0000 (15:11 +0300)]
KVM: x86 emulator: convert group 1 to new style

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: allow specifying group directly in opcode
Avi Kivity [Thu, 29 Jul 2010 12:11:39 +0000 (15:11 +0300)]
KVM: x86 emulator: allow specifying group directly in opcode

Instead of having a group number, store the group table pointer directly in
the opcode.

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

We'll be using that to distinguish between new-style and old-style groups.

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

No code changes.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: Add wrappers for easily defining opcodes
Avi Kivity [Thu, 29 Jul 2010 12:11:36 +0000 (15:11 +0300)]
KVM: x86 emulator: Add wrappers for easily defining opcodes

Once 'struct opcode' grows, its initializer will become more complicated.
Wrap the simple initializers in a D() macro, and replace the empty initializers
with an even simpler N macro.

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

This will hold all the information known about the opcode.  Currently, this
is just the decode flags.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: drop parentheses in repreat macros
Avi Kivity [Thu, 29 Jul 2010 12:11:34 +0000 (15:11 +0300)]
KVM: x86 emulator: drop parentheses in repreat macros

The parenthese make is impossible to use the macros with initializers that
require braces.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: Add IRET instruction
Mohammed Gamal [Wed, 28 Jul 2010 09:38:40 +0000 (12:38 +0300)]
KVM: x86 emulator: Add IRET instruction

Ths patch adds IRET instruction (opcode 0xcf).
Currently, only IRET in real mode is emulated. Protected mode support is to be added later if needed.

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Reviewed-by: Avi Kivity <avi@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: SVM: Emulate next_rip svm feature
Joerg Roedel [Tue, 27 Jul 2010 16:14:21 +0000 (18:14 +0200)]
KVM: SVM: Emulate next_rip svm feature

This patch implements the emulations of the svm next_rip
feature in the nested svm implementation in kvm.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: SVM: Sync efer back into nested vmcb
Joerg Roedel [Tue, 27 Jul 2010 16:14:20 +0000 (18:14 +0200)]
KVM: SVM: Sync efer back into nested vmcb

This patch fixes a bug in a nested hypervisor that heavily
switches between real-mode and long-mode. The problem is
fixed by syncing back efer into the guest vmcb on emulated
vmexit.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: remove valueless output message
Xiao Guangrong [Tue, 27 Jul 2010 03:21:18 +0000 (11:21 +0800)]
KVM: MMU: remove valueless output message

After commit 53383eaad08d, the '*spte' has updated before call
rmap_remove()(in most case it's 'shadow_trap_nonpresent_pte'), so
remove this information from error message

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: VMX: Use host_gdt variable wherever we need the host gdt
Avi Kivity [Mon, 26 Jul 2010 15:32:39 +0000 (18:32 +0300)]
KVM: VMX: Use host_gdt variable wherever we need the host gdt

Now that we have the host gdt conveniently stored in a variable, make use
of it instead of querying the cpu.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: unify the two Group 3 variants
Avi Kivity [Mon, 26 Jul 2010 11:37:51 +0000 (14:37 +0300)]
KVM: x86 emulator: unify the two Group 3 variants

Use just one group table for byte (F6) and word (F7) opcodes.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: Allow LOCK prefix for NEG and NOT
Avi Kivity [Mon, 26 Jul 2010 11:37:50 +0000 (14:37 +0300)]
KVM: x86 emulator: Allow LOCK prefix for NEG and NOT

Opcodes F6/2, F6/3, F7/2, F7/3.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: simplify Group 1 decoding
Avi Kivity [Mon, 26 Jul 2010 11:37:49 +0000 (14:37 +0300)]
KVM: x86 emulator: simplify Group 1 decoding

Move operand decoding to the opcode table, keep lock decoding in the group
table.  This allows us to get consolidate the four variants of Group 1 into one
group.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: mix decode bits from opcode and group decode tables
Avi Kivity [Mon, 26 Jul 2010 11:37:48 +0000 (14:37 +0300)]
KVM: x86 emulator: mix decode bits from opcode and group decode tables

Allow bits that are common to all members of a group to be specified in the
opcode table instead of the group table.  This allows some simplification
of the decode tables.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: add Undefined decode flag
Avi Kivity [Mon, 26 Jul 2010 11:37:47 +0000 (14:37 +0300)]
KVM: x86 emulator: add Undefined decode flag

Add a decode flag to indicate the instruction is invalid.  Will come in useful
later, when we mix decode bits from the opcode and group table.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: Make group storage bits separate from operand bits
Avi Kivity [Mon, 26 Jul 2010 11:37:46 +0000 (14:37 +0300)]
KVM: x86 emulator: Make group storage bits separate from operand bits

Currently group bits are stored in bits 0:7, where operand bits are stored.

Make group bits be 0:3, and move the existing bits 0:3 to 16:19, so we can
mix group and operand bits.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: consolidate Jcc rel32 decoding
Avi Kivity [Mon, 26 Jul 2010 11:37:45 +0000 (14:37 +0300)]
KVM: x86 emulator: consolidate Jcc rel32 decoding

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: consolidate CMOVcc decoding
Avi Kivity [Mon, 26 Jul 2010 11:37:44 +0000 (14:37 +0300)]
KVM: x86 emulator: consolidate CMOVcc decoding

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: consolidate MOV reg, imm decoding
Avi Kivity [Mon, 26 Jul 2010 11:37:43 +0000 (14:37 +0300)]
KVM: x86 emulator: consolidate MOV reg, imm decoding

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: consolidate Jcc rel8 decoding
Avi Kivity [Mon, 26 Jul 2010 11:37:42 +0000 (14:37 +0300)]
KVM: x86 emulator: consolidate Jcc rel8 decoding

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: consolidate push/pop reg decoding
Avi Kivity [Mon, 26 Jul 2010 11:37:41 +0000 (14:37 +0300)]
KVM: x86 emulator: consolidate push/pop reg decoding

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: consolidate inc/dec reg decoding
Avi Kivity [Mon, 26 Jul 2010 11:37:40 +0000 (14:37 +0300)]
KVM: x86 emulator: consolidate inc/dec reg decoding

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: add macros for repetitive instructions
Avi Kivity [Mon, 26 Jul 2010 11:37:39 +0000 (14:37 +0300)]
KVM: x86 emulator: add macros for repetitive instructions

Some instructions are repetitive in the opcode space, add macros for
consolidating them.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: fix handling for unemulated instructions
Avi Kivity [Sun, 25 Jul 2010 11:51:16 +0000 (14:51 +0300)]
KVM: x86 emulator: fix handling for unemulated instructions

If an instruction is present in the decode tables but not in the execution
switch, it will be emulated as a NOP.  An example is IRET (0xcf).

Fix by adding default: labels to the execution switches.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoMerge branch 'kvm-updates/2.6.36' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Linus Torvalds [Wed, 20 Oct 2010 16:00:44 +0000 (09:00 -0700)]
Merge branch 'kvm-updates/2.6.36' of git://git./virt/kvm/kvm

* 'kvm-updates/2.6.36' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
  KVM: Fix fs/gs reload oops with invalid ldt

14 years agoMerge branch 'drm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
Linus Torvalds [Tue, 19 Oct 2010 17:10:20 +0000 (10:10 -0700)]
Merge branch 'drm-fixes' of git://git./linux/kernel/git/airlied/drm-2.6

* 'drm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6:
  drm/radeon/kms: avivo cursor workaround applies to evergreen as well

14 years agoKVM: Fix fs/gs reload oops with invalid ldt
Avi Kivity [Tue, 19 Oct 2010 14:46:55 +0000 (16:46 +0200)]
KVM: Fix fs/gs reload oops with invalid ldt

kvm reloads the host's fs and gs blindly, however the underlying segment
descriptors may be invalid due to the user modifying the ldt after loading
them.

Fix by using the safe accessors (loadsegment() and load_gs_index()) instead
of home grown unsafe versions.

This is CVE-2010-3698.

KVM-Stable-Tag.
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoMerge branch 'upstream' of git://git.linux-mips.org/pub/scm/upstream-linus
Linus Torvalds [Mon, 18 Oct 2010 20:10:36 +0000 (13:10 -0700)]
Merge branch 'upstream' of git://git.linux-mips.org/upstream-linus

* 'upstream' of git://git.linux-mips.org/pub/scm/upstream-linus:
  MIPS: Enable ISA_DMA_API config to fix build failure
  MIPS: 32-bit: Fix build failure in asm/fcntl.h
  MIPS: Remove all generated vmlinuz* files on "make clean"
  MIPS: do_sigaltstack() expects userland pointers
  MIPS: Fix error values in case of bad_stack
  MIPS: Sanitize restart logics
  MIPS: secure_computing, syscall audit: syscall number should in r2, not r0.
  MIPS: Don't block signals if we'd failed to setup a sigframe

14 years agoMerge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
Linus Torvalds [Mon, 18 Oct 2010 20:10:08 +0000 (13:10 -0700)]
Merge branch 'for-linus' of git://git./linux/kernel/git/dtor/input

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input:
  Input: evdev - fix EVIOCSABS regression
  Input: evdev - fix Ooops in EVIOCGABS/EVIOCSABS

14 years agoMerge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
Linus Torvalds [Mon, 18 Oct 2010 20:09:26 +0000 (13:09 -0700)]
Merge branch 'for-linus' of git://git./linux/kernel/git/ieee1394/linux1394-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6:
  firewire: ohci: fix TI TSB82AA2 regression since 2.6.35

14 years agomxc_nand: do not depend on disabling the irq in the interrupt handler
Sascha Hauer [Mon, 18 Oct 2010 08:16:26 +0000 (10:16 +0200)]
mxc_nand: do not depend on disabling the irq in the interrupt handler

This patch reverts the driver to enabling/disabling the NFC interrupt
mask rather than enabling/disabling the system interrupt.  This cleans
up the driver so that it doesn't rely on interrupts being disabled
within the interrupt handler.

For i.MX21 we keep the current behaviour, that is calling
enable_irq/disable_irq_nosync to enable/disable interrupts.  This patch
is based on earlier work by John Ogness.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: John Ogness <john.ogness@linutronix.de>
Tested-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
14 years agoMerge branch 'for-linus/i2c/2636-rc8' of git://git.fluff.org/bjdooks/linux
Linus Torvalds [Mon, 18 Oct 2010 20:05:10 +0000 (13:05 -0700)]
Merge branch 'for-linus/i2c/2636-rc8' of git://git.fluff.org/bjdooks/linux

* 'for-linus/i2c/2636-rc8' of git://git.fluff.org/bjdooks/linux:
  i2c-imx: do not allow interruptions when waiting for I2C to complete
  i2c-davinci: Fix TX setup for more SoCs

14 years agoMerge branch 'fixes'
Linus Torvalds [Mon, 18 Oct 2010 20:04:33 +0000 (13:04 -0700)]
Merge branch 'fixes'

* fixes:
  v4l1: fix 32-bit compat microcode loading translation
  De-pessimize rds_page_copy_user

14 years agoMIPS: Enable ISA_DMA_API config to fix build failure
Namhyung Kim [Mon, 18 Oct 2010 03:55:21 +0000 (12:55 +0900)]
MIPS: Enable ISA_DMA_API config to fix build failure

Add ISA_DMA_API config item and select it when GENERIC_ISA_DMA enabled.
This fixes build failure on allmodconfig like following:

  CC      sound/isa/es18xx.o
sound/isa/es18xx.c: In function 'snd_es18xx_playback1_prepare':
sound/isa/es18xx.c:501:9: error: implicit declaration of function 'snd_dma_program'
sound/isa/es18xx.c: In function 'snd_es18xx_playback_pointer':
sound/isa/es18xx.c:818:3: error: implicit declaration of function 'snd_dma_pointer'
make[3]: *** [sound/isa/es18xx.o] Error 1
make[2]: *** [sound/isa/es18xx.o] Error 2
make[1]: *** [sub-make] Error 2
make: *** [all] Error 2

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/1717/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
14 years agoMIPS: 32-bit: Fix build failure in asm/fcntl.h
Namhyung Kim [Sun, 17 Oct 2010 16:41:39 +0000 (01:41 +0900)]
MIPS: 32-bit: Fix build failure in asm/fcntl.h

  CC      security/integrity/ima/ima_fs.o
In file included from linux/include/linux/fcntl.h:4:0,
                 from linux/security/integrity/ima/ima_fs.c:18:
linux/arch/mips/include/asm/fcntl.h:63:2: error: expected specifier-qualifier-list before 'off_t'
make[3]: *** [security/integrity/ima/ima_fs.o] Error 1
make[2]: *** [security/integrity/ima/ima_fs.o] Error 2
make[1]: *** [sub-make] Error 2
make: *** [all] Error 2

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/1715/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
14 years agoMIPS: Remove all generated vmlinuz* files on "make clean"
Wu Zhangjin [Wed, 22 Sep 2010 06:03:57 +0000 (14:03 +0800)]
MIPS: Remove all generated vmlinuz* files on "make clean"

[Ralf: I changed the patch to explicitly list all files to be deleted out
of paranoia.]

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
Patchwork: http://patchwork.linux-mips.org/patch/1590/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>