]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/log
linux-2.6-omap-h63xx.git
17 years agoeCryptfs: check readlink result was not an error before using it
Duane Griffin [Fri, 19 Dec 2008 20:47:10 +0000 (20:47 +0000)]
eCryptfs: check readlink result was not an error before using it

The result from readlink is being used to index into the link name
buffer without checking whether it is a valid length. If readlink
returns an error this will fault or cause memory corruption.

Cc: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Cc: Dustin Kirkland <kirkland@canonical.com>
Cc: ecryptfs-devel@lists.launchpad.net
Signed-off-by: Duane Griffin <duaneg@dghda.com>
Acked-by: Michael Halcrow <mhalcrow@us.ibm.com>
Acked-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
17 years agofs/namespace.c: drop code after return
Julia Lawall [Mon, 1 Dec 2008 22:34:51 +0000 (14:34 -0800)]
fs/namespace.c: drop code after return

The extra semicolon serves no purpose.

Signed-off-by: Julia Lawall <julia@diku.dk>
Reviewed-by: Richard Genoud <richard.genoud@gmail.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
17 years agoinclude: linux/fs.h: put declarations in __KERNEL__
Jan Engelhardt [Mon, 1 Dec 2008 22:34:50 +0000 (14:34 -0800)]
include: linux/fs.h: put declarations in __KERNEL__

include/linux/fs.h contains externs for a bunch of variables.  That obviously
belongs under ifdef __KERNEL__.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
17 years agoshrink struct dentry
Nick Piggin [Mon, 1 Dec 2008 08:33:43 +0000 (09:33 +0100)]
shrink struct dentry

struct dentry is one of the most critical structures in the kernel. So it's
sad to see it going neglected.

With CONFIG_PROFILING turned on (which is probably the common case at least
for distros and kernel developers), sizeof(struct dcache) == 208 here
(64-bit). This gives 19 objects per slab.

I packed d_mounted into a hole, and took another 4 bytes off the inline
name length to take the padding out from the end of the structure. This
shinks it to 200 bytes. I could have gone the other way and increased the
length to 40, but I'm aiming for a magic number, read on...

I then got rid of the d_cookie pointer. This shrinks it to 192 bytes. Rant:
why was this ever a good idea? The cookie system should increase its hash
size or use a tree or something if lookups are a problem. Also the "fast
dcookie lookups" in oprofile should be moved into the dcookie code -- how
can oprofile possibly care about the dcookie_mutex? It gets dropped after
get_dcookie() returns so it can't be providing any sort of protection.

At 192 bytes, 21 objects fit into a 4K page, saving about 3MB on my system
with ~140 000 entries allocated. 192 is also a multiple of 64, so we get
nice cacheline alignment on 64 and 32 byte line systems -- any given dentry
will now require 3 cachelines to touch all fields wheras previously it
would require 4.

I know the inline name size was chosen quite carefully, however with the
reduction in cacheline footprint, it should actually be just about as fast
to do a name lookup for a 36 character name as it was before the patch (and
faster for other sizes). The memory footprint savings for names which are
<= 32 or > 36 bytes long should more than make up for the memory cost for
33-36 byte names.

Performance is a feature...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
17 years agofs: reorder struct inotify_device on 64bits to remove padding
Richard Kennedy [Thu, 4 Dec 2008 11:17:47 +0000 (11:17 +0000)]
fs: reorder struct inotify_device on 64bits to remove padding

Reorder struct inotify_device to remove 8 bytes of padding on 64bit
builds, reducing size to 128 bytes . Therefore allocating from a smaller
slab & using one fewer cachelines.

Signed-off-by: Richard Kennedy <richard@rsk.demon.co.uk>
----
Hi,
patch against 2.6.28-rc7.
built & tested on AMDX2 desktop.

I've not been able to send this to the listed inotify maintainers, I
just get mail failures. So I guessed filesystem was the best home for
it, hope that's ok.

regards
Richard
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
17 years agointroduce new LSM hooks where vfsmount is available.
Kentaro Takeda [Wed, 17 Dec 2008 04:24:15 +0000 (13:24 +0900)]
introduce new LSM hooks where vfsmount is available.

Add new LSM hooks for path-based checks.  Call them on directory-modifying
operations at the points where we still know the vfsmount involved.

Signed-off-by: Kentaro Takeda <takedakn@nttdata.co.jp>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Toshiharu Harada <haradats@nttdata.co.jp>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
17 years agoMerge branch 'master' of ../mmc
Pierre Ossman [Wed, 31 Dec 2008 18:56:05 +0000 (19:56 +0100)]
Merge branch 'master' of ../mmc

17 years agommc: warn about voltage mismatches
David Brownell [Wed, 31 Dec 2008 17:50:30 +0000 (09:50 -0800)]
mmc: warn about voltage mismatches

Get rid of a silent failure mode when the MMC/SD host doesn't
support the voltages needed to operate a given card, by
adding a warning.  A 3.3V host and a 3.0V card, for example,
no longer need to mysteriously just not work at all.

This isn't the best diagnostic; ideally it would also tell
what voltage the card and host support (and not just by
dumping the bitmasks).

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agommc_spi: Add support for OpenFirmware bindings
Anton Vorontsov [Tue, 30 Dec 2008 15:15:28 +0000 (18:15 +0300)]
mmc_spi: Add support for OpenFirmware bindings

The support is implemented via platform data accessors, new module
(of_mmc_spi) will be created automatically when the driver compiles
on OpenFirmware platforms. Link-time dependency will load the module
automatically.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agopxamci: fix dma_unmap_sg length
Vernon Sauder [Tue, 30 Dec 2008 00:21:28 +0000 (19:21 -0500)]
pxamci: fix dma_unmap_sg length

dma_unmap_sg should be given the same length as dma_map_sg, not the
value returned from dma_map_sg

Signed-off-by: Vernon Sauder <vsauder@inhand.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agosmack: Add support for unlabeled network hosts and networks
Casey Schaufler [Wed, 31 Dec 2008 17:54:12 +0000 (12:54 -0500)]
smack: Add support for unlabeled network hosts and networks

Add support for unlabeled network hosts and networks.
Relies heavily on Paul Moore's netlabel support.

