linux/arch/s390/kernel
Heiko Carstens 457f218095 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-04-03 14:31:04 +02:00
..
vdso32 s390/time,vdso: fix clock_gettime for CLOCK_MONOTONIC 2013-12-02 18:15:25 +01:00
vdso64 s390/time,vdso: fix clock_gettime for CLOCK_MONOTONIC 2013-12-02 18:15:25 +01:00
.gitignore s390: add various .gitignore files. 2012-05-16 14:42:41 +02:00
asm-offsets.c s390/uaccess: rework uaccess code - fix locking issues 2014-04-03 14:31:04 +02:00
audit.c
audit.h
base.S s390/comments: unify copyright messages and remove file names 2012-07-20 11:15:04 +02:00
cache.c s390/cache: get rid of compile warning 2013-10-24 17:17:06 +02:00
compat_audit.c
compat_linux.c s390/compat: add sync_file_range and fallocate compat syscalls 2014-03-04 09:05:47 +01:00
compat_linux.h s390/compat: get rid of compat wrapper assembly code 2014-03-06 16:30:48 +01:00
compat_ptrace.h [S390] ptrace cleanup 2011-01-05 12:47:31 +01:00
compat_signal.c s390/compat: get rid of compat wrapper assembly code 2014-03-06 16:30:48 +01:00
compat_wrapper.c s390/compat: add copyright statement 2014-03-29 10:51:28 +01:00
cpcmd.c s390/comments: unify copyright messages and remove file names 2012-07-20 11:15:04 +02:00
crash_dump.c s390/sclp: Determine HSA size dynamically for zfcpdump 2013-11-15 14:08:40 +01:00
debug.c s390: convert use of typedef ctl_table to struct ctl_table 2013-10-28 08:36:25 +01:00
diag.c [S390] replace diag10() with diag10_range() function 2011-05-10 17:13:43 +02:00
dis.c s390/kprobes: allow kprobes only on known instructions 2013-10-24 17:16:50 +02:00
dumpstack.c s390/dis: move disassembler function prototypes to proper header file 2013-10-24 17:16:48 +02:00
early.c s390/mm,tlb: optimize TLB flushing for zEC12 2014-04-03 14:31:00 +02:00
ebcdic.c s390/comments: unify copyright messages and remove file names 2012-07-20 11:15:04 +02:00
entry64.S s390/uaccess: rework uaccess code - fix locking issues 2014-04-03 14:31:04 +02:00
entry.h s390/compat: get rid of compat wrapper assembly code 2014-03-06 16:30:48 +01:00
entry.S s390/uaccess: rework uaccess code - fix locking issues 2014-04-03 14:31:04 +02:00
ftrace.c s390/ftrace: prepare_ftrace_return() function call order 2013-10-24 17:17:03 +02:00
head31.S s390/mm: let kernel text section always begin at 1MB 2012-10-09 14:16:59 +02:00
head64.S s390: fix kernel crash due to linkage stack instructions 2014-02-05 11:00:50 +01:00
head_kdump.S s390/kdump: Use 64 bit mode for 0x10000 entry point 2012-10-18 17:50:09 +02:00
head.S s390/bitops: optimize set_bit() for constant values 2013-10-24 17:16:53 +02:00
ipl.c s390/uaccess: always run the kernel in home space 2013-10-24 17:16:57 +02:00
irq.c s390/irq: Use defines for external interruption codes 2014-04-03 14:30:52 +02:00
jump_label.c s390/jump-label: add arch_jump_label_transform_static() 2011-10-25 11:54:37 -07:00
kprobes.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2013-11-15 16:47:22 -08:00
lgr.c s390/sysinfo,stsi: change return code handling 2012-09-26 15:45:12 +02:00
machine_kexec.c s390: make various functions static, add declarations to header files 2013-09-07 11:58:03 +02:00
Makefile s390/compat: remove compat exec domain 2014-03-07 15:26:02 +01:00
mcount64.S s390/ftrace: fix mcount adjustment 2013-05-15 13:09:09 +02:00
mcount.S s390/ftrace: fix mcount adjustment 2013-05-15 13:09:09 +02:00
module.c mm/arch: use NUMA_NO_NODE 2013-11-13 12:09:05 +09:00
nmi.c s390/time: clock comparator revalidation 2013-08-22 12:20:08 +02:00
os_info.c Include missing linux/slab.h inclusions 2013-04-29 15:42:01 -04:00
perf_cpum_cf_events.c s390/cpum_cf: Export event names in sysfs 2013-12-16 14:37:50 +01:00
perf_cpum_cf.c s390/irq: Use defines for external interruption codes 2014-04-03 14:30:52 +02:00
perf_cpum_sf.c s390/irq: Use defines for external interruption codes 2014-04-03 14:30:52 +02:00
perf_event.c s390/perf: make print_debug_cf() static 2014-03-14 12:59:32 +01:00
pgm_check.S s390/mm: handle asce-type exceptions as normal page fault 2013-11-25 09:15:42 +01:00
process.c s390/mm: optimize randomize_et_dyn for !PF_RANDOMIZE 2013-12-18 17:36:38 +01:00
processor.c s390: delete __cpuinit usage from all s390 files 2013-07-14 19:36:53 -04:00
ptrace.c s390/ptrace: add support for PTRACE_SINGLEBLOCK 2014-03-14 12:59:38 +01:00
reipl64.S s390/comments: unify copyright messages and remove file names 2012-07-20 11:15:04 +02:00
reipl.S s390/comments: unify copyright messages and remove file names 2012-07-20 11:15:04 +02:00
relocate_kernel64.S s390/comments: unify copyright messages and remove file names 2012-07-20 11:15:04 +02:00
relocate_kernel.S s390/comments: unify copyright messages and remove file names 2012-07-20 11:15:04 +02:00
runtime_instr.c s390/irq: Use defines for external interruption codes 2014-04-03 14:30:52 +02:00
s390_ksyms.c s390: use IS_ENABLED to check if a CONFIG is set to y or m 2013-12-16 14:38:04 +01:00
sclp.S s390/irq: Use defines for external interruption codes 2014-04-03 14:30:52 +02:00
setup.c s390/uaccess: remove dead kernel parameter 'user_mode=' 2014-02-21 08:50:16 +01:00
signal.c s390/signal: always restore saved runtime instrumentation psw bit 2013-11-20 09:04:53 +01:00
smp.c s390/mm,tlb: optimize TLB flushing for zEC12 2014-04-03 14:31:00 +02:00
stacktrace.c s390/comments: unify copyright messages and remove file names 2012-07-20 11:15:04 +02:00
suspend.c s390: make various functions static, add declarations to header files 2013-09-07 11:58:03 +02:00
swsusp_asm64.S s390/hibernate: add early resume function 2013-08-30 08:57:15 +02:00
sys_s390.c teach SYSCALL_DEFINE<n> how to deal with long long/unsigned long long 2013-03-03 22:46:22 -05:00
syscalls.S s390/compat: get rid of compat wrapper assembly code 2014-03-06 16:30:48 +01:00
sysinfo.c s390: delete __cpuinit usage from all s390 files 2013-07-14 19:36:53 -04:00
time.c s390/irq: Use defines for external interruption codes 2014-04-03 14:30:52 +02:00
topology.c s390/topology: Remove call to update_cpu_masks() 2014-03-07 15:26:05 +01:00
traps.c s390/dumpstack: fix call chain walking 2013-04-17 14:07:28 +02:00
vdso.c s390/vdso: fix access-list entry initialization 2013-12-02 15:31:09 +01:00
vmlinux.lds.S s390/linker skript: discard exit.data at runtime 2013-02-14 15:55:21 +01:00
vtime.c s390/vtime: correct idle time calculation 2013-10-31 09:52:52 +01:00