2005-04-16 22:20:36 +00:00
|
|
|
#ifndef __I386_SCHED_H
|
|
|
|
#define __I386_SCHED_H
|
|
|
|
|
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/atomic.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/tlbflush.h>
|
2007-05-02 17:27:14 +00:00
|
|
|
#include <asm/paravirt.h>
|
|
|
|
#ifndef CONFIG_PARAVIRT
|
|
|
|
#include <asm-generic/mm_hooks.h>
|
|
|
|
|
|
|
|
static inline void paravirt_activate_mm(struct mm_struct *prev,
|
|
|
|
struct mm_struct *next)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* !CONFIG_PARAVIRT */
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Used for LDT copy/destruction.
|
|
|
|
*/
|
|
|
|
int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
|
|
|
|
void destroy_context(struct mm_struct *mm);
|
|
|
|
|
|
|
|
|
|
|
|
static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
unsigned cpu = smp_processor_id();
|
|
|
|
if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK)
|
|
|
|
per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_LAZY;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void switch_mm(struct mm_struct *prev,
|
|
|
|
struct mm_struct *next,
|
|
|
|
struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
|
|
|
|
if (likely(prev != next)) {
|
|
|
|
/* stop flush ipis for the previous mm */
|
|
|
|
cpu_clear(cpu, prev->cpu_vm_mask);
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK;
|
|
|
|
per_cpu(cpu_tlbstate, cpu).active_mm = next;
|
|
|
|
#endif
|
|
|
|
cpu_set(cpu, next->cpu_vm_mask);
|
|
|
|
|
|
|
|
/* Re-load page tables */
|
|
|
|
load_cr3(next->pgd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load the LDT, if the LDT is different:
|
|
|
|
*/
|
|
|
|
if (unlikely(prev->context.ldt != next->context.ldt))
|
2006-12-07 01:14:01 +00:00
|
|
|
load_LDT_nolock(&next->context);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
else {
|
|
|
|
per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK;
|
|
|
|
BUG_ON(per_cpu(cpu_tlbstate, cpu).active_mm != next);
|
|
|
|
|
|
|
|
if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
|
2008-03-23 08:02:42 +00:00
|
|
|
/* We were in lazy tlb mode and leave_mm disabled
|
2005-04-16 22:20:36 +00:00
|
|
|
* tlb flush IPI delivery. We must reload %cr3.
|
|
|
|
*/
|
|
|
|
load_cr3(next->pgd);
|
2006-12-07 01:14:01 +00:00
|
|
|
load_LDT_nolock(&next->context);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
[PATCH] i386: Use %gs as the PDA base-segment in the kernel
This patch is the meat of the PDA change. This patch makes several related
changes:
1: Most significantly, %gs is now used in the kernel. This means that on
entry, the old value of %gs is saved away, and it is reloaded with
__KERNEL_PDA.
2: entry.S constructs the stack in the shape of struct pt_regs, and this
is passed around the kernel so that the process's saved register
state can be accessed.
Unfortunately struct pt_regs doesn't currently have space for %gs
(or %fs). This patch extends pt_regs to add space for gs (no space
is allocated for %fs, since it won't be used, and it would just
complicate the code in entry.S to work around the space).
3: Because %gs is now saved on the stack like %ds, %es and the integer
registers, there are a number of places where it no longer needs to
be handled specially; namely context switch, and saving/restoring the
register state in a signal context.
4: And since kernel threads run in kernel space and call normal kernel
code, they need to be created with their %gs == __KERNEL_PDA.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Chuck Ebbert <76306.1226@compuserve.com>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Jan Beulich <jbeulich@novell.com>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
2006-12-07 01:14:02 +00:00
|
|
|
#define deactivate_mm(tsk, mm) \
|
2007-02-13 12:26:20 +00:00
|
|
|
asm("movl %0,%%gs": :"r" (0));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-03-23 08:02:42 +00:00
|
|
|
#define activate_mm(prev, next) \
|
|
|
|
do { \
|
|
|
|
paravirt_activate_mm((prev), (next)); \
|
|
|
|
switch_mm((prev), (next), NULL); \
|
|
|
|
} while (0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#endif
|