s390/mm: add debug user asce support
authorHeiko Carstens <hca@linux.ibm.com>
Mon, 16 Nov 2020 07:06:41 +0000 (08:06 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Mon, 23 Nov 2020 11:01:12 +0000 (12:01 +0100)
Verify on exit to user space that always
- the primary ASCE (cr1) is set to kernel ASCE
- the secondary ASCE (cr7) is set to user ASCE

If this is not the case: panic since something went terribly wrong.

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/Kconfig.debug
arch/s390/configs/debug_defconfig
arch/s390/include/asm/uaccess.h
arch/s390/kernel/entry.S
arch/s390/lib/uaccess.c

index ab48b69..6bfacee 100644 (file)
@@ -5,3 +5,11 @@ config TRACE_IRQFLAGS_SUPPORT
 
 config EARLY_PRINTK
        def_bool y
+
+config DEBUG_USER_ASCE
+       bool "Debug User ASCE"
+       help
+         Check on exit to user space that address space control
+         elements are setup correctly.
+
+         If unsure, say N.
index fe6f529..c52113a 100644 (file)
@@ -826,6 +826,7 @@ CONFIG_FTRACE_SYSCALLS=y
 CONFIG_BLK_DEV_IO_TRACE=y
 CONFIG_BPF_KPROBE_OVERRIDE=y
 CONFIG_HIST_TRIGGERS=y
+CONFIG_DEBUG_USER_ASCE=y
 CONFIG_NOTIFIER_ERROR_INJECTION=m
 CONFIG_NETDEV_NOTIFIER_ERROR_INJECT=m
 CONFIG_FAULT_INJECTION=y
index e59fd96..c670788 100644 (file)
@@ -18,6 +18,8 @@
 #include <asm/extable.h>
 #include <asm/facility.h>
 
+void debug_user_asce(void);
+
 static inline int __range_ok(unsigned long addr, unsigned long size)
 {
        return 1;
index d43ef46..377f756 100644 (file)
@@ -90,6 +90,12 @@ _LPP_OFFSET  = __LC_LPP
 #endif
        .endm
 
+       .macro  DEBUG_USER_ASCE
+#ifdef CONFIG_DEBUG_USER_ASCE
+       brasl   %r14,debug_user_asce
+#endif
+       .endm
+
        .macro  CHECK_VMAP_STACK savearea,oklabel
 #ifdef CONFIG_VMAP_STACK
        lgr     %r14,%r15
@@ -428,6 +434,7 @@ ENTRY(system_call)
        jnz     .Lsysc_work
        TSTMSK  __TI_flags(%r12),_TIF_WORK
        jnz     .Lsysc_work                     # check for work
+       DEBUG_USER_ASCE
        lctlg   %c1,%c1,__LC_USER_ASCE
        BPEXIT  __TI_flags(%r12),_TIF_ISOLATE_BP
        TSTMSK  __LC_CPU_FLAGS, _CIF_FPU
@@ -793,6 +800,7 @@ ENTRY(io_int_handler)
        mvc     __LC_RETURN_PSW(16),__PT_PSW(%r11)
        tm      __PT_PSW+1(%r11),0x01   # returning to user ?
        jno     .Lio_exit_kernel
+       DEBUG_USER_ASCE
        lctlg   %c1,%c1,__LC_USER_ASCE
        BPEXIT  __TI_flags(%r12),_TIF_ISOLATE_BP
        stpt    __LC_EXIT_TIMER
index 0ffbe1f..e8f6424 100644 (file)
 #include <asm/mmu_context.h>
 #include <asm/facility.h>
 
+#ifdef CONFIG_DEBUG_USER_ASCE
+void debug_user_asce(void)
+{
+       unsigned long cr1, cr7;
+
+       __ctl_store(cr1, 1, 1);
+       __ctl_store(cr7, 7, 7);
+       if (cr1 == S390_lowcore.kernel_asce && cr7 == S390_lowcore.user_asce)
+               return;
+       panic("incorrect ASCE on kernel exit\n"
+             "cr1:    %016lx cr7:  %016lx\n"
+             "kernel: %016llx user: %016llx\n",
+             cr1, cr7, S390_lowcore.kernel_asce, S390_lowcore.user_asce);
+}
+#endif /*CONFIG_DEBUG_USER_ASCE */
+
 #ifndef CONFIG_HAVE_MARCH_Z10_FEATURES
 static DEFINE_STATIC_KEY_FALSE(have_mvcos);