Creates a new entry in /smack called netlabel. Writes to /smack/netlabel
take the form:

    A.B.C.D LABEL
or
    A.B.C.D/N LABEL

where A.B.C.D is a network address, N is an integer between 0-32,
and LABEL is the Smack label to be used. If /N is omitted /32 is
assumed. N designates the netmask for the address. Entries are
matched by the most specific address/mask pair. 0.0.0.0/0 will
match everything, while 192.168.1.117/32 will match exactly one
host.

A new system label "@", pronounced "web", is defined. Processes
can not be assigned the web label. An address assigned the web
label can be written to by any process, and packets coming from
a web address can be written to any socket. Use of the web label
is a violation of any strict MAC policy, but the web label has
been requested many times.

The nltype entry has been removed from /smack. It did not work right
and the netlabel interface can be used to specify that all hosts
be treated as unlabeled.

CIPSO labels on incoming packets will be honored, even from designated
single label hosts. Single label hosts can only be written to by
processes with labels that can write to the label of the host.
Packets sent to single label hosts will always be unlabeled.

Once added a single label designation cannot be removed, however
the label may be changed.

The behavior of the ambient label remains unchanged.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Paul Moore <paul.moore@hp.com>
17 years agoselinux: Deprecate and schedule the removal of the the compat_net functionality
Paul Moore [Wed, 31 Dec 2008 17:54:11 +0000 (12:54 -0500)]
selinux: Deprecate and schedule the removal of the the compat_net functionality

This patch is the first step towards removing the old "compat_net" code from
the kernel.  Secmark, the "compat_net" replacement was first introduced in
2.6.18 (September 2006) and the major Linux distributions with SELinux support
have transitioned to Secmark so it is time to start deprecating the "compat_net"
mechanism.  Testing a patched version of 2.6.28-rc6 with the initial release of
Fedora Core 5 did not show any problems when running in enforcing mode.

This patch adds an entry to the feature-removal-schedule.txt file and removes
the SECURITY_SELINUX_ENABLE_SECMARK_DEFAULT configuration option, forcing
Secmark on by default although it can still be disabled at runtime.  The patch
also makes the Secmark permission checks "dynamic" in the sense that they are
only executed when Secmark is configured; this should help prevent problems
with older distributions that have not yet migrated to Secmark.

Signed-off-by: Paul Moore <paul.moore@hp.com>
Acked-by: James Morris <jmorris@namei.org>
17 years agonetlabel: Update kernel configuration API
Paul Moore [Wed, 31 Dec 2008 17:54:11 +0000 (12:54 -0500)]
netlabel: Update kernel configuration API

Update the NetLabel kernel API to expose the new features added in kernel
releases 2.6.25 and 2.6.28: the static/fallback label functionality and network
address based selectors.

Signed-off-by: Paul Moore <paul.moore@hp.com>
17 years agommc_block: ensure all sectors that do not have errors are read
Adrian Hunter [Wed, 31 Dec 2008 17:21:17 +0000 (18:21 +0100)]
mmc_block: ensure all sectors that do not have errors are read

If a card encounters an ECC error while reading a sector it will
timeout.  Instead of reporting the entire I/O request as having
an error, redo the I/O one sector at a time so that all readable
sectors are provided to the upper layers.

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agodrivers/mmc: Move a dereference below a NULL test
Julia Lawall [Tue, 16 Dec 2008 15:13:09 +0000 (16:13 +0100)]
drivers/mmc: Move a dereference below a NULL test

In each case, if the NULL test is necessary, then the dereference should be
moved below the NULL test.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
type T;
expression E;
identifier i,fld;
statement S;
@@

- T i = E->fld;
+ T i;
  ... when != E
      when != i
  if (E == NULL) S
+ i = E->fld;
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agosdhci: handle built-in sdhci with modular leds class
Pierre Ossman [Sun, 21 Dec 2008 16:01:48 +0000 (17:01 +0100)]
sdhci: handle built-in sdhci with modular leds class

As reported by Randy Dunlap, having sdhci built-in and LEDs class
as a module resulted in undefined symbols. Change the code to handle
that case properly (by not having LEDs class support in sdhci).

Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agommc: balanc pci_iomap with pci_iounmap
Roel Kluin [Sat, 13 Dec 2008 20:21:33 +0000 (21:21 +0100)]
mmc: balanc pci_iomap with pci_iounmap

balance pci_iomap with pci_iounmap, not iounmap

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agommc_block: print better error messages
Adrian Hunter [Thu, 16 Oct 2008 09:55:25 +0000 (12:55 +0300)]
mmc_block: print better error messages

Add command response and card status to error
messages.

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agommc: Add mmc_vddrange_to_ocrmask() helper function
Anton Vorontsov [Wed, 26 Nov 2008 19:54:17 +0000 (22:54 +0300)]
mmc: Add mmc_vddrange_to_ocrmask() helper function

This function sets the OCR mask bits according to provided voltage
ranges. Will be used by the mmc_spi OpenFirmware bindings.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agoricoh_mmc: Handle newer models of Ricoh controllers
philipl@overt.org [Mon, 1 Dec 2008 01:27:50 +0000 (20:27 -0500)]
ricoh_mmc: Handle newer models of Ricoh controllers

The latest generation of laptops are shipping with a newer
model of Ricoh chip where the firewire controller is the
primary PCI function but a cardbus controller is also present.

The existing code assumes that if a cardbus controller is,
present, then it must be the one to manipulate - but the real
rule is that you manipulate PCI function 0. This patch adds an
additional constraint that the target must be function 0.

Signed-off-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agommc: Add 8-bit bus width support
Jarkko Lavinen [Mon, 17 Nov 2008 12:35:21 +0000 (14:35 +0200)]
mmc: Add 8-bit bus width support

Signed-off-by: Jarkko Lavinen <jarkko.lavinen@nokia.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agosdhci: activate led support also when module
Éric Piel [Sat, 22 Nov 2008 18:29:29 +0000 (19:29 +0100)]
sdhci: activate led support also when module

