2006-12-06 18:14:07 -07: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 05:32:04 -07:00
|
|
|
|
|
|
|
2007 - x86_64 support added by Glauber de Oliveira Costa, Red Hat Inc
|
2006-12-06 18:14:07 -07:00
|
|
|
*/
|
2008-01-30 05:32:04 -07:00
|
|
|
|
2006-12-06 18:14:07 -07:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/bcd.h>
|
2007-05-02 10:27:15 -07:00
|
|
|
#include <linux/highmem.h>
|
2006-12-06 18:14:07 -07:00
|
|
|
|
|
|
|
#include <asm/bug.h>
|
|
|
|
#include <asm/paravirt.h>
|
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/arch_hooks.h>
|
2008-07-08 15:06:23 -07:00
|
|
|
#include <asm/pgtable.h>
|
2006-12-06 18:14:07 -07:00
|
|
|
#include <asm/time.h>
|
2008-06-24 21:19:12 -07:00
|
|
|
#include <asm/pgalloc.h>
|
2006-12-06 18:14:07 -07:00
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/delay.h>
|
2006-12-06 18:14:08 -07:00
|
|
|
#include <asm/fixmap.h>
|
|
|
|
#include <asm/apic.h>
|
2006-12-06 18:14:08 -07:00
|
|
|
#include <asm/tlbflush.h>
|
2007-03-05 01:30:35 -07:00
|
|
|
#include <asm/timer.h>
|
2006-12-06 18:14:07 -07:00
|
|
|
|
|
|
|
/* nop stub */
|
2007-05-02 10:27:13 -07:00
|
|
|
void _paravirt_nop(void)
|
2006-12-06 18:14:07 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init default_banner(void)
|
|
|
|
{
|
|
|
|
printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
|
2007-10-16 11:51:29 -07:00
|
|
|
pv_info.name);
|
2006-12-06 18:14:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
char *memory_setup(void)
|
|
|
|
{
|
2007-10-16 11:51:29 -07:00
|
|
|
return pv_init_ops.memory_setup();
|
2006-12-06 18:14:07 -07:00
|
|
|
}
|
|
|
|
|
2006-12-06 18:14:08 -07:00
|
|
|
/* Simple instruction patching code. */
|
2007-10-16 11:51:29 -07: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-06 18:14:08 -07:00
|
|
|
|
2007-05-02 10:27:14 -07:00
|
|
|
unsigned paravirt_patch_nop(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned paravirt_patch_ignore(unsigned len)
|
|
|
|
{
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2007-07-22 02:12:31 -07:00
|
|
|
struct branch {
|
|
|
|
unsigned char opcode;
|
|
|
|
u32 delta;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2007-08-10 13:31:03 -07:00
|
|
|
unsigned paravirt_patch_call(void *insnbuf,
|
|
|
|
const void *target, u16 tgt_clobbers,
|
|
|
|
unsigned long addr, u16 site_clobbers,
|
2007-05-02 10:27:14 -07:00
|
|
|
unsigned len)
|
|
|
|
{
|
2007-08-10 13:31:03 -07:00
|
|
|
struct branch *b = insnbuf;
|
|
|
|
unsigned long delta = (unsigned long)target - (addr+5);
|
2007-05-02 10:27:14 -07: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-06 18:14:08 -07:00
|
|
|
|
2007-08-10 13:31:03 -07:00
|
|
|
b->opcode = 0xe8; /* call */
|
|
|
|
b->delta = delta;
|
|
|
|
BUILD_BUG_ON(sizeof(*b) != 5);
|
2006-12-06 18:14:08 -07:00
|
|
|
|
2007-05-02 10:27:14 -07:00
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2007-10-16 11:51:29 -07:00
|
|
|
unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
|
2007-08-10 13:31:03 -07:00
|
|
|
unsigned long addr, unsigned len)
|
2007-05-02 10:27:14 -07:00
|
|
|
{
|
2007-08-10 13:31:03 -07:00
|
|
|
struct branch *b = insnbuf;
|
|
|
|
unsigned long delta = (unsigned long)target - (addr+5);
|
2007-05-02 10:27:14 -07:00
|
|
|
|
|
|
|
if (len < 5)
|
|
|
|
return len; /* call too long for patch site */
|
|
|
|
|
2007-08-10 13:31:03 -07:00
|
|
|
b->opcode = 0xe9; /* jmp */
|
|
|
|
b->delta = delta;
|
2007-05-02 10:27:14 -07:00
|
|
|
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2007-10-16 11:51:29 -07: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/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 12:07:50 -07:00
|
|
|
.pv_lock_ops = pv_lock_ops,
|
2007-10-16 11:51:29 -07:00
|
|
|
};
|
|
|
|
return *((void **)&tmpl + type);
|
|
|
|
}
|
|
|
|
|
2007-08-10 13:31:03 -07:00
|
|
|
unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
|
|
|
|
unsigned long addr, unsigned len)
|
2007-05-02 10:27:14 -07:00
|
|
|
{
|
2007-10-16 11:51:29 -07:00
|
|
|
void *opfunc = get_call_destination(type);
|
2007-05-02 10:27:14 -07:00
|
|
|
unsigned ret;
|
|
|
|
|
|
|
|
if (opfunc == NULL)
|
|
|
|
/* If there's no function, patch it with a ud2a (BUG) */
|
2007-10-16 11:51:29 -07:00
|
|
|
ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
|
2007-05-02 10:27:14 -07:00
|
|
|
else if (opfunc == paravirt_nop)
|
|
|
|
/* If the operation is a nop, then nop the callsite */
|
|
|
|
ret = paravirt_patch_nop();
|
2007-10-16 11:51:29 -07:00
|
|
|
else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
|
2008-06-24 21:19:26 -07:00
|
|
|
type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
|
2008-06-24 21:19:28 -07:00
|
|
|
type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
|
|
|
|
type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
|
2007-05-02 10:27:14 -07:00
|
|
|
/* If operation requires a jmp, then jmp */
|
2007-10-16 11:51:29 -07:00
|
|
|
ret = paravirt_patch_jmp(insnbuf, opfunc, addr, len);
|
2007-05-02 10:27:14 -07:00
|
|
|
else
|
|
|
|
/* Otherwise call the function; assume target could
|
|
|
|
clobber any caller-save reg */
|
2007-08-10 13:31:03 -07:00
|
|
|
ret = paravirt_patch_call(insnbuf, opfunc, CLBR_ANY,
|
|
|
|
addr, clobbers, len);
|
2007-05-02 10:27:14 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-10 13:31:03 -07:00
|
|
|
unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
|
2007-05-02 10:27:14 -07:00
|
|
|
const char *start, const char *end)
|
|
|
|
{
|
|
|
|
unsigned insn_len = end - start;
|
2006-12-06 18:14:08 -07:00
|
|
|
|
2007-05-02 10:27:14 -07:00
|
|
|
if (insn_len > len || start == NULL)
|
|
|
|
insn_len = len;
|
|
|
|
else
|
2007-08-10 13:31:03 -07:00
|
|
|
memcpy(insnbuf, start, insn_len);
|
2006-12-06 18:14:08 -07:00
|
|
|
|
|
|
|
return insn_len;
|
|
|
|
}
|
|
|
|
|
2006-12-06 18:14:07 -07:00
|
|
|
void init_IRQ(void)
|
|
|
|
{
|
2007-10-16 11:51:29 -07:00
|
|
|
pv_irq_ops.init_IRQ();
|
2006-12-06 18:14:07 -07:00
|
|
|
}
|
|
|
|
|
2007-02-13 05:26:25 -07:00
|
|
|
static void native_flush_tlb(void)
|
2006-12-06 18:14:08 -07: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 05:26:25 -07:00
|
|
|
static void native_flush_tlb_global(void)
|
2006-12-06 18:14:08 -07:00
|
|
|
{
|
|
|
|
__native_flush_tlb_global();
|
|
|
|
}
|
|
|
|
|
2007-05-02 10:27:14 -07:00
|
|
|
static void native_flush_tlb_single(unsigned long addr)
|
2006-12-06 18:14:08 -07:00
|
|
|
{
|
|
|
|
__native_flush_tlb_single(addr);
|
|
|
|
}
|
|
|
|
|
2006-12-06 18:14:07 -07:00
|
|
|
/* These are in entry.S */
|
2007-02-13 05:26:25 -07:00
|
|
|
extern void native_iret(void);
|
2008-06-24 21:19:26 -07:00
|
|
|
extern void native_irq_enable_sysexit(void);
|
2008-06-24 21:19:28 -07:00
|
|
|
extern void native_usergs_sysret32(void);
|
|
|
|
extern void native_usergs_sysret64(void);
|
2006-12-06 18:14:07 -07:00
|
|
|
|
|
|
|
static int __init print_banner(void)
|
|
|
|
{
|
2007-10-16 11:51:29 -07:00
|
|
|
pv_init_ops.banner();
|
2006-12-06 18:14:07 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
core_initcall(print_banner);
|
|
|
|
|
2007-07-17 18:37:04 -07: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-27 17:28:40 -07:00
|
|
|
return request_resource(&ioport_resource, &reserve_ioports);
|
2007-07-17 18:37:04 -07: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 11:51:29 -07: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)
|
|
|
|
{
|
2008-01-30 05:32:11 -07:00
|
|
|
BUG_ON(__get_cpu_var(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 11:51:29 -07:00
|
|
|
BUG_ON(preemptible());
|
|
|
|
|
2008-01-30 05:32:11 -07:00
|
|
|
__get_cpu_var(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 11:51:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void paravirt_leave_lazy(enum paravirt_lazy_mode mode)
|
|
|
|
{
|
2008-01-30 05:32:11 -07:00
|
|
|
BUG_ON(__get_cpu_var(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 11:51:29 -07:00
|
|
|
BUG_ON(preemptible());
|
|
|
|
|
2008-01-30 05:32:11 -07:00
|
|
|
__get_cpu_var(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 11:51:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void paravirt_enter_lazy_mmu(void)
|
|
|
|
{
|
|
|
|
enter_lazy(PARAVIRT_LAZY_MMU);
|
|
|
|
}
|
|
|
|
|
|
|
|
void paravirt_leave_lazy_mmu(void)
|
|
|
|
{
|
|
|
|
paravirt_leave_lazy(PARAVIRT_LAZY_MMU);
|
|
|
|
}
|
|
|
|
|
|
|
|
void paravirt_enter_lazy_cpu(void)
|
|
|
|
{
|
|
|
|
enter_lazy(PARAVIRT_LAZY_CPU);
|
|
|
|
}
|
|
|
|
|
|
|
|
void paravirt_leave_lazy_cpu(void)
|
|
|
|
{
|
|
|
|
paravirt_leave_lazy(PARAVIRT_LAZY_CPU);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
|
|
|
|
{
|
2008-01-30 05:32:11 -07:00
|
|
|
return __get_cpu_var(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 11:51:29 -07:00
|
|
|
}
|
|
|
|
|
2008-07-07 12:07:51 -07:00
|
|
|
void __init paravirt_use_bytelocks(void)
|
|
|
|
{
|
2008-07-09 05:33:33 -07:00
|
|
|
#ifdef CONFIG_SMP
|
2008-07-07 12:07:51 -07:00
|
|
|
pv_lock_ops.spin_is_locked = __byte_spin_is_locked;
|
|
|
|
pv_lock_ops.spin_is_contended = __byte_spin_is_contended;
|
|
|
|
pv_lock_ops.spin_lock = __byte_spin_lock;
|
|
|
|
pv_lock_ops.spin_trylock = __byte_spin_trylock;
|
|
|
|
pv_lock_ops.spin_unlock = __byte_spin_unlock;
|
2008-07-09 05:33:33 -07:00
|
|
|
#endif
|
2008-07-07 12:07:51 -07:00
|
|
|
}
|
|
|
|
|
2007-10-16 11:51:29 -07:00
|
|
|
struct pv_info pv_info = {
|
2006-12-06 18:14:07 -07: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 10:27:13 -07:00
|
|
|
.shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
|
2007-10-16 11:51:29 -07:00
|
|
|
};
|
2006-12-06 18:14:07 -07:00
|
|
|
|
2007-10-16 11:51:29 -07:00
|
|
|
struct pv_init_ops pv_init_ops = {
|
|
|
|
.patch = native_patch,
|
2006-12-06 18:14:07 -07:00
|
|
|
.banner = default_banner,
|
2007-05-02 10:27:13 -07:00
|
|
|
.arch_setup = paravirt_nop,
|
2006-12-06 18:14:07 -07:00
|
|
|
.memory_setup = machine_specific_memory_setup,
|
2007-10-16 11:51:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pv_time_ops pv_time_ops = {
|
|
|
|
.time_init = hpet_time_init,
|
2006-12-06 18:14:07 -07:00
|
|
|
.get_wallclock = native_get_wallclock,
|
|
|
|
.set_wallclock = native_set_wallclock,
|
2007-10-16 11:51:29 -07:00
|
|
|
.sched_clock = native_sched_clock,
|
2008-07-01 11:43:36 -07:00
|
|
|
.get_tsc_khz = native_calibrate_tsc,
|
2007-10-16 11:51:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pv_irq_ops pv_irq_ops = {
|
2006-12-06 18:14:07 -07:00
|
|
|
.init_IRQ = native_init_IRQ,
|
2007-10-16 11:51:29 -07:00
|
|
|
.save_fl = native_save_fl,
|
|
|
|
.restore_fl = native_restore_fl,
|
|
|
|
.irq_disable = native_irq_disable,
|
|
|
|
.irq_enable = native_irq_enable,
|
|
|
|
.safe_halt = native_safe_halt,
|
|
|
|
.halt = native_halt,
|
2008-06-24 21:19:31 -07:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
.adjust_exception_frame = paravirt_nop,
|
|
|
|
#endif
|
2007-10-16 11:51:29 -07:00
|
|
|
};
|
2006-12-06 18:14:07 -07:00
|
|
|
|
2007-10-16 11:51:29 -07:00
|
|
|
struct pv_cpu_ops pv_cpu_ops = {
|
2006-12-06 18:14:07 -07: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 05:33:19 -07:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
.read_cr8 = native_read_cr8,
|
|
|
|
.write_cr8 = native_write_cr8,
|
|
|
|
#endif
|
2006-12-06 18:14:07 -07:00
|
|
|
.wbinvd = native_wbinvd,
|
2007-05-02 10:27:10 -07:00
|
|
|
.read_msr = native_read_msr_safe,
|
2008-08-22 01:32:50 -07:00
|
|
|
.read_msr_amd = native_read_msr_amd_safe,
|
2007-05-02 10:27:10 -07:00
|
|
|
.write_msr = native_write_msr_safe,
|
2006-12-06 18:14:07 -07:00
|
|
|
.read_tsc = native_read_tsc,
|
|
|
|
.read_pmc = native_read_pmc,
|
2008-01-30 05:32:05 -07:00
|
|
|
.read_tscp = native_read_tscp,
|
2006-12-06 18:14:07 -07: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-24 21:19:32 -07:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
.load_gs_index = native_load_gs_index,
|
|
|
|
#endif
|
2008-01-30 05:31:13 -07:00
|
|
|
.write_ldt_entry = native_write_ldt_entry,
|
2008-01-30 05:31:13 -07:00
|
|
|
.write_gdt_entry = native_write_gdt_entry,
|
2008-01-30 05:31:12 -07:00
|
|
|
.write_idt_entry = native_write_idt_entry,
|
2008-01-30 05:31:02 -07:00
|
|
|
.load_sp0 = native_load_sp0,
|
2006-12-06 18:14:07 -07:00
|
|
|
|
2008-06-30 11:10:53 -07:00
|
|
|
#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
|
2008-06-24 21:19:26 -07:00
|
|
|
.irq_enable_sysexit = native_irq_enable_sysexit,
|
2008-06-30 11:10:53 -07:00
|
|
|
#endif
|
2008-06-24 21:19:28 -07:00
|
|
|
#ifdef CONFIG_X86_64
|
2008-06-30 11:10:53 -07:00
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
2008-06-24 21:19:28 -07:00
|
|
|
.usergs_sysret32 = native_usergs_sysret32,
|
2008-06-30 11:10:53 -07:00
|
|
|
#endif
|
2008-06-24 21:19:28 -07:00
|
|
|
.usergs_sysret64 = native_usergs_sysret64,
|
2008-06-24 21:19:26 -07:00
|
|
|
#endif
|
2007-10-16 11:51:29 -07:00
|
|
|
.iret = native_iret,
|
2008-01-30 05:32:08 -07:00
|
|
|
.swapgs = native_swapgs,
|
2007-10-16 11:51:29 -07:00
|
|
|
|
2006-12-06 18:14:07 -07: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 11:51:29 -07:00
|
|
|
|
|
|
|
.lazy_mode = {
|
|
|
|
.enter = paravirt_nop,
|
|
|
|
.leave = paravirt_nop,
|
|
|
|
},
|
2007-10-16 11:51:29 -07:00
|
|
|
};
|
2006-12-06 18:14:07 -07:00
|
|
|
|
2007-10-16 11:51:29 -07:00
|
|
|
struct pv_apic_ops pv_apic_ops = {
|
2006-12-06 18:14:08 -07:00
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
2007-02-13 05:26:21 -07:00
|
|
|
.setup_boot_clock = setup_boot_APIC_clock,
|
|
|
|
.setup_secondary_clock = setup_secondary_APIC_clock,
|
2007-05-02 10:27:18 -07:00
|
|
|
.startup_ipi_hook = paravirt_nop,
|
2006-12-06 18:14:08 -07:00
|
|
|
#endif
|
2007-10-16 11:51:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pv_mmu_ops pv_mmu_ops = {
|
2008-01-30 05:33:20 -07:00
|
|
|
#ifndef CONFIG_X86_64
|
[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 10:27:13 -07:00
|
|
|
.pagetable_setup_start = native_pagetable_setup_start,
|
|
|
|
.pagetable_setup_done = native_pagetable_setup_done,
|
2008-07-08 15:06:23 -07:00
|
|
|
#else
|
|
|
|
.pagetable_setup_start = paravirt_nop,
|
|
|
|
.pagetable_setup_done = paravirt_nop,
|
2008-01-30 05:33:20 -07:00
|
|
|
#endif
|
[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 10:27:13 -07:00
|
|
|
|
2007-10-16 11:51:29 -07:00
|
|
|
.read_cr2 = native_read_cr2,
|
|
|
|
.write_cr2 = native_write_cr2,
|
|
|
|
.read_cr3 = native_read_cr3,
|
|
|
|
.write_cr3 = native_write_cr3,
|
|
|
|
|
2006-12-06 18:14:08 -07:00
|
|
|
.flush_tlb_user = native_flush_tlb,
|
|
|
|
.flush_tlb_kernel = native_flush_tlb_global,
|
|
|
|
.flush_tlb_single = native_flush_tlb_single,
|
2007-05-02 10:27:15 -07:00
|
|
|
.flush_tlb_others = native_flush_tlb_others,
|
2006-12-06 18:14:08 -07:00
|
|
|
|
2008-06-24 21:19:12 -07:00
|
|
|
.pgd_alloc = __paravirt_pgd_alloc,
|
|
|
|
.pgd_free = paravirt_nop,
|
|
|
|
|
2008-03-17 16:37:01 -07:00
|
|
|
.alloc_pte = paravirt_nop,
|
|
|
|
.alloc_pmd = paravirt_nop,
|
|
|
|
.alloc_pmd_clone = paravirt_nop,
|
2008-03-17 16:37:02 -07:00
|
|
|
.alloc_pud = paravirt_nop,
|
2008-03-17 16:37:01 -07:00
|
|
|
.release_pte = paravirt_nop,
|
|
|
|
.release_pmd = paravirt_nop,
|
2008-03-17 16:37:02 -07:00
|
|
|
.release_pud = paravirt_nop,
|
2007-02-13 05:26:21 -07:00
|
|
|
|
2006-12-06 18:14:08 -07:00
|
|
|
.set_pte = native_set_pte,
|
|
|
|
.set_pte_at = native_set_pte_at,
|
|
|
|
.set_pmd = native_set_pmd,
|
2007-05-02 10:27:13 -07:00
|
|
|
.pte_update = paravirt_nop,
|
|
|
|
.pte_update_defer = paravirt_nop,
|
2007-05-02 10:27:13 -07:00
|
|
|
|
2008-06-16 04:30:01 -07:00
|
|
|
.ptep_modify_prot_start = __ptep_modify_prot_start,
|
|
|
|
.ptep_modify_prot_commit = __ptep_modify_prot_commit,
|
|
|
|
|
2007-05-02 10:27:15 -07:00
|
|
|
#ifdef CONFIG_HIGHPTE
|
|
|
|
.kmap_atomic_pte = kmap_atomic,
|
|
|
|
#endif
|
|
|
|
|
2008-01-30 05:33:20 -07:00
|
|
|
#if PAGETABLE_LEVELS >= 3
|
2006-12-06 18:14:08 -07:00
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
.set_pte_atomic = native_set_pte_atomic,
|
|
|
|
.set_pte_present = native_set_pte_present,
|
|
|
|
.pte_clear = native_pte_clear,
|
|
|
|
.pmd_clear = native_pmd_clear,
|
2008-01-30 05:33:20 -07:00
|
|
|
#endif
|
|
|
|
.set_pud = native_set_pud,
|
2007-05-02 10:27:13 -07:00
|
|
|
.pmd_val = native_pmd_val,
|
|
|
|
.make_pmd = native_make_pmd,
|
2008-01-30 05:33:20 -07:00
|
|
|
|
|
|
|
#if PAGETABLE_LEVELS == 4
|
|
|
|
.pud_val = native_pud_val,
|
|
|
|
.make_pud = native_make_pud,
|
|
|
|
.set_pgd = native_set_pgd,
|
2006-12-06 18:14:08 -07:00
|
|
|
#endif
|
2008-01-30 05:33:20 -07:00
|
|
|
#endif /* PAGETABLE_LEVELS >= 3 */
|
2006-12-06 18:14:08 -07:00
|
|
|
|
2007-05-02 10:27:13 -07:00
|
|
|
.pte_val = native_pte_val,
|
2008-07-21 22:40:46 -07:00
|
|
|
.pte_flags = native_pte_flags,
|
2007-05-02 10:27:13 -07:00
|
|
|
.pgd_val = native_pgd_val,
|
|
|
|
|
|
|
|
.make_pte = native_make_pte,
|
|
|
|
.make_pgd = native_make_pgd,
|
|
|
|
|
2007-05-02 10:27:14 -07: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 11:51:29 -07:00
|
|
|
|
|
|
|
.lazy_mode = {
|
|
|
|
.enter = paravirt_nop,
|
|
|
|
.leave = paravirt_nop,
|
|
|
|
},
|
2008-06-17 11:42:01 -07:00
|
|
|
|
|
|
|
.set_fixmap = native_set_fixmap,
|
2006-12-06 18:14:07 -07:00
|
|
|
};
|
2007-01-22 21:40:36 -07:00
|
|
|
|
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 12:07:50 -07:00
|
|
|
struct pv_lock_ops pv_lock_ops = {
|
2008-07-09 05:33:33 -07:00
|
|
|
#ifdef CONFIG_SMP
|
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 12:07:50 -07:00
|
|
|
.spin_is_locked = __ticket_spin_is_locked,
|
|
|
|
.spin_is_contended = __ticket_spin_is_contended,
|
|
|
|
|
|
|
|
.spin_lock = __ticket_spin_lock,
|
|
|
|
.spin_trylock = __ticket_spin_trylock,
|
|
|
|
.spin_unlock = __ticket_spin_unlock,
|
2008-07-09 05:33:33 -07:00
|
|
|
#endif
|
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 12:07:50 -07:00
|
|
|
};
|
2008-08-20 11:31:07 -07:00
|
|
|
EXPORT_SYMBOL(pv_lock_ops);
|
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 12:07:50 -07:00
|
|
|
|
2007-10-16 11:51:29 -07: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-28 17:22:11 -07:00
|
|
|
EXPORT_SYMBOL (pv_cpu_ops);
|
|
|
|
EXPORT_SYMBOL (pv_mmu_ops);
|
2007-10-16 11:51:29 -07:00
|
|
|
EXPORT_SYMBOL_GPL(pv_apic_ops);
|
|
|
|
EXPORT_SYMBOL_GPL(pv_info);
|
|
|
|
EXPORT_SYMBOL (pv_irq_ops);
|