s390/mm: use invalid asce instead of kernel asce
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)
Create a region 3 page table which contains only invalid entries, and
use that via "s390_invalid_asce" instead of the kernel ASCE whenever
there is either
- no user address space available, e.g. during early startup
- as an intermediate ASCE when address spaces are switched

This makes sure that user space accesses in such situations are
guaranteed to fail.

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/include/asm/mmu_context.h
arch/s390/include/asm/pgtable.h
arch/s390/kernel/smp.c
arch/s390/kernel/vmlinux.lds.S
arch/s390/mm/init.c

index 51def96..87a84fc 100644 (file)
@@ -79,7 +79,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
        S390_lowcore.user_asce = next->context.asce;
        cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
        /* Clear previous user-ASCE from CR7 */
-       __ctl_load(S390_lowcore.kernel_asce, 7, 7);
+       __ctl_load(s390_invalid_asce, 7, 7);
        if (prev != next)
                cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
 }
index a8edd96..794746a 100644 (file)
@@ -23,6 +23,7 @@
 
 extern pgd_t swapper_pg_dir[];
 extern void paging_init(void);
+extern unsigned long s390_invalid_asce;
 
 enum {
        PG_DIRECT_MAP_4K = 0,
index cac96f2..7f7d81f 100644 (file)
@@ -259,7 +259,7 @@ static void pcpu_prepare_secondary(struct pcpu *pcpu, int cpu)
        lc->spinlock_index = 0;
        lc->percpu_offset = __per_cpu_offset[cpu];
        lc->kernel_asce = S390_lowcore.kernel_asce;
-       lc->user_asce = S390_lowcore.kernel_asce;
+       lc->user_asce = s390_invalid_asce;
        lc->machine_flags = S390_lowcore.machine_flags;
        lc->user_timer = lc->system_timer =
                lc->steal_timer = lc->avg_steal_timer = 0;
index 177ccfb..4c0e191 100644 (file)
@@ -10,7 +10,8 @@
  * Put .bss..swapper_pg_dir as the first thing in .bss. This will
  * make sure it has 16k alignment.
  */
-#define BSS_FIRST_SECTIONS *(.bss..swapper_pg_dir)
+#define BSS_FIRST_SECTIONS *(.bss..swapper_pg_dir) \
+                          *(.bss..invalid_pg_dir)
 
 /* Handle ro_after_init data on our own. */
 #define RO_AFTER_INIT_DATA
index 69e6e2a..73a1630 100644 (file)
@@ -49,6 +49,9 @@
 #include <linux/virtio_config.h>
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(".bss..swapper_pg_dir");
+static pgd_t invalid_pg_dir[PTRS_PER_PGD] __section(".bss..invalid_pg_dir");
+
+unsigned long s390_invalid_asce;
 
 unsigned long empty_zero_page, zero_page_mask;
 EXPORT_SYMBOL(empty_zero_page);
@@ -92,6 +95,9 @@ void __init paging_init(void)
        unsigned long pgd_type, asce_bits;
        psw_t psw;
 
+       s390_invalid_asce  = (unsigned long)invalid_pg_dir;
+       s390_invalid_asce |= _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
+       crst_table_init((unsigned long *)invalid_pg_dir, _REGION3_ENTRY_EMPTY);
        init_mm.pgd = swapper_pg_dir;
        if (VMALLOC_END > _REGION2_SIZE) {
                asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
@@ -102,14 +108,14 @@ void __init paging_init(void)
        }
        init_mm.context.asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
        S390_lowcore.kernel_asce = init_mm.context.asce;
-       S390_lowcore.user_asce = S390_lowcore.kernel_asce;
+       S390_lowcore.user_asce = s390_invalid_asce;
        crst_table_init((unsigned long *) init_mm.pgd, pgd_type);
        vmem_map_init();
        kasan_copy_shadow_mapping();
 
        /* enable virtual mapping in kernel mode */
        __ctl_load(S390_lowcore.kernel_asce, 1, 1);
-       __ctl_load(S390_lowcore.kernel_asce, 7, 7);
+       __ctl_load(S390_lowcore.user_asce, 7, 7);
        __ctl_load(S390_lowcore.kernel_asce, 13, 13);
        psw.mask = __extract_psw();
        psw_bits(psw).dat = 1;