CONFIG_LEDS_CLASS is defined only if led-class is built-in, otherwise
when it is a module the option is called CONFIG_LEDS_CLASS_MODULE. Led
support should also be activated in this case.

Signed-off-by: Eric Piel <eric.piel@tremplin-utc.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agommc: trivial annotation of 'blocks'
Harvey Harrison [Thu, 23 Oct 2008 00:09:00 +0000 (17:09 -0700)]
mmc: trivial annotation of 'blocks'

sg_init_one is reading a be32, annotate as such.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agopci: use pci_ioremap_bar() in drivers/mmc
Arjan van de Ven [Sun, 28 Sep 2008 23:15:56 +0000 (16:15 -0700)]
pci: use pci_ioremap_bar() in drivers/mmc

Use the new pci_ioremap_bar() function in drivers/mmc.
pci_ioremap_bar() just takes a pci device and a bar number, with the goal
of making it really hard to get wrong, while also having a central place
to stick sanity checks.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
17 years agoMerge branch 'irq-fixes-for-linus-4' of git://git.kernel.org/pub/scm/linux/kernel...
Linus Torvalds [Wed, 31 Dec 2008 17:00:59 +0000 (09:00 -0800)]
Merge branch 'irq-fixes-for-linus-4' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'irq-fixes-for-linus-4' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  sparseirq: move __weak symbols into separate compilation unit
  sparseirq: work around __weak alias bug
  sparseirq: fix hang with !SPARSE_IRQ
  sparseirq: set lock_class for legacy irq when sparse_irq is selected
  sparseirq: work around compiler optimizing away __weak functions
  sparseirq: fix desc->lock init
  sparseirq: do not printk when migrating IRQ descriptors
  sparseirq: remove duplicated arch_early_irq_init()
  irq: simplify for_each_irq_desc() usage
  proc: remove ifdef CONFIG_SPARSE_IRQ from stat.c
  irq: for_each_irq_desc() move to irqnr.h
  hrtimer: remove #include <linux/irq.h>

17 years ago[WATCHDOG] Add support for the WM8350 watchdog
Mark Brown [Thu, 6 Nov 2008 10:56:21 +0000 (10:56 +0000)]
[WATCHDOG] Add support for the WM8350 watchdog

This driver implements support for the watchdog functionality provided
by the Wolfson Microelectronics WM8350, a multi-function audio and
power management subsystem intended for use in embedded systems. It is
based on a driver originally written by Graeme Gregory, though it has
been extensively modified since then.

Use of a GPIO to kick the watchdog is not yet supported.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
17 years ago[WATCHDOG] Add SMSC SCH311x Watchdog Timer.
Wim Van Sebroeck [Wed, 22 Oct 2008 08:59:25 +0000 (08:59 +0000)]
[WATCHDOG] Add SMSC SCH311x Watchdog Timer.

Add a watchdog driver for the hardware watchdog timer on the
SMSC SCH3112, SCH3114 and SCH3116 Super IO chipset.

Tested-by: Marco Chiappero <marco@absence.it>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
17 years ago[WATCHDOG] ib700wdt - add timeout parameter
Wim Van Sebroeck [Wed, 15 Oct 2008 11:44:40 +0000 (11:44 +0000)]
[WATCHDOG] ib700wdt - add timeout parameter

Add the timeout module parameter to ib700wdt.c

Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
17 years agoKVM: MMU: handle large host sptes on invlpg/resync
Marcelo Tosatti [Mon, 22 Dec 2008 20:49:30 +0000 (18:49 -0200)]
KVM: MMU: handle large host sptes on invlpg/resync

The invlpg and sync walkers lack knowledge of large host sptes,
descending to non-existant pagetable level.

Stop at directory level in such case.

Fixes SMP Windows XP with hugepages.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Add locking to virtual i8259 interrupt controller
Avi Kivity [Sun, 21 Dec 2008 20:48:32 +0000 (22:48 +0200)]
KVM: Add locking to virtual i8259 interrupt controller

While most accesses to the i8259 are with the kvm mutex taken, the call
to kvm_pic_read_irq() is not.  We can't easily take the kvm mutex there
since the function is called with interrupts disabled.

Fix by adding a spinlock to the virtual interrupt controller.  Since we
can't send an IPI under the spinlock (we also take the same spinlock in
an irq disabled context), we defer the IPI until the spinlock is released.
Similarly, we defer irq ack notifications until after spinlock release to
avoid lock recursion.

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: MMU: Don't treat a global pte as such if cr4.pge is cleared
Avi Kivity [Sun, 21 Dec 2008 16:31:10 +0000 (18:31 +0200)]
KVM: MMU: Don't treat a global pte as such if cr4.pge is cleared

The pte.g bit is meaningless if global pages are disabled; deferring
mmu page synchronization on these ptes will lead to the guest using stale
shadow ptes.

Fixes Vista x86 smp bootloader failure.

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoMAINTAINERS: Maintainership changes for kvm/ia64
Xiantao Zhang [Wed, 17 Dec 2008 01:38:14 +0000 (09:38 +0800)]
MAINTAINERS: Maintainership changes for kvm/ia64

Anthony Xu no longer works on kvm.

Cc: "Luck, Tony" <tony.luck@intel.com>
Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ia64: Fix kvm_arch_vcpu_ioctl_[gs]et_regs()
Jes Sorensen [Tue, 16 Dec 2008 15:45:47 +0000 (16:45 +0100)]
KVM: ia64: Fix kvm_arch_vcpu_ioctl_[gs]et_regs()

Fix kvm_arch_vcpu_ioctl_[gs]et_regs() to do something meaningful on
ia64. Old versions could never have worked since they required
pointers to be set in the ioctl payload which were never being set by
the ioctl handler for get_regs.

In addition reserve extra space for future extensions.

The change of layout of struct kvm_regs doesn't require adding a new
CAP since get/set regs never worked on ia64 until now.

This version doesn't support copying the KVM kernel stack in/out of
the kernel. This should be implemented in a seperate ioctl call if
ever needed.

Signed-off-by: Jes Sorensen <jes@sgi.com>
Acked-by : Xiantao Zhang <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86: Rework user space NMI injection as KVM_CAP_USER_NMI
Jan Kiszka [Thu, 11 Dec 2008 15:54:54 +0000 (16:54 +0100)]
KVM: x86: Rework user space NMI injection as KVM_CAP_USER_NMI

