2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* S390 version
|
2012-07-20 13:15:04 +04:00
|
|
|
* Copyright IBM Corp. 2002, 2006
|
2005-04-17 02:20:36 +04:00
|
|
|
* Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASM_THREAD_INFO_H
|
|
|
|
#define _ASM_THREAD_INFO_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Size of kernel stack for each process
|
|
|
|
*/
|
2012-05-23 18:24:51 +04:00
|
|
|
#ifndef CONFIG_64BIT
|
2005-04-17 02:20:36 +04:00
|
|
|
#define THREAD_ORDER 1
|
|
|
|
#define ASYNC_ORDER 1
|
2012-05-23 18:24:51 +04:00
|
|
|
#else /* CONFIG_64BIT */
|
2005-04-17 02:20:36 +04:00
|
|
|
#define THREAD_ORDER 2
|
|
|
|
#define ASYNC_ORDER 2
|
2012-05-23 18:24:51 +04:00
|
|
|
#endif /* CONFIG_64BIT */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER)
|
|
|
|
#define ASYNC_SIZE (PAGE_SIZE << ASYNC_ORDER)
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
#include <asm/lowcore.h>
|
2009-04-14 17:36:16 +04:00
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/processor.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* low level task data that entry.S needs immediate access to
|
|
|
|
* - this struct should fit entirely inside of one cache line
|
|
|
|
* - this struct shares the supervisor stack pages
|
|
|
|
* - if the contents of this structure are changed, the assembly constants must also be changed
|
|
|
|
*/
|
|
|
|
struct thread_info {
|
|
|
|
struct task_struct *task; /* main task structure */
|
|
|
|
struct exec_domain *exec_domain; /* execution domain */
|
|
|
|
unsigned long flags; /* low level flags */
|
2013-04-24 14:58:39 +04:00
|
|
|
unsigned long sys_call_table; /* System call table address */
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int cpu; /* current CPU */
|
2005-06-23 11:09:07 +04:00
|
|
|
int preempt_count; /* 0 => preemptable, <0 => BUG */
|
2005-04-17 02:20:36 +04:00
|
|
|
struct restart_block restart_block;
|
2011-10-30 18:16:47 +04:00
|
|
|
unsigned int system_call;
|
2008-12-31 17:11:39 +03:00
|
|
|
__u64 user_timer;
|
|
|
|
__u64 system_timer;
|
2010-05-17 12:00:05 +04:00
|
|
|
unsigned long last_break; /* last breaking-event-address. */
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* macros/functions for gaining access to the thread information structure
|
|
|
|
*/
|
|
|
|
#define INIT_THREAD_INFO(tsk) \
|
|
|
|
{ \
|
|
|
|
.task = &tsk, \
|
|
|
|
.exec_domain = &default_exec_domain, \
|
|
|
|
.flags = 0, \
|
|
|
|
.cpu = 0, \
|
2009-07-10 16:57:56 +04:00
|
|
|
.preempt_count = INIT_PREEMPT_COUNT, \
|
2005-04-17 02:20:36 +04:00
|
|
|
.restart_block = { \
|
|
|
|
.fn = do_no_restart_syscall, \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define init_thread_info (init_thread_union.thread_info)
|
|
|
|
#define init_stack (init_thread_union.stack)
|
|
|
|
|
|
|
|
/* how to get the thread information struct from C */
|
|
|
|
static inline struct thread_info *current_thread_info(void)
|
|
|
|
{
|
2011-01-05 14:47:42 +03:00
|
|
|
return (struct thread_info *) S390_lowcore.thread_info;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2008-07-25 12:45:40 +04:00
|
|
|
#define THREAD_SIZE_ORDER THREAD_ORDER
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* thread information flags bit numbers
|
|
|
|
*/
|
2011-10-30 18:16:49 +04:00
|
|
|
#define TIF_SYSCALL 0 /* inside a system call */
|
2008-10-10 23:33:20 +04:00
|
|
|
#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
|
2005-04-17 02:20:36 +04:00
|
|
|
#define TIF_SIGPENDING 2 /* signal pending */
|
|
|
|
#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
|
2014-04-14 17:11:26 +04:00
|
|
|
#define TIF_ASCE 5 /* user asce needs fixup / uaccess */
|
2011-01-05 14:48:10 +03:00
|
|
|
#define TIF_PER_TRAP 6 /* deliver sigtrap on return to user */
|
2005-06-26 01:55:30 +04:00
|
|
|
#define TIF_MCCK_PENDING 7 /* machine check handling is pending */
|
2009-06-12 12:26:26 +04:00
|
|
|
#define TIF_SYSCALL_TRACE 8 /* syscall trace active */
|
|
|
|
#define TIF_SYSCALL_AUDIT 9 /* syscall auditing active */
|
|
|
|
#define TIF_SECCOMP 10 /* secure computing */
|
2009-08-25 01:43:11 +04:00
|
|
|
#define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
|
2010-01-13 22:44:28 +03:00
|
|
|
#define TIF_31BIT 17 /* 32bit process */
|
2010-05-14 13:13:27 +04:00
|
|
|
#define TIF_MEMDIE 18 /* is terminating due to OOM killer */
|
2010-01-13 22:44:28 +03:00
|
|
|
#define TIF_RESTORE_SIGMASK 19 /* restore signal mask in do_signal() */
|
2011-01-05 14:48:10 +03:00
|
|
|
#define TIF_SINGLE_STEP 20 /* This task is single stepped */
|
2014-03-14 15:01:08 +04:00
|
|
|
#define TIF_BLOCK_STEP 21 /* This task is block stepped */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-10-30 18:16:49 +04:00
|
|
|
#define _TIF_SYSCALL (1<<TIF_SYSCALL)
|
2008-10-10 23:33:20 +04:00
|
|
|
#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
|
|
|
|
#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
|
s390/uaccess: rework uaccess code - fix locking issues
The current uaccess code uses a page table walk in some circumstances,
e.g. in case of the in atomic futex operations or if running on old
hardware which doesn't support the mvcos instruction.
However it turned out that the page table walk code does not correctly
lock page tables when accessing page table entries.
In other words: a different cpu may invalidate a page table entry while
the current cpu inspects the pte. This may lead to random data corruption.
Adding correct locking however isn't trivial for all uaccess operations.
Especially copy_in_user() is problematic since that requires to hold at
least two locks, but must be protected against ABBA deadlock when a
different cpu also performs a copy_in_user() operation.
So the solution is a different approach where we change address spaces:
User space runs in primary address mode, or access register mode within
vdso code, like it currently already does.
The kernel usually also runs in home space mode, however when accessing
user space the kernel switches to primary or secondary address mode if
the mvcos instruction is not available or if a compare-and-swap (futex)
instruction on a user space address is performed.
KVM however is special, since that requires the kernel to run in home
address space while implicitly accessing user space with the sie
instruction.
So we end up with:
User space:
- runs in primary or access register mode
- cr1 contains the user asce
- cr7 contains the user asce
- cr13 contains the kernel asce
Kernel space:
- runs in home space mode
- cr1 contains the user or kernel asce
-> the kernel asce is loaded when a uaccess requires primary or
secondary address mode
- cr7 contains the user or kernel asce, (changed with set_fs())
- cr13 contains the kernel asce
In case of uaccess the kernel changes to:
- primary space mode in case of a uaccess (copy_to_user) and uses
e.g. the mvcp instruction to access user space. However the kernel
will stay in home space mode if the mvcos instruction is available
- secondary space mode in case of futex atomic operations, so that the
instructions come from primary address space and data from secondary
space
In case of kvm the kernel runs in home space mode, but cr1 gets switched
to contain the gmap asce before the sie instruction gets executed. When
the sie instruction is finished cr1 will be switched back to contain the
user asce.
A context switch between two processes will always load the kernel asce
for the next process in cr1. So the first exit to user space is a bit
more expensive (one extra load control register instruction) than before,
however keeps the code rather simple.
In sum this means there is no need to perform any error prone page table
walks anymore when accessing user space.
The patch seems to be rather large, however it mainly removes the
the page table walk code and restores the previously deleted "standard"
uaccess code, with a couple of changes.
The uaccess without mvcos mode can be enforced with the "uaccess_primary"
kernel parameter.
Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2014-03-21 13:42:25 +04:00
|
|
|
#define _TIF_ASCE (1<<TIF_ASCE)
|
2011-01-05 14:48:10 +03:00
|
|
|
#define _TIF_PER_TRAP (1<<TIF_PER_TRAP)
|
2005-06-26 01:55:30 +04:00
|
|
|
#define _TIF_MCCK_PENDING (1<<TIF_MCCK_PENDING)
|
2009-06-12 12:26:26 +04:00
|
|
|
#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
|
|
|
|
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
|
|
|
|
#define _TIF_SECCOMP (1<<TIF_SECCOMP)
|
2009-08-25 01:43:11 +04:00
|
|
|
#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define _TIF_31BIT (1<<TIF_31BIT)
|
2011-10-30 18:16:35 +04:00
|
|
|
#define _TIF_SINGLE_STEP (1<<TIF_SINGLE_STEP)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-01-12 11:55:29 +03:00
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
#define is_32bit_task() (test_thread_flag(TIF_31BIT))
|
|
|
|
#else
|
|
|
|
#define is_32bit_task() (1)
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif /* _ASM_THREAD_INFO_H */
|