2019-08-25 09:49:19 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2008-02-05 06:30:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __UM_THREAD_INFO_H
|
|
|
|
#define __UM_THREAD_INFO_H
|
|
|
|
|
2018-01-02 15:12:01 +00:00
|
|
|
#define THREAD_SIZE_ORDER CONFIG_KERNEL_STACK_ORDER
|
|
|
|
#define THREAD_SIZE ((1 << CONFIG_KERNEL_STACK_ORDER) * PAGE_SIZE)
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#include <asm/types.h>
|
uml: header untangling
Untangle UML headers somewhat and add some includes where they were
needed explicitly, but gotten accidentally via some other header.
arch/um/include/um_uaccess.h loses asm/fixmap.h because it uses no
fixmap stuff and gains elf.h, because it needs FIXADDR_USER_*, and
archsetjmp.h, because it needs jmp_buf.
pmd_alloc_one is uninlined because it needs mm_struct, and that's
inconvenient to provide in asm-um/pgtable-3level.h.
elf_core_copy_fpregs is also uninlined from elf-i386.h and
elf-x86_64.h, which duplicated the code anyway, to
arch/um/kernel/process.c, so that the reference to current_thread
doesn't pull sched.h or anything related into asm/elf.h.
arch/um/sys-i386/ldt.c, arch/um/kernel/tlb.c and
arch/um/kernel/skas/uaccess.c got sched.h because they dereference
task_structs. Its includes of linux and asm headers got turned from
"" to <>.
arch/um/sys-i386/bug.c gets asm/errno.h because it needs errno
constants.
asm/elf-i386 gets asm/user.h because it needs user_regs_struct.
asm/fixmap.h gets page.h because it needs PAGE_SIZE and PAGE_MASK and
system.h for BUG_ON.
asm/pgtable doesn't need sched.h.
asm/processor-generic.h defined mm_segment_t, but didn't use it. So,
that definition is moved to uaccess.h, which defines a bunch of
mm_segment_t-related stuff. thread_info.h uses mm_segment_t, and
includes uaccess.h, which causes a recursion. So, the definition is
placed above the include of thread_info. in uaccess.h. thread_info.h
also gets page.h because it needs PAGE_SIZE.
ObCheckpatchViolationJustification - I'm not adding a typedef; I'm
moving mm_segment_t from one place to another.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-05 06:30:53 +00:00
|
|
|
#include <asm/page.h>
|
2015-05-11 22:17:28 +00:00
|
|
|
#include <asm/segment.h>
|
2017-07-29 15:03:23 +00:00
|
|
|
#include <sysdep/ptrace_user.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
struct thread_info {
|
|
|
|
struct task_struct *task; /* main task structure */
|
|
|
|
unsigned long flags; /* low level flags */
|
|
|
|
__u32 cpu; /* current CPU */
|
2005-06-23 07:09:07 +00:00
|
|
|
int preempt_count; /* 0 => preemptable,
|
2005-04-16 22:20:36 +00:00
|
|
|
<0 => BUG */
|
|
|
|
mm_segment_t addr_limit; /* thread address space:
|
|
|
|
0-0xBFFFFFFF for user
|
|
|
|
0-0xFFFFFFFF for kernel */
|
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 05:22:34 +00:00
|
|
|
struct thread_info *real_thread; /* Points to non-IRQ stack */
|
2017-07-29 15:03:23 +00:00
|
|
|
unsigned long aux_fp_regs[FP_SIZE]; /* auxiliary fp_regs to save/restore
|
|
|
|
them out-of-band */
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define INIT_THREAD_INFO(tsk) \
|
|
|
|
{ \
|
2006-03-31 10:30:15 +00:00
|
|
|
.task = &tsk, \
|
|
|
|
.flags = 0, \
|
|
|
|
.cpu = 0, \
|
2009-07-10 12:57:56 +00:00
|
|
|
.preempt_count = INIT_PREEMPT_COUNT, \
|
2006-03-31 10:30:15 +00:00
|
|
|
.addr_limit = KERNEL_DS, \
|
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 05:22:34 +00:00
|
|
|
.real_thread = NULL, \
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* how to get the thread information struct from C */
|
|
|
|
static inline struct thread_info *current_thread_info(void)
|
|
|
|
{
|
|
|
|
struct thread_info *ti;
|
2005-05-28 22:52:00 +00:00
|
|
|
unsigned long mask = THREAD_SIZE - 1;
|
2011-04-27 22:26:54 +00:00
|
|
|
void *p;
|
|
|
|
|
|
|
|
asm volatile ("" : "=r" (p) : "0" (&ti));
|
|
|
|
ti = (struct thread_info *) (((unsigned long)p) & ~mask);
|
2005-04-16 22:20:36 +00:00
|
|
|
return ti;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
|
|
|
|
#define TIF_SIGPENDING 1 /* signal pending */
|
|
|
|
#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
|
2020-10-09 21:47:28 +00:00
|
|
|
#define TIF_NOTIFY_SIGNAL 3 /* signal notifications exist */
|
2010-05-14 09:13:27 +00:00
|
|
|
#define TIF_RESTART_BLOCK 4
|
|
|
|
#define TIF_MEMDIE 5 /* is terminating due to OOM killer */
|
2005-05-03 06:54:51 +00:00
|
|
|
#define TIF_SYSCALL_AUDIT 6
|
2006-01-19 01:44:02 +00:00
|
|
|
#define TIF_RESTORE_SIGMASK 7
|
2012-04-24 06:37:07 +00:00
|
|
|
#define TIF_NOTIFY_RESUME 8
|
2015-12-29 20:35:47 +00:00
|
|
|
#define TIF_SECCOMP 9 /* secure computing */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
|
|
|
|
#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
|
|
|
|
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
|
2020-10-09 21:47:28 +00:00
|
|
|
#define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
|
2005-05-03 06:54:51 +00:00
|
|
|
#define _TIF_MEMDIE (1 << TIF_MEMDIE)
|
|
|
|
#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
|
2015-12-29 20:35:47 +00:00
|
|
|
#define _TIF_SECCOMP (1 << TIF_SECCOMP)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#endif
|