There is no point in doing the ready_for_nmi_injection/
request_nmi_window dance with user space. First, we don't do this for
in-kernel irqchip anyway, while the code path is the same as for user
space irqchip mode. And second, there is nothing to loose if a pending
NMI is overwritten by another one (in contrast to IRQs where we have to
save the number). Actually, there is even the risk of raising spurious
NMIs this way because the reason for the held-back NMI might already be
handled while processing the first one.

Therefore this patch creates a simplified user space NMI injection
interface, exporting it under KVM_CAP_USER_NMI and dropping the old
KVM_CAP_NMI capability. And this time we also take care to provide the
interface only on archs supporting NMIs via KVM (right now only x86).

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: VMX: Fix pending NMI-vs.-IRQ race for user space irqchip
Jan Kiszka [Mon, 24 Nov 2008 11:26:19 +0000 (12:26 +0100)]
KVM: VMX: Fix pending NMI-vs.-IRQ race for user space irqchip

As with the kernel irqchip, don't allow an NMI to stomp over an already
injected IRQ; instead wait for the IRQ injection to be completed.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: fix handling of ACK from shared guest IRQ
Mark McLoughlin [Tue, 2 Dec 2008 12:16:33 +0000 (12:16 +0000)]
KVM: fix handling of ACK from shared guest IRQ

If an assigned device shares a guest irq with an emulated
device then we currently interpret an ack generated by the
emulated device as originating from the assigned device
leading to e.g. "Unbalanced enable for IRQ 4347" from the
enable_irq() in kvm_assigned_dev_ack_irq().

The fix is fairly simple - don't enable the physical device
irq unless it was previously disabled.

Of course, this can still lead to a situation where a
non-assigned device ACK can cause the physical device irq to
be reenabled before the device was serviced. However, being
level sensitive, the interrupt will merely be regenerated.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: MMU: check for present pdptr shadow page in walk_shadow
Marcelo Tosatti [Tue, 9 Dec 2008 15:07:22 +0000 (16:07 +0100)]
KVM: MMU: check for present pdptr shadow page in walk_shadow

walk_shadow assumes the caller verified validity of the pdptr pointer in
question, which is not the case for the invlpg handler.

Fixes oops during Solaris 10 install.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Consolidate userspace memory capability reporting into common code
Avi Kivity [Mon, 8 Dec 2008 16:29:29 +0000 (18:29 +0200)]
KVM: Consolidate userspace memory capability reporting into common code

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Advertise the bug in memory region destruction as fixed
Avi Kivity [Mon, 8 Dec 2008 16:25:27 +0000 (18:25 +0200)]
KVM: Advertise the bug in memory region destruction as fixed

Userspace might need to act differently.

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: use cpumask_var_t for cpus_hardware_enabled
Rusty Russell [Sun, 7 Dec 2008 10:55:45 +0000 (21:25 +1030)]
KVM: use cpumask_var_t for cpus_hardware_enabled

This changes cpus_hardware_enabled from a cpumask_t to a cpumask_var_t:
equivalent for CONFIG_CPUMASKS_OFFSTACK=n, otherwise dynamically allocated.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: use modern cpumask primitives, no cpumask_t on stack
Rusty Russell [Mon, 8 Dec 2008 09:58:04 +0000 (20:28 +1030)]
KVM: use modern cpumask primitives, no cpumask_t on stack

We're getting rid on on-stack cpumasks for large NR_CPUS.

1) Use cpumask_var_t/alloc_cpumask_var.
2) smp_call_function_mask -> smp_call_function_many
3) cpus_clear, cpus_empty, cpu_set -> cpumask_clear, cpumask_empty,
   cpumask_set_cpu.

This actually generates slightly smaller code than the old one with
CONFIG_CPUMASKS_OFFSTACK=n.  (gcc knows that cpus cannot be NULL in
that case, where cpumask_var_t is cpumask_t[1]).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Extract core of kvm_flush_remote_tlbs/kvm_reload_remote_mmus
Rusty Russell [Mon, 8 Dec 2008 09:56:24 +0000 (20:26 +1030)]
KVM: Extract core of kvm_flush_remote_tlbs/kvm_reload_remote_mmus

Avi said:
> Wow, code duplication from Rusty. Things must be bad.

Something about glass houses comes to mind.  But instead, a patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: set owner of cpu and vm file operations
Christian Borntraeger [Tue, 2 Dec 2008 10:17:32 +0000 (11:17 +0100)]
KVM: set owner of cpu and vm file operations

There is a race between a "close of the file descriptors" and module
unload in the kvm module.

