2006-12-07 01:14:07 +00:00
|
|
|
/* Paravirtualization interfaces
|
|
|
|
Copyright (C) 2006 Rusty Russell IBM Corporation
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-01-30 12:32:04 +00:00
|
|
|
|
|
|
|
2007 - x86_64 support added by Glauber de Oliveira Costa, Red Hat Inc
|
2006-12-07 01:14:07 +00:00
|
|
|
*/
|
2008-01-30 12:32:04 +00:00
|
|
|
|
2006-12-07 01:14:07 +00:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/bcd.h>
|
2007-05-02 17:27:15 +00:00
|
|
|
#include <linux/highmem.h>
|
2006-12-07 01:14:07 +00:00
|
|
|
|
|
|
|
#include <asm/bug.h>
|
|
|
|
#include <asm/paravirt.h>
|
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/setup.h>
|
2008-07-08 22:06:23 +00:00
|
|
|
#include <asm/pgtable.h>
|
2006-12-07 01:14:07 +00:00
|
|
|
#include <asm/time.h>
|
2008-06-25 04:19:12 +00:00
|
|
|
#include <asm/pgalloc.h>
|
2006-12-07 01:14:07 +00:00
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/delay.h>
|
2006-12-07 01:14:08 +00:00
|
|
|
#include <asm/fixmap.h>
|
|
|
|
#include <asm/apic.h>
|
2006-12-07 01:14:08 +00:00
|
|
|
#include <asm/tlbflush.h>
|
2007-03-05 08:30:35 +00:00
|
|
|
#include <asm/timer.h>
|
2006-12-07 01:14:07 +00:00
|
|
|
|
|
|
|
/* nop stub */
|
2007-05-02 17:27:13 +00:00
|
|
|
void _paravirt_nop(void)
|
2006-12-07 01:14:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-28 22:35:02 +00:00
|
|
|
/* identity function, which can be inlined */
|
|
|
|
u32 _paravirt_ident_32(u32 x)
|
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 _paravirt_ident_64(u64 x)
|
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:19:57 +00:00
|
|
|
void __init default_banner(void)
|
2006-12-07 01:14:07 +00:00
|
|
|
{
|
|
|
|
printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
|
2007-10-16 18:51:29 +00:00
|
|
|
pv_info.name);
|
2006-12-07 01:14:07 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 01:14:08 +00:00
|
|
|
/* Simple instruction patching code. */
|
2007-10-16 18:51:29 +00:00
|
|
|
#define DEF_NATIVE(ops, name, code) \
|
|
|
|
extern const char start_##ops##_##name[], end_##ops##_##name[]; \
|
|
|
|
asm("start_" #ops "_" #name ": " code "; end_" #ops "_" #name ":")
|
|
|
|
|
|
|
|
/* Undefined instruction for dealing with missing ops pointers. */
|
|
|
|
static const unsigned char ud2a[] = { 0x0f, 0x0b };
|
2006-12-07 01:14:08 +00:00
|
|
|
|
2007-05-02 17:27:14 +00:00
|
|
|
unsigned paravirt_patch_nop(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned paravirt_patch_ignore(unsigned len)
|
|
|
|
{
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2007-07-22 09:12:31 +00:00
|
|
|
struct branch {
|
|
|
|
unsigned char opcode;
|
|
|
|
u32 delta;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2007-08-10 20:31:03 +00:00
|
|
|
unsigned paravirt_patch_call(void *insnbuf,
|
|
|
|
const void *target, u16 tgt_clobbers,
|
|
|
|
unsigned long addr, u16 site_clobbers,
|
2007-05-02 17:27:14 +00:00
|
|
|
unsigned len)
|
|
|
|
{
|
2007-08-10 20:31:03 +00:00
|
|
|
struct branch *b = insnbuf;
|
|
|
|
unsigned long delta = (unsigned long)target - (addr+5);
|
2007-05-02 17:27:14 +00:00
|
|
|
|
|
|
|
if (tgt_clobbers & ~site_clobbers)
|
|
|
|
return len; /* target would clobber too much for this site */
|
|
|
|
if (len < 5)
|
|
|
|
return len; /* call too long for patch site */
|
2006-12-07 01:14:08 +00:00
|
|
|
|
2007-08-10 20:31:03 +00:00
|
|
|
b->opcode = 0xe8; /* call */
|
|
|
|
b->delta = delta;
|
|
|
|
BUILD_BUG_ON(sizeof(*b) != 5);
|
2006-12-07 01:14:08 +00:00
|
|
|
|
2007-05-02 17:27:14 +00:00
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
|
2007-08-10 20:31:03 +00:00
|
|
|
unsigned long addr, unsigned len)
|
2007-05-02 17:27:14 +00:00
|
|
|
{
|
2007-08-10 20:31:03 +00:00
|
|
|
struct branch *b = insnbuf;
|
|
|
|
unsigned long delta = (unsigned long)target - (addr+5);
|
2007-05-02 17:27:14 +00:00
|
|
|
|
|
|
|
if (len < 5)
|
|
|
|
return len; /* call too long for patch site */
|
|
|
|
|
2007-08-10 20:31:03 +00:00
|
|
|
b->opcode = 0xe9; /* jmp */
|
|
|
|
b->delta = delta;
|
2007-05-02 17:27:14 +00:00
|
|
|
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
/* Neat trick to map patch type back to the call within the
|
|
|
|
* corresponding structure. */
|
|
|
|
static void *get_call_destination(u8 type)
|
|
|
|
{
|
|
|
|
struct paravirt_patch_template tmpl = {
|
|
|
|
.pv_init_ops = pv_init_ops,
|
|
|
|
.pv_time_ops = pv_time_ops,
|
|
|
|
.pv_cpu_ops = pv_cpu_ops,
|
|
|
|
.pv_irq_ops = pv_irq_ops,
|
|
|
|
.pv_apic_ops = pv_apic_ops,
|
|
|
|
.pv_mmu_ops = pv_mmu_ops,
|
x86: Fix performance regression caused by paravirt_ops on native kernels
Xiaohui Xin and some other folks at Intel have been looking into what's
behind the performance hit of paravirt_ops when running native.
It appears that the hit is entirely due to the paravirtualized
spinlocks introduced by:
| commit 8efcbab674de2bee45a2e4cdf97de16b8e609ac8
| Date: Mon Jul 7 12:07:51 2008 -0700
|
| paravirt: introduce a "lock-byte" spinlock implementation
The extra call/return in the spinlock path is somehow
causing an increase in the cycles/instruction of somewhere around 2-7%
(seems to vary quite a lot from test to test). The working theory is
that the CPU's pipeline is getting upset about the
call->call->locked-op->return->return, and seems to be failing to
speculate (though I haven't seen anything definitive about the precise
reasons). This doesn't entirely make sense, because the performance
hit is also visible on unlock and other operations which don't involve
locked instructions. But spinlock operations clearly swamp all the
other pvops operations, even though I can't imagine that they're
nearly as common (there's only a .05% increase in instructions
executed).
If I disable just the pv-spinlock calls, my tests show that pvops is
identical to non-pvops performance on native (my measurements show that
it is actually about .1% faster, but Xiaohui shows a .05% slowdown).
Summary of results, averaging 10 runs of the "mmperf" test, using a
no-pvops build as baseline:
nopv Pv-nospin Pv-spin
CPU cycles 100.00% 99.89% 102.18%
instructions 100.00% 100.10% 100.15%
CPI 100.00% 99.79% 102.03%
cache ref 100.00% 100.84% 100.28%
cache miss 100.00% 90.47% 88.56%
cache miss rate 100.00% 89.72% 88.31%
branches 100.00% 99.93% 100.04%
branch miss 100.00% 103.66% 107.72%
branch miss rt 100.00% 103.73% 107.67%
wallclock 100.00% 99.90% 102.20%
The clear effect here is that the 2% increase in CPI is
directly reflected in the final wallclock time.
(The other interesting effect is that the more ops are
out of line calls via pvops, the lower the cache access
and miss rates. Not too surprising, but it suggests that
the non-pvops kernel is over-inlined. On the flipside,
the branch misses go up correspondingly...)
So, what's the fix?
Paravirt patching turns all the pvops calls into direct calls, so
_spin_lock etc do end up having direct calls. For example, the compiler
generated code for paravirtualized _spin_lock is:
<_spin_lock+0>: mov %gs:0xb4c8,%rax
<_spin_lock+9>: incl 0xffffffffffffe044(%rax)
<_spin_lock+15>: callq *0xffffffff805a5b30
<_spin_lock+22>: retq
The indirect call will get patched to:
<_spin_lock+0>: mov %gs:0xb4c8,%rax
<_spin_lock+9>: incl 0xffffffffffffe044(%rax)
<_spin_lock+15>: callq <__ticket_spin_lock>
<_spin_lock+20>: nop; nop /* or whatever 2-byte nop */
<_spin_lock+22>: retq
One possibility is to inline _spin_lock, etc, when building an
optimised kernel (ie, when there's no spinlock/preempt
instrumentation/debugging enabled). That will remove the outer
call/return pair, returning the instruction stream to a single
call/return, which will presumably execute the same as the non-pvops
case. The downsides arel 1) it will replicate the
preempt_disable/enable code at eack lock/unlock callsite; this code is
fairly small, but not nothing; and 2) the spinlock definitions are
already a very heavily tangled mass of #ifdefs and other preprocessor
magic, and making any changes will be non-trivial.
The other obvious answer is to disable pv-spinlocks. Making them a
separate config option is fairly easy, and it would be trivial to
enable them only when Xen is enabled (as the only non-default user).
But it doesn't really address the common case of a distro build which
is going to have Xen support enabled, and leaves the open question of
whether the native performance cost of pv-spinlocks is worth the
performance improvement on a loaded Xen system (10% saving of overall
system CPU when guests block rather than spin). Still it is a
reasonable short-term workaround.
[ Impact: fix pvops performance regression when running native ]
Analysed-by: "Xin Xiaohui" <xiaohui.xin@intel.com>
Analysed-by: "Li Xin" <xin.li@intel.com>
Analysed-by: "Nakajima Jun" <jun.nakajima@intel.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Cc: Nick Piggin <npiggin@suse.de>
Cc: Xen-devel <xen-devel@lists.xensource.com>
LKML-Reference: <4A0B62F7.5030802@goop.org>
[ fixed the help text ]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-05-14 00:16:55 +00:00
|
|
|
#ifdef CONFIG_PARAVIRT_SPINLOCKS
|
x86/paravirt: add hooks for spinlock operations
Ticket spinlocks have absolutely ghastly worst-case performance
characteristics in a virtual environment. If there is any contention
for physical CPUs (ie, there are more runnable vcpus than cpus), then
ticket locks can cause the system to end up spending 90+% of its time
spinning.
The problem is that (v)cpus waiting on a ticket spinlock will be
granted access to the lock in strict order they got their tickets. If
the hypervisor scheduler doesn't give the vcpus time in that order,
they will burn timeslices waiting for the scheduler to give the right
vcpu some time. In the worst case it could take O(n^2) vcpu scheduler
timeslices for everyone waiting on the lock to get it, not counting
new cpus trying to take the lock while the log-jam is sorted out.
These hooks allow a paravirt backend to replace the spinlock
implementation.
At the very least, this could revert the implementation back to the
old lock algorithm, which allows the next scheduled vcpu to take the
lock, and has basically fairly good performance.
It also allows the spinlocks to take advantages of the hypervisor
features to make locks more efficient (spin and block, for example).
The cost to native execution is an extra direct call when using a
spinlock function. There's no overhead if CONFIG_PARAVIRT is turned
off.
The lock structure is fixed at a single "unsigned int", initialized to
zero, but the spinlock implementation can use it as it wishes.
Thanks to Thomas Friebel's Xen Summit talk "Preventing Guests from
Spinning Around" for pointing out this problem.
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Christoph Lameter <clameter@linux-foundation.org>
Cc: Petr Tesarik <ptesarik@suse.cz>
Cc: Virtualization <virtualization@lists.linux-foundation.org>
Cc: Xen devel <xen-devel@lists.xensource.com>
Cc: Thomas Friebel <thomas.friebel@amd.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-07-07 19:07:50 +00:00
|
|
|
.pv_lock_ops = pv_lock_ops,
|
x86: Fix performance regression caused by paravirt_ops on native kernels
Xiaohui Xin and some other folks at Intel have been looking into what's
behind the performance hit of paravirt_ops when running native.
It appears that the hit is entirely due to the paravirtualized
spinlocks introduced by:
| commit 8efcbab674de2bee45a2e4cdf97de16b8e609ac8
| Date: Mon Jul 7 12:07:51 2008 -0700
|
| paravirt: introduce a "lock-byte" spinlock implementation
The extra call/return in the spinlock path is somehow
causing an increase in the cycles/instruction of somewhere around 2-7%
(seems to vary quite a lot from test to test). The working theory is
that the CPU's pipeline is getting upset about the
call->call->locked-op->return->return, and seems to be failing to
speculate (though I haven't seen anything definitive about the precise
reasons). This doesn't entirely make sense, because the performance
hit is also visible on unlock and other operations which don't involve
locked instructions. But spinlock operations clearly swamp all the
other pvops operations, even though I can't imagine that they're
nearly as common (there's only a .05% increase in instructions
executed).
If I disable just the pv-spinlock calls, my tests show that pvops is
identical to non-pvops performance on native (my measurements show that
it is actually about .1% faster, but Xiaohui shows a .05% slowdown).
Summary of results, averaging 10 runs of the "mmperf" test, using a
no-pvops build as baseline:
nopv Pv-nospin Pv-spin
CPU cycles 100.00% 99.89% 102.18%
instructions 100.00% 100.10% 100.15%
CPI 100.00% 99.79% 102.03%
cache ref 100.00% 100.84% 100.28%
cache miss 100.00% 90.47% 88.56%
cache miss rate 100.00% 89.72% 88.31%
branches 100.00% 99.93% 100.04%
branch miss 100.00% 103.66% 107.72%
branch miss rt 100.00% 103.73% 107.67%
wallclock 100.00% 99.90% 102.20%
The clear effect here is that the 2% increase in CPI is
directly reflected in the final wallclock time.
(The other interesting effect is that the more ops are
out of line calls via pvops, the lower the cache access
and miss rates. Not too surprising, but it suggests that
the non-pvops kernel is over-inlined. On the flipside,
the branch misses go up correspondingly...)
So, what's the fix?
Paravirt patching turns all the pvops calls into direct calls, so
_spin_lock etc do end up having direct calls. For example, the compiler
generated code for paravirtualized _spin_lock is:
<_spin_lock+0>: mov %gs:0xb4c8,%rax
<_spin_lock+9>: incl 0xffffffffffffe044(%rax)
<_spin_lock+15>: callq *0xffffffff805a5b30
<_spin_lock+22>: retq
The indirect call will get patched to:
<_spin_lock+0>: mov %gs:0xb4c8,%rax
<_spin_lock+9>: incl 0xffffffffffffe044(%rax)
<_spin_lock+15>: callq <__ticket_spin_lock>
<_spin_lock+20>: nop; nop /* or whatever 2-byte nop */
<_spin_lock+22>: retq
One possibility is to inline _spin_lock, etc, when building an
optimised kernel (ie, when there's no spinlock/preempt
instrumentation/debugging enabled). That will remove the outer
call/return pair, returning the instruction stream to a single
call/return, which will presumably execute the same as the non-pvops
case. The downsides arel 1) it will replicate the
preempt_disable/enable code at eack lock/unlock callsite; this code is
fairly small, but not nothing; and 2) the spinlock definitions are
already a very heavily tangled mass of #ifdefs and other preprocessor
magic, and making any changes will be non-trivial.
The other obvious answer is to disable pv-spinlocks. Making them a
separate config option is fairly easy, and it would be trivial to
enable them only when Xen is enabled (as the only non-default user).
But it doesn't really address the common case of a distro build which
is going to have Xen support enabled, and leaves the open question of
whether the native performance cost of pv-spinlocks is worth the
performance improvement on a loaded Xen system (10% saving of overall
system CPU when guests block rather than spin). Still it is a
reasonable short-term workaround.
[ Impact: fix pvops performance regression when running native ]
Analysed-by: "Xin Xiaohui" <xiaohui.xin@intel.com>
Analysed-by: "Li Xin" <xin.li@intel.com>
Analysed-by: "Nakajima Jun" <jun.nakajima@intel.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Cc: Nick Piggin <npiggin@suse.de>
Cc: Xen-devel <xen-devel@lists.xensource.com>
LKML-Reference: <4A0B62F7.5030802@goop.org>
[ fixed the help text ]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-05-14 00:16:55 +00:00
|
|
|
#endif
|
2007-10-16 18:51:29 +00:00
|
|
|
};
|
|
|
|
return *((void **)&tmpl + type);
|
|
|
|
}
|
|
|
|
|
2007-08-10 20:31:03 +00:00
|
|
|
unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
|
|
|
|
unsigned long addr, unsigned len)
|
2007-05-02 17:27:14 +00:00
|
|
|
{
|
2007-10-16 18:51:29 +00:00
|
|
|
void *opfunc = get_call_destination(type);
|
2007-05-02 17:27:14 +00:00
|
|
|
unsigned ret;
|
|
|
|
|
|
|
|
if (opfunc == NULL)
|
|
|
|
/* If there's no function, patch it with a ud2a (BUG) */
|
2007-10-16 18:51:29 +00:00
|
|
|
ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
|
2009-01-28 22:35:02 +00:00
|
|
|
else if (opfunc == _paravirt_nop)
|
2007-05-02 17:27:14 +00:00
|
|
|
/* If the operation is a nop, then nop the callsite */
|
|
|
|
ret = paravirt_patch_nop();
|
2009-01-28 22:35:02 +00:00
|
|
|
|
|
|
|
/* identity functions just return their single argument */
|
|
|
|
else if (opfunc == _paravirt_ident_32)
|
|
|
|
ret = paravirt_patch_ident_32(insnbuf, len);
|
|
|
|
else if (opfunc == _paravirt_ident_64)
|
|
|
|
ret = paravirt_patch_ident_64(insnbuf, len);
|
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
|
2008-06-25 04:19:26 +00:00
|
|
|
type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
|
2008-06-25 04:19:28 +00:00
|
|
|
type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
|
|
|
|
type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
|
2007-05-02 17:27:14 +00:00
|
|
|
/* If operation requires a jmp, then jmp */
|
2007-10-16 18:51:29 +00:00
|
|
|
ret = paravirt_patch_jmp(insnbuf, opfunc, addr, len);
|
2007-05-02 17:27:14 +00:00
|
|
|
else
|
|
|
|
/* Otherwise call the function; assume target could
|
|
|
|
clobber any caller-save reg */
|
2007-08-10 20:31:03 +00:00
|
|
|
ret = paravirt_patch_call(insnbuf, opfunc, CLBR_ANY,
|
|
|
|
addr, clobbers, len);
|
2007-05-02 17:27:14 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-10 20:31:03 +00:00
|
|
|
unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
|
2007-05-02 17:27:14 +00:00
|
|
|
const char *start, const char *end)
|
|
|
|
{
|
|
|
|
unsigned insn_len = end - start;
|
2006-12-07 01:14:08 +00:00
|
|
|
|
2007-05-02 17:27:14 +00:00
|
|
|
if (insn_len > len || start == NULL)
|
|
|
|
insn_len = len;
|
|
|
|
else
|
2007-08-10 20:31:03 +00:00
|
|
|
memcpy(insnbuf, start, insn_len);
|
2006-12-07 01:14:08 +00:00
|
|
|
|
|
|
|
return insn_len;
|
|
|
|
}
|
|
|
|
|
2007-02-13 12:26:25 +00:00
|
|
|
static void native_flush_tlb(void)
|
2006-12-07 01:14:08 +00:00
|
|
|
{
|
|
|
|
__native_flush_tlb();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global pages have to be flushed a bit differently. Not a real
|
|
|
|
* performance problem because this does not happen often.
|
|
|
|
*/
|
2007-02-13 12:26:25 +00:00
|
|
|
static void native_flush_tlb_global(void)
|
2006-12-07 01:14:08 +00:00
|
|
|
{
|
|
|
|
__native_flush_tlb_global();
|
|
|
|
}
|
|
|
|
|
2007-05-02 17:27:14 +00:00
|
|
|
static void native_flush_tlb_single(unsigned long addr)
|
2006-12-07 01:14:08 +00:00
|
|
|
{
|
|
|
|
__native_flush_tlb_single(addr);
|
|
|
|
}
|
|
|
|
|
2006-12-07 01:14:07 +00:00
|
|
|
/* These are in entry.S */
|
2007-02-13 12:26:25 +00:00
|
|
|
extern void native_iret(void);
|
2008-06-25 04:19:26 +00:00
|
|
|
extern void native_irq_enable_sysexit(void);
|
2008-06-25 04:19:28 +00:00
|
|
|
extern void native_usergs_sysret32(void);
|
|
|
|
extern void native_usergs_sysret64(void);
|
2006-12-07 01:14:07 +00:00
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
static struct resource reserve_ioports = {
|
|
|
|
.start = 0,
|
|
|
|
.end = IO_SPACE_LIMIT,
|
|
|
|
.name = "paravirt-ioport",
|
|
|
|
.flags = IORESOURCE_IO | IORESOURCE_BUSY,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reserve the whole legacy IO space to prevent any legacy drivers
|
|
|
|
* from wasting time probing for their hardware. This is a fairly
|
|
|
|
* brute-force approach to disabling all non-virtual drivers.
|
|
|
|
*
|
|
|
|
* Note that this must be called very early to have any effect.
|
|
|
|
*/
|
|
|
|
int paravirt_disable_iospace(void)
|
|
|
|
{
|
2008-03-28 00:28:40 +00:00
|
|
|
return request_resource(&ioport_resource, &reserve_ioports);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
static DEFINE_PER_CPU(enum paravirt_lazy_mode, paravirt_lazy_mode) = PARAVIRT_LAZY_NONE;
|
|
|
|
|
|
|
|
static inline void enter_lazy(enum paravirt_lazy_mode mode)
|
|
|
|
{
|
2009-02-18 08:18:50 +00:00
|
|
|
BUG_ON(percpu_read(paravirt_lazy_mode) != PARAVIRT_LAZY_NONE);
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
|
2009-02-18 08:18:50 +00:00
|
|
|
percpu_write(paravirt_lazy_mode, mode);
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
}
|
|
|
|
|
2009-02-18 07:46:21 +00:00
|
|
|
static void leave_lazy(enum paravirt_lazy_mode mode)
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
{
|
2009-02-18 08:18:50 +00:00
|
|
|
BUG_ON(percpu_read(paravirt_lazy_mode) != mode);
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
|
2009-02-18 08:18:50 +00:00
|
|
|
percpu_write(paravirt_lazy_mode, PARAVIRT_LAZY_NONE);
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void paravirt_enter_lazy_mmu(void)
|
|
|
|
{
|
|
|
|
enter_lazy(PARAVIRT_LAZY_MMU);
|
|
|
|
}
|
|
|
|
|
|
|
|
void paravirt_leave_lazy_mmu(void)
|
|
|
|
{
|
2009-02-18 07:46:21 +00:00
|
|
|
leave_lazy(PARAVIRT_LAZY_MMU);
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
}
|
|
|
|
|
2009-02-18 19:18:57 +00:00
|
|
|
void paravirt_start_context_switch(struct task_struct *prev)
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
{
|
2009-02-18 07:53:19 +00:00
|
|
|
BUG_ON(preemptible());
|
|
|
|
|
2009-02-18 07:46:21 +00:00
|
|
|
if (percpu_read(paravirt_lazy_mode) == PARAVIRT_LAZY_MMU) {
|
|
|
|
arch_leave_lazy_mmu_mode();
|
2009-02-18 19:18:57 +00:00
|
|
|
set_ti_thread_flag(task_thread_info(prev), TIF_LAZY_MMU_UPDATES);
|
2009-02-18 07:46:21 +00:00
|
|
|
}
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
enter_lazy(PARAVIRT_LAZY_CPU);
|
|
|
|
}
|
|
|
|
|
2009-02-18 19:18:57 +00:00
|
|
|
void paravirt_end_context_switch(struct task_struct *next)
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
{
|
2009-02-18 07:53:19 +00:00
|
|
|
BUG_ON(preemptible());
|
|
|
|
|
2009-02-18 07:46:21 +00:00
|
|
|
leave_lazy(PARAVIRT_LAZY_CPU);
|
|
|
|
|
2009-02-18 19:18:57 +00:00
|
|
|
if (test_and_clear_ti_thread_flag(task_thread_info(next), TIF_LAZY_MMU_UPDATES))
|
2009-02-18 07:46:21 +00:00
|
|
|
arch_enter_lazy_mmu_mode();
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
|
|
|
|
{
|
2009-02-18 07:05:19 +00:00
|
|
|
if (in_interrupt())
|
|
|
|
return PARAVIRT_LAZY_NONE;
|
|
|
|
|
2009-02-18 08:18:50 +00:00
|
|
|
return percpu_read(paravirt_lazy_mode);
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
}
|
|
|
|
|
2009-02-12 18:02:56 +00:00
|
|
|
void arch_flush_lazy_mmu_mode(void)
|
|
|
|
{
|
|
|
|
preempt_disable();
|
|
|
|
|
|
|
|
if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU) {
|
|
|
|
arch_leave_lazy_mmu_mode();
|
|
|
|
arch_enter_lazy_mmu_mode();
|
|
|
|
}
|
|
|
|
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
struct pv_info pv_info = {
|
2006-12-07 01:14:07 +00:00
|
|
|
.name = "bare hardware",
|
|
|
|
.paravirt_enabled = 0,
|
|
|
|
.kernel_rpl = 0,
|
[PATCH] i386: PARAVIRT: Allow paravirt backend to choose kernel PMD sharing
Normally when running in PAE mode, the 4th PMD maps the kernel address space,
which can be shared among all processes (since they all need the same kernel
mappings).
Xen, however, does not allow guests to have the kernel pmd shared between page
tables, so parameterize pgtable.c to allow both modes of operation.
There are several side-effects of this. One is that vmalloc will update the
kernel address space mappings, and those updates need to be propagated into
all processes if the kernel mappings are not intrinsically shared. In the
non-PAE case, this is done by maintaining a pgd_list of all processes; this
list is used when all process pagetables must be updated. pgd_list is
threaded via otherwise unused entries in the page structure for the pgd, which
means that the pgd must be page-sized for this to work.
Normally the PAE pgd is only 4x64 byte entries large, but Xen requires the PAE
pgd to page aligned anyway, so this patch forces the pgd to be page
aligned+sized when the kernel pmd is unshared, to accomodate both these
requirements.
Also, since there may be several distinct kernel pmds (if the user/kernel
split is below 3G), there's no point in allocating them from a slab cache;
they're just allocated with get_free_page and initialized appropriately. (Of
course the could be cached if there is just a single kernel pmd - which is the
default with a 3G user/kernel split - but it doesn't seem worthwhile to add
yet another case into this code).
[ Many thanks to wli for review comments. ]
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: William Lee Irwin III <wli@holomorphy.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Christoph Lameter <clameter@sgi.com>
Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2007-05-02 17:27:13 +00:00
|
|
|
.shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
|
2007-10-16 18:51:29 +00:00
|
|
|
};
|
2006-12-07 01:14:07 +00:00
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
struct pv_init_ops pv_init_ops = {
|
|
|
|
.patch = native_patch,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pv_time_ops pv_time_ops = {
|
|
|
|
.sched_clock = native_sched_clock,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pv_irq_ops pv_irq_ops = {
|
x86/paravirt: add register-saving thunks to reduce caller register pressure
Impact: Optimization
One of the problems with inserting a pile of C calls where previously
there were none is that the register pressure is greatly increased.
The C calling convention says that the caller must expect a certain
set of registers may be trashed by the callee, and that the callee can
use those registers without restriction. This includes the function
argument registers, and several others.
This patch seeks to alleviate this pressure by introducing wrapper
thunks that will do the register saving/restoring, so that the
callsite doesn't need to worry about it, but the callee function can
be conventional compiler-generated code. In many cases (particularly
performance-sensitive cases) the callee will be in assembler anyway,
and need not use the compiler's calling convention.
Standard calling convention is:
arguments return scratch
x86-32 eax edx ecx eax ?
x86-64 rdi rsi rdx rcx rax r8 r9 r10 r11
The thunk preserves all argument and scratch registers. The return
register is not preserved, and is available as a scratch register for
unwrapped callee code (and of course the return value).
Wrapped function pointers are themselves wrapped in a struct
paravirt_callee_save structure, in order to get some warning from the
compiler when functions with mismatched calling conventions are used.
The most common paravirt ops, both statically and dynamically, are
interrupt enable/disable/save/restore, so handle them first. This is
particularly easy since their calls are handled specially anyway.
XXX Deal with VMI. What's their calling convention?
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-01-28 22:35:05 +00:00
|
|
|
.save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
|
|
|
|
.restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
|
|
|
|
.irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
|
|
|
|
.irq_enable = __PV_IS_CALLEE_SAVE(native_irq_enable),
|
2007-10-16 18:51:29 +00:00
|
|
|
.safe_halt = native_safe_halt,
|
|
|
|
.halt = native_halt,
|
2008-06-25 04:19:31 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
.adjust_exception_frame = paravirt_nop,
|
|
|
|
#endif
|
2007-10-16 18:51:29 +00:00
|
|
|
};
|
2006-12-07 01:14:07 +00:00
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
struct pv_cpu_ops pv_cpu_ops = {
|
2006-12-07 01:14:07 +00:00
|
|
|
.cpuid = native_cpuid,
|
|
|
|
.get_debugreg = native_get_debugreg,
|
|
|
|
.set_debugreg = native_set_debugreg,
|
|
|
|
.clts = native_clts,
|
|
|
|
.read_cr0 = native_read_cr0,
|
|
|
|
.write_cr0 = native_write_cr0,
|
|
|
|
.read_cr4 = native_read_cr4,
|
|
|
|
.read_cr4_safe = native_read_cr4_safe,
|
|
|
|
.write_cr4 = native_write_cr4,
|
2008-01-30 12:33:19 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
.read_cr8 = native_read_cr8,
|
|
|
|
.write_cr8 = native_write_cr8,
|
|
|
|
#endif
|
2006-12-07 01:14:07 +00:00
|
|
|
.wbinvd = native_wbinvd,
|
2007-05-02 17:27:10 +00:00
|
|
|
.read_msr = native_read_msr_safe,
|
2009-08-31 07:50:09 +00:00
|
|
|
.rdmsr_regs = native_rdmsr_safe_regs,
|
2007-05-02 17:27:10 +00:00
|
|
|
.write_msr = native_write_msr_safe,
|
2009-08-31 07:50:09 +00:00
|
|
|
.wrmsr_regs = native_wrmsr_safe_regs,
|
2006-12-07 01:14:07 +00:00
|
|
|
.read_tsc = native_read_tsc,
|
|
|
|
.read_pmc = native_read_pmc,
|
2008-01-30 12:32:05 +00:00
|
|
|
.read_tscp = native_read_tscp,
|
2006-12-07 01:14:07 +00:00
|
|
|
.load_tr_desc = native_load_tr_desc,
|
|
|
|
.set_ldt = native_set_ldt,
|
|
|
|
.load_gdt = native_load_gdt,
|
|
|
|
.load_idt = native_load_idt,
|
|
|
|
.store_gdt = native_store_gdt,
|
|
|
|
.store_idt = native_store_idt,
|
|
|
|
.store_tr = native_store_tr,
|
|
|
|
.load_tls = native_load_tls,
|
2008-06-25 04:19:32 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
.load_gs_index = native_load_gs_index,
|
|
|
|
#endif
|
2008-01-30 12:31:13 +00:00
|
|
|
.write_ldt_entry = native_write_ldt_entry,
|
2008-01-30 12:31:13 +00:00
|
|
|
.write_gdt_entry = native_write_gdt_entry,
|
2008-01-30 12:31:12 +00:00
|
|
|
.write_idt_entry = native_write_idt_entry,
|
2008-07-23 21:21:18 +00:00
|
|
|
|
|
|
|
.alloc_ldt = paravirt_nop,
|
|
|
|
.free_ldt = paravirt_nop,
|
|
|
|
|
2008-01-30 12:31:02 +00:00
|
|
|
.load_sp0 = native_load_sp0,
|
2006-12-07 01:14:07 +00:00
|
|
|
|
2008-06-30 18:10:53 +00:00
|
|
|
#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
|
2008-06-25 04:19:26 +00:00
|
|
|
.irq_enable_sysexit = native_irq_enable_sysexit,
|
2008-06-30 18:10:53 +00:00
|
|
|
#endif
|
2008-06-25 04:19:28 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
2008-06-30 18:10:53 +00:00
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
2008-06-25 04:19:28 +00:00
|
|
|
.usergs_sysret32 = native_usergs_sysret32,
|
2008-06-30 18:10:53 +00:00
|
|
|
#endif
|
2008-06-25 04:19:28 +00:00
|
|
|
.usergs_sysret64 = native_usergs_sysret64,
|
2008-06-25 04:19:26 +00:00
|
|
|
#endif
|
2007-10-16 18:51:29 +00:00
|
|
|
.iret = native_iret,
|
2008-01-30 12:32:08 +00:00
|
|
|
.swapgs = native_swapgs,
|
2007-10-16 18:51:29 +00:00
|
|
|
|
2006-12-07 01:14:07 +00:00
|
|
|
.set_iopl_mask = native_set_iopl_mask,
|
|
|
|
.io_delay = native_io_delay,
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
|
2009-02-18 19:18:57 +00:00
|
|
|
.start_context_switch = paravirt_nop,
|
|
|
|
.end_context_switch = paravirt_nop,
|
2007-10-16 18:51:29 +00:00
|
|
|
};
|
2006-12-07 01:14:07 +00:00
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
struct pv_apic_ops pv_apic_ops = {
|
2006-12-07 01:14:08 +00:00
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
2007-05-02 17:27:18 +00:00
|
|
|
.startup_ipi_hook = paravirt_nop,
|
2006-12-07 01:14:08 +00:00
|
|
|
#endif
|
2007-10-16 18:51:29 +00:00
|
|
|
};
|
|
|
|
|
2009-01-28 22:35:02 +00:00
|
|
|
#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
|
|
|
|
/* 32-bit pagetable entries */
|
2009-01-28 22:35:07 +00:00
|
|
|
#define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
|
2009-01-28 22:35:02 +00:00
|
|
|
#else
|
|
|
|
/* 64-bit pagetable entries */
|
2009-01-28 22:35:07 +00:00
|
|
|
#define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
|
2009-01-28 22:35:02 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
struct pv_mmu_ops pv_mmu_ops = {
|
[PATCH] i386: PARAVIRT: Hooks to set up initial pagetable
This patch introduces paravirt_ops hooks to control how the kernel's
initial pagetable is set up.
In the case of a native boot, the very early bootstrap code creates a
simple non-PAE pagetable to map the kernel and physical memory. When
the VM subsystem is initialized, it creates a proper pagetable which
respects the PAE mode, large pages, etc.
When booting under a hypervisor, there are many possibilities for what
paging environment the hypervisor establishes for the guest kernel, so
the constructon of the kernel's pagetable depends on the hypervisor.
In the case of Xen, the hypervisor boots the kernel with a fully
constructed pagetable, which is already using PAE if necessary. Also,
Xen requires particular care when constructing pagetables to make sure
all pagetables are always mapped read-only.
In order to make this easier, kernel's initial pagetable construction
has been changed to only allocate and initialize a pagetable page if
there's no page already present in the pagetable. This allows the Xen
paravirt backend to make a copy of the hypervisor-provided pagetable,
allowing the kernel to establish any more mappings it needs while
keeping the existing ones.
A slightly subtle point which is worth highlighting here is that Xen
requires all kernel mappings to share the same pte_t pages between all
pagetables, so that updating a kernel page's mapping in one pagetable
is reflected in all other pagetables. This makes it possible to
allocate a page and attach it to a pagetable without having to
explicitly enumerate that page's mapping in all pagetables.
And:
+From: "Eric W. Biederman" <ebiederm@xmission.com>
If we don't set the leaf page table entries it is quite possible that
will inherit and incorrect page table entry from the initial boot
page table setup in head.S. So we need to redo the effort here,
so we pick up PSE, PGE and the like.
Hypervisors like Xen require that their page tables be read-only,
which is slightly incompatible with our low identity mappings, however
I discussed this with Jeremy he has modified the Xen early set_pte
function to avoid problems in this area.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Acked-by: William Irwin <bill.irwin@oracle.com>
Cc: Ingo Molnar <mingo@elte.hu>
2007-05-02 17:27:13 +00:00
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
.read_cr2 = native_read_cr2,
|
|
|
|
.write_cr2 = native_write_cr2,
|
|
|
|
.read_cr3 = native_read_cr3,
|
|
|
|
.write_cr3 = native_write_cr3,
|
|
|
|
|
2006-12-07 01:14:08 +00:00
|
|
|
.flush_tlb_user = native_flush_tlb,
|
|
|
|
.flush_tlb_kernel = native_flush_tlb_global,
|
|
|
|
.flush_tlb_single = native_flush_tlb_single,
|
2007-05-02 17:27:15 +00:00
|
|
|
.flush_tlb_others = native_flush_tlb_others,
|
2006-12-07 01:14:08 +00:00
|
|
|
|
2008-06-25 04:19:12 +00:00
|
|
|
.pgd_alloc = __paravirt_pgd_alloc,
|
|
|
|
.pgd_free = paravirt_nop,
|
|
|
|
|
2008-03-17 23:37:01 +00:00
|
|
|
.alloc_pte = paravirt_nop,
|
|
|
|
.alloc_pmd = paravirt_nop,
|
2008-03-17 23:37:02 +00:00
|
|
|
.alloc_pud = paravirt_nop,
|
2008-03-17 23:37:01 +00:00
|
|
|
.release_pte = paravirt_nop,
|
|
|
|
.release_pmd = paravirt_nop,
|
2008-03-17 23:37:02 +00:00
|
|
|
.release_pud = paravirt_nop,
|
2007-02-13 12:26:21 +00:00
|
|
|
|
2006-12-07 01:14:08 +00:00
|
|
|
.set_pte = native_set_pte,
|
|
|
|
.set_pte_at = native_set_pte_at,
|
|
|
|
.set_pmd = native_set_pmd,
|
2007-05-02 17:27:13 +00:00
|
|
|
.pte_update = paravirt_nop,
|
|
|
|
.pte_update_defer = paravirt_nop,
|
2007-05-02 17:27:13 +00:00
|
|
|
|
2008-06-16 11:30:01 +00:00
|
|
|
.ptep_modify_prot_start = __ptep_modify_prot_start,
|
|
|
|
.ptep_modify_prot_commit = __ptep_modify_prot_commit,
|
|
|
|
|
2008-01-30 12:33:20 +00:00
|
|
|
#if PAGETABLE_LEVELS >= 3
|
2006-12-07 01:14:08 +00:00
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
.set_pte_atomic = native_set_pte_atomic,
|
|
|
|
.pte_clear = native_pte_clear,
|
|
|
|
.pmd_clear = native_pmd_clear,
|
2008-01-30 12:33:20 +00:00
|
|
|
#endif
|
|
|
|
.set_pud = native_set_pud,
|
2009-01-28 22:35:07 +00:00
|
|
|
|
|
|
|
.pmd_val = PTE_IDENT,
|
|
|
|
.make_pmd = PTE_IDENT,
|
2008-01-30 12:33:20 +00:00
|
|
|
|
|
|
|
#if PAGETABLE_LEVELS == 4
|
2009-01-28 22:35:07 +00:00
|
|
|
.pud_val = PTE_IDENT,
|
|
|
|
.make_pud = PTE_IDENT,
|
|
|
|
|
2008-01-30 12:33:20 +00:00
|
|
|
.set_pgd = native_set_pgd,
|
2006-12-07 01:14:08 +00:00
|
|
|
#endif
|
2008-01-30 12:33:20 +00:00
|
|
|
#endif /* PAGETABLE_LEVELS >= 3 */
|
2006-12-07 01:14:08 +00:00
|
|
|
|
2009-01-28 22:35:07 +00:00
|
|
|
.pte_val = PTE_IDENT,
|
|
|
|
.pgd_val = PTE_IDENT,
|
2007-05-02 17:27:13 +00:00
|
|
|
|
2009-01-28 22:35:07 +00:00
|
|
|
.make_pte = PTE_IDENT,
|
|
|
|
.make_pgd = PTE_IDENT,
|
2007-05-02 17:27:13 +00:00
|
|
|
|
2007-05-02 17:27:14 +00:00
|
|
|
.dup_mmap = paravirt_nop,
|
|
|
|
.exit_mmap = paravirt_nop,
|
|
|
|
.activate_mm = paravirt_nop,
|
paravirt: clean up lazy mode handling
Currently, the set_lazy_mode pv_op is overloaded with 5 functions:
1. enter lazy cpu mode
2. leave lazy cpu mode
3. enter lazy mmu mode
4. leave lazy mmu mode
5. flush pending batched operations
This complicates each paravirt backend, since it needs to deal with
all the possible state transitions, handling flushing, etc. In
particular, flushing is quite distinct from the other 4 functions, and
seems to just cause complication.
This patch removes the set_lazy_mode operation, and adds "enter" and
"leave" lazy mode operations on mmu_ops and cpu_ops. All the logic
associated with enter and leaving lazy states is now in common code
(basically BUG_ONs to make sure that no mode is current when entering
a lazy mode, and make sure that the mode is current when leaving).
Also, flush is handled in a common way, by simply leaving and
re-entering the lazy mode.
The result is that the Xen, lguest and VMI lazy mode implementations
are much simpler.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Zach Amsden <zach@vmware.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Anthony Liguory <aliguori@us.ibm.com>
Cc: "Glauber de Oliveira Costa" <glommer@gmail.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
2007-10-16 18:51:29 +00:00
|
|
|
|
|
|
|
.lazy_mode = {
|
|
|
|
.enter = paravirt_nop,
|
|
|
|
.leave = paravirt_nop,
|
|
|
|
},
|
2008-06-17 18:42:01 +00:00
|
|
|
|
|
|
|
.set_fixmap = native_set_fixmap,
|
2006-12-07 01:14:07 +00:00
|
|
|
};
|
2007-01-23 04:40:36 +00:00
|
|
|
|
2007-10-16 18:51:29 +00:00
|
|
|
EXPORT_SYMBOL_GPL(pv_time_ops);
|
x86/paravirt: revert exports to restore old behaviour
Subdividing the paravirt_ops structure caused a regression in certain
non-GPL modules which try to use mmu_ops and cpu_ops. This restores the
old behaviour, and makes it consistent with the non-CONFIG_PARAVIRT case.
Takashi Iwai <tiwai@suse.de> adds:
> I took at this problem (as I have an nvidia card on one of my
> workstations), and found out that the following suffer from
> EXPORT_SYMBOL_GPL changes:
>
> * local_disable_irq(), local_irq_save*(), etc.
> * MSR-related macros like rdmsr(), wrmsr(), read_cr0(), etc.
> wbinvd(), too.
> * pmd_val(), pgd_val(), etc are all involved with pv_mm_ops.
> pmd_large() and pmd_bad() is also indirectly involved.
> __flush_tlb() and friends suffer, too.
Christoph Hellwig objects to this patch on the grounds that modules
shouldn't be using these operations anyway. I don't think this is a
particularly good reason to reject the patch, for several reasons:
1. These operations are still available to modules when not using
CONFIG_PARAVIRT, since they are implicitly exported as inline
functions via the kernel headers. Exporting the same functionality as
GPL-only symbols just adds a gratuitious difference between
CONFIG_PARAVIRT and non-CONFIG_PARAVIRT configurations. If we really
think these operations are not for module use (or non-GPL module use),
then we should solve the problem in a general way.
2. It's a regression from previous kernels, which would work these
modules even with CONFIG_PARAVIRT enabled.
3. The operations in question seem pretty reasonable for modules to
use. The control registers/MSRs can be accessed directly anyway, so there's
no benefit in preventing modules from using standard interfaces. And it seems
reasonable to allow a graphics driver to create its own mappings if it wants.
Therefore, I think this patch should go in for 2.6.24. If people
really think that these operations should not be available to modules,
then we can address that separately.
Signed-off-by: Jeremy Fitzhardinge <Jeremy.Fitzhardinge@citrix.com>
Cc: Tobias Powalowski <t.powa@gmx.de>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Zachary Amsden <zach@vmware.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-11-29 00:22:11 +00:00
|
|
|
EXPORT_SYMBOL (pv_cpu_ops);
|
|
|
|
EXPORT_SYMBOL (pv_mmu_ops);
|
2007-10-16 18:51:29 +00:00
|
|
|
EXPORT_SYMBOL_GPL(pv_apic_ops);
|
|
|
|
EXPORT_SYMBOL_GPL(pv_info);
|
|
|
|
EXPORT_SYMBOL (pv_irq_ops);
|