Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 's390-6.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux

Pull s390 updates from Vasily Gorbik:

- Add support for stackleak feature. Also allow specifying
architecture-specific stackleak poison function to enable faster
implementation. On s390, the mvc-based implementation helps decrease
typical overhead from a factor of 3 to just 25%

- Convert all assembler files to use SYM* style macros, deprecating the
ENTRY() macro and other annotations. Select ARCH_USE_SYM_ANNOTATIONS

- Improve KASLR to also randomize module and special amode31 code base
load addresses

- Rework decompressor memory tracking to support memory holes and
improve error handling

- Add support for protected virtualization AP binding

- Add support for set_direct_map() calls

- Implement set_memory_rox() and noexec module_alloc()

- Remove obsolete overriding of mem*() functions for KASAN

- Rework kexec/kdump to avoid using nodat_stack to call purgatory

- Convert the rest of the s390 code to use flexible-array member
instead of a zero-length array

- Clean up uaccess inline asm

- Enable ARCH_HAS_MEMBARRIER_SYNC_CORE

- Convert to using CONFIG_FUNCTION_ALIGNMENT and enable
DEBUG_FORCE_FUNCTION_ALIGN_64B

- Resolve last_break in userspace fault reports

- Simplify one-level sysctl registration

- Clean up branch prediction handling

- Rework CPU counter facility to retrieve available counter sets just
once

- Other various small fixes and improvements all over the code

* tag 's390-6.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (118 commits)
s390/stackleak: provide fast __stackleak_poison() implementation
stackleak: allow to specify arch specific stackleak poison function
s390: select ARCH_USE_SYM_ANNOTATIONS
s390/mm: use VM_FLUSH_RESET_PERMS in module_alloc()
s390: wire up memfd_secret system call
s390/mm: enable ARCH_HAS_SET_DIRECT_MAP
s390/mm: use BIT macro to generate SET_MEMORY bit masks
s390/relocate_kernel: adjust indentation
s390/relocate_kernel: use SYM* macros instead of ENTRY(), etc.
s390/entry: use SYM* macros instead of ENTRY(), etc.
s390/purgatory: use SYM* macros instead of ENTRY(), etc.
s390/kprobes: use SYM* macros instead of ENTRY(), etc.
s390/reipl: use SYM* macros instead of ENTRY(), etc.
s390/head64: use SYM* macros instead of ENTRY(), etc.
s390/earlypgm: use SYM* macros instead of ENTRY(), etc.
s390/mcount: use SYM* macros instead of ENTRY(), etc.
s390/crc32le: use SYM* macros instead of ENTRY(), etc.
s390/crc32be: use SYM* macros instead of ENTRY(), etc.
s390/crypto,chacha: use SYM* macros instead of ENTRY(), etc.
s390/amode31: use SYM* macros instead of ENTRY(), etc.
...

+2813 -2465
+2 -2
Documentation/features/sched/membarrier-sync-core/arch-support.txt
··· 5 5 # 6 6 # Architecture requirements 7 7 # 8 - # * arm/arm64/powerpc 8 + # * arm/arm64/powerpc/s390 9 9 # 10 10 # Rely on implicit context synchronization as a result of exception return 11 11 # when returning from IPI handler, and when returning to user-space. ··· 45 45 | parisc: | TODO | 46 46 | powerpc: | ok | 47 47 | riscv: | TODO | 48 - | s390: | TODO | 48 + | s390: | ok | 49 49 | sh: | TODO | 50 50 | sparc: | TODO | 51 51 | um: | TODO |
+6 -4
arch/s390/Kconfig
··· 26 26 config GENERIC_BUG_RELATIVE_POINTERS 27 27 def_bool y 28 28 29 - config GENERIC_CSUM 30 - bool 31 - default y if KASAN 32 - 33 29 config GENERIC_LOCKBREAK 34 30 def_bool y if PREEMPTION 35 31 ··· 72 76 select ARCH_HAS_GCOV_PROFILE_ALL 73 77 select ARCH_HAS_GIGANTIC_PAGE 74 78 select ARCH_HAS_KCOV 79 + select ARCH_HAS_MEMBARRIER_SYNC_CORE 75 80 select ARCH_HAS_MEM_ENCRYPT 76 81 select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS 77 82 select ARCH_HAS_PTE_SPECIAL 78 83 select ARCH_HAS_SCALED_CPUTIME 84 + select ARCH_HAS_SET_DIRECT_MAP 79 85 select ARCH_HAS_SET_MEMORY 80 86 select ARCH_HAS_STRICT_KERNEL_RWX 81 87 select ARCH_HAS_STRICT_MODULE_RWX ··· 121 123 select ARCH_SUPPORTS_PER_VMA_LOCK 122 124 select ARCH_USE_BUILTIN_BSWAP 123 125 select ARCH_USE_CMPXCHG_LOCKREF 126 + select ARCH_USE_SYM_ANNOTATIONS 124 127 select ARCH_WANTS_DYNAMIC_TASK_STRUCT 125 128 select ARCH_WANTS_NO_INSTR 126 129 select ARCH_WANT_DEFAULT_BPF_JIT ··· 131 132 select CLONE_BACKWARDS2 132 133 select DMA_OPS if PCI 133 134 select DYNAMIC_FTRACE if FUNCTION_TRACER 135 + select FUNCTION_ALIGNMENT_8B if CC_IS_GCC 136 + select FUNCTION_ALIGNMENT_16B if !CC_IS_GCC 134 137 select GCC12_NO_ARRAY_BOUNDS 135 138 select GENERIC_ALLOCATOR 136 139 select GENERIC_CPU_AUTOPROBE ··· 154 153 select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET 155 154 select HAVE_ARCH_SECCOMP_FILTER 156 155 select HAVE_ARCH_SOFT_DIRTY 156 + select HAVE_ARCH_STACKLEAK 157 157 select HAVE_ARCH_TRACEHOOK 158 158 select HAVE_ARCH_TRANSPARENT_HUGEPAGE 159 159 select HAVE_ARCH_VMAP_STACK
+9 -23
arch/s390/appldata/appldata_base.c
··· 66 66 { }, 67 67 }; 68 68 69 - static struct ctl_table appldata_dir_table[] = { 70 - { 71 - .procname = appldata_proc_name, 72 - .maxlen = 0, 73 - .mode = S_IRUGO | S_IXUGO, 74 - .child = appldata_table, 75 - }, 76 - { }, 77 - }; 78 - 79 69 /* 80 70 * Timer 81 71 */ ··· 281 291 mutex_lock(&appldata_ops_mutex); 282 292 list_for_each(lh, &appldata_ops_list) { 283 293 tmp_ops = list_entry(lh, struct appldata_ops, list); 284 - if (&tmp_ops->ctl_table[2] == ctl) { 294 + if (&tmp_ops->ctl_table[0] == ctl) { 285 295 found = 1; 286 296 } 287 297 } ··· 351 361 if (ops->size > APPLDATA_MAX_REC_SIZE) 352 362 return -EINVAL; 353 363 354 - ops->ctl_table = kcalloc(4, sizeof(struct ctl_table), GFP_KERNEL); 364 + /* The last entry must be an empty one */ 365 + ops->ctl_table = kcalloc(2, sizeof(struct ctl_table), GFP_KERNEL); 355 366 if (!ops->ctl_table) 356 367 return -ENOMEM; 357 368 ··· 360 369 list_add(&ops->list, &appldata_ops_list); 361 370 mutex_unlock(&appldata_ops_mutex); 362 371 363 - ops->ctl_table[0].procname = appldata_proc_name; 364 - ops->ctl_table[0].maxlen = 0; 365 - ops->ctl_table[0].mode = S_IRUGO | S_IXUGO; 366 - ops->ctl_table[0].child = &ops->ctl_table[2]; 372 + ops->ctl_table[0].procname = ops->name; 373 + ops->ctl_table[0].mode = S_IRUGO | S_IWUSR; 374 + ops->ctl_table[0].proc_handler = appldata_generic_handler; 375 + ops->ctl_table[0].data = ops; 367 376 368 - ops->ctl_table[2].procname = ops->name; 369 - ops->ctl_table[2].mode = S_IRUGO | S_IWUSR; 370 - ops->ctl_table[2].proc_handler = appldata_generic_handler; 371 - ops->ctl_table[2].data = ops; 372 - 373 - ops->sysctl_header = register_sysctl_table(ops->ctl_table); 377 + ops->sysctl_header = register_sysctl(appldata_proc_name, ops->ctl_table); 374 378 if (!ops->sysctl_header) 375 379 goto out; 376 380 return 0; ··· 408 422 appldata_wq = alloc_ordered_workqueue("appldata", 0); 409 423 if (!appldata_wq) 410 424 return -ENOMEM; 411 - appldata_sysctl_header = register_sysctl_table(appldata_dir_table); 425 + appldata_sysctl_header = register_sysctl(appldata_proc_name, appldata_table); 412 426 return 0; 413 427 } 414 428
+1 -1
arch/s390/boot/Makefile
··· 35 35 36 36 CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char 37 37 38 - obj-y := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o vmem.o 38 + obj-y := head.o als.o startup.o physmem_info.o ipl_parm.o ipl_report.o vmem.o 39 39 obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o 40 40 obj-y += version.o pgm_check_info.o ctype.o ipl_data.o machine_kexec_reloc.o 41 41 obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o
+35 -7
arch/s390/boot/boot.h
··· 8 8 9 9 #ifndef __ASSEMBLY__ 10 10 11 + #include <asm/physmem_info.h> 12 + 11 13 struct machine_info { 12 14 unsigned char has_edat1 : 1; 13 15 unsigned char has_edat2 : 1; ··· 32 30 unsigned long init_mm_off; 33 31 unsigned long swapper_pg_dir_off; 34 32 unsigned long invalid_pg_dir_off; 33 + #ifdef CONFIG_KASAN 34 + unsigned long kasan_early_shadow_page_off; 35 + unsigned long kasan_early_shadow_pte_off; 36 + unsigned long kasan_early_shadow_pmd_off; 37 + unsigned long kasan_early_shadow_pud_off; 38 + unsigned long kasan_early_shadow_p4d_off; 39 + #endif 35 40 }; 36 41 37 42 void startup_kernel(void); 38 - unsigned long detect_memory(unsigned long *safe_addr); 39 - void mem_detect_set_usable_limit(unsigned long limit); 43 + unsigned long detect_max_physmem_end(void); 44 + void detect_physmem_online_ranges(unsigned long max_physmem_end); 45 + void physmem_set_usable_limit(unsigned long limit); 46 + void physmem_reserve(enum reserved_range_type type, unsigned long addr, unsigned long size); 47 + void physmem_free(enum reserved_range_type type); 48 + /* for continuous/multiple allocations per type */ 49 + unsigned long physmem_alloc_top_down(enum reserved_range_type type, unsigned long size, 50 + unsigned long align); 51 + /* for single allocations, 1 per type */ 52 + unsigned long physmem_alloc_range(enum reserved_range_type type, unsigned long size, 53 + unsigned long align, unsigned long min, unsigned long max, 54 + bool die_on_oom); 55 + unsigned long get_physmem_alloc_pos(void); 56 + bool ipl_report_certs_intersects(unsigned long addr, unsigned long size, 57 + unsigned long *intersection_start); 40 58 bool is_ipl_block_dump(void); 41 59 void store_ipl_parmblock(void); 42 - unsigned long read_ipl_report(unsigned long safe_addr); 60 + int read_ipl_report(void); 61 + void save_ipl_cert_comp_list(void); 43 62 void setup_boot_command_line(void); 44 63 void parse_boot_command_line(void); 45 64 void verify_facilities(void); 46 65 void print_missing_facilities(void); 47 66 void sclp_early_setup_buffer(void); 48 67 void print_pgm_check_info(void); 49 - unsigned long get_random_base(unsigned long safe_addr); 68 + unsigned long randomize_within_range(unsigned long size, unsigned long align, 69 + unsigned long min, unsigned long max); 50 70 void setup_vmem(unsigned long asce_limit); 51 - unsigned long vmem_estimate_memory_needs(unsigned long online_mem_total); 52 71 void __printf(1, 2) decompressor_printk(const char *fmt, ...); 72 + void print_stacktrace(unsigned long sp); 53 73 void error(char *m); 54 74 55 75 extern struct machine_info machine; ··· 81 57 extern unsigned long memory_limit; 82 58 extern unsigned long vmalloc_size; 83 59 extern int vmalloc_size_set; 84 - extern int kaslr_enabled; 85 60 extern char __boot_data_start[], __boot_data_end[]; 86 61 extern char __boot_data_preserved_start[], __boot_data_preserved_end[]; 87 62 extern char _decompressor_syms_start[], _decompressor_syms_end[]; 88 63 extern char _stack_start[], _stack_end[]; 89 - extern char _end[]; 64 + extern char _end[], _decompressor_end[]; 90 65 extern unsigned char _compressed_start[]; 91 66 extern unsigned char _compressed_end[]; 92 67 extern struct vmlinux_info _vmlinux_info; ··· 93 70 94 71 #define __abs_lowcore_pa(x) (((unsigned long)(x) - __abs_lowcore) % sizeof(struct lowcore)) 95 72 73 + static inline bool intersects(unsigned long addr0, unsigned long size0, 74 + unsigned long addr1, unsigned long size1) 75 + { 76 + return addr0 + size0 > addr1 && addr1 + size1 > addr0; 77 + } 96 78 #endif /* __ASSEMBLY__ */ 97 79 #endif /* BOOT_BOOT_H */
+4 -4
arch/s390/boot/install.sh
··· 17 17 18 18 echo "Warning: '${INSTALLKERNEL}' command not available - additional " \ 19 19 "bootloader config required" >&2 20 - if [ -f $4/vmlinuz-$1 ]; then mv $4/vmlinuz-$1 $4/vmlinuz-$1.old; fi 21 - if [ -f $4/System.map-$1 ]; then mv $4/System.map-$1 $4/System.map-$1.old; fi 20 + if [ -f "$4/vmlinuz-$1" ]; then mv -- "$4/vmlinuz-$1" "$4/vmlinuz-$1.old"; fi 21 + if [ -f "$4/System.map-$1" ]; then mv -- "$4/System.map-$1" "$4/System.map-$1.old"; fi 22 22 23 - cat $2 > $4/vmlinuz-$1 24 - cp $3 $4/System.map-$1 23 + cat -- "$2" > "$4/vmlinuz-$1" 24 + cp -- "$3" "$4/System.map-$1"
+3 -3
arch/s390/boot/ipl_parm.c
··· 24 24 unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL; 25 25 struct ipl_parameter_block __bootdata_preserved(ipl_block); 26 26 int __bootdata_preserved(ipl_block_valid); 27 + int __bootdata_preserved(__kaslr_enabled); 27 28 28 29 unsigned long vmalloc_size = VMALLOC_DEFAULT_SIZE; 29 30 unsigned long memory_limit; 30 31 int vmalloc_size_set; 31 - int kaslr_enabled; 32 32 33 33 static inline int __diag308(unsigned long subcode, void *addr) 34 34 { ··· 264 264 char *args; 265 265 int rc; 266 266 267 - kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE); 267 + __kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE); 268 268 args = strcpy(command_line_buf, early_command_line); 269 269 while (*args) { 270 270 args = next_arg(args, &param, &val); ··· 300 300 modify_fac_list(val); 301 301 302 302 if (!strcmp(param, "nokaslr")) 303 - kaslr_enabled = 0; 303 + __kaslr_enabled = 0; 304 304 305 305 #if IS_ENABLED(CONFIG_KVM) 306 306 if (!strcmp(param, "prot_virt")) {
+52 -60
arch/s390/boot/ipl_report.c
··· 5 5 #include <asm/sclp.h> 6 6 #include <asm/sections.h> 7 7 #include <asm/boot_data.h> 8 + #include <asm/physmem_info.h> 8 9 #include <uapi/asm/ipl.h> 9 10 #include "boot.h" 10 11 ··· 17 16 unsigned long __bootdata(early_ipl_comp_list_addr); 18 17 unsigned long __bootdata(early_ipl_comp_list_size); 19 18 19 + static struct ipl_rb_certificates *certs; 20 + static struct ipl_rb_components *comps; 21 + static bool ipl_report_needs_saving; 22 + 20 23 #define for_each_rb_entry(entry, rb) \ 21 24 for (entry = rb->entries; \ 22 25 (void *) entry + sizeof(*entry) <= (void *) rb + rb->len; \ 23 26 entry++) 24 27 25 - static inline bool intersects(unsigned long addr0, unsigned long size0, 26 - unsigned long addr1, unsigned long size1) 27 - { 28 - return addr0 + size0 > addr1 && addr1 + size1 > addr0; 29 - } 30 - 31 - static unsigned long find_bootdata_space(struct ipl_rb_components *comps, 32 - struct ipl_rb_certificates *certs, 33 - unsigned long safe_addr) 28 + static unsigned long get_cert_comp_list_size(void) 34 29 { 35 30 struct ipl_rb_certificate_entry *cert; 36 31 struct ipl_rb_component_entry *comp; ··· 41 44 ipl_cert_list_size = 0; 42 45 for_each_rb_entry(cert, certs) 43 46 ipl_cert_list_size += sizeof(unsigned int) + cert->len; 44 - size = ipl_cert_list_size + early_ipl_comp_list_size; 45 - 46 - /* 47 - * Start from safe_addr to find a free memory area large 48 - * enough for the IPL report boot data. This area is used 49 - * for ipl_cert_list_addr/ipl_cert_list_size and 50 - * early_ipl_comp_list_addr/early_ipl_comp_list_size. It must 51 - * not overlap with any component or any certificate. 52 - */ 53 - repeat: 54 - if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd_data.start && initrd_data.size && 55 - intersects(initrd_data.start, initrd_data.size, safe_addr, size)) 56 - safe_addr = initrd_data.start + initrd_data.size; 57 - if (intersects(safe_addr, size, (unsigned long)comps, comps->len)) { 58 - safe_addr = (unsigned long)comps + comps->len; 59 - goto repeat; 60 - } 61 - for_each_rb_entry(comp, comps) 62 - if (intersects(safe_addr, size, comp->addr, comp->len)) { 63 - safe_addr = comp->addr + comp->len; 64 - goto repeat; 65 - } 66 - if (intersects(safe_addr, size, (unsigned long)certs, certs->len)) { 67 - safe_addr = (unsigned long)certs + certs->len; 68 - goto repeat; 69 - } 70 - for_each_rb_entry(cert, certs) 71 - if (intersects(safe_addr, size, cert->addr, cert->len)) { 72 - safe_addr = cert->addr + cert->len; 73 - goto repeat; 74 - } 75 - early_ipl_comp_list_addr = safe_addr; 76 - ipl_cert_list_addr = safe_addr + early_ipl_comp_list_size; 77 - 78 - return safe_addr + size; 47 + return ipl_cert_list_size + early_ipl_comp_list_size; 79 48 } 80 49 81 - static void copy_components_bootdata(struct ipl_rb_components *comps) 50 + bool ipl_report_certs_intersects(unsigned long addr, unsigned long size, 51 + unsigned long *intersection_start) 52 + { 53 + struct ipl_rb_certificate_entry *cert; 54 + 55 + if (!ipl_report_needs_saving) 56 + return false; 57 + 58 + for_each_rb_entry(cert, certs) { 59 + if (intersects(addr, size, cert->addr, cert->len)) { 60 + *intersection_start = cert->addr; 61 + return true; 62 + } 63 + } 64 + return false; 65 + } 66 + 67 + static void copy_components_bootdata(void) 82 68 { 83 69 struct ipl_rb_component_entry *comp, *ptr; 84 70 ··· 70 90 memcpy(ptr++, comp, sizeof(*ptr)); 71 91 } 72 92 73 - static void copy_certificates_bootdata(struct ipl_rb_certificates *certs) 93 + static void copy_certificates_bootdata(void) 74 94 { 75 95 struct ipl_rb_certificate_entry *cert; 76 96 void *ptr; ··· 84 104 } 85 105 } 86 106 87 - unsigned long read_ipl_report(unsigned long safe_addr) 107 + int read_ipl_report(void) 88 108 { 89 - struct ipl_rb_certificates *certs; 90 - struct ipl_rb_components *comps; 91 109 struct ipl_pl_hdr *pl_hdr; 92 110 struct ipl_rl_hdr *rl_hdr; 93 111 struct ipl_rb_hdr *rb_hdr; ··· 98 120 */ 99 121 if (!ipl_block_valid || 100 122 !(ipl_block.hdr.flags & IPL_PL_FLAG_IPLSR)) 101 - return safe_addr; 123 + return -1; 102 124 ipl_secure_flag = !!(ipl_block.hdr.flags & IPL_PL_FLAG_SIPL); 103 125 /* 104 126 * There is an IPL report, to find it load the pointer to the ··· 136 158 * With either the component list or the certificate list 137 159 * missing the kernel will stay ignorant of secure IPL. 138 160 */ 139 - if (!comps || !certs) 140 - return safe_addr; 161 + if (!comps || !certs) { 162 + certs = NULL; 163 + return -1; 164 + } 141 165 142 - /* 143 - * Copy component and certificate list to a safe area 144 - * where the decompressed kernel can find them. 145 - */ 146 - safe_addr = find_bootdata_space(comps, certs, safe_addr); 147 - copy_components_bootdata(comps); 148 - copy_certificates_bootdata(certs); 166 + ipl_report_needs_saving = true; 167 + physmem_reserve(RR_IPLREPORT, (unsigned long)pl_hdr, 168 + (unsigned long)rl_end - (unsigned long)pl_hdr); 169 + return 0; 170 + } 149 171 150 - return safe_addr; 172 + void save_ipl_cert_comp_list(void) 173 + { 174 + unsigned long size; 175 + 176 + if (!ipl_report_needs_saving) 177 + return; 178 + 179 + size = get_cert_comp_list_size(); 180 + early_ipl_comp_list_addr = physmem_alloc_top_down(RR_CERT_COMP_LIST, size, sizeof(int)); 181 + ipl_cert_list_addr = early_ipl_comp_list_addr + early_ipl_comp_list_size; 182 + 183 + copy_components_bootdata(); 184 + copy_certificates_bootdata(); 185 + physmem_free(RR_IPLREPORT); 186 + ipl_report_needs_saving = false; 151 187 }
+97 -102
arch/s390/boot/kaslr.c
··· 3 3 * Copyright IBM Corp. 2019 4 4 */ 5 5 #include <linux/pgtable.h> 6 - #include <asm/mem_detect.h> 6 + #include <asm/physmem_info.h> 7 7 #include <asm/cpacf.h> 8 8 #include <asm/timex.h> 9 9 #include <asm/sclp.h> ··· 91 91 return 0; 92 92 } 93 93 94 + static void sort_reserved_ranges(struct reserved_range *res, unsigned long size) 95 + { 96 + struct reserved_range tmp; 97 + int i, j; 98 + 99 + for (i = 1; i < size; i++) { 100 + tmp = res[i]; 101 + for (j = i - 1; j >= 0 && res[j].start > tmp.start; j--) 102 + res[j + 1] = res[j]; 103 + res[j + 1] = tmp; 104 + } 105 + } 106 + 107 + static unsigned long iterate_valid_positions(unsigned long size, unsigned long align, 108 + unsigned long _min, unsigned long _max, 109 + struct reserved_range *res, size_t res_count, 110 + bool pos_count, unsigned long find_pos) 111 + { 112 + unsigned long start, end, tmp_end, range_pos, pos = 0; 113 + struct reserved_range *res_end = res + res_count; 114 + struct reserved_range *skip_res; 115 + int i; 116 + 117 + align = max(align, 8UL); 118 + _min = round_up(_min, align); 119 + for_each_physmem_usable_range(i, &start, &end) { 120 + if (_min >= end) 121 + continue; 122 + start = round_up(start, align); 123 + if (start >= _max) 124 + break; 125 + start = max(_min, start); 126 + end = min(_max, end); 127 + 128 + while (start + size <= end) { 129 + /* skip reserved ranges below the start */ 130 + while (res && res->end <= start) { 131 + res++; 132 + if (res >= res_end) 133 + res = NULL; 134 + } 135 + skip_res = NULL; 136 + tmp_end = end; 137 + /* has intersecting reserved range */ 138 + if (res && res->start < end) { 139 + skip_res = res; 140 + tmp_end = res->start; 141 + } 142 + if (start + size <= tmp_end) { 143 + range_pos = (tmp_end - start - size) / align + 1; 144 + if (pos_count) { 145 + pos += range_pos; 146 + } else { 147 + if (range_pos >= find_pos) 148 + return start + (find_pos - 1) * align; 149 + find_pos -= range_pos; 150 + } 151 + } 152 + if (!skip_res) 153 + break; 154 + start = round_up(skip_res->end, align); 155 + } 156 + } 157 + 158 + return pos_count ? pos : 0; 159 + } 160 + 94 161 /* 95 - * To randomize kernel base address we have to consider several facts: 96 - * 1. physical online memory might not be continuous and have holes. mem_detect 97 - * info contains list of online memory ranges we should consider. 98 - * 2. we have several memory regions which are occupied and we should not 99 - * overlap and destroy them. Currently safe_addr tells us the border below 100 - * which all those occupied regions are. We are safe to use anything above 101 - * safe_addr. 102 - * 3. the upper limit might apply as well, even if memory above that limit is 103 - * online. Currently those limitations are: 104 - * 3.1. Limit set by "mem=" kernel command line option 105 - * 3.2. memory reserved at the end for kasan initialization. 106 - * 4. kernel base address must be aligned to THREAD_SIZE (kernel stack size). 107 - * Which is required for CONFIG_CHECK_STACK. Currently THREAD_SIZE is 4 pages 108 - * (16 pages when the kernel is built with kasan enabled) 109 - * Assumptions: 110 - * 1. kernel size (including .bss size) and upper memory limit are page aligned. 111 - * 2. mem_detect memory region start is THREAD_SIZE aligned / end is PAGE_SIZE 112 - * aligned (in practice memory configurations granularity on z/VM and LPAR 113 - * is 1mb). 162 + * Two types of decompressor memory allocations/reserves are considered 163 + * differently. 114 164 * 115 - * To guarantee uniform distribution of kernel base address among all suitable 116 - * addresses we generate random value just once. For that we need to build a 117 - * continuous range in which every value would be suitable. We can build this 118 - * range by simply counting all suitable addresses (let's call them positions) 119 - * which would be valid as kernel base address. To count positions we iterate 120 - * over online memory ranges. For each range which is big enough for the 121 - * kernel image we count all suitable addresses we can put the kernel image at 122 - * that is 123 - * (end - start - kernel_size) / THREAD_SIZE + 1 124 - * Two functions count_valid_kernel_positions and position_to_address help 125 - * to count positions in memory range given and then convert position back 126 - * to address. 165 + * "Static" or "single" allocations are done via physmem_alloc_range() and 166 + * physmem_reserve(), and they are listed in physmem_info.reserved[]. Each 167 + * type of "static" allocation can only have one allocation per type and 168 + * cannot have chains. 169 + * 170 + * On the other hand, "dynamic" or "repetitive" allocations are done via 171 + * physmem_alloc_top_down(). These allocations are tightly packed together 172 + * top down from the end of online memory. physmem_alloc_pos represents 173 + * current position where those allocations start. 174 + * 175 + * Functions randomize_within_range() and iterate_valid_positions() 176 + * only consider "dynamic" allocations by never looking above 177 + * physmem_alloc_pos. "Static" allocations, however, are explicitly 178 + * considered by checking the "res" (reserves) array. The first 179 + * reserved_range of a "dynamic" allocation may also be checked along the 180 + * way, but it will always be above the maximum value anyway. 127 181 */ 128 - static unsigned long count_valid_kernel_positions(unsigned long kernel_size, 129 - unsigned long _min, 130 - unsigned long _max) 182 + unsigned long randomize_within_range(unsigned long size, unsigned long align, 183 + unsigned long min, unsigned long max) 131 184 { 132 - unsigned long start, end, pos = 0; 133 - int i; 185 + struct reserved_range res[RR_MAX]; 186 + unsigned long max_pos, pos; 134 187 135 - for_each_mem_detect_usable_block(i, &start, &end) { 136 - if (_min >= end) 137 - continue; 138 - if (start >= _max) 139 - break; 140 - start = max(_min, start); 141 - end = min(_max, end); 142 - if (end - start < kernel_size) 143 - continue; 144 - pos += (end - start - kernel_size) / THREAD_SIZE + 1; 145 - } 188 + memcpy(res, physmem_info.reserved, sizeof(res)); 189 + sort_reserved_ranges(res, ARRAY_SIZE(res)); 190 + max = min(max, get_physmem_alloc_pos()); 146 191 147 - return pos; 148 - } 149 - 150 - static unsigned long position_to_address(unsigned long pos, unsigned long kernel_size, 151 - unsigned long _min, unsigned long _max) 152 - { 153 - unsigned long start, end; 154 - int i; 155 - 156 - for_each_mem_detect_usable_block(i, &start, &end) { 157 - if (_min >= end) 158 - continue; 159 - if (start >= _max) 160 - break; 161 - start = max(_min, start); 162 - end = min(_max, end); 163 - if (end - start < kernel_size) 164 - continue; 165 - if ((end - start - kernel_size) / THREAD_SIZE + 1 >= pos) 166 - return start + (pos - 1) * THREAD_SIZE; 167 - pos -= (end - start - kernel_size) / THREAD_SIZE + 1; 168 - } 169 - 170 - return 0; 171 - } 172 - 173 - unsigned long get_random_base(unsigned long safe_addr) 174 - { 175 - unsigned long usable_total = get_mem_detect_usable_total(); 176 - unsigned long memory_limit = get_mem_detect_end(); 177 - unsigned long base_pos, max_pos, kernel_size; 178 - int i; 179 - 180 - /* 181 - * Avoid putting kernel in the end of physical memory 182 - * which vmem and kasan code will use for shadow memory and 183 - * pgtable mapping allocations. 184 - */ 185 - memory_limit -= kasan_estimate_memory_needs(usable_total); 186 - memory_limit -= vmem_estimate_memory_needs(usable_total); 187 - 188 - safe_addr = ALIGN(safe_addr, THREAD_SIZE); 189 - kernel_size = vmlinux.image_size + vmlinux.bss_size; 190 - if (safe_addr + kernel_size > memory_limit) 192 + max_pos = iterate_valid_positions(size, align, min, max, res, ARRAY_SIZE(res), true, 0); 193 + if (!max_pos) 191 194 return 0; 192 - 193 - max_pos = count_valid_kernel_positions(kernel_size, safe_addr, memory_limit); 194 - if (!max_pos) { 195 - sclp_early_printk("KASLR disabled: not enough memory\n"); 195 + if (get_random(max_pos, &pos)) 196 196 return 0; 197 - } 198 - 199 - /* we need a value in the range [1, base_pos] inclusive */ 200 - if (get_random(max_pos, &base_pos)) 201 - return 0; 202 - return position_to_address(base_pos + 1, kernel_size, safe_addr, memory_limit); 197 + return iterate_valid_positions(size, align, min, max, res, ARRAY_SIZE(res), false, pos + 1); 203 198 }
-191
arch/s390/boot/mem_detect.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - #include <linux/errno.h> 3 - #include <linux/init.h> 4 - #include <asm/setup.h> 5 - #include <asm/processor.h> 6 - #include <asm/sclp.h> 7 - #include <asm/sections.h> 8 - #include <asm/mem_detect.h> 9 - #include <asm/sparsemem.h> 10 - #include "decompressor.h" 11 - #include "boot.h" 12 - 13 - struct mem_detect_info __bootdata(mem_detect); 14 - 15 - /* up to 256 storage elements, 1020 subincrements each */ 16 - #define ENTRIES_EXTENDED_MAX \ 17 - (256 * (1020 / 2) * sizeof(struct mem_detect_block)) 18 - 19 - static struct mem_detect_block *__get_mem_detect_block_ptr(u32 n) 20 - { 21 - if (n < MEM_INLINED_ENTRIES) 22 - return &mem_detect.entries[n]; 23 - return &mem_detect.entries_extended[n - MEM_INLINED_ENTRIES]; 24 - } 25 - 26 - /* 27 - * sequential calls to add_mem_detect_block with adjacent memory areas 28 - * are merged together into single memory block. 29 - */ 30 - void add_mem_detect_block(u64 start, u64 end) 31 - { 32 - struct mem_detect_block *block; 33 - 34 - if (mem_detect.count) { 35 - block = __get_mem_detect_block_ptr(mem_detect.count - 1); 36 - if (block->end == start) { 37 - block->end = end; 38 - return; 39 - } 40 - } 41 - 42 - block = __get_mem_detect_block_ptr(mem_detect.count); 43 - block->start = start; 44 - block->end = end; 45 - mem_detect.count++; 46 - } 47 - 48 - static int __diag260(unsigned long rx1, unsigned long rx2) 49 - { 50 - unsigned long reg1, reg2, ry; 51 - union register_pair rx; 52 - psw_t old; 53 - int rc; 54 - 55 - rx.even = rx1; 56 - rx.odd = rx2; 57 - ry = 0x10; /* storage configuration */ 58 - rc = -1; /* fail */ 59 - asm volatile( 60 - " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n" 61 - " epsw %[reg1],%[reg2]\n" 62 - " st %[reg1],0(%[psw_pgm])\n" 63 - " st %[reg2],4(%[psw_pgm])\n" 64 - " larl %[reg1],1f\n" 65 - " stg %[reg1],8(%[psw_pgm])\n" 66 - " diag %[rx],%[ry],0x260\n" 67 - " ipm %[rc]\n" 68 - " srl %[rc],28\n" 69 - "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n" 70 - : [reg1] "=&d" (reg1), 71 - [reg2] "=&a" (reg2), 72 - [rc] "+&d" (rc), 73 - [ry] "+&d" (ry), 74 - "+Q" (S390_lowcore.program_new_psw), 75 - "=Q" (old) 76 - : [rx] "d" (rx.pair), 77 - [psw_old] "a" (&old), 78 - [psw_pgm] "a" (&S390_lowcore.program_new_psw) 79 - : "cc", "memory"); 80 - return rc == 0 ? ry : -1; 81 - } 82 - 83 - static int diag260(void) 84 - { 85 - int rc, i; 86 - 87 - struct { 88 - unsigned long start; 89 - unsigned long end; 90 - } storage_extents[8] __aligned(16); /* VM supports up to 8 extends */ 91 - 92 - memset(storage_extents, 0, sizeof(storage_extents)); 93 - rc = __diag260((unsigned long)storage_extents, sizeof(storage_extents)); 94 - if (rc == -1) 95 - return -1; 96 - 97 - for (i = 0; i < min_t(int, rc, ARRAY_SIZE(storage_extents)); i++) 98 - add_mem_detect_block(storage_extents[i].start, storage_extents[i].end + 1); 99 - return 0; 100 - } 101 - 102 - static int tprot(unsigned long addr) 103 - { 104 - unsigned long reg1, reg2; 105 - int rc = -EFAULT; 106 - psw_t old; 107 - 108 - asm volatile( 109 - " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n" 110 - " epsw %[reg1],%[reg2]\n" 111 - " st %[reg1],0(%[psw_pgm])\n" 112 - " st %[reg2],4(%[psw_pgm])\n" 113 - " larl %[reg1],1f\n" 114 - " stg %[reg1],8(%[psw_pgm])\n" 115 - " tprot 0(%[addr]),0\n" 116 - " ipm %[rc]\n" 117 - " srl %[rc],28\n" 118 - "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n" 119 - : [reg1] "=&d" (reg1), 120 - [reg2] "=&a" (reg2), 121 - [rc] "+&d" (rc), 122 - "=Q" (S390_lowcore.program_new_psw.addr), 123 - "=Q" (old) 124 - : [psw_old] "a" (&old), 125 - [psw_pgm] "a" (&S390_lowcore.program_new_psw), 126 - [addr] "a" (addr) 127 - : "cc", "memory"); 128 - return rc; 129 - } 130 - 131 - static unsigned long search_mem_end(void) 132 - { 133 - unsigned long range = 1 << (MAX_PHYSMEM_BITS - 20); /* in 1MB blocks */ 134 - unsigned long offset = 0; 135 - unsigned long pivot; 136 - 137 - while (range > 1) { 138 - range >>= 1; 139 - pivot = offset + range; 140 - if (!tprot(pivot << 20)) 141 - offset = pivot; 142 - } 143 - return (offset + 1) << 20; 144 - } 145 - 146 - unsigned long detect_memory(unsigned long *safe_addr) 147 - { 148 - unsigned long max_physmem_end = 0; 149 - 150 - sclp_early_get_memsize(&max_physmem_end); 151 - mem_detect.entries_extended = (struct mem_detect_block *)ALIGN(*safe_addr, sizeof(u64)); 152 - 153 - if (!sclp_early_read_storage_info()) { 154 - mem_detect.info_source = MEM_DETECT_SCLP_STOR_INFO; 155 - } else if (!diag260()) { 156 - mem_detect.info_source = MEM_DETECT_DIAG260; 157 - max_physmem_end = max_physmem_end ?: get_mem_detect_end(); 158 - } else if (max_physmem_end) { 159 - add_mem_detect_block(0, max_physmem_end); 160 - mem_detect.info_source = MEM_DETECT_SCLP_READ_INFO; 161 - } else { 162 - max_physmem_end = search_mem_end(); 163 - add_mem_detect_block(0, max_physmem_end); 164 - mem_detect.info_source = MEM_DETECT_BIN_SEARCH; 165 - } 166 - 167 - if (mem_detect.count > MEM_INLINED_ENTRIES) { 168 - *safe_addr += (mem_detect.count - MEM_INLINED_ENTRIES) * 169 - sizeof(struct mem_detect_block); 170 - } 171 - 172 - return max_physmem_end; 173 - } 174 - 175 - void mem_detect_set_usable_limit(unsigned long limit) 176 - { 177 - struct mem_detect_block *block; 178 - int i; 179 - 180 - /* make sure mem_detect.usable ends up within online memory block */ 181 - for (i = 0; i < mem_detect.count; i++) { 182 - block = __get_mem_detect_block_ptr(i); 183 - if (block->start >= limit) 184 - break; 185 - if (block->end >= limit) { 186 - mem_detect.usable = limit; 187 - break; 188 - } 189 - mem_detect.usable = block->end; 190 - } 191 - }
+3 -4
arch/s390/boot/pgm_check_info.c
··· 123 123 sclp_early_printk(buf); 124 124 } 125 125 126 - static noinline void print_stacktrace(void) 126 + void print_stacktrace(unsigned long sp) 127 127 { 128 128 struct stack_info boot_stack = { STACK_TYPE_TASK, (unsigned long)_stack_start, 129 129 (unsigned long)_stack_end }; 130 - unsigned long sp = S390_lowcore.gpregs_save_area[15]; 131 130 bool first = true; 132 131 133 132 decompressor_printk("Call Trace:\n"); ··· 153 154 decompressor_printk("Kernel command line: %s\n", early_command_line); 154 155 decompressor_printk("Kernel fault: interruption code %04x ilc:%x\n", 155 156 S390_lowcore.pgm_code, S390_lowcore.pgm_ilc >> 1); 156 - if (kaslr_enabled) 157 + if (kaslr_enabled()) 157 158 decompressor_printk("Kernel random base: %lx\n", __kaslr_offset); 158 159 decompressor_printk("PSW : %016lx %016lx (%pS)\n", 159 160 S390_lowcore.psw_save_area.mask, ··· 172 173 gpregs[8], gpregs[9], gpregs[10], gpregs[11]); 173 174 decompressor_printk(" %016lx %016lx %016lx %016lx\n", 174 175 gpregs[12], gpregs[13], gpregs[14], gpregs[15]); 175 - print_stacktrace(); 176 + print_stacktrace(S390_lowcore.gpregs_save_area[15]); 176 177 decompressor_printk("Last Breaking-Event-Address:\n"); 177 178 decompressor_printk(" [<%016lx>] %pS\n", (unsigned long)S390_lowcore.pgm_last_break, 178 179 (void *)S390_lowcore.pgm_last_break);
+328
arch/s390/boot/physmem_info.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/processor.h> 3 + #include <linux/errno.h> 4 + #include <linux/init.h> 5 + #include <asm/physmem_info.h> 6 + #include <asm/stacktrace.h> 7 + #include <asm/boot_data.h> 8 + #include <asm/sparsemem.h> 9 + #include <asm/sections.h> 10 + #include <asm/setup.h> 11 + #include <asm/sclp.h> 12 + #include <asm/uv.h> 13 + #include "decompressor.h" 14 + #include "boot.h" 15 + 16 + struct physmem_info __bootdata(physmem_info); 17 + static unsigned int physmem_alloc_ranges; 18 + static unsigned long physmem_alloc_pos; 19 + 20 + /* up to 256 storage elements, 1020 subincrements each */ 21 + #define ENTRIES_EXTENDED_MAX \ 22 + (256 * (1020 / 2) * sizeof(struct physmem_range)) 23 + 24 + static struct physmem_range *__get_physmem_range_ptr(u32 n) 25 + { 26 + if (n < MEM_INLINED_ENTRIES) 27 + return &physmem_info.online[n]; 28 + if (unlikely(!physmem_info.online_extended)) { 29 + physmem_info.online_extended = (struct physmem_range *)physmem_alloc_range( 30 + RR_MEM_DETECT_EXTENDED, ENTRIES_EXTENDED_MAX, sizeof(long), 0, 31 + physmem_alloc_pos, true); 32 + } 33 + return &physmem_info.online_extended[n - MEM_INLINED_ENTRIES]; 34 + } 35 + 36 + /* 37 + * sequential calls to add_physmem_online_range with adjacent memory ranges 38 + * are merged together into single memory range. 39 + */ 40 + void add_physmem_online_range(u64 start, u64 end) 41 + { 42 + struct physmem_range *range; 43 + 44 + if (physmem_info.range_count) { 45 + range = __get_physmem_range_ptr(physmem_info.range_count - 1); 46 + if (range->end == start) { 47 + range->end = end; 48 + return; 49 + } 50 + } 51 + 52 + range = __get_physmem_range_ptr(physmem_info.range_count); 53 + range->start = start; 54 + range->end = end; 55 + physmem_info.range_count++; 56 + } 57 + 58 + static int __diag260(unsigned long rx1, unsigned long rx2) 59 + { 60 + unsigned long reg1, reg2, ry; 61 + union register_pair rx; 62 + psw_t old; 63 + int rc; 64 + 65 + rx.even = rx1; 66 + rx.odd = rx2; 67 + ry = 0x10; /* storage configuration */ 68 + rc = -1; /* fail */ 69 + asm volatile( 70 + " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n" 71 + " epsw %[reg1],%[reg2]\n" 72 + " st %[reg1],0(%[psw_pgm])\n" 73 + " st %[reg2],4(%[psw_pgm])\n" 74 + " larl %[reg1],1f\n" 75 + " stg %[reg1],8(%[psw_pgm])\n" 76 + " diag %[rx],%[ry],0x260\n" 77 + " ipm %[rc]\n" 78 + " srl %[rc],28\n" 79 + "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n" 80 + : [reg1] "=&d" (reg1), 81 + [reg2] "=&a" (reg2), 82 + [rc] "+&d" (rc), 83 + [ry] "+&d" (ry), 84 + "+Q" (S390_lowcore.program_new_psw), 85 + "=Q" (old) 86 + : [rx] "d" (rx.pair), 87 + [psw_old] "a" (&old), 88 + [psw_pgm] "a" (&S390_lowcore.program_new_psw) 89 + : "cc", "memory"); 90 + return rc == 0 ? ry : -1; 91 + } 92 + 93 + static int diag260(void) 94 + { 95 + int rc, i; 96 + 97 + struct { 98 + unsigned long start; 99 + unsigned long end; 100 + } storage_extents[8] __aligned(16); /* VM supports up to 8 extends */ 101 + 102 + memset(storage_extents, 0, sizeof(storage_extents)); 103 + rc = __diag260((unsigned long)storage_extents, sizeof(storage_extents)); 104 + if (rc == -1) 105 + return -1; 106 + 107 + for (i = 0; i < min_t(int, rc, ARRAY_SIZE(storage_extents)); i++) 108 + add_physmem_online_range(storage_extents[i].start, storage_extents[i].end + 1); 109 + return 0; 110 + } 111 + 112 + static int tprot(unsigned long addr) 113 + { 114 + unsigned long reg1, reg2; 115 + int rc = -EFAULT; 116 + psw_t old; 117 + 118 + asm volatile( 119 + " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n" 120 + " epsw %[reg1],%[reg2]\n" 121 + " st %[reg1],0(%[psw_pgm])\n" 122 + " st %[reg2],4(%[psw_pgm])\n" 123 + " larl %[reg1],1f\n" 124 + " stg %[reg1],8(%[psw_pgm])\n" 125 + " tprot 0(%[addr]),0\n" 126 + " ipm %[rc]\n" 127 + " srl %[rc],28\n" 128 + "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n" 129 + : [reg1] "=&d" (reg1), 130 + [reg2] "=&a" (reg2), 131 + [rc] "+&d" (rc), 132 + "=Q" (S390_lowcore.program_new_psw.addr), 133 + "=Q" (old) 134 + : [psw_old] "a" (&old), 135 + [psw_pgm] "a" (&S390_lowcore.program_new_psw), 136 + [addr] "a" (addr) 137 + : "cc", "memory"); 138 + return rc; 139 + } 140 + 141 + static unsigned long search_mem_end(void) 142 + { 143 + unsigned long range = 1 << (MAX_PHYSMEM_BITS - 20); /* in 1MB blocks */ 144 + unsigned long offset = 0; 145 + unsigned long pivot; 146 + 147 + while (range > 1) { 148 + range >>= 1; 149 + pivot = offset + range; 150 + if (!tprot(pivot << 20)) 151 + offset = pivot; 152 + } 153 + return (offset + 1) << 20; 154 + } 155 + 156 + unsigned long detect_max_physmem_end(void) 157 + { 158 + unsigned long max_physmem_end = 0; 159 + 160 + if (!sclp_early_get_memsize(&max_physmem_end)) { 161 + physmem_info.info_source = MEM_DETECT_SCLP_READ_INFO; 162 + } else { 163 + max_physmem_end = search_mem_end(); 164 + physmem_info.info_source = MEM_DETECT_BIN_SEARCH; 165 + } 166 + return max_physmem_end; 167 + } 168 + 169 + void detect_physmem_online_ranges(unsigned long max_physmem_end) 170 + { 171 + if (!sclp_early_read_storage_info()) { 172 + physmem_info.info_source = MEM_DETECT_SCLP_STOR_INFO; 173 + } else if (!diag260()) { 174 + physmem_info.info_source = MEM_DETECT_DIAG260; 175 + } else if (max_physmem_end) { 176 + add_physmem_online_range(0, max_physmem_end); 177 + } 178 + } 179 + 180 + void physmem_set_usable_limit(unsigned long limit) 181 + { 182 + physmem_info.usable = limit; 183 + physmem_alloc_pos = limit; 184 + } 185 + 186 + static void die_oom(unsigned long size, unsigned long align, unsigned long min, unsigned long max) 187 + { 188 + unsigned long start, end, total_mem = 0, total_reserved_mem = 0; 189 + struct reserved_range *range; 190 + enum reserved_range_type t; 191 + int i; 192 + 193 + decompressor_printk("Linux version %s\n", kernel_version); 194 + if (!is_prot_virt_guest() && early_command_line[0]) 195 + decompressor_printk("Kernel command line: %s\n", early_command_line); 196 + decompressor_printk("Out of memory allocating %lx bytes %lx aligned in range %lx:%lx\n", 197 + size, align, min, max); 198 + decompressor_printk("Reserved memory ranges:\n"); 199 + for_each_physmem_reserved_range(t, range, &start, &end) { 200 + decompressor_printk("%016lx %016lx %s\n", start, end, get_rr_type_name(t)); 201 + total_reserved_mem += end - start; 202 + } 203 + decompressor_printk("Usable online memory ranges (info source: %s [%x]):\n", 204 + get_physmem_info_source(), physmem_info.info_source); 205 + for_each_physmem_usable_range(i, &start, &end) { 206 + decompressor_printk("%016lx %016lx\n", start, end); 207 + total_mem += end - start; 208 + } 209 + decompressor_printk("Usable online memory total: %lx Reserved: %lx Free: %lx\n", 210 + total_mem, total_reserved_mem, 211 + total_mem > total_reserved_mem ? total_mem - total_reserved_mem : 0); 212 + print_stacktrace(current_frame_address()); 213 + sclp_early_printk("\n\n -- System halted\n"); 214 + disabled_wait(); 215 + } 216 + 217 + void physmem_reserve(enum reserved_range_type type, unsigned long addr, unsigned long size) 218 + { 219 + physmem_info.reserved[type].start = addr; 220 + physmem_info.reserved[type].end = addr + size; 221 + } 222 + 223 + void physmem_free(enum reserved_range_type type) 224 + { 225 + physmem_info.reserved[type].start = 0; 226 + physmem_info.reserved[type].end = 0; 227 + } 228 + 229 + static bool __physmem_alloc_intersects(unsigned long addr, unsigned long size, 230 + unsigned long *intersection_start) 231 + { 232 + unsigned long res_addr, res_size; 233 + int t; 234 + 235 + for (t = 0; t < RR_MAX; t++) { 236 + if (!get_physmem_reserved(t, &res_addr, &res_size)) 237 + continue; 238 + if (intersects(addr, size, res_addr, res_size)) { 239 + *intersection_start = res_addr; 240 + return true; 241 + } 242 + } 243 + return ipl_report_certs_intersects(addr, size, intersection_start); 244 + } 245 + 246 + static unsigned long __physmem_alloc_range(unsigned long size, unsigned long align, 247 + unsigned long min, unsigned long max, 248 + unsigned int from_ranges, unsigned int *ranges_left, 249 + bool die_on_oom) 250 + { 251 + unsigned int nranges = from_ranges ?: physmem_info.range_count; 252 + unsigned long range_start, range_end; 253 + unsigned long intersection_start; 254 + unsigned long addr, pos = max; 255 + 256 + align = max(align, 8UL); 257 + while (nranges) { 258 + __get_physmem_range(nranges - 1, &range_start, &range_end, false); 259 + pos = min(range_end, pos); 260 + 261 + if (round_up(min, align) + size > pos) 262 + break; 263 + addr = round_down(pos - size, align); 264 + if (range_start > addr) { 265 + nranges--; 266 + continue; 267 + } 268 + if (__physmem_alloc_intersects(addr, size, &intersection_start)) { 269 + pos = intersection_start; 270 + continue; 271 + } 272 + 273 + if (ranges_left) 274 + *ranges_left = nranges; 275 + return addr; 276 + } 277 + if (die_on_oom) 278 + die_oom(size, align, min, max); 279 + return 0; 280 + } 281 + 282 + unsigned long physmem_alloc_range(enum reserved_range_type type, unsigned long size, 283 + unsigned long align, unsigned long min, unsigned long max, 284 + bool die_on_oom) 285 + { 286 + unsigned long addr; 287 + 288 + max = min(max, physmem_alloc_pos); 289 + addr = __physmem_alloc_range(size, align, min, max, 0, NULL, die_on_oom); 290 + if (addr) 291 + physmem_reserve(type, addr, size); 292 + return addr; 293 + } 294 + 295 + unsigned long physmem_alloc_top_down(enum reserved_range_type type, unsigned long size, 296 + unsigned long align) 297 + { 298 + struct reserved_range *range = &physmem_info.reserved[type]; 299 + struct reserved_range *new_range; 300 + unsigned int ranges_left; 301 + unsigned long addr; 302 + 303 + addr = __physmem_alloc_range(size, align, 0, physmem_alloc_pos, physmem_alloc_ranges, 304 + &ranges_left, true); 305 + /* if not a consecutive allocation of the same type or first allocation */ 306 + if (range->start != addr + size) { 307 + if (range->end) { 308 + physmem_alloc_pos = __physmem_alloc_range( 309 + sizeof(struct reserved_range), 0, 0, physmem_alloc_pos, 310 + physmem_alloc_ranges, &ranges_left, true); 311 + new_range = (struct reserved_range *)physmem_alloc_pos; 312 + *new_range = *range; 313 + range->chain = new_range; 314 + addr = __physmem_alloc_range(size, align, 0, physmem_alloc_pos, 315 + ranges_left, &ranges_left, true); 316 + } 317 + range->end = addr + size; 318 + } 319 + range->start = addr; 320 + physmem_alloc_pos = addr; 321 + physmem_alloc_ranges = ranges_left; 322 + return addr; 323 + } 324 + 325 + unsigned long get_physmem_alloc_pos(void) 326 + { 327 + return physmem_alloc_pos; 328 + }
+72 -55
arch/s390/boot/startup.c
··· 12 12 #include <asm/diag.h> 13 13 #include <asm/uv.h> 14 14 #include <asm/abs_lowcore.h> 15 - #include <asm/mem_detect.h> 15 + #include <asm/physmem_info.h> 16 16 #include "decompressor.h" 17 17 #include "boot.h" 18 18 #include "uv.h" ··· 21 21 unsigned long __bootdata_preserved(__abs_lowcore); 22 22 unsigned long __bootdata_preserved(__memcpy_real_area); 23 23 pte_t *__bootdata_preserved(memcpy_real_ptep); 24 - unsigned long __bootdata(__amode31_base); 25 24 unsigned long __bootdata_preserved(VMALLOC_START); 26 25 unsigned long __bootdata_preserved(VMALLOC_END); 27 26 struct page *__bootdata_preserved(vmemmap); ··· 28 29 unsigned long __bootdata_preserved(MODULES_VADDR); 29 30 unsigned long __bootdata_preserved(MODULES_END); 30 31 unsigned long __bootdata(ident_map_size); 31 - int __bootdata(is_full_image) = 1; 32 - struct initrd_data __bootdata(initrd_data); 33 32 34 33 u64 __bootdata_preserved(stfle_fac_list[16]); 35 34 u64 __bootdata_preserved(alt_stfle_fac_list[16]); ··· 73 76 } 74 77 #endif 75 78 76 - static unsigned long rescue_initrd(unsigned long safe_addr) 79 + static void rescue_initrd(unsigned long min, unsigned long max) 77 80 { 81 + unsigned long old_addr, addr, size; 82 + 78 83 if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD)) 79 - return safe_addr; 80 - if (!initrd_data.start || !initrd_data.size) 81 - return safe_addr; 82 - if (initrd_data.start < safe_addr) { 83 - memmove((void *)safe_addr, (void *)initrd_data.start, initrd_data.size); 84 - initrd_data.start = safe_addr; 85 - } 86 - return initrd_data.start + initrd_data.size; 84 + return; 85 + if (!get_physmem_reserved(RR_INITRD, &addr, &size)) 86 + return; 87 + if (addr >= min && addr + size <= max) 88 + return; 89 + old_addr = addr; 90 + physmem_free(RR_INITRD); 91 + addr = physmem_alloc_top_down(RR_INITRD, size, 0); 92 + memmove((void *)addr, (void *)old_addr, size); 87 93 } 88 94 89 95 static void copy_bootdata(void) ··· 140 140 * 141 141 * Consider the following factors: 142 142 * 1. max_physmem_end - end of physical memory online or standby. 143 - * Always <= end of the last online memory block (get_mem_detect_end()). 143 + * Always >= end of the last online memory range (get_physmem_online_end()). 144 144 * 2. CONFIG_MAX_PHYSMEM_BITS - the maximum size of physical memory the 145 145 * kernel is able to support. 146 146 * 3. "mem=" kernel command line option which limits physical memory usage. ··· 160 160 161 161 #ifdef CONFIG_CRASH_DUMP 162 162 if (oldmem_data.start) { 163 - kaslr_enabled = 0; 163 + __kaslr_enabled = 0; 164 164 ident_map_size = min(ident_map_size, oldmem_data.size); 165 165 } else if (ipl_block_valid && is_ipl_block_dump()) { 166 - kaslr_enabled = 0; 166 + __kaslr_enabled = 0; 167 167 if (!sclp_early_get_hsa_size(&hsa_size) && hsa_size) 168 168 ident_map_size = min(ident_map_size, hsa_size); 169 169 } ··· 235 235 /* 236 236 * This function clears the BSS section of the decompressed Linux kernel and NOT the decompressor's. 237 237 */ 238 - static void clear_bss_section(void) 238 + static void clear_bss_section(unsigned long vmlinux_lma) 239 239 { 240 - memset((void *)vmlinux.default_lma + vmlinux.image_size, 0, vmlinux.bss_size); 240 + memset((void *)vmlinux_lma + vmlinux.image_size, 0, vmlinux.bss_size); 241 241 } 242 242 243 243 /* ··· 256 256 257 257 static void offset_vmlinux_info(unsigned long offset) 258 258 { 259 - vmlinux.default_lma += offset; 260 259 *(unsigned long *)(&vmlinux.entry) += offset; 261 260 vmlinux.bootdata_off += offset; 262 261 vmlinux.bootdata_preserved_off += offset; ··· 265 266 vmlinux.init_mm_off += offset; 266 267 vmlinux.swapper_pg_dir_off += offset; 267 268 vmlinux.invalid_pg_dir_off += offset; 268 - } 269 - 270 - static unsigned long reserve_amode31(unsigned long safe_addr) 271 - { 272 - __amode31_base = PAGE_ALIGN(safe_addr); 273 - return __amode31_base + vmlinux.amode31_size; 269 + #ifdef CONFIG_KASAN 270 + vmlinux.kasan_early_shadow_page_off += offset; 271 + vmlinux.kasan_early_shadow_pte_off += offset; 272 + vmlinux.kasan_early_shadow_pmd_off += offset; 273 + vmlinux.kasan_early_shadow_pud_off += offset; 274 + vmlinux.kasan_early_shadow_p4d_off += offset; 275 + #endif 274 276 } 275 277 276 278 void startup_kernel(void) 277 279 { 278 280 unsigned long max_physmem_end; 279 - unsigned long random_lma; 280 - unsigned long safe_addr; 281 + unsigned long vmlinux_lma = 0; 282 + unsigned long amode31_lma = 0; 281 283 unsigned long asce_limit; 284 + unsigned long safe_addr; 282 285 void *img; 283 286 psw_t psw; 284 287 285 - initrd_data.start = parmarea.initrd_start; 286 - initrd_data.size = parmarea.initrd_size; 288 + setup_lpp(); 289 + safe_addr = mem_safe_offset(); 290 + /* 291 + * reserve decompressor memory together with decompression heap, buffer and 292 + * memory which might be occupied by uncompressed kernel at default 1Mb 293 + * position (if KASLR is off or failed). 294 + */ 295 + physmem_reserve(RR_DECOMPRESSOR, 0, safe_addr); 296 + if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && parmarea.initrd_size) 297 + physmem_reserve(RR_INITRD, parmarea.initrd_start, parmarea.initrd_size); 287 298 oldmem_data.start = parmarea.oldmem_base; 288 299 oldmem_data.size = parmarea.oldmem_size; 289 300 290 - setup_lpp(); 291 301 store_ipl_parmblock(); 292 - safe_addr = mem_safe_offset(); 293 - safe_addr = reserve_amode31(safe_addr); 294 - safe_addr = read_ipl_report(safe_addr); 302 + read_ipl_report(); 295 303 uv_query_info(); 296 - safe_addr = rescue_initrd(safe_addr); 297 304 sclp_early_read_info(); 298 305 setup_boot_command_line(); 299 306 parse_boot_command_line(); 300 307 detect_facilities(); 301 308 sanitize_prot_virt_host(); 302 - max_physmem_end = detect_memory(&safe_addr); 309 + max_physmem_end = detect_max_physmem_end(); 303 310 setup_ident_map_size(max_physmem_end); 304 311 setup_vmalloc_size(); 305 312 asce_limit = setup_kernel_memory_layout(); 306 - mem_detect_set_usable_limit(ident_map_size); 313 + /* got final ident_map_size, physmem allocations could be performed now */ 314 + physmem_set_usable_limit(ident_map_size); 315 + detect_physmem_online_ranges(max_physmem_end); 316 + save_ipl_cert_comp_list(); 317 + rescue_initrd(safe_addr, ident_map_size); 307 318 308 - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_enabled) { 309 - random_lma = get_random_base(safe_addr); 310 - if (random_lma) { 311 - __kaslr_offset = random_lma - vmlinux.default_lma; 312 - img = (void *)vmlinux.default_lma; 319 + if (kaslr_enabled()) { 320 + vmlinux_lma = randomize_within_range(vmlinux.image_size + vmlinux.bss_size, 321 + THREAD_SIZE, vmlinux.default_lma, 322 + ident_map_size); 323 + if (vmlinux_lma) { 324 + __kaslr_offset = vmlinux_lma - vmlinux.default_lma; 313 325 offset_vmlinux_info(__kaslr_offset); 314 326 } 315 327 } 328 + vmlinux_lma = vmlinux_lma ?: vmlinux.default_lma; 329 + physmem_reserve(RR_VMLINUX, vmlinux_lma, vmlinux.image_size + vmlinux.bss_size); 316 330 317 331 if (!IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED)) { 318 332 img = decompress_kernel(); 319 - memmove((void *)vmlinux.default_lma, img, vmlinux.image_size); 320 - } else if (__kaslr_offset) 321 - memcpy((void *)vmlinux.default_lma, img, vmlinux.image_size); 333 + memmove((void *)vmlinux_lma, img, vmlinux.image_size); 334 + } else if (__kaslr_offset) { 335 + img = (void *)vmlinux.default_lma; 336 + memmove((void *)vmlinux_lma, img, vmlinux.image_size); 337 + memset(img, 0, vmlinux.image_size); 338 + } 339 + 340 + /* vmlinux decompression is done, shrink reserved low memory */ 341 + physmem_reserve(RR_DECOMPRESSOR, 0, (unsigned long)_decompressor_end); 342 + if (kaslr_enabled()) 343 + amode31_lma = randomize_within_range(vmlinux.amode31_size, PAGE_SIZE, 0, SZ_2G); 344 + amode31_lma = amode31_lma ?: vmlinux.default_lma - vmlinux.amode31_size; 345 + physmem_reserve(RR_AMODE31, amode31_lma, vmlinux.amode31_size); 322 346 323 347 /* 324 348 * The order of the following operations is important: ··· 356 334 * - copy_bootdata() must follow setup_vmem() to propagate changes to 357 335 * bootdata made by setup_vmem() 358 336 */ 359 - clear_bss_section(); 337 + clear_bss_section(vmlinux_lma); 360 338 handle_relocs(__kaslr_offset); 361 339 setup_vmem(asce_limit); 362 340 copy_bootdata(); 363 341 364 - if (__kaslr_offset) { 365 - /* 366 - * Save KASLR offset for early dumps, before vmcore_info is set. 367 - * Mark as uneven to distinguish from real vmcore_info pointer. 368 - */ 369 - S390_lowcore.vmcore_info = __kaslr_offset | 0x1UL; 370 - /* Clear non-relocated kernel */ 371 - if (IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED)) 372 - memset(img, 0, vmlinux.image_size); 373 - } 342 + /* 343 + * Save KASLR offset for early dumps, before vmcore_info is set. 344 + * Mark as uneven to distinguish from real vmcore_info pointer. 345 + */ 346 + S390_lowcore.vmcore_info = __kaslr_offset ? __kaslr_offset | 0x1UL : 0; 374 347 375 348 /* 376 349 * Jump to the decompressed kernel entry point and switch DAT mode on.
+235 -73
arch/s390/boot/vmem.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/sched/task.h> 3 3 #include <linux/pgtable.h> 4 + #include <linux/kasan.h> 4 5 #include <asm/pgalloc.h> 5 6 #include <asm/facility.h> 6 7 #include <asm/sections.h> 7 - #include <asm/mem_detect.h> 8 + #include <asm/physmem_info.h> 8 9 #include <asm/maccess.h> 9 10 #include <asm/abs_lowcore.h> 10 11 #include "decompressor.h" 11 12 #include "boot.h" 12 13 14 + unsigned long __bootdata_preserved(s390_invalid_asce); 15 + 16 + #ifdef CONFIG_PROC_FS 17 + atomic_long_t __bootdata_preserved(direct_pages_count[PG_DIRECT_MAP_MAX]); 18 + #endif 19 + 13 20 #define init_mm (*(struct mm_struct *)vmlinux.init_mm_off) 14 21 #define swapper_pg_dir vmlinux.swapper_pg_dir_off 15 22 #define invalid_pg_dir vmlinux.invalid_pg_dir_off 23 + 24 + enum populate_mode { 25 + POPULATE_NONE, 26 + POPULATE_DIRECT, 27 + POPULATE_ABS_LOWCORE, 28 + #ifdef CONFIG_KASAN 29 + POPULATE_KASAN_MAP_SHADOW, 30 + POPULATE_KASAN_ZERO_SHADOW, 31 + POPULATE_KASAN_SHALLOW 32 + #endif 33 + }; 34 + 35 + static void pgtable_populate(unsigned long addr, unsigned long end, enum populate_mode mode); 36 + 37 + #ifdef CONFIG_KASAN 38 + 39 + #define kasan_early_shadow_page vmlinux.kasan_early_shadow_page_off 40 + #define kasan_early_shadow_pte ((pte_t *)vmlinux.kasan_early_shadow_pte_off) 41 + #define kasan_early_shadow_pmd ((pmd_t *)vmlinux.kasan_early_shadow_pmd_off) 42 + #define kasan_early_shadow_pud ((pud_t *)vmlinux.kasan_early_shadow_pud_off) 43 + #define kasan_early_shadow_p4d ((p4d_t *)vmlinux.kasan_early_shadow_p4d_off) 44 + #define __sha(x) ((unsigned long)kasan_mem_to_shadow((void *)x)) 45 + 46 + static pte_t pte_z; 47 + 48 + static void kasan_populate_shadow(void) 49 + { 50 + pmd_t pmd_z = __pmd(__pa(kasan_early_shadow_pte) | _SEGMENT_ENTRY); 51 + pud_t pud_z = __pud(__pa(kasan_early_shadow_pmd) | _REGION3_ENTRY); 52 + p4d_t p4d_z = __p4d(__pa(kasan_early_shadow_pud) | _REGION2_ENTRY); 53 + unsigned long untracked_end; 54 + unsigned long start, end; 55 + int i; 56 + 57 + pte_z = __pte(__pa(kasan_early_shadow_page) | pgprot_val(PAGE_KERNEL_RO)); 58 + if (!machine.has_nx) 59 + pte_z = clear_pte_bit(pte_z, __pgprot(_PAGE_NOEXEC)); 60 + crst_table_init((unsigned long *)kasan_early_shadow_p4d, p4d_val(p4d_z)); 61 + crst_table_init((unsigned long *)kasan_early_shadow_pud, pud_val(pud_z)); 62 + crst_table_init((unsigned long *)kasan_early_shadow_pmd, pmd_val(pmd_z)); 63 + memset64((u64 *)kasan_early_shadow_pte, pte_val(pte_z), PTRS_PER_PTE); 64 + 65 + /* 66 + * Current memory layout: 67 + * +- 0 -------------+ +- shadow start -+ 68 + * |1:1 ident mapping| /|1/8 of ident map| 69 + * | | / | | 70 + * +-end of ident map+ / +----------------+ 71 + * | ... gap ... | / | kasan | 72 + * | | / | zero page | 73 + * +- vmalloc area -+ / | mapping | 74 + * | vmalloc_size | / | (untracked) | 75 + * +- modules vaddr -+ / +----------------+ 76 + * | 2Gb |/ | unmapped | allocated per module 77 + * +- shadow start -+ +----------------+ 78 + * | 1/8 addr space | | zero pg mapping| (untracked) 79 + * +- shadow end ----+---------+- shadow end ---+ 80 + * 81 + * Current memory layout (KASAN_VMALLOC): 82 + * +- 0 -------------+ +- shadow start -+ 83 + * |1:1 ident mapping| /|1/8 of ident map| 84 + * | | / | | 85 + * +-end of ident map+ / +----------------+ 86 + * | ... gap ... | / | kasan zero page| (untracked) 87 + * | | / | mapping | 88 + * +- vmalloc area -+ / +----------------+ 89 + * | vmalloc_size | / |shallow populate| 90 + * +- modules vaddr -+ / +----------------+ 91 + * | 2Gb |/ |shallow populate| 92 + * +- shadow start -+ +----------------+ 93 + * | 1/8 addr space | | zero pg mapping| (untracked) 94 + * +- shadow end ----+---------+- shadow end ---+ 95 + */ 96 + 97 + for_each_physmem_usable_range(i, &start, &end) 98 + pgtable_populate(__sha(start), __sha(end), POPULATE_KASAN_MAP_SHADOW); 99 + if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) { 100 + untracked_end = VMALLOC_START; 101 + /* shallowly populate kasan shadow for vmalloc and modules */ 102 + pgtable_populate(__sha(VMALLOC_START), __sha(MODULES_END), POPULATE_KASAN_SHALLOW); 103 + } else { 104 + untracked_end = MODULES_VADDR; 105 + } 106 + /* populate kasan shadow for untracked memory */ 107 + pgtable_populate(__sha(ident_map_size), __sha(untracked_end), POPULATE_KASAN_ZERO_SHADOW); 108 + pgtable_populate(__sha(MODULES_END), __sha(_REGION1_SIZE), POPULATE_KASAN_ZERO_SHADOW); 109 + } 110 + 111 + static bool kasan_pgd_populate_zero_shadow(pgd_t *pgd, unsigned long addr, 112 + unsigned long end, enum populate_mode mode) 113 + { 114 + if (mode == POPULATE_KASAN_ZERO_SHADOW && 115 + IS_ALIGNED(addr, PGDIR_SIZE) && end - addr >= PGDIR_SIZE) { 116 + pgd_populate(&init_mm, pgd, kasan_early_shadow_p4d); 117 + return true; 118 + } 119 + return false; 120 + } 121 + 122 + static bool kasan_p4d_populate_zero_shadow(p4d_t *p4d, unsigned long addr, 123 + unsigned long end, enum populate_mode mode) 124 + { 125 + if (mode == POPULATE_KASAN_ZERO_SHADOW && 126 + IS_ALIGNED(addr, P4D_SIZE) && end - addr >= P4D_SIZE) { 127 + p4d_populate(&init_mm, p4d, kasan_early_shadow_pud); 128 + return true; 129 + } 130 + return false; 131 + } 132 + 133 + static bool kasan_pud_populate_zero_shadow(pud_t *pud, unsigned long addr, 134 + unsigned long end, enum populate_mode mode) 135 + { 136 + if (mode == POPULATE_KASAN_ZERO_SHADOW && 137 + IS_ALIGNED(addr, PUD_SIZE) && end - addr >= PUD_SIZE) { 138 + pud_populate(&init_mm, pud, kasan_early_shadow_pmd); 139 + return true; 140 + } 141 + return false; 142 + } 143 + 144 + static bool kasan_pmd_populate_zero_shadow(pmd_t *pmd, unsigned long addr, 145 + unsigned long end, enum populate_mode mode) 146 + { 147 + if (mode == POPULATE_KASAN_ZERO_SHADOW && 148 + IS_ALIGNED(addr, PMD_SIZE) && end - addr >= PMD_SIZE) { 149 + pmd_populate(&init_mm, pmd, kasan_early_shadow_pte); 150 + return true; 151 + } 152 + return false; 153 + } 154 + 155 + static bool kasan_pte_populate_zero_shadow(pte_t *pte, enum populate_mode mode) 156 + { 157 + pte_t entry; 158 + 159 + if (mode == POPULATE_KASAN_ZERO_SHADOW) { 160 + set_pte(pte, pte_z); 161 + return true; 162 + } 163 + return false; 164 + } 165 + #else 166 + 167 + static inline void kasan_populate_shadow(void) {} 168 + 169 + static inline bool kasan_pgd_populate_zero_shadow(pgd_t *pgd, unsigned long addr, 170 + unsigned long end, enum populate_mode mode) 171 + { 172 + return false; 173 + } 174 + 175 + static inline bool kasan_p4d_populate_zero_shadow(p4d_t *p4d, unsigned long addr, 176 + unsigned long end, enum populate_mode mode) 177 + { 178 + return false; 179 + } 180 + 181 + static inline bool kasan_pud_populate_zero_shadow(pud_t *pud, unsigned long addr, 182 + unsigned long end, enum populate_mode mode) 183 + { 184 + return false; 185 + } 186 + 187 + static inline bool kasan_pmd_populate_zero_shadow(pmd_t *pmd, unsigned long addr, 188 + unsigned long end, enum populate_mode mode) 189 + { 190 + return false; 191 + } 192 + 193 + static bool kasan_pte_populate_zero_shadow(pte_t *pte, enum populate_mode mode) 194 + { 195 + return false; 196 + } 197 + 198 + #endif 16 199 17 200 /* 18 201 * Mimic virt_to_kpte() in lack of init_mm symbol. Skip pmd NULL check though. ··· 205 22 return pte_offset_kernel(pmd_offset(pud_offset(p4d_offset(pgd_offset_k(va), va), va), va), va); 206 23 } 207 24 208 - unsigned long __bootdata_preserved(s390_invalid_asce); 209 - unsigned long __bootdata(pgalloc_pos); 210 - unsigned long __bootdata(pgalloc_end); 211 - unsigned long __bootdata(pgalloc_low); 212 - 213 - enum populate_mode { 214 - POPULATE_NONE, 215 - POPULATE_ONE2ONE, 216 - POPULATE_ABS_LOWCORE, 217 - }; 218 - 219 - static void boot_check_oom(void) 220 - { 221 - if (pgalloc_pos < pgalloc_low) 222 - error("out of memory on boot\n"); 223 - } 224 - 225 - static void pgtable_populate_init(void) 226 - { 227 - unsigned long initrd_end; 228 - unsigned long kernel_end; 229 - 230 - kernel_end = vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size; 231 - pgalloc_low = round_up(kernel_end, PAGE_SIZE); 232 - if (IS_ENABLED(CONFIG_BLK_DEV_INITRD)) { 233 - initrd_end = round_up(initrd_data.start + initrd_data.size, _SEGMENT_SIZE); 234 - pgalloc_low = max(pgalloc_low, initrd_end); 235 - } 236 - 237 - pgalloc_end = round_down(get_mem_detect_end(), PAGE_SIZE); 238 - pgalloc_pos = pgalloc_end; 239 - 240 - boot_check_oom(); 241 - } 242 - 243 - static void *boot_alloc_pages(unsigned int order) 244 - { 245 - unsigned long size = PAGE_SIZE << order; 246 - 247 - pgalloc_pos -= size; 248 - pgalloc_pos = round_down(pgalloc_pos, size); 249 - 250 - boot_check_oom(); 251 - 252 - return (void *)pgalloc_pos; 253 - } 254 - 255 25 static void *boot_crst_alloc(unsigned long val) 256 26 { 27 + unsigned long size = PAGE_SIZE << CRST_ALLOC_ORDER; 257 28 unsigned long *table; 258 29 259 - table = boot_alloc_pages(CRST_ALLOC_ORDER); 260 - if (table) 261 - crst_table_init(table, val); 30 + table = (unsigned long *)physmem_alloc_top_down(RR_VMEM, size, size); 31 + crst_table_init(table, val); 262 32 return table; 263 33 } 264 34 ··· 220 84 static void *pte_leftover; 221 85 pte_t *pte; 222 86 223 - BUILD_BUG_ON(_PAGE_TABLE_SIZE * 2 != PAGE_SIZE); 224 - 87 + /* 88 + * handling pte_leftovers this way helps to avoid memory fragmentation 89 + * during POPULATE_KASAN_MAP_SHADOW when EDAT is off 90 + */ 225 91 if (!pte_leftover) { 226 - pte_leftover = boot_alloc_pages(0); 92 + pte_leftover = (void *)physmem_alloc_top_down(RR_VMEM, PAGE_SIZE, PAGE_SIZE); 227 93 pte = pte_leftover + _PAGE_TABLE_SIZE; 228 94 } else { 229 95 pte = pte_leftover; 230 96 pte_leftover = NULL; 231 97 } 98 + 232 99 memset64((u64 *)pte, _PAGE_INVALID, PTRS_PER_PTE); 233 100 return pte; 234 101 } 235 102 236 - static unsigned long _pa(unsigned long addr, enum populate_mode mode) 103 + static unsigned long _pa(unsigned long addr, unsigned long size, enum populate_mode mode) 237 104 { 238 105 switch (mode) { 239 106 case POPULATE_NONE: 240 107 return -1; 241 - case POPULATE_ONE2ONE: 108 + case POPULATE_DIRECT: 242 109 return addr; 243 110 case POPULATE_ABS_LOWCORE: 244 111 return __abs_lowcore_pa(addr); 112 + #ifdef CONFIG_KASAN 113 + case POPULATE_KASAN_MAP_SHADOW: 114 + addr = physmem_alloc_top_down(RR_VMEM, size, size); 115 + memset((void *)addr, 0, size); 116 + return addr; 117 + #endif 245 118 default: 246 119 return -1; 247 120 } ··· 271 126 static void pgtable_pte_populate(pmd_t *pmd, unsigned long addr, unsigned long end, 272 127 enum populate_mode mode) 273 128 { 274 - unsigned long next; 129 + unsigned long pages = 0; 275 130 pte_t *pte, entry; 276 131 277 132 pte = pte_offset_kernel(pmd, addr); 278 133 for (; addr < end; addr += PAGE_SIZE, pte++) { 279 134 if (pte_none(*pte)) { 280 - entry = __pte(_pa(addr, mode)); 135 + if (kasan_pte_populate_zero_shadow(pte, mode)) 136 + continue; 137 + entry = __pte(_pa(addr, PAGE_SIZE, mode)); 281 138 entry = set_pte_bit(entry, PAGE_KERNEL_EXEC); 282 139 set_pte(pte, entry); 140 + pages++; 283 141 } 284 142 } 143 + if (mode == POPULATE_DIRECT) 144 + update_page_count(PG_DIRECT_MAP_4K, pages); 285 145 } 286 146 287 147 static void pgtable_pmd_populate(pud_t *pud, unsigned long addr, unsigned long end, 288 148 enum populate_mode mode) 289 149 { 290 - unsigned long next; 150 + unsigned long next, pages = 0; 291 151 pmd_t *pmd, entry; 292 152 pte_t *pte; 293 153 ··· 300 150 for (; addr < end; addr = next, pmd++) { 301 151 next = pmd_addr_end(addr, end); 302 152 if (pmd_none(*pmd)) { 153 + if (kasan_pmd_populate_zero_shadow(pmd, addr, next, mode)) 154 + continue; 303 155 if (can_large_pmd(pmd, addr, next)) { 304 - entry = __pmd(_pa(addr, mode)); 156 + entry = __pmd(_pa(addr, _SEGMENT_SIZE, mode)); 305 157 entry = set_pmd_bit(entry, SEGMENT_KERNEL_EXEC); 306 158 set_pmd(pmd, entry); 159 + pages++; 307 160 continue; 308 161 } 309 162 pte = boot_pte_alloc(); ··· 316 163 } 317 164 pgtable_pte_populate(pmd, addr, next, mode); 318 165 } 166 + if (mode == POPULATE_DIRECT) 167 + update_page_count(PG_DIRECT_MAP_1M, pages); 319 168 } 320 169 321 170 static void pgtable_pud_populate(p4d_t *p4d, unsigned long addr, unsigned long end, 322 171 enum populate_mode mode) 323 172 { 324 - unsigned long next; 173 + unsigned long next, pages = 0; 325 174 pud_t *pud, entry; 326 175 pmd_t *pmd; 327 176 ··· 331 176 for (; addr < end; addr = next, pud++) { 332 177 next = pud_addr_end(addr, end); 333 178 if (pud_none(*pud)) { 179 + if (kasan_pud_populate_zero_shadow(pud, addr, next, mode)) 180 + continue; 334 181 if (can_large_pud(pud, addr, next)) { 335 - entry = __pud(_pa(addr, mode)); 182 + entry = __pud(_pa(addr, _REGION3_SIZE, mode)); 336 183 entry = set_pud_bit(entry, REGION3_KERNEL_EXEC); 337 184 set_pud(pud, entry); 185 + pages++; 338 186 continue; 339 187 } 340 188 pmd = boot_crst_alloc(_SEGMENT_ENTRY_EMPTY); ··· 347 189 } 348 190 pgtable_pmd_populate(pud, addr, next, mode); 349 191 } 192 + if (mode == POPULATE_DIRECT) 193 + update_page_count(PG_DIRECT_MAP_2G, pages); 350 194 } 351 195 352 196 static void pgtable_p4d_populate(pgd_t *pgd, unsigned long addr, unsigned long end, ··· 362 202 for (; addr < end; addr = next, p4d++) { 363 203 next = p4d_addr_end(addr, end); 364 204 if (p4d_none(*p4d)) { 205 + if (kasan_p4d_populate_zero_shadow(p4d, addr, next, mode)) 206 + continue; 365 207 pud = boot_crst_alloc(_REGION3_ENTRY_EMPTY); 366 208 p4d_populate(&init_mm, p4d, pud); 367 209 } ··· 381 219 for (; addr < end; addr = next, pgd++) { 382 220 next = pgd_addr_end(addr, end); 383 221 if (pgd_none(*pgd)) { 222 + if (kasan_pgd_populate_zero_shadow(pgd, addr, next, mode)) 223 + continue; 384 224 p4d = boot_crst_alloc(_REGION2_ENTRY_EMPTY); 385 225 pgd_populate(&init_mm, pgd, p4d); 386 226 } 227 + #ifdef CONFIG_KASAN 228 + if (mode == POPULATE_KASAN_SHALLOW) 229 + continue; 230 + #endif 387 231 pgtable_p4d_populate(pgd, addr, next, mode); 388 232 } 389 233 } ··· 418 250 * To prevent creation of a large page at address 0 first map 419 251 * the lowcore and create the identity mapping only afterwards. 420 252 */ 421 - pgtable_populate_init(); 422 - pgtable_populate(0, sizeof(struct lowcore), POPULATE_ONE2ONE); 423 - for_each_mem_detect_usable_block(i, &start, &end) 424 - pgtable_populate(start, end, POPULATE_ONE2ONE); 253 + pgtable_populate(0, sizeof(struct lowcore), POPULATE_DIRECT); 254 + for_each_physmem_usable_range(i, &start, &end) 255 + pgtable_populate(start, end, POPULATE_DIRECT); 425 256 pgtable_populate(__abs_lowcore, __abs_lowcore + sizeof(struct lowcore), 426 257 POPULATE_ABS_LOWCORE); 427 258 pgtable_populate(__memcpy_real_area, __memcpy_real_area + PAGE_SIZE, 428 259 POPULATE_NONE); 429 260 memcpy_real_ptep = __virt_to_kpte(__memcpy_real_area); 261 + 262 + kasan_populate_shadow(); 430 263 431 264 S390_lowcore.kernel_asce = swapper_pg_dir | asce_bits; 432 265 S390_lowcore.user_asce = s390_invalid_asce; ··· 437 268 __ctl_load(S390_lowcore.kernel_asce, 13, 13); 438 269 439 270 init_mm.context.asce = S390_lowcore.kernel_asce; 440 - } 441 - 442 - unsigned long vmem_estimate_memory_needs(unsigned long online_mem_total) 443 - { 444 - unsigned long pages = DIV_ROUND_UP(online_mem_total, PAGE_SIZE); 445 - 446 - return DIV_ROUND_UP(pages, _PAGE_ENTRIES) * _PAGE_TABLE_SIZE * 2; 447 271 }
+2
arch/s390/boot/vmlinux.lds.S
··· 93 93 _decompressor_syms_end = .; 94 94 } 95 95 96 + _decompressor_end = .; 97 + 96 98 #ifdef CONFIG_KERNEL_UNCOMPRESSED 97 99 . = 0x100000; 98 100 #else
+22 -21
arch/s390/crypto/chacha-s390.S
··· 13 13 #define SP %r15 14 14 #define FRAME (16 * 8 + 4 * 8) 15 15 16 - .data 17 - .align 32 16 + .data 17 + .balign 32 18 18 19 - .Lsigma: 20 - .long 0x61707865,0x3320646e,0x79622d32,0x6b206574 # endian-neutral 21 - .long 1,0,0,0 22 - .long 2,0,0,0 23 - .long 3,0,0,0 24 - .long 0x03020100,0x07060504,0x0b0a0908,0x0f0e0d0c # byte swap 19 + SYM_DATA_START_LOCAL(sigma) 20 + .long 0x61707865,0x3320646e,0x79622d32,0x6b206574 # endian-neutral 21 + .long 1,0,0,0 22 + .long 2,0,0,0 23 + .long 3,0,0,0 24 + .long 0x03020100,0x07060504,0x0b0a0908,0x0f0e0d0c # byte swap 25 25 26 - .long 0,1,2,3 27 - .long 0x61707865,0x61707865,0x61707865,0x61707865 # smashed sigma 28 - .long 0x3320646e,0x3320646e,0x3320646e,0x3320646e 29 - .long 0x79622d32,0x79622d32,0x79622d32,0x79622d32 30 - .long 0x6b206574,0x6b206574,0x6b206574,0x6b206574 26 + .long 0,1,2,3 27 + .long 0x61707865,0x61707865,0x61707865,0x61707865 # smashed sigma 28 + .long 0x3320646e,0x3320646e,0x3320646e,0x3320646e 29 + .long 0x79622d32,0x79622d32,0x79622d32,0x79622d32 30 + .long 0x6b206574,0x6b206574,0x6b206574,0x6b206574 31 + SYM_DATA_END(sigma) 31 32 32 - .previous 33 + .previous 33 34 34 35 GEN_BR_THUNK %r14 35 36 36 - .text 37 + .text 37 38 38 39 ############################################################################# 39 40 # void chacha20_vx_4x(u8 *out, counst u8 *inp, size_t len, ··· 79 78 #define XT2 %v29 80 79 #define XT3 %v30 81 80 82 - ENTRY(chacha20_vx_4x) 81 + SYM_FUNC_START(chacha20_vx_4x) 83 82 stmg %r6,%r7,6*8(SP) 84 83 85 - larl %r7,.Lsigma 84 + larl %r7,sigma 86 85 lhi %r0,10 87 86 lhi %r1,0 88 87 ··· 404 403 405 404 lmg %r6,%r7,6*8(SP) 406 405 BR_EX %r14 407 - ENDPROC(chacha20_vx_4x) 406 + SYM_FUNC_END(chacha20_vx_4x) 408 407 409 408 #undef OUT 410 409 #undef INP ··· 472 471 #define T2 %v29 473 472 #define T3 %v30 474 473 475 - ENTRY(chacha20_vx) 474 + SYM_FUNC_START(chacha20_vx) 476 475 clgfi LEN,256 477 476 jle chacha20_vx_4x 478 477 stmg %r6,%r7,6*8(SP) ··· 482 481 la SP,0(%r1,SP) 483 482 stg %r0,0(SP) # back-chain 484 483 485 - larl %r7,.Lsigma 484 + larl %r7,sigma 486 485 lhi %r0,10 487 486 488 487 VLM K1,K2,0,KEY,0 # load key ··· 903 902 lmg %r6,%r7,FRAME+6*8(SP) 904 903 la SP,FRAME(SP) 905 904 BR_EX %r14 906 - ENDPROC(chacha20_vx) 905 + SYM_FUNC_END(chacha20_vx) 907 906 908 907 .previous
+9 -8
arch/s390/crypto/crc32be-vx.S
··· 24 24 #define CONST_RU_POLY %v13 25 25 #define CONST_CRC_POLY %v14 26 26 27 - .data 28 - .align 8 27 + .data 28 + .balign 8 29 29 30 30 /* 31 31 * The CRC-32 constant block contains reduction constants to fold and ··· 58 58 * P'(x) = 0xEDB88320 59 59 */ 60 60 61 - .Lconstants_CRC_32_BE: 61 + SYM_DATA_START_LOCAL(constants_CRC_32_BE) 62 62 .quad 0x08833794c, 0x0e6228b11 # R1, R2 63 63 .quad 0x0c5b9cd4c, 0x0e8a45605 # R3, R4 64 64 .quad 0x0f200aa66, 1 << 32 # R5, x32 65 65 .quad 0x0490d678d, 1 # R6, 1 66 66 .quad 0x104d101df, 0 # u 67 67 .quad 0x104C11DB7, 0 # P(x) 68 + SYM_DATA_END(constants_CRC_32_BE) 68 69 69 - .previous 70 + .previous 70 71 71 72 GEN_BR_THUNK %r14 72 73 73 - .text 74 + .text 74 75 /* 75 76 * The CRC-32 function(s) use these calling conventions: 76 77 * ··· 91 90 * 92 91 * V9..V14: CRC-32 constants. 93 92 */ 94 - ENTRY(crc32_be_vgfm_16) 93 + SYM_FUNC_START(crc32_be_vgfm_16) 95 94 /* Load CRC-32 constants */ 96 - larl %r5,.Lconstants_CRC_32_BE 95 + larl %r5,constants_CRC_32_BE 97 96 VLM CONST_R1R2,CONST_CRC_POLY,0,%r5 98 97 99 98 /* Load the initial CRC value into the leftmost word of V0. */ ··· 208 207 .Ldone: 209 208 VLGVF %r2,%v2,3 210 209 BR_EX %r14 211 - ENDPROC(crc32_be_vgfm_16) 210 + SYM_FUNC_END(crc32_be_vgfm_16) 212 211 213 212 .previous
+16 -14
arch/s390/crypto/crc32le-vx.S
··· 25 25 #define CONST_RU_POLY %v13 26 26 #define CONST_CRC_POLY %v14 27 27 28 - .data 29 - .align 8 28 + .data 29 + .balign 8 30 30 31 31 /* 32 32 * The CRC-32 constant block contains reduction constants to fold and ··· 59 59 * P'(x) = 0x82F63B78 60 60 */ 61 61 62 - .Lconstants_CRC_32_LE: 62 + SYM_DATA_START_LOCAL(constants_CRC_32_LE) 63 63 .octa 0x0F0E0D0C0B0A09080706050403020100 # BE->LE mask 64 64 .quad 0x1c6e41596, 0x154442bd4 # R2, R1 65 65 .quad 0x0ccaa009e, 0x1751997d0 # R4, R3 66 66 .octa 0x163cd6124 # R5 67 67 .octa 0x1F7011641 # u' 68 68 .octa 0x1DB710641 # P'(x) << 1 69 + SYM_DATA_END(constants_CRC_32_LE) 69 70 70 - .Lconstants_CRC_32C_LE: 71 + SYM_DATA_START_LOCAL(constants_CRC_32C_LE) 71 72 .octa 0x0F0E0D0C0B0A09080706050403020100 # BE->LE mask 72 73 .quad 0x09e4addf8, 0x740eef02 # R2, R1 73 74 .quad 0x14cd00bd6, 0xf20c0dfe # R4, R3 74 75 .octa 0x0dd45aab8 # R5 75 76 .octa 0x0dea713f1 # u' 76 77 .octa 0x105ec76f0 # P'(x) << 1 78 + SYM_DATA_END(constants_CRC_32C_LE) 77 79 78 - .previous 80 + .previous 79 81 80 82 GEN_BR_THUNK %r14 81 83 82 - .text 84 + .text 83 85 84 86 /* 85 87 * The CRC-32 functions use these calling conventions: ··· 104 102 * V10..V14: CRC-32 constants. 105 103 */ 106 104 107 - ENTRY(crc32_le_vgfm_16) 108 - larl %r5,.Lconstants_CRC_32_LE 105 + SYM_FUNC_START(crc32_le_vgfm_16) 106 + larl %r5,constants_CRC_32_LE 109 107 j crc32_le_vgfm_generic 110 - ENDPROC(crc32_le_vgfm_16) 108 + SYM_FUNC_END(crc32_le_vgfm_16) 111 109 112 - ENTRY(crc32c_le_vgfm_16) 113 - larl %r5,.Lconstants_CRC_32C_LE 110 + SYM_FUNC_START(crc32c_le_vgfm_16) 111 + larl %r5,constants_CRC_32C_LE 114 112 j crc32_le_vgfm_generic 115 - ENDPROC(crc32c_le_vgfm_16) 113 + SYM_FUNC_END(crc32c_le_vgfm_16) 116 114 117 - ENTRY(crc32_le_vgfm_generic) 115 + SYM_FUNC_START(crc32_le_vgfm_generic) 118 116 /* Load CRC-32 constants */ 119 117 VLM CONST_PERM_LE2BE,CONST_CRC_POLY,0,%r5 120 118 ··· 270 268 .Ldone: 271 269 VLGVF %r2,%v2,2 272 270 BR_EX %r14 273 - ENDPROC(crc32_le_vgfm_generic) 271 + SYM_FUNC_END(crc32_le_vgfm_generic) 274 272 275 273 .previous
+128 -24
arch/s390/include/asm/ap.h
··· 43 43 unsigned int queue_empty : 1; 44 44 unsigned int replies_waiting : 1; 45 45 unsigned int queue_full : 1; 46 - unsigned int _pad1 : 4; 46 + unsigned int : 3; 47 + unsigned int async : 1; 47 48 unsigned int irq_enabled : 1; 48 49 unsigned int response_code : 8; 49 - unsigned int _pad2 : 16; 50 + unsigned int : 16; 50 51 }; 51 52 52 53 /* ··· 87 86 return reg1 != 0; 88 87 } 89 88 89 + /* TAPQ register GR2 response struct */ 90 + struct ap_tapq_gr2 { 91 + union { 92 + unsigned long value; 93 + struct { 94 + unsigned int fac : 32; /* facility bits */ 95 + unsigned int apinfo : 32; /* ap type, ... */ 96 + }; 97 + struct { 98 + unsigned int s : 1; /* APSC */ 99 + unsigned int m : 1; /* AP4KM */ 100 + unsigned int c : 1; /* AP4KC */ 101 + unsigned int mode : 3; 102 + unsigned int n : 1; /* APXA */ 103 + unsigned int : 1; 104 + unsigned int class : 8; 105 + unsigned int bs : 2; /* SE bind/assoc */ 106 + unsigned int : 14; 107 + unsigned int at : 8; /* ap type */ 108 + unsigned int nd : 8; /* nr of domains */ 109 + unsigned int : 4; 110 + unsigned int ml : 4; /* apxl ml */ 111 + unsigned int : 4; 112 + unsigned int qd : 4; /* queue depth */ 113 + }; 114 + }; 115 + }; 116 + 117 + /* 118 + * Convenience defines to be used with the bs field from struct ap_tapq_gr2 119 + */ 120 + #define AP_BS_Q_USABLE 0 121 + #define AP_BS_Q_USABLE_NO_SECURE_KEY 1 122 + #define AP_BS_Q_AVAIL_FOR_BINDING 2 123 + #define AP_BS_Q_UNUSABLE 3 124 + 90 125 /** 91 126 * ap_tapq(): Test adjunct processor queue. 92 127 * @qid: The AP queue number ··· 130 93 * 131 94 * Returns AP queue status structure. 132 95 */ 133 - static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info) 96 + static inline struct ap_queue_status ap_tapq(ap_qid_t qid, struct ap_tapq_gr2 *info) 134 97 { 135 98 union ap_queue_status_reg reg1; 136 99 unsigned long reg2; ··· 145 108 : [qid] "d" (qid) 146 109 : "cc", "0", "1", "2"); 147 110 if (info) 148 - *info = reg2; 111 + info->value = reg2; 149 112 return reg1.status; 150 113 } 151 114 ··· 153 116 * ap_test_queue(): Test adjunct processor queue. 154 117 * @qid: The AP queue number 155 118 * @tbit: Test facilities bit 156 - * @info: Pointer to queue descriptor 119 + * @info: Ptr to tapq gr2 struct 157 120 * 158 121 * Returns AP queue status structure. 159 122 */ 160 - static inline struct ap_queue_status ap_test_queue(ap_qid_t qid, 161 - int tbit, 162 - unsigned long *info) 123 + static inline struct ap_queue_status ap_test_queue(ap_qid_t qid, int tbit, 124 + struct ap_tapq_gr2 *info) 163 125 { 164 126 if (tbit) 165 127 qid |= 1UL << 23; /* set T bit*/ ··· 168 132 /** 169 133 * ap_pqap_rapq(): Reset adjunct processor queue. 170 134 * @qid: The AP queue number 135 + * @fbit: if != 0 set F bit 171 136 * 172 137 * Returns AP queue status structure. 173 138 */ 174 - static inline struct ap_queue_status ap_rapq(ap_qid_t qid) 139 + static inline struct ap_queue_status ap_rapq(ap_qid_t qid, int fbit) 175 140 { 176 141 unsigned long reg0 = qid | (1UL << 24); /* fc 1UL is RAPQ */ 177 142 union ap_queue_status_reg reg1; 143 + 144 + if (fbit) 145 + reg0 |= 1UL << 22; 178 146 179 147 asm volatile( 180 148 " lgr 0,%[reg0]\n" /* qid arg into gr0 */ ··· 193 153 /** 194 154 * ap_pqap_zapq(): Reset and zeroize adjunct processor queue. 195 155 * @qid: The AP queue number 156 + * @fbit: if != 0 set F bit 196 157 * 197 158 * Returns AP queue status structure. 198 159 */ 199 - static inline struct ap_queue_status ap_zapq(ap_qid_t qid) 160 + static inline struct ap_queue_status ap_zapq(ap_qid_t qid, int fbit) 200 161 { 201 162 unsigned long reg0 = qid | (2UL << 24); /* fc 2UL is ZAPQ */ 202 163 union ap_queue_status_reg reg1; 164 + 165 + if (fbit) 166 + reg0 |= 1UL << 22; 203 167 204 168 asm volatile( 205 169 " lgr 0,%[reg0]\n" /* qid arg into gr0 */ ··· 224 180 unsigned int apxa : 1; /* N bit */ 225 181 unsigned int qact : 1; /* C bit */ 226 182 unsigned int rc8a : 1; /* R bit */ 227 - unsigned char _reserved1 : 4; 228 - unsigned char _reserved2[3]; 229 - unsigned char Na; /* max # of APs - 1 */ 230 - unsigned char Nd; /* max # of Domains - 1 */ 231 - unsigned char _reserved3[10]; 183 + unsigned int : 4; 184 + unsigned int apsb : 1; /* B bit */ 185 + unsigned int : 23; 186 + unsigned char na; /* max # of APs - 1 */ 187 + unsigned char nd; /* max # of Domains - 1 */ 188 + unsigned char _reserved0[10]; 232 189 unsigned int apm[8]; /* AP ID mask */ 233 190 unsigned int aqm[8]; /* AP (usage) queue mask */ 234 191 unsigned int adm[8]; /* AP (control) domain mask */ 235 - unsigned char _reserved4[16]; 192 + unsigned char _reserved1[16]; 236 193 } __aligned(8); 237 194 238 195 /** ··· 363 318 return reg1.status; 364 319 } 365 320 321 + /* 322 + * ap_bapq(): SE bind AP queue. 323 + * @qid: The AP queue number 324 + * 325 + * Returns AP queue status structure. 326 + * 327 + * Invoking this function in a non-SE environment 328 + * may case a specification exception. 329 + */ 330 + static inline struct ap_queue_status ap_bapq(ap_qid_t qid) 331 + { 332 + unsigned long reg0 = qid | (7UL << 24); /* fc 7 is BAPQ */ 333 + union ap_queue_status_reg reg1; 334 + 335 + asm volatile( 336 + " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 337 + " .insn rre,0xb2af0000,0,0\n" /* PQAP(BAPQ) */ 338 + " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 339 + : [reg1] "=&d" (reg1.value) 340 + : [reg0] "d" (reg0) 341 + : "cc", "0", "1"); 342 + 343 + return reg1.status; 344 + } 345 + 346 + /* 347 + * ap_aapq(): SE associate AP queue. 348 + * @qid: The AP queue number 349 + * @sec_idx: The secret index 350 + * 351 + * Returns AP queue status structure. 352 + * 353 + * Invoking this function in a non-SE environment 354 + * may case a specification exception. 355 + */ 356 + static inline struct ap_queue_status ap_aapq(ap_qid_t qid, unsigned int sec_idx) 357 + { 358 + unsigned long reg0 = qid | (8UL << 24); /* fc 8 is AAPQ */ 359 + unsigned long reg2 = sec_idx; 360 + union ap_queue_status_reg reg1; 361 + 362 + asm volatile( 363 + " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 364 + " lgr 2,%[reg2]\n" /* secret index into gr2 */ 365 + " .insn rre,0xb2af0000,0,0\n" /* PQAP(AAPQ) */ 366 + " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 367 + : [reg1] "=&d" (reg1.value) 368 + : [reg0] "d" (reg0), [reg2] "d" (reg2) 369 + : "cc", "0", "1", "2"); 370 + 371 + return reg1.status; 372 + } 373 + 366 374 /** 367 375 * ap_nqap(): Send message to adjunct processor queue. 368 376 * @qid: The AP queue number ··· 457 359 * ap_dqap(): Receive message from adjunct processor queue. 458 360 * @qid: The AP queue number 459 361 * @psmid: Pointer to program supplied message identifier 460 - * @msg: The message text 461 - * @length: The message length 462 - * @reslength: Resitual length on return 463 - * @resgr0: input: gr0 value (only used if != 0), output: resitual gr0 content 362 + * @msg: Pointer to message buffer 363 + * @msglen: Message buffer size 364 + * @length: Pointer to length of actually written bytes 365 + * @reslength: Residual length on return 366 + * @resgr0: input: gr0 value (only used if != 0), output: residual gr0 content 464 367 * 465 368 * Returns AP queue status structure. 466 369 * Condition code 1 on DQAP means the receive has taken place ··· 485 386 * *resgr0 is to be used instead of qid to further process this entry. 486 387 */ 487 388 static inline struct ap_queue_status ap_dqap(ap_qid_t qid, 488 - unsigned long long *psmid, 489 - void *msg, size_t length, 389 + unsigned long *psmid, 390 + void *msg, size_t msglen, 391 + size_t *length, 490 392 size_t *reslength, 491 393 unsigned long *resgr0) 492 394 { ··· 499 399 rp1.even = 0UL; 500 400 rp1.odd = 0UL; 501 401 rp2.even = (unsigned long)msg; 502 - rp2.odd = (unsigned long)length; 402 + rp2.odd = (unsigned long)msglen; 503 403 504 404 asm volatile( 505 405 " lgr 0,%[reg0]\n" /* qid param into gr0 */ ··· 529 429 if (resgr0) 530 430 *resgr0 = reg0; 531 431 } else { 532 - *psmid = (((unsigned long long)rp1.even) << 32) + rp1.odd; 432 + *psmid = (rp1.even << 32) + rp1.odd; 533 433 if (resgr0) 534 434 *resgr0 = 0; 535 435 } 436 + 437 + /* update *length with the nr of bytes stored into the msg buffer */ 438 + if (length) 439 + *length = msglen - rp2.odd; 536 440 537 441 return reg1.status; 538 442 }
+2 -8
arch/s390/include/asm/checksum.h
··· 12 12 #ifndef _S390_CHECKSUM_H 13 13 #define _S390_CHECKSUM_H 14 14 15 - #ifdef CONFIG_GENERIC_CSUM 16 - 17 - #include <asm-generic/checksum.h> 18 - 19 - #else /* CONFIG_GENERIC_CSUM */ 20 - 21 - #include <linux/uaccess.h> 15 + #include <linux/kasan-checks.h> 22 16 #include <linux/in6.h> 23 17 24 18 /* ··· 34 40 .odd = (unsigned long) len, 35 41 }; 36 42 43 + kasan_check_read(buff, len); 37 44 asm volatile( 38 45 "0: cksm %[sum],%[rp]\n" 39 46 " jo 0b\n" ··· 130 135 return csum_fold((__force __wsum)(sum >> 32)); 131 136 } 132 137 133 - #endif /* CONFIG_GENERIC_CSUM */ 134 138 #endif /* _S390_CHECKSUM_H */
+1 -1
arch/s390/include/asm/diag.h
··· 90 90 u8 num_partitions; 91 91 u16 width; 92 92 u16 height; 93 - u8 data[0]; 93 + u8 data[]; 94 94 } __packed __aligned(4); 95 95 96 96 extern int diag8c(struct diag8c *out, struct ccw_dev_id *devno);
-5
arch/s390/include/asm/entry-common.h
··· 60 60 61 61 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare 62 62 63 - static inline bool on_thread_stack(void) 64 - { 65 - return !(((unsigned long)(current->stack) ^ current_stack_pointer) & ~(THREAD_SIZE - 1)); 66 - } 67 - 68 63 #endif
+1 -1
arch/s390/include/asm/fcx.h
··· 286 286 */ 287 287 struct tccb { 288 288 struct tccb_tcah tcah; 289 - u8 tca[0]; 289 + u8 tca[]; 290 290 } __attribute__ ((packed, aligned(8))); 291 291 292 292 struct tcw *tcw_get_intrg(struct tcw *tcw);
+1 -30
arch/s390/include/asm/kasan.h
··· 2 2 #ifndef __ASM_KASAN_H 3 3 #define __ASM_KASAN_H 4 4 5 - #include <asm/pgtable.h> 5 + #include <linux/const.h> 6 6 7 7 #ifdef CONFIG_KASAN 8 8 ··· 13 13 #define KASAN_SHADOW_START KASAN_SHADOW_OFFSET 14 14 #define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) 15 15 16 - extern void kasan_early_init(void); 17 - 18 - /* 19 - * Estimate kasan memory requirements, which it will reserve 20 - * at the very end of available physical memory. To estimate 21 - * that, we take into account that kasan would require 22 - * 1/8 of available physical memory (for shadow memory) + 23 - * creating page tables for the shadow memory region. 24 - * To keep page tables estimates simple take the double of 25 - * combined ptes size. 26 - * 27 - * physmem parameter has to be already adjusted if not entire physical memory 28 - * would be used (e.g. due to effect of "mem=" option). 29 - */ 30 - static inline unsigned long kasan_estimate_memory_needs(unsigned long physmem) 31 - { 32 - unsigned long kasan_needs; 33 - unsigned long pages; 34 - /* for shadow memory */ 35 - kasan_needs = round_up(physmem / 8, PAGE_SIZE); 36 - /* for paging structures */ 37 - pages = DIV_ROUND_UP(kasan_needs, PAGE_SIZE); 38 - kasan_needs += DIV_ROUND_UP(pages, _PAGE_ENTRIES) * _PAGE_TABLE_SIZE * 2; 39 - 40 - return kasan_needs; 41 - } 42 - #else 43 - static inline void kasan_early_init(void) { } 44 - static inline unsigned long kasan_estimate_memory_needs(unsigned long physmem) { return 0; } 45 16 #endif 46 17 47 18 #endif
+1 -1
arch/s390/include/asm/linkage.h
··· 4 4 5 5 #include <linux/stringify.h> 6 6 7 - #define __ALIGN .align 16, 0x07 7 + #define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT, 0x07 8 8 #define __ALIGN_STR __stringify(__ALIGN) 9 9 10 10 #endif
-117
arch/s390/include/asm/mem_detect.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _ASM_S390_MEM_DETECT_H 3 - #define _ASM_S390_MEM_DETECT_H 4 - 5 - #include <linux/types.h> 6 - 7 - enum mem_info_source { 8 - MEM_DETECT_NONE = 0, 9 - MEM_DETECT_SCLP_STOR_INFO, 10 - MEM_DETECT_DIAG260, 11 - MEM_DETECT_SCLP_READ_INFO, 12 - MEM_DETECT_BIN_SEARCH 13 - }; 14 - 15 - struct mem_detect_block { 16 - u64 start; 17 - u64 end; 18 - }; 19 - 20 - /* 21 - * Storage element id is defined as 1 byte (up to 256 storage elements). 22 - * In practise only storage element id 0 and 1 are used). 23 - * According to architecture one storage element could have as much as 24 - * 1020 subincrements. 255 mem_detect_blocks are embedded in mem_detect_info. 25 - * If more mem_detect_blocks are required, a block of memory from already 26 - * known mem_detect_block is taken (entries_extended points to it). 27 - */ 28 - #define MEM_INLINED_ENTRIES 255 /* (PAGE_SIZE - 16) / 16 */ 29 - 30 - struct mem_detect_info { 31 - u32 count; 32 - u8 info_source; 33 - unsigned long usable; 34 - struct mem_detect_block entries[MEM_INLINED_ENTRIES]; 35 - struct mem_detect_block *entries_extended; 36 - }; 37 - extern struct mem_detect_info mem_detect; 38 - 39 - void add_mem_detect_block(u64 start, u64 end); 40 - 41 - static inline int __get_mem_detect_block(u32 n, unsigned long *start, 42 - unsigned long *end, bool respect_usable_limit) 43 - { 44 - if (n >= mem_detect.count) { 45 - *start = 0; 46 - *end = 0; 47 - return -1; 48 - } 49 - 50 - if (n < MEM_INLINED_ENTRIES) { 51 - *start = (unsigned long)mem_detect.entries[n].start; 52 - *end = (unsigned long)mem_detect.entries[n].end; 53 - } else { 54 - *start = (unsigned long)mem_detect.entries_extended[n - MEM_INLINED_ENTRIES].start; 55 - *end = (unsigned long)mem_detect.entries_extended[n - MEM_INLINED_ENTRIES].end; 56 - } 57 - 58 - if (respect_usable_limit && mem_detect.usable) { 59 - if (*start >= mem_detect.usable) 60 - return -1; 61 - if (*end > mem_detect.usable) 62 - *end = mem_detect.usable; 63 - } 64 - return 0; 65 - } 66 - 67 - /** 68 - * for_each_mem_detect_usable_block - early online memory range iterator 69 - * @i: an integer used as loop variable 70 - * @p_start: ptr to unsigned long for start address of the range 71 - * @p_end: ptr to unsigned long for end address of the range 72 - * 73 - * Walks over detected online memory ranges below usable limit. 74 - */ 75 - #define for_each_mem_detect_usable_block(i, p_start, p_end) \ 76 - for (i = 0; !__get_mem_detect_block(i, p_start, p_end, true); i++) 77 - 78 - /* Walks over all detected online memory ranges disregarding usable limit. */ 79 - #define for_each_mem_detect_block(i, p_start, p_end) \ 80 - for (i = 0; !__get_mem_detect_block(i, p_start, p_end, false); i++) 81 - 82 - static inline unsigned long get_mem_detect_usable_total(void) 83 - { 84 - unsigned long start, end, total = 0; 85 - int i; 86 - 87 - for_each_mem_detect_usable_block(i, &start, &end) 88 - total += end - start; 89 - 90 - return total; 91 - } 92 - 93 - static inline void get_mem_detect_reserved(unsigned long *start, 94 - unsigned long *size) 95 - { 96 - *start = (unsigned long)mem_detect.entries_extended; 97 - if (mem_detect.count > MEM_INLINED_ENTRIES) 98 - *size = (mem_detect.count - MEM_INLINED_ENTRIES) * sizeof(struct mem_detect_block); 99 - else 100 - *size = 0; 101 - } 102 - 103 - static inline unsigned long get_mem_detect_end(void) 104 - { 105 - unsigned long start; 106 - unsigned long end; 107 - 108 - if (mem_detect.usable) 109 - return mem_detect.usable; 110 - if (mem_detect.count) { 111 - __get_mem_detect_block(mem_detect.count - 1, &start, &end, false); 112 - return end; 113 - } 114 - return 0; 115 - } 116 - 117 - #endif
+2 -1
arch/s390/include/asm/nospec-insn.h
··· 2 2 #ifndef _ASM_S390_NOSPEC_ASM_H 3 3 #define _ASM_S390_NOSPEC_ASM_H 4 4 5 + #include <linux/linkage.h> 5 6 #include <asm/dwarf.h> 6 7 7 8 #ifdef __ASSEMBLY__ ··· 17 16 .macro __THUNK_PROLOG_NAME name 18 17 #ifdef CONFIG_EXPOLINE_EXTERN 19 18 .pushsection .text,"ax",@progbits 20 - .align 16,0x07 19 + __ALIGN 21 20 #else 22 21 .pushsection .text.\name,"axG",@progbits,\name,comdat 23 22 #endif
-2
arch/s390/include/asm/perf_event.h
··· 60 60 #define PERF_CPUM_SF_DIAG_MODE 0x0002 /* Diagnostic-sampling flag */ 61 61 #define PERF_CPUM_SF_MODE_MASK (PERF_CPUM_SF_BASIC_MODE| \ 62 62 PERF_CPUM_SF_DIAG_MODE) 63 - #define PERF_CPUM_SF_FULL_BLOCKS 0x0004 /* Process full SDBs only */ 64 63 #define PERF_CPUM_SF_FREQ_MODE 0x0008 /* Sampling with frequency */ 65 64 66 65 #define REG_NONE 0 ··· 70 71 #define SAMPL_RATE(hwc) ((hwc)->event_base) 71 72 #define SAMPL_FLAGS(hwc) ((hwc)->config_base) 72 73 #define SAMPL_DIAG_MODE(hwc) (SAMPL_FLAGS(hwc) & PERF_CPUM_SF_DIAG_MODE) 73 - #define SDB_FULL_BLOCKS(hwc) (SAMPL_FLAGS(hwc) & PERF_CPUM_SF_FULL_BLOCKS) 74 74 #define SAMPLE_FREQ_MODE(hwc) (SAMPL_FLAGS(hwc) & PERF_CPUM_SF_FREQ_MODE) 75 75 76 76 #define perf_arch_fetch_caller_regs(regs, __ip) do { \
+1 -1
arch/s390/include/asm/pgtable.h
··· 34 34 PG_DIRECT_MAP_MAX 35 35 }; 36 36 37 - extern atomic_long_t direct_pages_count[PG_DIRECT_MAP_MAX]; 37 + extern atomic_long_t __bootdata_preserved(direct_pages_count[PG_DIRECT_MAP_MAX]); 38 38 39 39 static inline void update_page_count(int level, long count) 40 40 {
+171
arch/s390/include/asm/physmem_info.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _ASM_S390_MEM_DETECT_H 3 + #define _ASM_S390_MEM_DETECT_H 4 + 5 + #include <linux/types.h> 6 + 7 + enum physmem_info_source { 8 + MEM_DETECT_NONE = 0, 9 + MEM_DETECT_SCLP_STOR_INFO, 10 + MEM_DETECT_DIAG260, 11 + MEM_DETECT_SCLP_READ_INFO, 12 + MEM_DETECT_BIN_SEARCH 13 + }; 14 + 15 + struct physmem_range { 16 + u64 start; 17 + u64 end; 18 + }; 19 + 20 + enum reserved_range_type { 21 + RR_DECOMPRESSOR, 22 + RR_INITRD, 23 + RR_VMLINUX, 24 + RR_AMODE31, 25 + RR_IPLREPORT, 26 + RR_CERT_COMP_LIST, 27 + RR_MEM_DETECT_EXTENDED, 28 + RR_VMEM, 29 + RR_MAX 30 + }; 31 + 32 + struct reserved_range { 33 + unsigned long start; 34 + unsigned long end; 35 + struct reserved_range *chain; 36 + }; 37 + 38 + /* 39 + * Storage element id is defined as 1 byte (up to 256 storage elements). 40 + * In practise only storage element id 0 and 1 are used). 41 + * According to architecture one storage element could have as much as 42 + * 1020 subincrements. 255 physmem_ranges are embedded in physmem_info. 43 + * If more physmem_ranges are required, a block of memory from already 44 + * known physmem_range is taken (online_extended points to it). 45 + */ 46 + #define MEM_INLINED_ENTRIES 255 /* (PAGE_SIZE - 16) / 16 */ 47 + 48 + struct physmem_info { 49 + u32 range_count; 50 + u8 info_source; 51 + unsigned long usable; 52 + struct reserved_range reserved[RR_MAX]; 53 + struct physmem_range online[MEM_INLINED_ENTRIES]; 54 + struct physmem_range *online_extended; 55 + }; 56 + 57 + extern struct physmem_info physmem_info; 58 + 59 + void add_physmem_online_range(u64 start, u64 end); 60 + 61 + static inline int __get_physmem_range(u32 n, unsigned long *start, 62 + unsigned long *end, bool respect_usable_limit) 63 + { 64 + if (n >= physmem_info.range_count) { 65 + *start = 0; 66 + *end = 0; 67 + return -1; 68 + } 69 + 70 + if (n < MEM_INLINED_ENTRIES) { 71 + *start = (unsigned long)physmem_info.online[n].start; 72 + *end = (unsigned long)physmem_info.online[n].end; 73 + } else { 74 + *start = (unsigned long)physmem_info.online_extended[n - MEM_INLINED_ENTRIES].start; 75 + *end = (unsigned long)physmem_info.online_extended[n - MEM_INLINED_ENTRIES].end; 76 + } 77 + 78 + if (respect_usable_limit && physmem_info.usable) { 79 + if (*start >= physmem_info.usable) 80 + return -1; 81 + if (*end > physmem_info.usable) 82 + *end = physmem_info.usable; 83 + } 84 + return 0; 85 + } 86 + 87 + /** 88 + * for_each_physmem_usable_range - early online memory range iterator 89 + * @i: an integer used as loop variable 90 + * @p_start: ptr to unsigned long for start address of the range 91 + * @p_end: ptr to unsigned long for end address of the range 92 + * 93 + * Walks over detected online memory ranges below usable limit. 94 + */ 95 + #define for_each_physmem_usable_range(i, p_start, p_end) \ 96 + for (i = 0; !__get_physmem_range(i, p_start, p_end, true); i++) 97 + 98 + /* Walks over all detected online memory ranges disregarding usable limit. */ 99 + #define for_each_physmem_online_range(i, p_start, p_end) \ 100 + for (i = 0; !__get_physmem_range(i, p_start, p_end, false); i++) 101 + 102 + static inline const char *get_physmem_info_source(void) 103 + { 104 + switch (physmem_info.info_source) { 105 + case MEM_DETECT_SCLP_STOR_INFO: 106 + return "sclp storage info"; 107 + case MEM_DETECT_DIAG260: 108 + return "diag260"; 109 + case MEM_DETECT_SCLP_READ_INFO: 110 + return "sclp read info"; 111 + case MEM_DETECT_BIN_SEARCH: 112 + return "binary search"; 113 + } 114 + return "none"; 115 + } 116 + 117 + #define RR_TYPE_NAME(t) case RR_ ## t: return #t 118 + static inline const char *get_rr_type_name(enum reserved_range_type t) 119 + { 120 + switch (t) { 121 + RR_TYPE_NAME(DECOMPRESSOR); 122 + RR_TYPE_NAME(INITRD); 123 + RR_TYPE_NAME(VMLINUX); 124 + RR_TYPE_NAME(AMODE31); 125 + RR_TYPE_NAME(IPLREPORT); 126 + RR_TYPE_NAME(CERT_COMP_LIST); 127 + RR_TYPE_NAME(MEM_DETECT_EXTENDED); 128 + RR_TYPE_NAME(VMEM); 129 + default: 130 + return "UNKNOWN"; 131 + } 132 + } 133 + 134 + #define for_each_physmem_reserved_type_range(t, range, p_start, p_end) \ 135 + for (range = &physmem_info.reserved[t], *p_start = range->start, *p_end = range->end; \ 136 + range && range->end; range = range->chain, \ 137 + *p_start = range ? range->start : 0, *p_end = range ? range->end : 0) 138 + 139 + static inline struct reserved_range *__physmem_reserved_next(enum reserved_range_type *t, 140 + struct reserved_range *range) 141 + { 142 + if (!range) { 143 + range = &physmem_info.reserved[*t]; 144 + if (range->end) 145 + return range; 146 + } 147 + if (range->chain) 148 + return range->chain; 149 + while (++*t < RR_MAX) { 150 + range = &physmem_info.reserved[*t]; 151 + if (range->end) 152 + return range; 153 + } 154 + return NULL; 155 + } 156 + 157 + #define for_each_physmem_reserved_range(t, range, p_start, p_end) \ 158 + for (t = 0, range = __physmem_reserved_next(&t, NULL), \ 159 + *p_start = range ? range->start : 0, *p_end = range ? range->end : 0; \ 160 + range; range = __physmem_reserved_next(&t, range), \ 161 + *p_start = range ? range->start : 0, *p_end = range ? range->end : 0) 162 + 163 + static inline unsigned long get_physmem_reserved(enum reserved_range_type type, 164 + unsigned long *addr, unsigned long *size) 165 + { 166 + *addr = physmem_info.reserved[type].start; 167 + *size = physmem_info.reserved[type].end - physmem_info.reserved[type].start; 168 + return *size; 169 + } 170 + 171 + #endif
+42 -4
arch/s390/include/asm/processor.h
··· 99 99 100 100 extern const struct seq_operations cpuinfo_op; 101 101 extern void execve_tail(void); 102 - extern void __bpon(void); 103 102 unsigned long vdso_size(void); 104 103 105 104 /* ··· 117 118 #define STACK_TOP_MAX (_REGION2_SIZE - vdso_size() - PAGE_SIZE) 118 119 119 120 #define HAVE_ARCH_PICK_MMAP_LAYOUT 121 + 122 + #define __stackleak_poison __stackleak_poison 123 + static __always_inline void __stackleak_poison(unsigned long erase_low, 124 + unsigned long erase_high, 125 + unsigned long poison) 126 + { 127 + unsigned long tmp, count; 128 + 129 + count = erase_high - erase_low; 130 + if (!count) 131 + return; 132 + asm volatile( 133 + " cghi %[count],8\n" 134 + " je 2f\n" 135 + " aghi %[count],-(8+1)\n" 136 + " srlg %[tmp],%[count],8\n" 137 + " ltgr %[tmp],%[tmp]\n" 138 + " jz 1f\n" 139 + "0: stg %[poison],0(%[addr])\n" 140 + " mvc 8(256-8,%[addr]),0(%[addr])\n" 141 + " la %[addr],256(%[addr])\n" 142 + " brctg %[tmp],0b\n" 143 + "1: stg %[poison],0(%[addr])\n" 144 + " larl %[tmp],3f\n" 145 + " ex %[count],0(%[tmp])\n" 146 + " j 4f\n" 147 + "2: stg %[poison],0(%[addr])\n" 148 + " j 4f\n" 149 + "3: mvc 8(1,%[addr]),0(%[addr])\n" 150 + "4:\n" 151 + : [addr] "+&a" (erase_low), [count] "+&d" (count), [tmp] "=&a" (tmp) 152 + : [poison] "d" (poison) 153 + : "memory", "cc" 154 + ); 155 + } 120 156 121 157 /* 122 158 * Thread structure ··· 261 227 return sp; 262 228 } 263 229 230 + static __always_inline bool on_thread_stack(void) 231 + { 232 + unsigned long ksp = S390_lowcore.kernel_stack; 233 + 234 + return !((ksp ^ current_stack_pointer) & ~(THREAD_SIZE - 1)); 235 + } 236 + 264 237 static __always_inline unsigned short stap(void) 265 238 { 266 239 unsigned short cpu_address; ··· 369 328 } 370 329 371 330 #define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL 372 - 373 - extern int s390_isolate_bp(void); 374 - extern int s390_isolate_bp_guest(void); 375 331 376 332 static __always_inline bool regs_irqs_disabled(struct pt_regs *regs) 377 333 {
+31 -5
arch/s390/include/asm/set_memory.h
··· 6 6 7 7 extern struct mutex cpa_mutex; 8 8 9 - #define SET_MEMORY_RO 1UL 10 - #define SET_MEMORY_RW 2UL 11 - #define SET_MEMORY_NX 4UL 12 - #define SET_MEMORY_X 8UL 13 - #define SET_MEMORY_4K 16UL 9 + enum { 10 + _SET_MEMORY_RO_BIT, 11 + _SET_MEMORY_RW_BIT, 12 + _SET_MEMORY_NX_BIT, 13 + _SET_MEMORY_X_BIT, 14 + _SET_MEMORY_4K_BIT, 15 + _SET_MEMORY_INV_BIT, 16 + _SET_MEMORY_DEF_BIT, 17 + }; 18 + 19 + #define SET_MEMORY_RO BIT(_SET_MEMORY_RO_BIT) 20 + #define SET_MEMORY_RW BIT(_SET_MEMORY_RW_BIT) 21 + #define SET_MEMORY_NX BIT(_SET_MEMORY_NX_BIT) 22 + #define SET_MEMORY_X BIT(_SET_MEMORY_X_BIT) 23 + #define SET_MEMORY_4K BIT(_SET_MEMORY_4K_BIT) 24 + #define SET_MEMORY_INV BIT(_SET_MEMORY_INV_BIT) 25 + #define SET_MEMORY_DEF BIT(_SET_MEMORY_DEF_BIT) 14 26 15 27 int __set_memory(unsigned long addr, int numpages, unsigned long flags); 16 28 ··· 46 34 return __set_memory(addr, numpages, SET_MEMORY_X); 47 35 } 48 36 37 + #define set_memory_rox set_memory_rox 38 + static inline int set_memory_rox(unsigned long addr, int numpages) 39 + { 40 + return __set_memory(addr, numpages, SET_MEMORY_RO | SET_MEMORY_X); 41 + } 42 + 43 + static inline int set_memory_rwnx(unsigned long addr, int numpages) 44 + { 45 + return __set_memory(addr, numpages, SET_MEMORY_RW | SET_MEMORY_NX); 46 + } 47 + 49 48 static inline int set_memory_4k(unsigned long addr, int numpages) 50 49 { 51 50 return __set_memory(addr, numpages, SET_MEMORY_4K); 52 51 } 52 + 53 + int set_direct_map_invalid_noflush(struct page *page); 54 + int set_direct_map_default_noflush(struct page *page); 53 55 54 56 #endif
+8 -12
arch/s390/include/asm/setup.h
··· 74 74 75 75 extern int noexec_disabled; 76 76 extern unsigned long ident_map_size; 77 - extern unsigned long pgalloc_pos; 78 - extern unsigned long pgalloc_end; 79 - extern unsigned long pgalloc_low; 80 - extern unsigned long __amode31_base; 81 77 82 78 /* The Write Back bit position in the physaddr is given by the SLPC PCI */ 83 79 extern unsigned long mio_wb_bit_mask; ··· 146 150 return __kaslr_offset; 147 151 } 148 152 149 - extern int is_full_image; 150 - 151 - struct initrd_data { 152 - unsigned long start; 153 - unsigned long size; 154 - }; 155 - extern struct initrd_data initrd_data; 153 + extern int __kaslr_enabled; 154 + static inline int kaslr_enabled(void) 155 + { 156 + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) 157 + return __kaslr_enabled; 158 + return 0; 159 + } 156 160 157 161 struct oldmem_data { 158 162 unsigned long start; ··· 160 164 }; 161 165 extern struct oldmem_data oldmem_data; 162 166 163 - static inline u32 gen_lpswe(unsigned long addr) 167 + static __always_inline u32 gen_lpswe(unsigned long addr) 164 168 { 165 169 BUILD_BUG_ON(addr > 0xfff); 166 170 return 0xb2b20000 | addr;
+44 -8
arch/s390/include/asm/stacktrace.h
··· 189 189 (rettype)r2; \ 190 190 }) 191 191 192 - #define call_on_stack_noreturn(fn, stack) \ 192 + /* 193 + * Use call_nodat() to call a function with DAT disabled. 194 + * Proper sign and zero extension of function arguments is done. 195 + * Usage: 196 + * 197 + * rc = call_nodat(nr, rettype, fn, t1, a1, t2, a2, ...) 198 + * 199 + * - nr specifies the number of function arguments of fn. 200 + * - fn is the function to be called, where fn is a physical address. 201 + * - rettype is the return type of fn. 202 + * - t1, a1, ... are pairs, where t1 must match the type of the first 203 + * argument of fn, t2 the second, etc. a1 is the corresponding 204 + * first function argument (not name), etc. 205 + * 206 + * fn() is called with standard C function call ABI, with the exception 207 + * that no useful stackframe or stackpointer is passed via register 15. 208 + * Therefore the called function must not use r15 to access the stack. 209 + */ 210 + #define call_nodat(nr, rettype, fn, ...) \ 193 211 ({ \ 194 - void (*__fn)(void) = fn; \ 212 + rettype (*__fn)(CALL_PARM_##nr(__VA_ARGS__)) = (fn); \ 213 + /* aligned since psw_leave must not cross page boundary */ \ 214 + psw_t __aligned(16) psw_leave; \ 215 + psw_t psw_enter; \ 216 + CALL_LARGS_##nr(__VA_ARGS__); \ 217 + CALL_REGS_##nr; \ 195 218 \ 219 + CALL_TYPECHECK_##nr(__VA_ARGS__); \ 220 + psw_enter.mask = PSW_KERNEL_BITS & ~PSW_MASK_DAT; \ 221 + psw_enter.addr = (unsigned long)__fn; \ 196 222 asm volatile( \ 197 - " la 15,0(%[_stack])\n" \ 198 - " xc %[_bc](8,15),%[_bc](15)\n" \ 199 - " brasl 14,%[_fn]\n" \ 200 - ::[_bc] "i" (offsetof(struct stack_frame, back_chain)), \ 201 - [_stack] "a" (stack), [_fn] "X" (__fn)); \ 202 - BUG(); \ 223 + " epsw 0,1\n" \ 224 + " risbg 1,0,0,31,32\n" \ 225 + " larl 7,1f\n" \ 226 + " stg 1,%[psw_leave]\n" \ 227 + " stg 7,8+%[psw_leave]\n" \ 228 + " la 7,%[psw_leave]\n" \ 229 + " lra 7,0(7)\n" \ 230 + " larl 1,0f\n" \ 231 + " lra 14,0(1)\n" \ 232 + " lpswe %[psw_enter]\n" \ 233 + "0: lpswe 0(7)\n" \ 234 + "1:\n" \ 235 + : CALL_FMT_##nr, [psw_leave] "=Q" (psw_leave) \ 236 + : [psw_enter] "Q" (psw_enter) \ 237 + : "7", CALL_CLOBBER_##nr); \ 238 + (rettype)r2; \ 203 239 }) 204 240 205 241 #endif /* _ASM_S390_STACKTRACE_H */
+3 -12
arch/s390/include/asm/string.h
··· 55 55 56 56 #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) 57 57 58 - extern void *__memcpy(void *dest, const void *src, size_t n); 59 - extern void *__memset(void *s, int c, size_t n); 60 - extern void *__memmove(void *dest, const void *src, size_t n); 61 - 62 - /* 63 - * For files that are not instrumented (e.g. mm/slub.c) we 64 - * should use not instrumented version of mem* functions. 65 - */ 66 - 67 - #define memcpy(dst, src, len) __memcpy(dst, src, len) 68 - #define memmove(dst, src, len) __memmove(dst, src, len) 69 - #define memset(s, c, n) __memset(s, c, n) 70 58 #define strlen(s) __strlen(s) 71 59 72 60 #define __no_sanitize_prefix_strfunc(x) __##x ··· 67 79 #define __no_sanitize_prefix_strfunc(x) x 68 80 #endif /* defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) */ 69 81 82 + void *__memcpy(void *dest, const void *src, size_t n); 83 + void *__memset(void *s, int c, size_t n); 84 + void *__memmove(void *dest, const void *src, size_t n); 70 85 void *__memset16(uint16_t *s, uint16_t v, size_t count); 71 86 void *__memset32(uint32_t *s, uint32_t v, size_t count); 72 87 void *__memset64(uint64_t *s, uint64_t v, size_t count);
+5 -5
arch/s390/include/asm/thread_info.h
··· 9 9 #define _ASM_THREAD_INFO_H 10 10 11 11 #include <linux/bits.h> 12 + #ifndef ASM_OFFSETS_C 13 + #include <asm/asm-offsets.h> 14 + #endif 12 15 13 16 /* 14 17 * General size of kernel stacks ··· 24 21 #define BOOT_STACK_SIZE (PAGE_SIZE << 2) 25 22 #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) 26 23 24 + #define STACK_INIT_OFFSET (THREAD_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE) 25 + 27 26 #ifndef __ASSEMBLY__ 28 27 #include <asm/lowcore.h> 29 28 #include <asm/page.h> 30 - 31 - #define STACK_INIT_OFFSET \ 32 - (THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs)) 33 29 34 30 /* 35 31 * low level task data that entry.S needs immediate access to ··· 72 70 #define TIF_PATCH_PENDING 5 /* pending live patching update */ 73 71 #define TIF_PGSTE 6 /* New mm's will use 4K page tables */ 74 72 #define TIF_NOTIFY_SIGNAL 7 /* signal notifications exist */ 75 - #define TIF_ISOLATE_BP 8 /* Run process with isolated BP */ 76 73 #define TIF_ISOLATE_BP_GUEST 9 /* Run KVM guests with isolated BP */ 77 74 #define TIF_PER_TRAP 10 /* Need to handle PER trap on exit to usermode */ 78 75 ··· 95 94 #define _TIF_UPROBE BIT(TIF_UPROBE) 96 95 #define _TIF_GUARDED_STORAGE BIT(TIF_GUARDED_STORAGE) 97 96 #define _TIF_PATCH_PENDING BIT(TIF_PATCH_PENDING) 98 - #define _TIF_ISOLATE_BP BIT(TIF_ISOLATE_BP) 99 97 #define _TIF_ISOLATE_BP_GUEST BIT(TIF_ISOLATE_BP_GUEST) 100 98 #define _TIF_PER_TRAP BIT(TIF_PER_TRAP) 101 99
+2 -12
arch/s390/kernel/debug.c
··· 60 60 * except of floats, and long long (32 bit) 61 61 * 62 62 */ 63 - long args[0]; 63 + long args[]; 64 64 } debug_sprintf_entry_t; 65 65 66 66 /* internal function prototyes */ ··· 981 981 { } 982 982 }; 983 983 984 - static struct ctl_table s390dbf_dir_table[] = { 985 - { 986 - .procname = "s390dbf", 987 - .maxlen = 0, 988 - .mode = S_IRUGO | S_IXUGO, 989 - .child = s390dbf_table, 990 - }, 991 - { } 992 - }; 993 - 994 984 static struct ctl_table_header *s390dbf_sysctl_header; 995 985 996 986 /** ··· 1564 1574 */ 1565 1575 static int __init debug_init(void) 1566 1576 { 1567 - s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table); 1577 + s390dbf_sysctl_header = register_sysctl("s390dbf", s390dbf_table); 1568 1578 mutex_lock(&debug_mutex); 1569 1579 debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT, NULL); 1570 1580 initialized = 1;
+21 -25
arch/s390/kernel/dumpstack.c
··· 41 41 EXPORT_SYMBOL_GPL(stack_type_name); 42 42 43 43 static inline bool in_stack(unsigned long sp, struct stack_info *info, 44 - enum stack_type type, unsigned long low, 45 - unsigned long high) 44 + enum stack_type type, unsigned long stack) 46 45 { 47 - if (sp < low || sp >= high) 46 + if (sp < stack || sp >= stack + THREAD_SIZE) 48 47 return false; 49 48 info->type = type; 50 - info->begin = low; 51 - info->end = high; 49 + info->begin = stack; 50 + info->end = stack + THREAD_SIZE; 52 51 return true; 53 52 } 54 53 55 54 static bool in_task_stack(unsigned long sp, struct task_struct *task, 56 55 struct stack_info *info) 57 56 { 58 - unsigned long stack; 57 + unsigned long stack = (unsigned long)task_stack_page(task); 59 58 60 - stack = (unsigned long) task_stack_page(task); 61 - return in_stack(sp, info, STACK_TYPE_TASK, stack, stack + THREAD_SIZE); 59 + return in_stack(sp, info, STACK_TYPE_TASK, stack); 62 60 } 63 61 64 62 static bool in_irq_stack(unsigned long sp, struct stack_info *info) 65 63 { 66 - unsigned long frame_size, top; 64 + unsigned long stack = S390_lowcore.async_stack - STACK_INIT_OFFSET; 67 65 68 - frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs); 69 - top = S390_lowcore.async_stack + frame_size; 70 - return in_stack(sp, info, STACK_TYPE_IRQ, top - THREAD_SIZE, top); 66 + return in_stack(sp, info, STACK_TYPE_IRQ, stack); 71 67 } 72 68 73 69 static bool in_nodat_stack(unsigned long sp, struct stack_info *info) 74 70 { 75 - unsigned long frame_size, top; 71 + unsigned long stack = S390_lowcore.nodat_stack - STACK_INIT_OFFSET; 76 72 77 - frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs); 78 - top = S390_lowcore.nodat_stack + frame_size; 79 - return in_stack(sp, info, STACK_TYPE_NODAT, top - THREAD_SIZE, top); 73 + return in_stack(sp, info, STACK_TYPE_NODAT, stack); 80 74 } 81 75 82 76 static bool in_mcck_stack(unsigned long sp, struct stack_info *info) 83 77 { 84 - unsigned long frame_size, top; 78 + unsigned long stack = S390_lowcore.mcck_stack - STACK_INIT_OFFSET; 85 79 86 - frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs); 87 - top = S390_lowcore.mcck_stack + frame_size; 88 - return in_stack(sp, info, STACK_TYPE_MCCK, top - THREAD_SIZE, top); 80 + return in_stack(sp, info, STACK_TYPE_MCCK, stack); 89 81 } 90 82 91 83 static bool in_restart_stack(unsigned long sp, struct stack_info *info) 92 84 { 93 - unsigned long frame_size, top; 85 + unsigned long stack = S390_lowcore.restart_stack - STACK_INIT_OFFSET; 94 86 95 - frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs); 96 - top = S390_lowcore.restart_stack + frame_size; 97 - return in_stack(sp, info, STACK_TYPE_RESTART, top - THREAD_SIZE, top); 87 + return in_stack(sp, info, STACK_TYPE_RESTART, stack); 98 88 } 99 89 100 90 int get_stack_info(unsigned long sp, struct task_struct *task, ··· 142 152 static void show_last_breaking_event(struct pt_regs *regs) 143 153 { 144 154 printk("Last Breaking-Event-Address:\n"); 145 - printk(" [<%016lx>] %pSR\n", regs->last_break, (void *)regs->last_break); 155 + printk(" [<%016lx>] ", regs->last_break); 156 + if (user_mode(regs)) { 157 + print_vma_addr(KERN_CONT, regs->last_break); 158 + pr_cont("\n"); 159 + } else { 160 + pr_cont("%pSR\n", (void *)regs->last_break); 161 + } 146 162 } 147 163 148 164 void show_registers(struct pt_regs *regs)
+9 -14
arch/s390/kernel/early.c
··· 34 34 #include <asm/switch_to.h> 35 35 #include "entry.h" 36 36 37 - int __bootdata(is_full_image); 38 - 39 37 #define decompressor_handled_param(param) \ 40 38 static int __init ignore_decompressor_param_##param(char *s) \ 41 39 { \ ··· 50 52 #if IS_ENABLED(CONFIG_KVM) 51 53 decompressor_handled_param(prot_virt); 52 54 #endif 55 + 56 + static void __init kasan_early_init(void) 57 + { 58 + #ifdef CONFIG_KASAN 59 + init_task.kasan_depth = 0; 60 + sclp_early_printk("KernelAddressSanitizer initialized\n"); 61 + #endif 62 + } 53 63 54 64 static void __init reset_tod_clock(void) 55 65 { ··· 294 288 strscpy(boot_command_line, early_command_line, COMMAND_LINE_SIZE); 295 289 } 296 290 297 - static void __init check_image_bootable(void) 298 - { 299 - if (is_full_image) 300 - return; 301 - 302 - sclp_early_printk("Linux kernel boot failure: An attempt to boot a vmlinux ELF image failed.\n"); 303 - sclp_early_printk("This image does not contain all parts necessary for starting up. Use\n"); 304 - sclp_early_printk("bzImage or arch/s390/boot/compressed/vmlinux instead.\n"); 305 - disabled_wait(); 306 - } 307 - 308 291 static void __init sort_amode31_extable(void) 309 292 { 310 293 sort_extable(__start_amode31_ex_table, __stop_amode31_ex_table); ··· 301 306 302 307 void __init startup_init(void) 303 308 { 309 + kasan_early_init(); 304 310 reset_tod_clock(); 305 - check_image_bootable(); 306 311 time_early_init(); 307 312 init_kernel_storage_key(); 308 313 lockdep_off();
+2 -2
arch/s390/kernel/earlypgm.S
··· 7 7 #include <linux/linkage.h> 8 8 #include <asm/asm-offsets.h> 9 9 10 - ENTRY(early_pgm_check_handler) 10 + SYM_CODE_START(early_pgm_check_handler) 11 11 stmg %r8,%r15,__LC_SAVE_AREA_SYNC 12 12 aghi %r15,-(STACK_FRAME_OVERHEAD+__PT_SIZE) 13 13 la %r11,STACK_FRAME_OVERHEAD(%r15) ··· 20 20 mvc __LC_RETURN_PSW(16),STACK_FRAME_OVERHEAD+__PT_PSW(%r15) 21 21 lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15) 22 22 lpswe __LC_RETURN_PSW 23 - ENDPROC(early_pgm_check_handler) 23 + SYM_CODE_END(early_pgm_check_handler)
+70 -82
arch/s390/kernel/entry.S
··· 29 29 #include <asm/export.h> 30 30 #include <asm/nospec-insn.h> 31 31 32 - STACK_SHIFT = PAGE_SHIFT + THREAD_SIZE_ORDER 33 - STACK_SIZE = 1 << STACK_SHIFT 34 - STACK_INIT = STACK_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE 35 - 36 32 _LPP_OFFSET = __LC_LPP 37 33 38 34 .macro STBEAR address ··· 49 53 50 54 .macro CHECK_STACK savearea 51 55 #ifdef CONFIG_CHECK_STACK 52 - tml %r15,STACK_SIZE - CONFIG_STACK_GUARD 56 + tml %r15,THREAD_SIZE - CONFIG_STACK_GUARD 53 57 lghi %r14,\savearea 54 58 jz stack_overflow 55 59 #endif ··· 58 62 .macro CHECK_VMAP_STACK savearea,oklabel 59 63 #ifdef CONFIG_VMAP_STACK 60 64 lgr %r14,%r15 61 - nill %r14,0x10000 - STACK_SIZE 62 - oill %r14,STACK_INIT 65 + nill %r14,0x10000 - THREAD_SIZE 66 + oill %r14,STACK_INIT_OFFSET 63 67 clg %r14,__LC_KERNEL_STACK 64 68 je \oklabel 65 69 clg %r14,__LC_ASYNC_STACK ··· 150 154 .endm 151 155 #endif 152 156 157 + .macro STACKLEAK_ERASE 158 + #ifdef CONFIG_GCC_PLUGIN_STACKLEAK 159 + brasl %r14,stackleak_erase_on_task_stack 160 + #endif 161 + .endm 162 + 153 163 GEN_BR_THUNK %r14 154 164 155 165 .section .kprobes.text, "ax" 156 166 .Ldummy: 157 167 /* 158 - * This nop exists only in order to avoid that __bpon starts at 159 - * the beginning of the kprobes text section. In that case we would 160 - * have several symbols at the same address. E.g. objdump would take 161 - * an arbitrary symbol name when disassembling this code. 162 - * With the added nop in between the __bpon symbol is unique 163 - * again. 168 + * The following nop exists only in order to avoid that the next 169 + * symbol starts at the beginning of the kprobes text section. 170 + * In that case there would be several symbols at the same address. 171 + * E.g. objdump would take an arbitrary symbol when disassembling 172 + * the code. 173 + * With the added nop in between this cannot happen. 164 174 */ 165 175 nop 0 166 - 167 - ENTRY(__bpon) 168 - .globl __bpon 169 - BPON 170 - BR_EX %r14 171 - ENDPROC(__bpon) 172 176 173 177 /* 174 178 * Scheduler resume function, called by switch_to ··· 177 181 * Returns: 178 182 * gpr2 = prev 179 183 */ 180 - ENTRY(__switch_to) 184 + SYM_FUNC_START(__switch_to) 181 185 stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task 182 186 lghi %r4,__TASK_stack 183 187 lghi %r1,__TASK_thread 184 - llill %r5,STACK_INIT 188 + llill %r5,STACK_INIT_OFFSET 185 189 stg %r15,__THREAD_ksp(%r1,%r2) # store kernel stack of prev 186 190 lg %r15,0(%r4,%r3) # start of kernel stack of next 187 191 agr %r15,%r5 # end of kernel stack of next ··· 193 197 lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task 194 198 ALTERNATIVE "nop", "lpp _LPP_OFFSET", 40 195 199 BR_EX %r14 196 - ENDPROC(__switch_to) 200 + SYM_FUNC_END(__switch_to) 197 201 198 202 #if IS_ENABLED(CONFIG_KVM) 199 203 /* ··· 202 206 * %r3 pointer to sie control block virt 203 207 * %r4 guest register save area 204 208 */ 205 - ENTRY(__sie64a) 209 + SYM_FUNC_START(__sie64a) 206 210 stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers 207 211 lg %r12,__LC_CURRENT 208 212 stg %r2,__SF_SIE_CONTROL_PHYS(%r15) # save sie block physical.. ··· 223 227 TSTMSK __LC_CPU_FLAGS,_CIF_FPU 224 228 jo .Lsie_skip # exit if fp/vx regs changed 225 229 lg %r14,__SF_SIE_CONTROL_PHYS(%r15) # get sie block phys addr 226 - BPEXIT __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST) 230 + BPEXIT __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST 227 231 .Lsie_entry: 228 232 sie 0(%r14) 229 233 # Let the next instruction be NOP to avoid triggering a machine check ··· 231 235 nopr 7 232 236 .Lsie_leave: 233 237 BPOFF 234 - BPENTER __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST) 238 + BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST 235 239 .Lsie_skip: 236 240 lg %r14,__SF_SIE_CONTROL(%r15) # get control block pointer 237 241 ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE ··· 248 252 nopr 7 249 253 .Lrewind_pad2: 250 254 nopr 7 251 - .globl sie_exit 252 - sie_exit: 255 + SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL) 253 256 lg %r14,__SF_SIE_SAVEAREA(%r15) # load guest register save area 254 257 stmg %r0,%r13,0(%r14) # save guest gprs 0-13 255 258 xgr %r0,%r0 # clear guest registers to ··· 268 273 EX_TABLE(.Lrewind_pad4,.Lsie_fault) 269 274 EX_TABLE(.Lrewind_pad2,.Lsie_fault) 270 275 EX_TABLE(sie_exit,.Lsie_fault) 271 - ENDPROC(__sie64a) 276 + SYM_FUNC_END(__sie64a) 272 277 EXPORT_SYMBOL(__sie64a) 273 278 EXPORT_SYMBOL(sie_exit) 274 279 #endif ··· 278 283 * are entered with interrupts disabled. 279 284 */ 280 285 281 - ENTRY(system_call) 286 + SYM_CODE_START(system_call) 282 287 stpt __LC_SYS_ENTER_TIMER 283 288 stmg %r8,%r15,__LC_SAVE_AREA_SYNC 284 289 BPOFF ··· 286 291 .Lsysc_per: 287 292 STBEAR __LC_LAST_BREAK 288 293 lctlg %c1,%c1,__LC_KERNEL_ASCE 289 - lg %r12,__LC_CURRENT 290 294 lg %r15,__LC_KERNEL_STACK 291 295 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) 292 296 stmg %r0,%r7,STACK_FRAME_OVERHEAD+__PT_R0(%r15) 293 - BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP 294 297 # clear user controlled register to prevent speculative use 295 298 xgr %r0,%r0 296 299 xgr %r1,%r1 ··· 305 312 MBEAR %r2 306 313 lgr %r3,%r14 307 314 brasl %r14,__do_syscall 315 + STACKLEAK_ERASE 308 316 lctlg %c1,%c1,__LC_USER_ASCE 309 317 mvc __LC_RETURN_PSW(16),STACK_FRAME_OVERHEAD+__PT_PSW(%r15) 310 - BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP 318 + BPON 311 319 LBEAR STACK_FRAME_OVERHEAD+__PT_LAST_BREAK(%r15) 312 320 lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15) 313 321 stpt __LC_EXIT_TIMER 314 322 LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE 315 - ENDPROC(system_call) 323 + SYM_CODE_END(system_call) 316 324 317 325 # 318 326 # a new process exits the kernel with ret_from_fork 319 327 # 320 - ENTRY(ret_from_fork) 328 + SYM_CODE_START(ret_from_fork) 321 329 lgr %r3,%r11 322 330 brasl %r14,__ret_from_fork 331 + STACKLEAK_ERASE 323 332 lctlg %c1,%c1,__LC_USER_ASCE 324 333 mvc __LC_RETURN_PSW(16),STACK_FRAME_OVERHEAD+__PT_PSW(%r15) 325 - BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP 334 + BPON 326 335 LBEAR STACK_FRAME_OVERHEAD+__PT_LAST_BREAK(%r15) 327 336 lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15) 328 337 stpt __LC_EXIT_TIMER 329 338 LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE 330 - ENDPROC(ret_from_fork) 339 + SYM_CODE_END(ret_from_fork) 331 340 332 341 /* 333 342 * Program check handler routine 334 343 */ 335 344 336 - ENTRY(pgm_check_handler) 345 + SYM_CODE_START(pgm_check_handler) 337 346 stpt __LC_SYS_ENTER_TIMER 338 347 BPOFF 339 348 stmg %r8,%r15,__LC_SAVE_AREA_SYNC 340 - lg %r12,__LC_CURRENT 341 349 lghi %r10,0 342 350 lmg %r8,%r9,__LC_PGM_OLD_PSW 343 351 tmhh %r8,0x0001 # coming from user space? ··· 349 355 #if IS_ENABLED(CONFIG_KVM) 350 356 # cleanup critical section for program checks in __sie64a 351 357 OUTSIDE %r9,.Lsie_gmap,.Lsie_done,1f 358 + BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST 352 359 SIEEXIT 353 360 lghi %r10,_PIF_GUEST_FAULT 354 361 #endif ··· 361 366 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE) 362 367 # CHECK_VMAP_STACK branches to stack_overflow or 4f 363 368 CHECK_VMAP_STACK __LC_SAVE_AREA_SYNC,4f 364 - 3: BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP 365 - lg %r15,__LC_KERNEL_STACK 369 + 3: lg %r15,__LC_KERNEL_STACK 366 370 4: la %r11,STACK_FRAME_OVERHEAD(%r15) 367 371 stg %r10,__PT_FLAGS(%r11) 368 372 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) ··· 382 388 brasl %r14,__do_pgm_check 383 389 tmhh %r8,0x0001 # returning to user space? 384 390 jno .Lpgm_exit_kernel 391 + STACKLEAK_ERASE 385 392 lctlg %c1,%c1,__LC_USER_ASCE 386 - BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP 393 + BPON 387 394 stpt __LC_EXIT_TIMER 388 395 .Lpgm_exit_kernel: 389 396 mvc __LC_RETURN_PSW(16),STACK_FRAME_OVERHEAD+__PT_PSW(%r15) ··· 402 407 lghi %r14,1 403 408 LBEAR __LC_PGM_LAST_BREAK 404 409 LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE # branch to .Lsysc_per 405 - ENDPROC(pgm_check_handler) 410 + SYM_CODE_END(pgm_check_handler) 406 411 407 412 /* 408 413 * Interrupt handler macro used for external and IO interrupts. 409 414 */ 410 415 .macro INT_HANDLER name,lc_old_psw,handler 411 - ENTRY(\name) 416 + SYM_CODE_START(\name) 412 417 stckf __LC_INT_CLOCK 413 418 stpt __LC_SYS_ENTER_TIMER 414 419 STBEAR __LC_LAST_BREAK 415 420 BPOFF 416 421 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC 417 - lg %r12,__LC_CURRENT 418 422 lmg %r8,%r9,\lc_old_psw 419 423 tmhh %r8,0x0001 # interrupting from user ? 420 424 jnz 1f 421 425 #if IS_ENABLED(CONFIG_KVM) 422 426 OUTSIDE %r9,.Lsie_gmap,.Lsie_done,0f 423 - BPENTER __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST) 427 + BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST 424 428 SIEEXIT 425 429 #endif 426 430 0: CHECK_STACK __LC_SAVE_AREA_ASYNC 427 431 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE) 428 432 j 2f 429 - 1: BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP 430 - lctlg %c1,%c1,__LC_KERNEL_ASCE 433 + 1: lctlg %c1,%c1,__LC_KERNEL_ASCE 431 434 lg %r15,__LC_KERNEL_STACK 432 435 2: xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) 433 436 la %r11,STACK_FRAME_OVERHEAD(%r15) ··· 448 455 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11) 449 456 tmhh %r8,0x0001 # returning to user ? 450 457 jno 2f 458 + STACKLEAK_ERASE 451 459 lctlg %c1,%c1,__LC_USER_ASCE 452 - BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP 460 + BPON 453 461 stpt __LC_EXIT_TIMER 454 462 2: LBEAR __PT_LAST_BREAK(%r11) 455 463 lmg %r0,%r15,__PT_R0(%r11) 456 464 LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE 457 - ENDPROC(\name) 465 + SYM_CODE_END(\name) 458 466 .endm 459 467 460 468 INT_HANDLER ext_int_handler,__LC_EXT_OLD_PSW,do_ext_irq ··· 464 470 /* 465 471 * Load idle PSW. 466 472 */ 467 - ENTRY(psw_idle) 473 + SYM_FUNC_START(psw_idle) 468 474 stg %r14,(__SF_GPRS+8*8)(%r15) 469 475 stg %r3,__SF_EMPTY(%r15) 470 476 larl %r1,psw_idle_exit ··· 480 486 stckf __CLOCK_IDLE_ENTER(%r2) 481 487 stpt __TIMER_IDLE_ENTER(%r2) 482 488 lpswe __SF_EMPTY(%r15) 483 - .globl psw_idle_exit 484 - psw_idle_exit: 489 + SYM_INNER_LABEL(psw_idle_exit, SYM_L_GLOBAL) 485 490 BR_EX %r14 486 - ENDPROC(psw_idle) 491 + SYM_FUNC_END(psw_idle) 487 492 488 493 /* 489 494 * Machine check handler routines 490 495 */ 491 - ENTRY(mcck_int_handler) 496 + SYM_CODE_START(mcck_int_handler) 492 497 stckf __LC_MCCK_CLOCK 493 498 BPOFF 494 499 la %r1,4095 # validate r1 495 500 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # validate cpu timer 496 501 LBEAR __LC_LAST_BREAK_SAVE_AREA-4095(%r1) # validate bear 497 - lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# validate gprs 498 - lg %r12,__LC_CURRENT 502 + lmg %r0,%r15,__LC_GPREGS_SAVE_AREA # validate gprs 499 503 lmg %r8,%r9,__LC_MCK_OLD_PSW 500 504 TSTMSK __LC_MCCK_CODE,MCCK_CODE_SYSTEM_DAMAGE 501 505 jo .Lmcck_panic # yes -> rest of mcck code invalid 502 506 TSTMSK __LC_MCCK_CODE,MCCK_CODE_CR_VALID 503 507 jno .Lmcck_panic # control registers invalid -> panic 504 - la %r14,4095 505 - lctlg %c0,%c15,__LC_CREGS_SAVE_AREA-4095(%r14) # validate ctl regs 508 + lctlg %c0,%c15,__LC_CREGS_SAVE_AREA # validate ctl regs 506 509 ptlb 507 510 lghi %r14,__LC_CPU_TIMER_SAVE_AREA 508 511 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14) ··· 521 530 TSTMSK __LC_MCCK_CODE,MCCK_CODE_PSW_IA_VALID 522 531 jno .Lmcck_panic 523 532 #if IS_ENABLED(CONFIG_KVM) 524 - OUTSIDE %r9,.Lsie_gmap,.Lsie_done,.Lmcck_stack 533 + OUTSIDE %r9,.Lsie_gmap,.Lsie_done,.Lmcck_user 525 534 OUTSIDE %r9,.Lsie_entry,.Lsie_leave,4f 526 535 oi __LC_CPU_FLAGS+7, _CIF_MCCK_GUEST 527 - 4: BPENTER __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST) 536 + 4: BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST 528 537 SIEEXIT 529 - j .Lmcck_stack 530 538 #endif 531 539 .Lmcck_user: 532 - BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP 533 - .Lmcck_stack: 534 540 lg %r15,__LC_MCCK_STACK 535 541 la %r11,STACK_FRAME_OVERHEAD(%r15) 536 542 stctg %c1,%c1,__PT_CR1(%r11) ··· 555 567 mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW 556 568 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ? 557 569 jno 0f 558 - BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP 570 + BPON 559 571 stpt __LC_EXIT_TIMER 560 572 0: ALTERNATIVE "nop", __stringify(lghi %r12,__LC_LAST_BREAK_SAVE_AREA),193 561 573 LBEAR 0(%r12) ··· 571 583 */ 572 584 lhi %r5,0 573 585 lhi %r6,1 574 - larl %r7,.Lstop_lock 586 + larl %r7,stop_lock 575 587 cs %r5,%r6,0(%r7) # single CPU-stopper only 576 588 jnz 4f 577 - larl %r7,.Lthis_cpu 589 + larl %r7,this_cpu 578 590 stap 0(%r7) # this CPU address 579 591 lh %r4,0(%r7) 580 592 nilh %r4,0 ··· 590 602 3: sigp %r1,%r4,SIGP_STOP # stop this CPU 591 603 brc SIGP_CC_BUSY,3b 592 604 4: j 4b 593 - ENDPROC(mcck_int_handler) 605 + SYM_CODE_END(mcck_int_handler) 594 606 595 - ENTRY(restart_int_handler) 607 + SYM_CODE_START(restart_int_handler) 596 608 ALTERNATIVE "nop", "lpp _LPP_OFFSET", 40 597 609 stg %r15,__LC_SAVE_AREA_RESTART 598 610 TSTMSK __LC_RESTART_FLAGS,RESTART_FLAG_CTLREGS,4 599 611 jz 0f 600 - la %r15,4095 601 - lctlg %c0,%c15,__LC_CREGS_SAVE_AREA-4095(%r15) 602 - 0: larl %r15,.Lstosm_tmp 612 + lctlg %c0,%c15,__LC_CREGS_SAVE_AREA 613 + 0: larl %r15,stosm_tmp 603 614 stosm 0(%r15),0x04 # turn dat on, keep irqs off 604 615 lg %r15,__LC_RESTART_STACK 605 616 xc STACK_FRAME_OVERHEAD(__PT_SIZE,%r15),STACK_FRAME_OVERHEAD(%r15) ··· 619 632 2: sigp %r4,%r3,SIGP_STOP # sigp stop to current cpu 620 633 brc 2,2b 621 634 3: j 3b 622 - ENDPROC(restart_int_handler) 635 + SYM_CODE_END(restart_int_handler) 623 636 624 637 .section .kprobes.text, "ax" 625 638 ··· 629 642 * No need to properly save the registers, we are going to panic anyway. 630 643 * Setup a pt_regs so that show_trace can provide a good call trace. 631 644 */ 632 - ENTRY(stack_overflow) 645 + SYM_CODE_START(stack_overflow) 633 646 lg %r15,__LC_NODAT_STACK # change to panic stack 634 647 la %r11,STACK_FRAME_OVERHEAD(%r15) 635 648 stmg %r0,%r7,__PT_R0(%r11) ··· 639 652 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) 640 653 lgr %r2,%r11 # pass pointer to pt_regs 641 654 jg kernel_stack_overflow 642 - ENDPROC(stack_overflow) 655 + SYM_CODE_END(stack_overflow) 643 656 #endif 644 657 645 658 .section .data, "aw" 646 - .align 4 647 - .Lstop_lock: .long 0 648 - .Lthis_cpu: .short 0 649 - .Lstosm_tmp: .byte 0 659 + .balign 4 660 + SYM_DATA_LOCAL(stop_lock, .long 0) 661 + SYM_DATA_LOCAL(this_cpu, .short 0) 662 + SYM_DATA_LOCAL(stosm_tmp, .byte 0) 663 + 650 664 .section .rodata, "a" 651 665 #define SYSCALL(esame,emu) .quad __s390x_ ## esame 652 - .globl sys_call_table 653 - sys_call_table: 666 + SYM_DATA_START(sys_call_table) 654 667 #include "asm/syscall_table.h" 668 + SYM_DATA_END(sys_call_table) 655 669 #undef SYSCALL 656 670 657 671 #ifdef CONFIG_COMPAT 658 672 659 673 #define SYSCALL(esame,emu) .quad __s390_ ## emu 660 - .globl sys_call_table_emu 661 - sys_call_table_emu: 674 + SYM_DATA_START(sys_call_table_emu) 662 675 #include "asm/syscall_table.h" 676 + SYM_DATA_END(sys_call_table_emu) 663 677 #undef SYSCALL 664 678 #endif
+1 -21
arch/s390/kernel/ftrace.c
··· 49 49 s32 disp; 50 50 } __packed; 51 51 52 - asm( 53 - " .align 16\n" 54 - "ftrace_shared_hotpatch_trampoline_br:\n" 55 - " lmg %r0,%r1,2(%r1)\n" 56 - " br %r1\n" 57 - "ftrace_shared_hotpatch_trampoline_br_end:\n" 58 - ); 59 - 60 - #ifdef CONFIG_EXPOLINE 61 - asm( 62 - " .align 16\n" 63 - "ftrace_shared_hotpatch_trampoline_exrl:\n" 64 - " lmg %r0,%r1,2(%r1)\n" 65 - " exrl %r0,0f\n" 66 - " j .\n" 67 - "0: br %r1\n" 68 - "ftrace_shared_hotpatch_trampoline_exrl_end:\n" 69 - ); 70 - #endif /* CONFIG_EXPOLINE */ 71 - 72 52 #ifdef CONFIG_MODULES 73 53 static char *ftrace_plt; 74 54 #endif /* CONFIG_MODULES */ ··· 226 246 227 247 start = ftrace_shared_hotpatch_trampoline(&end); 228 248 memcpy(ftrace_plt, start, end - start); 229 - set_memory_ro((unsigned long)ftrace_plt, 1); 249 + set_memory_rox((unsigned long)ftrace_plt, 1); 230 250 return 0; 231 251 } 232 252 device_initcall(ftrace_plt_init);
+6 -8
arch/s390/kernel/head64.S
··· 16 16 #include <asm/ptrace.h> 17 17 18 18 __HEAD 19 - ENTRY(startup_continue) 19 + SYM_CODE_START(startup_continue) 20 20 larl %r1,tod_clock_base 21 21 mvc 0(16,%r1),__LC_BOOT_CLOCK 22 22 # ··· 24 24 # 25 25 larl %r14,init_task 26 26 stg %r14,__LC_CURRENT 27 - larl %r15,init_thread_union+THREAD_SIZE-STACK_FRAME_OVERHEAD-__PT_SIZE 27 + larl %r15,init_thread_union+STACK_INIT_OFFSET 28 + stg %r15,__LC_KERNEL_STACK 28 29 brasl %r14,sclp_early_adjust_va # allow sclp_early_printk 29 - #ifdef CONFIG_KASAN 30 - brasl %r14,kasan_early_init 31 - #endif 32 30 brasl %r14,startup_init # s390 specific early init 33 31 brasl %r14,start_kernel # common init code 34 32 # 35 33 # We returned from start_kernel ?!? PANIK 36 34 # 37 35 basr %r13,0 38 - lpswe .Ldw-.(%r13) # load disabled wait psw 36 + lpswe dw_psw-.(%r13) # load disabled wait psw 37 + SYM_CODE_END(startup_continue) 39 38 40 39 .align 16 41 - .LPG1: 42 - .Ldw: .quad 0x0002000180000000,0x0000000000000000 40 + SYM_DATA_LOCAL(dw_psw, .quad 0x0002000180000000,0x0000000000000000)
+3 -4
arch/s390/kernel/ipl.c
··· 176 176 static bool reipl_ccw_clear; 177 177 static bool reipl_eckd_clear; 178 178 179 - static inline int __diag308(unsigned long subcode, void *addr) 179 + static inline int __diag308(unsigned long subcode, unsigned long addr) 180 180 { 181 181 union register_pair r1; 182 182 183 - r1.even = (unsigned long) addr; 183 + r1.even = addr; 184 184 r1.odd = 0; 185 185 asm volatile( 186 186 " diag %[r1],%[subcode],0x308\n" ··· 195 195 int diag308(unsigned long subcode, void *addr) 196 196 { 197 197 diag_stat_inc(DIAG_STAT_X308); 198 - return __diag308(subcode, addr); 198 + return __diag308(subcode, addr ? virt_to_phys(addr) : 0); 199 199 } 200 200 EXPORT_SYMBOL_GPL(diag308); 201 201 ··· 649 649 650 650 static void __ipl_run(void *unused) 651 651 { 652 - __bpon(); 653 652 diag308(DIAG308_LOAD_CLEAR, NULL); 654 653 } 655 654
+1 -1
arch/s390/kernel/kprobes.c
··· 41 41 page = module_alloc(PAGE_SIZE); 42 42 if (!page) 43 43 return NULL; 44 - __set_memory((unsigned long) page, 1, SET_MEMORY_RO | SET_MEMORY_X); 44 + set_memory_rox((unsigned long)page, 1); 45 45 return page; 46 46 } 47 47
+2 -2
arch/s390/kernel/kprobes_insn_page.S
··· 14 14 */ 15 15 .section .kprobes.text, "ax" 16 16 .align 4096 17 - ENTRY(kprobes_insn_page) 17 + SYM_CODE_START(kprobes_insn_page) 18 18 .rept 2048 19 19 .word 0x07fe 20 20 .endr 21 - ENDPROC(kprobes_insn_page) 21 + SYM_CODE_END(kprobes_insn_page) 22 22 .previous
+22 -34
arch/s390/kernel/machine_kexec.c
··· 29 29 #include <asm/nmi.h> 30 30 #include <asm/sclp.h> 31 31 32 - typedef void (*relocate_kernel_t)(kimage_entry_t *, unsigned long, 33 - unsigned long); 32 + typedef void (*relocate_kernel_t)(unsigned long, unsigned long, unsigned long); 33 + typedef int (*purgatory_t)(int); 34 34 35 35 extern const unsigned char relocate_kernel[]; 36 36 extern const unsigned long long relocate_kernel_len; ··· 41 41 * Reset the system, copy boot CPU registers to absolute zero, 42 42 * and jump to the kdump image 43 43 */ 44 - static void __do_machine_kdump(void *image) 44 + static void __do_machine_kdump(void *data) 45 45 { 46 - int (*start_kdump)(int); 46 + struct kimage *image = data; 47 + purgatory_t purgatory; 47 48 unsigned long prefix; 49 + 50 + purgatory = (purgatory_t)image->start; 48 51 49 52 /* store_status() saved the prefix register to lowcore */ 50 53 prefix = (unsigned long) S390_lowcore.prefixreg_save_area; ··· 61 58 * prefix register of this CPU to zero 62 59 */ 63 60 memcpy(absolute_pointer(__LC_FPREGS_SAVE_AREA), 64 - (void *)(prefix + __LC_FPREGS_SAVE_AREA), 512); 61 + phys_to_virt(prefix + __LC_FPREGS_SAVE_AREA), 512); 65 62 66 - __load_psw_mask(PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA); 67 - start_kdump = (void *)((struct kimage *) image)->start; 68 - start_kdump(1); 63 + call_nodat(1, int, purgatory, int, 1); 69 64 70 - /* Die if start_kdump returns */ 65 + /* Die if kdump returns */ 71 66 disabled_wait(); 72 67 } 73 68 ··· 112 111 store_status(__do_machine_kdump, image); 113 112 } 114 113 115 - static unsigned long do_start_kdump(unsigned long addr) 116 - { 117 - struct kimage *image = (struct kimage *) addr; 118 - int (*start_kdump)(int) = (void *)image->start; 119 - int rc; 120 - 121 - __arch_local_irq_stnsm(0xfb); /* disable DAT */ 122 - rc = start_kdump(0); 123 - __arch_local_irq_stosm(0x04); /* enable DAT */ 124 - return rc; 125 - } 126 - 127 114 #endif /* CONFIG_CRASH_DUMP */ 128 115 129 116 /* ··· 120 131 static bool kdump_csum_valid(struct kimage *image) 121 132 { 122 133 #ifdef CONFIG_CRASH_DUMP 134 + purgatory_t purgatory = (purgatory_t)image->start; 123 135 int rc; 124 136 125 - preempt_disable(); 126 - rc = call_on_stack(1, S390_lowcore.nodat_stack, unsigned long, do_start_kdump, 127 - unsigned long, (unsigned long)image); 128 - preempt_enable(); 137 + rc = call_nodat(1, int, purgatory, int, 0); 129 138 return rc == 0; 130 139 #else 131 140 return false; ··· 197 210 return -EINVAL; 198 211 199 212 /* Get the destination where the assembler code should be copied to.*/ 200 - reboot_code_buffer = (void *) page_to_phys(image->control_code_page); 213 + reboot_code_buffer = page_to_virt(image->control_code_page); 201 214 202 215 /* Then copy it */ 203 216 memcpy(reboot_code_buffer, relocate_kernel, relocate_kernel_len); ··· 237 250 */ 238 251 static void __do_machine_kexec(void *data) 239 252 { 240 - unsigned long diag308_subcode; 241 - relocate_kernel_t data_mover; 253 + unsigned long data_mover, entry, diag308_subcode; 242 254 struct kimage *image = data; 243 255 244 - s390_reset_system(); 245 - data_mover = (relocate_kernel_t) page_to_phys(image->control_code_page); 246 - 247 - __arch_local_irq_stnsm(0xfb); /* disable DAT - avoid no-execute */ 248 - /* Call the moving routine */ 256 + data_mover = page_to_phys(image->control_code_page); 257 + entry = virt_to_phys(&image->head); 249 258 diag308_subcode = DIAG308_CLEAR_RESET; 250 259 if (sclp.has_iplcc) 251 260 diag308_subcode |= DIAG308_FLAG_EI; 252 - (*data_mover)(&image->head, image->start, diag308_subcode); 261 + s390_reset_system(); 262 + 263 + call_nodat(3, void, (relocate_kernel_t)data_mover, 264 + unsigned long, entry, 265 + unsigned long, image->start, 266 + unsigned long, diag308_subcode); 253 267 254 268 /* Die if kexec returns */ 255 269 disabled_wait();
+20 -6
arch/s390/kernel/mcount.S
··· 28 28 29 29 .section .kprobes.text, "ax" 30 30 31 - ENTRY(ftrace_stub) 31 + SYM_FUNC_START(ftrace_stub) 32 32 BR_EX %r14 33 - ENDPROC(ftrace_stub) 33 + SYM_FUNC_END(ftrace_stub) 34 34 35 35 SYM_CODE_START(ftrace_stub_direct_tramp) 36 36 lgr %r1, %r0 ··· 140 140 #endif 141 141 #endif /* CONFIG_FUNCTION_TRACER */ 142 142 143 + SYM_CODE_START(ftrace_shared_hotpatch_trampoline_br) 144 + lmg %r0,%r1,2(%r1) 145 + br %r1 146 + SYM_INNER_LABEL(ftrace_shared_hotpatch_trampoline_br_end, SYM_L_GLOBAL) 147 + SYM_CODE_END(ftrace_shared_hotpatch_trampoline_br) 148 + 149 + #ifdef CONFIG_EXPOLINE 150 + SYM_CODE_START(ftrace_shared_hotpatch_trampoline_exrl) 151 + lmg %r0,%r1,2(%r1) 152 + exrl %r0,0f 153 + j . 154 + 0: br %r1 155 + SYM_INNER_LABEL(ftrace_shared_hotpatch_trampoline_exrl_end, SYM_L_GLOBAL) 156 + SYM_CODE_END(ftrace_shared_hotpatch_trampoline_exrl) 157 + #endif /* CONFIG_EXPOLINE */ 158 + 143 159 #ifdef CONFIG_RETHOOK 144 160 145 - SYM_FUNC_START(arch_rethook_trampoline) 146 - 161 + SYM_CODE_START(arch_rethook_trampoline) 147 162 stg %r14,(__SF_GPRS+8*8)(%r15) 148 163 lay %r15,-STACK_FRAME_SIZE(%r15) 149 164 stmg %r0,%r14,STACK_PTREGS_GPRS(%r15) ··· 181 166 mvc __SF_EMPTY(16,%r7),STACK_PTREGS_PSW(%r15) 182 167 lmg %r0,%r15,STACK_PTREGS_GPRS(%r15) 183 168 lpswe __SF_EMPTY(%r15) 184 - 185 - SYM_FUNC_END(arch_rethook_trampoline) 169 + SYM_CODE_END(arch_rethook_trampoline) 186 170 187 171 #endif /* CONFIG_RETHOOK */
+25 -4
arch/s390/kernel/module.c
··· 26 26 #include <asm/facility.h> 27 27 #include <asm/ftrace.lds.h> 28 28 #include <asm/set_memory.h> 29 + #include <asm/setup.h> 29 30 30 31 #if 0 31 32 #define DEBUGP printk ··· 36 35 37 36 #define PLT_ENTRY_SIZE 22 38 37 38 + static unsigned long get_module_load_offset(void) 39 + { 40 + static DEFINE_MUTEX(module_kaslr_mutex); 41 + static unsigned long module_load_offset; 42 + 43 + if (!kaslr_enabled()) 44 + return 0; 45 + /* 46 + * Calculate the module_load_offset the first time this code 47 + * is called. Once calculated it stays the same until reboot. 48 + */ 49 + mutex_lock(&module_kaslr_mutex); 50 + if (!module_load_offset) 51 + module_load_offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; 52 + mutex_unlock(&module_kaslr_mutex); 53 + return module_load_offset; 54 + } 55 + 39 56 void *module_alloc(unsigned long size) 40 57 { 41 58 gfp_t gfp_mask = GFP_KERNEL; ··· 61 42 62 43 if (PAGE_ALIGN(size) > MODULES_LEN) 63 44 return NULL; 64 - p = __vmalloc_node_range(size, MODULE_ALIGN, MODULES_VADDR, MODULES_END, 65 - gfp_mask, PAGE_KERNEL_EXEC, VM_DEFER_KMEMLEAK, NUMA_NO_NODE, 66 - __builtin_return_address(0)); 45 + p = __vmalloc_node_range(size, MODULE_ALIGN, 46 + MODULES_VADDR + get_module_load_offset(), 47 + MODULES_END, gfp_mask, PAGE_KERNEL, 48 + VM_FLUSH_RESET_PERMS | VM_DEFER_KMEMLEAK, 49 + NUMA_NO_NODE, __builtin_return_address(0)); 67 50 if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) { 68 51 vfree(p); 69 52 return NULL; ··· 512 491 start = module_alloc(numpages * PAGE_SIZE); 513 492 if (!start) 514 493 return -ENOMEM; 515 - set_memory_ro((unsigned long)start, numpages); 494 + set_memory_rox((unsigned long)start, numpages); 516 495 end = start + size; 517 496 518 497 me->arch.trampolines_start = (struct ftrace_hotpatch_trampoline *)start;
+91 -115
arch/s390/kernel/perf_cpum_cf.c
··· 76 76 } 77 77 78 78 struct cpu_cf_events { 79 - struct cpumf_ctr_info info; 80 79 atomic_t ctr_set[CPUMF_CTR_SET_MAX]; 81 80 u64 state; /* For perf_event_open SVC */ 82 81 u64 dev_state; /* For /dev/hwctr */ ··· 93 94 94 95 static unsigned int cfdiag_cpu_speed; /* CPU speed for CF_DIAG trailer */ 95 96 static debug_info_t *cf_dbg; 97 + 98 + /* 99 + * The CPU Measurement query counter information instruction contains 100 + * information which varies per machine generation, but is constant and 101 + * does not change when running on a particular machine, such as counter 102 + * first and second version number. This is needed to determine the size 103 + * of counter sets. Extract this information at device driver initialization. 104 + */ 105 + static struct cpumf_ctr_info cpumf_ctr_info; 96 106 97 107 #define CF_DIAG_CTRSET_DEF 0xfeef /* Counter set header mark */ 98 108 /* interval in seconds */ ··· 175 167 /* Create the trailer data at the end of a page. */ 176 168 static void cfdiag_trailer(struct cf_trailer_entry *te) 177 169 { 178 - struct cpu_cf_events *cpuhw = this_cpu_ptr(&cpu_cf_events); 179 170 struct cpuid cpuid; 180 171 181 - te->cfvn = cpuhw->info.cfvn; /* Counter version numbers */ 182 - te->csvn = cpuhw->info.csvn; 172 + te->cfvn = cpumf_ctr_info.cfvn; /* Counter version numbers */ 173 + te->csvn = cpumf_ctr_info.csvn; 183 174 184 175 get_cpu_id(&cpuid); /* Machine type */ 185 176 te->mach_type = cpuid.machine; ··· 191 184 } 192 185 193 186 /* 194 - * Return the maximum possible counter set size (in number of 8 byte counters) 195 - * depending on type and model number. 187 + * The number of counters per counter set varies between machine generations, 188 + * but is constant when running on a particular machine generation. 189 + * Determine each counter set size at device driver initialization and 190 + * retrieve it later. 196 191 */ 197 - static size_t cpum_cf_ctrset_size(enum cpumf_ctr_set ctrset, 198 - struct cpumf_ctr_info *info) 192 + static size_t cpumf_ctr_setsizes[CPUMF_CTR_SET_MAX]; 193 + static void cpum_cf_make_setsize(enum cpumf_ctr_set ctrset) 199 194 { 200 195 size_t ctrset_size = 0; 201 196 202 197 switch (ctrset) { 203 198 case CPUMF_CTR_SET_BASIC: 204 - if (info->cfvn >= 1) 199 + if (cpumf_ctr_info.cfvn >= 1) 205 200 ctrset_size = 6; 206 201 break; 207 202 case CPUMF_CTR_SET_USER: 208 - if (info->cfvn == 1) 203 + if (cpumf_ctr_info.cfvn == 1) 209 204 ctrset_size = 6; 210 - else if (info->cfvn >= 3) 205 + else if (cpumf_ctr_info.cfvn >= 3) 211 206 ctrset_size = 2; 212 207 break; 213 208 case CPUMF_CTR_SET_CRYPTO: 214 - if (info->csvn >= 1 && info->csvn <= 5) 209 + if (cpumf_ctr_info.csvn >= 1 && cpumf_ctr_info.csvn <= 5) 215 210 ctrset_size = 16; 216 - else if (info->csvn == 6 || info->csvn == 7) 211 + else if (cpumf_ctr_info.csvn == 6 || cpumf_ctr_info.csvn == 7) 217 212 ctrset_size = 20; 218 213 break; 219 214 case CPUMF_CTR_SET_EXT: 220 - if (info->csvn == 1) 215 + if (cpumf_ctr_info.csvn == 1) 221 216 ctrset_size = 32; 222 - else if (info->csvn == 2) 217 + else if (cpumf_ctr_info.csvn == 2) 223 218 ctrset_size = 48; 224 - else if (info->csvn >= 3 && info->csvn <= 5) 219 + else if (cpumf_ctr_info.csvn >= 3 && cpumf_ctr_info.csvn <= 5) 225 220 ctrset_size = 128; 226 - else if (info->csvn == 6 || info->csvn == 7) 221 + else if (cpumf_ctr_info.csvn == 6 || cpumf_ctr_info.csvn == 7) 227 222 ctrset_size = 160; 228 223 break; 229 224 case CPUMF_CTR_SET_MT_DIAG: 230 - if (info->csvn > 3) 225 + if (cpumf_ctr_info.csvn > 3) 231 226 ctrset_size = 48; 232 227 break; 233 228 case CPUMF_CTR_SET_MAX: 234 229 break; 235 230 } 231 + cpumf_ctr_setsizes[ctrset] = ctrset_size; 232 + } 236 233 237 - return ctrset_size; 234 + /* 235 + * Return the maximum possible counter set size (in number of 8 byte counters) 236 + * depending on type and model number. 237 + */ 238 + static size_t cpum_cf_read_setsize(enum cpumf_ctr_set ctrset) 239 + { 240 + return cpumf_ctr_setsizes[ctrset]; 238 241 } 239 242 240 243 /* Read a counter set. The counter set number determines the counter set and ··· 265 248 static size_t cfdiag_getctrset(struct cf_ctrset_entry *ctrdata, int ctrset, 266 249 size_t room, bool error_ok) 267 250 { 268 - struct cpu_cf_events *cpuhw = this_cpu_ptr(&cpu_cf_events); 269 251 size_t ctrset_size, need = 0; 270 252 int rc = 3; /* Assume write failure */ 271 253 272 254 ctrdata->def = CF_DIAG_CTRSET_DEF; 273 255 ctrdata->set = ctrset; 274 256 ctrdata->res1 = 0; 275 - ctrset_size = cpum_cf_ctrset_size(ctrset, &cpuhw->info); 257 + ctrset_size = cpum_cf_read_setsize(ctrset); 276 258 277 259 if (ctrset_size) { /* Save data */ 278 260 need = ctrset_size * sizeof(u64) + sizeof(*ctrdata); ··· 285 269 need = 0; 286 270 } 287 271 288 - debug_sprintf_event(cf_dbg, 3, 289 - "%s ctrset %d ctrset_size %zu cfvn %d csvn %d" 290 - " need %zd rc %d\n", __func__, ctrset, ctrset_size, 291 - cpuhw->info.cfvn, cpuhw->info.csvn, need, rc); 292 272 return need; 293 273 } 294 274 ··· 389 377 return set; 390 378 } 391 379 392 - static int validate_ctr_version(const struct hw_perf_event *hwc, 393 - enum cpumf_ctr_set set) 380 + static int validate_ctr_version(const u64 config, enum cpumf_ctr_set set) 394 381 { 395 - struct cpu_cf_events *cpuhw; 396 - int err = 0; 397 382 u16 mtdiag_ctl; 398 - 399 - cpuhw = &get_cpu_var(cpu_cf_events); 383 + int err = 0; 400 384 401 385 /* check required version for counter sets */ 402 386 switch (set) { 403 387 case CPUMF_CTR_SET_BASIC: 404 388 case CPUMF_CTR_SET_USER: 405 - if (cpuhw->info.cfvn < 1) 389 + if (cpumf_ctr_info.cfvn < 1) 406 390 err = -EOPNOTSUPP; 407 391 break; 408 392 case CPUMF_CTR_SET_CRYPTO: 409 - if ((cpuhw->info.csvn >= 1 && cpuhw->info.csvn <= 5 && 410 - hwc->config > 79) || 411 - (cpuhw->info.csvn >= 6 && hwc->config > 83)) 393 + if ((cpumf_ctr_info.csvn >= 1 && cpumf_ctr_info.csvn <= 5 && 394 + config > 79) || (cpumf_ctr_info.csvn >= 6 && config > 83)) 412 395 err = -EOPNOTSUPP; 413 396 break; 414 397 case CPUMF_CTR_SET_EXT: 415 - if (cpuhw->info.csvn < 1) 398 + if (cpumf_ctr_info.csvn < 1) 416 399 err = -EOPNOTSUPP; 417 - if ((cpuhw->info.csvn == 1 && hwc->config > 159) || 418 - (cpuhw->info.csvn == 2 && hwc->config > 175) || 419 - (cpuhw->info.csvn >= 3 && cpuhw->info.csvn <= 5 420 - && hwc->config > 255) || 421 - (cpuhw->info.csvn >= 6 && hwc->config > 287)) 400 + if ((cpumf_ctr_info.csvn == 1 && config > 159) || 401 + (cpumf_ctr_info.csvn == 2 && config > 175) || 402 + (cpumf_ctr_info.csvn >= 3 && cpumf_ctr_info.csvn <= 5 && 403 + config > 255) || 404 + (cpumf_ctr_info.csvn >= 6 && config > 287)) 422 405 err = -EOPNOTSUPP; 423 406 break; 424 407 case CPUMF_CTR_SET_MT_DIAG: 425 - if (cpuhw->info.csvn <= 3) 408 + if (cpumf_ctr_info.csvn <= 3) 426 409 err = -EOPNOTSUPP; 427 410 /* 428 411 * MT-diagnostic counters are read-only. The counter set ··· 432 425 * counter set is enabled and active. 433 426 */ 434 427 mtdiag_ctl = cpumf_ctr_ctl[CPUMF_CTR_SET_MT_DIAG]; 435 - if (!((cpuhw->info.auth_ctl & mtdiag_ctl) && 436 - (cpuhw->info.enable_ctl & mtdiag_ctl) && 437 - (cpuhw->info.act_ctl & mtdiag_ctl))) 428 + if (!((cpumf_ctr_info.auth_ctl & mtdiag_ctl) && 429 + (cpumf_ctr_info.enable_ctl & mtdiag_ctl) && 430 + (cpumf_ctr_info.act_ctl & mtdiag_ctl))) 438 431 err = -EOPNOTSUPP; 439 432 break; 440 433 case CPUMF_CTR_SET_MAX: 441 434 err = -EOPNOTSUPP; 442 435 } 443 436 444 - put_cpu_var(cpu_cf_events); 445 - return err; 446 - } 447 - 448 - static int validate_ctr_auth(const struct hw_perf_event *hwc) 449 - { 450 - struct cpu_cf_events *cpuhw; 451 - int err = 0; 452 - 453 - cpuhw = &get_cpu_var(cpu_cf_events); 454 - 455 - /* Check authorization for cpu counter sets. 456 - * If the particular CPU counter set is not authorized, 457 - * return with -ENOENT in order to fall back to other 458 - * PMUs that might suffice the event request. 459 - */ 460 - if (!(hwc->config_base & cpuhw->info.auth_ctl)) 461 - err = -ENOENT; 462 - 463 - put_cpu_var(cpu_cf_events); 464 437 return err; 465 438 } 466 439 ··· 458 471 return; 459 472 460 473 err = lcctl(cpuhw->state | cpuhw->dev_state); 461 - if (err) { 462 - pr_err("Enabling the performance measuring unit " 463 - "failed with rc=%x\n", err); 464 - return; 465 - } 466 - 467 - cpuhw->flags |= PMU_F_ENABLED; 474 + if (err) 475 + pr_err("Enabling the performance measuring unit failed with rc=%x\n", err); 476 + else 477 + cpuhw->flags |= PMU_F_ENABLED; 468 478 } 469 479 470 480 /* ··· 481 497 inactive = cpuhw->state & ~((1 << CPUMF_LCCTL_ENABLE_SHIFT) - 1); 482 498 inactive |= cpuhw->dev_state; 483 499 err = lcctl(inactive); 484 - if (err) { 485 - pr_err("Disabling the performance measuring unit " 486 - "failed with rc=%x\n", err); 487 - return; 488 - } 489 - 490 - cpuhw->flags &= ~PMU_F_ENABLED; 500 + if (err) 501 + pr_err("Disabling the performance measuring unit failed with rc=%x\n", err); 502 + else 503 + cpuhw->flags &= ~PMU_F_ENABLED; 491 504 } 492 505 493 506 #define PMC_INIT 0UL ··· 496 515 497 516 switch ((unsigned long)flags) { 498 517 case PMC_INIT: 499 - memset(&cpuhw->info, 0, sizeof(cpuhw->info)); 500 - qctri(&cpuhw->info); 501 518 cpuhw->flags |= PMU_F_RESERVED; 502 519 break; 503 520 ··· 581 602 struct perf_event_attr *attr = &event->attr; 582 603 struct hw_perf_event *hwc = &event->hw; 583 604 enum cpumf_ctr_set set; 584 - int err = 0; 585 605 u64 ev; 586 606 587 607 switch (type) { ··· 656 678 cpumf_hw_inuse(); 657 679 event->destroy = hw_perf_event_destroy; 658 680 659 - /* Finally, validate version and authorization of the counter set */ 660 - err = validate_ctr_auth(hwc); 661 - if (!err) 662 - err = validate_ctr_version(hwc, set); 663 - 664 - return err; 681 + /* 682 + * Finally, validate version and authorization of the counter set. 683 + * If the particular CPU counter set is not authorized, 684 + * return with -ENOENT in order to fall back to other 685 + * PMUs that might suffice the event request. 686 + */ 687 + if (!(hwc->config_base & cpumf_ctr_info.auth_ctl)) 688 + return -ENOENT; 689 + return validate_ctr_version(hwc->config, set); 665 690 } 666 691 667 692 /* Events CPU_CYLCES and INSTRUCTIONS can be submitted with two different ··· 964 983 965 984 /* counter authorization change alert */ 966 985 if (alert & CPU_MF_INT_CF_CACA) 967 - qctri(&cpuhw->info); 986 + qctri(&cpumf_ctr_info); 968 987 969 988 /* loss of counter data alert */ 970 989 if (alert & CPU_MF_INT_CF_LCDA) ··· 981 1000 { 982 1001 int rc; 983 1002 984 - if (!cpum_cf_avail()) 1003 + /* Extract counter measurement facility information */ 1004 + if (!cpum_cf_avail() || qctri(&cpumf_ctr_info)) 985 1005 return -ENODEV; 1006 + 1007 + /* Determine and store counter set sizes for later reference */ 1008 + for (rc = CPUMF_CTR_SET_BASIC; rc < CPUMF_CTR_SET_MAX; ++rc) 1009 + cpum_cf_make_setsize(rc); 986 1010 987 1011 /* 988 1012 * Clear bit 15 of cr0 to unauthorize problem-state to ··· 1255 1269 */ 1256 1270 static size_t cfset_needspace(unsigned int sets) 1257 1271 { 1258 - struct cpu_cf_events *cpuhw = get_cpu_ptr(&cpu_cf_events); 1259 1272 size_t bytes = 0; 1260 1273 int i; 1261 1274 1262 1275 for (i = CPUMF_CTR_SET_BASIC; i < CPUMF_CTR_SET_MAX; ++i) { 1263 1276 if (!(sets & cpumf_ctr_ctl[i])) 1264 1277 continue; 1265 - bytes += cpum_cf_ctrset_size(i, &cpuhw->info) * sizeof(u64) + 1278 + bytes += cpum_cf_read_setsize(i) * sizeof(u64) + 1266 1279 sizeof(((struct s390_ctrset_setdata *)0)->set) + 1267 1280 sizeof(((struct s390_ctrset_setdata *)0)->no_cnts); 1268 1281 } 1269 1282 bytes = sizeof(((struct s390_ctrset_read *)0)->no_cpus) + nr_cpu_ids * 1270 1283 (bytes + sizeof(((struct s390_ctrset_cpudata *)0)->cpu_nr) + 1271 1284 sizeof(((struct s390_ctrset_cpudata *)0)->no_sets)); 1272 - put_cpu_ptr(&cpu_cf_events); 1273 1285 return bytes; 1274 1286 } 1275 1287 1276 1288 static int cfset_all_copy(unsigned long arg, cpumask_t *mask) 1277 1289 { 1278 1290 struct s390_ctrset_read __user *ctrset_read; 1279 - unsigned int cpu, cpus, rc; 1291 + unsigned int cpu, cpus, rc = 0; 1280 1292 void __user *uptr; 1281 1293 1282 1294 ctrset_read = (struct s390_ctrset_read __user *)arg; ··· 1288 1304 rc |= put_user(cpuhw->sets, &ctrset_cpudata->no_sets); 1289 1305 rc |= copy_to_user(ctrset_cpudata->data, cpuhw->data, 1290 1306 cpuhw->used); 1291 - if (rc) 1292 - return -EFAULT; 1307 + if (rc) { 1308 + rc = -EFAULT; 1309 + goto out; 1310 + } 1293 1311 uptr += sizeof(struct s390_ctrset_cpudata) + cpuhw->used; 1294 1312 cond_resched(); 1295 1313 } 1296 1314 cpus = cpumask_weight(mask); 1297 1315 if (put_user(cpus, &ctrset_read->no_cpus)) 1298 - return -EFAULT; 1299 - debug_sprintf_event(cf_dbg, 4, "%s copied %ld\n", __func__, 1316 + rc = -EFAULT; 1317 + out: 1318 + debug_sprintf_event(cf_dbg, 4, "%s rc %d copied %ld\n", __func__, rc, 1300 1319 uptr - (void __user *)ctrset_read->data); 1301 - return 0; 1320 + return rc; 1302 1321 } 1303 1322 1304 1323 static size_t cfset_cpuset_read(struct s390_ctrset_setdata *p, int ctrset, ··· 1341 1354 1342 1355 if (!(p->sets & cpumf_ctr_ctl[set])) 1343 1356 continue; /* Counter set not in list */ 1344 - set_size = cpum_cf_ctrset_size(set, &cpuhw->info); 1357 + set_size = cpum_cf_read_setsize(set); 1345 1358 space = sizeof(cpuhw->data) - cpuhw->used; 1346 1359 space = cfset_cpuset_read(sp, set, set_size, space); 1347 1360 if (space) { ··· 1372 1385 1373 1386 static long cfset_ioctl_read(unsigned long arg, struct cfset_request *req) 1374 1387 { 1375 - struct s390_ctrset_read read; 1376 1388 int ret = -ENODATA; 1377 1389 1378 - if (req && req->ctrset) { 1379 - if (copy_from_user(&read, (char __user *)arg, sizeof(read))) 1380 - return -EFAULT; 1390 + if (req && req->ctrset) 1381 1391 ret = cfset_all_read(arg, req); 1382 - } 1383 1392 return ret; 1384 1393 } 1385 1394 ··· 1552 1569 1553 1570 static int get_authctrsets(void) 1554 1571 { 1555 - struct cpu_cf_events *cpuhw; 1556 1572 unsigned long auth = 0; 1557 1573 enum cpumf_ctr_set i; 1558 1574 1559 - cpuhw = &get_cpu_var(cpu_cf_events); 1560 1575 for (i = CPUMF_CTR_SET_BASIC; i < CPUMF_CTR_SET_MAX; ++i) { 1561 - if (cpuhw->info.auth_ctl & cpumf_ctr_ctl[i]) 1576 + if (cpumf_ctr_info.auth_ctl & cpumf_ctr_ctl[i]) 1562 1577 auth |= cpumf_ctr_ctl[i]; 1563 1578 } 1564 - put_cpu_var(cpu_cf_events); 1565 1579 return auth; 1566 1580 } 1567 1581 ··· 1696 1716 enum cpumf_ctr_set i; 1697 1717 1698 1718 for (i = CPUMF_CTR_SET_BASIC; i < CPUMF_CTR_SET_MAX; ++i) { 1699 - size_t size = cpum_cf_ctrset_size(i, info); 1719 + size_t size = cpum_cf_read_setsize(i); 1700 1720 1701 1721 if (size) 1702 1722 max_size += size * sizeof(u64) + ··· 1730 1750 1731 1751 static int cfset_init(void) 1732 1752 { 1733 - struct cpumf_ctr_info info; 1734 1753 size_t need; 1735 1754 int rc; 1736 1755 1737 - if (qctri(&info)) 1738 - return -ENODEV; 1739 - 1740 1756 cfdiag_get_cpu_speed(); 1741 1757 /* Make sure the counter set data fits into predefined buffer. */ 1742 - need = cfdiag_maxsize(&info); 1758 + need = cfdiag_maxsize(&cpumf_ctr_info); 1743 1759 if (need > sizeof(((struct cpu_cf_events *)0)->start)) { 1744 1760 pr_err("Insufficient memory for PMU(cpum_cf_diag) need=%zu\n", 1745 1761 need);
+2 -12
arch/s390/kernel/perf_cpum_sf.c
··· 882 882 SAMPL_FLAGS(hwc) |= PERF_CPUM_SF_DIAG_MODE; 883 883 } 884 884 885 - /* Check and set other sampling flags */ 886 - if (attr->config1 & PERF_CPUM_SF_FULL_BLOCKS) 887 - SAMPL_FLAGS(hwc) |= PERF_CPUM_SF_FULL_BLOCKS; 888 - 889 885 err = __hw_perf_event_init_rate(event, &si); 890 886 if (err) 891 887 goto out; ··· 1289 1293 * The sampling buffer position are retrieved and saved in the TEAR_REG 1290 1294 * register of the specified perf event. 1291 1295 * 1292 - * Only full sample-data-blocks are processed. Specify the flash_all flag 1293 - * to also walk through partially filled sample-data-blocks. It is ignored 1294 - * if PERF_CPUM_SF_FULL_BLOCKS is set. The PERF_CPUM_SF_FULL_BLOCKS flag 1295 - * enforces the processing of full sample-data-blocks only (trailer entries 1296 - * with the block-full-indicator bit set). 1296 + * Only full sample-data-blocks are processed. Specify the flush_all flag 1297 + * to also walk through partially filled sample-data-blocks. 1297 1298 */ 1298 1299 static void hw_perf_event_update(struct perf_event *event, int flush_all) 1299 1300 { ··· 1307 1314 */ 1308 1315 if (SAMPL_DIAG_MODE(&event->hw)) 1309 1316 return; 1310 - 1311 - if (flush_all && SDB_FULL_BLOCKS(hwc)) 1312 - flush_all = 0; 1313 1317 1314 1318 sdbt = (unsigned long *) TEAR_REG(hwc); 1315 1319 done = event_overflow = sampl_overflow = num_sdb = 0;
+4 -6
arch/s390/kernel/process.c
··· 136 136 p->thread.last_break = 1; 137 137 138 138 frame->sf.back_chain = 0; 139 - frame->sf.gprs[5] = (unsigned long)frame + sizeof(struct stack_frame); 140 - frame->sf.gprs[6] = (unsigned long)p; 139 + frame->sf.gprs[11 - 6] = (unsigned long)&frame->childregs; 140 + frame->sf.gprs[12 - 6] = (unsigned long)p; 141 141 /* new return point is ret_from_fork */ 142 - frame->sf.gprs[8] = (unsigned long)ret_from_fork; 142 + frame->sf.gprs[14 - 6] = (unsigned long)ret_from_fork; 143 143 /* fake return stack for resume(), don't go back to schedule */ 144 - frame->sf.gprs[9] = (unsigned long)frame; 144 + frame->sf.gprs[15 - 6] = (unsigned long)frame; 145 145 146 146 /* Store access registers to kernel stack of new process. */ 147 147 if (unlikely(args->fn)) { ··· 149 149 memset(&frame->childregs, 0, sizeof(struct pt_regs)); 150 150 frame->childregs.psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | 151 151 PSW_MASK_EXT | PSW_MASK_MCHECK; 152 - frame->childregs.psw.addr = 153 - (unsigned long)__ret_from_fork; 154 152 frame->childregs.gprs[9] = (unsigned long)args->fn; 155 153 frame->childregs.gprs[10] = (unsigned long)args->fn_arg; 156 154 frame->childregs.orig_gpr2 = -1;
-18
arch/s390/kernel/processor.c
··· 364 364 .stop = c_stop, 365 365 .show = show_cpuinfo, 366 366 }; 367 - 368 - int s390_isolate_bp(void) 369 - { 370 - if (!test_facility(82)) 371 - return -EOPNOTSUPP; 372 - set_thread_flag(TIF_ISOLATE_BP); 373 - return 0; 374 - } 375 - EXPORT_SYMBOL(s390_isolate_bp); 376 - 377 - int s390_isolate_bp_guest(void) 378 - { 379 - if (!test_facility(82)) 380 - return -EOPNOTSUPP; 381 - set_thread_flag(TIF_ISOLATE_BP_GUEST); 382 - return 0; 383 - } 384 - EXPORT_SYMBOL(s390_isolate_bp_guest);
+5 -5
arch/s390/kernel/reipl.S
··· 19 19 # r2 = Function to be called after store status 20 20 # r3 = Parameter for function 21 21 # 22 - ENTRY(store_status) 22 + SYM_CODE_START(store_status) 23 23 /* Save register one and load save area base */ 24 24 stg %r1,__LC_SAVE_AREA_RESTART 25 25 /* General purpose registers */ ··· 61 61 stpx 0(%r1) 62 62 /* Clock comparator - seven bytes */ 63 63 lghi %r1,__LC_CLOCK_COMP_SAVE_AREA 64 - larl %r4,.Lclkcmp 64 + larl %r4,clkcmp 65 65 stckc 0(%r4) 66 66 mvc 1(7,%r1),1(%r4) 67 67 /* Program status word */ ··· 73 73 lgr %r9,%r2 74 74 lgr %r2,%r3 75 75 BR_EX %r9 76 - ENDPROC(store_status) 76 + SYM_CODE_END(store_status) 77 77 78 78 .section .bss 79 - .align 8 80 - .Lclkcmp: .quad 0x0000000000000000 79 + .balign 8 80 + SYM_DATA_LOCAL(clkcmp, .quad 0x0000000000000000) 81 81 .previous
+47 -49
arch/s390/kernel/relocate_kernel.S
··· 26 26 */ 27 27 28 28 .text 29 - ENTRY(relocate_kernel) 30 - basr %r13,0 # base address 31 - .base: 32 - lghi %r7,PAGE_SIZE # load PAGE_SIZE in r7 33 - lghi %r9,PAGE_SIZE # load PAGE_SIZE in r9 34 - lg %r5,0(%r2) # read another word for indirection page 35 - aghi %r2,8 # increment pointer 36 - tml %r5,0x1 # is it a destination page? 37 - je .indir_check # NO, goto "indir_check" 38 - lgr %r6,%r5 # r6 = r5 39 - nill %r6,0xf000 # mask it out and... 40 - j .base # ...next iteration 41 - .indir_check: 42 - tml %r5,0x2 # is it a indirection page? 43 - je .done_test # NO, goto "done_test" 44 - nill %r5,0xf000 # YES, mask out, 45 - lgr %r2,%r5 # move it into the right register, 46 - j .base # and read next... 47 - .done_test: 48 - tml %r5,0x4 # is it the done indicator? 49 - je .source_test # NO! Well, then it should be the source indicator... 50 - j .done # ok, lets finish it here... 51 - .source_test: 52 - tml %r5,0x8 # it should be a source indicator... 53 - je .base # NO, ignore it... 54 - lgr %r8,%r5 # r8 = r5 55 - nill %r8,0xf000 # masking 56 - 0: mvcle %r6,%r8,0x0 # copy PAGE_SIZE bytes from r8 to r6 - pad with 0 57 - jo 0b 58 - j .base 59 - .done: 60 - lgr %r0,%r4 # subcode 61 - cghi %r3,0 62 - je .diag 63 - la %r4,load_psw-.base(%r13) # load psw-address into the register 64 - o %r3,4(%r4) # or load address into psw 65 - st %r3,4(%r4) 66 - mvc 0(8,%r0),0(%r4) # copy psw to absolute address 0 67 - .diag: 68 - diag %r0,%r0,0x308 69 - ENDPROC(relocate_kernel) 29 + SYM_CODE_START(relocate_kernel) 30 + basr %r13,0 # base address 31 + .base: 32 + lghi %r7,PAGE_SIZE # load PAGE_SIZE in r7 33 + lghi %r9,PAGE_SIZE # load PAGE_SIZE in r9 34 + lg %r5,0(%r2) # read another word for indirection page 35 + aghi %r2,8 # increment pointer 36 + tml %r5,0x1 # is it a destination page? 37 + je .indir_check # NO, goto "indir_check" 38 + lgr %r6,%r5 # r6 = r5 39 + nill %r6,0xf000 # mask it out and... 40 + j .base # ...next iteration 41 + .indir_check: 42 + tml %r5,0x2 # is it a indirection page? 43 + je .done_test # NO, goto "done_test" 44 + nill %r5,0xf000 # YES, mask out, 45 + lgr %r2,%r5 # move it into the right register, 46 + j .base # and read next... 47 + .done_test: 48 + tml %r5,0x4 # is it the done indicator? 49 + je .source_test # NO! Well, then it should be the source indicator... 50 + j .done # ok, lets finish it here... 51 + .source_test: 52 + tml %r5,0x8 # it should be a source indicator... 53 + je .base # NO, ignore it... 54 + lgr %r8,%r5 # r8 = r5 55 + nill %r8,0xf000 # masking 56 + 0: mvcle %r6,%r8,0x0 # copy PAGE_SIZE bytes from r8 to r6 - pad with 0 57 + jo 0b 58 + j .base 59 + .done: 60 + lgr %r0,%r4 # subcode 61 + cghi %r3,0 62 + je .diag 63 + la %r4,load_psw-.base(%r13) # load psw-address into the register 64 + o %r3,4(%r4) # or load address into psw 65 + st %r3,4(%r4) 66 + mvc 0(8,%r0),0(%r4) # copy psw to absolute address 0 67 + .diag: 68 + diag %r0,%r0,0x308 69 + SYM_CODE_END(relocate_kernel) 70 70 71 - .align 8 72 - load_psw: 73 - .long 0x00080000,0x80000000 74 - relocate_kernel_end: 75 - .align 8 76 - .globl relocate_kernel_len 77 - relocate_kernel_len: 78 - .quad relocate_kernel_end - relocate_kernel 71 + .balign 8 72 + SYM_DATA_START_LOCAL(load_psw) 73 + .long 0x00080000,0x80000000 74 + SYM_DATA_END_LABEL(load_psw, SYM_L_LOCAL, relocate_kernel_end) 75 + .balign 8 76 + SYM_DATA(relocate_kernel_len, .quad relocate_kernel_end - relocate_kernel)
+50 -106
arch/s390/kernel/setup.c
··· 74 74 #include <asm/numa.h> 75 75 #include <asm/alternative.h> 76 76 #include <asm/nospec-branch.h> 77 - #include <asm/mem_detect.h> 77 + #include <asm/physmem_info.h> 78 78 #include <asm/maccess.h> 79 79 #include <asm/uv.h> 80 80 #include <asm/asm-offsets.h> ··· 147 147 148 148 int __bootdata(noexec_disabled); 149 149 unsigned long __bootdata(ident_map_size); 150 - struct mem_detect_info __bootdata(mem_detect); 151 - struct initrd_data __bootdata(initrd_data); 152 - unsigned long __bootdata(pgalloc_pos); 153 - unsigned long __bootdata(pgalloc_end); 154 - unsigned long __bootdata(pgalloc_low); 150 + struct physmem_info __bootdata(physmem_info); 155 151 156 152 unsigned long __bootdata_preserved(__kaslr_offset); 157 - unsigned long __bootdata(__amode31_base); 153 + int __bootdata_preserved(__kaslr_enabled); 158 154 unsigned int __bootdata_preserved(zlib_dfltcc_support); 159 155 EXPORT_SYMBOL(zlib_dfltcc_support); 160 156 u64 __bootdata_preserved(stfle_fac_list[16]); ··· 381 385 #endif 382 386 } 383 387 384 - int __init arch_early_irq_init(void) 385 - { 386 - unsigned long stack; 387 - 388 - stack = __get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER); 389 - if (!stack) 390 - panic("Couldn't allocate async stack"); 391 - S390_lowcore.async_stack = stack + STACK_INIT_OFFSET; 392 - return 0; 393 - } 394 - 395 388 void __init __noreturn arch_call_rest_init(void) 396 389 { 390 + smp_reinit_ipl_cpu(); 391 + rest_init(); 392 + } 393 + 394 + static unsigned long __init stack_alloc_early(void) 395 + { 397 396 unsigned long stack; 398 397 399 - smp_reinit_ipl_cpu(); 400 - stack = stack_alloc(); 401 - if (!stack) 402 - panic("Couldn't allocate kernel stack"); 403 - current->stack = (void *) stack; 404 - #ifdef CONFIG_VMAP_STACK 405 - current->stack_vm_area = (void *) stack; 406 - #endif 407 - set_task_stack_end_magic(current); 408 - stack += STACK_INIT_OFFSET; 409 - S390_lowcore.kernel_stack = stack; 410 - call_on_stack_noreturn(rest_init, stack); 398 + stack = (unsigned long)memblock_alloc(THREAD_SIZE, THREAD_SIZE); 399 + if (!stack) { 400 + panic("%s: Failed to allocate %lu bytes align=0x%lx\n", 401 + __func__, THREAD_SIZE, THREAD_SIZE); 402 + } 403 + return stack; 411 404 } 412 405 413 406 static void __init setup_lowcore(void) 414 407 { 415 408 struct lowcore *lc, *abs_lc; 416 - unsigned long mcck_stack; 417 409 418 410 /* 419 411 * Setup lowcore for boot cpu ··· 425 441 lc->io_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_MCHECK; 426 442 lc->io_new_psw.addr = (unsigned long) io_int_handler; 427 443 lc->clock_comparator = clock_comparator_max; 428 - lc->nodat_stack = ((unsigned long) &init_thread_union) 429 - + THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs); 430 444 lc->current_task = (unsigned long)&init_task; 431 445 lc->lpp = LPP_MAGIC; 432 446 lc->machine_flags = S390_lowcore.machine_flags; ··· 437 455 lc->steal_timer = S390_lowcore.steal_timer; 438 456 lc->last_update_timer = S390_lowcore.last_update_timer; 439 457 lc->last_update_clock = S390_lowcore.last_update_clock; 440 - 441 458 /* 442 459 * Allocate the global restart stack which is the same for 443 - * all CPUs in cast *one* of them does a PSW restart. 460 + * all CPUs in case *one* of them does a PSW restart. 444 461 */ 445 - restart_stack = memblock_alloc(THREAD_SIZE, THREAD_SIZE); 446 - if (!restart_stack) 447 - panic("%s: Failed to allocate %lu bytes align=0x%lx\n", 448 - __func__, THREAD_SIZE, THREAD_SIZE); 449 - restart_stack += STACK_INIT_OFFSET; 450 - 462 + restart_stack = (void *)(stack_alloc_early() + STACK_INIT_OFFSET); 463 + lc->mcck_stack = stack_alloc_early() + STACK_INIT_OFFSET; 464 + lc->async_stack = stack_alloc_early() + STACK_INIT_OFFSET; 465 + lc->nodat_stack = stack_alloc_early() + STACK_INIT_OFFSET; 466 + lc->kernel_stack = S390_lowcore.kernel_stack; 451 467 /* 452 468 * Set up PSW restart to call ipl.c:do_restart(). Copy the relevant 453 469 * restart data to the absolute zero lowcore. This is necessary if ··· 456 476 lc->restart_data = 0; 457 477 lc->restart_source = -1U; 458 478 __ctl_store(lc->cregs_save_area, 0, 15); 459 - 460 - mcck_stack = (unsigned long)memblock_alloc(THREAD_SIZE, THREAD_SIZE); 461 - if (!mcck_stack) 462 - panic("%s: Failed to allocate %lu bytes align=0x%lx\n", 463 - __func__, THREAD_SIZE, THREAD_SIZE); 464 - lc->mcck_stack = mcck_stack + STACK_INIT_OFFSET; 465 - 466 479 lc->spinlock_lockval = arch_spin_lockval(0); 467 480 lc->spinlock_index = 0; 468 481 arch_spin_lock_setup(0); ··· 608 635 */ 609 636 static void __init reserve_pgtables(void) 610 637 { 611 - memblock_reserve(pgalloc_pos, pgalloc_end - pgalloc_pos); 638 + unsigned long start, end; 639 + struct reserved_range *range; 640 + 641 + for_each_physmem_reserved_type_range(RR_VMEM, range, &start, &end) 642 + memblock_reserve(start, end - start); 612 643 } 613 644 614 645 /* ··· 689 712 */ 690 713 static void __init reserve_initrd(void) 691 714 { 692 - #ifdef CONFIG_BLK_DEV_INITRD 693 - if (!initrd_data.start || !initrd_data.size) 715 + unsigned long addr, size; 716 + 717 + if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD) || !get_physmem_reserved(RR_INITRD, &addr, &size)) 694 718 return; 695 - initrd_start = (unsigned long)__va(initrd_data.start); 696 - initrd_end = initrd_start + initrd_data.size; 697 - memblock_reserve(initrd_data.start, initrd_data.size); 698 - #endif 719 + initrd_start = (unsigned long)__va(addr); 720 + initrd_end = initrd_start + size; 721 + memblock_reserve(addr, size); 699 722 } 700 723 701 724 /* ··· 707 730 memblock_reserve(ipl_cert_list_addr, ipl_cert_list_size); 708 731 } 709 732 710 - static void __init reserve_mem_detect_info(void) 733 + static void __init reserve_physmem_info(void) 711 734 { 712 - unsigned long start, size; 735 + unsigned long addr, size; 713 736 714 - get_mem_detect_reserved(&start, &size); 715 - if (size) 716 - memblock_reserve(start, size); 737 + if (get_physmem_reserved(RR_MEM_DETECT_EXTENDED, &addr, &size)) 738 + memblock_reserve(addr, size); 717 739 } 718 740 719 - static void __init free_mem_detect_info(void) 741 + static void __init free_physmem_info(void) 720 742 { 721 - unsigned long start, size; 743 + unsigned long addr, size; 722 744 723 - get_mem_detect_reserved(&start, &size); 724 - if (size) 725 - memblock_phys_free(start, size); 745 + if (get_physmem_reserved(RR_MEM_DETECT_EXTENDED, &addr, &size)) 746 + memblock_phys_free(addr, size); 726 747 } 727 748 728 - static const char * __init get_mem_info_source(void) 729 - { 730 - switch (mem_detect.info_source) { 731 - case MEM_DETECT_SCLP_STOR_INFO: 732 - return "sclp storage info"; 733 - case MEM_DETECT_DIAG260: 734 - return "diag260"; 735 - case MEM_DETECT_SCLP_READ_INFO: 736 - return "sclp read info"; 737 - case MEM_DETECT_BIN_SEARCH: 738 - return "binary search"; 739 - } 740 - return "none"; 741 - } 742 - 743 - static void __init memblock_add_mem_detect_info(void) 749 + static void __init memblock_add_physmem_info(void) 744 750 { 745 751 unsigned long start, end; 746 752 int i; 747 753 748 754 pr_debug("physmem info source: %s (%hhd)\n", 749 - get_mem_info_source(), mem_detect.info_source); 755 + get_physmem_info_source(), physmem_info.info_source); 750 756 /* keep memblock lists close to the kernel */ 751 757 memblock_set_bottom_up(true); 752 - for_each_mem_detect_usable_block(i, &start, &end) 758 + for_each_physmem_usable_range(i, &start, &end) 753 759 memblock_add(start, end - start); 754 - for_each_mem_detect_block(i, &start, &end) 760 + for_each_physmem_online_range(i, &start, &end) 755 761 memblock_physmem_add(start, end - start); 756 762 memblock_set_bottom_up(false); 757 763 memblock_set_node(0, ULONG_MAX, &memblock.memory, 0); 758 - } 759 - 760 - /* 761 - * Check for initrd being in usable memory 762 - */ 763 - static void __init check_initrd(void) 764 - { 765 - #ifdef CONFIG_BLK_DEV_INITRD 766 - if (initrd_data.start && initrd_data.size && 767 - !memblock_is_region_memory(initrd_data.start, initrd_data.size)) { 768 - pr_err("The initial RAM disk does not fit into the memory\n"); 769 - memblock_phys_free(initrd_data.start, initrd_data.size); 770 - initrd_start = initrd_end = 0; 771 - } 772 - #endif 773 764 } 774 765 775 766 /* ··· 748 803 memblock_reserve(0, STARTUP_NORMAL_OFFSET); 749 804 memblock_reserve(OLDMEM_BASE, sizeof(unsigned long)); 750 805 memblock_reserve(OLDMEM_SIZE, sizeof(unsigned long)); 751 - memblock_reserve(__amode31_base, __eamode31 - __samode31); 806 + memblock_reserve(physmem_info.reserved[RR_AMODE31].start, __eamode31 - __samode31); 752 807 memblock_reserve(__pa(sclp_early_sccb), EXT_SCCB_READ_SCP); 753 808 memblock_reserve(__pa(_stext), _end - _stext); 754 809 } ··· 770 825 static void __init relocate_amode31_section(void) 771 826 { 772 827 unsigned long amode31_size = __eamode31 - __samode31; 773 - long amode31_offset = __amode31_base - __samode31; 828 + long amode31_offset = physmem_info.reserved[RR_AMODE31].start - __samode31; 774 829 long *ptr; 775 830 776 831 pr_info("Relocating AMODE31 section of size 0x%08lx\n", amode31_size); 777 832 778 833 /* Move original AMODE31 section to the new one */ 779 - memmove((void *)__amode31_base, (void *)__samode31, amode31_size); 834 + memmove((void *)physmem_info.reserved[RR_AMODE31].start, (void *)__samode31, amode31_size); 780 835 /* Zero out the old AMODE31 section to catch invalid accesses within it */ 781 836 memset((void *)__samode31, 0, amode31_size); 782 837 ··· 942 997 reserve_kernel(); 943 998 reserve_initrd(); 944 999 reserve_certificate_list(); 945 - reserve_mem_detect_info(); 1000 + reserve_physmem_info(); 946 1001 memblock_set_current_limit(ident_map_size); 947 1002 memblock_allow_resize(); 948 1003 949 1004 /* Get information about *all* installed memory */ 950 - memblock_add_mem_detect_info(); 1005 + memblock_add_physmem_info(); 951 1006 952 - free_mem_detect_info(); 1007 + free_physmem_info(); 953 1008 setup_memory_end(); 954 1009 memblock_dump_all(); 955 1010 setup_memory(); ··· 962 1017 if (MACHINE_HAS_EDAT2) 963 1018 hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); 964 1019 965 - check_initrd(); 966 1020 reserve_crashkernel(); 967 1021 #ifdef CONFIG_CRASH_DUMP 968 1022 /*
+4 -7
arch/s390/kernel/smp.c
··· 280 280 281 281 cpu = pcpu - pcpu_devices; 282 282 lc = lowcore_ptr[cpu]; 283 - lc->kernel_stack = (unsigned long) task_stack_page(tsk) 284 - + THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs); 285 - lc->current_task = (unsigned long) tsk; 283 + lc->kernel_stack = (unsigned long)task_stack_page(tsk) + STACK_INIT_OFFSET; 284 + lc->current_task = (unsigned long)tsk; 286 285 lc->lpp = LPP_MAGIC; 287 286 lc->current_pid = tsk->pid; 288 287 lc->user_timer = tsk->thread.user_timer; ··· 347 348 abs_lc->restart_source = source_cpu; 348 349 put_abs_lowcore(abs_lc); 349 350 } 350 - __bpon(); 351 351 asm volatile( 352 352 "0: sigp 0,%0,%2 # sigp restart to target cpu\n" 353 353 " brc 2,0b # busy, try again\n" ··· 984 986 void __noreturn cpu_die(void) 985 987 { 986 988 idle_task_exit(); 987 - __bpon(); 988 989 pcpu_sigp_retry(pcpu_devices + smp_processor_id(), SIGP_STOP, 0); 989 990 for (;;) ; 990 991 } ··· 1299 1302 local_mcck_enable(); 1300 1303 local_irq_restore(flags); 1301 1304 1302 - free_pages(lc_ipl->async_stack - STACK_INIT_OFFSET, THREAD_SIZE_ORDER); 1303 1305 memblock_free_late(__pa(lc_ipl->mcck_stack - STACK_INIT_OFFSET), THREAD_SIZE); 1306 + memblock_free_late(__pa(lc_ipl->async_stack - STACK_INIT_OFFSET), THREAD_SIZE); 1307 + memblock_free_late(__pa(lc_ipl->nodat_stack - STACK_INIT_OFFSET), THREAD_SIZE); 1304 1308 memblock_free_late(__pa(lc_ipl), sizeof(*lc_ipl)); 1305 - 1306 1309 return 0; 1307 1310 }
+1 -1
arch/s390/kernel/syscalls/syscall.tbl
··· 449 449 444 common landlock_create_ruleset sys_landlock_create_ruleset sys_landlock_create_ruleset 450 450 445 common landlock_add_rule sys_landlock_add_rule sys_landlock_add_rule 451 451 446 common landlock_restrict_self sys_landlock_restrict_self sys_landlock_restrict_self 452 - # 447 reserved for memfd_secret 452 + 447 common memfd_secret sys_memfd_secret sys_memfd_secret 453 453 448 common process_mrelease sys_process_mrelease sys_process_mrelease 454 454 449 common futex_waitv sys_futex_waitv sys_futex_waitv 455 455 450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node
+31 -44
arch/s390/kernel/text_amode31.S
··· 27 27 /* 28 28 * int _diag14_amode31(unsigned long rx, unsigned long ry1, unsigned long subcode) 29 29 */ 30 - ENTRY(_diag14_amode31) 30 + SYM_FUNC_START(_diag14_amode31) 31 31 lgr %r1,%r2 32 32 lgr %r2,%r3 33 33 lgr %r3,%r4 ··· 42 42 lgfr %r2,%r5 43 43 BR_EX_AMODE31_r14 44 44 EX_TABLE_AMODE31(.Ldiag14_ex, .Ldiag14_fault) 45 - ENDPROC(_diag14_amode31) 45 + SYM_FUNC_END(_diag14_amode31) 46 46 47 47 /* 48 48 * int _diag210_amode31(struct diag210 *addr) 49 49 */ 50 - ENTRY(_diag210_amode31) 50 + SYM_FUNC_START(_diag210_amode31) 51 51 lgr %r1,%r2 52 52 lhi %r2,-1 53 53 sam31 ··· 60 60 lgfr %r2,%r2 61 61 BR_EX_AMODE31_r14 62 62 EX_TABLE_AMODE31(.Ldiag210_ex, .Ldiag210_fault) 63 - ENDPROC(_diag210_amode31) 63 + SYM_FUNC_END(_diag210_amode31) 64 64 65 65 /* 66 66 * int diag8c(struct diag8c *addr, struct ccw_dev_id *devno, size_t len) 67 67 */ 68 - ENTRY(_diag8c_amode31) 68 + SYM_FUNC_START(_diag8c_amode31) 69 69 llgf %r3,0(%r3) 70 70 sam31 71 71 diag %r2,%r4,0x8c ··· 74 74 lgfr %r2,%r3 75 75 BR_EX_AMODE31_r14 76 76 EX_TABLE_AMODE31(.Ldiag8c_ex, .Ldiag8c_ex) 77 - ENDPROC(_diag8c_amode31) 77 + SYM_FUNC_END(_diag8c_amode31) 78 78 /* 79 79 * int _diag26c_amode31(void *req, void *resp, enum diag26c_sc subcode) 80 80 */ 81 - ENTRY(_diag26c_amode31) 81 + SYM_FUNC_START(_diag26c_amode31) 82 82 lghi %r5,-EOPNOTSUPP 83 83 sam31 84 84 diag %r2,%r4,0x26c ··· 87 87 lgfr %r2,%r5 88 88 BR_EX_AMODE31_r14 89 89 EX_TABLE_AMODE31(.Ldiag26c_ex, .Ldiag26c_ex) 90 - ENDPROC(_diag26c_amode31) 90 + SYM_FUNC_END(_diag26c_amode31) 91 91 92 92 /* 93 93 * void _diag0c_amode31(struct hypfs_diag0c_entry *entry) 94 94 */ 95 - ENTRY(_diag0c_amode31) 95 + SYM_FUNC_START(_diag0c_amode31) 96 96 sam31 97 97 diag %r2,%r2,0x0c 98 98 sam64 99 99 BR_EX_AMODE31_r14 100 - ENDPROC(_diag0c_amode31) 100 + SYM_FUNC_END(_diag0c_amode31) 101 101 102 102 /* 103 103 * void _diag308_reset_amode31(void) 104 104 * 105 105 * Calls diag 308 subcode 1 and continues execution 106 106 */ 107 - ENTRY(_diag308_reset_amode31) 108 - larl %r4,.Lctlregs # Save control registers 107 + SYM_FUNC_START(_diag308_reset_amode31) 108 + larl %r4,ctlregs # Save control registers 109 109 stctg %c0,%c15,0(%r4) 110 110 lg %r2,0(%r4) # Disable lowcore protection 111 111 nilh %r2,0xefff 112 - larl %r4,.Lctlreg0 112 + larl %r4,ctlreg0 113 113 stg %r2,0(%r4) 114 114 lctlg %c0,%c0,0(%r4) 115 - larl %r4,.Lfpctl # Floating point control register 115 + larl %r4,fpctl # Floating point control register 116 116 stfpc 0(%r4) 117 - larl %r4,.Lprefix # Save prefix register 117 + larl %r4,prefix # Save prefix register 118 118 stpx 0(%r4) 119 - larl %r4,.Lprefix_zero # Set prefix register to 0 119 + larl %r4,prefix_zero # Set prefix register to 0 120 120 spx 0(%r4) 121 - larl %r4,.Lcontinue_psw # Save PSW flags 121 + larl %r4,continue_psw # Save PSW flags 122 122 epsw %r2,%r3 123 123 stm %r2,%r3,0(%r4) 124 124 larl %r4,.Lrestart_part2 # Setup restart PSW at absolute 0 125 - larl %r3,.Lrestart_diag308_psw 125 + larl %r3,restart_diag308_psw 126 126 og %r4,0(%r3) # Save PSW 127 127 lghi %r3,0 128 128 sturg %r4,%r3 # Use sturg, because of large pages ··· 134 134 lhi %r1,2 # Use mode 2 = ESAME (dump) 135 135 sigp %r1,%r0,SIGP_SET_ARCHITECTURE # Switch to ESAME mode 136 136 sam64 # Switch to 64 bit addressing mode 137 - larl %r4,.Lctlregs # Restore control registers 137 + larl %r4,ctlregs # Restore control registers 138 138 lctlg %c0,%c15,0(%r4) 139 - larl %r4,.Lfpctl # Restore floating point ctl register 139 + larl %r4,fpctl # Restore floating point ctl register 140 140 lfpc 0(%r4) 141 - larl %r4,.Lprefix # Restore prefix register 141 + larl %r4,prefix # Restore prefix register 142 142 spx 0(%r4) 143 - larl %r4,.Lcontinue_psw # Restore PSW flags 143 + larl %r4,continue_psw # Restore PSW flags 144 144 larl %r2,.Lcontinue 145 145 stg %r2,8(%r4) 146 146 lpswe 0(%r4) 147 147 .Lcontinue: 148 148 BR_EX_AMODE31_r14 149 - ENDPROC(_diag308_reset_amode31) 149 + SYM_FUNC_END(_diag308_reset_amode31) 150 150 151 151 .section .amode31.data,"aw",@progbits 152 - .align 8 153 - .Lrestart_diag308_psw: 154 - .long 0x00080000,0x80000000 155 - 156 - .align 8 157 - .Lcontinue_psw: 158 - .quad 0,0 159 - 160 - .align 8 161 - .Lctlreg0: 162 - .quad 0 163 - .Lctlregs: 164 - .rept 16 165 - .quad 0 166 - .endr 167 - .Lfpctl: 168 - .long 0 169 - .Lprefix: 170 - .long 0 171 - .Lprefix_zero: 172 - .long 0 152 + .balign 8 153 + SYM_DATA_LOCAL(restart_diag308_psw, .long 0x00080000,0x80000000) 154 + SYM_DATA_LOCAL(continue_psw, .quad 0,0) 155 + SYM_DATA_LOCAL(ctlreg0, .quad 0) 156 + SYM_DATA_LOCAL(ctlregs, .fill 16,8,0) 157 + SYM_DATA_LOCAL(fpctl, .long 0) 158 + SYM_DATA_LOCAL(prefix, .long 0) 159 + SYM_DATA_LOCAL(prefix_zero, .long 0)
+1 -11
arch/s390/kernel/topology.c
··· 637 637 { }, 638 638 }; 639 639 640 - static struct ctl_table topology_dir_table[] = { 641 - { 642 - .procname = "s390", 643 - .maxlen = 0, 644 - .mode = 0555, 645 - .child = topology_ctl_table, 646 - }, 647 - { }, 648 - }; 649 - 650 640 static int __init topology_init(void) 651 641 { 652 642 struct device *dev_root; ··· 647 657 set_topology_timer(); 648 658 else 649 659 topology_update_polarization_simple(); 650 - register_sysctl_table(topology_dir_table); 660 + register_sysctl("s390", topology_ctl_table); 651 661 652 662 dev_root = bus_get_dev_root(&cpu_subsys); 653 663 if (dev_root) {
+2 -1
arch/s390/kernel/vdso32/vdso_user_wrapper.S
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 3 + #include <linux/linkage.h> 3 4 #include <asm/unistd.h> 4 5 #include <asm/dwarf.h> 5 6 6 7 .macro vdso_syscall func,syscall 7 8 .globl __kernel_compat_\func 8 9 .type __kernel_compat_\func,@function 9 - .align 8 10 + __ALIGN 10 11 __kernel_compat_\func: 11 12 CFI_STARTPROC 12 13 svc \syscall
+3 -2
arch/s390/kernel/vdso64/vdso_user_wrapper.S
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 + #include <linux/linkage.h> 2 3 #include <asm/vdso.h> 3 4 #include <asm/unistd.h> 4 5 #include <asm/asm-offsets.h> ··· 17 16 .macro vdso_func func 18 17 .globl __kernel_\func 19 18 .type __kernel_\func,@function 20 - .align 8 19 + __ALIGN 21 20 __kernel_\func: 22 21 CFI_STARTPROC 23 22 aghi %r15,-WRAPPER_FRAME_SIZE ··· 42 41 .macro vdso_syscall func,syscall 43 42 .globl __kernel_\func 44 43 .type __kernel_\func,@function 45 - .align 8 44 + __ALIGN 46 45 __kernel_\func: 47 46 CFI_STARTPROC 48 47 svc \syscall
+9 -1
arch/s390/kernel/vmlinux.lds.S
··· 14 14 #define BSS_FIRST_SECTIONS *(.bss..swapper_pg_dir) \ 15 15 *(.bss..invalid_pg_dir) 16 16 17 + #define RO_EXCEPTION_TABLE_ALIGN 16 18 + 17 19 /* Handle ro_after_init data on our own. */ 18 20 #define RO_AFTER_INIT_DATA 19 21 ··· 68 66 *(.data..ro_after_init) 69 67 JUMP_TABLE_DATA 70 68 } :data 71 - EXCEPTION_TABLE(16) 72 69 . = ALIGN(PAGE_SIZE); 73 70 __end_ro_after_init = .; 74 71 ··· 220 219 QUAD(init_mm) 221 220 QUAD(swapper_pg_dir) 222 221 QUAD(invalid_pg_dir) 222 + #ifdef CONFIG_KASAN 223 + QUAD(kasan_early_shadow_page) 224 + QUAD(kasan_early_shadow_pte) 225 + QUAD(kasan_early_shadow_pmd) 226 + QUAD(kasan_early_shadow_pud) 227 + QUAD(kasan_early_shadow_p4d) 228 + #endif 223 229 } :NONE 224 230 225 231 /* Debugging sections. */
+17 -11
arch/s390/lib/mem.S
··· 14 14 /* 15 15 * void *memmove(void *dest, const void *src, size_t n) 16 16 */ 17 - WEAK(memmove) 18 - ENTRY(__memmove) 17 + SYM_FUNC_START(__memmove) 19 18 ltgr %r4,%r4 20 19 lgr %r1,%r2 21 20 jz .Lmemmove_exit ··· 47 48 BR_EX %r14 48 49 .Lmemmove_mvc: 49 50 mvc 0(1,%r1),0(%r3) 50 - ENDPROC(__memmove) 51 + SYM_FUNC_END(__memmove) 52 + EXPORT_SYMBOL(__memmove) 53 + 54 + SYM_FUNC_ALIAS(memmove, __memmove) 51 55 EXPORT_SYMBOL(memmove) 52 56 53 57 /* ··· 68 66 * return __builtin_memset(s, c, n); 69 67 * } 70 68 */ 71 - WEAK(memset) 72 - ENTRY(__memset) 69 + SYM_FUNC_START(__memset) 73 70 ltgr %r4,%r4 74 71 jz .Lmemset_exit 75 72 ltgr %r3,%r3 ··· 112 111 xc 0(1,%r1),0(%r1) 113 112 .Lmemset_mvc: 114 113 mvc 1(1,%r1),0(%r1) 115 - ENDPROC(__memset) 114 + SYM_FUNC_END(__memset) 115 + EXPORT_SYMBOL(__memset) 116 + 117 + SYM_FUNC_ALIAS(memset, __memset) 116 118 EXPORT_SYMBOL(memset) 117 119 118 120 /* ··· 123 119 * 124 120 * void *memcpy(void *dest, const void *src, size_t n) 125 121 */ 126 - WEAK(memcpy) 127 - ENTRY(__memcpy) 122 + SYM_FUNC_START(__memcpy) 128 123 ltgr %r4,%r4 129 124 jz .Lmemcpy_exit 130 125 aghi %r4,-1 ··· 144 141 j .Lmemcpy_remainder 145 142 .Lmemcpy_mvc: 146 143 mvc 0(1,%r1),0(%r3) 147 - ENDPROC(__memcpy) 144 + SYM_FUNC_END(__memcpy) 145 + EXPORT_SYMBOL(__memcpy) 146 + 147 + SYM_FUNC_ALIAS(memcpy, __memcpy) 148 148 EXPORT_SYMBOL(memcpy) 149 149 150 150 /* ··· 158 152 * void *__memset64(uint64_t *s, uint64_t v, size_t count) 159 153 */ 160 154 .macro __MEMSET bits,bytes,insn 161 - ENTRY(__memset\bits) 155 + SYM_FUNC_START(__memset\bits) 162 156 ltgr %r4,%r4 163 157 jz .L__memset_exit\bits 164 158 cghi %r4,\bytes ··· 184 178 BR_EX %r14 185 179 .L__memset_mvc\bits: 186 180 mvc \bytes(1,%r1),0(%r1) 187 - ENDPROC(__memset\bits) 181 + SYM_FUNC_END(__memset\bits) 188 182 .endm 189 183 190 184 __MEMSET 16,2,sth
+71 -66
arch/s390/lib/uaccess.c
··· 27 27 "kernel: %016llx user: %016llx\n", 28 28 exit ? "exit" : "entry", cr1, cr7, 29 29 S390_lowcore.kernel_asce, S390_lowcore.user_asce); 30 - 31 30 } 32 31 #endif /*CONFIG_DEBUG_ENTRY */ 33 32 34 33 static unsigned long raw_copy_from_user_key(void *to, const void __user *from, 35 34 unsigned long size, unsigned long key) 36 35 { 37 - unsigned long tmp1, tmp2; 36 + unsigned long rem; 38 37 union oac spec = { 39 38 .oac2.key = key, 40 39 .oac2.as = PSW_BITS_AS_SECONDARY, ··· 41 42 .oac2.a = 1, 42 43 }; 43 44 44 - tmp1 = -4096UL; 45 45 asm volatile( 46 - " lr 0,%[spec]\n" 47 - "0: mvcos 0(%2),0(%1),%0\n" 48 - "6: jz 4f\n" 49 - "1: algr %0,%3\n" 50 - " slgr %1,%3\n" 51 - " slgr %2,%3\n" 52 - " j 0b\n" 53 - "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */ 54 - " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */ 55 - " slgr %4,%1\n" 56 - " clgr %0,%4\n" /* copy crosses next page boundary? */ 57 - " jnh 5f\n" 58 - "3: mvcos 0(%2),0(%1),%4\n" 59 - "7: slgr %0,%4\n" 60 - " j 5f\n" 61 - "4: slgr %0,%0\n" 62 - "5:\n" 63 - EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b) 64 - : "+a" (size), "+a" (from), "+a" (to), "+a" (tmp1), "=a" (tmp2) 65 - : [spec] "d" (spec.val) 46 + " lr 0,%[spec]\n" 47 + "0: mvcos 0(%[to]),0(%[from]),%[size]\n" 48 + "1: jz 5f\n" 49 + " algr %[size],%[val]\n" 50 + " slgr %[from],%[val]\n" 51 + " slgr %[to],%[val]\n" 52 + " j 0b\n" 53 + "2: la %[rem],4095(%[from])\n" /* rem = from + 4095 */ 54 + " nr %[rem],%[val]\n" /* rem = (from + 4095) & -4096 */ 55 + " slgr %[rem],%[from]\n" 56 + " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */ 57 + " jnh 6f\n" 58 + "3: mvcos 0(%[to]),0(%[from]),%[rem]\n" 59 + "4: slgr %[size],%[rem]\n" 60 + " j 6f\n" 61 + "5: slgr %[size],%[size]\n" 62 + "6:\n" 63 + EX_TABLE(0b, 2b) 64 + EX_TABLE(1b, 2b) 65 + EX_TABLE(3b, 6b) 66 + EX_TABLE(4b, 6b) 67 + : [size] "+&a" (size), [from] "+&a" (from), [to] "+&a" (to), [rem] "=&a" (rem) 68 + : [val] "a" (-4096UL), [spec] "d" (spec.val) 66 69 : "cc", "memory", "0"); 67 70 return size; 68 71 } ··· 95 94 static unsigned long raw_copy_to_user_key(void __user *to, const void *from, 96 95 unsigned long size, unsigned long key) 97 96 { 98 - unsigned long tmp1, tmp2; 97 + unsigned long rem; 99 98 union oac spec = { 100 99 .oac1.key = key, 101 100 .oac1.as = PSW_BITS_AS_SECONDARY, ··· 103 102 .oac1.a = 1, 104 103 }; 105 104 106 - tmp1 = -4096UL; 107 105 asm volatile( 108 - " lr 0,%[spec]\n" 109 - "0: mvcos 0(%1),0(%2),%0\n" 110 - "6: jz 4f\n" 111 - "1: algr %0,%3\n" 112 - " slgr %1,%3\n" 113 - " slgr %2,%3\n" 114 - " j 0b\n" 115 - "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */ 116 - " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */ 117 - " slgr %4,%1\n" 118 - " clgr %0,%4\n" /* copy crosses next page boundary? */ 119 - " jnh 5f\n" 120 - "3: mvcos 0(%1),0(%2),%4\n" 121 - "7: slgr %0,%4\n" 122 - " j 5f\n" 123 - "4: slgr %0,%0\n" 124 - "5:\n" 125 - EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b) 126 - : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2) 127 - : [spec] "d" (spec.val) 106 + " lr 0,%[spec]\n" 107 + "0: mvcos 0(%[to]),0(%[from]),%[size]\n" 108 + "1: jz 5f\n" 109 + " algr %[size],%[val]\n" 110 + " slgr %[to],%[val]\n" 111 + " slgr %[from],%[val]\n" 112 + " j 0b\n" 113 + "2: la %[rem],4095(%[to])\n" /* rem = to + 4095 */ 114 + " nr %[rem],%[val]\n" /* rem = (to + 4095) & -4096 */ 115 + " slgr %[rem],%[to]\n" 116 + " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */ 117 + " jnh 6f\n" 118 + "3: mvcos 0(%[to]),0(%[from]),%[rem]\n" 119 + "4: slgr %[size],%[rem]\n" 120 + " j 6f\n" 121 + "5: slgr %[size],%[size]\n" 122 + "6:\n" 123 + EX_TABLE(0b, 2b) 124 + EX_TABLE(1b, 2b) 125 + EX_TABLE(3b, 6b) 126 + EX_TABLE(4b, 6b) 127 + : [size] "+&a" (size), [to] "+&a" (to), [from] "+&a" (from), [rem] "=&a" (rem) 128 + : [val] "a" (-4096UL), [spec] "d" (spec.val) 128 129 : "cc", "memory", "0"); 129 130 return size; 130 131 } ··· 150 147 151 148 unsigned long __clear_user(void __user *to, unsigned long size) 152 149 { 153 - unsigned long tmp1, tmp2; 150 + unsigned long rem; 154 151 union oac spec = { 155 152 .oac1.as = PSW_BITS_AS_SECONDARY, 156 153 .oac1.a = 1, 157 154 }; 158 155 159 - tmp1 = -4096UL; 160 156 asm volatile( 161 - " lr 0,%[spec]\n" 162 - "0: mvcos 0(%1),0(%4),%0\n" 163 - "6: jz 4f\n" 164 - "1: algr %0,%2\n" 165 - " slgr %1,%2\n" 166 - " j 0b\n" 167 - "2: la %3,4095(%1)\n"/* %4 = to + 4095 */ 168 - " nr %3,%2\n" /* %4 = (to + 4095) & -4096 */ 169 - " slgr %3,%1\n" 170 - " clgr %0,%3\n" /* copy crosses next page boundary? */ 171 - " jnh 5f\n" 172 - "3: mvcos 0(%1),0(%4),%3\n" 173 - "7: slgr %0,%3\n" 174 - " j 5f\n" 175 - "4: slgr %0,%0\n" 176 - "5:\n" 177 - EX_TABLE(0b,2b) EX_TABLE(6b,2b) EX_TABLE(3b,5b) EX_TABLE(7b,5b) 178 - : "+&a" (size), "+&a" (to), "+a" (tmp1), "=&a" (tmp2) 179 - : "a" (empty_zero_page), [spec] "d" (spec.val) 157 + " lr 0,%[spec]\n" 158 + "0: mvcos 0(%[to]),0(%[zeropg]),%[size]\n" 159 + "1: jz 5f\n" 160 + " algr %[size],%[val]\n" 161 + " slgr %[to],%[val]\n" 162 + " j 0b\n" 163 + "2: la %[rem],4095(%[to])\n" /* rem = to + 4095 */ 164 + " nr %[rem],%[val]\n" /* rem = (to + 4095) & -4096 */ 165 + " slgr %[rem],%[to]\n" 166 + " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */ 167 + " jnh 6f\n" 168 + "3: mvcos 0(%[to]),0(%[zeropg]),%[rem]\n" 169 + "4: slgr %[size],%[rem]\n" 170 + " j 6f\n" 171 + "5: slgr %[size],%[size]\n" 172 + "6:\n" 173 + EX_TABLE(0b, 2b) 174 + EX_TABLE(1b, 2b) 175 + EX_TABLE(3b, 6b) 176 + EX_TABLE(4b, 6b) 177 + : [size] "+&a" (size), [to] "+&a" (to), [rem] "=&a" (rem) 178 + : [val] "a" (-4096UL), [zeropg] "a" (empty_zero_page), [spec] "d" (spec.val) 180 179 : "cc", "memory", "0"); 181 180 return size; 182 181 }
-3
arch/s390/mm/Makefile
··· 10 10 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o 11 11 obj-$(CONFIG_PTDUMP_CORE) += dump_pagetables.o 12 12 obj-$(CONFIG_PGSTE) += gmap.o 13 - 14 - KASAN_SANITIZE_kasan_init.o := n 15 - obj-$(CONFIG_KASAN) += kasan_init.o
+1 -11
arch/s390/mm/cmm.c
··· 335 335 { } 336 336 }; 337 337 338 - static struct ctl_table cmm_dir_table[] = { 339 - { 340 - .procname = "vm", 341 - .maxlen = 0, 342 - .mode = 0555, 343 - .child = cmm_table, 344 - }, 345 - { } 346 - }; 347 - 348 338 #ifdef CONFIG_CMM_IUCV 349 339 #define SMSG_PREFIX "CMM" 350 340 static void cmm_smsg_target(const char *from, char *msg) ··· 379 389 { 380 390 int rc = -ENOMEM; 381 391 382 - cmm_sysctl_header = register_sysctl_table(cmm_dir_table); 392 + cmm_sysctl_header = register_sysctl("vm", cmm_table); 383 393 if (!cmm_sysctl_header) 384 394 goto out_sysctl; 385 395 #ifdef CONFIG_CMM_IUCV
+2 -3
arch/s390/mm/init.c
··· 176 176 177 177 void free_initmem(void) 178 178 { 179 - __set_memory((unsigned long)_sinittext, 180 - (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT, 181 - SET_MEMORY_RW | SET_MEMORY_NX); 179 + set_memory_rwnx((unsigned long)_sinittext, 180 + (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT); 182 181 free_initmem_default(POISON_FREE_INITMEM); 183 182 } 184 183
-301
arch/s390/mm/kasan_init.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - #include <linux/kasan.h> 3 - #include <linux/sched/task.h> 4 - #include <linux/pgtable.h> 5 - #include <asm/pgalloc.h> 6 - #include <asm/kasan.h> 7 - #include <asm/mem_detect.h> 8 - #include <asm/processor.h> 9 - #include <asm/sclp.h> 10 - #include <asm/facility.h> 11 - #include <asm/sections.h> 12 - #include <asm/setup.h> 13 - #include <asm/uv.h> 14 - 15 - static unsigned long segment_pos __initdata; 16 - static unsigned long segment_low __initdata; 17 - static bool has_edat __initdata; 18 - static bool has_nx __initdata; 19 - 20 - #define __sha(x) ((unsigned long)kasan_mem_to_shadow((void *)x)) 21 - 22 - static void __init kasan_early_panic(const char *reason) 23 - { 24 - sclp_early_printk("The Linux kernel failed to boot with the KernelAddressSanitizer:\n"); 25 - sclp_early_printk(reason); 26 - disabled_wait(); 27 - } 28 - 29 - static void * __init kasan_early_alloc_segment(void) 30 - { 31 - segment_pos -= _SEGMENT_SIZE; 32 - 33 - if (segment_pos < segment_low) 34 - kasan_early_panic("out of memory during initialisation\n"); 35 - 36 - return __va(segment_pos); 37 - } 38 - 39 - static void * __init kasan_early_alloc_pages(unsigned int order) 40 - { 41 - pgalloc_pos -= (PAGE_SIZE << order); 42 - 43 - if (pgalloc_pos < pgalloc_low) 44 - kasan_early_panic("out of memory during initialisation\n"); 45 - 46 - return __va(pgalloc_pos); 47 - } 48 - 49 - static void * __init kasan_early_crst_alloc(unsigned long val) 50 - { 51 - unsigned long *table; 52 - 53 - table = kasan_early_alloc_pages(CRST_ALLOC_ORDER); 54 - if (table) 55 - crst_table_init(table, val); 56 - return table; 57 - } 58 - 59 - static pte_t * __init kasan_early_pte_alloc(void) 60 - { 61 - static void *pte_leftover; 62 - pte_t *pte; 63 - 64 - BUILD_BUG_ON(_PAGE_TABLE_SIZE * 2 != PAGE_SIZE); 65 - 66 - if (!pte_leftover) { 67 - pte_leftover = kasan_early_alloc_pages(0); 68 - pte = pte_leftover + _PAGE_TABLE_SIZE; 69 - } else { 70 - pte = pte_leftover; 71 - pte_leftover = NULL; 72 - } 73 - memset64((u64 *)pte, _PAGE_INVALID, PTRS_PER_PTE); 74 - return pte; 75 - } 76 - 77 - enum populate_mode { 78 - POPULATE_MAP, 79 - POPULATE_ZERO_SHADOW, 80 - POPULATE_SHALLOW 81 - }; 82 - 83 - static inline pgprot_t pgprot_clear_bit(pgprot_t pgprot, unsigned long bit) 84 - { 85 - return __pgprot(pgprot_val(pgprot) & ~bit); 86 - } 87 - 88 - static void __init kasan_early_pgtable_populate(unsigned long address, 89 - unsigned long end, 90 - enum populate_mode mode) 91 - { 92 - pgprot_t pgt_prot_zero = PAGE_KERNEL_RO; 93 - pgprot_t pgt_prot = PAGE_KERNEL; 94 - pgprot_t sgt_prot = SEGMENT_KERNEL; 95 - pgd_t *pg_dir; 96 - p4d_t *p4_dir; 97 - pud_t *pu_dir; 98 - pmd_t *pm_dir; 99 - pte_t *pt_dir; 100 - pmd_t pmd; 101 - pte_t pte; 102 - 103 - if (!has_nx) { 104 - pgt_prot_zero = pgprot_clear_bit(pgt_prot_zero, _PAGE_NOEXEC); 105 - pgt_prot = pgprot_clear_bit(pgt_prot, _PAGE_NOEXEC); 106 - sgt_prot = pgprot_clear_bit(sgt_prot, _SEGMENT_ENTRY_NOEXEC); 107 - } 108 - 109 - while (address < end) { 110 - pg_dir = pgd_offset_k(address); 111 - if (pgd_none(*pg_dir)) { 112 - if (mode == POPULATE_ZERO_SHADOW && 113 - IS_ALIGNED(address, PGDIR_SIZE) && 114 - end - address >= PGDIR_SIZE) { 115 - pgd_populate(&init_mm, pg_dir, 116 - kasan_early_shadow_p4d); 117 - address = (address + PGDIR_SIZE) & PGDIR_MASK; 118 - continue; 119 - } 120 - p4_dir = kasan_early_crst_alloc(_REGION2_ENTRY_EMPTY); 121 - pgd_populate(&init_mm, pg_dir, p4_dir); 122 - } 123 - 124 - if (mode == POPULATE_SHALLOW) { 125 - address = (address + P4D_SIZE) & P4D_MASK; 126 - continue; 127 - } 128 - 129 - p4_dir = p4d_offset(pg_dir, address); 130 - if (p4d_none(*p4_dir)) { 131 - if (mode == POPULATE_ZERO_SHADOW && 132 - IS_ALIGNED(address, P4D_SIZE) && 133 - end - address >= P4D_SIZE) { 134 - p4d_populate(&init_mm, p4_dir, 135 - kasan_early_shadow_pud); 136 - address = (address + P4D_SIZE) & P4D_MASK; 137 - continue; 138 - } 139 - pu_dir = kasan_early_crst_alloc(_REGION3_ENTRY_EMPTY); 140 - p4d_populate(&init_mm, p4_dir, pu_dir); 141 - } 142 - 143 - pu_dir = pud_offset(p4_dir, address); 144 - if (pud_none(*pu_dir)) { 145 - if (mode == POPULATE_ZERO_SHADOW && 146 - IS_ALIGNED(address, PUD_SIZE) && 147 - end - address >= PUD_SIZE) { 148 - pud_populate(&init_mm, pu_dir, 149 - kasan_early_shadow_pmd); 150 - address = (address + PUD_SIZE) & PUD_MASK; 151 - continue; 152 - } 153 - pm_dir = kasan_early_crst_alloc(_SEGMENT_ENTRY_EMPTY); 154 - pud_populate(&init_mm, pu_dir, pm_dir); 155 - } 156 - 157 - pm_dir = pmd_offset(pu_dir, address); 158 - if (pmd_none(*pm_dir)) { 159 - if (IS_ALIGNED(address, PMD_SIZE) && 160 - end - address >= PMD_SIZE) { 161 - if (mode == POPULATE_ZERO_SHADOW) { 162 - pmd_populate(&init_mm, pm_dir, kasan_early_shadow_pte); 163 - address = (address + PMD_SIZE) & PMD_MASK; 164 - continue; 165 - } else if (has_edat) { 166 - void *page = kasan_early_alloc_segment(); 167 - 168 - memset(page, 0, _SEGMENT_SIZE); 169 - pmd = __pmd(__pa(page)); 170 - pmd = set_pmd_bit(pmd, sgt_prot); 171 - set_pmd(pm_dir, pmd); 172 - address = (address + PMD_SIZE) & PMD_MASK; 173 - continue; 174 - } 175 - } 176 - pt_dir = kasan_early_pte_alloc(); 177 - pmd_populate(&init_mm, pm_dir, pt_dir); 178 - } else if (pmd_large(*pm_dir)) { 179 - address = (address + PMD_SIZE) & PMD_MASK; 180 - continue; 181 - } 182 - 183 - pt_dir = pte_offset_kernel(pm_dir, address); 184 - if (pte_none(*pt_dir)) { 185 - void *page; 186 - 187 - switch (mode) { 188 - case POPULATE_MAP: 189 - page = kasan_early_alloc_pages(0); 190 - memset(page, 0, PAGE_SIZE); 191 - pte = __pte(__pa(page)); 192 - pte = set_pte_bit(pte, pgt_prot); 193 - set_pte(pt_dir, pte); 194 - break; 195 - case POPULATE_ZERO_SHADOW: 196 - page = kasan_early_shadow_page; 197 - pte = __pte(__pa(page)); 198 - pte = set_pte_bit(pte, pgt_prot_zero); 199 - set_pte(pt_dir, pte); 200 - break; 201 - case POPULATE_SHALLOW: 202 - /* should never happen */ 203 - break; 204 - } 205 - } 206 - address += PAGE_SIZE; 207 - } 208 - } 209 - 210 - static void __init kasan_early_detect_facilities(void) 211 - { 212 - if (test_facility(8)) { 213 - has_edat = true; 214 - __ctl_set_bit(0, 23); 215 - } 216 - if (!noexec_disabled && test_facility(130)) { 217 - has_nx = true; 218 - __ctl_set_bit(0, 20); 219 - } 220 - } 221 - 222 - void __init kasan_early_init(void) 223 - { 224 - pte_t pte_z = __pte(__pa(kasan_early_shadow_page) | pgprot_val(PAGE_KERNEL_RO)); 225 - pmd_t pmd_z = __pmd(__pa(kasan_early_shadow_pte) | _SEGMENT_ENTRY); 226 - pud_t pud_z = __pud(__pa(kasan_early_shadow_pmd) | _REGION3_ENTRY); 227 - p4d_t p4d_z = __p4d(__pa(kasan_early_shadow_pud) | _REGION2_ENTRY); 228 - unsigned long untracked_end = MODULES_VADDR; 229 - unsigned long shadow_alloc_size; 230 - unsigned long start, end; 231 - int i; 232 - 233 - kasan_early_detect_facilities(); 234 - if (!has_nx) 235 - pte_z = clear_pte_bit(pte_z, __pgprot(_PAGE_NOEXEC)); 236 - 237 - BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_START, P4D_SIZE)); 238 - BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, P4D_SIZE)); 239 - 240 - /* init kasan zero shadow */ 241 - crst_table_init((unsigned long *)kasan_early_shadow_p4d, p4d_val(p4d_z)); 242 - crst_table_init((unsigned long *)kasan_early_shadow_pud, pud_val(pud_z)); 243 - crst_table_init((unsigned long *)kasan_early_shadow_pmd, pmd_val(pmd_z)); 244 - memset64((u64 *)kasan_early_shadow_pte, pte_val(pte_z), PTRS_PER_PTE); 245 - 246 - if (has_edat) { 247 - shadow_alloc_size = get_mem_detect_usable_total() >> KASAN_SHADOW_SCALE_SHIFT; 248 - segment_pos = round_down(pgalloc_pos, _SEGMENT_SIZE); 249 - segment_low = segment_pos - shadow_alloc_size; 250 - segment_low = round_down(segment_low, _SEGMENT_SIZE); 251 - pgalloc_pos = segment_low; 252 - } 253 - /* 254 - * Current memory layout: 255 - * +- 0 -------------+ +- shadow start -+ 256 - * |1:1 ident mapping| /|1/8 of ident map| 257 - * | | / | | 258 - * +-end of ident map+ / +----------------+ 259 - * | ... gap ... | / | kasan | 260 - * | | / | zero page | 261 - * +- vmalloc area -+ / | mapping | 262 - * | vmalloc_size | / | (untracked) | 263 - * +- modules vaddr -+ / +----------------+ 264 - * | 2Gb |/ | unmapped | allocated per module 265 - * +- shadow start -+ +----------------+ 266 - * | 1/8 addr space | | zero pg mapping| (untracked) 267 - * +- shadow end ----+---------+- shadow end ---+ 268 - * 269 - * Current memory layout (KASAN_VMALLOC): 270 - * +- 0 -------------+ +- shadow start -+ 271 - * |1:1 ident mapping| /|1/8 of ident map| 272 - * | | / | | 273 - * +-end of ident map+ / +----------------+ 274 - * | ... gap ... | / | kasan zero page| (untracked) 275 - * | | / | mapping | 276 - * +- vmalloc area -+ / +----------------+ 277 - * | vmalloc_size | / |shallow populate| 278 - * +- modules vaddr -+ / +----------------+ 279 - * | 2Gb |/ |shallow populate| 280 - * +- shadow start -+ +----------------+ 281 - * | 1/8 addr space | | zero pg mapping| (untracked) 282 - * +- shadow end ----+---------+- shadow end ---+ 283 - */ 284 - /* populate kasan shadow (for identity mapping and zero page mapping) */ 285 - for_each_mem_detect_usable_block(i, &start, &end) 286 - kasan_early_pgtable_populate(__sha(start), __sha(end), POPULATE_MAP); 287 - if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) { 288 - untracked_end = VMALLOC_START; 289 - /* shallowly populate kasan shadow for vmalloc and modules */ 290 - kasan_early_pgtable_populate(__sha(VMALLOC_START), __sha(MODULES_END), 291 - POPULATE_SHALLOW); 292 - } 293 - /* populate kasan shadow for untracked memory */ 294 - kasan_early_pgtable_populate(__sha(ident_map_size), __sha(untracked_end), 295 - POPULATE_ZERO_SHADOW); 296 - kasan_early_pgtable_populate(__sha(MODULES_END), __sha(_REGION1_SIZE), 297 - POPULATE_ZERO_SHADOW); 298 - /* enable kasan */ 299 - init_task.kasan_depth = 0; 300 - sclp_early_printk("KernelAddressSanitizer initialized\n"); 301 - }
+86 -8
arch/s390/mm/pageattr.c
··· 4 4 * Author(s): Jan Glauber <jang@linux.vnet.ibm.com> 5 5 */ 6 6 #include <linux/hugetlb.h> 7 + #include <linux/vmalloc.h> 7 8 #include <linux/mm.h> 8 9 #include <asm/cacheflush.h> 9 10 #include <asm/facility.h> ··· 42 41 } 43 42 44 43 #ifdef CONFIG_PROC_FS 45 - atomic_long_t direct_pages_count[PG_DIRECT_MAP_MAX]; 44 + atomic_long_t __bootdata_preserved(direct_pages_count[PG_DIRECT_MAP_MAX]); 46 45 47 46 void arch_report_meminfo(struct seq_file *m) 48 47 { ··· 102 101 new = set_pte_bit(new, __pgprot(_PAGE_NOEXEC)); 103 102 else if (flags & SET_MEMORY_X) 104 103 new = clear_pte_bit(new, __pgprot(_PAGE_NOEXEC)); 104 + if (flags & SET_MEMORY_INV) { 105 + new = set_pte_bit(new, __pgprot(_PAGE_INVALID)); 106 + } else if (flags & SET_MEMORY_DEF) { 107 + new = __pte(pte_val(new) & PAGE_MASK); 108 + new = set_pte_bit(new, PAGE_KERNEL); 109 + if (!MACHINE_HAS_NX) 110 + new = clear_pte_bit(new, __pgprot(_PAGE_NOEXEC)); 111 + } 105 112 pgt_set((unsigned long *)ptep, pte_val(new), addr, CRDTE_DTT_PAGE); 106 113 ptep++; 107 114 addr += PAGE_SIZE; ··· 160 151 new = set_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_NOEXEC)); 161 152 else if (flags & SET_MEMORY_X) 162 153 new = clear_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_NOEXEC)); 154 + if (flags & SET_MEMORY_INV) { 155 + new = set_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_INVALID)); 156 + } else if (flags & SET_MEMORY_DEF) { 157 + new = __pmd(pmd_val(new) & PMD_MASK); 158 + new = set_pmd_bit(new, SEGMENT_KERNEL); 159 + if (!MACHINE_HAS_NX) 160 + new = clear_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_NOEXEC)); 161 + } 163 162 pgt_set((unsigned long *)pmdp, pmd_val(new), addr, CRDTE_DTT_SEGMENT); 164 163 } 165 164 ··· 249 232 new = set_pud_bit(new, __pgprot(_REGION_ENTRY_NOEXEC)); 250 233 else if (flags & SET_MEMORY_X) 251 234 new = clear_pud_bit(new, __pgprot(_REGION_ENTRY_NOEXEC)); 235 + if (flags & SET_MEMORY_INV) { 236 + new = set_pud_bit(new, __pgprot(_REGION_ENTRY_INVALID)); 237 + } else if (flags & SET_MEMORY_DEF) { 238 + new = __pud(pud_val(new) & PUD_MASK); 239 + new = set_pud_bit(new, REGION3_KERNEL); 240 + if (!MACHINE_HAS_NX) 241 + new = clear_pud_bit(new, __pgprot(_REGION_ENTRY_NOEXEC)); 242 + } 252 243 pgt_set((unsigned long *)pudp, pud_val(new), addr, CRDTE_DTT_REGION3); 253 244 } 254 245 ··· 323 298 int rc = -EINVAL; 324 299 pgd_t *pgdp; 325 300 326 - if (addr == end) 327 - return 0; 328 - if (end >= MODULES_END) 329 - return -EINVAL; 330 - mutex_lock(&cpa_mutex); 331 301 pgdp = pgd_offset_k(addr); 332 302 do { 333 303 if (pgd_none(*pgdp)) ··· 333 313 break; 334 314 cond_resched(); 335 315 } while (pgdp++, addr = next, addr < end && !rc); 336 - mutex_unlock(&cpa_mutex); 316 + return rc; 317 + } 318 + 319 + static int change_page_attr_alias(unsigned long addr, unsigned long end, 320 + unsigned long flags) 321 + { 322 + unsigned long alias, offset, va_start, va_end; 323 + struct vm_struct *area; 324 + int rc = 0; 325 + 326 + /* 327 + * Changes to read-only permissions on kernel VA mappings are also 328 + * applied to the kernel direct mapping. Execute permissions are 329 + * intentionally not transferred to keep all allocated pages within 330 + * the direct mapping non-executable. 331 + */ 332 + flags &= SET_MEMORY_RO | SET_MEMORY_RW; 333 + if (!flags) 334 + return 0; 335 + area = NULL; 336 + while (addr < end) { 337 + if (!area) 338 + area = find_vm_area((void *)addr); 339 + if (!area || !(area->flags & VM_ALLOC)) 340 + return 0; 341 + va_start = (unsigned long)area->addr; 342 + va_end = va_start + area->nr_pages * PAGE_SIZE; 343 + offset = (addr - va_start) >> PAGE_SHIFT; 344 + alias = (unsigned long)page_address(area->pages[offset]); 345 + rc = change_page_attr(alias, alias + PAGE_SIZE, flags); 346 + if (rc) 347 + break; 348 + addr += PAGE_SIZE; 349 + if (addr >= va_end) 350 + area = NULL; 351 + } 337 352 return rc; 338 353 } 339 354 340 355 int __set_memory(unsigned long addr, int numpages, unsigned long flags) 341 356 { 357 + unsigned long end; 358 + int rc; 359 + 342 360 if (!MACHINE_HAS_NX) 343 361 flags &= ~(SET_MEMORY_NX | SET_MEMORY_X); 344 362 if (!flags) 345 363 return 0; 364 + if (!numpages) 365 + return 0; 346 366 addr &= PAGE_MASK; 347 - return change_page_attr(addr, addr + numpages * PAGE_SIZE, flags); 367 + end = addr + numpages * PAGE_SIZE; 368 + mutex_lock(&cpa_mutex); 369 + rc = change_page_attr(addr, end, flags); 370 + if (rc) 371 + goto out; 372 + rc = change_page_attr_alias(addr, end, flags); 373 + out: 374 + mutex_unlock(&cpa_mutex); 375 + return rc; 376 + } 377 + 378 + int set_direct_map_invalid_noflush(struct page *page) 379 + { 380 + return __set_memory((unsigned long)page_to_virt(page), 1, SET_MEMORY_INV); 381 + } 382 + 383 + int set_direct_map_default_noflush(struct page *page) 384 + { 385 + return __set_memory((unsigned long)page_to_virt(page), 1, SET_MEMORY_DEF); 348 386 } 349 387 350 388 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE)
+2 -18
arch/s390/mm/pgalloc.c
··· 33 33 { } 34 34 }; 35 35 36 - static struct ctl_table page_table_sysctl_dir[] = { 37 - { 38 - .procname = "vm", 39 - .maxlen = 0, 40 - .mode = 0555, 41 - .child = page_table_sysctl, 42 - }, 43 - { } 44 - }; 45 - 46 36 static int __init page_table_register_sysctl(void) 47 37 { 48 - return register_sysctl_table(page_table_sysctl_dir) ? 0 : -ENOMEM; 38 + return register_sysctl("vm", page_table_sysctl) ? 0 : -ENOMEM; 49 39 } 50 40 __initcall(page_table_register_sysctl); 51 41 ··· 133 143 134 144 static inline unsigned int atomic_xor_bits(atomic_t *v, unsigned int bits) 135 145 { 136 - unsigned int old, new; 137 - 138 - do { 139 - old = atomic_read(v); 140 - new = old ^ bits; 141 - } while (atomic_cmpxchg(v, old, new) != old); 142 - return new; 146 + return atomic_fetch_xor(bits, v) ^ bits; 143 147 } 144 148 145 149 #ifdef CONFIG_PGSTE
+20 -15
arch/s390/mm/vmem.c
··· 5 5 6 6 #include <linux/memory_hotplug.h> 7 7 #include <linux/memblock.h> 8 + #include <linux/kasan.h> 8 9 #include <linux/pfn.h> 9 10 #include <linux/mm.h> 10 11 #include <linux/init.h> ··· 665 664 swap(*(struct memblock_region *)a, *(struct memblock_region *)b); 666 665 } 667 666 667 + #ifdef CONFIG_KASAN 668 + #define __sha(x) ((unsigned long)kasan_mem_to_shadow((void *)x)) 669 + #endif 668 670 /* 669 671 * map whole physical memory to virtual memory (identity mapping) 670 672 * we reserve enough space in the vmalloc area for vmemmap to hotplug ··· 732 728 memblock_region_cmp, memblock_region_swap); 733 729 __for_each_mem_range(i, &memblock.memory, &memory_rwx, 734 730 NUMA_NO_NODE, MEMBLOCK_NONE, &base, &end, NULL) { 735 - __set_memory((unsigned long)__va(base), 736 - (end - base) >> PAGE_SHIFT, 737 - SET_MEMORY_RW | SET_MEMORY_NX); 731 + set_memory_rwnx((unsigned long)__va(base), 732 + (end - base) >> PAGE_SHIFT); 738 733 } 739 734 740 - __set_memory((unsigned long)_stext, 741 - (unsigned long)(_etext - _stext) >> PAGE_SHIFT, 742 - SET_MEMORY_RO | SET_MEMORY_X); 743 - __set_memory((unsigned long)_etext, 744 - (unsigned long)(__end_rodata - _etext) >> PAGE_SHIFT, 745 - SET_MEMORY_RO); 746 - __set_memory((unsigned long)_sinittext, 747 - (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT, 748 - SET_MEMORY_RO | SET_MEMORY_X); 749 - __set_memory(__stext_amode31, 750 - (__etext_amode31 - __stext_amode31) >> PAGE_SHIFT, 751 - SET_MEMORY_RO | SET_MEMORY_X); 735 + #ifdef CONFIG_KASAN 736 + for_each_mem_range(i, &base, &end) { 737 + set_memory_rwnx(__sha(base), 738 + (__sha(end) - __sha(base)) >> PAGE_SHIFT); 739 + } 740 + #endif 741 + set_memory_rox((unsigned long)_stext, 742 + (unsigned long)(_etext - _stext) >> PAGE_SHIFT); 743 + set_memory_ro((unsigned long)_etext, 744 + (unsigned long)(__end_rodata - _etext) >> PAGE_SHIFT); 745 + set_memory_rox((unsigned long)_sinittext, 746 + (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT); 747 + set_memory_rox(__stext_amode31, 748 + (__etext_amode31 - __stext_amode31) >> PAGE_SHIFT); 752 749 753 750 /* lowcore must be executable for LPSWE */ 754 751 if (static_key_enabled(&cpu_has_bear))
+3 -20
arch/s390/pci/pci.c
··· 874 874 * @fh: The general function handle supplied by the platform 875 875 * 876 876 * Given a device in the configuration state Configured, enables, scans and 877 - * adds it to the common code PCI subsystem if possible. If the PCI device is 878 - * parked because we can not yet create a PCI bus because we have not seen 879 - * function 0, it is ignored but will be scanned once function 0 appears. 880 - * If any failure occurs, the zpci_dev is left disabled. 877 + * adds it to the common code PCI subsystem if possible. If any failure occurs, 878 + * the zpci_dev is left disabled. 881 879 * 882 880 * Return: 0 on success, or an error code otherwise 883 881 */ 884 882 int zpci_scan_configured_device(struct zpci_dev *zdev, u32 fh) 885 883 { 886 - int rc; 887 - 888 884 zpci_update_fh(zdev, fh); 889 - /* the PCI function will be scanned once function 0 appears */ 890 - if (!zdev->zbus->bus) 891 - return 0; 892 - 893 - /* For function 0 on a multi-function bus scan whole bus as we might 894 - * have to pick up existing functions waiting for it to allow creating 895 - * the PCI bus 896 - */ 897 - if (zdev->devfn == 0 && zdev->zbus->multifunction) 898 - rc = zpci_bus_scan_bus(zdev->zbus); 899 - else 900 - rc = zpci_bus_scan_device(zdev); 901 - 902 - return rc; 885 + return zpci_bus_scan_device(zdev); 903 886 } 904 887 905 888 /**
+3 -8
arch/s390/pci/pci_bus.c
··· 85 85 if (!pdev) 86 86 return -ENODEV; 87 87 88 - pci_bus_add_device(pdev); 89 88 pci_lock_rescan_remove(); 90 - pci_bus_add_devices(zdev->zbus->bus); 89 + pci_bus_add_device(pdev); 91 90 pci_unlock_rescan_remove(); 92 91 93 92 return 0; ··· 129 130 * @zbus: the zbus to be scanned 130 131 * 131 132 * Enables and scans all PCI functions on the bus making them available to the 132 - * common PCI code. If there is no function 0 on the zbus nothing is scanned. If 133 - * a function does not have a slot yet because it was added to the zbus before 134 - * function 0 the slot is created. If a PCI function fails to be initialized 135 - * an error will be returned but attempts will still be made for all other 136 - * functions on the bus. 133 + * common PCI code. If a PCI function fails to be initialized an error will be 134 + * returned but attempts will still be made for all other functions on the bus. 137 135 * 138 136 * Return: 0 on success, an error value otherwise 139 137 */ ··· 207 211 } 208 212 209 213 zbus->bus = bus; 210 - pci_bus_add_devices(bus); 211 214 212 215 return 0; 213 216 }
+18 -42
arch/s390/purgatory/head.S
··· 76 76 diag %r0,%r1,0x308 77 77 .endm 78 78 79 - .text 80 - .align PAGE_SIZE 81 - ENTRY(purgatory_start) 79 + .text 80 + .balign PAGE_SIZE 81 + SYM_CODE_START(purgatory_start) 82 82 /* The purgatory might be called after a diag308 so better set 83 83 * architecture and addressing mode. 84 84 */ ··· 245 245 246 246 /* start crash kernel */ 247 247 START_NEXT_KERNEL .base_dst 1 248 + SYM_CODE_END(purgatory_start) 248 249 249 - 250 - load_psw_mask: 251 - .long 0x00080000,0x80000000 252 - 253 - .align 8 254 - disabled_wait_psw: 255 - .quad 0x0002000180000000 256 - .quad 0x0000000000000000 + .do_checksum_verification 257 - 258 - gprregs: 259 - .rept 10 260 - .quad 0 261 - .endr 262 - 263 - /* Macro to define a global variable with name and size (in bytes) to be 264 - * shared with C code. 265 - * 266 - * Add the .size and .type attribute to satisfy checks on the Elf_Sym during 267 - * purgatory load. 268 - */ 269 - .macro GLOBAL_VARIABLE name,size 270 - \name: 271 - .global \name 272 - .size \name,\size 273 - .type \name,object 274 - .skip \size,0 275 - .endm 276 - 277 - GLOBAL_VARIABLE purgatory_sha256_digest,32 278 - GLOBAL_VARIABLE purgatory_sha_regions,16*__KEXEC_SHA_REGION_SIZE 279 - GLOBAL_VARIABLE kernel_entry,8 280 - GLOBAL_VARIABLE kernel_type,8 281 - GLOBAL_VARIABLE crash_start,8 282 - GLOBAL_VARIABLE crash_size,8 283 - 284 - .align PAGE_SIZE 285 - stack: 250 + SYM_DATA_LOCAL(load_psw_mask, .long 0x00080000,0x80000000) 251 + .balign 8 252 + SYM_DATA_LOCAL(disabled_wait_psw, .quad 0x0002000180000000,.do_checksum_verification) 253 + SYM_DATA_LOCAL(gprregs, .fill 10,8,0) 254 + SYM_DATA(purgatory_sha256_digest, .skip 32) 255 + SYM_DATA(purgatory_sha_regions, .skip 16*__KEXEC_SHA_REGION_SIZE) 256 + SYM_DATA(kernel_entry, .skip 8) 257 + SYM_DATA(kernel_type, .skip 8) 258 + SYM_DATA(crash_start, .skip 8) 259 + SYM_DATA(crash_size, .skip 8) 260 + .balign PAGE_SIZE 261 + SYM_DATA_START_LOCAL(stack) 286 262 /* The buffer to move this code must be as big as the code. */ 287 263 .skip stack-purgatory_start 288 - .align PAGE_SIZE 289 - purgatory_end: 264 + .balign PAGE_SIZE 265 + SYM_DATA_END_LABEL(stack, SYM_L_LOCAL, purgatory_end)
+6 -8
arch/s390/purgatory/kexec-purgatory.S
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 + #include <linux/linkage.h> 2 3 3 4 .section .rodata, "a" 4 5 5 - .align 8 6 - kexec_purgatory: 7 - .globl kexec_purgatory 6 + .balign 8 7 + SYM_DATA_START(kexec_purgatory) 8 8 .incbin "arch/s390/purgatory/purgatory.ro" 9 - .Lkexec_purgatroy_end: 9 + SYM_DATA_END_LABEL(kexec_purgatory, SYM_L_LOCAL, kexec_purgatory_end) 10 10 11 - .align 8 12 - kexec_purgatory_size: 13 - .globl kexec_purgatory_size 14 - .quad .Lkexec_purgatroy_end - kexec_purgatory 11 + .balign 8 12 + SYM_DATA(kexec_purgatory_size, .quad kexec_purgatory_end-kexec_purgatory)
+1 -1
drivers/s390/char/sclp.h
··· 204 204 u16 assigned; 205 205 u16 standby; 206 206 u16 :16; 207 - u32 entries[0]; 207 + u32 entries[]; 208 208 } __packed; 209 209 210 210 static inline void sclp_fill_core_info(struct sclp_core_info *info,
+1 -1
drivers/s390/char/sclp_cmd.c
··· 241 241 u16 :16; 242 242 u16 assigned; 243 243 u32 :32; 244 - u32 entries[0]; 244 + u32 entries[]; 245 245 } __packed; 246 246 247 247 static int sclp_attach_storage(u8 id)
+4 -4
drivers/s390/char/sclp_early_core.c
··· 10 10 #include <asm/ebcdic.h> 11 11 #include <asm/irq.h> 12 12 #include <asm/sections.h> 13 - #include <asm/mem_detect.h> 13 + #include <asm/physmem_info.h> 14 14 #include <asm/facility.h> 15 15 #include "sclp.h" 16 16 #include "sclp_rw.h" ··· 336 336 337 337 #define SCLP_STORAGE_INFO_FACILITY 0x0000400000000000UL 338 338 339 - void __weak __init add_mem_detect_block(u64 start, u64 end) {} 339 + void __weak __init add_physmem_online_range(u64 start, u64 end) {} 340 340 int __init sclp_early_read_storage_info(void) 341 341 { 342 342 struct read_storage_sccb *sccb = (struct read_storage_sccb *)sclp_early_sccb; ··· 369 369 if (!sccb->entries[sn]) 370 370 continue; 371 371 rn = sccb->entries[sn] >> 16; 372 - add_mem_detect_block((rn - 1) * rzm, rn * rzm); 372 + add_physmem_online_range((rn - 1) * rzm, rn * rzm); 373 373 } 374 374 break; 375 375 case 0x0310: ··· 382 382 383 383 return 0; 384 384 fail: 385 - mem_detect.count = 0; 385 + physmem_info.range_count = 0; 386 386 return -EIO; 387 387 }
+1 -1
drivers/s390/cio/chsc.c
··· 1171 1171 u8 cssid; 1172 1172 u8 iid; 1173 1173 u32 : 16; 1174 - } list[0]; 1174 + } list[]; 1175 1175 } *sdcal_area; 1176 1176 int ret; 1177 1177
+1 -1
drivers/s390/cio/chsc.h
··· 120 120 u32 zeroes1; 121 121 struct chsc_header response; 122 122 u32:32; 123 - u8 data[0]; 123 + u8 data[]; 124 124 } __packed __aligned(PAGE_SIZE); 125 125 126 126 struct chsc_sda_area {
+153 -105
drivers/s390/crypto/ap_bus.c
··· 122 122 * In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds. 123 123 * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling. 124 124 */ 125 - static unsigned long long poll_timeout = 250000; 125 + static unsigned long poll_high_timeout = 250000UL; 126 + 127 + /* 128 + * Some state machine states only require a low frequency polling. 129 + * We use 25 Hz frequency for these. 130 + */ 131 + static unsigned long poll_low_timeout = 40000000UL; 126 132 127 133 /* Maximum domain id, if not given via qci */ 128 134 static int ap_max_domain_id = 15; ··· 207 201 } 208 202 209 203 /* 204 + * ap_sb_available(): Test if the AP secure binding facility is available. 205 + * 206 + * Returns 1 if secure binding facility is available. 207 + */ 208 + int ap_sb_available(void) 209 + { 210 + if (ap_qci_info) 211 + return ap_qci_info->apsb; 212 + return 0; 213 + } 214 + 215 + /* 210 216 * ap_fetch_qci_info(): Fetch cryptographic config info 211 217 * 212 218 * Returns the ap configuration info fetched via PQAP(QCI). ··· 266 248 AP_DBF_INFO("%s successful fetched initial qci info\n", __func__); 267 249 268 250 if (ap_qci_info->apxa) { 269 - if (ap_qci_info->Na) { 270 - ap_max_adapter_id = ap_qci_info->Na; 251 + if (ap_qci_info->na) { 252 + ap_max_adapter_id = ap_qci_info->na; 271 253 AP_DBF_INFO("%s new ap_max_adapter_id is %d\n", 272 254 __func__, ap_max_adapter_id); 273 255 } 274 - if (ap_qci_info->Nd) { 275 - ap_max_domain_id = ap_qci_info->Nd; 256 + if (ap_qci_info->nd) { 257 + ap_max_domain_id = ap_qci_info->nd; 276 258 AP_DBF_INFO("%s new ap_max_domain_id is %d\n", 277 259 __func__, ap_max_domain_id); 278 260 } ··· 342 324 343 325 /* 344 326 * ap_queue_info(): Check and get AP queue info. 345 - * Returns true if TAPQ succeeded and the info is filled or 346 - * false otherwise. 327 + * Returns: 1 if APQN exists and info is filled, 328 + * 0 if APQN seems to exit but there is no info 329 + * available (eg. caused by an asynch pending error) 330 + * -1 invalid APQN, TAPQ error or AP queue status which 331 + * indicates there is no APQN. 347 332 */ 348 - static bool ap_queue_info(ap_qid_t qid, int *q_type, unsigned int *q_fac, 349 - int *q_depth, int *q_ml, bool *q_decfg, bool *q_cstop) 333 + static int ap_queue_info(ap_qid_t qid, int *q_type, unsigned int *q_fac, 334 + int *q_depth, int *q_ml, bool *q_decfg, bool *q_cstop) 350 335 { 351 336 struct ap_queue_status status; 352 - union { 353 - unsigned long value; 354 - struct { 355 - unsigned int fac : 32; /* facility bits */ 356 - unsigned int at : 8; /* ap type */ 357 - unsigned int _res1 : 8; 358 - unsigned int _res2 : 4; 359 - unsigned int ml : 4; /* apxl ml */ 360 - unsigned int _res3 : 4; 361 - unsigned int qd : 4; /* queue depth */ 362 - } tapq_gr2; 363 - } tapq_info; 337 + struct ap_tapq_gr2 tapq_info; 364 338 365 339 tapq_info.value = 0; 366 340 367 341 /* make sure we don't run into a specifiation exception */ 368 342 if (AP_QID_CARD(qid) > ap_max_adapter_id || 369 343 AP_QID_QUEUE(qid) > ap_max_domain_id) 370 - return false; 344 + return -1; 371 345 372 346 /* call TAPQ on this APQN */ 373 - status = ap_test_queue(qid, ap_apft_available(), &tapq_info.value); 347 + status = ap_test_queue(qid, ap_apft_available(), &tapq_info); 348 + 349 + /* handle pending async error with return 'no info available' */ 350 + if (status.async) 351 + return 0; 352 + 374 353 switch (status.response_code) { 375 354 case AP_RESPONSE_NORMAL: 376 355 case AP_RESPONSE_RESET_IN_PROGRESS: ··· 380 365 * there is at least one of the mode bits set. 381 366 */ 382 367 if (WARN_ON_ONCE(!tapq_info.value)) 383 - return false; 384 - *q_type = tapq_info.tapq_gr2.at; 385 - *q_fac = tapq_info.tapq_gr2.fac; 386 - *q_depth = tapq_info.tapq_gr2.qd; 387 - *q_ml = tapq_info.tapq_gr2.ml; 368 + return 0; 369 + *q_type = tapq_info.at; 370 + *q_fac = tapq_info.fac; 371 + *q_depth = tapq_info.qd; 372 + *q_ml = tapq_info.ml; 388 373 *q_decfg = status.response_code == AP_RESPONSE_DECONFIGURED; 389 374 *q_cstop = status.response_code == AP_RESPONSE_CHECKSTOPPED; 390 375 switch (*q_type) { ··· 404 389 default: 405 390 break; 406 391 } 407 - return true; 392 + return 1; 408 393 default: 409 394 /* 410 395 * A response code which indicates, there is no info available. 411 396 */ 412 - return false; 397 + return -1; 413 398 } 414 399 } 415 400 ··· 427 412 break; 428 413 } 429 414 fallthrough; 430 - case AP_SM_WAIT_TIMEOUT: 415 + case AP_SM_WAIT_LOW_TIMEOUT: 416 + case AP_SM_WAIT_HIGH_TIMEOUT: 431 417 spin_lock_bh(&ap_poll_timer_lock); 432 418 if (!hrtimer_is_queued(&ap_poll_timer)) { 433 - hr_time = poll_timeout; 419 + hr_time = 420 + wait == AP_SM_WAIT_LOW_TIMEOUT ? 421 + poll_low_timeout : poll_high_timeout; 434 422 hrtimer_forward_now(&ap_poll_timer, hr_time); 435 423 hrtimer_restart(&ap_poll_timer); 436 424 } ··· 1186 1168 1187 1169 static ssize_t ap_domain_show(const struct bus_type *bus, char *buf) 1188 1170 { 1189 - return scnprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index); 1171 + return sysfs_emit(buf, "%d\n", ap_domain_index); 1190 1172 } 1191 1173 1192 1174 static ssize_t ap_domain_store(const struct bus_type *bus, ··· 1214 1196 static ssize_t ap_control_domain_mask_show(const struct bus_type *bus, char *buf) 1215 1197 { 1216 1198 if (!ap_qci_info) /* QCI not supported */ 1217 - return scnprintf(buf, PAGE_SIZE, "not supported\n"); 1199 + return sysfs_emit(buf, "not supported\n"); 1218 1200 1219 - return scnprintf(buf, PAGE_SIZE, 1220 - "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1221 - ap_qci_info->adm[0], ap_qci_info->adm[1], 1222 - ap_qci_info->adm[2], ap_qci_info->adm[3], 1223 - ap_qci_info->adm[4], ap_qci_info->adm[5], 1224 - ap_qci_info->adm[6], ap_qci_info->adm[7]); 1201 + return sysfs_emit(buf, "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1202 + ap_qci_info->adm[0], ap_qci_info->adm[1], 1203 + ap_qci_info->adm[2], ap_qci_info->adm[3], 1204 + ap_qci_info->adm[4], ap_qci_info->adm[5], 1205 + ap_qci_info->adm[6], ap_qci_info->adm[7]); 1225 1206 } 1226 1207 1227 1208 static BUS_ATTR_RO(ap_control_domain_mask); ··· 1228 1211 static ssize_t ap_usage_domain_mask_show(const struct bus_type *bus, char *buf) 1229 1212 { 1230 1213 if (!ap_qci_info) /* QCI not supported */ 1231 - return scnprintf(buf, PAGE_SIZE, "not supported\n"); 1214 + return sysfs_emit(buf, "not supported\n"); 1232 1215 1233 - return scnprintf(buf, PAGE_SIZE, 1234 - "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1235 - ap_qci_info->aqm[0], ap_qci_info->aqm[1], 1236 - ap_qci_info->aqm[2], ap_qci_info->aqm[3], 1237 - ap_qci_info->aqm[4], ap_qci_info->aqm[5], 1238 - ap_qci_info->aqm[6], ap_qci_info->aqm[7]); 1216 + return sysfs_emit(buf, "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1217 + ap_qci_info->aqm[0], ap_qci_info->aqm[1], 1218 + ap_qci_info->aqm[2], ap_qci_info->aqm[3], 1219 + ap_qci_info->aqm[4], ap_qci_info->aqm[5], 1220 + ap_qci_info->aqm[6], ap_qci_info->aqm[7]); 1239 1221 } 1240 1222 1241 1223 static BUS_ATTR_RO(ap_usage_domain_mask); ··· 1242 1226 static ssize_t ap_adapter_mask_show(const struct bus_type *bus, char *buf) 1243 1227 { 1244 1228 if (!ap_qci_info) /* QCI not supported */ 1245 - return scnprintf(buf, PAGE_SIZE, "not supported\n"); 1229 + return sysfs_emit(buf, "not supported\n"); 1246 1230 1247 - return scnprintf(buf, PAGE_SIZE, 1248 - "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1249 - ap_qci_info->apm[0], ap_qci_info->apm[1], 1250 - ap_qci_info->apm[2], ap_qci_info->apm[3], 1251 - ap_qci_info->apm[4], ap_qci_info->apm[5], 1252 - ap_qci_info->apm[6], ap_qci_info->apm[7]); 1231 + return sysfs_emit(buf, "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1232 + ap_qci_info->apm[0], ap_qci_info->apm[1], 1233 + ap_qci_info->apm[2], ap_qci_info->apm[3], 1234 + ap_qci_info->apm[4], ap_qci_info->apm[5], 1235 + ap_qci_info->apm[6], ap_qci_info->apm[7]); 1253 1236 } 1254 1237 1255 1238 static BUS_ATTR_RO(ap_adapter_mask); 1256 1239 1257 1240 static ssize_t ap_interrupts_show(const struct bus_type *bus, char *buf) 1258 1241 { 1259 - return scnprintf(buf, PAGE_SIZE, "%d\n", 1260 - ap_irq_flag ? 1 : 0); 1242 + return sysfs_emit(buf, "%d\n", ap_irq_flag ? 1 : 0); 1261 1243 } 1262 1244 1263 1245 static BUS_ATTR_RO(ap_interrupts); 1264 1246 1265 1247 static ssize_t config_time_show(const struct bus_type *bus, char *buf) 1266 1248 { 1267 - return scnprintf(buf, PAGE_SIZE, "%d\n", ap_config_time); 1249 + return sysfs_emit(buf, "%d\n", ap_config_time); 1268 1250 } 1269 1251 1270 1252 static ssize_t config_time_store(const struct bus_type *bus, ··· 1281 1267 1282 1268 static ssize_t poll_thread_show(const struct bus_type *bus, char *buf) 1283 1269 { 1284 - return scnprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0); 1270 + return sysfs_emit(buf, "%d\n", ap_poll_kthread ? 1 : 0); 1285 1271 } 1286 1272 1287 1273 static ssize_t poll_thread_store(const struct bus_type *bus, 1288 1274 const char *buf, size_t count) 1289 1275 { 1290 - int flag, rc; 1276 + bool value; 1277 + int rc; 1291 1278 1292 - if (sscanf(buf, "%d\n", &flag) != 1) 1293 - return -EINVAL; 1294 - if (flag) { 1279 + rc = kstrtobool(buf, &value); 1280 + if (rc) 1281 + return rc; 1282 + 1283 + if (value) { 1295 1284 rc = ap_poll_thread_start(); 1296 1285 if (rc) 1297 1286 count = rc; ··· 1308 1291 1309 1292 static ssize_t poll_timeout_show(const struct bus_type *bus, char *buf) 1310 1293 { 1311 - return scnprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout); 1294 + return sysfs_emit(buf, "%lu\n", poll_high_timeout); 1312 1295 } 1313 1296 1314 1297 static ssize_t poll_timeout_store(const struct bus_type *bus, const char *buf, 1315 1298 size_t count) 1316 1299 { 1317 - unsigned long long time; 1300 + unsigned long value; 1318 1301 ktime_t hr_time; 1302 + int rc; 1303 + 1304 + rc = kstrtoul(buf, 0, &value); 1305 + if (rc) 1306 + return rc; 1319 1307 1320 1308 /* 120 seconds = maximum poll interval */ 1321 - if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 || 1322 - time > 120000000000ULL) 1309 + if (value > 120000000000UL) 1323 1310 return -EINVAL; 1324 - poll_timeout = time; 1325 - hr_time = poll_timeout; 1311 + poll_high_timeout = value; 1312 + hr_time = poll_high_timeout; 1326 1313 1327 1314 spin_lock_bh(&ap_poll_timer_lock); 1328 1315 hrtimer_cancel(&ap_poll_timer); ··· 1341 1320 1342 1321 static ssize_t ap_max_domain_id_show(const struct bus_type *bus, char *buf) 1343 1322 { 1344 - return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_domain_id); 1323 + return sysfs_emit(buf, "%d\n", ap_max_domain_id); 1345 1324 } 1346 1325 1347 1326 static BUS_ATTR_RO(ap_max_domain_id); 1348 1327 1349 1328 static ssize_t ap_max_adapter_id_show(const struct bus_type *bus, char *buf) 1350 1329 { 1351 - return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_adapter_id); 1330 + return sysfs_emit(buf, "%d\n", ap_max_adapter_id); 1352 1331 } 1353 1332 1354 1333 static BUS_ATTR_RO(ap_max_adapter_id); ··· 1359 1338 1360 1339 if (mutex_lock_interruptible(&ap_perms_mutex)) 1361 1340 return -ERESTARTSYS; 1362 - rc = scnprintf(buf, PAGE_SIZE, 1363 - "0x%016lx%016lx%016lx%016lx\n", 1364 - ap_perms.apm[0], ap_perms.apm[1], 1365 - ap_perms.apm[2], ap_perms.apm[3]); 1341 + rc = sysfs_emit(buf, "0x%016lx%016lx%016lx%016lx\n", 1342 + ap_perms.apm[0], ap_perms.apm[1], 1343 + ap_perms.apm[2], ap_perms.apm[3]); 1366 1344 mutex_unlock(&ap_perms_mutex); 1367 1345 1368 1346 return rc; ··· 1451 1431 1452 1432 if (mutex_lock_interruptible(&ap_perms_mutex)) 1453 1433 return -ERESTARTSYS; 1454 - rc = scnprintf(buf, PAGE_SIZE, 1455 - "0x%016lx%016lx%016lx%016lx\n", 1456 - ap_perms.aqm[0], ap_perms.aqm[1], 1457 - ap_perms.aqm[2], ap_perms.aqm[3]); 1434 + rc = sysfs_emit(buf, "0x%016lx%016lx%016lx%016lx\n", 1435 + ap_perms.aqm[0], ap_perms.aqm[1], 1436 + ap_perms.aqm[2], ap_perms.aqm[3]); 1458 1437 mutex_unlock(&ap_perms_mutex); 1459 1438 1460 1439 return rc; ··· 1539 1520 1540 1521 static ssize_t scans_show(const struct bus_type *bus, char *buf) 1541 1522 { 1542 - return scnprintf(buf, PAGE_SIZE, "%llu\n", 1543 - atomic64_read(&ap_scan_bus_count)); 1523 + return sysfs_emit(buf, "%llu\n", atomic64_read(&ap_scan_bus_count)); 1544 1524 } 1545 1525 1546 1526 static ssize_t scans_store(const struct bus_type *bus, const char *buf, ··· 1561 1543 1562 1544 ap_calc_bound_apqns(&apqns, &n); 1563 1545 if (atomic64_read(&ap_scan_bus_count) >= 1 && n == apqns) 1564 - rc = scnprintf(buf, PAGE_SIZE, "%u/%u (complete)\n", n, apqns); 1546 + rc = sysfs_emit(buf, "%u/%u (complete)\n", n, apqns); 1565 1547 else 1566 - rc = scnprintf(buf, PAGE_SIZE, "%u/%u\n", n, apqns); 1548 + rc = sysfs_emit(buf, "%u/%u\n", n, apqns); 1567 1549 1568 1550 return rc; 1569 1551 } 1570 1552 1571 1553 static BUS_ATTR_RO(bindings); 1554 + 1555 + static ssize_t features_show(const struct bus_type *bus, char *buf) 1556 + { 1557 + int n = 0; 1558 + 1559 + if (!ap_qci_info) /* QCI not supported */ 1560 + return sysfs_emit(buf, "-\n"); 1561 + 1562 + if (ap_qci_info->apsc) 1563 + n += sysfs_emit_at(buf, n, "APSC "); 1564 + if (ap_qci_info->apxa) 1565 + n += sysfs_emit_at(buf, n, "APXA "); 1566 + if (ap_qci_info->qact) 1567 + n += sysfs_emit_at(buf, n, "QACT "); 1568 + if (ap_qci_info->rc8a) 1569 + n += sysfs_emit_at(buf, n, "RC8A "); 1570 + if (ap_qci_info->apsb) 1571 + n += sysfs_emit_at(buf, n, "APSB "); 1572 + 1573 + sysfs_emit_at(buf, n == 0 ? 0 : n - 1, "\n"); 1574 + 1575 + return n; 1576 + } 1577 + 1578 + static BUS_ATTR_RO(features); 1572 1579 1573 1580 static struct attribute *ap_bus_attrs[] = { 1574 1581 &bus_attr_ap_domain.attr, ··· 1610 1567 &bus_attr_aqmask.attr, 1611 1568 &bus_attr_scans.attr, 1612 1569 &bus_attr_bindings.attr, 1570 + &bus_attr_features.attr, 1613 1571 NULL, 1614 1572 }; 1615 1573 ATTRIBUTE_GROUPS(ap_bus); ··· 1806 1762 */ 1807 1763 static inline void ap_scan_domains(struct ap_card *ac) 1808 1764 { 1809 - bool decfg, chkstop; 1810 - ap_qid_t qid; 1811 - unsigned int func; 1812 - struct device *dev; 1813 - struct ap_queue *aq; 1814 1765 int rc, dom, depth, type, ml; 1766 + bool decfg, chkstop; 1767 + struct ap_queue *aq; 1768 + struct device *dev; 1769 + unsigned int func; 1770 + ap_qid_t qid; 1815 1771 1816 1772 /* 1817 1773 * Go through the configuration for the domains and compare them ··· 1830 1786 AP_DBF_INFO("%s(%d,%d) not in config anymore, rm queue dev\n", 1831 1787 __func__, ac->id, dom); 1832 1788 device_unregister(dev); 1833 - put_device(dev); 1834 1789 } 1835 - continue; 1790 + goto put_dev_and_continue; 1836 1791 } 1837 1792 /* domain is valid, get info from this APQN */ 1838 - if (!ap_queue_info(qid, &type, &func, &depth, 1839 - &ml, &decfg, &chkstop)) { 1840 - if (aq) { 1793 + rc = ap_queue_info(qid, &type, &func, &depth, 1794 + &ml, &decfg, &chkstop); 1795 + switch (rc) { 1796 + case -1: 1797 + if (dev) { 1841 1798 AP_DBF_INFO("%s(%d,%d) queue_info() failed, rm queue dev\n", 1842 1799 __func__, ac->id, dom); 1843 1800 device_unregister(dev); 1844 - put_device(dev); 1845 1801 } 1846 - continue; 1802 + fallthrough; 1803 + case 0: 1804 + goto put_dev_and_continue; 1805 + default: 1806 + break; 1847 1807 } 1848 1808 /* if no queue device exists, create a new one */ 1849 1809 if (!aq) { ··· 1963 1915 */ 1964 1916 static inline void ap_scan_adapter(int ap) 1965 1917 { 1966 - bool decfg, chkstop; 1967 - ap_qid_t qid; 1968 - unsigned int func; 1969 - struct device *dev; 1970 - struct ap_card *ac; 1971 1918 int rc, dom, depth, type, comp_type, ml; 1919 + bool decfg, chkstop; 1920 + struct ap_card *ac; 1921 + struct device *dev; 1922 + unsigned int func; 1923 + ap_qid_t qid; 1972 1924 1973 1925 /* Is there currently a card device for this adapter ? */ 1974 1926 dev = bus_find_device(&ap_bus_type, NULL, ··· 1998 1950 if (ap_test_config_usage_domain(dom)) { 1999 1951 qid = AP_MKQID(ap, dom); 2000 1952 if (ap_queue_info(qid, &type, &func, &depth, 2001 - &ml, &decfg, &chkstop)) 1953 + &ml, &decfg, &chkstop) > 0) 2002 1954 break; 2003 1955 } 2004 1956 if (dom > ap_max_domain_id) { 2005 - /* Could not find a valid APQN for this adapter */ 1957 + /* Could not find one valid APQN for this adapter */ 2006 1958 if (ac) { 2007 1959 AP_DBF_INFO("%s(%d) no type info (no APQN found), rm card and queue devs\n", 2008 1960 __func__, ap); ··· 2027 1979 } 2028 1980 return; 2029 1981 } 2030 - 2031 1982 if (ac) { 2032 1983 /* Check APQN against existing card device for changes */ 2033 1984 if (ac->raw_hwtype != type) { ··· 2035 1988 ap_scan_rm_card_dev_and_queue_devs(ac); 2036 1989 put_device(dev); 2037 1990 ac = NULL; 2038 - } else if (ac->functions != func) { 1991 + } else if ((ac->functions & TAPQ_CARD_FUNC_CMP_MASK) != 1992 + (func & TAPQ_CARD_FUNC_CMP_MASK)) { 2039 1993 AP_DBF_INFO("%s(%d) functions 0x%08x changed, rm card and queue devs\n", 2040 - __func__, ap, type); 1994 + __func__, ap, func); 2041 1995 ap_scan_rm_card_dev_and_queue_devs(ac); 2042 1996 put_device(dev); 2043 1997 ac = NULL; ··· 2293 2245 * If we are running under z/VM adjust polling to z/VM polling rate. 2294 2246 */ 2295 2247 if (MACHINE_IS_VM) 2296 - poll_timeout = 1500000; 2248 + poll_high_timeout = 1500000; 2297 2249 hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 2298 2250 ap_poll_timer.function = ap_poll_timeout; 2299 2251
+44 -26
drivers/s390/crypto/ap_bus.h
··· 39 39 return (*ptr & (0x80000000u >> nr)) != 0; 40 40 } 41 41 42 - #define AP_RESPONSE_NORMAL 0x00 43 - #define AP_RESPONSE_Q_NOT_AVAIL 0x01 44 - #define AP_RESPONSE_RESET_IN_PROGRESS 0x02 45 - #define AP_RESPONSE_DECONFIGURED 0x03 46 - #define AP_RESPONSE_CHECKSTOPPED 0x04 47 - #define AP_RESPONSE_BUSY 0x05 48 - #define AP_RESPONSE_INVALID_ADDRESS 0x06 49 - #define AP_RESPONSE_OTHERWISE_CHANGED 0x07 50 - #define AP_RESPONSE_INVALID_GISA 0x08 51 - #define AP_RESPONSE_Q_FULL 0x10 52 - #define AP_RESPONSE_NO_PENDING_REPLY 0x10 53 - #define AP_RESPONSE_INDEX_TOO_BIG 0x11 54 - #define AP_RESPONSE_NO_FIRST_PART 0x13 55 - #define AP_RESPONSE_MESSAGE_TOO_BIG 0x15 56 - #define AP_RESPONSE_REQ_FAC_NOT_INST 0x16 57 - #define AP_RESPONSE_INVALID_DOMAIN 0x42 42 + #define AP_RESPONSE_NORMAL 0x00 43 + #define AP_RESPONSE_Q_NOT_AVAIL 0x01 44 + #define AP_RESPONSE_RESET_IN_PROGRESS 0x02 45 + #define AP_RESPONSE_DECONFIGURED 0x03 46 + #define AP_RESPONSE_CHECKSTOPPED 0x04 47 + #define AP_RESPONSE_BUSY 0x05 48 + #define AP_RESPONSE_INVALID_ADDRESS 0x06 49 + #define AP_RESPONSE_OTHERWISE_CHANGED 0x07 50 + #define AP_RESPONSE_INVALID_GISA 0x08 51 + #define AP_RESPONSE_Q_BOUND_TO_ANOTHER 0x09 52 + #define AP_RESPONSE_STATE_CHANGE_IN_PROGRESS 0x0A 53 + #define AP_RESPONSE_Q_NOT_BOUND 0x0B 54 + #define AP_RESPONSE_Q_FULL 0x10 55 + #define AP_RESPONSE_NO_PENDING_REPLY 0x10 56 + #define AP_RESPONSE_INDEX_TOO_BIG 0x11 57 + #define AP_RESPONSE_NO_FIRST_PART 0x13 58 + #define AP_RESPONSE_MESSAGE_TOO_BIG 0x15 59 + #define AP_RESPONSE_REQ_FAC_NOT_INST 0x16 60 + #define AP_RESPONSE_Q_BIND_ERROR 0x30 61 + #define AP_RESPONSE_Q_NOT_AVAIL_FOR_ASSOC 0x31 62 + #define AP_RESPONSE_Q_NOT_EMPTY 0x32 63 + #define AP_RESPONSE_BIND_LIMIT_EXCEEDED 0x33 64 + #define AP_RESPONSE_INVALID_ASSOC_SECRET 0x34 65 + #define AP_RESPONSE_ASSOC_SECRET_NOT_UNIQUE 0x35 66 + #define AP_RESPONSE_ASSOC_FAILED 0x36 67 + #define AP_RESPONSE_INVALID_DOMAIN 0x42 58 68 59 69 /* 60 70 * Known device types ··· 102 92 AP_SM_STATE_IDLE, 103 93 AP_SM_STATE_WORKING, 104 94 AP_SM_STATE_QUEUE_FULL, 95 + AP_SM_STATE_ASSOC_WAIT, 105 96 NR_AP_SM_STATES 106 97 }; 107 98 ··· 119 108 * AP queue state wait behaviour 120 109 */ 121 110 enum ap_sm_wait { 122 - AP_SM_WAIT_AGAIN = 0, /* retry immediately */ 123 - AP_SM_WAIT_TIMEOUT, /* wait for timeout */ 124 - AP_SM_WAIT_INTERRUPT, /* wait for thin interrupt (if available) */ 125 - AP_SM_WAIT_NONE, /* no wait */ 111 + AP_SM_WAIT_AGAIN = 0, /* retry immediately */ 112 + AP_SM_WAIT_HIGH_TIMEOUT, /* poll high freq, wait for timeout */ 113 + AP_SM_WAIT_LOW_TIMEOUT, /* poll low freq, wait for timeout */ 114 + AP_SM_WAIT_INTERRUPT, /* wait for thin interrupt (if available) */ 115 + AP_SM_WAIT_NONE, /* no wait */ 126 116 NR_AP_SM_WAIT 127 117 }; 128 118 ··· 190 178 struct ap_card { 191 179 struct ap_device ap_dev; 192 180 int raw_hwtype; /* AP raw hardware type. */ 193 - unsigned int functions; /* AP device function bitfield. */ 181 + unsigned int functions; /* TAPQ GR2 upper 32 facility bits */ 194 182 int queue_depth; /* AP queue depth.*/ 195 183 int id; /* AP card number. */ 196 184 unsigned int maxmsgsize; /* AP msg limit for this card */ ··· 198 186 bool chkstop; /* checkstop state */ 199 187 atomic64_t total_request_count; /* # requests ever for this AP device.*/ 200 188 }; 189 + 190 + #define TAPQ_CARD_FUNC_CMP_MASK 0xFFFF0000 191 + #define ASSOC_IDX_INVALID 0x10000 201 192 202 193 #define to_ap_card(x) container_of((x), struct ap_card, ap_dev.device) 203 194 ··· 214 199 bool chkstop; /* checkstop state */ 215 200 ap_qid_t qid; /* AP queue id. */ 216 201 bool interrupt; /* indicate if interrupts are enabled */ 202 + unsigned int assoc_idx; /* SE association index */ 217 203 int queue_count; /* # messages currently on AP queue. */ 218 204 int pendingq_count; /* # requests on pendingq list. */ 219 205 int requestq_count; /* # requests on requestq list. */ ··· 225 209 struct list_head requestq; /* List of message yet to be sent. */ 226 210 struct ap_message *reply; /* Per device reply message. */ 227 211 enum ap_sm_state sm_state; /* ap queue state machine state */ 212 + int rapq_fbit; /* fbit arg for next rapq invocation */ 228 213 int last_err_rc; /* last error state response code */ 229 214 }; 230 215 ··· 259 242 260 243 struct ap_message { 261 244 struct list_head list; /* Request queueing. */ 262 - unsigned long long psmid; /* Message id. */ 245 + unsigned long psmid; /* Message id. */ 263 246 void *msg; /* Pointer to message buffer. */ 264 - unsigned int len; /* actual msg len in msg buffer */ 265 - unsigned int bufsize; /* allocated msg buffer size */ 247 + size_t len; /* actual msg len in msg buffer */ 248 + size_t bufsize; /* allocated msg buffer size */ 266 249 u16 flags; /* Flags, see AP_MSG_FLAG_xxx */ 267 250 struct ap_fi fi; /* Failure Injection cmd */ 268 251 int rc; /* Return code for this message */ ··· 302 285 * for the first time. Otherwise the ap message queue will get 303 286 * confused. 304 287 */ 305 - int ap_send(ap_qid_t, unsigned long long, void *, size_t); 306 - int ap_recv(ap_qid_t, unsigned long long *, void *, size_t); 288 + int ap_send(ap_qid_t qid, unsigned long psmid, void *msg, size_t msglen); 289 + int ap_recv(ap_qid_t qid, unsigned long *psmid, void *msg, size_t msglen); 307 290 308 291 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event); 309 292 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event); ··· 313 296 void ap_flush_queue(struct ap_queue *aq); 314 297 315 298 void *ap_airq_ptr(void); 299 + int ap_sb_available(void); 316 300 void ap_wait(enum ap_sm_wait wait); 317 301 void ap_request_timeout(struct timer_list *t); 318 302 void ap_bus_force_rescan(void);
+11 -12
drivers/s390/crypto/ap_card.c
··· 24 24 { 25 25 struct ap_card *ac = to_ap_card(dev); 26 26 27 - return scnprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type); 27 + return sysfs_emit(buf, "%d\n", ac->ap_dev.device_type); 28 28 } 29 29 30 30 static DEVICE_ATTR_RO(hwtype); ··· 34 34 { 35 35 struct ap_card *ac = to_ap_card(dev); 36 36 37 - return scnprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype); 37 + return sysfs_emit(buf, "%d\n", ac->raw_hwtype); 38 38 } 39 39 40 40 static DEVICE_ATTR_RO(raw_hwtype); ··· 44 44 { 45 45 struct ap_card *ac = to_ap_card(dev); 46 46 47 - return scnprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth); 47 + return sysfs_emit(buf, "%d\n", ac->queue_depth); 48 48 } 49 49 50 50 static DEVICE_ATTR_RO(depth); ··· 54 54 { 55 55 struct ap_card *ac = to_ap_card(dev); 56 56 57 - return scnprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions); 57 + return sysfs_emit(buf, "0x%08X\n", ac->functions); 58 58 } 59 59 60 60 static DEVICE_ATTR_RO(ap_functions); ··· 70 70 spin_lock_bh(&ap_queues_lock); 71 71 req_cnt = atomic64_read(&ac->total_request_count); 72 72 spin_unlock_bh(&ap_queues_lock); 73 - return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); 73 + return sysfs_emit(buf, "%llu\n", req_cnt); 74 74 } 75 75 76 76 static ssize_t request_count_store(struct device *dev, ··· 107 107 if (ac == aq->card) 108 108 reqq_cnt += aq->requestq_count; 109 109 spin_unlock_bh(&ap_queues_lock); 110 - return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); 110 + return sysfs_emit(buf, "%d\n", reqq_cnt); 111 111 } 112 112 113 113 static DEVICE_ATTR_RO(requestq_count); ··· 126 126 if (ac == aq->card) 127 127 penq_cnt += aq->pendingq_count; 128 128 spin_unlock_bh(&ap_queues_lock); 129 - return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); 129 + return sysfs_emit(buf, "%d\n", penq_cnt); 130 130 } 131 131 132 132 static DEVICE_ATTR_RO(pendingq_count); ··· 134 134 static ssize_t modalias_show(struct device *dev, 135 135 struct device_attribute *attr, char *buf) 136 136 { 137 - return scnprintf(buf, PAGE_SIZE, "ap:t%02X\n", 138 - to_ap_dev(dev)->device_type); 137 + return sysfs_emit(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type); 139 138 } 140 139 141 140 static DEVICE_ATTR_RO(modalias); ··· 144 145 { 145 146 struct ap_card *ac = to_ap_card(dev); 146 147 147 - return scnprintf(buf, PAGE_SIZE, "%d\n", ac->config ? 1 : 0); 148 + return sysfs_emit(buf, "%d\n", ac->config ? 1 : 0); 148 149 } 149 150 150 151 static ssize_t config_store(struct device *dev, ··· 178 179 { 179 180 struct ap_card *ac = to_ap_card(dev); 180 181 181 - return scnprintf(buf, PAGE_SIZE, "%d\n", ac->chkstop ? 1 : 0); 182 + return sysfs_emit(buf, "%d\n", ac->chkstop ? 1 : 0); 182 183 } 183 184 184 185 static DEVICE_ATTR_RO(chkstop); ··· 188 189 { 189 190 struct ap_card *ac = to_ap_card(dev); 190 191 191 - return scnprintf(buf, PAGE_SIZE, "%u\n", ac->maxmsgsize); 192 + return sysfs_emit(buf, "%u\n", ac->maxmsgsize); 192 193 } 193 194 194 195 static DEVICE_ATTR_RO(max_msg_size);
+348 -62
drivers/s390/crypto/ap_queue.c
··· 18 18 19 19 static void __ap_flush_queue(struct ap_queue *aq); 20 20 21 + /* 22 + * some AP queue helper functions 23 + */ 24 + 25 + static inline bool ap_q_supports_bind(struct ap_queue *aq) 26 + { 27 + return ap_test_bit(&aq->card->functions, AP_FUNC_EP11) || 28 + ap_test_bit(&aq->card->functions, AP_FUNC_ACCEL); 29 + } 30 + 31 + static inline bool ap_q_supports_assoc(struct ap_queue *aq) 32 + { 33 + return ap_test_bit(&aq->card->functions, AP_FUNC_EP11); 34 + } 35 + 21 36 /** 22 37 * ap_queue_enable_irq(): Enable interrupt support on this AP queue. 23 38 * @aq: The AP queue ··· 50 35 qirqctrl.ir = 1; 51 36 qirqctrl.isc = AP_ISC; 52 37 status = ap_aqic(aq->qid, qirqctrl, virt_to_phys(ind)); 38 + if (status.async) 39 + return -EPERM; 53 40 switch (status.response_code) { 54 41 case AP_RESPONSE_NORMAL: 55 42 case AP_RESPONSE_OTHERWISE_CHANGED: ··· 76 59 * @qid: The AP queue number 77 60 * @psmid: The program supplied message identifier 78 61 * @msg: The message text 79 - * @length: The message length 62 + * @msglen: The message length 80 63 * @special: Special Bit 81 64 * 82 65 * Returns AP queue status structure. ··· 85 68 * because a segment boundary was reached. The NQAP is repeated. 86 69 */ 87 70 static inline struct ap_queue_status 88 - __ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length, 71 + __ap_send(ap_qid_t qid, unsigned long psmid, void *msg, size_t msglen, 89 72 int special) 90 73 { 91 74 if (special) 92 75 qid |= 0x400000UL; 93 - return ap_nqap(qid, psmid, msg, length); 76 + return ap_nqap(qid, psmid, msg, msglen); 94 77 } 95 78 96 - int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length) 79 + int ap_send(ap_qid_t qid, unsigned long psmid, void *msg, size_t msglen) 97 80 { 98 81 struct ap_queue_status status; 99 82 100 - status = __ap_send(qid, psmid, msg, length, 0); 83 + status = __ap_send(qid, psmid, msg, msglen, 0); 84 + if (status.async) 85 + return -EPERM; 101 86 switch (status.response_code) { 102 87 case AP_RESPONSE_NORMAL: 103 88 return 0; ··· 114 95 } 115 96 EXPORT_SYMBOL(ap_send); 116 97 117 - int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length) 98 + int ap_recv(ap_qid_t qid, unsigned long *psmid, void *msg, size_t msglen) 118 99 { 119 100 struct ap_queue_status status; 120 101 121 102 if (!msg) 122 103 return -EINVAL; 123 - status = ap_dqap(qid, psmid, msg, length, NULL, NULL); 104 + status = ap_dqap(qid, psmid, msg, msglen, NULL, NULL, NULL); 105 + if (status.async) 106 + return -EPERM; 124 107 switch (status.response_code) { 125 108 case AP_RESPONSE_NORMAL: 126 109 return 0; ··· 171 150 do { 172 151 status = ap_dqap(aq->qid, &aq->reply->psmid, 173 152 aq->reply->msg, aq->reply->bufsize, 174 - &reslen, &resgr0); 153 + &aq->reply->len, &reslen, &resgr0); 175 154 parts++; 176 155 } while (status.response_code == 0xFF && resgr0 != 0); 177 156 ··· 198 177 break; 199 178 } 200 179 if (!found) { 201 - AP_DBF_WARN("%s unassociated reply psmid=0x%016llx on 0x%02x.%04x\n", 180 + AP_DBF_WARN("%s unassociated reply psmid=0x%016lx on 0x%02x.%04x\n", 202 181 __func__, aq->reply->psmid, 203 182 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 204 183 } ··· 231 210 if (!aq->reply) 232 211 return AP_SM_WAIT_NONE; 233 212 status = ap_sm_recv(aq); 213 + if (status.async) 214 + return AP_SM_WAIT_NONE; 234 215 switch (status.response_code) { 235 216 case AP_RESPONSE_NORMAL: 236 217 if (aq->queue_count > 0) { ··· 244 221 case AP_RESPONSE_NO_PENDING_REPLY: 245 222 if (aq->queue_count > 0) 246 223 return aq->interrupt ? 247 - AP_SM_WAIT_INTERRUPT : AP_SM_WAIT_TIMEOUT; 224 + AP_SM_WAIT_INTERRUPT : AP_SM_WAIT_HIGH_TIMEOUT; 248 225 aq->sm_state = AP_SM_STATE_IDLE; 249 226 return AP_SM_WAIT_NONE; 250 227 default: ··· 284 261 status = __ap_send(qid, ap_msg->psmid, 285 262 ap_msg->msg, ap_msg->len, 286 263 ap_msg->flags & AP_MSG_FLAG_SPECIAL); 264 + if (status.async) 265 + return AP_SM_WAIT_NONE; 287 266 switch (status.response_code) { 288 267 case AP_RESPONSE_NORMAL: 289 268 aq->queue_count = max_t(int, 1, aq->queue_count + 1); ··· 302 277 case AP_RESPONSE_Q_FULL: 303 278 aq->sm_state = AP_SM_STATE_QUEUE_FULL; 304 279 return aq->interrupt ? 305 - AP_SM_WAIT_INTERRUPT : AP_SM_WAIT_TIMEOUT; 280 + AP_SM_WAIT_INTERRUPT : AP_SM_WAIT_HIGH_TIMEOUT; 306 281 case AP_RESPONSE_RESET_IN_PROGRESS: 307 282 aq->sm_state = AP_SM_STATE_RESET_WAIT; 308 - return AP_SM_WAIT_TIMEOUT; 283 + return AP_SM_WAIT_LOW_TIMEOUT; 309 284 case AP_RESPONSE_INVALID_DOMAIN: 310 285 AP_DBF_WARN("%s RESPONSE_INVALID_DOMAIN on NQAP\n", __func__); 311 286 fallthrough; ··· 347 322 { 348 323 struct ap_queue_status status; 349 324 350 - status = ap_rapq(aq->qid); 325 + status = ap_rapq(aq->qid, aq->rapq_fbit); 326 + if (status.async) 327 + return AP_SM_WAIT_NONE; 351 328 switch (status.response_code) { 352 329 case AP_RESPONSE_NORMAL: 353 330 case AP_RESPONSE_RESET_IN_PROGRESS: 354 331 aq->sm_state = AP_SM_STATE_RESET_WAIT; 355 332 aq->interrupt = false; 356 - return AP_SM_WAIT_TIMEOUT; 333 + aq->rapq_fbit = 0; 334 + return AP_SM_WAIT_LOW_TIMEOUT; 357 335 default: 358 336 aq->dev_state = AP_DEV_STATE_ERROR; 359 337 aq->last_err_rc = status.response_code; ··· 396 368 return AP_SM_WAIT_AGAIN; 397 369 case AP_RESPONSE_BUSY: 398 370 case AP_RESPONSE_RESET_IN_PROGRESS: 399 - return AP_SM_WAIT_TIMEOUT; 371 + return AP_SM_WAIT_LOW_TIMEOUT; 400 372 case AP_RESPONSE_Q_NOT_AVAIL: 401 373 case AP_RESPONSE_DECONFIGURED: 402 374 case AP_RESPONSE_CHECKSTOPPED: ··· 440 412 return AP_SM_WAIT_AGAIN; 441 413 fallthrough; 442 414 case AP_RESPONSE_NO_PENDING_REPLY: 443 - return AP_SM_WAIT_TIMEOUT; 415 + return AP_SM_WAIT_LOW_TIMEOUT; 444 416 default: 445 417 aq->dev_state = AP_DEV_STATE_ERROR; 446 418 aq->last_err_rc = status.response_code; 447 419 AP_DBF_WARN("%s RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 448 420 __func__, status.response_code, 421 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 422 + return AP_SM_WAIT_NONE; 423 + } 424 + } 425 + 426 + /** 427 + * ap_sm_assoc_wait(): Test queue for completion of a pending 428 + * association request. 429 + * @aq: pointer to the AP queue 430 + */ 431 + static enum ap_sm_wait ap_sm_assoc_wait(struct ap_queue *aq) 432 + { 433 + struct ap_queue_status status; 434 + struct ap_tapq_gr2 info; 435 + 436 + status = ap_test_queue(aq->qid, 1, &info); 437 + /* handle asynchronous error on this queue */ 438 + if (status.async && status.response_code) { 439 + aq->dev_state = AP_DEV_STATE_ERROR; 440 + aq->last_err_rc = status.response_code; 441 + AP_DBF_WARN("%s asynch RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 442 + __func__, status.response_code, 443 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 444 + return AP_SM_WAIT_NONE; 445 + } 446 + if (status.response_code > AP_RESPONSE_BUSY) { 447 + aq->dev_state = AP_DEV_STATE_ERROR; 448 + aq->last_err_rc = status.response_code; 449 + AP_DBF_WARN("%s RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 450 + __func__, status.response_code, 451 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 452 + return AP_SM_WAIT_NONE; 453 + } 454 + 455 + /* check bs bits */ 456 + switch (info.bs) { 457 + case AP_BS_Q_USABLE: 458 + /* association is through */ 459 + aq->sm_state = AP_SM_STATE_IDLE; 460 + AP_DBF_DBG("%s queue 0x%02x.%04x associated with %u\n", 461 + __func__, AP_QID_CARD(aq->qid), 462 + AP_QID_QUEUE(aq->qid), aq->assoc_idx); 463 + return AP_SM_WAIT_NONE; 464 + case AP_BS_Q_USABLE_NO_SECURE_KEY: 465 + /* association still pending */ 466 + return AP_SM_WAIT_LOW_TIMEOUT; 467 + default: 468 + /* reset from 'outside' happened or no idea at all */ 469 + aq->assoc_idx = ASSOC_IDX_INVALID; 470 + aq->dev_state = AP_DEV_STATE_ERROR; 471 + aq->last_err_rc = status.response_code; 472 + AP_DBF_WARN("%s bs 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 473 + __func__, info.bs, 449 474 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 450 475 return AP_SM_WAIT_NONE; 451 476 } ··· 530 449 }, 531 450 [AP_SM_STATE_QUEUE_FULL] = { 532 451 [AP_SM_EVENT_POLL] = ap_sm_read, 452 + [AP_SM_EVENT_TIMEOUT] = ap_sm_reset, 453 + }, 454 + [AP_SM_STATE_ASSOC_WAIT] = { 455 + [AP_SM_EVENT_POLL] = ap_sm_assoc_wait, 533 456 [AP_SM_EVENT_TIMEOUT] = ap_sm_reset, 534 457 }, 535 458 }; ··· 575 490 spin_unlock_bh(&aq->lock); 576 491 577 492 if (valid) 578 - return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); 493 + return sysfs_emit(buf, "%llu\n", req_cnt); 579 494 else 580 - return scnprintf(buf, PAGE_SIZE, "-\n"); 495 + return sysfs_emit(buf, "-\n"); 581 496 } 582 497 583 498 static ssize_t request_count_store(struct device *dev, ··· 605 520 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) 606 521 reqq_cnt = aq->requestq_count; 607 522 spin_unlock_bh(&aq->lock); 608 - return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); 523 + return sysfs_emit(buf, "%d\n", reqq_cnt); 609 524 } 610 525 611 526 static DEVICE_ATTR_RO(requestq_count); ··· 620 535 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) 621 536 penq_cnt = aq->pendingq_count; 622 537 spin_unlock_bh(&aq->lock); 623 - return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); 538 + return sysfs_emit(buf, "%d\n", penq_cnt); 624 539 } 625 540 626 541 static DEVICE_ATTR_RO(pendingq_count); ··· 635 550 switch (aq->sm_state) { 636 551 case AP_SM_STATE_RESET_START: 637 552 case AP_SM_STATE_RESET_WAIT: 638 - rc = scnprintf(buf, PAGE_SIZE, "Reset in progress.\n"); 553 + rc = sysfs_emit(buf, "Reset in progress.\n"); 639 554 break; 640 555 case AP_SM_STATE_WORKING: 641 556 case AP_SM_STATE_QUEUE_FULL: 642 - rc = scnprintf(buf, PAGE_SIZE, "Reset Timer armed.\n"); 557 + rc = sysfs_emit(buf, "Reset Timer armed.\n"); 643 558 break; 644 559 default: 645 - rc = scnprintf(buf, PAGE_SIZE, "No Reset Timer set.\n"); 560 + rc = sysfs_emit(buf, "No Reset Timer set.\n"); 646 561 } 647 562 spin_unlock_bh(&aq->lock); 648 563 return rc; ··· 676 591 677 592 spin_lock_bh(&aq->lock); 678 593 if (aq->sm_state == AP_SM_STATE_SETIRQ_WAIT) 679 - rc = scnprintf(buf, PAGE_SIZE, "Enable Interrupt pending.\n"); 594 + rc = sysfs_emit(buf, "Enable Interrupt pending.\n"); 680 595 else if (aq->interrupt) 681 - rc = scnprintf(buf, PAGE_SIZE, "Interrupts enabled.\n"); 596 + rc = sysfs_emit(buf, "Interrupts enabled.\n"); 682 597 else 683 - rc = scnprintf(buf, PAGE_SIZE, "Interrupts disabled.\n"); 598 + rc = sysfs_emit(buf, "Interrupts disabled.\n"); 684 599 spin_unlock_bh(&aq->lock); 685 600 return rc; 686 601 } ··· 694 609 int rc; 695 610 696 611 spin_lock_bh(&aq->lock); 697 - rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->config ? 1 : 0); 612 + rc = sysfs_emit(buf, "%d\n", aq->config ? 1 : 0); 698 613 spin_unlock_bh(&aq->lock); 699 614 return rc; 700 615 } ··· 708 623 int rc; 709 624 710 625 spin_lock_bh(&aq->lock); 711 - rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->chkstop ? 1 : 0); 626 + rc = sysfs_emit(buf, "%d\n", aq->chkstop ? 1 : 0); 712 627 spin_unlock_bh(&aq->lock); 713 628 return rc; 714 629 } 715 630 716 631 static DEVICE_ATTR_RO(chkstop); 632 + 633 + static ssize_t ap_functions_show(struct device *dev, 634 + struct device_attribute *attr, char *buf) 635 + { 636 + struct ap_queue *aq = to_ap_queue(dev); 637 + struct ap_queue_status status; 638 + struct ap_tapq_gr2 info; 639 + 640 + status = ap_test_queue(aq->qid, 1, &info); 641 + if (status.response_code > AP_RESPONSE_BUSY) { 642 + AP_DBF_DBG("%s RC 0x%02x on tapq(0x%02x.%04x)\n", 643 + __func__, status.response_code, 644 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 645 + return -EIO; 646 + } 647 + 648 + return sysfs_emit(buf, "0x%08X\n", info.fac); 649 + } 650 + 651 + static DEVICE_ATTR_RO(ap_functions); 717 652 718 653 #ifdef CONFIG_ZCRYPT_DEBUG 719 654 static ssize_t states_show(struct device *dev, ··· 746 641 /* queue device state */ 747 642 switch (aq->dev_state) { 748 643 case AP_DEV_STATE_UNINITIATED: 749 - rc = scnprintf(buf, PAGE_SIZE, "UNINITIATED\n"); 644 + rc = sysfs_emit(buf, "UNINITIATED\n"); 750 645 break; 751 646 case AP_DEV_STATE_OPERATING: 752 - rc = scnprintf(buf, PAGE_SIZE, "OPERATING"); 647 + rc = sysfs_emit(buf, "OPERATING"); 753 648 break; 754 649 case AP_DEV_STATE_SHUTDOWN: 755 - rc = scnprintf(buf, PAGE_SIZE, "SHUTDOWN"); 650 + rc = sysfs_emit(buf, "SHUTDOWN"); 756 651 break; 757 652 case AP_DEV_STATE_ERROR: 758 - rc = scnprintf(buf, PAGE_SIZE, "ERROR"); 653 + rc = sysfs_emit(buf, "ERROR"); 759 654 break; 760 655 default: 761 - rc = scnprintf(buf, PAGE_SIZE, "UNKNOWN"); 656 + rc = sysfs_emit(buf, "UNKNOWN"); 762 657 } 763 658 /* state machine state */ 764 659 if (aq->dev_state) { 765 660 switch (aq->sm_state) { 766 661 case AP_SM_STATE_RESET_START: 767 - rc += scnprintf(buf + rc, PAGE_SIZE - rc, 768 - " [RESET_START]\n"); 662 + rc += sysfs_emit_at(buf, rc, " [RESET_START]\n"); 769 663 break; 770 664 case AP_SM_STATE_RESET_WAIT: 771 - rc += scnprintf(buf + rc, PAGE_SIZE - rc, 772 - " [RESET_WAIT]\n"); 665 + rc += sysfs_emit_at(buf, rc, " [RESET_WAIT]\n"); 773 666 break; 774 667 case AP_SM_STATE_SETIRQ_WAIT: 775 - rc += scnprintf(buf + rc, PAGE_SIZE - rc, 776 - " [SETIRQ_WAIT]\n"); 668 + rc += sysfs_emit_at(buf, rc, " [SETIRQ_WAIT]\n"); 777 669 break; 778 670 case AP_SM_STATE_IDLE: 779 - rc += scnprintf(buf + rc, PAGE_SIZE - rc, 780 - " [IDLE]\n"); 671 + rc += sysfs_emit_at(buf, rc, " [IDLE]\n"); 781 672 break; 782 673 case AP_SM_STATE_WORKING: 783 - rc += scnprintf(buf + rc, PAGE_SIZE - rc, 784 - " [WORKING]\n"); 674 + rc += sysfs_emit_at(buf, rc, " [WORKING]\n"); 785 675 break; 786 676 case AP_SM_STATE_QUEUE_FULL: 787 - rc += scnprintf(buf + rc, PAGE_SIZE - rc, 788 - " [FULL]\n"); 677 + rc += sysfs_emit_at(buf, rc, " [FULL]\n"); 678 + break; 679 + case AP_SM_STATE_ASSOC_WAIT: 680 + rc += sysfs_emit_at(buf, rc, " [ASSOC_WAIT]\n"); 789 681 break; 790 682 default: 791 - rc += scnprintf(buf + rc, PAGE_SIZE - rc, 792 - " [UNKNOWN]\n"); 683 + rc += sysfs_emit_at(buf, rc, " [UNKNOWN]\n"); 793 684 } 794 685 } 795 686 spin_unlock_bh(&aq->lock); ··· 806 705 807 706 switch (rc) { 808 707 case AP_RESPONSE_NORMAL: 809 - return scnprintf(buf, PAGE_SIZE, "NORMAL\n"); 708 + return sysfs_emit(buf, "NORMAL\n"); 810 709 case AP_RESPONSE_Q_NOT_AVAIL: 811 - return scnprintf(buf, PAGE_SIZE, "Q_NOT_AVAIL\n"); 710 + return sysfs_emit(buf, "Q_NOT_AVAIL\n"); 812 711 case AP_RESPONSE_RESET_IN_PROGRESS: 813 - return scnprintf(buf, PAGE_SIZE, "RESET_IN_PROGRESS\n"); 712 + return sysfs_emit(buf, "RESET_IN_PROGRESS\n"); 814 713 case AP_RESPONSE_DECONFIGURED: 815 - return scnprintf(buf, PAGE_SIZE, "DECONFIGURED\n"); 714 + return sysfs_emit(buf, "DECONFIGURED\n"); 816 715 case AP_RESPONSE_CHECKSTOPPED: 817 - return scnprintf(buf, PAGE_SIZE, "CHECKSTOPPED\n"); 716 + return sysfs_emit(buf, "CHECKSTOPPED\n"); 818 717 case AP_RESPONSE_BUSY: 819 - return scnprintf(buf, PAGE_SIZE, "BUSY\n"); 718 + return sysfs_emit(buf, "BUSY\n"); 820 719 case AP_RESPONSE_INVALID_ADDRESS: 821 - return scnprintf(buf, PAGE_SIZE, "INVALID_ADDRESS\n"); 720 + return sysfs_emit(buf, "INVALID_ADDRESS\n"); 822 721 case AP_RESPONSE_OTHERWISE_CHANGED: 823 - return scnprintf(buf, PAGE_SIZE, "OTHERWISE_CHANGED\n"); 722 + return sysfs_emit(buf, "OTHERWISE_CHANGED\n"); 824 723 case AP_RESPONSE_Q_FULL: 825 - return scnprintf(buf, PAGE_SIZE, "Q_FULL/NO_PENDING_REPLY\n"); 724 + return sysfs_emit(buf, "Q_FULL/NO_PENDING_REPLY\n"); 826 725 case AP_RESPONSE_INDEX_TOO_BIG: 827 - return scnprintf(buf, PAGE_SIZE, "INDEX_TOO_BIG\n"); 726 + return sysfs_emit(buf, "INDEX_TOO_BIG\n"); 828 727 case AP_RESPONSE_NO_FIRST_PART: 829 - return scnprintf(buf, PAGE_SIZE, "NO_FIRST_PART\n"); 728 + return sysfs_emit(buf, "NO_FIRST_PART\n"); 830 729 case AP_RESPONSE_MESSAGE_TOO_BIG: 831 - return scnprintf(buf, PAGE_SIZE, "MESSAGE_TOO_BIG\n"); 730 + return sysfs_emit(buf, "MESSAGE_TOO_BIG\n"); 832 731 case AP_RESPONSE_REQ_FAC_NOT_INST: 833 - return scnprintf(buf, PAGE_SIZE, "REQ_FAC_NOT_INST\n"); 732 + return sysfs_emit(buf, "REQ_FAC_NOT_INST\n"); 834 733 default: 835 - return scnprintf(buf, PAGE_SIZE, "response code %d\n", rc); 734 + return sysfs_emit(buf, "response code %d\n", rc); 836 735 } 837 736 } 838 737 static DEVICE_ATTR_RO(last_err_rc); ··· 846 745 &dev_attr_interrupt.attr, 847 746 &dev_attr_config.attr, 848 747 &dev_attr_chkstop.attr, 748 + &dev_attr_ap_functions.attr, 849 749 #ifdef CONFIG_ZCRYPT_DEBUG 850 750 &dev_attr_states.attr, 851 751 &dev_attr_last_err_rc.attr, ··· 866 764 static struct device_type ap_queue_type = { 867 765 .name = "ap_queue", 868 766 .groups = ap_queue_dev_attr_groups, 767 + }; 768 + 769 + static ssize_t se_bind_show(struct device *dev, 770 + struct device_attribute *attr, char *buf) 771 + { 772 + struct ap_queue *aq = to_ap_queue(dev); 773 + struct ap_queue_status status; 774 + struct ap_tapq_gr2 info; 775 + 776 + if (!ap_q_supports_bind(aq)) 777 + return sysfs_emit(buf, "-\n"); 778 + 779 + status = ap_test_queue(aq->qid, 1, &info); 780 + if (status.response_code > AP_RESPONSE_BUSY) { 781 + AP_DBF_DBG("%s RC 0x%02x on tapq(0x%02x.%04x)\n", 782 + __func__, status.response_code, 783 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 784 + return -EIO; 785 + } 786 + switch (info.bs) { 787 + case AP_BS_Q_USABLE: 788 + case AP_BS_Q_USABLE_NO_SECURE_KEY: 789 + return sysfs_emit(buf, "bound\n"); 790 + default: 791 + return sysfs_emit(buf, "unbound\n"); 792 + } 793 + } 794 + 795 + static ssize_t se_bind_store(struct device *dev, 796 + struct device_attribute *attr, 797 + const char *buf, size_t count) 798 + { 799 + struct ap_queue *aq = to_ap_queue(dev); 800 + struct ap_queue_status status; 801 + bool value; 802 + int rc; 803 + 804 + if (!ap_q_supports_bind(aq)) 805 + return -EINVAL; 806 + 807 + /* only 0 (unbind) and 1 (bind) allowed */ 808 + rc = kstrtobool(buf, &value); 809 + if (rc) 810 + return rc; 811 + 812 + if (value) { 813 + /* bind, do BAPQ */ 814 + spin_lock_bh(&aq->lock); 815 + if (aq->sm_state < AP_SM_STATE_IDLE) { 816 + spin_unlock_bh(&aq->lock); 817 + return -EBUSY; 818 + } 819 + status = ap_bapq(aq->qid); 820 + spin_unlock_bh(&aq->lock); 821 + if (status.response_code) { 822 + AP_DBF_WARN("%s RC 0x%02x on bapq(0x%02x.%04x)\n", 823 + __func__, status.response_code, 824 + AP_QID_CARD(aq->qid), 825 + AP_QID_QUEUE(aq->qid)); 826 + return -EIO; 827 + } 828 + } else { 829 + /* unbind, set F bit arg and trigger RAPQ */ 830 + spin_lock_bh(&aq->lock); 831 + __ap_flush_queue(aq); 832 + aq->rapq_fbit = 1; 833 + aq->assoc_idx = ASSOC_IDX_INVALID; 834 + aq->sm_state = AP_SM_STATE_RESET_START; 835 + ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); 836 + spin_unlock_bh(&aq->lock); 837 + } 838 + 839 + return count; 840 + } 841 + 842 + static DEVICE_ATTR_RW(se_bind); 843 + 844 + static ssize_t se_associate_show(struct device *dev, 845 + struct device_attribute *attr, char *buf) 846 + { 847 + struct ap_queue *aq = to_ap_queue(dev); 848 + struct ap_queue_status status; 849 + struct ap_tapq_gr2 info; 850 + 851 + if (!ap_q_supports_assoc(aq)) 852 + return sysfs_emit(buf, "-\n"); 853 + 854 + status = ap_test_queue(aq->qid, 1, &info); 855 + if (status.response_code > AP_RESPONSE_BUSY) { 856 + AP_DBF_DBG("%s RC 0x%02x on tapq(0x%02x.%04x)\n", 857 + __func__, status.response_code, 858 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 859 + return -EIO; 860 + } 861 + 862 + switch (info.bs) { 863 + case AP_BS_Q_USABLE: 864 + if (aq->assoc_idx == ASSOC_IDX_INVALID) { 865 + AP_DBF_WARN("%s AP_BS_Q_USABLE but invalid assoc_idx\n", __func__); 866 + return -EIO; 867 + } 868 + return sysfs_emit(buf, "associated %u\n", aq->assoc_idx); 869 + case AP_BS_Q_USABLE_NO_SECURE_KEY: 870 + if (aq->assoc_idx != ASSOC_IDX_INVALID) 871 + return sysfs_emit(buf, "association pending\n"); 872 + fallthrough; 873 + default: 874 + return sysfs_emit(buf, "unassociated\n"); 875 + } 876 + } 877 + 878 + static ssize_t se_associate_store(struct device *dev, 879 + struct device_attribute *attr, 880 + const char *buf, size_t count) 881 + { 882 + struct ap_queue *aq = to_ap_queue(dev); 883 + struct ap_queue_status status; 884 + unsigned int value; 885 + int rc; 886 + 887 + if (!ap_q_supports_assoc(aq)) 888 + return -EINVAL; 889 + 890 + /* association index needs to be >= 0 */ 891 + rc = kstrtouint(buf, 0, &value); 892 + if (rc) 893 + return rc; 894 + if (value >= ASSOC_IDX_INVALID) 895 + return -EINVAL; 896 + 897 + spin_lock_bh(&aq->lock); 898 + 899 + /* sm should be in idle state */ 900 + if (aq->sm_state != AP_SM_STATE_IDLE) { 901 + spin_unlock_bh(&aq->lock); 902 + return -EBUSY; 903 + } 904 + 905 + /* already associated or association pending ? */ 906 + if (aq->assoc_idx != ASSOC_IDX_INVALID) { 907 + spin_unlock_bh(&aq->lock); 908 + return -EINVAL; 909 + } 910 + 911 + /* trigger the asynchronous association request */ 912 + status = ap_aapq(aq->qid, value); 913 + switch (status.response_code) { 914 + case AP_RESPONSE_NORMAL: 915 + case AP_RESPONSE_STATE_CHANGE_IN_PROGRESS: 916 + aq->sm_state = AP_SM_STATE_ASSOC_WAIT; 917 + aq->assoc_idx = value; 918 + ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); 919 + spin_unlock_bh(&aq->lock); 920 + break; 921 + default: 922 + spin_unlock_bh(&aq->lock); 923 + AP_DBF_WARN("%s RC 0x%02x on aapq(0x%02x.%04x)\n", 924 + __func__, status.response_code, 925 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 926 + return -EIO; 927 + } 928 + 929 + return count; 930 + } 931 + 932 + static DEVICE_ATTR_RW(se_associate); 933 + 934 + static struct attribute *ap_queue_dev_sb_attrs[] = { 935 + &dev_attr_se_bind.attr, 936 + &dev_attr_se_associate.attr, 937 + NULL 938 + }; 939 + 940 + static struct attribute_group ap_queue_dev_sb_attr_group = { 941 + .attrs = ap_queue_dev_sb_attrs 942 + }; 943 + 944 + static const struct attribute_group *ap_queue_dev_sb_attr_groups[] = { 945 + &ap_queue_dev_sb_attr_group, 946 + NULL 869 947 }; 870 948 871 949 static void ap_queue_device_release(struct device *dev) ··· 1069 787 aq->ap_dev.device.release = ap_queue_device_release; 1070 788 aq->ap_dev.device.type = &ap_queue_type; 1071 789 aq->ap_dev.device_type = device_type; 790 + // add optional SE secure binding attributes group 791 + if (ap_sb_available() && is_prot_virt_guest()) 792 + aq->ap_dev.device.groups = ap_queue_dev_sb_attr_groups; 1072 793 aq->qid = qid; 1073 794 aq->interrupt = false; 1074 795 spin_lock_init(&aq->lock); ··· 1207 922 * to the initial value AP_DEV_STATE_UNINITIATED. 1208 923 */ 1209 924 spin_lock_bh(&aq->lock); 1210 - ap_zapq(aq->qid); 925 + ap_zapq(aq->qid, 0); 1211 926 aq->dev_state = AP_DEV_STATE_UNINITIATED; 1212 927 spin_unlock_bh(&aq->lock); 1213 928 } ··· 1218 933 aq->dev_state = AP_DEV_STATE_OPERATING; 1219 934 aq->sm_state = AP_SM_STATE_RESET_START; 1220 935 aq->last_err_rc = 0; 936 + aq->assoc_idx = ASSOC_IDX_INVALID; 1221 937 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); 1222 938 spin_unlock_bh(&aq->lock); 1223 939 }
-6
drivers/s390/crypto/vfio_ap_drv.c
··· 60 60 kfree(matrix_dev); 61 61 } 62 62 63 - static int matrix_bus_match(struct device *dev, struct device_driver *drv) 64 - { 65 - return 1; 66 - } 67 - 68 63 static struct bus_type matrix_bus = { 69 64 .name = "matrix", 70 - .match = &matrix_bus_match, 71 65 }; 72 66 73 67 static struct device_driver matrix_driver = {
+7 -9
drivers/s390/crypto/vfio_ap_ops.c
··· 599 599 static void vfio_ap_matrix_init(struct ap_config_info *info, 600 600 struct ap_matrix *matrix) 601 601 { 602 - matrix->apm_max = info->apxa ? info->Na : 63; 603 - matrix->aqm_max = info->apxa ? info->Nd : 15; 604 - matrix->adm_max = info->apxa ? info->Nd : 15; 602 + matrix->apm_max = info->apxa ? info->na : 63; 603 + matrix->aqm_max = info->apxa ? info->nd : 15; 604 + matrix->adm_max = info->apxa ? info->nd : 15; 605 605 } 606 606 607 607 static void vfio_ap_mdev_update_guest_apcb(struct ap_matrix_mdev *matrix_mdev) ··· 1657 1657 if (!q) 1658 1658 return 0; 1659 1659 retry_zapq: 1660 - status = ap_zapq(q->apqn); 1660 + status = ap_zapq(q->apqn, 0); 1661 1661 q->reset_rc = status.response_code; 1662 1662 switch (status.response_code) { 1663 1663 case AP_RESPONSE_NORMAL: ··· 2115 2115 { 2116 2116 bool apid_cleared; 2117 2117 struct ap_queue_status status; 2118 - unsigned long apid, apqi, info; 2119 - int qtype, qtype_mask = 0xff000000; 2118 + unsigned long apid, apqi; 2119 + struct ap_tapq_gr2 info; 2120 2120 2121 2121 for_each_set_bit_inv(apid, apm, AP_DEVICES) { 2122 2122 apid_cleared = false; ··· 2133 2133 case AP_RESPONSE_DECONFIGURED: 2134 2134 case AP_RESPONSE_CHECKSTOPPED: 2135 2135 case AP_RESPONSE_BUSY: 2136 - qtype = info & qtype_mask; 2137 - 2138 2136 /* 2139 2137 * The vfio_ap device driver only 2140 2138 * supports CEX4 and newer adapters, so 2141 2139 * remove the APID if the adapter is 2142 2140 * older than a CEX4. 2143 2141 */ 2144 - if (qtype < AP_DEVICE_TYPE_CEX4) { 2142 + if (info.at < AP_DEVICE_TYPE_CEX4) { 2145 2143 clear_bit_inv(apid, apm); 2146 2144 apid_cleared = true; 2147 2145 }
+20 -40
drivers/s390/crypto/zcrypt_api.c
··· 159 159 struct device_attribute *attr, 160 160 char *buf) 161 161 { 162 - int i, rc; 163 162 struct zcdn_device *zcdndev = to_zcdn_dev(dev); 163 + int i, n; 164 164 165 165 if (mutex_lock_interruptible(&ap_perms_mutex)) 166 166 return -ERESTARTSYS; 167 167 168 - buf[0] = '0'; 169 - buf[1] = 'x'; 168 + n = sysfs_emit(buf, "0x"); 170 169 for (i = 0; i < sizeof(zcdndev->perms.ioctlm) / sizeof(long); i++) 171 - snprintf(buf + 2 + 2 * i * sizeof(long), 172 - PAGE_SIZE - 2 - 2 * i * sizeof(long), 173 - "%016lx", zcdndev->perms.ioctlm[i]); 174 - buf[2 + 2 * i * sizeof(long)] = '\n'; 175 - buf[2 + 2 * i * sizeof(long) + 1] = '\0'; 176 - rc = 2 + 2 * i * sizeof(long) + 1; 170 + n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.ioctlm[i]); 171 + n += sysfs_emit_at(buf, n, "\n"); 177 172 178 173 mutex_unlock(&ap_perms_mutex); 179 174 180 - return rc; 175 + return n; 181 176 } 182 177 183 178 static ssize_t ioctlmask_store(struct device *dev, ··· 196 201 struct device_attribute *attr, 197 202 char *buf) 198 203 { 199 - int i, rc; 200 204 struct zcdn_device *zcdndev = to_zcdn_dev(dev); 205 + int i, n; 201 206 202 207 if (mutex_lock_interruptible(&ap_perms_mutex)) 203 208 return -ERESTARTSYS; 204 209 205 - buf[0] = '0'; 206 - buf[1] = 'x'; 210 + n = sysfs_emit(buf, "0x"); 207 211 for (i = 0; i < sizeof(zcdndev->perms.apm) / sizeof(long); i++) 208 - snprintf(buf + 2 + 2 * i * sizeof(long), 209 - PAGE_SIZE - 2 - 2 * i * sizeof(long), 210 - "%016lx", zcdndev->perms.apm[i]); 211 - buf[2 + 2 * i * sizeof(long)] = '\n'; 212 - buf[2 + 2 * i * sizeof(long) + 1] = '\0'; 213 - rc = 2 + 2 * i * sizeof(long) + 1; 212 + n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.apm[i]); 213 + n += sysfs_emit_at(buf, n, "\n"); 214 214 215 215 mutex_unlock(&ap_perms_mutex); 216 216 217 - return rc; 217 + return n; 218 218 } 219 219 220 220 static ssize_t apmask_store(struct device *dev, ··· 233 243 struct device_attribute *attr, 234 244 char *buf) 235 245 { 236 - int i, rc; 237 246 struct zcdn_device *zcdndev = to_zcdn_dev(dev); 247 + int i, n; 238 248 239 249 if (mutex_lock_interruptible(&ap_perms_mutex)) 240 250 return -ERESTARTSYS; 241 251 242 - buf[0] = '0'; 243 - buf[1] = 'x'; 252 + n = sysfs_emit(buf, "0x"); 244 253 for (i = 0; i < sizeof(zcdndev->perms.aqm) / sizeof(long); i++) 245 - snprintf(buf + 2 + 2 * i * sizeof(long), 246 - PAGE_SIZE - 2 - 2 * i * sizeof(long), 247 - "%016lx", zcdndev->perms.aqm[i]); 248 - buf[2 + 2 * i * sizeof(long)] = '\n'; 249 - buf[2 + 2 * i * sizeof(long) + 1] = '\0'; 250 - rc = 2 + 2 * i * sizeof(long) + 1; 254 + n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.aqm[i]); 255 + n += sysfs_emit_at(buf, n, "\n"); 251 256 252 257 mutex_unlock(&ap_perms_mutex); 253 258 254 - return rc; 259 + return n; 255 260 } 256 261 257 262 static ssize_t aqmask_store(struct device *dev, ··· 270 285 struct device_attribute *attr, 271 286 char *buf) 272 287 { 273 - int i, rc; 274 288 struct zcdn_device *zcdndev = to_zcdn_dev(dev); 289 + int i, n; 275 290 276 291 if (mutex_lock_interruptible(&ap_perms_mutex)) 277 292 return -ERESTARTSYS; 278 293 279 - buf[0] = '0'; 280 - buf[1] = 'x'; 294 + n = sysfs_emit(buf, "0x"); 281 295 for (i = 0; i < sizeof(zcdndev->perms.adm) / sizeof(long); i++) 282 - snprintf(buf + 2 + 2 * i * sizeof(long), 283 - PAGE_SIZE - 2 - 2 * i * sizeof(long), 284 - "%016lx", zcdndev->perms.adm[i]); 285 - buf[2 + 2 * i * sizeof(long)] = '\n'; 286 - buf[2 + 2 * i * sizeof(long) + 1] = '\0'; 287 - rc = 2 + 2 * i * sizeof(long) + 1; 296 + n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.adm[i]); 297 + n += sysfs_emit_at(buf, n, "\n"); 288 298 289 299 mutex_unlock(&ap_perms_mutex); 290 300 291 - return rc; 301 + return n; 292 302 } 293 303 294 304 static ssize_t admask_store(struct device *dev,
+3 -3
drivers/s390/crypto/zcrypt_card.c
··· 41 41 { 42 42 struct zcrypt_card *zc = dev_get_drvdata(dev); 43 43 44 - return scnprintf(buf, PAGE_SIZE, "%s\n", zc->type_string); 44 + return sysfs_emit(buf, "%s\n", zc->type_string); 45 45 } 46 46 47 47 static DEVICE_ATTR_RO(type); ··· 54 54 struct ap_card *ac = to_ap_card(dev); 55 55 int online = ac->config && zc->online ? 1 : 0; 56 56 57 - return scnprintf(buf, PAGE_SIZE, "%d\n", online); 57 + return sysfs_emit(buf, "%d\n", online); 58 58 } 59 59 60 60 static ssize_t online_store(struct device *dev, ··· 118 118 { 119 119 struct zcrypt_card *zc = dev_get_drvdata(dev); 120 120 121 - return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zc->load)); 121 + return sysfs_emit(buf, "%d\n", atomic_read(&zc->load)); 122 122 } 123 123 124 124 static DEVICE_ATTR_RO(load);
+13 -24
drivers/s390/crypto/zcrypt_cca_key.h
··· 89 89 #define CCA_PVT_EXT_CRT_SEC_FMT_CL 0x40 90 90 91 91 /** 92 - * Set up private key fields of a type6 MEX message. The _pad variant 93 - * strips leading zeroes from the b_key. 94 - * Note that all numerics in the key token are big-endian, 95 - * while the entries in the key block header are little-endian. 92 + * Set up private key fields of a type6 MEX message. 96 93 * 97 94 * @mex: pointer to user input data 98 95 * @p: pointer to memory area for the key ··· 108 111 struct t6_keyblock_hdr t6_hdr; 109 112 struct cca_token_hdr pubhdr; 110 113 struct cca_public_sec pubsec; 111 - char exponent[0]; 114 + char exponent[]; 112 115 } __packed *key = p; 113 - unsigned char *temp; 114 - int i; 116 + unsigned char *ptr; 115 117 116 118 /* 117 119 * The inputdatalength was a selection criteria in the dispatching ··· 127 131 key->pubsec = static_pub_sec; 128 132 129 133 /* key parameter block */ 130 - temp = key->exponent; 131 - if (copy_from_user(temp, mex->b_key, mex->inputdatalength)) 134 + ptr = key->exponent; 135 + if (copy_from_user(ptr, mex->b_key, mex->inputdatalength)) 132 136 return -EFAULT; 133 - /* Strip leading zeroes from b_key. */ 134 - for (i = 0; i < mex->inputdatalength; i++) 135 - if (temp[i]) 136 - break; 137 - if (i >= mex->inputdatalength) 138 - return -EINVAL; 139 - memmove(temp, temp + i, mex->inputdatalength - i); 140 - temp += mex->inputdatalength - i; 137 + ptr += mex->inputdatalength; 141 138 /* modulus */ 142 - if (copy_from_user(temp, mex->n_modulus, mex->inputdatalength)) 139 + if (copy_from_user(ptr, mex->n_modulus, mex->inputdatalength)) 143 140 return -EFAULT; 144 141 145 142 key->pubsec.modulus_bit_len = 8 * mex->inputdatalength; 146 143 key->pubsec.modulus_byte_len = mex->inputdatalength; 147 - key->pubsec.exponent_len = mex->inputdatalength - i; 144 + key->pubsec.exponent_len = mex->inputdatalength; 148 145 key->pubsec.section_length = sizeof(key->pubsec) + 149 - 2 * mex->inputdatalength - i; 146 + 2 * mex->inputdatalength; 150 147 key->pubhdr.token_length = 151 148 key->pubsec.section_length + sizeof(key->pubhdr); 152 149 key->t6_hdr.ulen = key->pubhdr.token_length + 4; 153 150 key->t6_hdr.blen = key->pubhdr.token_length + 6; 154 - return sizeof(*key) + 2 * mex->inputdatalength - i; 151 + 152 + return sizeof(*key) + 2 * mex->inputdatalength; 155 153 } 156 154 157 155 /** 158 156 * Set up private key fields of a type6 CRT message. 159 - * Note that all numerics in the key token are big-endian, 160 - * while the entries in the key block header are little-endian. 161 157 * 162 158 * @mex: pointer to user input data 163 159 * @p: pointer to memory area for the key ··· 168 180 struct t6_keyblock_hdr t6_hdr; 169 181 struct cca_token_hdr token; 170 182 struct cca_pvt_ext_crt_sec pvt; 171 - char key_parts[0]; 183 + char key_parts[]; 172 184 } __packed *key = p; 173 185 struct cca_public_sec *pub; 174 186 int short_len, long_len, pad_len, key_len, size; ··· 230 242 * used. 231 243 */ 232 244 memcpy((char *)(pub + 1), pk_exponent, 3); 245 + 233 246 return size; 234 247 } 235 248
+36 -38
drivers/s390/crypto/zcrypt_ccamisc.c
··· 450 450 char rule_array[8]; 451 451 struct lv1 { 452 452 u16 len; 453 - u8 clrkey[0]; 453 + u8 clrkey[]; 454 454 } lv1; 455 - struct lv2 { 456 - u16 len; 457 - struct keyid { 458 - u16 len; 459 - u16 attr; 460 - u8 data[SECKEYBLOBSIZE]; 461 - } keyid; 462 - } lv2; 455 + /* followed by struct lv2 */ 463 456 } __packed * preqparm; 464 - struct lv2 *plv2; 457 + struct lv2 { 458 + u16 len; 459 + struct keyid { 460 + u16 len; 461 + u16 attr; 462 + u8 data[SECKEYBLOBSIZE]; 463 + } keyid; 464 + } __packed * plv2; 465 465 struct cmrepparm { 466 466 u8 subfunc_code[2]; 467 467 u16 rule_array_len; ··· 512 512 } 513 513 preqparm->lv1.len = sizeof(struct lv1) + keysize; 514 514 memcpy(preqparm->lv1.clrkey, clrkey, keysize); 515 - plv2 = (struct lv2 *)(((u8 *)&preqparm->lv2) + keysize); 515 + plv2 = (struct lv2 *)(((u8 *)preqparm) + sizeof(*preqparm) + keysize); 516 516 plv2->len = sizeof(struct lv2); 517 517 plv2->keyid.len = sizeof(struct keyid); 518 518 plv2->keyid.attr = 0x30; 519 - preqcblk->req_parml = sizeof(struct cmreqparm) + keysize; 519 + preqcblk->req_parml = sizeof(*preqparm) + keysize + sizeof(*plv2); 520 520 521 521 /* fill xcrb struct */ 522 522 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); ··· 761 761 u16 key_name_2_len; 762 762 u16 user_data_1_len; 763 763 u16 user_data_2_len; 764 - u8 key_name_1[0]; 765 - u8 key_name_2[0]; 766 - u8 user_data_1[0]; 767 - u8 user_data_2[0]; 764 + /* u8 key_name_1[]; */ 765 + /* u8 key_name_2[]; */ 766 + /* u8 user_data_1[]; */ 767 + /* u8 user_data_2[]; */ 768 768 } vud; 769 769 struct { 770 770 u16 len; 771 771 struct { 772 772 u16 len; 773 773 u16 flag; 774 - u8 kek_id_1[0]; 774 + /* u8 kek_id_1[]; */ 775 775 } tlv1; 776 776 struct { 777 777 u16 len; 778 778 u16 flag; 779 - u8 kek_id_2[0]; 779 + /* u8 kek_id_2[]; */ 780 780 } tlv2; 781 781 struct { 782 782 u16 len; ··· 786 786 struct { 787 787 u16 len; 788 788 u16 flag; 789 - u8 gen_key_id_1_label[0]; 789 + /* u8 gen_key_id_1_label[]; */ 790 790 } tlv4; 791 791 struct { 792 792 u16 len; 793 793 u16 flag; 794 - u8 gen_key_id_2[0]; 794 + /* u8 gen_key_id_2[]; */ 795 795 } tlv5; 796 796 struct { 797 797 u16 len; 798 798 u16 flag; 799 - u8 gen_key_id_2_label[0]; 799 + /* u8 gen_key_id_2_label[]; */ 800 800 } tlv6; 801 801 } kb; 802 802 } __packed * preqparm; ··· 811 811 struct { 812 812 u16 len; 813 813 u16 flag; 814 - u8 gen_key[0]; /* 120-136 bytes */ 814 + u8 gen_key[]; /* 120-136 bytes */ 815 815 } tlv1; 816 816 } kb; 817 817 } __packed * prepparm; ··· 955 955 struct rule_array_block { 956 956 u8 subfunc_code[2]; 957 957 u16 rule_array_len; 958 - char rule_array[0]; 958 + char rule_array[]; 959 959 } __packed * preq_ra_block; 960 960 struct vud_block { 961 961 u16 len; ··· 967 967 struct { 968 968 u16 len; 969 969 u16 flag; /* 0x0063 */ 970 - u8 clr_key[0]; /* clear key value bytes */ 970 + u8 clr_key[]; /* clear key value bytes */ 971 971 } tlv2; 972 972 } __packed * preq_vud_block; 973 973 struct key_block { ··· 975 975 struct { 976 976 u16 len; 977 977 u16 flag; /* 0x0030 */ 978 - u8 key_token[0]; /* key skeleton */ 978 + u8 key_token[]; /* key skeleton */ 979 979 } tlv1; 980 980 } __packed * preq_key_block; 981 981 struct iprepparm { ··· 989 989 struct { 990 990 u16 len; 991 991 u16 flag; /* 0x0030 */ 992 - u8 key_token[0]; /* key token */ 992 + u8 key_token[]; /* key token */ 993 993 } tlv1; 994 994 } kb; 995 995 } __packed * prepparm; ··· 1201 1201 u16 len; 1202 1202 u16 cca_key_token_len; 1203 1203 u16 cca_key_token_flags; 1204 - u8 cca_key_token[0]; // 64 or more 1204 + u8 cca_key_token[]; /* 64 or more */ 1205 1205 } kb; 1206 1206 } __packed * preqparm; 1207 1207 struct aurepparm { ··· 1370 1370 u16 len; 1371 1371 u16 cca_key_token_len; 1372 1372 u16 cca_key_token_flags; 1373 - u8 cca_key_token[0]; 1373 + u8 cca_key_token[]; 1374 1374 } kb; 1375 1375 } __packed * preqparm; 1376 1376 struct aurepparm { ··· 1387 1387 u8 form; 1388 1388 u8 pad1[3]; 1389 1389 u16 keylen; 1390 - u8 key[0]; /* the key (keylen bytes) */ 1391 - u16 keyattrlen; 1392 - u8 keyattr[32]; 1393 - u8 pad2[1]; 1394 - u8 vptype; 1395 - u8 vp[32]; /* verification pattern */ 1390 + u8 key[]; /* the key (keylen bytes) */ 1391 + /* u16 keyattrlen; */ 1392 + /* u8 keyattr[32]; */ 1393 + /* u8 pad2[1]; */ 1394 + /* u8 vptype; */ 1395 + /* u8 vp[32]; verification pattern */ 1396 1396 } ckb; 1397 1397 } vud; 1398 - struct { 1399 - u16 len; 1400 - } kb; 1398 + /* followed by a key block */ 1401 1399 } __packed * prepparm; 1402 1400 int keylen = ((struct eccprivkeytoken *)key)->len; 1403 1401 ··· 1523 1525 size_t parmbsize = sizeof(struct fqreqparm); 1524 1526 struct fqrepparm { 1525 1527 u8 subfunc_code[2]; 1526 - u8 lvdata[0]; 1528 + u8 lvdata[]; 1527 1529 } __packed * prepparm; 1528 1530 1529 1531 /* get already prepared memory for 2 cprbs with param block each */
+31 -35
drivers/s390/crypto/zcrypt_cex2c.c
··· 75 75 if (ap_domain_index >= 0) 76 76 cca_get_info(ac->id, ap_domain_index, &ci, zc->online); 77 77 78 - return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial); 78 + return sysfs_emit(buf, "%s\n", ci.serial); 79 79 } 80 80 81 81 static struct device_attribute dev_attr_cca_serialnr = ··· 110 110 &ci, zq->online); 111 111 112 112 if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3') 113 - n = scnprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n", 114 - new_state[ci.new_aes_mk_state - '1'], 115 - ci.new_aes_mkvp); 113 + n = sysfs_emit(buf, "AES NEW: %s 0x%016llx\n", 114 + new_state[ci.new_aes_mk_state - '1'], 115 + ci.new_aes_mkvp); 116 116 else 117 - n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n"); 117 + n = sysfs_emit(buf, "AES NEW: - -\n"); 118 118 119 119 if (ci.cur_aes_mk_state >= '1' && ci.cur_aes_mk_state <= '2') 120 - n += scnprintf(buf + n, PAGE_SIZE - n, 121 - "AES CUR: %s 0x%016llx\n", 122 - cao_state[ci.cur_aes_mk_state - '1'], 123 - ci.cur_aes_mkvp); 120 + n += sysfs_emit_at(buf, n, "AES CUR: %s 0x%016llx\n", 121 + cao_state[ci.cur_aes_mk_state - '1'], 122 + ci.cur_aes_mkvp); 124 123 else 125 - n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n"); 124 + n += sysfs_emit_at(buf, n, "AES CUR: - -\n"); 126 125 127 126 if (ci.old_aes_mk_state >= '1' && ci.old_aes_mk_state <= '2') 128 - n += scnprintf(buf + n, PAGE_SIZE - n, 129 - "AES OLD: %s 0x%016llx\n", 130 - cao_state[ci.old_aes_mk_state - '1'], 131 - ci.old_aes_mkvp); 127 + n += sysfs_emit_at(buf, n, "AES OLD: %s 0x%016llx\n", 128 + cao_state[ci.old_aes_mk_state - '1'], 129 + ci.old_aes_mkvp); 132 130 else 133 - n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n"); 131 + n += sysfs_emit_at(buf, n, "AES OLD: - -\n"); 134 132 135 133 if (ci.new_apka_mk_state >= '1' && ci.new_apka_mk_state <= '3') 136 - n += scnprintf(buf + n, PAGE_SIZE - n, 137 - "APKA NEW: %s 0x%016llx\n", 138 - new_state[ci.new_apka_mk_state - '1'], 139 - ci.new_apka_mkvp); 134 + n += sysfs_emit_at(buf, n, "APKA NEW: %s 0x%016llx\n", 135 + new_state[ci.new_apka_mk_state - '1'], 136 + ci.new_apka_mkvp); 140 137 else 141 - n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n"); 138 + n += sysfs_emit_at(buf, n, "APKA NEW: - -\n"); 142 139 143 140 if (ci.cur_apka_mk_state >= '1' && ci.cur_apka_mk_state <= '2') 144 - n += scnprintf(buf + n, PAGE_SIZE - n, 145 - "APKA CUR: %s 0x%016llx\n", 146 - cao_state[ci.cur_apka_mk_state - '1'], 147 - ci.cur_apka_mkvp); 141 + n += sysfs_emit_at(buf, n, "APKA CUR: %s 0x%016llx\n", 142 + cao_state[ci.cur_apka_mk_state - '1'], 143 + ci.cur_apka_mkvp); 148 144 else 149 - n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n"); 145 + n += sysfs_emit_at(buf, n, "APKA CUR: - -\n"); 150 146 151 147 if (ci.old_apka_mk_state >= '1' && ci.old_apka_mk_state <= '2') 152 - n += scnprintf(buf + n, PAGE_SIZE - n, 153 - "APKA OLD: %s 0x%016llx\n", 154 - cao_state[ci.old_apka_mk_state - '1'], 155 - ci.old_apka_mkvp); 148 + n += sysfs_emit_at(buf, n, "APKA OLD: %s 0x%016llx\n", 149 + cao_state[ci.old_apka_mk_state - '1'], 150 + ci.old_apka_mkvp); 156 151 else 157 - n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n"); 152 + n += sysfs_emit_at(buf, n, "APKA OLD: - -\n"); 158 153 159 154 return n; 160 155 } ··· 176 181 static int zcrypt_cex2c_rng_supported(struct ap_queue *aq) 177 182 { 178 183 struct ap_message ap_msg; 179 - unsigned long long psmid; 184 + unsigned long psmid; 180 185 unsigned int domain; 181 186 struct { 182 187 struct type86_hdr hdr; ··· 198 203 ap_msg.msg = (void *)get_zeroed_page(GFP_KERNEL); 199 204 if (!ap_msg.msg) 200 205 return -ENOMEM; 206 + ap_msg.bufsize = PAGE_SIZE; 201 207 202 208 rng_type6cprb_msgx(&ap_msg, 4, &domain); 203 209 204 210 msg = ap_msg.msg; 205 211 msg->cprbx.domain = AP_QID_QUEUE(aq->qid); 206 212 207 - rc = ap_send(aq->qid, 0x0102030405060708ULL, ap_msg.msg, ap_msg.len); 213 + rc = ap_send(aq->qid, 0x0102030405060708UL, ap_msg.msg, ap_msg.len); 208 214 if (rc) 209 215 goto out_free; 210 216 211 217 /* Wait for the test message to complete. */ 212 218 for (i = 0; i < 2 * HZ; i++) { 213 219 msleep(1000 / HZ); 214 - rc = ap_recv(aq->qid, &psmid, ap_msg.msg, 4096); 215 - if (rc == 0 && psmid == 0x0102030405060708ULL) 220 + rc = ap_recv(aq->qid, &psmid, ap_msg.msg, ap_msg.bufsize); 221 + if (rc == 0 && psmid == 0x0102030405060708UL) 216 222 break; 217 223 } 218 224 ··· 338 342 zq->queue = aq; 339 343 zq->online = 1; 340 344 atomic_set(&zq->load, 0); 341 - ap_rapq(aq->qid); 345 + ap_rapq(aq->qid, 0); 342 346 rc = zcrypt_cex2c_rng_supported(aq); 343 347 if (rc < 0) { 344 348 zcrypt_queue_free(zq);
+66 -75
drivers/s390/crypto/zcrypt_cex4.c
··· 88 88 if (ap_domain_index >= 0) 89 89 cca_get_info(ac->id, ap_domain_index, &ci, zc->online); 90 90 91 - return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial); 91 + return sysfs_emit(buf, "%s\n", ci.serial); 92 92 } 93 93 94 94 static struct device_attribute dev_attr_cca_serialnr = ··· 123 123 &ci, zq->online); 124 124 125 125 if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3') 126 - n += scnprintf(buf + n, PAGE_SIZE, 127 - "AES NEW: %s 0x%016llx\n", 128 - new_state[ci.new_aes_mk_state - '1'], 129 - ci.new_aes_mkvp); 126 + n += sysfs_emit_at(buf, n, "AES NEW: %s 0x%016llx\n", 127 + new_state[ci.new_aes_mk_state - '1'], 128 + ci.new_aes_mkvp); 130 129 else 131 - n += scnprintf(buf + n, PAGE_SIZE, "AES NEW: - -\n"); 130 + n += sysfs_emit_at(buf, n, "AES NEW: - -\n"); 132 131 133 132 if (ci.cur_aes_mk_state >= '1' && ci.cur_aes_mk_state <= '2') 134 - n += scnprintf(buf + n, PAGE_SIZE - n, 135 - "AES CUR: %s 0x%016llx\n", 136 - cao_state[ci.cur_aes_mk_state - '1'], 137 - ci.cur_aes_mkvp); 133 + n += sysfs_emit_at(buf, n, "AES CUR: %s 0x%016llx\n", 134 + cao_state[ci.cur_aes_mk_state - '1'], 135 + ci.cur_aes_mkvp); 138 136 else 139 - n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n"); 137 + n += sysfs_emit_at(buf, n, "AES CUR: - -\n"); 140 138 141 139 if (ci.old_aes_mk_state >= '1' && ci.old_aes_mk_state <= '2') 142 - n += scnprintf(buf + n, PAGE_SIZE - n, 143 - "AES OLD: %s 0x%016llx\n", 144 - cao_state[ci.old_aes_mk_state - '1'], 145 - ci.old_aes_mkvp); 140 + n += sysfs_emit_at(buf, n, "AES OLD: %s 0x%016llx\n", 141 + cao_state[ci.old_aes_mk_state - '1'], 142 + ci.old_aes_mkvp); 146 143 else 147 - n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n"); 144 + n += sysfs_emit_at(buf, n, "AES OLD: - -\n"); 148 145 149 146 if (ci.new_apka_mk_state >= '1' && ci.new_apka_mk_state <= '3') 150 - n += scnprintf(buf + n, PAGE_SIZE - n, 151 - "APKA NEW: %s 0x%016llx\n", 152 - new_state[ci.new_apka_mk_state - '1'], 153 - ci.new_apka_mkvp); 147 + n += sysfs_emit_at(buf, n, "APKA NEW: %s 0x%016llx\n", 148 + new_state[ci.new_apka_mk_state - '1'], 149 + ci.new_apka_mkvp); 154 150 else 155 - n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n"); 151 + n += sysfs_emit_at(buf, n, "APKA NEW: - -\n"); 156 152 157 153 if (ci.cur_apka_mk_state >= '1' && ci.cur_apka_mk_state <= '2') 158 - n += scnprintf(buf + n, PAGE_SIZE - n, 159 - "APKA CUR: %s 0x%016llx\n", 160 - cao_state[ci.cur_apka_mk_state - '1'], 161 - ci.cur_apka_mkvp); 154 + n += sysfs_emit_at(buf, n, "APKA CUR: %s 0x%016llx\n", 155 + cao_state[ci.cur_apka_mk_state - '1'], 156 + ci.cur_apka_mkvp); 162 157 else 163 - n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n"); 158 + n += sysfs_emit_at(buf, n, "APKA CUR: - -\n"); 164 159 165 160 if (ci.old_apka_mk_state >= '1' && ci.old_apka_mk_state <= '2') 166 - n += scnprintf(buf + n, PAGE_SIZE - n, 167 - "APKA OLD: %s 0x%016llx\n", 168 - cao_state[ci.old_apka_mk_state - '1'], 169 - ci.old_apka_mkvp); 161 + n += sysfs_emit_at(buf, n, "APKA OLD: %s 0x%016llx\n", 162 + cao_state[ci.old_apka_mk_state - '1'], 163 + ci.old_apka_mkvp); 170 164 else 171 - n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n"); 165 + n += sysfs_emit_at(buf, n, "APKA OLD: - -\n"); 172 166 173 167 if (ci.new_asym_mk_state >= '1' && ci.new_asym_mk_state <= '3') 174 - n += scnprintf(buf + n, PAGE_SIZE, 175 - "ASYM NEW: %s 0x%016llx%016llx\n", 176 - new_state[ci.new_asym_mk_state - '1'], 177 - *((u64 *)(ci.new_asym_mkvp)), 178 - *((u64 *)(ci.new_asym_mkvp + sizeof(u64)))); 168 + n += sysfs_emit_at(buf, n, "ASYM NEW: %s 0x%016llx%016llx\n", 169 + new_state[ci.new_asym_mk_state - '1'], 170 + *((u64 *)(ci.new_asym_mkvp)), 171 + *((u64 *)(ci.new_asym_mkvp + sizeof(u64)))); 179 172 else 180 - n += scnprintf(buf + n, PAGE_SIZE, "ASYM NEW: - -\n"); 173 + n += sysfs_emit_at(buf, n, "ASYM NEW: - -\n"); 181 174 182 175 if (ci.cur_asym_mk_state >= '1' && ci.cur_asym_mk_state <= '2') 183 - n += scnprintf(buf + n, PAGE_SIZE - n, 184 - "ASYM CUR: %s 0x%016llx%016llx\n", 185 - cao_state[ci.cur_asym_mk_state - '1'], 186 - *((u64 *)(ci.cur_asym_mkvp)), 187 - *((u64 *)(ci.cur_asym_mkvp + sizeof(u64)))); 176 + n += sysfs_emit_at(buf, n, "ASYM CUR: %s 0x%016llx%016llx\n", 177 + cao_state[ci.cur_asym_mk_state - '1'], 178 + *((u64 *)(ci.cur_asym_mkvp)), 179 + *((u64 *)(ci.cur_asym_mkvp + sizeof(u64)))); 188 180 else 189 - n += scnprintf(buf + n, PAGE_SIZE - n, "ASYM CUR: - -\n"); 181 + n += sysfs_emit_at(buf, n, "ASYM CUR: - -\n"); 190 182 191 183 if (ci.old_asym_mk_state >= '1' && ci.old_asym_mk_state <= '2') 192 - n += scnprintf(buf + n, PAGE_SIZE - n, 193 - "ASYM OLD: %s 0x%016llx%016llx\n", 194 - cao_state[ci.old_asym_mk_state - '1'], 195 - *((u64 *)(ci.old_asym_mkvp)), 196 - *((u64 *)(ci.old_asym_mkvp + sizeof(u64)))); 184 + n += sysfs_emit_at(buf, n, "ASYM OLD: %s 0x%016llx%016llx\n", 185 + cao_state[ci.old_asym_mk_state - '1'], 186 + *((u64 *)(ci.old_asym_mkvp)), 187 + *((u64 *)(ci.old_asym_mkvp + sizeof(u64)))); 197 188 else 198 - n += scnprintf(buf + n, PAGE_SIZE - n, "ASYM OLD: - -\n"); 189 + n += sysfs_emit_at(buf, n, "ASYM OLD: - -\n"); 199 190 200 191 return n; 201 192 } ··· 219 228 ep11_get_card_info(ac->id, &ci, zc->online); 220 229 221 230 if (ci.API_ord_nr > 0) 222 - return scnprintf(buf, PAGE_SIZE, "%u\n", ci.API_ord_nr); 231 + return sysfs_emit(buf, "%u\n", ci.API_ord_nr); 223 232 else 224 - return scnprintf(buf, PAGE_SIZE, "\n"); 233 + return sysfs_emit(buf, "\n"); 225 234 } 226 235 227 236 static struct device_attribute dev_attr_ep11_api_ordinalnr = ··· 240 249 ep11_get_card_info(ac->id, &ci, zc->online); 241 250 242 251 if (ci.FW_version > 0) 243 - return scnprintf(buf, PAGE_SIZE, "%d.%d\n", 244 - (int)(ci.FW_version >> 8), 245 - (int)(ci.FW_version & 0xFF)); 252 + return sysfs_emit(buf, "%d.%d\n", 253 + (int)(ci.FW_version >> 8), 254 + (int)(ci.FW_version & 0xFF)); 246 255 else 247 - return scnprintf(buf, PAGE_SIZE, "\n"); 256 + return sysfs_emit(buf, "\n"); 248 257 } 249 258 250 259 static struct device_attribute dev_attr_ep11_fw_version = ··· 263 272 ep11_get_card_info(ac->id, &ci, zc->online); 264 273 265 274 if (ci.serial[0]) 266 - return scnprintf(buf, PAGE_SIZE, "%16.16s\n", ci.serial); 275 + return sysfs_emit(buf, "%16.16s\n", ci.serial); 267 276 else 268 - return scnprintf(buf, PAGE_SIZE, "\n"); 277 + return sysfs_emit(buf, "\n"); 269 278 } 270 279 271 280 static struct device_attribute dev_attr_ep11_serialnr = ··· 300 309 if (ci.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) { 301 310 if (n > 0) 302 311 buf[n++] = ' '; 303 - n += scnprintf(buf + n, PAGE_SIZE - n, 304 - "%s", ep11_op_modes[i].mode_txt); 312 + n += sysfs_emit_at(buf, n, "%s", 313 + ep11_op_modes[i].mode_txt); 305 314 } 306 315 } 307 - n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); 316 + n += sysfs_emit_at(buf, n, "\n"); 308 317 309 318 return n; 310 319 } ··· 347 356 &di); 348 357 349 358 if (di.cur_wk_state == '0') { 350 - n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s -\n", 351 - cwk_state[di.cur_wk_state - '0']); 359 + n = sysfs_emit(buf, "WK CUR: %s -\n", 360 + cwk_state[di.cur_wk_state - '0']); 352 361 } else if (di.cur_wk_state == '1') { 353 - n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s 0x", 354 - cwk_state[di.cur_wk_state - '0']); 362 + n = sysfs_emit(buf, "WK CUR: %s 0x", 363 + cwk_state[di.cur_wk_state - '0']); 355 364 bin2hex(buf + n, di.cur_wkvp, sizeof(di.cur_wkvp)); 356 365 n += 2 * sizeof(di.cur_wkvp); 357 - n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); 366 + n += sysfs_emit_at(buf, n, "\n"); 358 367 } else { 359 - n = scnprintf(buf, PAGE_SIZE, "WK CUR: - -\n"); 368 + n = sysfs_emit(buf, "WK CUR: - -\n"); 360 369 } 361 370 362 371 if (di.new_wk_state == '0') { 363 - n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s -\n", 364 - nwk_state[di.new_wk_state - '0']); 372 + n += sysfs_emit_at(buf, n, "WK NEW: %s -\n", 373 + nwk_state[di.new_wk_state - '0']); 365 374 } else if (di.new_wk_state >= '1' && di.new_wk_state <= '2') { 366 - n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s 0x", 367 - nwk_state[di.new_wk_state - '0']); 375 + n += sysfs_emit_at(buf, n, "WK NEW: %s 0x", 376 + nwk_state[di.new_wk_state - '0']); 368 377 bin2hex(buf + n, di.new_wkvp, sizeof(di.new_wkvp)); 369 378 n += 2 * sizeof(di.new_wkvp); 370 - n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); 379 + n += sysfs_emit_at(buf, n, "\n"); 371 380 } else { 372 - n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: - -\n"); 381 + n += sysfs_emit_at(buf, n, "WK NEW: - -\n"); 373 382 } 374 383 375 384 return n; ··· 397 406 if (di.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) { 398 407 if (n > 0) 399 408 buf[n++] = ' '; 400 - n += scnprintf(buf + n, PAGE_SIZE - n, 401 - "%s", ep11_op_modes[i].mode_txt); 409 + n += sysfs_emit_at(buf, n, "%s", 410 + ep11_op_modes[i].mode_txt); 402 411 } 403 412 } 404 - n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); 413 + n += sysfs_emit_at(buf, n, "\n"); 405 414 406 415 return n; 407 416 }
+1 -1
drivers/s390/crypto/zcrypt_ep11misc.c
··· 1275 1275 u32 pkeybitsize; 1276 1276 u64 pkeysize; 1277 1277 u8 res2[8]; 1278 - u8 pkey[0]; 1278 + u8 pkey[]; 1279 1279 } __packed * wki; 1280 1280 const u8 *key; 1281 1281 struct ep11kblob_header *hdr;
+9 -6
drivers/s390/crypto/zcrypt_msgtype50.c
··· 441 441 t80h = reply->msg; 442 442 if (t80h->type == TYPE80_RSP_CODE) { 443 443 len = t80h->len; 444 - if (len > reply->bufsize || len > msg->bufsize) { 444 + if (len > reply->bufsize || len > msg->bufsize || 445 + len != reply->len) { 446 + ZCRYPT_DBF_DBG("%s len mismatch => EMSGSIZE\n", __func__); 445 447 msg->rc = -EMSGSIZE; 446 - } else { 447 - memcpy(msg->msg, reply->msg, len); 448 - msg->len = len; 448 + goto out; 449 449 } 450 + memcpy(msg->msg, reply->msg, len); 451 + msg->len = len; 450 452 } else { 451 453 memcpy(msg->msg, reply->msg, sizeof(error_reply)); 454 + msg->len = sizeof(error_reply); 452 455 } 453 456 out: 454 457 complete((struct completion *)msg->private); ··· 479 476 if (!ap_msg->msg) 480 477 return -ENOMEM; 481 478 ap_msg->receive = zcrypt_cex2a_receive; 482 - ap_msg->psmid = (((unsigned long long)current->pid) << 32) + 479 + ap_msg->psmid = (((unsigned long)current->pid) << 32) + 483 480 atomic_inc_return(&zcrypt_step); 484 481 ap_msg->private = &work; 485 482 rc = ICAMEX_msg_to_type50MEX_msg(zq, ap_msg, mex); ··· 530 527 if (!ap_msg->msg) 531 528 return -ENOMEM; 532 529 ap_msg->receive = zcrypt_cex2a_receive; 533 - ap_msg->psmid = (((unsigned long long)current->pid) << 32) + 530 + ap_msg->psmid = (((unsigned long)current->pid) << 32) + 534 531 atomic_inc_return(&zcrypt_step); 535 532 ap_msg->private = &work; 536 533 rc = ICACRT_msg_to_type50CRT_msg(zq, ap_msg, crt);
+47 -92
drivers/s390/crypto/zcrypt_msgtype6.c
··· 208 208 struct CPRBX cprbx; 209 209 struct function_and_rules_block fr; 210 210 unsigned short length; 211 - char text[0]; 211 + char text[]; 212 212 } __packed * msg = ap_msg->msg; 213 213 int size; 214 214 ··· 278 278 struct CPRBX cprbx; 279 279 struct function_and_rules_block fr; 280 280 unsigned short length; 281 - char text[0]; 281 + char text[]; 282 282 } __packed * msg = ap_msg->msg; 283 283 int size; 284 284 ··· 566 566 struct type86_fmt2_ext fmt2; 567 567 struct CPRBX cprbx; 568 568 unsigned char pad[4]; /* 4 byte function code/rules block ? */ 569 - unsigned short length; 570 - char text[]; 569 + unsigned short length; /* length of data including length field size */ 570 + char data[]; 571 571 } __packed; 572 572 573 573 struct type86_ep11_reply { ··· 581 581 char __user *outputdata, 582 582 unsigned int outputdatalength) 583 583 { 584 - static unsigned char static_pad[] = { 585 - 0x00, 0x02, 586 - 0x1B, 0x7B, 0x5D, 0xB5, 0x75, 0x01, 0x3D, 0xFD, 587 - 0x8D, 0xD1, 0xC7, 0x03, 0x2D, 0x09, 0x23, 0x57, 588 - 0x89, 0x49, 0xB9, 0x3F, 0xBB, 0x99, 0x41, 0x5B, 589 - 0x75, 0x21, 0x7B, 0x9D, 0x3B, 0x6B, 0x51, 0x39, 590 - 0xBB, 0x0D, 0x35, 0xB9, 0x89, 0x0F, 0x93, 0xA5, 591 - 0x0B, 0x47, 0xF1, 0xD3, 0xBB, 0xCB, 0xF1, 0x9D, 592 - 0x23, 0x73, 0x71, 0xFF, 0xF3, 0xF5, 0x45, 0xFB, 593 - 0x61, 0x29, 0x23, 0xFD, 0xF1, 0x29, 0x3F, 0x7F, 594 - 0x17, 0xB7, 0x1B, 0xA9, 0x19, 0xBD, 0x57, 0xA9, 595 - 0xD7, 0x95, 0xA3, 0xCB, 0xED, 0x1D, 0xDB, 0x45, 596 - 0x7D, 0x11, 0xD1, 0x51, 0x1B, 0xED, 0x71, 0xE9, 597 - 0xB1, 0xD1, 0xAB, 0xAB, 0x21, 0x2B, 0x1B, 0x9F, 598 - 0x3B, 0x9F, 0xF7, 0xF7, 0xBD, 0x63, 0xEB, 0xAD, 599 - 0xDF, 0xB3, 0x6F, 0x5B, 0xDB, 0x8D, 0xA9, 0x5D, 600 - 0xE3, 0x7D, 0x77, 0x49, 0x47, 0xF5, 0xA7, 0xFD, 601 - 0xAB, 0x2F, 0x27, 0x35, 0x77, 0xD3, 0x49, 0xC9, 602 - 0x09, 0xEB, 0xB1, 0xF9, 0xBF, 0x4B, 0xCB, 0x2B, 603 - 0xEB, 0xEB, 0x05, 0xFF, 0x7D, 0xC7, 0x91, 0x8B, 604 - 0x09, 0x83, 0xB9, 0xB9, 0x69, 0x33, 0x39, 0x6B, 605 - 0x79, 0x75, 0x19, 0xBF, 0xBB, 0x07, 0x1D, 0xBD, 606 - 0x29, 0xBF, 0x39, 0x95, 0x93, 0x1D, 0x35, 0xC7, 607 - 0xC9, 0x4D, 0xE5, 0x97, 0x0B, 0x43, 0x9B, 0xF1, 608 - 0x16, 0x93, 0x03, 0x1F, 0xA5, 0xFB, 0xDB, 0xF3, 609 - 0x27, 0x4F, 0x27, 0x61, 0x05, 0x1F, 0xB9, 0x23, 610 - 0x2F, 0xC3, 0x81, 0xA9, 0x23, 0x71, 0x55, 0x55, 611 - 0xEB, 0xED, 0x41, 0xE5, 0xF3, 0x11, 0xF1, 0x43, 612 - 0x69, 0x03, 0xBD, 0x0B, 0x37, 0x0F, 0x51, 0x8F, 613 - 0x0B, 0xB5, 0x89, 0x5B, 0x67, 0xA9, 0xD9, 0x4F, 614 - 0x01, 0xF9, 0x21, 0x77, 0x37, 0x73, 0x79, 0xC5, 615 - 0x7F, 0x51, 0xC1, 0xCF, 0x97, 0xA1, 0x75, 0xAD, 616 - 0x35, 0x9D, 0xD3, 0xD3, 0xA7, 0x9D, 0x5D, 0x41, 617 - 0x6F, 0x65, 0x1B, 0xCF, 0xA9, 0x87, 0x91, 0x09 618 - }; 619 584 struct type86x_reply *msg = reply->msg; 620 585 unsigned short service_rc, service_rs; 621 - unsigned int reply_len, pad_len; 622 - char *data; 586 + unsigned int data_len; 623 587 624 588 service_rc = msg->cprbx.ccp_rtcode; 625 589 if (unlikely(service_rc != 0)) { ··· 611 647 ap_send_online_uevent(&zq->queue->ap_dev, zq->online); 612 648 return -EAGAIN; 613 649 } 614 - data = msg->text; 615 - reply_len = msg->length - 2; 616 - if (reply_len > outputdatalength) 617 - return -EINVAL; 618 - /* 619 - * For all encipher requests, the length of the ciphertext (reply_len) 620 - * will always equal the modulus length. For MEX decipher requests 621 - * the output needs to get padded. Minimum pad size is 10. 622 - * 623 - * Currently, the cases where padding will be added is for: 624 - * - PCIXCC_MCL2 using a CRT form token (since PKD didn't support 625 - * ZERO-PAD and CRT is only supported for PKD requests) 626 - * - PCICC, always 627 - */ 628 - pad_len = outputdatalength - reply_len; 629 - if (pad_len > 0) { 630 - if (pad_len < 10) 631 - return -EINVAL; 632 - /* 'restore' padding left in the CEXXC card. */ 633 - if (copy_to_user(outputdata, static_pad, pad_len - 1)) 634 - return -EFAULT; 635 - if (put_user(0, outputdata + pad_len - 1)) 636 - return -EFAULT; 637 - } 650 + data_len = msg->length - sizeof(msg->length); 651 + if (data_len > outputdatalength) 652 + return -EMSGSIZE; 653 + 638 654 /* Copy the crypto response to user space. */ 639 - if (copy_to_user(outputdata + pad_len, data, reply_len)) 655 + if (copy_to_user(outputdata, msg->data, data_len)) 640 656 return -EFAULT; 641 657 return 0; 642 658 } ··· 870 926 .type = TYPE82_RSP_CODE, 871 927 .reply_code = REP82_ERROR_MACHINE_FAILURE, 872 928 }; 873 - struct response_type *resp_type = 874 - (struct response_type *)msg->private; 929 + struct response_type *resp_type = msg->private; 875 930 struct type86x_reply *t86r; 876 931 int len; 877 932 ··· 882 939 t86r->cprbx.cprb_ver_id == 0x02) { 883 940 switch (resp_type->type) { 884 941 case CEXXC_RESPONSE_TYPE_ICA: 885 - len = sizeof(struct type86x_reply) + t86r->length - 2; 886 - if (len > reply->bufsize || len > msg->bufsize) { 942 + len = sizeof(struct type86x_reply) + t86r->length; 943 + if (len > reply->bufsize || len > msg->bufsize || 944 + len != reply->len) { 945 + ZCRYPT_DBF_DBG("%s len mismatch => EMSGSIZE\n", __func__); 887 946 msg->rc = -EMSGSIZE; 888 - } else { 889 - memcpy(msg->msg, reply->msg, len); 890 - msg->len = len; 947 + goto out; 891 948 } 949 + memcpy(msg->msg, reply->msg, len); 950 + msg->len = len; 892 951 break; 893 952 case CEXXC_RESPONSE_TYPE_XCRB: 894 - len = t86r->fmt2.offset2 + t86r->fmt2.count2; 895 - if (len > reply->bufsize || len > msg->bufsize) { 953 + if (t86r->fmt2.count2) 954 + len = t86r->fmt2.offset2 + t86r->fmt2.count2; 955 + else 956 + len = t86r->fmt2.offset1 + t86r->fmt2.count1; 957 + if (len > reply->bufsize || len > msg->bufsize || 958 + len != reply->len) { 959 + ZCRYPT_DBF_DBG("%s len mismatch => EMSGSIZE\n", __func__); 896 960 msg->rc = -EMSGSIZE; 897 - } else { 898 - memcpy(msg->msg, reply->msg, len); 899 - msg->len = len; 961 + goto out; 900 962 } 963 + memcpy(msg->msg, reply->msg, len); 964 + msg->len = len; 901 965 break; 902 966 default: 903 967 memcpy(msg->msg, &error_reply, sizeof(error_reply)); 968 + msg->len = sizeof(error_reply); 904 969 } 905 970 } else { 906 971 memcpy(msg->msg, reply->msg, sizeof(error_reply)); 972 + msg->len = sizeof(error_reply); 907 973 } 908 974 out: 909 975 complete(&resp_type->work); ··· 934 982 .type = TYPE82_RSP_CODE, 935 983 .reply_code = REP82_ERROR_MACHINE_FAILURE, 936 984 }; 937 - struct response_type *resp_type = 938 - (struct response_type *)msg->private; 985 + struct response_type *resp_type = msg->private; 939 986 struct type86_ep11_reply *t86r; 940 987 int len; 941 988 ··· 947 996 switch (resp_type->type) { 948 997 case CEXXC_RESPONSE_TYPE_EP11: 949 998 len = t86r->fmt2.offset1 + t86r->fmt2.count1; 950 - if (len > reply->bufsize || len > msg->bufsize) { 999 + if (len > reply->bufsize || len > msg->bufsize || 1000 + len != reply->len) { 1001 + ZCRYPT_DBF_DBG("%s len mismatch => EMSGSIZE\n", __func__); 951 1002 msg->rc = -EMSGSIZE; 952 - } else { 953 - memcpy(msg->msg, reply->msg, len); 954 - msg->len = len; 1003 + goto out; 955 1004 } 1005 + memcpy(msg->msg, reply->msg, len); 1006 + msg->len = len; 956 1007 break; 957 1008 default: 958 1009 memcpy(msg->msg, &error_reply, sizeof(error_reply)); 1010 + msg->len = sizeof(error_reply); 959 1011 } 960 1012 } else { 961 1013 memcpy(msg->msg, reply->msg, sizeof(error_reply)); 1014 + msg->len = sizeof(error_reply); 962 1015 } 963 1016 out: 964 1017 complete(&resp_type->work); ··· 991 1036 return -ENOMEM; 992 1037 ap_msg->bufsize = PAGE_SIZE; 993 1038 ap_msg->receive = zcrypt_msgtype6_receive; 994 - ap_msg->psmid = (((unsigned long long)current->pid) << 32) + 1039 + ap_msg->psmid = (((unsigned long)current->pid) << 32) + 995 1040 atomic_inc_return(&zcrypt_step); 996 1041 ap_msg->private = &resp_type; 997 1042 rc = icamex_msg_to_type6mex_msgx(zq, ap_msg, mex); ··· 1041 1086 return -ENOMEM; 1042 1087 ap_msg->bufsize = PAGE_SIZE; 1043 1088 ap_msg->receive = zcrypt_msgtype6_receive; 1044 - ap_msg->psmid = (((unsigned long long)current->pid) << 32) + 1089 + ap_msg->psmid = (((unsigned long)current->pid) << 32) + 1045 1090 atomic_inc_return(&zcrypt_step); 1046 1091 ap_msg->private = &resp_type; 1047 1092 rc = icacrt_msg_to_type6crt_msgx(zq, ap_msg, crt); ··· 1092 1137 if (!ap_msg->msg) 1093 1138 return -ENOMEM; 1094 1139 ap_msg->receive = zcrypt_msgtype6_receive; 1095 - ap_msg->psmid = (((unsigned long long)current->pid) << 32) + 1140 + ap_msg->psmid = (((unsigned long)current->pid) << 32) + 1096 1141 atomic_inc_return(&zcrypt_step); 1097 1142 ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL); 1098 1143 if (!ap_msg->private) ··· 1112 1157 struct ap_message *ap_msg) 1113 1158 { 1114 1159 int rc; 1115 - struct response_type *rtype = (struct response_type *)(ap_msg->private); 1160 + struct response_type *rtype = ap_msg->private; 1116 1161 struct { 1117 1162 struct type6_hdr hdr; 1118 1163 struct CPRBX cprbx; ··· 1173 1218 if (!ap_msg->msg) 1174 1219 return -ENOMEM; 1175 1220 ap_msg->receive = zcrypt_msgtype6_receive_ep11; 1176 - ap_msg->psmid = (((unsigned long long)current->pid) << 32) + 1221 + ap_msg->psmid = (((unsigned long)current->pid) << 32) + 1177 1222 atomic_inc_return(&zcrypt_step); 1178 1223 ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL); 1179 1224 if (!ap_msg->private) ··· 1195 1240 { 1196 1241 int rc; 1197 1242 unsigned int lfmt; 1198 - struct response_type *rtype = (struct response_type *)(ap_msg->private); 1243 + struct response_type *rtype = ap_msg->private; 1199 1244 struct { 1200 1245 struct type6_hdr hdr; 1201 1246 struct ep11_cprb cprbx; ··· 1283 1328 if (!ap_msg->msg) 1284 1329 return -ENOMEM; 1285 1330 ap_msg->receive = zcrypt_msgtype6_receive; 1286 - ap_msg->psmid = (((unsigned long long)current->pid) << 32) + 1331 + ap_msg->psmid = (((unsigned long)current->pid) << 32) + 1287 1332 atomic_inc_return(&zcrypt_step); 1288 1333 ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL); 1289 1334 if (!ap_msg->private) ··· 1314 1359 short int verb_length; 1315 1360 short int key_length; 1316 1361 } __packed * msg = ap_msg->msg; 1317 - struct response_type *rtype = (struct response_type *)(ap_msg->private); 1362 + struct response_type *rtype = ap_msg->private; 1318 1363 int rc; 1319 1364 1320 1365 msg->cprbx.domain = AP_QID_QUEUE(zq->queue->qid);
+2 -2
drivers/s390/crypto/zcrypt_queue.c
··· 44 44 struct ap_queue *aq = to_ap_queue(dev); 45 45 int online = aq->config && zq->online ? 1 : 0; 46 46 47 - return scnprintf(buf, PAGE_SIZE, "%d\n", online); 47 + return sysfs_emit(buf, "%d\n", online); 48 48 } 49 49 50 50 static ssize_t online_store(struct device *dev, ··· 84 84 { 85 85 struct zcrypt_queue *zq = dev_get_drvdata(dev); 86 86 87 - return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load)); 87 + return sysfs_emit(buf, "%d\n", atomic_read(&zq->load)); 88 88 } 89 89 90 90 static DEVICE_ATTR_RO(load);
+13 -4
kernel/stackleak.c
··· 70 70 #define skip_erasing() false 71 71 #endif /* CONFIG_STACKLEAK_RUNTIME_DISABLE */ 72 72 73 + #ifndef __stackleak_poison 74 + static __always_inline void __stackleak_poison(unsigned long erase_low, 75 + unsigned long erase_high, 76 + unsigned long poison) 77 + { 78 + while (erase_low < erase_high) { 79 + *(unsigned long *)erase_low = poison; 80 + erase_low += sizeof(unsigned long); 81 + } 82 + } 83 + #endif 84 + 73 85 static __always_inline void __stackleak_erase(bool on_task_stack) 74 86 { 75 87 const unsigned long task_stack_low = stackleak_task_low_bound(current); ··· 113 101 else 114 102 erase_high = task_stack_high; 115 103 116 - while (erase_low < erase_high) { 117 - *(unsigned long *)erase_low = STACKLEAK_POISON; 118 - erase_low += sizeof(unsigned long); 119 - } 104 + __stackleak_poison(erase_low, erase_high, STACKLEAK_POISON); 120 105 121 106 /* Reset the 'lowest_stack' value for the next syscall */ 122 107 current->lowest_stack = task_stack_high;
+1 -1
lib/Kconfig.debug
··· 502 502 503 503 config DEBUG_FORCE_FUNCTION_ALIGN_64B 504 504 bool "Force all function address 64B aligned" 505 - depends on EXPERT && (X86_64 || ARM64 || PPC32 || PPC64 || ARC) 505 + depends on EXPERT && (X86_64 || ARM64 || PPC32 || PPC64 || ARC || S390) 506 506 select FUNCTION_ALIGNMENT_64B 507 507 help 508 508 There are cases that a commit from one domain changes the function