You can easily trigger this problem by applying this debug patch:
>--- kvm.orig/virt/kvm/kvm_main.c
>+++ kvm/virt/kvm/kvm_main.c
>@@ -648,10 +648,14 @@ void kvm_free_physmem(struct kvm *kvm)
>                kvm_free_physmem_slot(&kvm->memslots[i], NULL);
> }
>
>+#include <linux/delay.h>
> static void kvm_destroy_vm(struct kvm *kvm)
> {
>        struct mm_struct *mm = kvm->mm;
>
>+       printk("off1\n");
>+       msleep(5000);
>+       printk("off2\n");
>        spin_lock(&kvm_lock);
>        list_del(&kvm->vm_list);
>        spin_unlock(&kvm_lock);

and killing the userspace, followed by an rmmod.

The problem is that kvm_destroy_vm can run while the module count
is 0. That means, you can remove the module while kvm_destroy_vm
is running. But kvm_destroy_vm is part of the module text. This
causes a kerneloops. The race exists without the msleep but is much
harder to trigger.

This patch requires the fix for anon_inodes (anon_inodes: use fops->owner
for module refcount).
With this patch, we can set the owner of all anonymous KVM inodes file
operations. The VFS will then control the KVM module refcount as long as there
is an open file. kvm_destroy_vm will be called by the release function of the
last closed file - before the VFS drops the module refcount.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoanon_inodes: use fops->owner for module refcount
Christian Borntraeger [Tue, 2 Dec 2008 10:16:03 +0000 (11:16 +0100)]
anon_inodes: use fops->owner for module refcount

There is an imbalance for anonymous inodes. If the fops->owner field is set,
the module reference count of owner is decreases on release.
("filp_close" --> "__fput" ---> "fops_put")

On the other hand, anon_inode_getfd does not increase the module reference
count of owner. This causes two problems:

- if owner is set, the module refcount goes negative
- if owner is not set, the module can be unloaded while code is running

This patch changes anon_inode_getfd to be symmetric regarding fops->owner
handling.

I have checked all existing users of anon_inode_getfd. Noone sets fops->owner,
thats why nobody has seen the module refcount negative. The refcounting was
tested with a patched and unpatched KVM module.(see patch 2/2) I also did an
epoll_open/close test.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Davide Libenzi <davidel@xmailserver.org>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agox86: KVM guest: kvm_get_tsc_khz: return khz, not lpj
Eduardo Habkost [Fri, 5 Dec 2008 20:36:45 +0000 (18:36 -0200)]
x86: KVM guest: kvm_get_tsc_khz: return khz, not lpj

kvm_get_tsc_khz() currently returns the previously-calculated preset_lpj
value, but it is in loops-per-jiffy, not kHz. The current code works
correctly only when HZ=1000.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: MMU: prepopulate the shadow on invlpg
Marcelo Tosatti [Tue, 2 Dec 2008 00:32:05 +0000 (22:32 -0200)]
KVM: MMU: prepopulate the shadow on invlpg

If the guest executes invlpg, peek into the pagetable and attempt to
prepopulate the shadow entry.

Also stop dirty fault updates from interfering with the fork detector.

2% improvement on RHEL3/AIM7.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: MMU: skip global pgtables on sync due to cr3 switch
Marcelo Tosatti [Tue, 2 Dec 2008 00:32:04 +0000 (22:32 -0200)]
KVM: MMU: skip global pgtables on sync due to cr3 switch

Skip syncing global pages on cr3 switch (but not on cr4/cr0). This is
important for Linux 32-bit guests with PAE, where the kmap page is
marked as global.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: MMU: collapse remote TLB flushes on root sync
Marcelo Tosatti [Tue, 2 Dec 2008 00:32:03 +0000 (22:32 -0200)]
KVM: MMU: collapse remote TLB flushes on root sync

Collapse remote TLB flushes on root sync.

kernbench is 2.7% faster on 4-way guest. Improvements have been seen
with other loads such as AIM7.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: MMU: use page array in unsync walk
Marcelo Tosatti [Tue, 2 Dec 2008 00:32:02 +0000 (22:32 -0200)]
KVM: MMU: use page array in unsync walk

Instead of invoking the handler directly collect pages into
an array so the caller can work with it.

Simplifies TLB flush collapsing.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: Fix handling of VMMCALL instruction
Amit Shah [Thu, 4 Dec 2008 11:11:40 +0000 (11:11 +0000)]
KVM: x86 emulator: Fix handling of VMMCALL instruction

The VMMCALL instruction doesn't get recognised and isn't processed
by the emulator.

This is seen on an Intel host that tries to execute the VMMCALL
instruction after a guest live migrates from an AMD host.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: add the emulation of shld and shrd instructions
Guillaume Thouvenin [Thu, 4 Dec 2008 13:30:13 +0000 (14:30 +0100)]
KVM: x86 emulator: add the emulation of shld and shrd instructions

Add emulation of shld and shrd instructions

Signed-off-by: Guillaume Thouvenin <guillaume.thouvenin@ext.bull.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: add the assembler code for three operands
Guillaume Thouvenin [Thu, 4 Dec 2008 13:29:00 +0000 (14:29 +0100)]
KVM: x86 emulator: add the assembler code for three operands

Add the assembler code for instruction with three operands and one
operand is stored in ECX register

Signed-off-by: Guillaume Thouvenin <guillaume.thouvenin@ext.bull.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: add a new "implied 1" Src decode type
Guillaume Thouvenin [Thu, 4 Dec 2008 13:27:38 +0000 (14:27 +0100)]
KVM: x86 emulator: add a new "implied 1" Src decode type

Add SrcOne operand type when we need to decode an implied '1' like with
regular shift instruction

Signed-off-by: Guillaume Thouvenin <guillaume.thouvenin@ext.bull.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: add Src2 decode set
Guillaume Thouvenin [Thu, 4 Dec 2008 13:26:42 +0000 (14:26 +0100)]
KVM: x86 emulator: add Src2 decode set

Instruction like shld has three operands, so we need to add a Src2
decode set. We start with Src2None, Src2CL, and Src2ImmByte, Src2One to
support shld/shrd and we will expand it later.

Signed-off-by: Guillaume Thouvenin <guillaume.thouvenin@ext.bull.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: Extend the opcode descriptor
Guillaume Thouvenin [Thu, 4 Dec 2008 13:25:38 +0000 (14:25 +0100)]
KVM: x86 emulator: Extend the opcode descriptor

Extend the opcode descriptor to 32 bits. This is needed by the
introduction of a new Src2 operand type.

Signed-off-by: Guillaume Thouvenin <guillaume.thouvenin@ext.bull.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Really remove a slot when a user ask us so
Glauber Costa [Wed, 3 Dec 2008 15:40:51 +0000 (13:40 -0200)]
KVM: Really remove a slot when a user ask us so

Right now, KVM does not remove a slot when we do a
register ioctl for size 0 (would be the expected behaviour).

Instead, we only mark it as empty, but keep all bitmaps
and allocated data structures present. It completely
nullifies our chances of reusing that same slot again
for mapping a different piece of memory.

In this patch, we destroy rmaps, and vfree() the
pointers that used to hold the dirty bitmap, rmap
and lpage_info structures.

Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ppc: mostly cosmetic updates to the exit timing accounting code
Hollis Blanchard [Tue, 2 Dec 2008 21:51:58 +0000 (15:51 -0600)]
KVM: ppc: mostly cosmetic updates to the exit timing accounting code

The only significant changes were to kvmppc_exit_timing_write() and
kvmppc_exit_timing_show(), both of which were dramatically simplified.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ppc: Implement in-kernel exit timing statistics
Hollis Blanchard [Tue, 2 Dec 2008 21:51:57 +0000 (15:51 -0600)]
KVM: ppc: Implement in-kernel exit timing statistics

Existing KVM statistics are either just counters (kvm_stat) reported for
KVM generally or trace based aproaches like kvm_trace.
For KVM on powerpc we had the need to track the timings of the different exit
types. While this could be achieved parsing data created with a kvm_trace
extension this adds too much overhead (at least on embedded PowerPC) slowing
down the workloads we wanted to measure.

Therefore this patch adds a in-kernel exit timing statistic to the powerpc kvm
code. These statistic is available per vm&vcpu under the kvm debugfs directory.
As this statistic is low, but still some overhead it can be enabled via a
.config entry and should be off by default.

Since this patch touched all powerpc kvm_stat code anyway this code is now
merged and simplified together with the exit timing statistic code (still
working with exit timing disabled in .config).

Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ppc: save and restore guest mappings on context switch
Hollis Blanchard [Tue, 2 Dec 2008 21:51:56 +0000 (15:51 -0600)]
KVM: ppc: save and restore guest mappings on context switch

Store shadow TLB entries in memory, but only use it on host context switch
(instead of every guest entry). This improves performance for most workloads on
440 by reducing the guest TLB miss rate.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ppc: directly insert shadow mappings into the hardware TLB
Hollis Blanchard [Tue, 2 Dec 2008 21:51:55 +0000 (15:51 -0600)]
KVM: ppc: directly insert shadow mappings into the hardware TLB

Formerly, we used to maintain a per-vcpu shadow TLB and on every entry to the
guest would load this array into the hardware TLB. This consumed 1280 bytes of
memory (64 entries of 16 bytes plus a struct page pointer each), and also
required some assembly to loop over the array on every entry.

Instead of saving a copy in memory, we can just store shadow mappings directly
into the hardware TLB, accepting that the host kernel will clobber these as
part of the normal 440 TLB round robin. When we do that we need less than half
the memory, and we have decreased the exit handling time for all guest exits,
at the cost of increased number of TLB misses because the host overwrites some
guest entries.

These savings will be increased on processors with larger TLBs or which
implement intelligent flush instructions like tlbivax (which will avoid the
need to walk arrays in software).

In addition to that and to the code simplification, we have a greater chance of
leaving other host userspace mappings in the TLB, instead of forcing all
subsequent tasks to re-fault all their mappings.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agopowerpc/44x: declare tlb_44x_index for use in C code
Hollis Blanchard [Tue, 2 Dec 2008 21:51:54 +0000 (15:51 -0600)]
powerpc/44x: declare tlb_44x_index for use in C code

KVM currently ignores the host's round robin TLB eviction selection, instead
maintaining its own TLB state and its own round robin index. However, by
participating in the normal 44x TLB selection, we can drop the alternate TLB
processing in KVM. This results in a significant performance improvement,
since that processing currently must be done on *every* guest exit.

Accordingly, KVM needs to be able to access and increment tlb_44x_index.
(KVM on 440 cannot be a module, so there is no need to export this symbol.)

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Acked-by: Josh Boyer <jwboyer@linux.vnet.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ppc: support large host pages
Hollis Blanchard [Tue, 2 Dec 2008 21:51:53 +0000 (15:51 -0600)]
KVM: ppc: support large host pages

KVM on 440 has always been able to handle large guest mappings with 4K host
pages -- we must, since the guest kernel uses 256MB mappings.

This patch makes KVM work when the host has large pages too (tested with 64K).

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: split out kvm_free_assigned_irq()
Mark McLoughlin [Mon, 1 Dec 2008 13:57:49 +0000 (13:57 +0000)]
KVM: split out kvm_free_assigned_irq()

Split out the logic corresponding to undoing assign_irq() and
clean it up a bit.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: add KVM_USERSPACE_IRQ_SOURCE_ID assertions
Mark McLoughlin [Mon, 1 Dec 2008 13:57:48 +0000 (13:57 +0000)]
KVM: add KVM_USERSPACE_IRQ_SOURCE_ID assertions

Make sure kvm_request_irq_source_id() never returns
KVM_USERSPACE_IRQ_SOURCE_ID.

Likewise, check that kvm_free_irq_source_id() never accepts
KVM_USERSPACE_IRQ_SOURCE_ID.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: don't free an unallocated irq source id
Mark McLoughlin [Mon, 1 Dec 2008 13:57:47 +0000 (13:57 +0000)]
KVM: don't free an unallocated irq source id

Set assigned_dev->irq_source_id to -1 so that we can avoid freeing
a source ID which we never allocated.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: make kvm_unregister_irq_ack_notifier() safe
Mark McLoughlin [Mon, 1 Dec 2008 13:57:46 +0000 (13:57 +0000)]
KVM: make kvm_unregister_irq_ack_notifier() safe

We never pass a NULL notifier pointer here, but we may well
pass a notifier struct which hasn't previously been
registered.

Guard against this by using hlist_del_init() which will
not do anything if the node hasn't been added to the list
and, when removing the node, will ensure that a subsequent
call to hlist_del_init() will be fine too.

Fixes an oops seen when an assigned device is freed before
and IRQ is assigned to it.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: remove the IRQ ACK notifier assertions
Mark McLoughlin [Mon, 1 Dec 2008 13:57:45 +0000 (13:57 +0000)]
KVM: remove the IRQ ACK notifier assertions

We will obviously never pass a NULL struct kvm_irq_ack_notifier* to
this functions. They are always embedded in the assigned device
structure, so the assertion add nothing.

The irqchip_in_kernel() assertion is very out of place - clearly
this little abstraction needs to know nothing about the upper
layer details.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: VMX: fix sparse warning
Hannes Eder [Fri, 28 Nov 2008 16:02:06 +0000 (17:02 +0100)]
KVM: VMX: fix sparse warning

Impact: make global function static

  arch/x86/kvm/vmx.c:134:3: warning: symbol 'vmx_capability' was not declared. Should it be static?

Signed-off-by: Hannes Eder <hannes@hanneseder.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: fix sparse warning
Hannes Eder [Fri, 28 Nov 2008 16:02:42 +0000 (17:02 +0100)]
KVM: fix sparse warning

Impact: make global function static

  virt/kvm/kvm_main.c:85:6: warning: symbol 'kvm_rebooting' was not declared. Should it be static?

Signed-off-by: Hannes Eder <hannes@hanneseder.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Remove extraneous semicolon after do/while
Avi Kivity [Sat, 29 Nov 2008 18:38:12 +0000 (20:38 +0200)]
KVM: Remove extraneous semicolon after do/while

Notices by Guillaume Thouvenin.

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: fix popf emulation
Avi Kivity [Sat, 29 Nov 2008 18:36:13 +0000 (20:36 +0200)]
KVM: x86 emulator: fix popf emulation

Set operand type and size to get correct writeback behavior.

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: fix ret emulation
Avi Kivity [Thu, 27 Nov 2008 22:14:07 +0000 (00:14 +0200)]
KVM: x86 emulator: fix ret emulation

'ret' did not set the operand type or size for the destination, so
writeback ignored it.

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: switch 'pop reg' instruction to emulate_pop()
Avi Kivity [Thu, 27 Nov 2008 16:06:33 +0000 (18:06 +0200)]
KVM: x86 emulator: switch 'pop reg' instruction to emulate_pop()

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: allow pop from mmio
Avi Kivity [Thu, 27 Nov 2008 16:00:28 +0000 (18:00 +0200)]
KVM: x86 emulator: allow pop from mmio

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: Extract 'pop' sequence into a function
Avi Kivity [Thu, 27 Nov 2008 15:36:41 +0000 (17:36 +0200)]
KVM: x86 emulator: Extract 'pop' sequence into a function

Switch 'pop r/m' instruction to use the new function.

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Prevent trace call into unloaded module text
Wu Fengguang [Wed, 26 Nov 2008 11:59:06 +0000 (19:59 +0800)]
KVM: Prevent trace call into unloaded module text

Add marker_synchronize_unregister() before module unloading.
This prevents possible trace calls into unloaded module text.

Signed-off-by: Wu Fengguang <wfg@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: s390: Fix memory leak of vcpu->run
Christian Borntraeger [Wed, 26 Nov 2008 13:51:08 +0000 (14:51 +0100)]
KVM: s390: Fix memory leak of vcpu->run

The s390 backend of kvm never calls kvm_vcpu_uninit. This causes
a memory leak of vcpu->run pages.
Lets call kvm_vcpu_uninit in kvm_arch_vcpu_destroy to free
the vcpu->run.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: s390: Fix refcounting and allow module unload
Christian Borntraeger [Wed, 26 Nov 2008 13:50:27 +0000 (14:50 +0100)]
KVM: s390: Fix refcounting and allow module unload

Currently it is impossible to unload the kvm module on s390.
This patch fixes kvm_arch_destroy_vm to release all cpus.
This make it possible to unload the module.

In addition we stop messing with the module refcount in arch code.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: consolidate emulation of two operand instructions
Avi Kivity [Wed, 26 Nov 2008 13:30:45 +0000 (15:30 +0200)]
KVM: x86 emulator: consolidate emulation of two operand instructions

No need to repeat the same assembly block over and over.

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: x86 emulator: reduce duplication in one operand emulation thunks
Avi Kivity [Wed, 26 Nov 2008 13:14:10 +0000 (15:14 +0200)]
KVM: x86 emulator: reduce duplication in one operand emulation thunks

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: MMU: optimize set_spte for page sync
Marcelo Tosatti [Tue, 25 Nov 2008 14:58:07 +0000 (15:58 +0100)]
KVM: MMU: optimize set_spte for page sync

The write protect verification in set_spte is unnecessary for page sync.

Its guaranteed that, if the unsync spte was writable, the target page
does not have a write protected shadow (if it had, the spte would have
been write protected under mmu_lock by rmap_write_protect before).

Same reasoning applies to mark_page_dirty: the gfn has been marked as
dirty via the pagefault path.

The cost of hash table and memslot lookups are quite significant if the
workload is pagetable write intensive resulting in increased mmu_lock
contention.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: MSI to INTx translate
Sheng Yang [Mon, 24 Nov 2008 06:32:57 +0000 (14:32 +0800)]
KVM: MSI to INTx translate

Now we use MSI as default one, and translate MSI to INTx when guest need
INTx rather than MSI. For legacy device, we provide support for non-sharing
host IRQ.

Provide a parameter msi2intx for this method. The value is true by default in
x86 architecture.

We can't guarantee this mode can work on every device, but for most of us
tested, it works. If your device encounter some trouble with this mode, you can
try set msi2intx modules parameter to 0. If the device is OK with msi2intx=0,
then please report it to KVM mailing list or me. We may prepare a blacklist for
the device that can't work in this mode.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Enable MSI for device assignment
Sheng Yang [Mon, 24 Nov 2008 06:32:56 +0000 (14:32 +0800)]
KVM: Enable MSI for device assignment

We enable guest MSI and host MSI support in this patch. The userspace want to
enable MSI should set KVM_DEV_IRQ_ASSIGN_ENABLE_MSI in the assigned_irq's flag.
Function would return -ENOTTY if can't enable MSI, userspace shouldn't set MSI
Enable bit when KVM_ASSIGN_IRQ return -ENOTTY with
KVM_DEV_IRQ_ASSIGN_ENABLE_MSI.

Userspace can tell the support of MSI device from #ifdef KVM_CAP_DEVICE_MSI.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Add assigned_device_msi_dispatch()
Sheng Yang [Mon, 24 Nov 2008 06:32:55 +0000 (14:32 +0800)]
KVM: Add assigned_device_msi_dispatch()

The function is used to dispatch MSI to lapic according to MSI message
address and message data.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Export ioapic_get_delivery_bitmask
Sheng Yang [Mon, 24 Nov 2008 06:32:54 +0000 (14:32 +0800)]
KVM: Export ioapic_get_delivery_bitmask

It would be used for MSI in device assignment, for MSI dispatch.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Add fields for MSI device assignment
Sheng Yang [Mon, 24 Nov 2008 06:32:53 +0000 (14:32 +0800)]
KVM: Add fields for MSI device assignment

Prepared for kvm_arch_assigned_device_msi_dispatch().

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Clean up assigned_device_update_irq
Sheng Yang [Mon, 24 Nov 2008 06:32:52 +0000 (14:32 +0800)]
KVM: Clean up assigned_device_update_irq

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Replace irq_requested with more generic irq_requested_type
Sheng Yang [Mon, 24 Nov 2008 06:32:51 +0000 (14:32 +0800)]
KVM: Replace irq_requested with more generic irq_requested_type

Separate guest irq type and host irq type, for we can support guest using INTx
with host using MSI (but not opposite combination).

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Separate update irq to a single function
Sheng Yang [Mon, 24 Nov 2008 06:32:50 +0000 (14:32 +0800)]
KVM: Separate update irq to a single function

Separate INTx enabling part to a independence function, so that we can add MSI
enabling part easily.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: Move ack notifier register and IRQ sourcd ID request
Sheng Yang [Mon, 24 Nov 2008 06:32:49 +0000 (14:32 +0800)]
KVM: Move ack notifier register and IRQ sourcd ID request

Distinguish common part for device assignment and INTx part, perparing for
refactor later.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agox86: KVM guest: sign kvmclock as paravirt
Glauber Costa [Mon, 24 Nov 2008 17:45:23 +0000 (15:45 -0200)]
x86: KVM guest: sign kvmclock as paravirt

Currently, we only set the KVM paravirt signature in case
of CONFIG_KVM_GUEST. However, it is possible to have it turned
off, while CONFIG_KVM_CLOCK is turned on. This is also a paravirt
case, and should be shown accordingly.

Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: VMX: Conditionally request interrupt window after injecting irq
Avi Kivity [Sun, 23 Nov 2008 16:08:57 +0000 (18:08 +0200)]
KVM: VMX: Conditionally request interrupt window after injecting irq

If we're injecting an interrupt, and another one is pending, request
an interrupt window notification so we don't have excess latency on the
second interrupt.

This shouldn't happen in practice since an EOI will be issued, giving a second
chance to request an interrupt window, but...

Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ia64: Clean up vmm_ivt.S using tab to indent every line
Xiantao Zhang [Fri, 21 Nov 2008 13:04:37 +0000 (21:04 +0800)]
KVM: ia64: Clean up vmm_ivt.S using tab to indent every line

Using tab for indentation for vmm_ivt.S.

Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ia64: Add handler for crashed vmm
Xiantao Zhang [Fri, 21 Nov 2008 09:16:07 +0000 (17:16 +0800)]
KVM: ia64: Add handler for crashed vmm

Since vmm runs in an isolated address space and it is just a copy
of host's kvm-intel module, so once vmm crashes, we just crash all guests
running on it instead of crashing whole kernel.

Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ia64: Add some debug points to provide crash infomation
Xiantao Zhang [Fri, 21 Nov 2008 02:46:12 +0000 (10:46 +0800)]
KVM: ia64: Add some debug points to provide crash infomation

Use printk infrastructure to print out some debug info once VM crashes.

Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: ia64: Define printk function for kvm-intel module
Xiantao Zhang [Fri, 21 Nov 2008 12:58:11 +0000 (20:58 +0800)]
KVM: ia64: Define printk function for kvm-intel module

kvm-intel module is relocated to an isolated address space
with kernel, so it can't call host kernel's printk for debug
purpose. In the module, we implement the printk to output debug
info of vmm.

Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agox86: disable VMX on all CPUs on reboot
Eduardo Habkost [Mon, 17 Nov 2008 21:03:24 +0000 (19:03 -0200)]
x86: disable VMX on all CPUs on reboot

On emergency_restart, we may need to use an NMI to disable virtualization
on all CPUs. We do that using nmi_shootdown_cpus() if VMX is enabled.

Note: With this patch, we will run the NMI stuff only when the CPU where
emergency_restart() was called has VMX enabled. This should work on most
cases because KVM enables VMX on all CPUs, but we may miss the small
window where KVM is doing that. Also, I don't know if all code using
VMX out there always enable VMX on all CPUs like KVM does. We have two
other alternatives for that:

a) Have an API that all code that enables VMX on any CPU should use
   to tell the kernel core that it is going to enable VMX on the CPUs.
