2006-12-07 09:14:07 +08: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
|
|
|
|
*/
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/bcd.h>
|
2007-05-03 01:27:15 +08:00
|
|
|
#include <linux/highmem.h>
|
2006-12-07 09:14:07 +08:00
|
|
|
|
|
|
|
#include <asm/bug.h>
|
|
|
|
#include <asm/paravirt.h>
|
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/arch_hooks.h>
|
|
|
|
#include <asm/time.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/delay.h>
|
2006-12-07 09:14:08 +08:00
|
|
|
#include <asm/fixmap.h>
|
|
|
|
#include <asm/apic.h>
|
2006-12-07 09:14:08 +08:00
|
|
|
#include <asm/tlbflush.h>
|
2007-03-05 16:30:35 +08:00
|
|
|
#include <asm/timer.h>
|
2006-12-07 09:14:07 +08:00
|
|
|
|
|
|
|
/* nop stub */
|
2007-05-03 01:27:13 +08:00
|
|
|
void _paravirt_nop(void)
|
2006-12-07 09:14:07 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init default_banner(void)
|
|
|
|
{
|
|
|
|
printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
|
2007-10-17 02:51:29 +08:00
|
|
|
pv_info.name);
|
2006-12-07 09:14:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char *memory_setup(void)
|
|
|
|
{
|
2007-10-17 02:51:29 +08:00
|
|
|
return pv_init_ops.memory_setup();
|
2006-12-07 09:14:07 +08:00
|
|
|
}
|
|
|
|
|
2006-12-07 09:14:08 +08:00
|
|
|
/* Simple instruction patching code. */
|
2007-10-17 02:51:29 +08:00
|
|
|
#define DEF_NATIVE(ops, name, code) \
|
|
|
|
extern const char start_##ops##_##name[], end_##ops##_##name[]; \
|
|
|
|
asm("start_" #ops "_" #name ": " code "; end_" #ops "_" #name ":")
|
|
|
|
|
|
|
|
DEF_NATIVE(pv_irq_ops, irq_disable, "cli");
|
|
|
|
DEF_NATIVE(pv_irq_ops, irq_enable, "sti");
|
|
|
|
DEF_NATIVE(pv_irq_ops, restore_fl, "push %eax; popf");
|
|
|
|
DEF_NATIVE(pv_irq_ops, save_fl, "pushf; pop %eax");
|
|
|
|
DEF_NATIVE(pv_cpu_ops, iret, "iret");
|
2008-01-30 20:30:33 +08:00
|
|
|
DEF_NATIVE(pv_cpu_ops, irq_enable_syscall_ret, "sti; sysexit");
|
2007-10-17 02:51:29 +08:00
|
|
|
DEF_NATIVE(pv_mmu_ops, read_cr2, "mov %cr2, %eax");
|
|
|
|
DEF_NATIVE(pv_mmu_ops, write_cr3, "mov %eax, %cr3");
|
|
|
|
DEF_NATIVE(pv_mmu_ops, read_cr3, "mov %cr3, %eax");
|
|
|
|
DEF_NATIVE(pv_cpu_ops, clts, "clts");
|
|
|
|
DEF_NATIVE(pv_cpu_ops, read_tsc, "rdtsc");
|
|
|
|
|
|
|
|
/* Undefined instruction for dealing with missing ops pointers. */
|
|
|
|
static const unsigned char ud2a[] = { 0x0f, 0x0b };
|
2006-12-07 09:14:08 +08:00
|
|
|
|
2007-08-11 04:31:03 +08:00
|
|
|
static unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
|
|
|
|
unsigned long addr, unsigned len)
|
2006-12-07 09:14:08 +08:00
|
|
|
{
|
2007-05-03 01:27:14 +08:00
|
|
|
const unsigned char *start, *end;
|
|
|
|
unsigned ret;
|
|
|
|
|
|
|
|
switch(type) {
|
2007-10-17 02:51:29 +08:00
|
|
|
#define SITE(ops, x) \
|
|
|
|
case PARAVIRT_PATCH(ops.x): \
|
|
|
|
start = start_##ops##_##x; \
|
|
|
|
end = end_##ops##_##x; \
|
|
|
|
goto patch_site
|
|
|
|
|
|
|
|
SITE(pv_irq_ops, irq_disable);
|
|
|
|
SITE(pv_irq_ops, irq_enable);
|
|
|
|
SITE(pv_irq_ops, restore_fl);
|
|
|
|
SITE(pv_irq_ops, save_fl);
|
|
|
|
SITE(pv_cpu_ops, iret);
|
2008-01-30 20:30:33 +08:00
|
|
|
SITE(pv_cpu_ops, irq_enable_syscall_ret);
|
2007-10-17 02:51:29 +08:00
|
|
|
SITE(pv_mmu_ops, read_cr2);
|
|
|
|
SITE(pv_mmu_ops, read_cr3);
|
|
|
|
SITE(pv_mmu_ops, write_cr3);
|
|
|
|
SITE(pv_cpu_ops, clts);
|
|
|
|
SITE(pv_cpu_ops, read_tsc);
|
2007-05-03 01:27:14 +08:00
|
|
|
#undef SITE
|
|
|
|
|
|
|
|
patch_site:
|
2007-08-11 04:31:03 +08:00
|
|
|
ret = paravirt_patch_insns(ibuf, len, start, end);
|
2007-05-03 01:27:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-08-11 04:31:03 +08:00
|
|
|
ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
|
2007-05-03 01:27:14 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned paravirt_patch_nop(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned paravirt_patch_ignore(unsigned len)
|
|
|
|
{
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2007-07-22 17:12:31 +08:00
|
|
|
struct branch {
|
|
|
|
unsigned char opcode;
|
|
|
|
u32 delta;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2007-08-11 04:31:03 +08:00
|
|
|
unsigned paravirt_patch_call(void *insnbuf,
|
|
|
|
const void *target, u16 tgt_clobbers,
|
|
|
|
unsigned long addr, u16 site_clobbers,
|
2007-05-03 01:27:14 +08:00
|
|
|
unsigned len)
|
|
|
|
{
|
2007-08-11 04:31:03 +08:00
|
|
|
struct branch *b = insnbuf;
|
|
|
|
unsigned long delta = (unsigned long)target - (addr+5);
|
2007-05-03 01:27:14 +08: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 09:14:08 +08:00
|
|
|
|
2007-08-11 04:31:03 +08:00
|
|
|
b->opcode = 0xe8; /* call */
|
|
|
|
b->delta = delta;
|
|
|
|
BUILD_BUG_ON(sizeof(*b) != 5);
|
2006-12-07 09:14:08 +08:00
|
|
|
|
2007-05-03 01:27:14 +08:00
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2007-10-17 02:51:29 +08:00
|
|
|
unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
|
2007-08-11 04:31:03 +08:00
|
|
|
unsigned long addr, unsigned len)
|
2007-05-03 01:27:14 +08:00
|
|
|
{
|
2007-08-11 04:31:03 +08:00
|
|
|
struct branch *b = insnbuf;
|
|
|
|
unsigned long delta = (unsigned long)target - (addr+5);
|
2007-05-03 01:27:14 +08:00
|
|
|
|
|
|
|
if (len < 5)
|
|
|
|
return len; /* call too long for patch site */
|
|
|
|
|
2007-08-11 04:31:03 +08:00
|
|
|
b->opcode = 0xe9; /* jmp */
|
|
|
|
b->delta = delta;
|
2007-05-03 01:27:14 +08:00
|
|
|
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2007-10-17 02:51:29 +08: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,
|
|
|
|
};
|
|
|
|
return *((void **)&tmpl + type);
|
|
|
|
}
|
|
|
|
|
2007-08-11 04:31:03 +08:00
|
|
|
unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
|
|
|
|
unsigned long addr, unsigned len)
|
2007-05-03 01:27:14 +08:00
|
|
|
{
|
2007-10-17 02:51:29 +08:00
|
|
|
void *opfunc = get_call_destination(type);
|
2007-05-03 01:27:14 +08:00
|
|
|
unsigned ret;
|
|
|
|
|
|
|
|
if (opfunc == NULL)
|
|
|
|
/* If there's no function, patch it with a ud2a (BUG) */
|
2007-10-17 02:51:29 +08:00
|
|
|
ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
|
2007-05-03 01:27:14 +08:00
|
|
|
else if (opfunc == paravirt_nop)
|
|
|
|
/* If the operation is a nop, then nop the callsite */
|
|
|
|
ret = paravirt_patch_nop();
|
2007-10-17 02:51:29 +08:00
|
|
|
else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
|
2008-01-30 20:30:33 +08:00
|
|
|
type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_syscall_ret))
|
2007-05-03 01:27:14 +08:00
|
|
|
/* If operation requires a jmp, then jmp */
|
2007-10-17 02:51:29 +08:00
|
|
|
ret = paravirt_patch_jmp(insnbuf, opfunc, addr, len);
|
2007-05-03 01:27:14 +08:00
|
|
|
else
|
|
|
|
/* Otherwise call the function; assume target could
|
|
|
|
clobber any caller-save reg */
|
2007-08-11 04:31:03 +08:00
|
|
|
ret = paravirt_patch_call(insnbuf, opfunc, CLBR_ANY,
|
|
|
|
addr, clobbers, len);
|
2007-05-03 01:27:14 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-11 04:31:03 +08:00
|
|
|
unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
|
2007-05-03 01:27:14 +08:00
|
|
|
const char *start, const char *end)
|
|
|
|
{
|
|
|
|
unsigned insn_len = end - start;
|
2006-12-07 09:14:08 +08:00
|
|
|
|
2007-05-03 01:27:14 +08:00
|
|
|
if (insn_len > len || start == NULL)
|
|
|
|
insn_len = len;
|
|
|
|
else
|
2007-08-11 04:31:03 +08:00
|
|
|
memcpy(insnbuf, start, insn_len);
|
2006-12-07 09:14:08 +08:00
|
|
|
|
|
|
|
return insn_len;
|
|
|
|
}
|
|
|
|
|
2006-12-07 09:14:07 +08:00
|
|
|
void init_IRQ(void)
|
|
|
|
{
|
2007-10-17 02:51:29 +08:00
|
|
|
pv_irq_ops.init_IRQ();
|
2006-12-07 09:14:07 +08:00
|
|
|
}
|
|
|
|
|
2007-02-13 20:26:25 +08:00
|
|
|
static void native_flush_tlb(void)
|
2006-12-07 09:14:08 +08: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 20:26:25 +08:00
|
|
|
static void native_flush_tlb_global(void)
|
2006-12-07 09:14:08 +08:00
|
|
|
{
|
|
|
|
__native_flush_tlb_global();
|
|
|
|
}
|
|
|
|
|
2007-05-03 01:27:14 +08:00
|
|
|
static void native_flush_tlb_single(unsigned long addr)
|
2006-12-07 09:14:08 +08:00
|
|
|
{
|
|
|
|
__native_flush_tlb_single(addr);
|
|
|
|
}
|
|
|
|
|
2006-12-07 09:14:07 +08:00
|
|
|
/* These are in entry.S */
|
2007-02-13 20:26:25 +08:00
|
|
|
extern void native_iret(void);
|
2008-01-30 20:30:33 +08:00
|
|
|
extern void native_irq_enable_syscall_ret(void);
|
2006-12-07 09:14:07 +08:00
|
|
|
|
|
|
|
static int __init print_banner(void)
|
|
|
|
{
|
2007-10-17 02:51:29 +08:00
|
|
|
pv_init_ops.banner();
|
2006-12-07 09:14:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
core_initcall(print_banner);
|
|
|
|
|
2007-07-18 09:37:04 +08:00
|
|
|
static struct resource reserve_ioports = {
|
|
|
|
.start = 0,
|
|
|
|
.end = IO_SPACE_LIMIT,
|
|
|
|
.name = "paravirt-ioport",
|
|
|
|
.flags = IORESOURCE_IO | IORESOURCE_BUSY,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource reserve_iomem = {
|
|
|
|
.start = 0,
|
|
|
|
.end = -1,
|
|
|
|
.name = "paravirt-iomem",
|
|
|
|
.flags = IORESOURCE_MEM | 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)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = request_resource(&ioport_resource, &reserve_ioports);
|
|
|
|
if (ret == 0) {
|
|
|
|
ret = request_resource(&iomem_resource, &reserve_iomem);
|
|
|
|
if (ret)
|
|
|
|
release_resource(&reserve_ioports);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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-17 02:51:29 +08: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)
|
|
|
|
{
|
|
|
|
BUG_ON(x86_read_percpu(paravirt_lazy_mode) != PARAVIRT_LAZY_NONE);
|
|
|
|
BUG_ON(preemptible());
|
|
|
|
|
|
|
|
x86_write_percpu(paravirt_lazy_mode, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void paravirt_leave_lazy(enum paravirt_lazy_mode mode)
|
|
|
|
{
|
|
|
|
BUG_ON(x86_read_percpu(paravirt_lazy_mode) != mode);
|
|
|
|
BUG_ON(preemptible());
|
|
|
|
|
|
|
|
x86_write_percpu(paravirt_lazy_mode, PARAVIRT_LAZY_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return x86_read_percpu(paravirt_lazy_mode);
|
|
|
|
}
|
|
|
|
|
2007-10-17 02:51:29 +08:00
|
|
|
struct pv_info pv_info = {
|
2006-12-07 09:14:07 +08: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-03 01:27:13 +08:00
|
|
|
.shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
|
2007-10-17 02:51:29 +08:00
|
|
|
};
|
2006-12-07 09:14:07 +08:00
|
|
|
|
2007-10-17 02:51:29 +08:00
|
|
|
struct pv_init_ops pv_init_ops = {
|
|
|
|
.patch = native_patch,
|
2006-12-07 09:14:07 +08:00
|
|
|
.banner = default_banner,
|
2007-05-03 01:27:13 +08:00
|
|
|
.arch_setup = paravirt_nop,
|
2006-12-07 09:14:07 +08:00
|
|
|
.memory_setup = machine_specific_memory_setup,
|
2007-10-17 02:51:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pv_time_ops pv_time_ops = {
|
|
|
|
.time_init = hpet_time_init,
|
2006-12-07 09:14:07 +08:00
|
|
|
.get_wallclock = native_get_wallclock,
|
|
|
|
.set_wallclock = native_set_wallclock,
|
2007-10-17 02:51:29 +08:00
|
|
|
.sched_clock = native_sched_clock,
|
|
|
|
.get_cpu_khz = native_calculate_cpu_khz,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pv_irq_ops pv_irq_ops = {
|
2006-12-07 09:14:07 +08:00
|
|
|
.init_IRQ = native_init_IRQ,
|
2007-10-17 02:51:29 +08: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,
|
|
|
|
};
|
2006-12-07 09:14:07 +08:00
|
|
|
|
2007-10-17 02:51:29 +08:00
|
|
|
struct pv_cpu_ops pv_cpu_ops = {
|
2006-12-07 09:14:07 +08: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,
|
|
|
|
.wbinvd = native_wbinvd,
|
2007-05-03 01:27:10 +08:00
|
|
|
.read_msr = native_read_msr_safe,
|
|
|
|
.write_msr = native_write_msr_safe,
|
2006-12-07 09:14:07 +08:00
|
|
|
.read_tsc = native_read_tsc,
|
|
|
|
.read_pmc = native_read_pmc,
|
|
|
|
.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-01-30 20:31:13 +08:00
|
|
|
.write_ldt_entry = native_write_ldt_entry,
|
2008-01-30 20:31:13 +08:00
|
|
|
.write_gdt_entry = native_write_gdt_entry,
|
2008-01-30 20:31:12 +08:00
|
|
|
.write_idt_entry = native_write_idt_entry,
|
2008-01-30 20:31:02 +08:00
|
|
|
.load_sp0 = native_load_sp0,
|
2006-12-07 09:14:07 +08:00
|
|
|
|
2008-01-30 20:30:33 +08:00
|
|
|
.irq_enable_syscall_ret = native_irq_enable_syscall_ret,
|
2007-10-17 02:51:29 +08:00
|
|
|
.iret = native_iret,
|
|
|
|
|
2006-12-07 09:14:07 +08: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-17 02:51:29 +08:00
|
|
|
|
|
|
|
.lazy_mode = {
|
|
|
|
.enter = paravirt_nop,
|
|
|
|
.leave = paravirt_nop,
|
|
|
|
},
|
2007-10-17 02:51:29 +08:00
|
|
|
};
|
2006-12-07 09:14:07 +08:00
|
|
|
|
2007-10-17 02:51:29 +08:00
|
|
|
struct pv_apic_ops pv_apic_ops = {
|
2006-12-07 09:14:08 +08:00
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
|
|
|
.apic_write = native_apic_write,
|
|
|
|
.apic_write_atomic = native_apic_write_atomic,
|
|
|
|
.apic_read = native_apic_read,
|
2007-02-13 20:26:21 +08:00
|
|
|
.setup_boot_clock = setup_boot_APIC_clock,
|
|
|
|
.setup_secondary_clock = setup_secondary_APIC_clock,
|
2007-05-03 01:27:18 +08:00
|
|
|
.startup_ipi_hook = paravirt_nop,
|
2006-12-07 09:14:08 +08:00
|
|
|
#endif
|
2007-10-17 02:51:29 +08: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-03 01:27:13 +08:00
|
|
|
.pagetable_setup_start = native_pagetable_setup_start,
|
|
|
|
.pagetable_setup_done = native_pagetable_setup_done,
|
|
|
|
|
2007-10-17 02:51:29 +08:00
|
|
|
.read_cr2 = native_read_cr2,
|
|
|
|
.write_cr2 = native_write_cr2,
|
|
|
|
.read_cr3 = native_read_cr3,
|
|
|
|
.write_cr3 = native_write_cr3,
|
|
|
|
|
2006-12-07 09:14:08 +08:00
|
|
|
.flush_tlb_user = native_flush_tlb,
|
|
|
|
.flush_tlb_kernel = native_flush_tlb_global,
|
|
|
|
.flush_tlb_single = native_flush_tlb_single,
|
2007-05-03 01:27:15 +08:00
|
|
|
.flush_tlb_others = native_flush_tlb_others,
|
2006-12-07 09:14:08 +08:00
|
|
|
|
2007-05-03 01:27:13 +08:00
|
|
|
.alloc_pt = paravirt_nop,
|
|
|
|
.alloc_pd = paravirt_nop,
|
|
|
|
.alloc_pd_clone = paravirt_nop,
|
|
|
|
.release_pt = paravirt_nop,
|
|
|
|
.release_pd = paravirt_nop,
|
2007-02-13 20:26:21 +08:00
|
|
|
|
2006-12-07 09:14:08 +08:00
|
|
|
.set_pte = native_set_pte,
|
|
|
|
.set_pte_at = native_set_pte_at,
|
|
|
|
.set_pmd = native_set_pmd,
|
2007-05-03 01:27:13 +08:00
|
|
|
.pte_update = paravirt_nop,
|
|
|
|
.pte_update_defer = paravirt_nop,
|
2007-05-03 01:27:13 +08:00
|
|
|
|
2007-05-03 01:27:15 +08:00
|
|
|
#ifdef CONFIG_HIGHPTE
|
|
|
|
.kmap_atomic_pte = kmap_atomic,
|
|
|
|
#endif
|
|
|
|
|
2006-12-07 09:14:08 +08:00
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
.set_pte_atomic = native_set_pte_atomic,
|
|
|
|
.set_pte_present = native_set_pte_present,
|
|
|
|
.set_pud = native_set_pud,
|
|
|
|
.pte_clear = native_pte_clear,
|
|
|
|
.pmd_clear = native_pmd_clear,
|
2007-05-03 01:27:13 +08:00
|
|
|
|
|
|
|
.pmd_val = native_pmd_val,
|
|
|
|
.make_pmd = native_make_pmd,
|
2006-12-07 09:14:08 +08:00
|
|
|
#endif
|
|
|
|
|
2007-05-03 01:27:13 +08:00
|
|
|
.pte_val = native_pte_val,
|
|
|
|
.pgd_val = native_pgd_val,
|
|
|
|
|
|
|
|
.make_pte = native_make_pte,
|
|
|
|
.make_pgd = native_make_pgd,
|
|
|
|
|
2007-05-03 01:27:14 +08: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-17 02:51:29 +08:00
|
|
|
|
|
|
|
.lazy_mode = {
|
|
|
|
.enter = paravirt_nop,
|
|
|
|
.leave = paravirt_nop,
|
|
|
|
},
|
2006-12-07 09:14:07 +08:00
|
|
|
};
|
2007-01-23 12:40:36 +08:00
|
|
|
|
2007-10-17 02:51:29 +08: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 08:22:11 +08:00
|
|
|
EXPORT_SYMBOL (pv_cpu_ops);
|
|
|
|
EXPORT_SYMBOL (pv_mmu_ops);
|
2007-10-17 02:51:29 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pv_apic_ops);
|
|
|
|
EXPORT_SYMBOL_GPL(pv_info);
|
|
|
|
EXPORT_SYMBOL (pv_irq_ops);
|