2006-09-27 16:50:40 +08:00
|
|
|
/*
|
2007-10-16 16:27:00 +08:00
|
|
|
* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2006-09-27 16:50:40 +08:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
2012-10-08 10:27:32 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <as-layout.h>
|
|
|
|
#include <kern.h>
|
|
|
|
#include <os.h>
|
|
|
|
#include <skas.h>
|
2006-09-27 16:50:40 +08:00
|
|
|
|
|
|
|
int new_mm(unsigned long stack)
|
|
|
|
{
|
2008-02-05 14:30:58 +08:00
|
|
|
int fd, err;
|
2006-09-27 16:50:40 +08:00
|
|
|
|
|
|
|
fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
|
2007-10-16 16:27:00 +08:00
|
|
|
if (fd < 0)
|
2007-10-16 16:26:58 +08:00
|
|
|
return fd;
|
2006-09-27 16:50:40 +08:00
|
|
|
|
2008-02-05 14:30:58 +08:00
|
|
|
if (skas_needs_stub) {
|
|
|
|
err = map_stub_pages(fd, STUB_CODE, STUB_DATA, stack);
|
|
|
|
if (err) {
|
|
|
|
os_close_file(fd);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
2006-09-27 16:50:40 +08:00
|
|
|
|
2007-10-16 16:26:58 +08:00
|
|
|
return fd;
|
2006-09-27 16:50:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern void start_kernel(void);
|
|
|
|
|
2007-07-24 09:43:48 +08:00
|
|
|
static int __init start_kernel_proc(void *unused)
|
2006-09-27 16:50:40 +08:00
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
block_signals();
|
|
|
|
pid = os_getpid();
|
|
|
|
|
|
|
|
cpu_tasks[0].pid = pid;
|
|
|
|
cpu_tasks[0].task = current;
|
|
|
|
#ifdef CONFIG_SMP
|
2012-03-29 13:08:30 +08:00
|
|
|
init_cpu_online(get_cpu_mask(0));
|
2006-09-27 16:50:40 +08:00
|
|
|
#endif
|
|
|
|
start_kernel();
|
2007-10-16 16:26:58 +08:00
|
|
|
return 0;
|
2006-09-27 16:50:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int userspace_pid[];
|
|
|
|
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 13:22:34 +08:00
|
|
|
extern char cpu0_irqstack[];
|
|
|
|
|
2007-10-16 16:26:58 +08:00
|
|
|
int __init start_uml(void)
|
2006-09-27 16:50:40 +08:00
|
|
|
{
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 13:22:34 +08:00
|
|
|
stack_protections((unsigned long) &cpu0_irqstack);
|
|
|
|
set_sigstack(cpu0_irqstack, THREAD_SIZE);
|
2008-02-05 14:30:58 +08:00
|
|
|
if (proc_mm) {
|
2006-09-27 16:50:40 +08:00
|
|
|
userspace_pid[0] = start_userspace(0);
|
2008-02-05 14:30:58 +08:00
|
|
|
if (userspace_pid[0] < 0) {
|
|
|
|
printf("start_uml - start_userspace returned %d\n",
|
|
|
|
userspace_pid[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2006-09-27 16:50:40 +08:00
|
|
|
|
|
|
|
init_new_thread_signals();
|
|
|
|
|
|
|
|
init_task.thread.request.u.thread.proc = start_kernel_proc;
|
|
|
|
init_task.thread.request.u.thread.arg = NULL;
|
2007-10-16 16:26:58 +08:00
|
|
|
return start_idle_thread(task_stack_page(&init_task),
|
|
|
|
&init_task.thread.switch_buf);
|
2006-09-27 16:50:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long current_stub_stack(void)
|
|
|
|
{
|
2007-10-16 16:27:00 +08:00
|
|
|
if (current->mm == NULL)
|
2007-10-16 16:26:58 +08:00
|
|
|
return 0;
|
2006-09-27 16:50:40 +08:00
|
|
|
|
2007-10-16 16:27:06 +08:00
|
|
|
return current->mm->context.id.stack;
|
2006-09-27 16:50:40 +08:00
|
|
|
}
|