b) Always call nmi_shootdown_cpus() if the CPU supports VMX. This is
   a bit intrusive and more risky, as it would run nmi_shootdown_cpus()
   on emergency_reboot() even on systems where virtualization is never
   enabled.

Finding a proper point to hook the nmi_shootdown_cpus() call isn't
trivial, as the non-emergency machine_restart() (that doesn't need the
NMI tricks) uses machine_emergency_restart() directly.

The solution to make this work without adding a new function or argument
to machine_ops was setting a 'reboot_emergency' flag that tells if
native_machine_emergency_restart() needs to do the virt cleanup or not.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agokdump: forcibly disable VMX and SVM on machine_crash_shutdown()
Eduardo Habkost [Mon, 17 Nov 2008 21:03:23 +0000 (19:03 -0200)]
kdump: forcibly disable VMX and SVM on machine_crash_shutdown()

We need to disable virtualization extensions on all CPUs before booting
the kdump kernel, otherwise the kdump kernel booting will fail, and
rebooting after the kdump kernel did its task may also fail.

We do it using cpu_emergency_vmxoff() and cpu_emergency_svm_disable(),
that should always work, because those functions check if the CPUs
support SVM or VMX before doing their tasks.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agox86: cpu_emergency_svm_disable() function
Eduardo Habkost [Mon, 17 Nov 2008 21:03:22 +0000 (19:03 -0200)]
x86: cpu_emergency_svm_disable() function

This function can be used by the reboot or kdump code to forcibly
disable SVM on the CPU.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
17 years agoKVM: SVM: move svm_hardware_disable() code to asm/virtext.h
Eduardo Habkost [Mon, 17 Nov 2008 21:03:21 +0000 (19:03 -0200)]
KVM: SVM: move svm_hardware_disable() code to asm/virtext.h

Create cpu_svm_disable() function.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>