History

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. ...

Linus Torvalds committed 3 years ago

Commit 10de6382 parents d55571c 2a405f699 files · +2784 −2436Browse files

Unified · Split

99 files
  1. Documentation/features/sched/membarrier-sync-core/arch-support.txt +2 −2
  2. arch/s390/Kconfig +6 −4
  3. arch/s390/appldata/appldata_base.c +9 −23
  4. arch/s390/boot/Makefile +1 −1
  5. arch/s390/boot/boot.h +35 −7
  6. arch/s390/boot/install.sh +4 −4
  7. arch/s390/boot/ipl_parm.c +3 −3
  8. arch/s390/boot/ipl_report.c +49 −57
  9. arch/s390/boot/kaslr.c +83 −88
  10. arch/s390/boot/mem_detect.c +0 −191
  11. arch/s390/boot/pgm_check_info.c +3 −4
  12. arch/s390/boot/physmem_info.c +328 −0
  13. arch/s390/boot/startup.c +73 −56
  14. arch/s390/boot/vmem.c +223 −61
  15. arch/s390/boot/vmlinux.lds.S +2 −0
  16. arch/s390/crypto/chacha-s390.S +24 −23
  17. arch/s390/crypto/crc32be-vx.S +9 −8
  18. arch/s390/crypto/crc32le-vx.S +16 −14
  19. arch/s390/include/asm/ap.h +128 −24
  20. arch/s390/include/asm/checksum.h +2 −8
  21. arch/s390/include/asm/diag.h +1 −1
  22. arch/s390/include/asm/entry-common.h +0 −5
  23. arch/s390/include/asm/fcx.h +1 −1
  24. arch/s390/include/asm/kasan.h +1 −30
  25. arch/s390/include/asm/linkage.h +1 −1
  26. arch/s390/include/asm/mem_detect.h +0 −117
  27. arch/s390/include/asm/nospec-insn.h +2 −1
  28. arch/s390/include/asm/perf_event.h +0 −2
  29. arch/s390/include/asm/pgtable.h +1 −1
  30. arch/s390/include/asm/physmem_info.h +171 −0
  31. arch/s390/include/asm/processor.h +42 −4
  32. arch/s390/include/asm/set_memory.h +31 −5
  33. arch/s390/include/asm/setup.h +8 −12
  34. arch/s390/include/asm/stacktrace.h +44 −8
  35. arch/s390/include/asm/string.h +3 −12
  36. arch/s390/include/asm/thread_info.h +5 −5
  37. arch/s390/kernel/debug.c +2 −12
  38. arch/s390/kernel/dumpstack.c +21 −25
  39. arch/s390/kernel/early.c +9 −14
  40. arch/s390/kernel/earlypgm.S +2 −2
  41. arch/s390/kernel/entry.S +70 −82
  42. arch/s390/kernel/ftrace.c +1 −21
  43. arch/s390/kernel/head64.S +6 −8
  44. arch/s390/kernel/ipl.c +3 −4
  45. arch/s390/kernel/kprobes.c +1 −1
  46. arch/s390/kernel/kprobes_insn_page.S +2 −2
  47. arch/s390/kernel/machine_kexec.c +22 −34
  48. arch/s390/kernel/mcount.S +20 −6
  49. arch/s390/kernel/module.c +25 −4
  50. arch/s390/kernel/perf_cpum_cf.c +91 −115
  51. arch/s390/kernel/perf_cpum_sf.c +2 −12
  52. arch/s390/kernel/process.c +4 −6
  53. arch/s390/kernel/processor.c +0 −18
  54. arch/s390/kernel/reipl.S +5 −5
  55. arch/s390/kernel/relocate_kernel.S +47 −49
  56. arch/s390/kernel/setup.c +48 −104
  57. arch/s390/kernel/smp.c +4 −7
  58. arch/s390/kernel/syscalls/syscall.tbl +1 −1
  59. arch/s390/kernel/text_amode31.S +31 −44
  60. arch/s390/kernel/topology.c +1 −11
  61. arch/s390/kernel/vdso32/vdso_user_wrapper.S +2 −1
  62. arch/s390/kernel/vdso64/vdso_user_wrapper.S +3 −2
  63. arch/s390/kernel/vmlinux.lds.S +9 −1
  64. arch/s390/lib/mem.S +17 −11
  65. arch/s390/lib/uaccess.c +71 −66
  66. arch/s390/mm/Makefile +0 −3
  67. arch/s390/mm/cmm.c +1 −11
  68. arch/s390/mm/init.c +2 −3
  69. arch/s390/mm/kasan_init.c +0 −301
  70. arch/s390/mm/pageattr.c +86 −8
  71. arch/s390/mm/pgalloc.c +2 −18
  72. arch/s390/mm/vmem.c +20 −15
  73. arch/s390/pci/pci.c +3 −20
  74. arch/s390/pci/pci_bus.c +3 −8
  75. arch/s390/purgatory/head.S +19 −43
  76. arch/s390/purgatory/kexec-purgatory.S +6 −8
  77. drivers/s390/char/sclp.h +1 −1
  78. drivers/s390/char/sclp_cmd.c +1 −1
  79. drivers/s390/char/sclp_early_core.c +4 −4
  80. drivers/s390/cio/chsc.c +1 −1
  81. drivers/s390/cio/chsc.h +1 −1
  82. drivers/s390/crypto/ap_bus.c +151 −103
  83. drivers/s390/crypto/ap_bus.h +44 −26
  84. drivers/s390/crypto/ap_card.c +11 −12
  85. drivers/s390/crypto/ap_queue.c +348 −62
  86. drivers/s390/crypto/vfio_ap_drv.c +0 −6
  87. drivers/s390/crypto/vfio_ap_ops.c +7 −9
  88. drivers/s390/crypto/zcrypt_api.c +20 −40
  89. drivers/s390/crypto/zcrypt_card.c +3 −3
  90. drivers/s390/crypto/zcrypt_cca_key.h +13 −24
  91. drivers/s390/crypto/zcrypt_ccamisc.c +36 −38
  92. drivers/s390/crypto/zcrypt_cex2c.c +31 −35
  93. drivers/s390/crypto/zcrypt_cex4.c +66 −75
  94. drivers/s390/crypto/zcrypt_ep11misc.c +1 −1
  95. drivers/s390/crypto/zcrypt_msgtype50.c +9 −6
  96. drivers/s390/crypto/zcrypt_msgtype6.c +47 −92
  97. drivers/s390/crypto/zcrypt_queue.c +2 −2
  98. kernel/stackleak.c +13 −4
  99. lib/Kconfig.debug +1 −1
Documentation/features/sched/membarrier-sync-core/arch-support.txt+2−2
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 #
66 # Architecture requirements
77 #
8−# * arm/arm64/powerpc
8+# * arm/arm64/powerpc/s390
99 #
1010 # Rely on implicit context synchronization as a result of exception return
1111 # when returning from IPI handler, and when returning to user-space.
@@ -45,7 +45,7 @@ · 33 unmodified lines
4545 | parisc: | TODO |
4646 | powerpc: | ok |
4747 | riscv: | TODO |
48− | s390: | TODO |
48+ | s390: | ok |
4949 | sh: | TODO |
5050 | sparc: | TODO |
5151 | um: | TODO |
arch/s390/Kconfig+6−4
@@ -26,10 +26,6 @@ config GENERIC_BUG · 25 unmodified lines
2626 config GENERIC_BUG_RELATIVE_POINTERS
2727 def_bool y
2828
29−config GENERIC_CSUM
30− bool
31− default y if KASAN
32−
3329 config GENERIC_LOCKBREAK
3430 def_bool y if PREEMPTION
3531
@@ -76,10 +72,12 @@ config S390 · 40 unmodified lines
7672 select ARCH_HAS_GCOV_PROFILE_ALL
7773 select ARCH_HAS_GIGANTIC_PAGE
7874 select ARCH_HAS_KCOV
75+ select ARCH_HAS_MEMBARRIER_SYNC_CORE
7976 select ARCH_HAS_MEM_ENCRYPT
8077 select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS
8178 select ARCH_HAS_PTE_SPECIAL
8279 select ARCH_HAS_SCALED_CPUTIME
80+ select ARCH_HAS_SET_DIRECT_MAP
8381 select ARCH_HAS_SET_MEMORY
8482 select ARCH_HAS_STRICT_KERNEL_RWX
8583 select ARCH_HAS_STRICT_MODULE_RWX
@@ -123,6 +121,7 @@ config S390 · 37 unmodified lines
123121 select ARCH_SUPPORTS_PER_VMA_LOCK
124122 select ARCH_USE_BUILTIN_BSWAP
125123 select ARCH_USE_CMPXCHG_LOCKREF
124+ select ARCH_USE_SYM_ANNOTATIONS
126125 select ARCH_WANTS_DYNAMIC_TASK_STRUCT
127126 select ARCH_WANTS_NO_INSTR
128127 select ARCH_WANT_DEFAULT_BPF_JIT
@@ -132,6 +131,8 @@ config S390 · 3 unmodified lines
132131 select CLONE_BACKWARDS2
133132 select DMA_OPS if PCI
134133 select DYNAMIC_FTRACE if FUNCTION_TRACER
134+ select FUNCTION_ALIGNMENT_8B if CC_IS_GCC
135+ select FUNCTION_ALIGNMENT_16B if !CC_IS_GCC
135136 select GCC12_NO_ARRAY_BOUNDS
136137 select GENERIC_ALLOCATOR
137138 select GENERIC_CPU_AUTOPROBE
@@ -153,6 +154,7 @@ config S390 · 15 unmodified lines
153154 select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
154155 select HAVE_ARCH_SECCOMP_FILTER
155156 select HAVE_ARCH_SOFT_DIRTY
157+ select HAVE_ARCH_STACKLEAK
156158 select HAVE_ARCH_TRACEHOOK
157159 select HAVE_ARCH_TRANSPARENT_HUGEPAGE
158160 select HAVE_ARCH_VMAP_STACK
arch/s390/appldata/appldata_base.c+9−23
@@ -66,16 +66,6 @@ static struct ctl_table appldata_table[] = { · 65 unmodified lines
6666 { },
6767 };
6868
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−
7969 /*
8070 * Timer
8171 */
@@ -291,7 +281,7 @@ appldata_generic_handler(struct ctl_table *ctl, int write, · 209 unmodified lines
291281 mutex_lock(&appldata_ops_mutex);
292282 list_for_each(lh, &appldata_ops_list) {
293283 tmp_ops = list_entry(lh, struct appldata_ops, list);
294− if (&tmp_ops->ctl_table[2] == ctl) {
284+ if (&tmp_ops->ctl_table[0] == ctl) {
295285 found = 1;
296286 }
297287 }
@@ -361,7 +351,8 @@ int appldata_register_ops(struct appldata_ops *ops) · 63 unmodified lines
361351 if (ops->size > APPLDATA_MAX_REC_SIZE)
362352 return -EINVAL;
363353
364− ops->ctl_table = kcalloc(4, sizeof(struct ctl_table), GFP_KERNEL);
354+ /* The last entry must be an empty one */
355+ ops->ctl_table = kcalloc(2, sizeof(struct ctl_table), GFP_KERNEL);
365356 if (!ops->ctl_table)
366357 return -ENOMEM;
367358
@@ -369,17 +360,12 @@ int appldata_register_ops(struct appldata_ops *ops) · 1 unmodified line
369360 list_add(&ops->list, &appldata_ops_list);
370361 mutex_unlock(&appldata_ops_mutex);
371362
372− ops->ctl_table[0].procname = appldata_proc_name;
373− ops->ctl_table[0].maxlen = 0;
374− ops->ctl_table[0].mode = S_IRUGO | S_IXUGO;
375− ops->ctl_table[0].child = &ops->ctl_table[2];
376−
377− ops->ctl_table[2].procname = ops->name;
378− ops->ctl_table[2].mode = S_IRUGO | S_IWUSR;
379− ops->ctl_table[2].proc_handler = appldata_generic_handler;
380− ops->ctl_table[2].data = ops;
363+ ops->ctl_table[0].procname = ops->name;
364+ ops->ctl_table[0].mode = S_IRUGO | S_IWUSR;
365+ ops->ctl_table[0].proc_handler = appldata_generic_handler;
366+ ops->ctl_table[0].data = ops;
381367
382− ops->sysctl_header = register_sysctl_table(ops->ctl_table);
368+ ops->sysctl_header = register_sysctl(appldata_proc_name, ops->ctl_table);
383369 if (!ops->sysctl_header)
384370 goto out;
385371 return 0;
@@ -422,7 +408,7 @@ static int __init appldata_init(void) · 36 unmodified lines
422408 appldata_wq = alloc_ordered_workqueue("appldata", 0);
423409 if (!appldata_wq)
424410 return -ENOMEM;
425− appldata_sysctl_header = register_sysctl_table(appldata_dir_table);
411+ appldata_sysctl_header = register_sysctl(appldata_proc_name, appldata_table);
426412 return 0;
427413 }
428414
arch/s390/boot/Makefile+1−1
@@ -35,7 +35,7 @@ endif · 34 unmodified lines
3535
3636 CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char
3737
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
3939 obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o
4040 obj-y += version.o pgm_check_info.o ctype.o ipl_data.o machine_kexec_reloc.o
4141 obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o
arch/s390/boot/boot.h+35−7
@@ -8,6 +8,8 @@ · 7 unmodified lines
88
99 #ifndef __ASSEMBLY__
1010
11+#include <asm/physmem_info.h>
12+
1113 struct machine_info {
1214 unsigned char has_edat1 : 1;
1315 unsigned char has_edat2 : 1;
@@ -30,24 +32,46 @@ struct vmlinux_info { · 16 unmodified lines
3032 unsigned long init_mm_off;
3133 unsigned long swapper_pg_dir_off;
3234 unsigned long invalid_pg_dir_off;
35+#ifdef CONFIG_KASAN
36+ unsigned long kasan_early_shadow_page_off;
37+ unsigned long kasan_early_shadow_pte_off;
38+ unsigned long kasan_early_shadow_pmd_off;
39+ unsigned long kasan_early_shadow_pud_off;
40+ unsigned long kasan_early_shadow_p4d_off;
41+#endif
3342 };
3443
3544 void startup_kernel(void);
36−unsigned long detect_memory(unsigned long *safe_addr);
37−void mem_detect_set_usable_limit(unsigned long limit);
45+unsigned long detect_max_physmem_end(void);
46+void detect_physmem_online_ranges(unsigned long max_physmem_end);
47+void physmem_set_usable_limit(unsigned long limit);
48+void physmem_reserve(enum reserved_range_type type, unsigned long addr, unsigned long size);
49+void physmem_free(enum reserved_range_type type);
50+/* for continuous/multiple allocations per type */
51+unsigned long physmem_alloc_top_down(enum reserved_range_type type, unsigned long size,
52+ unsigned long align);
53+/* for single allocations, 1 per type */
54+unsigned long physmem_alloc_range(enum reserved_range_type type, unsigned long size,
55+ unsigned long align, unsigned long min, unsigned long max,
56+ bool die_on_oom);
57+unsigned long get_physmem_alloc_pos(void);
58+bool ipl_report_certs_intersects(unsigned long addr, unsigned long size,
59+ unsigned long *intersection_start);
3860 bool is_ipl_block_dump(void);
3961 void store_ipl_parmblock(void);
40−unsigned long read_ipl_report(unsigned long safe_addr);
62+int read_ipl_report(void);
63+void save_ipl_cert_comp_list(void);
4164 void setup_boot_command_line(void);
4265 void parse_boot_command_line(void);
4366 void verify_facilities(void);
4467 void print_missing_facilities(void);
4568 void sclp_early_setup_buffer(void);
4669 void print_pgm_check_info(void);
47−unsigned long get_random_base(unsigned long safe_addr);
70+unsigned long randomize_within_range(unsigned long size, unsigned long align,
71+ unsigned long min, unsigned long max);
4872 void setup_vmem(unsigned long asce_limit);
49−unsigned long vmem_estimate_memory_needs(unsigned long online_mem_total);
5073 void __printf(1, 2) decompressor_printk(const char *fmt, ...);
74+void print_stacktrace(unsigned long sp);
5175 void error(char *m);
5276
5377 extern struct machine_info machine;
@@ -57,12 +81,11 @@ extern const char kernel_version[]; · 3 unmodified lines
5781 extern unsigned long memory_limit;
5882 extern unsigned long vmalloc_size;
5983 extern int vmalloc_size_set;
60−extern int kaslr_enabled;
6184 extern char __boot_data_start[], __boot_data_end[];
6285 extern char __boot_data_preserved_start[], __boot_data_preserved_end[];
6386 extern char _decompressor_syms_start[], _decompressor_syms_end[];
6487 extern char _stack_start[], _stack_end[];
65−extern char _end[];
88+extern char _end[], _decompressor_end[];
6689 extern unsigned char _compressed_start[];
6790 extern unsigned char _compressed_end[];
6891 extern struct vmlinux_info _vmlinux_info;
@@ -70,5 +93,10 @@ extern struct vmlinux_info _vmlinux_info; · 1 unmodified line
7093
7194 #define __abs_lowcore_pa(x) (((unsigned long)(x) - __abs_lowcore) % sizeof(struct lowcore))
7295
96+static inline bool intersects(unsigned long addr0, unsigned long size0,
97+ unsigned long addr1, unsigned long size1)
98+{
99+ return addr0 + size0 > addr1 && addr1 + size1 > addr0;
100+}
73101 #endif /* __ASSEMBLY__ */
74102 #endif /* BOOT_BOOT_H */
arch/s390/boot/install.sh+4−4
@@ -17,8 +17,8 @@ · 16 unmodified lines
1717
1818 echo "Warning: '${INSTALLKERNEL}' command not available - additional " \
1919 "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
2222
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"
arch/s390/boot/ipl_parm.c+3−3
@@ -24,11 +24,11 @@ int __bootdata(noexec_disabled); · 23 unmodified lines
2424 unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL;
2525 struct ipl_parameter_block __bootdata_preserved(ipl_block);
2626 int __bootdata_preserved(ipl_block_valid);
27+int __bootdata_preserved(__kaslr_enabled);
2728
2829 unsigned long vmalloc_size = VMALLOC_DEFAULT_SIZE;
2930 unsigned long memory_limit;
3031 int vmalloc_size_set;
31−int kaslr_enabled;
3232
3333 static inline int __diag308(unsigned long subcode, void *addr)
3434 {
@@ -264,7 +264,7 @@ void parse_boot_command_line(void) · 229 unmodified lines
264264 char *args;
265265 int rc;
266266
267− kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
267+ __kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
268268 args = strcpy(command_line_buf, early_command_line);
269269 while (*args) {
270270 args = next_arg(args, &param, &val);
@@ -300,7 +300,7 @@ void parse_boot_command_line(void) · 29 unmodified lines
300300 modify_fac_list(val);
301301
302302 if (!strcmp(param, "nokaslr"))
303− kaslr_enabled = 0;
303+ __kaslr_enabled = 0;
304304
305305 #if IS_ENABLED(CONFIG_KVM)
306306 if (!strcmp(param, "prot_virt")) {
arch/s390/boot/ipl_report.c+49−57
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 #include <asm/sclp.h>
66 #include <asm/sections.h>
77 #include <asm/boot_data.h>
8+#include <asm/physmem_info.h>
89 #include <uapi/asm/ipl.h>
910 #include "boot.h"
1011
@@ -16,20 +17,16 @@ unsigned long __bootdata_preserved(ipl_cert_list_size); · 5 unmodified lines
1617 unsigned long __bootdata(early_ipl_comp_list_addr);
1718 unsigned long __bootdata(early_ipl_comp_list_size);
1819
20+static struct ipl_rb_certificates *certs;
21+static struct ipl_rb_components *comps;
22+static bool ipl_report_needs_saving;
23+
1924 #define for_each_rb_entry(entry, rb) \
2025 for (entry = rb->entries; \
2126 (void *) entry + sizeof(*entry) <= (void *) rb + rb->len; \
2227 entry++)
2328
24−static inline bool intersects(unsigned long addr0, unsigned long size0,
25− unsigned long addr1, unsigned long size1)
26−{
27− return addr0 + size0 > addr1 && addr1 + size1 > addr0;
28−}
29−
30−static unsigned long find_bootdata_space(struct ipl_rb_components *comps,
31− struct ipl_rb_certificates *certs,
32− unsigned long safe_addr)
29+static unsigned long get_cert_comp_list_size(void)
3330 {
3431 struct ipl_rb_certificate_entry *cert;
3532 struct ipl_rb_component_entry *comp;
@@ -44,44 +41,27 @@ static unsigned long find_bootdata_space(struct ipl_rb_components *comps, · 8 unmodified lines
4441 ipl_cert_list_size = 0;
4542 for_each_rb_entry(cert, certs)
4643 ipl_cert_list_size += sizeof(unsigned int) + cert->len;
47− size = ipl_cert_list_size + early_ipl_comp_list_size;
44+ return ipl_cert_list_size + early_ipl_comp_list_size;
45+}
4846
49− /*
50− * Start from safe_addr to find a free memory area large
51− * enough for the IPL report boot data. This area is used
52− * for ipl_cert_list_addr/ipl_cert_list_size and
53− * early_ipl_comp_list_addr/early_ipl_comp_list_size. It must
54− * not overlap with any component or any certificate.
55− */
56−repeat:
57− if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd_data.start && initrd_data.size &&
58− intersects(initrd_data.start, initrd_data.size, safe_addr, size))
59− safe_addr = initrd_data.start + initrd_data.size;
60− if (intersects(safe_addr, size, (unsigned long)comps, comps->len)) {
61− safe_addr = (unsigned long)comps + comps->len;
62− goto repeat;
63− }
64− for_each_rb_entry(comp, comps)
65− if (intersects(safe_addr, size, comp->addr, comp->len)) {
66− safe_addr = comp->addr + comp->len;
67− goto repeat;
47+bool ipl_report_certs_intersects(unsigned long addr, unsigned long size,
48+ unsigned long *intersection_start)
49+{
50+ struct ipl_rb_certificate_entry *cert;
51+
52+ if (!ipl_report_needs_saving)
53+ return false;
54+
55+ for_each_rb_entry(cert, certs) {
56+ if (intersects(addr, size, cert->addr, cert->len)) {
57+ *intersection_start = cert->addr;
58+ return true;
6859 }
69− if (intersects(safe_addr, size, (unsigned long)certs, certs->len)) {
70− safe_addr = (unsigned long)certs + certs->len;
71− goto repeat;
7260 }
73− for_each_rb_entry(cert, certs)
74− if (intersects(safe_addr, size, cert->addr, cert->len)) {
75− safe_addr = cert->addr + cert->len;
76− goto repeat;
77− }
78− early_ipl_comp_list_addr = safe_addr;
79− ipl_cert_list_addr = safe_addr + early_ipl_comp_list_size;
80−
81− return safe_addr + size;
61+ return false;
8262 }
8363
84−static void copy_components_bootdata(struct ipl_rb_components *comps)
64+static void copy_components_bootdata(void)
8565 {
8666 struct ipl_rb_component_entry *comp, *ptr;
8767
@@ -90,7 +70,7 @@ static void copy_components_bootdata(struct ipl_rb_components *comps) · 2 unmodified lines
9070 memcpy(ptr++, comp, sizeof(*ptr));
9171 }
9272
93−static void copy_certificates_bootdata(struct ipl_rb_certificates *certs)
73+static void copy_certificates_bootdata(void)
9474 {
9575 struct ipl_rb_certificate_entry *cert;
9676 void *ptr;
@@ -104,10 +84,8 @@ static void copy_certificates_bootdata(struct ipl_rb_certificates *certs) · 7 unmodified lines
10484 }
10585 }
10686
107−unsigned long read_ipl_report(unsigned long safe_addr)
87+int read_ipl_report(void)
10888 {
109− struct ipl_rb_certificates *certs;
110− struct ipl_rb_components *comps;
11189 struct ipl_pl_hdr *pl_hdr;
11290 struct ipl_rl_hdr *rl_hdr;
11391 struct ipl_rb_hdr *rb_hdr;
@@ -120,7 +98,7 @@ unsigned long read_ipl_report(unsigned long safe_addr) · 6 unmodified lines
12098 */
12199 if (!ipl_block_valid ||
122100 !(ipl_block.hdr.flags & IPL_PL_FLAG_IPLSR))
123− return safe_addr;
101+ return -1;
124102 ipl_secure_flag = !!(ipl_block.hdr.flags & IPL_PL_FLAG_SIPL);
125103 /*
126104 * There is an IPL report, to find it load the pointer to the
@@ -158,16 +136,30 @@ unsigned long read_ipl_report(unsigned long safe_addr) · 31 unmodified lines
158136 * With either the component list or the certificate list
159137 * missing the kernel will stay ignorant of secure IPL.
160138 */
161− if (!comps || !certs)
162− return safe_addr;
139+ if (!comps || !certs) {
140+ certs = NULL;
141+ return -1;
142+ }
163143
164− /*
165− * Copy component and certificate list to a safe area
166− * where the decompressed kernel can find them.
167− */
168− safe_addr = find_bootdata_space(comps, certs, safe_addr);
169− copy_components_bootdata(comps);
170− copy_certificates_bootdata(certs);
144+ ipl_report_needs_saving = true;
145+ physmem_reserve(RR_IPLREPORT, (unsigned long)pl_hdr,
146+ (unsigned long)rl_end - (unsigned long)pl_hdr);
147+ return 0;
148+}
149+
150+void save_ipl_cert_comp_list(void)
151+{
152+ unsigned long size;
153+
154+ if (!ipl_report_needs_saving)
155+ return;
156+
157+ size = get_cert_comp_list_size();
158+ early_ipl_comp_list_addr = physmem_alloc_top_down(RR_CERT_COMP_LIST, size, sizeof(int));
159+ ipl_cert_list_addr = early_ipl_comp_list_addr + early_ipl_comp_list_size;
171160
172− return safe_addr;
161+ copy_components_bootdata();
162+ copy_certificates_bootdata();
163+ physmem_free(RR_IPLREPORT);
164+ ipl_report_needs_saving = false;
173165 }
arch/s390/boot/kaslr.c+83−88
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 * Copyright IBM Corp. 2019
44 */
55 #include <linux/pgtable.h>
6−#include <asm/mem_detect.h>
6+#include <asm/physmem_info.h>
77 #include <asm/cpacf.h>
88 #include <asm/timex.h>
99 #include <asm/sclp.h>
@@ -91,113 +91,108 @@ static int get_random(unsigned long limit, unsigned long *value) · 81 unmodified lines
9191 return 0;
9292 }
9393
94−/*
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).
114− *
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.
127− */
128−static unsigned long count_valid_kernel_positions(unsigned long kernel_size,
129− unsigned long _min,
130− unsigned long _max)
94+static void sort_reserved_ranges(struct reserved_range *res, unsigned long size)
13195 {
132− unsigned long start, end, pos = 0;
133− int i;
134−
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;
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;
145104 }
146−
147− return pos;
148105 }
149106
150−static unsigned long position_to_address(unsigned long pos, unsigned long kernel_size,
151− unsigned long _min, unsigned long _max)
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)
152111 {
153− unsigned long start, end;
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;
154115 int i;
155116
156− for_each_mem_detect_usable_block(i, &start, &end) {
117+ align = max(align, 8UL);
118+ _min = round_up(_min, align);
119+ for_each_physmem_usable_range(i, &start, &end) {
157120 if (_min >= end)
158121 continue;
122+ start = round_up(start, align);
159123 if (start >= _max)
160124 break;
161125 start = max(_min, start);
162126 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;
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+ }
168156 }
169157
170− return 0;
158+ return pos_count ? pos : 0;
171159 }
172160
173−unsigned long get_random_base(unsigned long safe_addr)
161+/*
162+ * Two types of decompressor memory allocations/reserves are considered
163+ * differently.
164+ *
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.
181+ */
182+unsigned long randomize_within_range(unsigned long size, unsigned long align,
183+ unsigned long min, unsigned long max)
174184 {
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);
185+ struct reserved_range res[RR_MAX];
186+ unsigned long max_pos, pos;
187187
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)
191− return 0;
188+ memcpy(res, physmem_info.reserved, sizeof(res));
189+ sort_reserved_ranges(res, ARRAY_SIZE(res));
190+ max = min(max, get_physmem_alloc_pos());
192191
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");
192+ max_pos = iterate_valid_positions(size, align, min, max, res, ARRAY_SIZE(res), true, 0);
193+ if (!max_pos)
196194 return 0;
197− }
198−
199− /* we need a value in the range [1, base_pos] inclusive */
200− if (get_random(max_pos, &base_pos))
195+ if (get_random(max_pos, &pos))
201196 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);
203198 }
arch/s390/boot/mem_detect.c+0−191
@@ -1,191 +0,0 @@
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−}
arch/s390/boot/pgm_check_info.c+3−4
@@ -123,11 +123,10 @@ out: · 122 unmodified lines
123123 sclp_early_printk(buf);
124124 }
125125
126−static noinline void print_stacktrace(void)
126+void print_stacktrace(unsigned long sp)
127127 {
128128 struct stack_info boot_stack = { STACK_TYPE_TASK, (unsigned long)_stack_start,
129129 (unsigned long)_stack_end };
130− unsigned long sp = S390_lowcore.gpregs_save_area[15];
131130 bool first = true;
132131
133132 decompressor_printk("Call Trace:\n");
@@ -154,7 +153,7 @@ void print_pgm_check_info(void) · 20 unmodified lines
154153 decompressor_printk("Kernel command line: %s\n", early_command_line);
155154 decompressor_printk("Kernel fault: interruption code %04x ilc:%x\n",
156155 S390_lowcore.pgm_code, S390_lowcore.pgm_ilc >> 1);
157− if (kaslr_enabled)
156+ if (kaslr_enabled())
158157 decompressor_printk("Kernel random base: %lx\n", __kaslr_offset);
159158 decompressor_printk("PSW : %016lx %016lx (%pS)\n",
160159 S390_lowcore.psw_save_area.mask,
@@ -173,7 +172,7 @@ void print_pgm_check_info(void) · 12 unmodified lines
173172 gpregs[8], gpregs[9], gpregs[10], gpregs[11]);
174173 decompressor_printk(" %016lx %016lx %016lx %016lx\n",
175174 gpregs[12], gpregs[13], gpregs[14], gpregs[15]);
176− print_stacktrace();
175+ print_stacktrace(S390_lowcore.gpregs_save_area[15]);
177176 decompressor_printk("Last Breaking-Event-Address:\n");
178177 decompressor_printk(" [<%016lx>] %pS\n", (unsigned long)S390_lowcore.pgm_last_break,
179178 (void *)S390_lowcore.pgm_last_break);
arch/s390/boot/physmem_info.c+328−0
@@ -0,0 +1,328 @@
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+}
arch/s390/boot/startup.c+73−56
@@ -12,7 +12,7 @@ · 11 unmodified lines
1212 #include <asm/diag.h>
1313 #include <asm/uv.h>
1414 #include <asm/abs_lowcore.h>
15−#include <asm/mem_detect.h>
15+#include <asm/physmem_info.h>
1616 #include "decompressor.h"
1717 #include "boot.h"
1818 #include "uv.h"
@@ -21,7 +21,6 @@ unsigned long __bootdata_preserved(__kaslr_offset); · 2 unmodified lines
2121 unsigned long __bootdata_preserved(__abs_lowcore);
2222 unsigned long __bootdata_preserved(__memcpy_real_area);
2323 pte_t *__bootdata_preserved(memcpy_real_ptep);
24−unsigned long __bootdata(__amode31_base);
2524 unsigned long __bootdata_preserved(VMALLOC_START);
2625 unsigned long __bootdata_preserved(VMALLOC_END);
2726 struct page *__bootdata_preserved(vmemmap);
@@ -29,8 +28,6 @@ unsigned long __bootdata_preserved(vmemmap_size); · 1 unmodified line
2928 unsigned long __bootdata_preserved(MODULES_VADDR);
3029 unsigned long __bootdata_preserved(MODULES_END);
3130 unsigned long __bootdata(ident_map_size);
32−int __bootdata(is_full_image) = 1;
33−struct initrd_data __bootdata(initrd_data);
3431
3532 u64 __bootdata_preserved(stfle_fac_list[16]);
3633 u64 __bootdata_preserved(alt_stfle_fac_list[16]);
@@ -76,17 +73,20 @@ unsigned long mem_safe_offset(void) · 39 unmodified lines
7673 }
7774 #endif
7875
79−static unsigned long rescue_initrd(unsigned long safe_addr)
76+static void rescue_initrd(unsigned long min, unsigned long max)
8077 {
78+ unsigned long old_addr, addr, size;
79+
8180 if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD))
82− return safe_addr;
83− if (!initrd_data.start || !initrd_data.size)
84− return safe_addr;
85− if (initrd_data.start < safe_addr) {
86− memmove((void *)safe_addr, (void *)initrd_data.start, initrd_data.size);
87− initrd_data.start = safe_addr;
88− }
89− return initrd_data.start + initrd_data.size;
81+ return;
82+ if (!get_physmem_reserved(RR_INITRD, &addr, &size))
83+ return;
84+ if (addr >= min && addr + size <= max)
85+ return;
86+ old_addr = addr;
87+ physmem_free(RR_INITRD);
88+ addr = physmem_alloc_top_down(RR_INITRD, size, 0);
89+ memmove((void *)addr, (void *)old_addr, size);
9090 }
9191
9292 static void copy_bootdata(void)
@@ -140,7 +140,7 @@ static void handle_relocs(unsigned long offset) · 47 unmodified lines
140140 *
141141 * Consider the following factors:
142142 * 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()).
144144 * 2. CONFIG_MAX_PHYSMEM_BITS - the maximum size of physical memory the
145145 * kernel is able to support.
146146 * 3. "mem=" kernel command line option which limits physical memory usage.
@@ -160,10 +160,10 @@ static void setup_ident_map_size(unsigned long max_physmem_end) · 13 unmodified lines
160160
161161 #ifdef CONFIG_CRASH_DUMP
162162 if (oldmem_data.start) {
163− kaslr_enabled = 0;
163+ __kaslr_enabled = 0;
164164 ident_map_size = min(ident_map_size, oldmem_data.size);
165165 } else if (ipl_block_valid && is_ipl_block_dump()) {
166− kaslr_enabled = 0;
166+ __kaslr_enabled = 0;
167167 if (!sclp_early_get_hsa_size(&hsa_size) && hsa_size)
168168 ident_map_size = min(ident_map_size, hsa_size);
169169 }
@@ -235,9 +235,9 @@ static unsigned long setup_kernel_memory_layout(void) · 65 unmodified lines
235235 /*
236236 * This function clears the BSS section of the decompressed Linux kernel and NOT the decompressor's.
237237 */
238−static void clear_bss_section(void)
238+static void clear_bss_section(unsigned long vmlinux_lma)
239239 {
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);
241241 }
242242
243243 /*
@@ -256,7 +256,6 @@ static void setup_vmalloc_size(void) · 12 unmodified lines
256256
257257 static void offset_vmlinux_info(unsigned long offset)
258258 {
259− vmlinux.default_lma += offset;
260259 *(unsigned long *)(&vmlinux.entry) += offset;
261260 vmlinux.bootdata_off += offset;
262261 vmlinux.bootdata_preserved_off += offset;
@@ -266,60 +265,83 @@ static void offset_vmlinux_info(unsigned long offset) · 3 unmodified lines
266265 vmlinux.init_mm_off += offset;
267266 vmlinux.swapper_pg_dir_off += offset;
268267 vmlinux.invalid_pg_dir_off += offset;
269−}
270−
271−static unsigned long reserve_amode31(unsigned long safe_addr)
272−{
273− __amode31_base = PAGE_ALIGN(safe_addr);
274− return __amode31_base + vmlinux.amode31_size;
268+#ifdef CONFIG_KASAN
269+ vmlinux.kasan_early_shadow_page_off += offset;
270+ vmlinux.kasan_early_shadow_pte_off += offset;
271+ vmlinux.kasan_early_shadow_pmd_off += offset;
272+ vmlinux.kasan_early_shadow_pud_off += offset;
273+ vmlinux.kasan_early_shadow_p4d_off += offset;
274+#endif
275275 }
276276
277277 void startup_kernel(void)
278278 {
279279 unsigned long max_physmem_end;
280− unsigned long random_lma;
281− unsigned long safe_addr;
280+ unsigned long vmlinux_lma = 0;
281+ unsigned long amode31_lma = 0;
282282 unsigned long asce_limit;
283+ unsigned long safe_addr;
283284 void *img;
284285 psw_t psw;
285286
286− initrd_data.start = parmarea.initrd_start;
287− initrd_data.size = parmarea.initrd_size;
287+ setup_lpp();
288+ safe_addr = mem_safe_offset();
289+ /*
290+ * reserve decompressor memory together with decompression heap, buffer and
291+ * memory which might be occupied by uncompressed kernel at default 1Mb
292+ * position (if KASLR is off or failed).
293+ */
294+ physmem_reserve(RR_DECOMPRESSOR, 0, safe_addr);
295+ if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && parmarea.initrd_size)
296+ physmem_reserve(RR_INITRD, parmarea.initrd_start, parmarea.initrd_size);
288297 oldmem_data.start = parmarea.oldmem_base;
289298 oldmem_data.size = parmarea.oldmem_size;
290299
291− setup_lpp();
292300 store_ipl_parmblock();
293− safe_addr = mem_safe_offset();
294− safe_addr = reserve_amode31(safe_addr);
295− safe_addr = read_ipl_report(safe_addr);
301+ read_ipl_report();
296302 uv_query_info();
297− safe_addr = rescue_initrd(safe_addr);
298303 sclp_early_read_info();
299304 setup_boot_command_line();
300305 parse_boot_command_line();
301306 detect_facilities();
302307 sanitize_prot_virt_host();
303− max_physmem_end = detect_memory(&safe_addr);
308+ max_physmem_end = detect_max_physmem_end();
304309 setup_ident_map_size(max_physmem_end);
305310 setup_vmalloc_size();
306311 asce_limit = setup_kernel_memory_layout();
307− mem_detect_set_usable_limit(ident_map_size);
308−
309− if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_enabled) {
310− random_lma = get_random_base(safe_addr);
311− if (random_lma) {
312− __kaslr_offset = random_lma - vmlinux.default_lma;
313− img = (void *)vmlinux.default_lma;
312+ /* got final ident_map_size, physmem allocations could be performed now */
313+ physmem_set_usable_limit(ident_map_size);
314+ detect_physmem_online_ranges(max_physmem_end);
315+ save_ipl_cert_comp_list();
316+ rescue_initrd(safe_addr, ident_map_size);
317+
318+ if (kaslr_enabled()) {
319+ vmlinux_lma = randomize_within_range(vmlinux.image_size + vmlinux.bss_size,
320+ THREAD_SIZE, vmlinux.default_lma,
321+ ident_map_size);
322+ if (vmlinux_lma) {
323+ __kaslr_offset = vmlinux_lma - vmlinux.default_lma;
314324 offset_vmlinux_info(__kaslr_offset);
315325 }
316326 }
327+ vmlinux_lma = vmlinux_lma ?: vmlinux.default_lma;
328+ physmem_reserve(RR_VMLINUX, vmlinux_lma, vmlinux.image_size + vmlinux.bss_size);
317329
318330 if (!IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED)) {
319331 img = decompress_kernel();
320− memmove((void *)vmlinux.default_lma, img, vmlinux.image_size);
321− } else if (__kaslr_offset)
322− memcpy((void *)vmlinux.default_lma, img, vmlinux.image_size);
332+ memmove((void *)vmlinux_lma, img, vmlinux.image_size);
333+ } else if (__kaslr_offset) {
334+ img = (void *)vmlinux.default_lma;
335+ memmove((void *)vmlinux_lma, img, vmlinux.image_size);
336+ memset(img, 0, vmlinux.image_size);
337+ }
338+
339+ /* vmlinux decompression is done, shrink reserved low memory */
340+ physmem_reserve(RR_DECOMPRESSOR, 0, (unsigned long)_decompressor_end);
341+ if (kaslr_enabled())
342+ amode31_lma = randomize_within_range(vmlinux.amode31_size, PAGE_SIZE, 0, SZ_2G);
343+ amode31_lma = amode31_lma ?: vmlinux.default_lma - vmlinux.amode31_size;
344+ physmem_reserve(RR_AMODE31, amode31_lma, vmlinux.amode31_size);
323345
324346 /*
325347 * The order of the following operations is important:
@@ -334,21 +356,16 @@ void startup_kernel(void) · 8 unmodified lines
334356 * - copy_bootdata() must follow setup_vmem() to propagate changes to
335357 * bootdata made by setup_vmem()
336358 */
337− clear_bss_section();
359+ clear_bss_section(vmlinux_lma);
338360 handle_relocs(__kaslr_offset);
339361 setup_vmem(asce_limit);
340362 copy_bootdata();
341363
342− if (__kaslr_offset) {
343− /*
344− * Save KASLR offset for early dumps, before vmcore_info is set.
345− * Mark as uneven to distinguish from real vmcore_info pointer.
346− */
347− S390_lowcore.vmcore_info = __kaslr_offset | 0x1UL;
348− /* Clear non-relocated kernel */
349− if (IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED))
350− memset(img, 0, vmlinux.image_size);
351− }
364+ /*
365+ * Save KASLR offset for early dumps, before vmcore_info is set.
366+ * Mark as uneven to distinguish from real vmcore_info pointer.
367+ */
368+ S390_lowcore.vmcore_info = __kaslr_offset ? __kaslr_offset | 0x1UL : 0;
352369
353370 /*
354371 * Jump to the decompressed kernel entry point and switch DAT mode on.
arch/s390/boot/vmem.c+223−61
@@ -1,81 +1,217 @@
11 // SPDX-License-Identifier: GPL-2.0
22 #include <linux/sched/task.h>
33 #include <linux/pgtable.h>
4+#include <linux/kasan.h>
45 #include <asm/pgalloc.h>
56 #include <asm/facility.h>
67 #include <asm/sections.h>
7−#include <asm/mem_detect.h>
8+#include <asm/physmem_info.h>
89 #include <asm/maccess.h>
910 #include <asm/abs_lowcore.h>
1011 #include "decompressor.h"
1112 #include "boot.h"
1213
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+
1320 #define init_mm (*(struct mm_struct *)vmlinux.init_mm_off)
1421 #define swapper_pg_dir vmlinux.swapper_pg_dir_off
1522 #define invalid_pg_dir vmlinux.invalid_pg_dir_off
1623
17−/*
18− * Mimic virt_to_kpte() in lack of init_mm symbol. Skip pmd NULL check though.
19− */
20−static inline pte_t *__virt_to_kpte(unsigned long va)
21−{
22− return pte_offset_kernel(pmd_offset(pud_offset(p4d_offset(pgd_offset_k(va), va), va), va), va);
23−}
24−
25−unsigned long __bootdata_preserved(s390_invalid_asce);
26−unsigned long __bootdata(pgalloc_pos);
27−unsigned long __bootdata(pgalloc_end);
28−unsigned long __bootdata(pgalloc_low);
29−
3024 enum populate_mode {
3125 POPULATE_NONE,
32− POPULATE_ONE2ONE,
26+ POPULATE_DIRECT,
3327 POPULATE_ABS_LOWCORE,
28+#ifdef CONFIG_KASAN
29+ POPULATE_KASAN_MAP_SHADOW,
30+ POPULATE_KASAN_ZERO_SHADOW,
31+ POPULATE_KASAN_SHALLOW
32+#endif
3433 };
3534
36−static void boot_check_oom(void)
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)
37113 {
38− if (pgalloc_pos < pgalloc_low)
39− error("out of memory on boot\n");
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;
40120 }
41121
42−static void pgtable_populate_init(void)
122+static bool kasan_p4d_populate_zero_shadow(p4d_t *p4d, unsigned long addr,
123+ unsigned long end, enum populate_mode mode)
43124 {
44− unsigned long initrd_end;
45− unsigned long kernel_end;
46−
47− kernel_end = vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size;
48− pgalloc_low = round_up(kernel_end, PAGE_SIZE);
49− if (IS_ENABLED(CONFIG_BLK_DEV_INITRD)) {
50− initrd_end = round_up(initrd_data.start + initrd_data.size, _SEGMENT_SIZE);
51− pgalloc_low = max(pgalloc_low, initrd_end);
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;
52129 }
130+ return false;
131+}
53132
54− pgalloc_end = round_down(get_mem_detect_end(), PAGE_SIZE);
55− pgalloc_pos = pgalloc_end;
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+}
56143
57− boot_check_oom();
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;
58153 }
59154
60−static void *boot_alloc_pages(unsigned int order)
155+static bool kasan_pte_populate_zero_shadow(pte_t *pte, enum populate_mode mode)
61156 {
62− unsigned long size = PAGE_SIZE << order;
157+ pte_t entry;
63158
64− pgalloc_pos -= size;
65− pgalloc_pos = round_down(pgalloc_pos, size);
159+ if (mode == POPULATE_KASAN_ZERO_SHADOW) {
160+ set_pte(pte, pte_z);
161+ return true;
162+ }
163+ return false;
164+}
165+#else
66166
67− boot_check_oom();
167+static inline void kasan_populate_shadow(void) {}
68168
69− return (void *)pgalloc_pos;
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
199+
200+/*
201+ * Mimic virt_to_kpte() in lack of init_mm symbol. Skip pmd NULL check though.
202+ */
203+static inline pte_t *__virt_to_kpte(unsigned long va)
204+{
205+ return pte_offset_kernel(pmd_offset(pud_offset(p4d_offset(pgd_offset_k(va), va), va), va), va);
70206 }
71207
72208 static void *boot_crst_alloc(unsigned long val)
73209 {
210+ unsigned long size = PAGE_SIZE << CRST_ALLOC_ORDER;
74211 unsigned long *table;
75212
76− table = boot_alloc_pages(CRST_ALLOC_ORDER);
77− if (table)
78− crst_table_init(table, val);
213+ table = (unsigned long *)physmem_alloc_top_down(RR_VMEM, size, size);
214+ crst_table_init(table, val);
79215 return table;
80216 }
81217
@@ -84,28 +220,37 @@ static pte_t *boot_pte_alloc(void) · 2 unmodified lines
84220 static void *pte_leftover;
85221 pte_t *pte;
86222
87− BUILD_BUG_ON(_PAGE_TABLE_SIZE * 2 != PAGE_SIZE);
88−
223+ /*
224+ * handling pte_leftovers this way helps to avoid memory fragmentation
225+ * during POPULATE_KASAN_MAP_SHADOW when EDAT is off
226+ */
89227 if (!pte_leftover) {
90− pte_leftover = boot_alloc_pages(0);
228+ pte_leftover = (void *)physmem_alloc_top_down(RR_VMEM, PAGE_SIZE, PAGE_SIZE);
91229 pte = pte_leftover + _PAGE_TABLE_SIZE;
92230 } else {
93231 pte = pte_leftover;
94232 pte_leftover = NULL;
95233 }
234+
96235 memset64((u64 *)pte, _PAGE_INVALID, PTRS_PER_PTE);
97236 return pte;
98237 }
99238
100−static unsigned long _pa(unsigned long addr, enum populate_mode mode)
239+static unsigned long _pa(unsigned long addr, unsigned long size, enum populate_mode mode)
101240 {
102241 switch (mode) {
103242 case POPULATE_NONE:
104243 return -1;
105− case POPULATE_ONE2ONE:
244+ case POPULATE_DIRECT:
106245 return addr;
107246 case POPULATE_ABS_LOWCORE:
108247 return __abs_lowcore_pa(addr);
248+#ifdef CONFIG_KASAN
249+ case POPULATE_KASAN_MAP_SHADOW:
250+ addr = physmem_alloc_top_down(RR_VMEM, size, size);
251+ memset((void *)addr, 0, size);
252+ return addr;
253+#endif
109254 default:
110255 return -1;
111256 }
@@ -126,23 +271,28 @@ static bool can_large_pmd(pmd_t *pm_dir, unsigned long addr, unsigned long end) · 14 unmodified lines
126271 static void pgtable_pte_populate(pmd_t *pmd, unsigned long addr, unsigned long end,
127272 enum populate_mode mode)
128273 {
129− unsigned long next;
274+ unsigned long pages = 0;
130275 pte_t *pte, entry;
131276
132277 pte = pte_offset_kernel(pmd, addr);
133278 for (; addr < end; addr += PAGE_SIZE, pte++) {
134279 if (pte_none(*pte)) {
135− entry = __pte(_pa(addr, mode));
280+ if (kasan_pte_populate_zero_shadow(pte, mode))
281+ continue;
282+ entry = __pte(_pa(addr, PAGE_SIZE, mode));
136283 entry = set_pte_bit(entry, PAGE_KERNEL_EXEC);
137284 set_pte(pte, entry);
285+ pages++;
138286 }
139287 }
288+ if (mode == POPULATE_DIRECT)
289+ update_page_count(PG_DIRECT_MAP_4K, pages);
140290 }
141291
142292 static void pgtable_pmd_populate(pud_t *pud, unsigned long addr, unsigned long end,
143293 enum populate_mode mode)
144294 {
145− unsigned long next;
295+ unsigned long next, pages = 0;
146296 pmd_t *pmd, entry;
147297 pte_t *pte;
148298
@@ -150,10 +300,13 @@ static void pgtable_pmd_populate(pud_t *pud, unsigned long addr, unsigned long e · 1 unmodified line
150300 for (; addr < end; addr = next, pmd++) {
151301 next = pmd_addr_end(addr, end);
152302 if (pmd_none(*pmd)) {
303+ if (kasan_pmd_populate_zero_shadow(pmd, addr, next, mode))
304+ continue;
153305 if (can_large_pmd(pmd, addr, next)) {
154− entry = __pmd(_pa(addr, mode));
306+ entry = __pmd(_pa(addr, _SEGMENT_SIZE, mode));
155307 entry = set_pmd_bit(entry, SEGMENT_KERNEL_EXEC);
156308 set_pmd(pmd, entry);
309+ pages++;
157310 continue;
158311 }
159312 pte = boot_pte_alloc();
@@ -163,12 +316,14 @@ static void pgtable_pmd_populate(pud_t *pud, unsigned long addr, unsigned long e · 3 unmodified lines
163316 }
164317 pgtable_pte_populate(pmd, addr, next, mode);
165318 }
319+ if (mode == POPULATE_DIRECT)
320+ update_page_count(PG_DIRECT_MAP_1M, pages);
166321 }
167322
168323 static void pgtable_pud_populate(p4d_t *p4d, unsigned long addr, unsigned long end,
169324 enum populate_mode mode)
170325 {
171− unsigned long next;
326+ unsigned long next, pages = 0;
172327 pud_t *pud, entry;
173328 pmd_t *pmd;
174329
@@ -176,10 +331,13 @@ static void pgtable_pud_populate(p4d_t *p4d, unsigned long addr, unsigned long e · 1 unmodified line
176331 for (; addr < end; addr = next, pud++) {
177332 next = pud_addr_end(addr, end);
178333 if (pud_none(*pud)) {
334+ if (kasan_pud_populate_zero_shadow(pud, addr, next, mode))
335+ continue;
179336 if (can_large_pud(pud, addr, next)) {
180− entry = __pud(_pa(addr, mode));
337+ entry = __pud(_pa(addr, _REGION3_SIZE, mode));
181338 entry = set_pud_bit(entry, REGION3_KERNEL_EXEC);
182339 set_pud(pud, entry);
340+ pages++;
183341 continue;
184342 }
185343 pmd = boot_crst_alloc(_SEGMENT_ENTRY_EMPTY);
@@ -189,6 +347,8 @@ static void pgtable_pud_populate(p4d_t *p4d, unsigned long addr, unsigned long e · 3 unmodified lines
189347 }
190348 pgtable_pmd_populate(pud, addr, next, mode);
191349 }
350+ if (mode == POPULATE_DIRECT)
351+ update_page_count(PG_DIRECT_MAP_2G, pages);
192352 }
193353
194354 static void pgtable_p4d_populate(pgd_t *pgd, unsigned long addr, unsigned long end,
@@ -202,6 +362,8 @@ static void pgtable_p4d_populate(pgd_t *pgd, unsigned long addr, unsigned long e · 7 unmodified lines
202362 for (; addr < end; addr = next, p4d++) {
203363 next = p4d_addr_end(addr, end);
204364 if (p4d_none(*p4d)) {
365+ if (kasan_p4d_populate_zero_shadow(p4d, addr, next, mode))
366+ continue;
205367 pud = boot_crst_alloc(_REGION3_ENTRY_EMPTY);
206368 p4d_populate(&init_mm, p4d, pud);
207369 }
@@ -219,9 +381,15 @@ static void pgtable_populate(unsigned long addr, unsigned long end, enum populat · 11 unmodified lines
219381 for (; addr < end; addr = next, pgd++) {
220382 next = pgd_addr_end(addr, end);
221383 if (pgd_none(*pgd)) {
384+ if (kasan_pgd_populate_zero_shadow(pgd, addr, next, mode))
385+ continue;
222386 p4d = boot_crst_alloc(_REGION2_ENTRY_EMPTY);
223387 pgd_populate(&init_mm, pgd, p4d);
224388 }
389+#ifdef CONFIG_KASAN
390+ if (mode == POPULATE_KASAN_SHALLOW)
391+ continue;
392+#endif
225393 pgtable_p4d_populate(pgd, addr, next, mode);
226394 }
227395 }
@@ -250,16 +418,17 @@ void setup_vmem(unsigned long asce_limit) · 22 unmodified lines
250418 * To prevent creation of a large page at address 0 first map
251419 * the lowcore and create the identity mapping only afterwards.
252420 */
253− pgtable_populate_init();
254− pgtable_populate(0, sizeof(struct lowcore), POPULATE_ONE2ONE);
255− for_each_mem_detect_usable_block(i, &start, &end)
256− pgtable_populate(start, end, POPULATE_ONE2ONE);
421+ pgtable_populate(0, sizeof(struct lowcore), POPULATE_DIRECT);
422+ for_each_physmem_usable_range(i, &start, &end)
423+ pgtable_populate(start, end, POPULATE_DIRECT);
257424 pgtable_populate(__abs_lowcore, __abs_lowcore + sizeof(struct lowcore),
258425 POPULATE_ABS_LOWCORE);
259426 pgtable_populate(__memcpy_real_area, __memcpy_real_area + PAGE_SIZE,
260427 POPULATE_NONE);
261428 memcpy_real_ptep = __virt_to_kpte(__memcpy_real_area);
262429
430+ kasan_populate_shadow();
431+
263432 S390_lowcore.kernel_asce = swapper_pg_dir | asce_bits;
264433 S390_lowcore.user_asce = s390_invalid_asce;
265434
@@ -269,10 +438,3 @@ void setup_vmem(unsigned long asce_limit) · 3 unmodified lines
269438
270439 init_mm.context.asce = S390_lowcore.kernel_asce;
271440 }
272−
273−unsigned long vmem_estimate_memory_needs(unsigned long online_mem_total)
274−{
275− unsigned long pages = DIV_ROUND_UP(online_mem_total, PAGE_SIZE);
276−
277− return DIV_ROUND_UP(pages, _PAGE_ENTRIES) * _PAGE_TABLE_SIZE * 2;
278−}
arch/s390/boot/vmlinux.lds.S+2−0
@@ -93,6 +93,8 @@ SECTIONS · 92 unmodified lines
9393 _decompressor_syms_end = .;
9494 }
9595
96+ _decompressor_end = .;
97+
9698 #ifdef CONFIG_KERNEL_UNCOMPRESSED
9799 . = 0x100000;
98100 #else
arch/s390/crypto/chacha-s390.S+24−23
@@ -13,27 +13,28 @@ · 12 unmodified lines
1313 #define SP %r15
1414 #define FRAME (16 * 8 + 4 * 8)
1515
16−.data
17−.align 32
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
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
16+ .data
17+ .balign 32
3118
32−.previous
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+
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)
32+
33+ .previous
3334
3435 GEN_BR_THUNK %r14
3536
36−.text
37+ .text
3738
3839 #############################################################################
3940 # void chacha20_vx_4x(u8 *out, counst u8 *inp, size_t len,
@@ -78,10 +79,10 @@ · 38 unmodified lines
7879 #define XT2 %v29
7980 #define XT3 %v30
8081
81−ENTRY(chacha20_vx_4x)
82+SYM_FUNC_START(chacha20_vx_4x)
8283 stmg %r6,%r7,6*8(SP)
8384
84− larl %r7,.Lsigma
85+ larl %r7,sigma
8586 lhi %r0,10
8687 lhi %r1,0
8788
@@ -403,7 +404,7 @@ ENTRY(chacha20_vx_4x) · 315 unmodified lines
403404
404405 lmg %r6,%r7,6*8(SP)
405406 BR_EX %r14
406−ENDPROC(chacha20_vx_4x)
407+SYM_FUNC_END(chacha20_vx_4x)
407408
408409 #undef OUT
409410 #undef INP
@@ -471,7 +472,7 @@ ENDPROC(chacha20_vx_4x) · 61 unmodified lines
471472 #define T2 %v29
472473 #define T3 %v30
473474
474−ENTRY(chacha20_vx)
475+SYM_FUNC_START(chacha20_vx)
475476 clgfi LEN,256
476477 jle chacha20_vx_4x
477478 stmg %r6,%r7,6*8(SP)
@@ -481,7 +482,7 @@ ENTRY(chacha20_vx) · 3 unmodified lines
481482 la SP,0(%r1,SP)
482483 stg %r0,0(SP) # back-chain
483484
484− larl %r7,.Lsigma
485+ larl %r7,sigma
485486 lhi %r0,10
486487
487488 VLM K1,K2,0,KEY,0 # load key
@@ -902,6 +903,6 @@ ENTRY(chacha20_vx) · 414 unmodified lines
902903 lmg %r6,%r7,FRAME+6*8(SP)
903904 la SP,FRAME(SP)
904905 BR_EX %r14
905−ENDPROC(chacha20_vx)
906+SYM_FUNC_END(chacha20_vx)
906907
907908 .previous
arch/s390/crypto/crc32be-vx.S+9−8
@@ -24,8 +24,8 @@ · 23 unmodified lines
2424 #define CONST_RU_POLY %v13
2525 #define CONST_CRC_POLY %v14
2626
27−.data
28−.align 8
27+ .data
28+ .balign 8
2929
3030 /*
3131 * The CRC-32 constant block contains reduction constants to fold and
@@ -58,19 +58,20 @@ · 26 unmodified lines
5858 * P'(x) = 0xEDB88320
5959 */
6060
61−.Lconstants_CRC_32_BE:
61+SYM_DATA_START_LOCAL(constants_CRC_32_BE)
6262 .quad 0x08833794c, 0x0e6228b11 # R1, R2
6363 .quad 0x0c5b9cd4c, 0x0e8a45605 # R3, R4
6464 .quad 0x0f200aa66, 1 << 32 # R5, x32
6565 .quad 0x0490d678d, 1 # R6, 1
6666 .quad 0x104d101df, 0 # u
6767 .quad 0x104C11DB7, 0 # P(x)
68+SYM_DATA_END(constants_CRC_32_BE)
6869
69−.previous
70+ .previous
7071
7172 GEN_BR_THUNK %r14
7273
73−.text
74+ .text
7475 /*
7576 * The CRC-32 function(s) use these calling conventions:
7677 *
@@ -90,9 +91,9 @@ · 13 unmodified lines
9091 *
9192 * V9..V14: CRC-32 constants.
9293 */
93−ENTRY(crc32_be_vgfm_16)
94+SYM_FUNC_START(crc32_be_vgfm_16)
9495 /* Load CRC-32 constants */
95− larl %r5,.Lconstants_CRC_32_BE
96+ larl %r5,constants_CRC_32_BE
9697 VLM CONST_R1R2,CONST_CRC_POLY,0,%r5
9798
9899 /* Load the initial CRC value into the leftmost word of V0. */
@@ -207,6 +208,6 @@ ENTRY(crc32_be_vgfm_16) · 108 unmodified lines
207208 .Ldone:
208209 VLGVF %r2,%v2,3
209210 BR_EX %r14
210−ENDPROC(crc32_be_vgfm_16)
211+SYM_FUNC_END(crc32_be_vgfm_16)
211212
212213 .previous
arch/s390/crypto/crc32le-vx.S+16−14
@@ -25,8 +25,8 @@ · 24 unmodified lines
2525 #define CONST_RU_POLY %v13
2626 #define CONST_CRC_POLY %v14
2727
28−.data
29−.align 8
28+ .data
29+ .balign 8
3030
3131 /*
3232 * The CRC-32 constant block contains reduction constants to fold and
@@ -59,27 +59,29 @@ · 26 unmodified lines
5959 * P'(x) = 0x82F63B78
6060 */
6161
62−.Lconstants_CRC_32_LE:
62+SYM_DATA_START_LOCAL(constants_CRC_32_LE)
6363 .octa 0x0F0E0D0C0B0A09080706050403020100 # BE->LE mask
6464 .quad 0x1c6e41596, 0x154442bd4 # R2, R1
6565 .quad 0x0ccaa009e, 0x1751997d0 # R4, R3
6666 .octa 0x163cd6124 # R5
6767 .octa 0x1F7011641 # u'
6868 .octa 0x1DB710641 # P'(x) << 1
69+SYM_DATA_END(constants_CRC_32_LE)
6970
70−.Lconstants_CRC_32C_LE:
71+SYM_DATA_START_LOCAL(constants_CRC_32C_LE)
7172 .octa 0x0F0E0D0C0B0A09080706050403020100 # BE->LE mask
7273 .quad 0x09e4addf8, 0x740eef02 # R2, R1
7374 .quad 0x14cd00bd6, 0xf20c0dfe # R4, R3
7475 .octa 0x0dd45aab8 # R5
7576 .octa 0x0dea713f1 # u'
7677 .octa 0x105ec76f0 # P'(x) << 1
78+SYM_DATA_END(constants_CRC_32C_LE)
7779
78−.previous
80+ .previous
7981
8082 GEN_BR_THUNK %r14
8183
82−.text
84+ .text
8385
8486 /*
8587 * The CRC-32 functions use these calling conventions:
@@ -102,17 +104,17 @@ · 16 unmodified lines
102104 * V10..V14: CRC-32 constants.
103105 */
104106
105−ENTRY(crc32_le_vgfm_16)
106− larl %r5,.Lconstants_CRC_32_LE
107+SYM_FUNC_START(crc32_le_vgfm_16)
108+ larl %r5,constants_CRC_32_LE
107109 j crc32_le_vgfm_generic
108−ENDPROC(crc32_le_vgfm_16)
110+SYM_FUNC_END(crc32_le_vgfm_16)
109111
110−ENTRY(crc32c_le_vgfm_16)
111− larl %r5,.Lconstants_CRC_32C_LE
112+SYM_FUNC_START(crc32c_le_vgfm_16)
113+ larl %r5,constants_CRC_32C_LE
112114 j crc32_le_vgfm_generic
113−ENDPROC(crc32c_le_vgfm_16)
115+SYM_FUNC_END(crc32c_le_vgfm_16)
114116
115−ENTRY(crc32_le_vgfm_generic)
117+SYM_FUNC_START(crc32_le_vgfm_generic)
116118 /* Load CRC-32 constants */
117119 VLM CONST_PERM_LE2BE,CONST_CRC_POLY,0,%r5
118120
@@ -268,6 +270,6 @@ ENTRY(crc32_le_vgfm_generic) · 149 unmodified lines
268270 .Ldone:
269271 VLGVF %r2,%v2,2
270272 BR_EX %r14
271−ENDPROC(crc32_le_vgfm_generic)
273+SYM_FUNC_END(crc32_le_vgfm_generic)
272274
273275 .previous
arch/s390/include/asm/ap.h+128−24
@@ -43,10 +43,11 @@ struct ap_queue_status { · 42 unmodified lines
4343 unsigned int queue_empty : 1;
4444 unsigned int replies_waiting : 1;
4545 unsigned int queue_full : 1;
46− unsigned int _pad1 : 4;
46+ unsigned int : 3;
47+ unsigned int async : 1;
4748 unsigned int irq_enabled : 1;
4849 unsigned int response_code : 8;
49− unsigned int _pad2 : 16;
50+ unsigned int : 16;
5051 };
5152
5253 /*
@@ -86,6 +87,42 @@ static inline bool ap_instructions_available(void) · 33 unmodified lines
8687 return reg1 != 0;
8788 }
8889
90+/* TAPQ register GR2 response struct */
91+struct ap_tapq_gr2 {
92+ union {
93+ unsigned long value;
94+ struct {
95+ unsigned int fac : 32; /* facility bits */
96+ unsigned int apinfo : 32; /* ap type, ... */
97+ };
98+ struct {
99+ unsigned int s : 1; /* APSC */
100+ unsigned int m : 1; /* AP4KM */
101+ unsigned int c : 1; /* AP4KC */
102+ unsigned int mode : 3;
103+ unsigned int n : 1; /* APXA */
104+ unsigned int : 1;
105+ unsigned int class : 8;
106+ unsigned int bs : 2; /* SE bind/assoc */
107+ unsigned int : 14;
108+ unsigned int at : 8; /* ap type */
109+ unsigned int nd : 8; /* nr of domains */
110+ unsigned int : 4;
111+ unsigned int ml : 4; /* apxl ml */
112+ unsigned int : 4;
113+ unsigned int qd : 4; /* queue depth */
114+ };
115+ };
116+};
117+
118+/*
119+ * Convenience defines to be used with the bs field from struct ap_tapq_gr2
120+ */
121+#define AP_BS_Q_USABLE 0
122+#define AP_BS_Q_USABLE_NO_SECURE_KEY 1
123+#define AP_BS_Q_AVAIL_FOR_BINDING 2
124+#define AP_BS_Q_UNUSABLE 3
125+
89126 /**
90127 * ap_tapq(): Test adjunct processor queue.
91128 * @qid: The AP queue number
@@ -93,7 +130,7 @@ static inline bool ap_instructions_available(void) · 1 unmodified line
93130 *
94131 * Returns AP queue status structure.
95132 */
96−static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info)
133+static inline struct ap_queue_status ap_tapq(ap_qid_t qid, struct ap_tapq_gr2 *info)
97134 {
98135 union ap_queue_status_reg reg1;
99136 unsigned long reg2;
@@ -108,7 +145,7 @@ static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info) · 8 unmodified lines
108145 : [qid] "d" (qid)
109146 : "cc", "0", "1", "2");
110147 if (info)
111− *info = reg2;
148+ info->value = reg2;
112149 return reg1.status;
113150 }
114151
@@ -116,13 +153,12 @@ static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info) · 1 unmodified line
116153 * ap_test_queue(): Test adjunct processor queue.
117154 * @qid: The AP queue number
118155 * @tbit: Test facilities bit
119− * @info: Pointer to queue descriptor
156+ * @info: Ptr to tapq gr2 struct
120157 *
121158 * Returns AP queue status structure.
122159 */
123−static inline struct ap_queue_status ap_test_queue(ap_qid_t qid,
124− int tbit,
125− unsigned long *info)
160+static inline struct ap_queue_status ap_test_queue(ap_qid_t qid, int tbit,
161+ struct ap_tapq_gr2 *info)
126162 {
127163 if (tbit)
128164 qid |= 1UL << 23; /* set T bit*/
@@ -132,14 +168,18 @@ static inline struct ap_queue_status ap_test_queue(ap_qid_t qid, · 3 unmodified lines
132168 /**
133169 * ap_pqap_rapq(): Reset adjunct processor queue.
134170 * @qid: The AP queue number
171+ * @fbit: if != 0 set F bit
135172 *
136173 * Returns AP queue status structure.
137174 */
138−static inline struct ap_queue_status ap_rapq(ap_qid_t qid)
175+static inline struct ap_queue_status ap_rapq(ap_qid_t qid, int fbit)
139176 {
140177 unsigned long reg0 = qid | (1UL << 24); /* fc 1UL is RAPQ */
141178 union ap_queue_status_reg reg1;
142179
180+ if (fbit)
181+ reg0 |= 1UL << 22;
182+
143183 asm volatile(
144184 " lgr 0,%[reg0]\n" /* qid arg into gr0 */
145185 " .insn rre,0xb2af0000,0,0\n" /* PQAP(RAPQ) */
@@ -153,14 +193,18 @@ static inline struct ap_queue_status ap_rapq(ap_qid_t qid) · 7 unmodified lines
153193 /**
154194 * ap_pqap_zapq(): Reset and zeroize adjunct processor queue.
155195 * @qid: The AP queue number
196+ * @fbit: if != 0 set F bit
156197 *
157198 * Returns AP queue status structure.
158199 */
159−static inline struct ap_queue_status ap_zapq(ap_qid_t qid)
200+static inline struct ap_queue_status ap_zapq(ap_qid_t qid, int fbit)
160201 {
161202 unsigned long reg0 = qid | (2UL << 24); /* fc 2UL is ZAPQ */
162203 union ap_queue_status_reg reg1;
163204
205+ if (fbit)
206+ reg0 |= 1UL << 22;
207+
164208 asm volatile(
165209 " lgr 0,%[reg0]\n" /* qid arg into gr0 */
166210 " .insn rre,0xb2af0000,0,0\n" /* PQAP(ZAPQ) */
@@ -180,15 +224,16 @@ struct ap_config_info { · 13 unmodified lines
180224 unsigned int apxa : 1; /* N bit */
181225 unsigned int qact : 1; /* C bit */
182226 unsigned int rc8a : 1; /* R bit */
183− unsigned char _reserved1 : 4;
184− unsigned char _reserved2[3];
185− unsigned char Na; /* max # of APs - 1 */
186− unsigned char Nd; /* max # of Domains - 1 */
187− unsigned char _reserved3[10];
227+ unsigned int : 4;
228+ unsigned int apsb : 1; /* B bit */
229+ unsigned int : 23;
230+ unsigned char na; /* max # of APs - 1 */
231+ unsigned char nd; /* max # of Domains - 1 */
232+ unsigned char _reserved0[10];
188233 unsigned int apm[8]; /* AP ID mask */
189234 unsigned int aqm[8]; /* AP (usage) queue mask */
190235 unsigned int adm[8]; /* AP (control) domain mask */
191− unsigned char _reserved4[16];
236+ unsigned char _reserved1[16];
192237 } __aligned(8);
193238
194239 /**
@@ -318,6 +363,59 @@ static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit, · 123 unmodified lines
318363 return reg1.status;
319364 }
320365
366+/*
367+ * ap_bapq(): SE bind AP queue.
368+ * @qid: The AP queue number
369+ *
370+ * Returns AP queue status structure.
371+ *
372+ * Invoking this function in a non-SE environment
373+ * may case a specification exception.
374+ */
375+static inline struct ap_queue_status ap_bapq(ap_qid_t qid)
376+{
377+ unsigned long reg0 = qid | (7UL << 24); /* fc 7 is BAPQ */
378+ union ap_queue_status_reg reg1;
379+
380+ asm volatile(
381+ " lgr 0,%[reg0]\n" /* qid arg into gr0 */
382+ " .insn rre,0xb2af0000,0,0\n" /* PQAP(BAPQ) */
383+ " lgr %[reg1],1\n" /* gr1 (status) into reg1 */
384+ : [reg1] "=&d" (reg1.value)
385+ : [reg0] "d" (reg0)
386+ : "cc", "0", "1");
387+
388+ return reg1.status;
389+}
390+
391+/*
392+ * ap_aapq(): SE associate AP queue.
393+ * @qid: The AP queue number
394+ * @sec_idx: The secret index
395+ *
396+ * Returns AP queue status structure.
397+ *
398+ * Invoking this function in a non-SE environment
399+ * may case a specification exception.
400+ */
401+static inline struct ap_queue_status ap_aapq(ap_qid_t qid, unsigned int sec_idx)
402+{
403+ unsigned long reg0 = qid | (8UL << 24); /* fc 8 is AAPQ */
404+ unsigned long reg2 = sec_idx;
405+ union ap_queue_status_reg reg1;
406+
407+ asm volatile(
408+ " lgr 0,%[reg0]\n" /* qid arg into gr0 */
409+ " lgr 2,%[reg2]\n" /* secret index into gr2 */
410+ " .insn rre,0xb2af0000,0,0\n" /* PQAP(AAPQ) */
411+ " lgr %[reg1],1\n" /* gr1 (status) into reg1 */
412+ : [reg1] "=&d" (reg1.value)
413+ : [reg0] "d" (reg0), [reg2] "d" (reg2)
414+ : "cc", "0", "1", "2");
415+
416+ return reg1.status;
417+}
418+
321419 /**
322420 * ap_nqap(): Send message to adjunct processor queue.
323421 * @qid: The AP queue number
@@ -359,10 +457,11 @@ static inline struct ap_queue_status ap_nqap(ap_qid_t qid, · 35 unmodified lines
359457 * ap_dqap(): Receive message from adjunct processor queue.
360458 * @qid: The AP queue number
361459 * @psmid: Pointer to program supplied message identifier
362− * @msg: The message text
363− * @length: The message length
364− * @reslength: Resitual length on return
365− * @resgr0: input: gr0 value (only used if != 0), output: resitual gr0 content
460+ * @msg: Pointer to message buffer
461+ * @msglen: Message buffer size
462+ * @length: Pointer to length of actually written bytes
463+ * @reslength: Residual length on return
464+ * @resgr0: input: gr0 value (only used if != 0), output: residual gr0 content
366465 *
367466 * Returns AP queue status structure.
368467 * Condition code 1 on DQAP means the receive has taken place
@@ -386,8 +485,9 @@ static inline struct ap_queue_status ap_nqap(ap_qid_t qid, · 17 unmodified lines
386485 * *resgr0 is to be used instead of qid to further process this entry.
387486 */
388487 static inline struct ap_queue_status ap_dqap(ap_qid_t qid,
389− unsigned long long *psmid,
390− void *msg, size_t length,
488+ unsigned long *psmid,
489+ void *msg, size_t msglen,
490+ size_t *length,
391491 size_t *reslength,
392492 unsigned long *resgr0)
393493 {
@@ -399,7 +499,7 @@ static inline struct ap_queue_status ap_dqap(ap_qid_t qid, · 5 unmodified lines
399499 rp1.even = 0UL;
400500 rp1.odd = 0UL;
401501 rp2.even = (unsigned long)msg;
402− rp2.odd = (unsigned long)length;
502+ rp2.odd = (unsigned long)msglen;
403503
404504 asm volatile(
405505 " lgr 0,%[reg0]\n" /* qid param into gr0 */
@@ -429,11 +529,15 @@ static inline struct ap_queue_status ap_dqap(ap_qid_t qid, · 23 unmodified lines
429529 if (resgr0)
430530 *resgr0 = reg0;
431531 } else {
432− *psmid = (((unsigned long long)rp1.even) << 32) + rp1.odd;
532+ *psmid = (rp1.even << 32) + rp1.odd;
433533 if (resgr0)
434534 *resgr0 = 0;
435535 }
436536
537+ /* update *length with the nr of bytes stored into the msg buffer */
538+ if (length)
539+ *length = msglen - rp2.odd;
540+
437541 return reg1.status;
438542 }
439543
arch/s390/include/asm/checksum.h+2−8
@@ -12,13 +12,7 @@ · 11 unmodified lines
1212 #ifndef _S390_CHECKSUM_H
1313 #define _S390_CHECKSUM_H
1414
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>
2216 #include <linux/in6.h>
2317
2418 /*
@@ -40,6 +34,7 @@ static inline __wsum csum_partial(const void *buff, int len, __wsum sum) · 15 unmodified lines
4034 .odd = (unsigned long) len,
4135 };
4236
37+ kasan_check_read(buff, len);
4338 asm volatile(
4439 "0: cksm %[sum],%[rp]\n"
4540 " jo 0b\n"
@@ -135,5 +130,4 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, · 89 unmodified lines
135130 return csum_fold((__force __wsum)(sum >> 32));
136131 }
137132
138−#endif /* CONFIG_GENERIC_CSUM */
139133 #endif /* _S390_CHECKSUM_H */
arch/s390/include/asm/diag.h+1−1
@@ -90,7 +90,7 @@ struct diag8c { · 89 unmodified lines
9090 u8 num_partitions;
9191 u16 width;
9292 u16 height;
93− u8 data[0];
93+ u8 data[];
9494 } __packed __aligned(4);
9595
9696 extern int diag8c(struct diag8c *out, struct ccw_dev_id *devno);
arch/s390/include/asm/entry-common.h+0−5
@@ -60,9 +60,4 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs, · 59 unmodified lines
6060
6161 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
6262
63−static inline bool on_thread_stack(void)
64−{
65− return !(((unsigned long)(current->stack) ^ current_stack_pointer) & ~(THREAD_SIZE - 1));
66−}
67−
6863 #endif
arch/s390/include/asm/fcx.h+1−1
@@ -286,7 +286,7 @@ struct tccb_tcat { · 285 unmodified lines
286286 */
287287 struct tccb {
288288 struct tccb_tcah tcah;
289− u8 tca[0];
289+ u8 tca[];
290290 } __attribute__ ((packed, aligned(8)));
291291
292292 struct tcw *tcw_get_intrg(struct tcw *tcw);
arch/s390/include/asm/kasan.h+1−30
@@ -2,7 +2,7 @@ · 1 unmodified line
22 #ifndef __ASM_KASAN_H
33 #define __ASM_KASAN_H
44
5−#include <asm/pgtable.h>
5+#include <linux/const.h>
66
77 #ifdef CONFIG_KASAN
88
@@ -13,35 +13,6 @@ · 4 unmodified lines
1313 #define KASAN_SHADOW_START KASAN_SHADOW_OFFSET
1414 #define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE)
1515
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; }
4516 #endif
4617
4718 #endif
arch/s390/include/asm/linkage.h+1−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
44
55 #include <linux/stringify.h>
66
7−#define __ALIGN .align 16, 0x07
7+#define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT, 0x07
88 #define __ALIGN_STR __stringify(__ALIGN)
99
1010 #endif
arch/s390/include/asm/mem_detect.h+0−117
@@ -1,117 +0,0 @@
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
arch/s390/include/asm/nospec-insn.h+2−1
@@ -2,6 +2,7 @@ · 1 unmodified line
22 #ifndef _ASM_S390_NOSPEC_ASM_H
33 #define _ASM_S390_NOSPEC_ASM_H
44
5+#include <linux/linkage.h>
56 #include <asm/dwarf.h>
67
78 #ifdef __ASSEMBLY__
@@ -16,7 +17,7 @@ · 8 unmodified lines
1617 .macro __THUNK_PROLOG_NAME name
1718 #ifdef CONFIG_EXPOLINE_EXTERN
1819 .pushsection .text,"ax",@progbits
19− .align 16,0x07
20+ __ALIGN
2021 #else
2122 .pushsection .text.\name,"axG",@progbits,\name,comdat
2223 #endif
arch/s390/include/asm/perf_event.h+0−2
@@ -60,7 +60,6 @@ struct perf_sf_sde_regs { · 59 unmodified lines
6060 #define PERF_CPUM_SF_DIAG_MODE 0x0002 /* Diagnostic-sampling flag */
6161 #define PERF_CPUM_SF_MODE_MASK (PERF_CPUM_SF_BASIC_MODE| \
6262 PERF_CPUM_SF_DIAG_MODE)
63−#define PERF_CPUM_SF_FULL_BLOCKS 0x0004 /* Process full SDBs only */
6463 #define PERF_CPUM_SF_FREQ_MODE 0x0008 /* Sampling with frequency */
6564
6665 #define REG_NONE 0
@@ -71,7 +70,6 @@ struct perf_sf_sde_regs { · 4 unmodified lines
7170 #define SAMPL_RATE(hwc) ((hwc)->event_base)
7271 #define SAMPL_FLAGS(hwc) ((hwc)->config_base)
7372 #define SAMPL_DIAG_MODE(hwc) (SAMPL_FLAGS(hwc) & PERF_CPUM_SF_DIAG_MODE)
74−#define SDB_FULL_BLOCKS(hwc) (SAMPL_FLAGS(hwc) & PERF_CPUM_SF_FULL_BLOCKS)
7573 #define SAMPLE_FREQ_MODE(hwc) (SAMPL_FLAGS(hwc) & PERF_CPUM_SF_FREQ_MODE)
7674
7775 #define perf_arch_fetch_caller_regs(regs, __ip) do { \
arch/s390/include/asm/pgtable.h+1−1
@@ -34,7 +34,7 @@ enum { · 33 unmodified lines
3434 PG_DIRECT_MAP_MAX
3535 };
3636
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]);
3838
3939 static inline void update_page_count(int level, long count)
4040 {
arch/s390/include/asm/physmem_info.h+171−0
@@ -0,0 +1,171 @@
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
arch/s390/include/asm/processor.h+42−4
@@ -99,7 +99,6 @@ void cpu_detect_mhz_feature(void); · 98 unmodified lines
9999
100100 extern const struct seq_operations cpuinfo_op;
101101 extern void execve_tail(void);
102−extern void __bpon(void);
103102 unsigned long vdso_size(void);
104103
105104 /*
@@ -119,6 +118,41 @@ unsigned long vdso_size(void); · 13 unmodified lines
119118
120119 #define HAVE_ARCH_PICK_MMAP_LAYOUT
121120
121+#define __stackleak_poison __stackleak_poison
122+static __always_inline void __stackleak_poison(unsigned long erase_low,
123+ unsigned long erase_high,
124+ unsigned long poison)
125+{
126+ unsigned long tmp, count;
127+
128+ count = erase_high - erase_low;
129+ if (!count)
130+ return;
131+ asm volatile(
132+ " cghi %[count],8\n"
133+ " je 2f\n"
134+ " aghi %[count],-(8+1)\n"
135+ " srlg %[tmp],%[count],8\n"
136+ " ltgr %[tmp],%[tmp]\n"
137+ " jz 1f\n"
138+ "0: stg %[poison],0(%[addr])\n"
139+ " mvc 8(256-8,%[addr]),0(%[addr])\n"
140+ " la %[addr],256(%[addr])\n"
141+ " brctg %[tmp],0b\n"
142+ "1: stg %[poison],0(%[addr])\n"
143+ " larl %[tmp],3f\n"
144+ " ex %[count],0(%[tmp])\n"
145+ " j 4f\n"
146+ "2: stg %[poison],0(%[addr])\n"
147+ " j 4f\n"
148+ "3: mvc 8(1,%[addr]),0(%[addr])\n"
149+ "4:\n"
150+ : [addr] "+&a" (erase_low), [count] "+&d" (count), [tmp] "=&a" (tmp)
151+ : [poison] "d" (poison)
152+ : "memory", "cc"
153+ );
154+}
155+
122156 /*
123157 * Thread structure
124158 */
@@ -227,6 +261,13 @@ static __always_inline unsigned long __current_stack_pointer(void) · 102 unmodified lines
227261 return sp;
228262 }
229263
264+static __always_inline bool on_thread_stack(void)
265+{
266+ unsigned long ksp = S390_lowcore.kernel_stack;
267+
268+ return !((ksp ^ current_stack_pointer) & ~(THREAD_SIZE - 1));
269+}
270+
230271 static __always_inline unsigned short stap(void)
231272 {
232273 unsigned short cpu_address;
@@ -329,9 +370,6 @@ static __always_inline void __noreturn disabled_wait(void) · 96 unmodified lines
329370
330371 #define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
331372
332−extern int s390_isolate_bp(void);
333−extern int s390_isolate_bp_guest(void);
334−
335373 static __always_inline bool regs_irqs_disabled(struct pt_regs *regs)
336374 {
337375 return arch_irqs_disabled_flags(regs->psw.mask);
arch/s390/include/asm/set_memory.h+31−5
@@ -6,11 +6,23 @@ · 5 unmodified lines
66
77 extern struct mutex cpa_mutex;
88
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)
1426
1527 int __set_memory(unsigned long addr, int numpages, unsigned long flags);
1628
@@ -34,9 +46,23 @@ static inline int set_memory_x(unsigned long addr, int numpages) · 17 unmodified lines
3446 return __set_memory(addr, numpages, SET_MEMORY_X);
3547 }
3648
49+#define set_memory_rox set_memory_rox
50+static inline int set_memory_rox(unsigned long addr, int numpages)
51+{
52+ return __set_memory(addr, numpages, SET_MEMORY_RO | SET_MEMORY_X);
53+}
54+
55+static inline int set_memory_rwnx(unsigned long addr, int numpages)
56+{
57+ return __set_memory(addr, numpages, SET_MEMORY_RW | SET_MEMORY_NX);
58+}
59+
3760 static inline int set_memory_4k(unsigned long addr, int numpages)
3861 {
3962 return __set_memory(addr, numpages, SET_MEMORY_4K);
4063 }
4164
65+int set_direct_map_invalid_noflush(struct page *page);
66+int set_direct_map_default_noflush(struct page *page);
67+
4268 #endif
arch/s390/include/asm/setup.h+8−12
@@ -74,10 +74,6 @@ extern unsigned int zlib_dfltcc_support; · 73 unmodified lines
7474
7575 extern int noexec_disabled;
7676 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;
8177
8278 /* The Write Back bit position in the physaddr is given by the SLPC PCI */
8379 extern unsigned long mio_wb_bit_mask;
@@ -150,13 +146,13 @@ static inline unsigned long kaslr_offset(void) · 66 unmodified lines
150146 return __kaslr_offset;
151147 }
152148
153−extern int is_full_image;
154−
155−struct initrd_data {
156− unsigned long start;
157− unsigned long size;
158−};
159−extern struct initrd_data initrd_data;
149+extern int __kaslr_enabled;
150+static inline int kaslr_enabled(void)
151+{
152+ if (IS_ENABLED(CONFIG_RANDOMIZE_BASE))
153+ return __kaslr_enabled;
154+ return 0;
155+}
160156
161157 struct oldmem_data {
162158 unsigned long start;
@@ -164,7 +160,7 @@ struct oldmem_data { · 1 unmodified line
164160 };
165161 extern struct oldmem_data oldmem_data;
166162
167−static inline u32 gen_lpswe(unsigned long addr)
163+static __always_inline u32 gen_lpswe(unsigned long addr)
168164 {
169165 BUILD_BUG_ON(addr > 0xfff);
170166 return 0xb2b20000 | addr;
arch/s390/include/asm/stacktrace.h+44−8
@@ -189,17 +189,53 @@ static __always_inline unsigned long get_stack_pointer(struct task_struct *task, · 188 unmodified lines
189189 (rettype)r2; \
190190 })
191191
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, ...) \
193211 ({ \
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; \
195218 \
219+ CALL_TYPECHECK_##nr(__VA_ARGS__); \
220+ psw_enter.mask = PSW_KERNEL_BITS & ~PSW_MASK_DAT; \
221+ psw_enter.addr = (unsigned long)__fn; \
196222 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; \
203239 })
204240
205241 #endif /* _ASM_S390_STACKTRACE_H */
arch/s390/include/asm/string.h+3−12
@@ -55,18 +55,6 @@ char *strstr(const char *s1, const char *s2); · 54 unmodified lines
5555
5656 #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
5757
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)
7058 #define strlen(s) __strlen(s)
7159
7260 #define __no_sanitize_prefix_strfunc(x) __##x
@@ -79,6 +67,9 @@ extern void *__memmove(void *dest, const void *src, size_t n); · 6 unmodified lines
7967 #define __no_sanitize_prefix_strfunc(x) x
8068 #endif /* defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) */
8169
70+void *__memcpy(void *dest, const void *src, size_t n);
71+void *__memset(void *s, int c, size_t n);
72+void *__memmove(void *dest, const void *src, size_t n);
8273 void *__memset16(uint16_t *s, uint16_t v, size_t count);
8374 void *__memset32(uint32_t *s, uint32_t v, size_t count);
8475 void *__memset64(uint64_t *s, uint64_t v, size_t count);
arch/s390/include/asm/thread_info.h+5−5
@@ -9,6 +9,9 @@ · 8 unmodified lines
99 #define _ASM_THREAD_INFO_H
1010
1111 #include <linux/bits.h>
12+#ifndef ASM_OFFSETS_C
13+#include <asm/asm-offsets.h>
14+#endif
1215
1316 /*
1417 * General size of kernel stacks
@@ -21,13 +24,12 @@ · 6 unmodified lines
2124 #define BOOT_STACK_SIZE (PAGE_SIZE << 2)
2225 #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
2326
27+#define STACK_INIT_OFFSET (THREAD_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE)
28+
2429 #ifndef __ASSEMBLY__
2530 #include <asm/lowcore.h>
2631 #include <asm/page.h>
2732
28−#define STACK_INIT_OFFSET \
29− (THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs))
30−
3133 /*
3234 * low level task data that entry.S needs immediate access to
3335 * - this struct should fit entirely inside of one cache line
@@ -70,7 +72,6 @@ void arch_setup_new_exec(void); · 36 unmodified lines
7072 #define TIF_PATCH_PENDING 5 /* pending live patching update */
7173 #define TIF_PGSTE 6 /* New mm's will use 4K page tables */
7274 #define TIF_NOTIFY_SIGNAL 7 /* signal notifications exist */
73−#define TIF_ISOLATE_BP 8 /* Run process with isolated BP */
7475 #define TIF_ISOLATE_BP_GUEST 9 /* Run KVM guests with isolated BP */
7576 #define TIF_PER_TRAP 10 /* Need to handle PER trap on exit to usermode */
7677
@@ -94,7 +95,6 @@ void arch_setup_new_exec(void); · 17 unmodified lines
9495 #define _TIF_UPROBE BIT(TIF_UPROBE)
9596 #define _TIF_GUARDED_STORAGE BIT(TIF_GUARDED_STORAGE)
9697 #define _TIF_PATCH_PENDING BIT(TIF_PATCH_PENDING)
97−#define _TIF_ISOLATE_BP BIT(TIF_ISOLATE_BP)
9898 #define _TIF_ISOLATE_BP_GUEST BIT(TIF_ISOLATE_BP_GUEST)
9999 #define _TIF_PER_TRAP BIT(TIF_PER_TRAP)
100100
arch/s390/kernel/debug.c+2−12
@@ -60,7 +60,7 @@ typedef struct { · 59 unmodified lines
6060 * except of floats, and long long (32 bit)
6161 *
6262 */
63− long args[0];
63+ long args[];
6464 } debug_sprintf_entry_t;
6565
6666 /* internal function prototyes */
@@ -981,16 +981,6 @@ static struct ctl_table s390dbf_table[] = { · 914 unmodified lines
981981 { }
982982 };
983983
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−
994984 static struct ctl_table_header *s390dbf_sysctl_header;
995985
996986 /**
@@ -1574,7 +1564,7 @@ out: · 577 unmodified lines
15741564 */
15751565 static int __init debug_init(void)
15761566 {
1577− s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table);
1567+ s390dbf_sysctl_header = register_sysctl("s390dbf", s390dbf_table);
15781568 mutex_lock(&debug_mutex);
15791569 debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT, NULL);
15801570 initialized = 1;
arch/s390/kernel/dumpstack.c+21−25
@@ -41,60 +41,50 @@ const char *stack_type_name(enum stack_type type) · 40 unmodified lines
4141 EXPORT_SYMBOL_GPL(stack_type_name);
4242
4343 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)
4645 {
47− if (sp < low || sp >= high)
46+ if (sp < stack || sp >= stack + THREAD_SIZE)
4847 return false;
4948 info->type = type;
50− info->begin = low;
51− info->end = high;
49+ info->begin = stack;
50+ info->end = stack + THREAD_SIZE;
5251 return true;
5352 }
5453
5554 static bool in_task_stack(unsigned long sp, struct task_struct *task,
5655 struct stack_info *info)
5756 {
58− unsigned long stack;
57+ unsigned long stack = (unsigned long)task_stack_page(task);
5958
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);
6260 }
6361
6462 static bool in_irq_stack(unsigned long sp, struct stack_info *info)
6563 {
66− unsigned long frame_size, top;
64+ unsigned long stack = S390_lowcore.async_stack - STACK_INIT_OFFSET;
6765
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);
7167 }
7268
7369 static bool in_nodat_stack(unsigned long sp, struct stack_info *info)
7470 {
75− unsigned long frame_size, top;
71+ unsigned long stack = S390_lowcore.nodat_stack - STACK_INIT_OFFSET;
7672
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);
8074 }
8175
8276 static bool in_mcck_stack(unsigned long sp, struct stack_info *info)
8377 {
84− unsigned long frame_size, top;
78+ unsigned long stack = S390_lowcore.mcck_stack - STACK_INIT_OFFSET;
8579
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);
8981 }
9082
9183 static bool in_restart_stack(unsigned long sp, struct stack_info *info)
9284 {
93− unsigned long frame_size, top;
85+ unsigned long stack = S390_lowcore.restart_stack - STACK_INIT_OFFSET;
9486
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);
9888 }
9989
10090 int get_stack_info(unsigned long sp, struct task_struct *task,
@@ -152,7 +142,13 @@ void show_stack(struct task_struct *task, unsigned long *stack, · 51 unmodified lines
152142 static void show_last_breaking_event(struct pt_regs *regs)
153143 {
154144 printk("Last Breaking-Event-Address:\n");
155− printk(" [<%016lx>] %pSR\n", regs->last_break, (void *)regs->last_break);
145+ printk(" [<%016lx>] ", regs->last_break);
146+ if (user_mode(regs)) {
147+ print_vma_addr(KERN_CONT, regs->last_break);
148+ pr_cont("\n");
149+ } else {
150+ pr_cont("%pSR\n", (void *)regs->last_break);
151+ }
156152 }
157153
158154 void show_registers(struct pt_regs *regs)
arch/s390/kernel/early.c+9−14
@@ -34,8 +34,6 @@ · 33 unmodified lines
3434 #include <asm/switch_to.h>
3535 #include "entry.h"
3636
37−int __bootdata(is_full_image);
38−
3937 #define decompressor_handled_param(param) \
4038 static int __init ignore_decompressor_param_##param(char *s) \
4139 { \
@@ -53,6 +51,14 @@ decompressor_handled_param(nokaslr); · 11 unmodified lines
5351 decompressor_handled_param(prot_virt);
5452 #endif
5553
54+static void __init kasan_early_init(void)
55+{
56+#ifdef CONFIG_KASAN
57+ init_task.kasan_depth = 0;
58+ sclp_early_printk("KernelAddressSanitizer initialized\n");
59+#endif
60+}
61+
5662 static void __init reset_tod_clock(void)
5763 {
5864 union tod_clock clk;
@@ -288,17 +294,6 @@ static void __init setup_boot_command_line(void) · 229 unmodified lines
288294 strscpy(boot_command_line, early_command_line, COMMAND_LINE_SIZE);
289295 }
290296
291−static void __init check_image_bootable(void)
292−{
293− if (is_full_image)
294− return;
295−
296− sclp_early_printk("Linux kernel boot failure: An attempt to boot a vmlinux ELF image failed.\n");
297− sclp_early_printk("This image does not contain all parts necessary for starting up. Use\n");
298− sclp_early_printk("bzImage or arch/s390/boot/compressed/vmlinux instead.\n");
299− disabled_wait();
300−}
301−
302297 static void __init sort_amode31_extable(void)
303298 {
304299 sort_extable(__start_amode31_ex_table, __stop_amode31_ex_table);
@@ -306,8 +301,8 @@ static void __init sort_amode31_extable(void) · 1 unmodified line
306301
307302 void __init startup_init(void)
308303 {
304+ kasan_early_init();
309305 reset_tod_clock();
310− check_image_bootable();
311306 time_early_init();
312307 init_kernel_storage_key();
313308 lockdep_off();
arch/s390/kernel/earlypgm.S+2−2
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 #include <linux/linkage.h>
88 #include <asm/asm-offsets.h>
99
10−ENTRY(early_pgm_check_handler)
10+SYM_CODE_START(early_pgm_check_handler)
1111 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
1212 aghi %r15,-(STACK_FRAME_OVERHEAD+__PT_SIZE)
1313 la %r11,STACK_FRAME_OVERHEAD(%r15)
@@ -20,4 +20,4 @@ ENTRY(early_pgm_check_handler) · 6 unmodified lines
2020 mvc __LC_RETURN_PSW(16),STACK_FRAME_OVERHEAD+__PT_PSW(%r15)
2121 lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
2222 lpswe __LC_RETURN_PSW
23−ENDPROC(early_pgm_check_handler)
23+SYM_CODE_END(early_pgm_check_handler)
arch/s390/kernel/entry.S+70−82
@@ -29,10 +29,6 @@ · 28 unmodified lines
2929 #include <asm/export.h>
3030 #include <asm/nospec-insn.h>
3131
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−
3632 _LPP_OFFSET = __LC_LPP
3733
3834 .macro STBEAR address
@@ -53,7 +49,7 @@ _LPP_OFFSET = __LC_LPP · 14 unmodified lines
5349
5450 .macro CHECK_STACK savearea
5551 #ifdef CONFIG_CHECK_STACK
56− tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
52+ tml %r15,THREAD_SIZE - CONFIG_STACK_GUARD
5753 lghi %r14,\savearea
5854 jz stack_overflow
5955 #endif
@@ -62,8 +58,8 @@ _LPP_OFFSET = __LC_LPP · 2 unmodified lines
6258 .macro CHECK_VMAP_STACK savearea,oklabel
6359 #ifdef CONFIG_VMAP_STACK
6460 lgr %r14,%r15
65− nill %r14,0x10000 - STACK_SIZE
66− oill %r14,STACK_INIT
61+ nill %r14,0x10000 - THREAD_SIZE
62+ oill %r14,STACK_INIT_OFFSET
6763 clg %r14,__LC_KERNEL_STACK
6864 je \oklabel
6965 clg %r14,__LC_ASYNC_STACK
@@ -154,26 +150,26 @@ _LPP_OFFSET = __LC_LPP · 84 unmodified lines
154150 .endm
155151 #endif
156152
153+ .macro STACKLEAK_ERASE
154+#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
155+ brasl %r14,stackleak_erase_on_task_stack
156+#endif
157+ .endm
158+
157159 GEN_BR_THUNK %r14
158160
159161 .section .kprobes.text, "ax"
160162 .Ldummy:
161163 /*
162− * This nop exists only in order to avoid that __bpon starts at
163− * the beginning of the kprobes text section. In that case we would
164− * have several symbols at the same address. E.g. objdump would take
165− * an arbitrary symbol name when disassembling this code.
166− * With the added nop in between the __bpon symbol is unique
167− * again.
164+ * The following nop exists only in order to avoid that the next
165+ * symbol starts at the beginning of the kprobes text section.
166+ * In that case there would be several symbols at the same address.
167+ * E.g. objdump would take an arbitrary symbol when disassembling
168+ * the code.
169+ * With the added nop in between this cannot happen.
168170 */
169171 nop 0
170172
171−ENTRY(__bpon)
172− .globl __bpon
173− BPON
174− BR_EX %r14
175−ENDPROC(__bpon)
176−
177173 /*
178174 * Scheduler resume function, called by switch_to
179175 * gpr2 = (task_struct *) prev
@@ -181,11 +177,11 @@ ENDPROC(__bpon) · 1 unmodified line
181177 * Returns:
182178 * gpr2 = prev
183179 */
184−ENTRY(__switch_to)
180+SYM_FUNC_START(__switch_to)
185181 stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
186182 lghi %r4,__TASK_stack
187183 lghi %r1,__TASK_thread
188− llill %r5,STACK_INIT
184+ llill %r5,STACK_INIT_OFFSET
189185 stg %r15,__THREAD_ksp(%r1,%r2) # store kernel stack of prev
190186 lg %r15,0(%r4,%r3) # start of kernel stack of next
191187 agr %r15,%r5 # end of kernel stack of next
@@ -197,7 +193,7 @@ ENTRY(__switch_to) · 5 unmodified lines
197193 lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
198194 ALTERNATIVE "nop", "lpp _LPP_OFFSET", 40
199195 BR_EX %r14
200−ENDPROC(__switch_to)
196+SYM_FUNC_END(__switch_to)
201197
202198 #if IS_ENABLED(CONFIG_KVM)
203199 /*
@@ -206,7 +202,7 @@ ENDPROC(__switch_to) · 2 unmodified lines
206202 * %r3 pointer to sie control block virt
207203 * %r4 guest register save area
208204 */
209−ENTRY(__sie64a)
205+SYM_FUNC_START(__sie64a)
210206 stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
211207 lg %r12,__LC_CURRENT
212208 stg %r2,__SF_SIE_CONTROL_PHYS(%r15) # save sie block physical..
@@ -227,7 +223,7 @@ ENTRY(__sie64a) · 14 unmodified lines
227223 TSTMSK __LC_CPU_FLAGS,_CIF_FPU
228224 jo .Lsie_skip # exit if fp/vx regs changed
229225 lg %r14,__SF_SIE_CONTROL_PHYS(%r15) # get sie block phys addr
230− BPEXIT __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
226+ BPEXIT __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
231227 .Lsie_entry:
232228 sie 0(%r14)
233229 # Let the next instruction be NOP to avoid triggering a machine check
@@ -235,7 +231,7 @@ ENTRY(__sie64a) · 1 unmodified line
235231 nopr 7
236232 .Lsie_leave:
237233 BPOFF
238− BPENTER __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
234+ BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
239235 .Lsie_skip:
240236 lg %r14,__SF_SIE_CONTROL(%r15) # get control block pointer
241237 ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
@@ -252,8 +248,7 @@ ENTRY(__sie64a) · 10 unmodified lines
252248 nopr 7
253249 .Lrewind_pad2:
254250 nopr 7
255− .globl sie_exit
256−sie_exit:
251+SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL)
257252 lg %r14,__SF_SIE_SAVEAREA(%r15) # load guest register save area
258253 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
259254 xgr %r0,%r0 # clear guest registers to
@@ -273,7 +268,7 @@ sie_exit: · 13 unmodified lines
273268 EX_TABLE(.Lrewind_pad4,.Lsie_fault)
274269 EX_TABLE(.Lrewind_pad2,.Lsie_fault)
275270 EX_TABLE(sie_exit,.Lsie_fault)
276−ENDPROC(__sie64a)
271+SYM_FUNC_END(__sie64a)
277272 EXPORT_SYMBOL(__sie64a)
278273 EXPORT_SYMBOL(sie_exit)
279274 #endif
@@ -283,7 +278,7 @@ EXPORT_SYMBOL(sie_exit) · 3 unmodified lines
283278 * are entered with interrupts disabled.
284279 */
285280
286−ENTRY(system_call)
281+SYM_CODE_START(system_call)
287282 stpt __LC_SYS_ENTER_TIMER
288283 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
289284 BPOFF
@@ -291,11 +286,9 @@ ENTRY(system_call) · 1 unmodified line
291286 .Lsysc_per:
292287 STBEAR __LC_LAST_BREAK
293288 lctlg %c1,%c1,__LC_KERNEL_ASCE
294− lg %r12,__LC_CURRENT
295289 lg %r15,__LC_KERNEL_STACK
296290 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
297291 stmg %r0,%r7,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
298− BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
299292 # clear user controlled register to prevent speculative use
300293 xgr %r0,%r0
301294 xgr %r1,%r1
@@ -312,39 +305,40 @@ ENTRY(system_call) · 10 unmodified lines
312305 MBEAR %r2
313306 lgr %r3,%r14
314307 brasl %r14,__do_syscall
308+ STACKLEAK_ERASE
315309 lctlg %c1,%c1,__LC_USER_ASCE
316310 mvc __LC_RETURN_PSW(16),STACK_FRAME_OVERHEAD+__PT_PSW(%r15)
317− BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
311+ BPON
318312 LBEAR STACK_FRAME_OVERHEAD+__PT_LAST_BREAK(%r15)
319313 lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
320314 stpt __LC_EXIT_TIMER
321315 LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE
322−ENDPROC(system_call)
316+SYM_CODE_END(system_call)
323317
324318 #
325319 # a new process exits the kernel with ret_from_fork
326320 #
327−ENTRY(ret_from_fork)
321+SYM_CODE_START(ret_from_fork)
328322 lgr %r3,%r11
329323 brasl %r14,__ret_from_fork
324+ STACKLEAK_ERASE
330325 lctlg %c1,%c1,__LC_USER_ASCE
331326 mvc __LC_RETURN_PSW(16),STACK_FRAME_OVERHEAD+__PT_PSW(%r15)
332− BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
327+ BPON
333328 LBEAR STACK_FRAME_OVERHEAD+__PT_LAST_BREAK(%r15)
334329 lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
335330 stpt __LC_EXIT_TIMER
336331 LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE
337−ENDPROC(ret_from_fork)
332+SYM_CODE_END(ret_from_fork)
338333
339334 /*
340335 * Program check handler routine
341336 */
342337
343−ENTRY(pgm_check_handler)
338+SYM_CODE_START(pgm_check_handler)
344339 stpt __LC_SYS_ENTER_TIMER
345340 BPOFF
346341 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
347− lg %r12,__LC_CURRENT
348342 lghi %r10,0
349343 lmg %r8,%r9,__LC_PGM_OLD_PSW
350344 tmhh %r8,0x0001 # coming from user space?
@@ -355,6 +349,7 @@ ENTRY(pgm_check_handler) · 4 unmodified lines
355349 #if IS_ENABLED(CONFIG_KVM)
356350 # cleanup critical section for program checks in __sie64a
357351 OUTSIDE %r9,.Lsie_gmap,.Lsie_done,1f
352+ BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
358353 SIEEXIT
359354 lghi %r10,_PIF_GUEST_FAULT
360355 #endif
@@ -366,8 +361,7 @@ ENTRY(pgm_check_handler) · 5 unmodified lines
366361 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
367362 # CHECK_VMAP_STACK branches to stack_overflow or 4f
368363 CHECK_VMAP_STACK __LC_SAVE_AREA_SYNC,4f
369−3: BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
370− lg %r15,__LC_KERNEL_STACK
364+3: lg %r15,__LC_KERNEL_STACK
371365 4: la %r11,STACK_FRAME_OVERHEAD(%r15)
372366 stg %r10,__PT_FLAGS(%r11)
373367 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
@@ -388,8 +382,9 @@ ENTRY(pgm_check_handler) · 14 unmodified lines
388382 brasl %r14,__do_pgm_check
389383 tmhh %r8,0x0001 # returning to user space?
390384 jno .Lpgm_exit_kernel
385+ STACKLEAK_ERASE
391386 lctlg %c1,%c1,__LC_USER_ASCE
392− BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
387+ BPON
393388 stpt __LC_EXIT_TIMER
394389 .Lpgm_exit_kernel:
395390 mvc __LC_RETURN_PSW(16),STACK_FRAME_OVERHEAD+__PT_PSW(%r15)
@@ -407,32 +402,30 @@ ENTRY(pgm_check_handler) · 11 unmodified lines
407402 lghi %r14,1
408403 LBEAR __LC_PGM_LAST_BREAK
409404 LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE # branch to .Lsysc_per
410−ENDPROC(pgm_check_handler)
405+SYM_CODE_END(pgm_check_handler)
411406
412407 /*
413408 * Interrupt handler macro used for external and IO interrupts.
414409 */
415410 .macro INT_HANDLER name,lc_old_psw,handler
416−ENTRY(\name)
411+SYM_CODE_START(\name)
417412 stckf __LC_INT_CLOCK
418413 stpt __LC_SYS_ENTER_TIMER
419414 STBEAR __LC_LAST_BREAK
420415 BPOFF
421416 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
422− lg %r12,__LC_CURRENT
423417 lmg %r8,%r9,\lc_old_psw
424418 tmhh %r8,0x0001 # interrupting from user ?
425419 jnz 1f
426420 #if IS_ENABLED(CONFIG_KVM)
427421 OUTSIDE %r9,.Lsie_gmap,.Lsie_done,0f
428− BPENTER __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
422+ BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
429423 SIEEXIT
430424 #endif
431425 0: CHECK_STACK __LC_SAVE_AREA_ASYNC
432426 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
433427 j 2f
434−1: BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
435− lctlg %c1,%c1,__LC_KERNEL_ASCE
428+1: lctlg %c1,%c1,__LC_KERNEL_ASCE
436429 lg %r15,__LC_KERNEL_STACK
437430 2: xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
438431 la %r11,STACK_FRAME_OVERHEAD(%r15)
@@ -455,13 +448,14 @@ ENTRY(\name) · 16 unmodified lines
455448 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
456449 tmhh %r8,0x0001 # returning to user ?
457450 jno 2f
451+ STACKLEAK_ERASE
458452 lctlg %c1,%c1,__LC_USER_ASCE
459− BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
453+ BPON
460454 stpt __LC_EXIT_TIMER
461455 2: LBEAR __PT_LAST_BREAK(%r11)
462456 lmg %r0,%r15,__PT_R0(%r11)
463457 LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE
464−ENDPROC(\name)
458+SYM_CODE_END(\name)
465459 .endm
466460
467461 INT_HANDLER ext_int_handler,__LC_EXT_OLD_PSW,do_ext_irq
@@ -470,7 +464,7 @@ INT_HANDLER io_int_handler,__LC_IO_OLD_PSW,do_io_irq · 2 unmodified lines
470464 /*
471465 * Load idle PSW.
472466 */
473−ENTRY(psw_idle)
467+SYM_FUNC_START(psw_idle)
474468 stg %r14,(__SF_GPRS+8*8)(%r15)
475469 stg %r3,__SF_EMPTY(%r15)
476470 larl %r1,psw_idle_exit
@@ -486,29 +480,26 @@ ENTRY(psw_idle) · 9 unmodified lines
486480 stckf __CLOCK_IDLE_ENTER(%r2)
487481 stpt __TIMER_IDLE_ENTER(%r2)
488482 lpswe __SF_EMPTY(%r15)
489−.globl psw_idle_exit
490−psw_idle_exit:
483+SYM_INNER_LABEL(psw_idle_exit, SYM_L_GLOBAL)
491484 BR_EX %r14
492−ENDPROC(psw_idle)
485+SYM_FUNC_END(psw_idle)
493486
494487 /*
495488 * Machine check handler routines
496489 */
497−ENTRY(mcck_int_handler)
490+SYM_CODE_START(mcck_int_handler)
498491 stckf __LC_MCCK_CLOCK
499492 BPOFF
500493 la %r1,4095 # validate r1
501494 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # validate cpu timer
502495 LBEAR __LC_LAST_BREAK_SAVE_AREA-4095(%r1) # validate bear
503− lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# validate gprs
504− lg %r12,__LC_CURRENT
496+ lmg %r0,%r15,__LC_GPREGS_SAVE_AREA # validate gprs
505497 lmg %r8,%r9,__LC_MCK_OLD_PSW
506498 TSTMSK __LC_MCCK_CODE,MCCK_CODE_SYSTEM_DAMAGE
507499 jo .Lmcck_panic # yes -> rest of mcck code invalid
508500 TSTMSK __LC_MCCK_CODE,MCCK_CODE_CR_VALID
509501 jno .Lmcck_panic # control registers invalid -> panic
510− la %r14,4095
511− lctlg %c0,%c15,__LC_CREGS_SAVE_AREA-4095(%r14) # validate ctl regs
502+ lctlg %c0,%c15,__LC_CREGS_SAVE_AREA # validate ctl regs
512503 ptlb
513504 lghi %r14,__LC_CPU_TIMER_SAVE_AREA
514505 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
@@ -530,16 +521,13 @@ ENTRY(mcck_int_handler) · 15 unmodified lines
530521 TSTMSK __LC_MCCK_CODE,MCCK_CODE_PSW_IA_VALID
531522 jno .Lmcck_panic
532523 #if IS_ENABLED(CONFIG_KVM)
533− OUTSIDE %r9,.Lsie_gmap,.Lsie_done,.Lmcck_stack
524+ OUTSIDE %r9,.Lsie_gmap,.Lsie_done,.Lmcck_user
534525 OUTSIDE %r9,.Lsie_entry,.Lsie_leave,4f
535526 oi __LC_CPU_FLAGS+7, _CIF_MCCK_GUEST
536−4: BPENTER __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
527+4: BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
537528 SIEEXIT
538− j .Lmcck_stack
539529 #endif
540530 .Lmcck_user:
541− BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
542−.Lmcck_stack:
543531 lg %r15,__LC_MCCK_STACK
544532 la %r11,STACK_FRAME_OVERHEAD(%r15)
545533 stctg %c1,%c1,__PT_CR1(%r11)
@@ -567,7 +555,7 @@ ENTRY(mcck_int_handler) · 21 unmodified lines
567555 mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
568556 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
569557 jno 0f
570− BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
558+ BPON
571559 stpt __LC_EXIT_TIMER
572560 0: ALTERNATIVE "nop", __stringify(lghi %r12,__LC_LAST_BREAK_SAVE_AREA),193
573561 LBEAR 0(%r12)
@@ -583,10 +571,10 @@ ENTRY(mcck_int_handler) · 9 unmodified lines
583571 */
584572 lhi %r5,0
585573 lhi %r6,1
586− larl %r7,.Lstop_lock
574+ larl %r7,stop_lock
587575 cs %r5,%r6,0(%r7) # single CPU-stopper only
588576 jnz 4f
589− larl %r7,.Lthis_cpu
577+ larl %r7,this_cpu
590578 stap 0(%r7) # this CPU address
591579 lh %r4,0(%r7)
592580 nilh %r4,0
@@ -602,16 +590,15 @@ ENTRY(mcck_int_handler) · 9 unmodified lines
602590 3: sigp %r1,%r4,SIGP_STOP # stop this CPU
603591 brc SIGP_CC_BUSY,3b
604592 4: j 4b
605−ENDPROC(mcck_int_handler)
593+SYM_CODE_END(mcck_int_handler)
606594
607−ENTRY(restart_int_handler)
595+SYM_CODE_START(restart_int_handler)
608596 ALTERNATIVE "nop", "lpp _LPP_OFFSET", 40
609597 stg %r15,__LC_SAVE_AREA_RESTART
610598 TSTMSK __LC_RESTART_FLAGS,RESTART_FLAG_CTLREGS,4
611599 jz 0f
612− la %r15,4095
613− lctlg %c0,%c15,__LC_CREGS_SAVE_AREA-4095(%r15)
614−0: larl %r15,.Lstosm_tmp
600+ lctlg %c0,%c15,__LC_CREGS_SAVE_AREA
601+0: larl %r15,stosm_tmp
615602 stosm 0(%r15),0x04 # turn dat on, keep irqs off
616603 lg %r15,__LC_RESTART_STACK
617604 xc STACK_FRAME_OVERHEAD(__PT_SIZE,%r15),STACK_FRAME_OVERHEAD(%r15)
@@ -632,7 +619,7 @@ ENTRY(restart_int_handler) · 14 unmodified lines
632619 2: sigp %r4,%r3,SIGP_STOP # sigp stop to current cpu
633620 brc 2,2b
634621 3: j 3b
635−ENDPROC(restart_int_handler)
622+SYM_CODE_END(restart_int_handler)
636623
637624 .section .kprobes.text, "ax"
638625
@@ -642,7 +629,7 @@ ENDPROC(restart_int_handler) · 3 unmodified lines
642629 * No need to properly save the registers, we are going to panic anyway.
643630 * Setup a pt_regs so that show_trace can provide a good call trace.
644631 */
645−ENTRY(stack_overflow)
632+SYM_CODE_START(stack_overflow)
646633 lg %r15,__LC_NODAT_STACK # change to panic stack
647634 la %r11,STACK_FRAME_OVERHEAD(%r15)
648635 stmg %r0,%r7,__PT_R0(%r11)
@@ -652,26 +639,27 @@ ENTRY(stack_overflow) · 3 unmodified lines
652639 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
653640 lgr %r2,%r11 # pass pointer to pt_regs
654641 jg kernel_stack_overflow
655−ENDPROC(stack_overflow)
642+SYM_CODE_END(stack_overflow)
656643 #endif
657644
658645 .section .data, "aw"
659− .align 4
660−.Lstop_lock: .long 0
661−.Lthis_cpu: .short 0
662−.Lstosm_tmp: .byte 0
646+ .balign 4
647+SYM_DATA_LOCAL(stop_lock, .long 0)
648+SYM_DATA_LOCAL(this_cpu, .short 0)
649+SYM_DATA_LOCAL(stosm_tmp, .byte 0)
650+
663651 .section .rodata, "a"
664652 #define SYSCALL(esame,emu) .quad __s390x_ ## esame
665− .globl sys_call_table
666−sys_call_table:
653+SYM_DATA_START(sys_call_table)
667654 #include "asm/syscall_table.h"
655+SYM_DATA_END(sys_call_table)
668656 #undef SYSCALL
669657
670658 #ifdef CONFIG_COMPAT
671659
672660 #define SYSCALL(esame,emu) .quad __s390_ ## emu
673− .globl sys_call_table_emu
674−sys_call_table_emu:
661+SYM_DATA_START(sys_call_table_emu)
675662 #include "asm/syscall_table.h"
663+SYM_DATA_END(sys_call_table_emu)
676664 #undef SYSCALL
677665 #endif
arch/s390/kernel/ftrace.c+1−21
@@ -49,26 +49,6 @@ struct ftrace_insn { · 48 unmodified lines
4949 s32 disp;
5050 } __packed;
5151
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−
7252 #ifdef CONFIG_MODULES
7353 static char *ftrace_plt;
7454 #endif /* CONFIG_MODULES */
@@ -246,7 +226,7 @@ static int __init ftrace_plt_init(void) · 171 unmodified lines
246226
247227 start = ftrace_shared_hotpatch_trampoline(&end);
248228 memcpy(ftrace_plt, start, end - start);
249− set_memory_ro((unsigned long)ftrace_plt, 1);
229+ set_memory_rox((unsigned long)ftrace_plt, 1);
250230 return 0;
251231 }
252232 device_initcall(ftrace_plt_init);
arch/s390/kernel/head64.S+6−8
@@ -16,7 +16,7 @@ · 15 unmodified lines
1616 #include <asm/ptrace.h>
1717
1818 __HEAD
19−ENTRY(startup_continue)
19+SYM_CODE_START(startup_continue)
2020 larl %r1,tod_clock_base
2121 mvc 0(16,%r1),__LC_BOOT_CLOCK
2222 #
@@ -24,19 +24,17 @@ ENTRY(startup_continue) · 1 unmodified line
2424 #
2525 larl %r14,init_task
2626 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
2829 brasl %r14,sclp_early_adjust_va # allow sclp_early_printk
29−#ifdef CONFIG_KASAN
30− brasl %r14,kasan_early_init
31−#endif
3230 brasl %r14,startup_init # s390 specific early init
3331 brasl %r14,start_kernel # common init code
3432 #
3533 # We returned from start_kernel ?!? PANIK
3634 #
3735 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)
3938
4039 .align 16
41−.LPG1:
42−.Ldw: .quad 0x0002000180000000,0x0000000000000000
40+SYM_DATA_LOCAL(dw_psw, .quad 0x0002000180000000,0x0000000000000000)
arch/s390/kernel/ipl.c+3−4
@@ -176,11 +176,11 @@ static bool reipl_fcp_clear; · 175 unmodified lines
176176 static bool reipl_ccw_clear;
177177 static bool reipl_eckd_clear;
178178
179−static inline int __diag308(unsigned long subcode, void *addr)
179+static inline int __diag308(unsigned long subcode, unsigned long addr)
180180 {
181181 union register_pair r1;
182182
183− r1.even = (unsigned long) addr;
183+ r1.even = addr;
184184 r1.odd = 0;
185185 asm volatile(
186186 " diag %[r1],%[subcode],0x308\n"
@@ -195,7 +195,7 @@ static inline int __diag308(unsigned long subcode, void *addr) · 8 unmodified lines
195195 int diag308(unsigned long subcode, void *addr)
196196 {
197197 diag_stat_inc(DIAG_STAT_X308);
198− return __diag308(subcode, addr);
198+ return __diag308(subcode, addr ? virt_to_phys(addr) : 0);
199199 }
200200 EXPORT_SYMBOL_GPL(diag308);
201201
@@ -649,7 +649,6 @@ static struct kset *ipl_kset; · 447 unmodified lines
649649
650650 static void __ipl_run(void *unused)
651651 {
652− __bpon();
653652 diag308(DIAG308_LOAD_CLEAR, NULL);
654653 }
655654
arch/s390/kernel/kprobes.c+1−1
@@ -41,7 +41,7 @@ void *alloc_insn_page(void) · 40 unmodified lines
4141 page = module_alloc(PAGE_SIZE);
4242 if (!page)
4343 return NULL;
44− __set_memory((unsigned long) page, 1, SET_MEMORY_RO | SET_MEMORY_X);
44+ set_memory_rox((unsigned long)page, 1);
4545 return page;
4646 }
4747
arch/s390/kernel/kprobes_insn_page.S+2−2
@@ -14,9 +14,9 @@ · 13 unmodified lines
1414 */
1515 .section .kprobes.text, "ax"
1616 .align 4096
17−ENTRY(kprobes_insn_page)
17+SYM_CODE_START(kprobes_insn_page)
1818 .rept 2048
1919 .word 0x07fe
2020 .endr
21−ENDPROC(kprobes_insn_page)
21+SYM_CODE_END(kprobes_insn_page)
2222 .previous
arch/s390/kernel/machine_kexec.c+22−34
@@ -29,8 +29,8 @@ · 28 unmodified lines
2929 #include <asm/nmi.h>
3030 #include <asm/sclp.h>
3131
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);
3434
3535 extern const unsigned char relocate_kernel[];
3636 extern const unsigned long long relocate_kernel_len;
@@ -41,11 +41,14 @@ extern const unsigned long long relocate_kernel_len; · 4 unmodified lines
4141 * Reset the system, copy boot CPU registers to absolute zero,
4242 * and jump to the kdump image
4343 */
44−static void __do_machine_kdump(void *image)
44+static void __do_machine_kdump(void *data)
4545 {
46− int (*start_kdump)(int);
46+ struct kimage *image = data;
47+ purgatory_t purgatory;
4748 unsigned long prefix;
4849
50+ purgatory = (purgatory_t)image->start;
51+
4952 /* store_status() saved the prefix register to lowcore */
5053 prefix = (unsigned long) S390_lowcore.prefixreg_save_area;
5154
@@ -58,13 +61,11 @@ static void __do_machine_kdump(void *image) · 6 unmodified lines
5861 * prefix register of this CPU to zero
5962 */
6063 memcpy(absolute_pointer(__LC_FPREGS_SAVE_AREA),
61− (void *)(prefix + __LC_FPREGS_SAVE_AREA), 512);
64+ phys_to_virt(prefix + __LC_FPREGS_SAVE_AREA), 512);
6265
63− __load_psw_mask(PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA);
64− start_kdump = (void *)((struct kimage *) image)->start;
65− start_kdump(1);
66+ call_nodat(1, int, purgatory, int, 1);
6667
67− /* Die if start_kdump returns */
68+ /* Die if kdump returns */
6869 disabled_wait();
6970 }
7071
@@ -111,18 +112,6 @@ static noinline void __machine_kdump(void *image) · 40 unmodified lines
111112 store_status(__do_machine_kdump, image);
112113 }
113114
114−static unsigned long do_start_kdump(unsigned long addr)
115−{
116− struct kimage *image = (struct kimage *) addr;
117− int (*start_kdump)(int) = (void *)image->start;
118− int rc;
119−
120− __arch_local_irq_stnsm(0xfb); /* disable DAT */
121− rc = start_kdump(0);
122− __arch_local_irq_stosm(0x04); /* enable DAT */
123− return rc;
124−}
125−
126115 #endif /* CONFIG_CRASH_DUMP */
127116
128117 /*
@@ -131,12 +120,10 @@ static unsigned long do_start_kdump(unsigned long addr) · 2 unmodified lines
131120 static bool kdump_csum_valid(struct kimage *image)
132121 {
133122 #ifdef CONFIG_CRASH_DUMP
123+ purgatory_t purgatory = (purgatory_t)image->start;
134124 int rc;
135125
136− preempt_disable();
137− rc = call_on_stack(1, S390_lowcore.nodat_stack, unsigned long, do_start_kdump,
138− unsigned long, (unsigned long)image);
139− preempt_enable();
126+ rc = call_nodat(1, int, purgatory, int, 0);
140127 return rc == 0;
141128 #else
142129 return false;
@@ -210,7 +197,7 @@ int machine_kexec_prepare(struct kimage *image) · 67 unmodified lines
210197 return -EINVAL;
211198
212199 /* Get the destination where the assembler code should be copied to.*/
213− reboot_code_buffer = (void *) page_to_phys(image->control_code_page);
200+ reboot_code_buffer = page_to_virt(image->control_code_page);
214201
215202 /* Then copy it */
216203 memcpy(reboot_code_buffer, relocate_kernel, relocate_kernel_len);
@@ -250,19 +237,20 @@ void machine_crash_shutdown(struct pt_regs *regs) · 33 unmodified lines
250237 */
251238 static void __do_machine_kexec(void *data)
252239 {
253− unsigned long diag308_subcode;
254− relocate_kernel_t data_mover;
240+ unsigned long data_mover, entry, diag308_subcode;
255241 struct kimage *image = data;
256242
257− s390_reset_system();
258− data_mover = (relocate_kernel_t) page_to_phys(image->control_code_page);
259−
260− __arch_local_irq_stnsm(0xfb); /* disable DAT - avoid no-execute */
261− /* Call the moving routine */
243+ data_mover = page_to_phys(image->control_code_page);
244+ entry = virt_to_phys(&image->head);
262245 diag308_subcode = DIAG308_CLEAR_RESET;
263246 if (sclp.has_iplcc)
264247 diag308_subcode |= DIAG308_FLAG_EI;
265− (*data_mover)(&image->head, image->start, diag308_subcode);
248+ s390_reset_system();
249+
250+ call_nodat(3, void, (relocate_kernel_t)data_mover,
251+ unsigned long, entry,
252+ unsigned long, image->start,
253+ unsigned long, diag308_subcode);
266254
267255 /* Die if kexec returns */
268256 disabled_wait();
arch/s390/kernel/mcount.S+20−6
@@ -28,9 +28,9 @@ · 27 unmodified lines
2828
2929 .section .kprobes.text, "ax"
3030
31−ENTRY(ftrace_stub)
31+SYM_FUNC_START(ftrace_stub)
3232 BR_EX %r14
33−ENDPROC(ftrace_stub)
33+SYM_FUNC_END(ftrace_stub)
3434
3535 SYM_CODE_START(ftrace_stub_direct_tramp)
3636 lgr %r1, %r0
@@ -140,10 +140,25 @@ SYM_FUNC_END(return_to_handler) · 103 unmodified lines
140140 #endif
141141 #endif /* CONFIG_FUNCTION_TRACER */
142142
143−#ifdef CONFIG_RETHOOK
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 */
144158
145−SYM_FUNC_START(arch_rethook_trampoline)
159+#ifdef CONFIG_RETHOOK
146160
161+SYM_CODE_START(arch_rethook_trampoline)
147162 stg %r14,(__SF_GPRS+8*8)(%r15)
148163 lay %r15,-STACK_FRAME_SIZE(%r15)
149164 stmg %r0,%r14,STACK_PTREGS_GPRS(%r15)
@@ -166,7 +181,6 @@ SYM_FUNC_START(arch_rethook_trampoline) · 16 unmodified lines
166181 mvc __SF_EMPTY(16,%r7),STACK_PTREGS_PSW(%r15)
167182 lmg %r0,%r15,STACK_PTREGS_GPRS(%r15)
168183 lpswe __SF_EMPTY(%r15)
169−
170−SYM_FUNC_END(arch_rethook_trampoline)
184+SYM_CODE_END(arch_rethook_trampoline)
171185
172186 #endif /* CONFIG_RETHOOK */
arch/s390/kernel/module.c+25−4
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include <asm/facility.h>
2727 #include <asm/ftrace.lds.h>
2828 #include <asm/set_memory.h>
29+#include <asm/setup.h>
2930
3031 #if 0
3132 #define DEBUGP printk
@@ -35,6 +36,24 @@ · 3 unmodified lines
3536
3637 #define PLT_ENTRY_SIZE 22
3738
39+static unsigned long get_module_load_offset(void)
40+{
41+ static DEFINE_MUTEX(module_kaslr_mutex);
42+ static unsigned long module_load_offset;
43+
44+ if (!kaslr_enabled())
45+ return 0;
46+ /*
47+ * Calculate the module_load_offset the first time this code
48+ * is called. Once calculated it stays the same until reboot.
49+ */
50+ mutex_lock(&module_kaslr_mutex);
51+ if (!module_load_offset)
52+ module_load_offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE;
53+ mutex_unlock(&module_kaslr_mutex);
54+ return module_load_offset;
55+}
56+
3857 void *module_alloc(unsigned long size)
3958 {
4059 gfp_t gfp_mask = GFP_KERNEL;
@@ -42,9 +61,11 @@ void *module_alloc(unsigned long size) · 1 unmodified line
4261
4362 if (PAGE_ALIGN(size) > MODULES_LEN)
4463 return NULL;
45− p = __vmalloc_node_range(size, MODULE_ALIGN, MODULES_VADDR, MODULES_END,
46− gfp_mask, PAGE_KERNEL_EXEC, VM_DEFER_KMEMLEAK, NUMA_NO_NODE,
47− __builtin_return_address(0));
64+ p = __vmalloc_node_range(size, MODULE_ALIGN,
65+ MODULES_VADDR + get_module_load_offset(),
66+ MODULES_END, gfp_mask, PAGE_KERNEL,
67+ VM_FLUSH_RESET_PERMS | VM_DEFER_KMEMLEAK,
68+ NUMA_NO_NODE, __builtin_return_address(0));
4869 if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) {
4970 vfree(p);
5071 return NULL;
@@ -491,7 +512,7 @@ static int module_alloc_ftrace_hotpatch_trampolines(struct module *me, · 440 unmodified lines
491512 start = module_alloc(numpages * PAGE_SIZE);
492513 if (!start)
493514 return -ENOMEM;
494− set_memory_ro((unsigned long)start, numpages);
515+ set_memory_rox((unsigned long)start, numpages);
495516 end = start + size;
496517
497518 me->arch.trampolines_start = (struct ftrace_hotpatch_trampoline *)start;
arch/s390/kernel/perf_cpum_cf.c+91−115
@@ -76,7 +76,6 @@ static inline int ctr_stcctm(enum cpumf_ctr_set set, u64 range, u64 *dest) · 75 unmodified lines
7676 }
7777
7878 struct cpu_cf_events {
79− struct cpumf_ctr_info info;
8079 atomic_t ctr_set[CPUMF_CTR_SET_MAX];
8180 u64 state; /* For perf_event_open SVC */
8281 u64 dev_state; /* For /dev/hwctr */
@@ -95,6 +94,15 @@ static DEFINE_PER_CPU(struct cpu_cf_events, cpu_cf_events); · 12 unmodified lines
9594 static unsigned int cfdiag_cpu_speed; /* CPU speed for CF_DIAG trailer */
9695 static debug_info_t *cf_dbg;
9796
97+/*
98+ * The CPU Measurement query counter information instruction contains
99+ * information which varies per machine generation, but is constant and
100+ * does not change when running on a particular machine, such as counter
101+ * first and second version number. This is needed to determine the size
102+ * of counter sets. Extract this information at device driver initialization.
103+ */
104+static struct cpumf_ctr_info cpumf_ctr_info;
105+
98106 #define CF_DIAG_CTRSET_DEF 0xfeef /* Counter set header mark */
99107 /* interval in seconds */
100108
@@ -167,11 +175,10 @@ struct cf_trailer_entry { /* CPU-M CF_DIAG trailer (64 byte) */ · 66 unmodified lines
167175 /* Create the trailer data at the end of a page. */
168176 static void cfdiag_trailer(struct cf_trailer_entry *te)
169177 {
170− struct cpu_cf_events *cpuhw = this_cpu_ptr(&cpu_cf_events);
171178 struct cpuid cpuid;
172179
173− te->cfvn = cpuhw->info.cfvn; /* Counter version numbers */
174− te->csvn = cpuhw->info.csvn;
180+ te->cfvn = cpumf_ctr_info.cfvn; /* Counter version numbers */
181+ te->csvn = cpumf_ctr_info.csvn;
175182
176183 get_cpu_id(&cpuid); /* Machine type */
177184 te->mach_type = cpuid.machine;
@@ -184,50 +191,60 @@ static void cfdiag_trailer(struct cf_trailer_entry *te) · 6 unmodified lines
184191 }
185192
186193 /*
187− * Return the maximum possible counter set size (in number of 8 byte counters)
188− * depending on type and model number.
194+ * The number of counters per counter set varies between machine generations,
195+ * but is constant when running on a particular machine generation.
196+ * Determine each counter set size at device driver initialization and
197+ * retrieve it later.
189198 */
190−static size_t cpum_cf_ctrset_size(enum cpumf_ctr_set ctrset,
191− struct cpumf_ctr_info *info)
199+static size_t cpumf_ctr_setsizes[CPUMF_CTR_SET_MAX];
200+static void cpum_cf_make_setsize(enum cpumf_ctr_set ctrset)
192201 {
193202 size_t ctrset_size = 0;
194203
195204 switch (ctrset) {
196205 case CPUMF_CTR_SET_BASIC:
197− if (info->cfvn >= 1)
206+ if (cpumf_ctr_info.cfvn >= 1)
198207 ctrset_size = 6;
199208 break;
200209 case CPUMF_CTR_SET_USER:
201− if (info->cfvn == 1)
210+ if (cpumf_ctr_info.cfvn == 1)
202211 ctrset_size = 6;
203− else if (info->cfvn >= 3)
212+ else if (cpumf_ctr_info.cfvn >= 3)
204213 ctrset_size = 2;
205214 break;
206215 case CPUMF_CTR_SET_CRYPTO:
207− if (info->csvn >= 1 && info->csvn <= 5)
216+ if (cpumf_ctr_info.csvn >= 1 && cpumf_ctr_info.csvn <= 5)
208217 ctrset_size = 16;
209− else if (info->csvn == 6 || info->csvn == 7)
218+ else if (cpumf_ctr_info.csvn == 6 || cpumf_ctr_info.csvn == 7)
210219 ctrset_size = 20;
211220 break;
212221 case CPUMF_CTR_SET_EXT:
213− if (info->csvn == 1)
222+ if (cpumf_ctr_info.csvn == 1)
214223 ctrset_size = 32;
215− else if (info->csvn == 2)
224+ else if (cpumf_ctr_info.csvn == 2)
216225 ctrset_size = 48;
217− else if (info->csvn >= 3 && info->csvn <= 5)
226+ else if (cpumf_ctr_info.csvn >= 3 && cpumf_ctr_info.csvn <= 5)
218227 ctrset_size = 128;
219− else if (info->csvn == 6 || info->csvn == 7)
228+ else if (cpumf_ctr_info.csvn == 6 || cpumf_ctr_info.csvn == 7)
220229 ctrset_size = 160;
221230 break;
222231 case CPUMF_CTR_SET_MT_DIAG:
223− if (info->csvn > 3)
232+ if (cpumf_ctr_info.csvn > 3)
224233 ctrset_size = 48;
225234 break;
226235 case CPUMF_CTR_SET_MAX:
227236 break;
228237 }
238+ cpumf_ctr_setsizes[ctrset] = ctrset_size;
239+}
229240
230− return ctrset_size;
241+/*
242+ * Return the maximum possible counter set size (in number of 8 byte counters)
243+ * depending on type and model number.
244+ */
245+static size_t cpum_cf_read_setsize(enum cpumf_ctr_set ctrset)
246+{
247+ return cpumf_ctr_setsizes[ctrset];
231248 }
232249
233250 /* Read a counter set. The counter set number determines the counter set and
@@ -248,14 +265,13 @@ static size_t cpum_cf_ctrset_size(enum cpumf_ctr_set ctrset, · 14 unmodified lines
248265 static size_t cfdiag_getctrset(struct cf_ctrset_entry *ctrdata, int ctrset,
249266 size_t room, bool error_ok)
250267 {
251− struct cpu_cf_events *cpuhw = this_cpu_ptr(&cpu_cf_events);
252268 size_t ctrset_size, need = 0;
253269 int rc = 3; /* Assume write failure */
254270
255271 ctrdata->def = CF_DIAG_CTRSET_DEF;
256272 ctrdata->set = ctrset;
257273 ctrdata->res1 = 0;
258− ctrset_size = cpum_cf_ctrset_size(ctrset, &cpuhw->info);
274+ ctrset_size = cpum_cf_read_setsize(ctrset);
259275
260276 if (ctrset_size) { /* Save data */
261277 need = ctrset_size * sizeof(u64) + sizeof(*ctrdata);
@@ -269,10 +285,6 @@ static size_t cfdiag_getctrset(struct cf_ctrset_entry *ctrdata, int ctrset, · 7 unmodified lines
269285 need = 0;
270286 }
271287
272− debug_sprintf_event(cf_dbg, 3,
273− "%s ctrset %d ctrset_size %zu cfvn %d csvn %d"
274− " need %zd rc %d\n", __func__, ctrset, ctrset_size,
275− cpuhw->info.cfvn, cpuhw->info.csvn, need, rc);
276288 return need;
277289 }
278290
@@ -377,40 +389,35 @@ static enum cpumf_ctr_set get_counter_set(u64 event) · 98 unmodified lines
377389 return set;
378390 }
379391
380−static int validate_ctr_version(const struct hw_perf_event *hwc,
381− enum cpumf_ctr_set set)
392+static int validate_ctr_version(const u64 config, enum cpumf_ctr_set set)
382393 {
383− struct cpu_cf_events *cpuhw;
384− int err = 0;
385394 u16 mtdiag_ctl;
386−
387− cpuhw = &get_cpu_var(cpu_cf_events);
395+ int err = 0;
388396
389397 /* check required version for counter sets */
390398 switch (set) {
391399 case CPUMF_CTR_SET_BASIC:
392400 case CPUMF_CTR_SET_USER:
393− if (cpuhw->info.cfvn < 1)
401+ if (cpumf_ctr_info.cfvn < 1)
394402 err = -EOPNOTSUPP;
395403 break;
396404 case CPUMF_CTR_SET_CRYPTO:
397− if ((cpuhw->info.csvn >= 1 && cpuhw->info.csvn <= 5 &&
398− hwc->config > 79) ||
399− (cpuhw->info.csvn >= 6 && hwc->config > 83))
405+ if ((cpumf_ctr_info.csvn >= 1 && cpumf_ctr_info.csvn <= 5 &&
406+ config > 79) || (cpumf_ctr_info.csvn >= 6 && config > 83))
400407 err = -EOPNOTSUPP;
401408 break;
402409 case CPUMF_CTR_SET_EXT:
403− if (cpuhw->info.csvn < 1)
410+ if (cpumf_ctr_info.csvn < 1)
404411 err = -EOPNOTSUPP;
405− if ((cpuhw->info.csvn == 1 && hwc->config > 159) ||
406− (cpuhw->info.csvn == 2 && hwc->config > 175) ||
407− (cpuhw->info.csvn >= 3 && cpuhw->info.csvn <= 5
408− && hwc->config > 255) ||
409− (cpuhw->info.csvn >= 6 && hwc->config > 287))
412+ if ((cpumf_ctr_info.csvn == 1 && config > 159) ||
413+ (cpumf_ctr_info.csvn == 2 && config > 175) ||
414+ (cpumf_ctr_info.csvn >= 3 && cpumf_ctr_info.csvn <= 5 &&
415+ config > 255) ||
416+ (cpumf_ctr_info.csvn >= 6 && config > 287))
410417 err = -EOPNOTSUPP;
411418 break;
412419 case CPUMF_CTR_SET_MT_DIAG:
413− if (cpuhw->info.csvn <= 3)
420+ if (cpumf_ctr_info.csvn <= 3)
414421 err = -EOPNOTSUPP;
415422 /*
416423 * MT-diagnostic counters are read-only. The counter set
@@ -425,35 +432,15 @@ static int validate_ctr_version(const struct hw_perf_event *hwc, · 8 unmodified lines
425432 * counter set is enabled and active.
426433 */
427434 mtdiag_ctl = cpumf_ctr_ctl[CPUMF_CTR_SET_MT_DIAG];
428− if (!((cpuhw->info.auth_ctl & mtdiag_ctl) &&
429− (cpuhw->info.enable_ctl & mtdiag_ctl) &&
430− (cpuhw->info.act_ctl & mtdiag_ctl)))
435+ if (!((cpumf_ctr_info.auth_ctl & mtdiag_ctl) &&
436+ (cpumf_ctr_info.enable_ctl & mtdiag_ctl) &&
437+ (cpumf_ctr_info.act_ctl & mtdiag_ctl)))
431438 err = -EOPNOTSUPP;
432439 break;
433440 case CPUMF_CTR_SET_MAX:
434441 err = -EOPNOTSUPP;
435442 }
436443
437− put_cpu_var(cpu_cf_events);
438− return err;
439−}
440−
441−static int validate_ctr_auth(const struct hw_perf_event *hwc)
442−{
443− struct cpu_cf_events *cpuhw;
444− int err = 0;
445−
446− cpuhw = &get_cpu_var(cpu_cf_events);
447−
448− /* Check authorization for cpu counter sets.
449− * If the particular CPU counter set is not authorized,
450− * return with -ENOENT in order to fall back to other
451− * PMUs that might suffice the event request.
452− */
453− if (!(hwc->config_base & cpuhw->info.auth_ctl))
454− err = -ENOENT;
455−
456− put_cpu_var(cpu_cf_events);
457444 return err;
458445 }
459446
@@ -471,13 +458,10 @@ static void cpumf_pmu_enable(struct pmu *pmu) · 11 unmodified lines
471458 return;
472459
473460 err = lcctl(cpuhw->state | cpuhw->dev_state);
474− if (err) {
475− pr_err("Enabling the performance measuring unit "
476− "failed with rc=%x\n", err);
477− return;
478− }
479−
480− cpuhw->flags |= PMU_F_ENABLED;
461+ if (err)
462+ pr_err("Enabling the performance measuring unit failed with rc=%x\n", err);
463+ else
464+ cpuhw->flags |= PMU_F_ENABLED;
481465 }
482466
483467 /*
@@ -497,13 +481,10 @@ static void cpumf_pmu_disable(struct pmu *pmu) · 13 unmodified lines
497481 inactive = cpuhw->state & ~((1 << CPUMF_LCCTL_ENABLE_SHIFT) - 1);
498482 inactive |= cpuhw->dev_state;
499483 err = lcctl(inactive);
500− if (err) {
501− pr_err("Disabling the performance measuring unit "
502− "failed with rc=%x\n", err);
503− return;
504− }
505−
506− cpuhw->flags &= ~PMU_F_ENABLED;
484+ if (err)
485+ pr_err("Disabling the performance measuring unit failed with rc=%x\n", err);
486+ else
487+ cpuhw->flags &= ~PMU_F_ENABLED;
507488 }
508489
509490 #define PMC_INIT 0UL
@@ -515,8 +496,6 @@ static void cpum_cf_setup_cpu(void *flags) · 5 unmodified lines
515496
516497 switch ((unsigned long)flags) {
517498 case PMC_INIT:
518− memset(&cpuhw->info, 0, sizeof(cpuhw->info));
519− qctri(&cpuhw->info);
520499 cpuhw->flags |= PMU_F_RESERVED;
521500 break;
522501
@@ -602,7 +581,6 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type) · 79 unmodified lines
602581 struct perf_event_attr *attr = &event->attr;
603582 struct hw_perf_event *hwc = &event->hw;
604583 enum cpumf_ctr_set set;
605− int err = 0;
606584 u64 ev;
607585
608586 switch (type) {
@@ -678,12 +656,15 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type) · 69 unmodified lines
678656 cpumf_hw_inuse();
679657 event->destroy = hw_perf_event_destroy;
680658
681− /* Finally, validate version and authorization of the counter set */
682− err = validate_ctr_auth(hwc);
683− if (!err)
684− err = validate_ctr_version(hwc, set);
685−
686− return err;
659+ /*
660+ * Finally, validate version and authorization of the counter set.
661+ * If the particular CPU counter set is not authorized,
662+ * return with -ENOENT in order to fall back to other
663+ * PMUs that might suffice the event request.
664+ */
665+ if (!(hwc->config_base & cpumf_ctr_info.auth_ctl))
666+ return -ENOENT;
667+ return validate_ctr_version(hwc->config, set);
687668 }
688669
689670 /* Events CPU_CYLCES and INSTRUCTIONS can be submitted with two different
@@ -983,7 +964,7 @@ static void cpumf_measurement_alert(struct ext_code ext_code, · 293 unmodified lines
983964
984965 /* counter authorization change alert */
985966 if (alert & CPU_MF_INT_CF_CACA)
986− qctri(&cpuhw->info);
967+ qctri(&cpumf_ctr_info);
987968
988969 /* loss of counter data alert */
989970 if (alert & CPU_MF_INT_CF_LCDA)
@@ -1000,9 +981,14 @@ static int __init cpumf_pmu_init(void) · 10 unmodified lines
1000981 {
1001982 int rc;
1002983
1003− if (!cpum_cf_avail())
984+ /* Extract counter measurement facility information */
985+ if (!cpum_cf_avail() || qctri(&cpumf_ctr_info))
1004986 return -ENODEV;
1005987
988+ /* Determine and store counter set sizes for later reference */
989+ for (rc = CPUMF_CTR_SET_BASIC; rc < CPUMF_CTR_SET_MAX; ++rc)
990+ cpum_cf_make_setsize(rc);
991+
1006992 /*
1007993 * Clear bit 15 of cr0 to unauthorize problem-state to
1008994 * extract measurement counters
@@ -1269,28 +1255,26 @@ static int cfset_all_start(struct cfset_request *req) · 260 unmodified lines
12691255 */
12701256 static size_t cfset_needspace(unsigned int sets)
12711257 {
1272− struct cpu_cf_events *cpuhw = get_cpu_ptr(&cpu_cf_events);
12731258 size_t bytes = 0;
12741259 int i;
12751260
12761261 for (i = CPUMF_CTR_SET_BASIC; i < CPUMF_CTR_SET_MAX; ++i) {
12771262 if (!(sets & cpumf_ctr_ctl[i]))
12781263 continue;
1279− bytes += cpum_cf_ctrset_size(i, &cpuhw->info) * sizeof(u64) +
1264+ bytes += cpum_cf_read_setsize(i) * sizeof(u64) +
12801265 sizeof(((struct s390_ctrset_setdata *)0)->set) +
12811266 sizeof(((struct s390_ctrset_setdata *)0)->no_cnts);
12821267 }
12831268 bytes = sizeof(((struct s390_ctrset_read *)0)->no_cpus) + nr_cpu_ids *
12841269 (bytes + sizeof(((struct s390_ctrset_cpudata *)0)->cpu_nr) +
12851270 sizeof(((struct s390_ctrset_cpudata *)0)->no_sets));
1286− put_cpu_ptr(&cpu_cf_events);
12871271 return bytes;
12881272 }
12891273
12901274 static int cfset_all_copy(unsigned long arg, cpumask_t *mask)
12911275 {
12921276 struct s390_ctrset_read __user *ctrset_read;
1293− unsigned int cpu, cpus, rc;
1277+ unsigned int cpu, cpus, rc = 0;
12941278 void __user *uptr;
12951279
12961280 ctrset_read = (struct s390_ctrset_read __user *)arg;
@@ -1304,17 +1288,20 @@ static int cfset_all_copy(unsigned long arg, cpumask_t *mask) · 7 unmodified lines
13041288 rc |= put_user(cpuhw->sets, &ctrset_cpudata->no_sets);
13051289 rc |= copy_to_user(ctrset_cpudata->data, cpuhw->data,
13061290 cpuhw->used);
1307− if (rc)
1308− return -EFAULT;
1291+ if (rc) {
1292+ rc = -EFAULT;
1293+ goto out;
1294+ }
13091295 uptr += sizeof(struct s390_ctrset_cpudata) + cpuhw->used;
13101296 cond_resched();
13111297 }
13121298 cpus = cpumask_weight(mask);
13131299 if (put_user(cpus, &ctrset_read->no_cpus))
1314− return -EFAULT;
1315− debug_sprintf_event(cf_dbg, 4, "%s copied %ld\n", __func__,
1300+ rc = -EFAULT;
1301+out:
1302+ debug_sprintf_event(cf_dbg, 4, "%s rc %d copied %ld\n", __func__, rc,
13161303 uptr - (void __user *)ctrset_read->data);
1317− return 0;
1304+ return rc;
13181305 }
13191306
13201307 static size_t cfset_cpuset_read(struct s390_ctrset_setdata *p, int ctrset,
@@ -1354,7 +1341,7 @@ static void cfset_cpu_read(void *parm) · 33 unmodified lines
13541341
13551342 if (!(p->sets & cpumf_ctr_ctl[set]))
13561343 continue; /* Counter set not in list */
1357− set_size = cpum_cf_ctrset_size(set, &cpuhw->info);
1344+ set_size = cpum_cf_read_setsize(set);
13581345 space = sizeof(cpuhw->data) - cpuhw->used;
13591346 space = cfset_cpuset_read(sp, set, set_size, space);
13601347 if (space) {
@@ -1385,14 +1372,10 @@ static int cfset_all_read(unsigned long arg, struct cfset_request *req) · 24 unmodified lines
13851372
13861373 static long cfset_ioctl_read(unsigned long arg, struct cfset_request *req)
13871374 {
1388− struct s390_ctrset_read read;
13891375 int ret = -ENODATA;
13901376
1391− if (req && req->ctrset) {
1392− if (copy_from_user(&read, (char __user *)arg, sizeof(read)))
1393− return -EFAULT;
1377+ if (req && req->ctrset)
13941378 ret = cfset_all_read(arg, req);
1395− }
13961379 return ret;
13971380 }
13981381
@@ -1569,16 +1552,13 @@ static void cfdiag_read(struct perf_event *event) · 170 unmodified lines
15691552
15701553 static int get_authctrsets(void)
15711554 {
1572− struct cpu_cf_events *cpuhw;
15731555 unsigned long auth = 0;
15741556 enum cpumf_ctr_set i;
15751557
1576− cpuhw = &get_cpu_var(cpu_cf_events);
15771558 for (i = CPUMF_CTR_SET_BASIC; i < CPUMF_CTR_SET_MAX; ++i) {
1578− if (cpuhw->info.auth_ctl & cpumf_ctr_ctl[i])
1559+ if (cpumf_ctr_info.auth_ctl & cpumf_ctr_ctl[i])
15791560 auth |= cpumf_ctr_ctl[i];
15801561 }
1581− put_cpu_var(cpu_cf_events);
15821562 return auth;
15831563 }
15841564
@@ -1716,7 +1696,7 @@ static size_t cfdiag_maxsize(struct cpumf_ctr_info *info) · 131 unmodified lines
17161696 enum cpumf_ctr_set i;
17171697
17181698 for (i = CPUMF_CTR_SET_BASIC; i < CPUMF_CTR_SET_MAX; ++i) {
1719− size_t size = cpum_cf_ctrset_size(i, info);
1699+ size_t size = cpum_cf_read_setsize(i);
17201700
17211701 if (size)
17221702 max_size += size * sizeof(u64) +
@@ -1750,16 +1730,12 @@ static void cfdiag_get_cpu_speed(void) · 27 unmodified lines
17501730
17511731 static int cfset_init(void)
17521732 {
1753− struct cpumf_ctr_info info;
17541733 size_t need;
17551734 int rc;
17561735
1757− if (qctri(&info))
1758− return -ENODEV;
1759−
17601736 cfdiag_get_cpu_speed();
17611737 /* Make sure the counter set data fits into predefined buffer. */
1762− need = cfdiag_maxsize(&info);
1738+ need = cfdiag_maxsize(&cpumf_ctr_info);
17631739 if (need > sizeof(((struct cpu_cf_events *)0)->start)) {
17641740 pr_err("Insufficient memory for PMU(cpum_cf_diag) need=%zu\n",
17651741 need);
arch/s390/kernel/perf_cpum_sf.c+2−12
@@ -882,10 +882,6 @@ static int __hw_perf_event_init(struct perf_event *event) · 881 unmodified lines
882882 SAMPL_FLAGS(hwc) |= PERF_CPUM_SF_DIAG_MODE;
883883 }
884884
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−
889885 err = __hw_perf_event_init_rate(event, &si);
890886 if (err)
891887 goto out;
@@ -1293,11 +1289,8 @@ static inline __uint128_t __cdsg(__uint128_t *ptr, __uint128_t old, __uint128_t · 401 unmodified lines
12931289 * The sampling buffer position are retrieved and saved in the TEAR_REG
12941290 * register of the specified perf event.
12951291 *
1296− * Only full sample-data-blocks are processed. Specify the flash_all flag
1297− * to also walk through partially filled sample-data-blocks. It is ignored
1298− * if PERF_CPUM_SF_FULL_BLOCKS is set. The PERF_CPUM_SF_FULL_BLOCKS flag
1299− * enforces the processing of full sample-data-blocks only (trailer entries
1300− * with the block-full-indicator bit set).
1292+ * Only full sample-data-blocks are processed. Specify the flush_all flag
1293+ * to also walk through partially filled sample-data-blocks.
13011294 */
13021295 static void hw_perf_event_update(struct perf_event *event, int flush_all)
13031296 {
@@ -1315,9 +1308,6 @@ static void hw_perf_event_update(struct perf_event *event, int flush_all) · 11 unmodified lines
13151308 if (SAMPL_DIAG_MODE(&event->hw))
13161309 return;
13171310
1318− if (flush_all && SDB_FULL_BLOCKS(hwc))
1319− flush_all = 0;
1320−
13211311 sdbt = (unsigned long *) TEAR_REG(hwc);
13221312 done = event_overflow = sampl_overflow = num_sdb = 0;
13231313 while (!done) {
arch/s390/kernel/process.c+4−6
@@ -136,12 +136,12 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) · 135 unmodified lines
136136 p->thread.last_break = 1;
137137
138138 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;
141141 /* 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;
143143 /* 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;
145145
146146 /* Store access registers to kernel stack of new process. */
147147 if (unlikely(args->fn)) {
@@ -149,8 +149,6 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) · 1 unmodified line
149149 memset(&frame->childregs, 0, sizeof(struct pt_regs));
150150 frame->childregs.psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO |
151151 PSW_MASK_EXT | PSW_MASK_MCHECK;
152− frame->childregs.psw.addr =
153− (unsigned long)__ret_from_fork;
154152 frame->childregs.gprs[9] = (unsigned long)args->fn;
155153 frame->childregs.gprs[10] = (unsigned long)args->fn_arg;
156154 frame->childregs.orig_gpr2 = -1;
arch/s390/kernel/processor.c+0−18
@@ -364,21 +364,3 @@ const struct seq_operations cpuinfo_op = { · 363 unmodified lines
364364 .stop = c_stop,
365365 .show = show_cpuinfo,
366366 };
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);
arch/s390/kernel/reipl.S+5−5
@@ -19,7 +19,7 @@ · 18 unmodified lines
1919 # r2 = Function to be called after store status
2020 # r3 = Parameter for function
2121 #
22−ENTRY(store_status)
22+SYM_CODE_START(store_status)
2323 /* Save register one and load save area base */
2424 stg %r1,__LC_SAVE_AREA_RESTART
2525 /* General purpose registers */
@@ -61,7 +61,7 @@ ENTRY(store_status) · 35 unmodified lines
6161 stpx 0(%r1)
6262 /* Clock comparator - seven bytes */
6363 lghi %r1,__LC_CLOCK_COMP_SAVE_AREA
64− larl %r4,.Lclkcmp
64+ larl %r4,clkcmp
6565 stckc 0(%r4)
6666 mvc 1(7,%r1),1(%r4)
6767 /* Program status word */
@@ -73,9 +73,9 @@ ENTRY(store_status) · 5 unmodified lines
7373 lgr %r9,%r2
7474 lgr %r2,%r3
7575 BR_EX %r9
76−ENDPROC(store_status)
76+SYM_CODE_END(store_status)
7777
7878 .section .bss
79− .align 8
80−.Lclkcmp: .quad 0x0000000000000000
79+ .balign 8
80+SYM_DATA_LOCAL(clkcmp, .quad 0x0000000000000000)
8181 .previous
arch/s390/kernel/relocate_kernel.S+47−49
@@ -26,53 +26,51 @@ · 25 unmodified lines
2626 */
2727
2828 .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)
7070
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)
arch/s390/kernel/setup.c+48−104
@@ -74,7 +74,7 @@ · 73 unmodified lines
7474 #include <asm/numa.h>
7575 #include <asm/alternative.h>
7676 #include <asm/nospec-branch.h>
77−#include <asm/mem_detect.h>
77+#include <asm/physmem_info.h>
7878 #include <asm/maccess.h>
7979 #include <asm/uv.h>
8080 #include <asm/asm-offsets.h>
@@ -147,14 +147,10 @@ static u32 __amode31_ref *__ctl_duct = __ctl_duct_amode31; · 66 unmodified lines
147147
148148 int __bootdata(noexec_disabled);
149149 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);
155151
156152 unsigned long __bootdata_preserved(__kaslr_offset);
157−unsigned long __bootdata(__amode31_base);
153+int __bootdata_preserved(__kaslr_enabled);
158154 unsigned int __bootdata_preserved(zlib_dfltcc_support);
159155 EXPORT_SYMBOL(zlib_dfltcc_support);
160156 u64 __bootdata_preserved(stfle_fac_list[16]);
@@ -385,39 +381,27 @@ void stack_free(unsigned long stack) · 224 unmodified lines
385381 #endif
386382 }
387383
388−int __init arch_early_irq_init(void)
384+void __init __noreturn arch_call_rest_init(void)
389385 {
390− unsigned long stack;
391−
392− stack = __get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER);
393− if (!stack)
394− panic("Couldn't allocate async stack");
395− S390_lowcore.async_stack = stack + STACK_INIT_OFFSET;
396− return 0;
386+ smp_reinit_ipl_cpu();
387+ rest_init();
397388 }
398389
399−void __init __noreturn arch_call_rest_init(void)
390+static unsigned long __init stack_alloc_early(void)
400391 {
401392 unsigned long stack;
402393
403− smp_reinit_ipl_cpu();
404− stack = stack_alloc();
405− if (!stack)
406− panic("Couldn't allocate kernel stack");
407− current->stack = (void *) stack;
408−#ifdef CONFIG_VMAP_STACK
409− current->stack_vm_area = (void *) stack;
410−#endif
411− set_task_stack_end_magic(current);
412− stack += STACK_INIT_OFFSET;
413− S390_lowcore.kernel_stack = stack;
414− call_on_stack_noreturn(rest_init, stack);
394+ stack = (unsigned long)memblock_alloc(THREAD_SIZE, THREAD_SIZE);
395+ if (!stack) {
396+ panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
397+ __func__, THREAD_SIZE, THREAD_SIZE);
398+ }
399+ return stack;
415400 }
416401
417402 static void __init setup_lowcore(void)
418403 {
419404 struct lowcore *lc, *abs_lc;
420− unsigned long mcck_stack;
421405
422406 /*
423407 * Setup lowcore for boot cpu
@@ -441,8 +425,6 @@ static void __init setup_lowcore(void) · 17 unmodified lines
441425 lc->io_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_MCHECK;
442426 lc->io_new_psw.addr = (unsigned long) io_int_handler;
443427 lc->clock_comparator = clock_comparator_max;
444− lc->nodat_stack = ((unsigned long) &init_thread_union)
445− + THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
446428 lc->current_task = (unsigned long)&init_task;
447429 lc->lpp = LPP_MAGIC;
448430 lc->machine_flags = S390_lowcore.machine_flags;
@@ -455,17 +437,15 @@ static void __init setup_lowcore(void) · 6 unmodified lines
455437 lc->steal_timer = S390_lowcore.steal_timer;
456438 lc->last_update_timer = S390_lowcore.last_update_timer;
457439 lc->last_update_clock = S390_lowcore.last_update_clock;
458−
459440 /*
460441 * Allocate the global restart stack which is the same for
461− * all CPUs in cast *one* of them does a PSW restart.
442+ * all CPUs in case *one* of them does a PSW restart.
462443 */
463− restart_stack = memblock_alloc(THREAD_SIZE, THREAD_SIZE);
464− if (!restart_stack)
465− panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
466− __func__, THREAD_SIZE, THREAD_SIZE);
467− restart_stack += STACK_INIT_OFFSET;
468−
444+ restart_stack = (void *)(stack_alloc_early() + STACK_INIT_OFFSET);
445+ lc->mcck_stack = stack_alloc_early() + STACK_INIT_OFFSET;
446+ lc->async_stack = stack_alloc_early() + STACK_INIT_OFFSET;
447+ lc->nodat_stack = stack_alloc_early() + STACK_INIT_OFFSET;
448+ lc->kernel_stack = S390_lowcore.kernel_stack;
469449 /*
470450 * Set up PSW restart to call ipl.c:do_restart(). Copy the relevant
471451 * restart data to the absolute zero lowcore. This is necessary if
@@ -476,13 +456,6 @@ static void __init setup_lowcore(void) · 4 unmodified lines
476456 lc->restart_data = 0;
477457 lc->restart_source = -1U;
478458 __ctl_store(lc->cregs_save_area, 0, 15);
479−
480− mcck_stack = (unsigned long)memblock_alloc(THREAD_SIZE, THREAD_SIZE);
481− if (!mcck_stack)
482− panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
483− __func__, THREAD_SIZE, THREAD_SIZE);
484− lc->mcck_stack = mcck_stack + STACK_INIT_OFFSET;
485−
486459 lc->spinlock_lockval = arch_spin_lockval(0);
487460 lc->spinlock_index = 0;
488461 arch_spin_lock_setup(0);
@@ -635,7 +608,11 @@ static struct notifier_block kdump_mem_nb = { · 146 unmodified lines
635608 */
636609 static void __init reserve_pgtables(void)
637610 {
638− memblock_reserve(pgalloc_pos, pgalloc_end - pgalloc_pos);
611+ unsigned long start, end;
612+ struct reserved_range *range;
613+
614+ for_each_physmem_reserved_type_range(RR_VMEM, range, &start, &end)
615+ memblock_reserve(start, end - start);
639616 }
640617
641618 /*
@@ -712,13 +689,13 @@ static void __init reserve_crashkernel(void) · 70 unmodified lines
712689 */
713690 static void __init reserve_initrd(void)
714691 {
715−#ifdef CONFIG_BLK_DEV_INITRD
716− if (!initrd_data.start || !initrd_data.size)
692+ unsigned long addr, size;
693+
694+ if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD) || !get_physmem_reserved(RR_INITRD, &addr, &size))
717695 return;
718− initrd_start = (unsigned long)__va(initrd_data.start);
719− initrd_end = initrd_start + initrd_data.size;
720− memblock_reserve(initrd_data.start, initrd_data.size);
721−#endif
696+ initrd_start = (unsigned long)__va(addr);
697+ initrd_end = initrd_start + size;
698+ memblock_reserve(addr, size);
722699 }
723700
724701 /*
@@ -730,71 +707,39 @@ static void __init reserve_certificate_list(void) · 5 unmodified lines
730707 memblock_reserve(ipl_cert_list_addr, ipl_cert_list_size);
731708 }
732709
733−static void __init reserve_mem_detect_info(void)
710+static void __init reserve_physmem_info(void)
734711 {
735− unsigned long start, size;
712+ unsigned long addr, size;
736713
737− get_mem_detect_reserved(&start, &size);
738− if (size)
739− memblock_reserve(start, size);
714+ if (get_physmem_reserved(RR_MEM_DETECT_EXTENDED, &addr, &size))
715+ memblock_reserve(addr, size);
740716 }
741717
742−static void __init free_mem_detect_info(void)
718+static void __init free_physmem_info(void)
743719 {
744− unsigned long start, size;
720+ unsigned long addr, size;
745721
746− get_mem_detect_reserved(&start, &size);
747− if (size)
748− memblock_phys_free(start, size);
722+ if (get_physmem_reserved(RR_MEM_DETECT_EXTENDED, &addr, &size))
723+ memblock_phys_free(addr, size);
749724 }
750725
751−static const char * __init get_mem_info_source(void)
752−{
753− switch (mem_detect.info_source) {
754− case MEM_DETECT_SCLP_STOR_INFO:
755− return "sclp storage info";
756− case MEM_DETECT_DIAG260:
757− return "diag260";
758− case MEM_DETECT_SCLP_READ_INFO:
759− return "sclp read info";
760− case MEM_DETECT_BIN_SEARCH:
761− return "binary search";
762− }
763− return "none";
764−}
765−
766−static void __init memblock_add_mem_detect_info(void)
726+static void __init memblock_add_physmem_info(void)
767727 {
768728 unsigned long start, end;
769729 int i;
770730
771731 pr_debug("physmem info source: %s (%hhd)\n",
772− get_mem_info_source(), mem_detect.info_source);
732+ get_physmem_info_source(), physmem_info.info_source);
773733 /* keep memblock lists close to the kernel */
774734 memblock_set_bottom_up(true);
775− for_each_mem_detect_usable_block(i, &start, &end)
735+ for_each_physmem_usable_range(i, &start, &end)
776736 memblock_add(start, end - start);
777− for_each_mem_detect_block(i, &start, &end)
737+ for_each_physmem_online_range(i, &start, &end)
778738 memblock_physmem_add(start, end - start);
779739 memblock_set_bottom_up(false);
780740 memblock_set_node(0, ULONG_MAX, &memblock.memory, 0);
781741 }
782742
783−/*
784− * Check for initrd being in usable memory
785− */
786−static void __init check_initrd(void)
787−{
788−#ifdef CONFIG_BLK_DEV_INITRD
789− if (initrd_data.start && initrd_data.size &&
790− !memblock_is_region_memory(initrd_data.start, initrd_data.size)) {
791− pr_err("The initial RAM disk does not fit into the memory\n");
792− memblock_phys_free(initrd_data.start, initrd_data.size);
793− initrd_start = initrd_end = 0;
794− }
795−#endif
796−}
797−
798743 /*
799744 * Reserve memory used for lowcore/command line/kernel image.
800745 */
@@ -803,7 +748,7 @@ static void __init reserve_kernel(void) · 2 unmodified lines
803748 memblock_reserve(0, STARTUP_NORMAL_OFFSET);
804749 memblock_reserve(OLDMEM_BASE, sizeof(unsigned long));
805750 memblock_reserve(OLDMEM_SIZE, sizeof(unsigned long));
806− memblock_reserve(__amode31_base, __eamode31 - __samode31);
751+ memblock_reserve(physmem_info.reserved[RR_AMODE31].start, __eamode31 - __samode31);
807752 memblock_reserve(__pa(sclp_early_sccb), EXT_SCCB_READ_SCP);
808753 memblock_reserve(__pa(_stext), _end - _stext);
809754 }
@@ -825,13 +770,13 @@ static void __init setup_memory(void) · 15 unmodified lines
825770 static void __init relocate_amode31_section(void)
826771 {
827772 unsigned long amode31_size = __eamode31 - __samode31;
828− long amode31_offset = __amode31_base - __samode31;
773+ long amode31_offset = physmem_info.reserved[RR_AMODE31].start - __samode31;
829774 long *ptr;
830775
831776 pr_info("Relocating AMODE31 section of size 0x%08lx\n", amode31_size);
832777
833778 /* Move original AMODE31 section to the new one */
834− memmove((void *)__amode31_base, (void *)__samode31, amode31_size);
779+ memmove((void *)physmem_info.reserved[RR_AMODE31].start, (void *)__samode31, amode31_size);
835780 /* Zero out the old AMODE31 section to catch invalid accesses within it */
836781 memset((void *)__samode31, 0, amode31_size);
837782
@@ -997,14 +942,14 @@ void __init setup_arch(char **cmdline_p) · 159 unmodified lines
997942 reserve_kernel();
998943 reserve_initrd();
999944 reserve_certificate_list();
1000− reserve_mem_detect_info();
945+ reserve_physmem_info();
1001946 memblock_set_current_limit(ident_map_size);
1002947 memblock_allow_resize();
1003948
1004949 /* Get information about *all* installed memory */
1005− memblock_add_mem_detect_info();
950+ memblock_add_physmem_info();
1006951
1007− free_mem_detect_info();
952+ free_physmem_info();
1008953 setup_memory_end();
1009954 memblock_dump_all();
1010955 setup_memory();
@@ -1017,7 +962,6 @@ void __init setup_arch(char **cmdline_p) · 6 unmodified lines
1017962 if (MACHINE_HAS_EDAT2)
1018963 hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT);
1019964
1020− check_initrd();
1021965 reserve_crashkernel();
1022966 #ifdef CONFIG_CRASH_DUMP
1023967 /*
arch/s390/kernel/smp.c+4−7
@@ -280,9 +280,8 @@ static void pcpu_attach_task(struct pcpu *pcpu, struct task_struct *tsk) · 279 unmodified lines
280280
281281 cpu = pcpu - pcpu_devices;
282282 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;
286285 lc->lpp = LPP_MAGIC;
287286 lc->current_pid = tsk->pid;
288287 lc->user_timer = tsk->thread.user_timer;
@@ -348,7 +347,6 @@ static void pcpu_delegate(struct pcpu *pcpu, · 59 unmodified lines
348347 abs_lc->restart_source = source_cpu;
349348 put_abs_lowcore(abs_lc);
350349 }
351− __bpon();
352350 asm volatile(
353351 "0: sigp 0,%0,%2 # sigp restart to target cpu\n"
354352 " brc 2,0b # busy, try again\n"
@@ -986,7 +984,6 @@ void __cpu_die(unsigned int cpu) · 631 unmodified lines
986984 void __noreturn cpu_die(void)
987985 {
988986 idle_task_exit();
989− __bpon();
990987 pcpu_sigp_retry(pcpu_devices + smp_processor_id(), SIGP_STOP, 0);
991988 for (;;) ;
992989 }
@@ -1302,9 +1299,9 @@ int __init smp_reinit_ipl_cpu(void) · 309 unmodified lines
13021299 local_mcck_enable();
13031300 local_irq_restore(flags);
13041301
1305− free_pages(lc_ipl->async_stack - STACK_INIT_OFFSET, THREAD_SIZE_ORDER);
13061302 memblock_free_late(__pa(lc_ipl->mcck_stack - STACK_INIT_OFFSET), THREAD_SIZE);
1303+ memblock_free_late(__pa(lc_ipl->async_stack - STACK_INIT_OFFSET), THREAD_SIZE);
1304+ memblock_free_late(__pa(lc_ipl->nodat_stack - STACK_INIT_OFFSET), THREAD_SIZE);
13071305 memblock_free_late(__pa(lc_ipl), sizeof(*lc_ipl));
1308−
13091306 return 0;
13101307 }
arch/s390/kernel/syscalls/syscall.tbl+1−1
@@ -449,7 +449,7 @@ · 448 unmodified lines
449449 444 common landlock_create_ruleset sys_landlock_create_ruleset sys_landlock_create_ruleset
450450 445 common landlock_add_rule sys_landlock_add_rule sys_landlock_add_rule
451451 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
453453 448 common process_mrelease sys_process_mrelease sys_process_mrelease
454454 449 common futex_waitv sys_futex_waitv sys_futex_waitv
455455 450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node
arch/s390/kernel/text_amode31.S+31−44
@@ -27,7 +27,7 @@ · 26 unmodified lines
2727 /*
2828 * int _diag14_amode31(unsigned long rx, unsigned long ry1, unsigned long subcode)
2929 */
30−ENTRY(_diag14_amode31)
30+SYM_FUNC_START(_diag14_amode31)
3131 lgr %r1,%r2
3232 lgr %r2,%r3
3333 lgr %r3,%r4
@@ -42,12 +42,12 @@ ENTRY(_diag14_amode31) · 8 unmodified lines
4242 lgfr %r2,%r5
4343 BR_EX_AMODE31_r14
4444 EX_TABLE_AMODE31(.Ldiag14_ex, .Ldiag14_fault)
45−ENDPROC(_diag14_amode31)
45+SYM_FUNC_END(_diag14_amode31)
4646
4747 /*
4848 * int _diag210_amode31(struct diag210 *addr)
4949 */
50−ENTRY(_diag210_amode31)
50+SYM_FUNC_START(_diag210_amode31)
5151 lgr %r1,%r2
5252 lhi %r2,-1
5353 sam31
@@ -60,12 +60,12 @@ ENTRY(_diag210_amode31) · 6 unmodified lines
6060 lgfr %r2,%r2
6161 BR_EX_AMODE31_r14
6262 EX_TABLE_AMODE31(.Ldiag210_ex, .Ldiag210_fault)
63−ENDPROC(_diag210_amode31)
63+SYM_FUNC_END(_diag210_amode31)
6464
6565 /*
6666 * int diag8c(struct diag8c *addr, struct ccw_dev_id *devno, size_t len)
6767 */
68−ENTRY(_diag8c_amode31)
68+SYM_FUNC_START(_diag8c_amode31)
6969 llgf %r3,0(%r3)
7070 sam31
7171 diag %r2,%r4,0x8c
@@ -74,11 +74,11 @@ ENTRY(_diag8c_amode31) · 2 unmodified lines
7474 lgfr %r2,%r3
7575 BR_EX_AMODE31_r14
7676 EX_TABLE_AMODE31(.Ldiag8c_ex, .Ldiag8c_ex)
77−ENDPROC(_diag8c_amode31)
77+SYM_FUNC_END(_diag8c_amode31)
7878 /*
7979 * int _diag26c_amode31(void *req, void *resp, enum diag26c_sc subcode)
8080 */
81−ENTRY(_diag26c_amode31)
81+SYM_FUNC_START(_diag26c_amode31)
8282 lghi %r5,-EOPNOTSUPP
8383 sam31
8484 diag %r2,%r4,0x26c
@@ -87,42 +87,42 @@ ENTRY(_diag26c_amode31) · 2 unmodified lines
8787 lgfr %r2,%r5
8888 BR_EX_AMODE31_r14
8989 EX_TABLE_AMODE31(.Ldiag26c_ex, .Ldiag26c_ex)
90−ENDPROC(_diag26c_amode31)
90+SYM_FUNC_END(_diag26c_amode31)
9191
9292 /*
9393 * void _diag0c_amode31(struct hypfs_diag0c_entry *entry)
9494 */
95−ENTRY(_diag0c_amode31)
95+SYM_FUNC_START(_diag0c_amode31)
9696 sam31
9797 diag %r2,%r2,0x0c
9898 sam64
9999 BR_EX_AMODE31_r14
100−ENDPROC(_diag0c_amode31)
100+SYM_FUNC_END(_diag0c_amode31)
101101
102102 /*
103103 * void _diag308_reset_amode31(void)
104104 *
105105 * Calls diag 308 subcode 1 and continues execution
106106 */
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
109109 stctg %c0,%c15,0(%r4)
110110 lg %r2,0(%r4) # Disable lowcore protection
111111 nilh %r2,0xefff
112− larl %r4,.Lctlreg0
112+ larl %r4,ctlreg0
113113 stg %r2,0(%r4)
114114 lctlg %c0,%c0,0(%r4)
115− larl %r4,.Lfpctl # Floating point control register
115+ larl %r4,fpctl # Floating point control register
116116 stfpc 0(%r4)
117− larl %r4,.Lprefix # Save prefix register
117+ larl %r4,prefix # Save prefix register
118118 stpx 0(%r4)
119− larl %r4,.Lprefix_zero # Set prefix register to 0
119+ larl %r4,prefix_zero # Set prefix register to 0
120120 spx 0(%r4)
121− larl %r4,.Lcontinue_psw # Save PSW flags
121+ larl %r4,continue_psw # Save PSW flags
122122 epsw %r2,%r3
123123 stm %r2,%r3,0(%r4)
124124 larl %r4,.Lrestart_part2 # Setup restart PSW at absolute 0
125− larl %r3,.Lrestart_diag308_psw
125+ larl %r3,restart_diag308_psw
126126 og %r4,0(%r3) # Save PSW
127127 lghi %r3,0
128128 sturg %r4,%r3 # Use sturg, because of large pages
@@ -134,39 +134,26 @@ ENTRY(_diag308_reset_amode31) · 5 unmodified lines
134134 lhi %r1,2 # Use mode 2 = ESAME (dump)
135135 sigp %r1,%r0,SIGP_SET_ARCHITECTURE # Switch to ESAME mode
136136 sam64 # Switch to 64 bit addressing mode
137− larl %r4,.Lctlregs # Restore control registers
137+ larl %r4,ctlregs # Restore control registers
138138 lctlg %c0,%c15,0(%r4)
139− larl %r4,.Lfpctl # Restore floating point ctl register
139+ larl %r4,fpctl # Restore floating point ctl register
140140 lfpc 0(%r4)
141− larl %r4,.Lprefix # Restore prefix register
141+ larl %r4,prefix # Restore prefix register
142142 spx 0(%r4)
143− larl %r4,.Lcontinue_psw # Restore PSW flags
143+ larl %r4,continue_psw # Restore PSW flags
144144 larl %r2,.Lcontinue
145145 stg %r2,8(%r4)
146146 lpswe 0(%r4)
147147 .Lcontinue:
148148 BR_EX_AMODE31_r14
149−ENDPROC(_diag308_reset_amode31)
149+SYM_FUNC_END(_diag308_reset_amode31)
150150
151151 .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)
arch/s390/kernel/topology.c+1−11
@@ -637,16 +637,6 @@ static struct ctl_table topology_ctl_table[] = { · 636 unmodified lines
637637 { },
638638 };
639639
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−
650640 static int __init topology_init(void)
651641 {
652642 struct device *dev_root;
@@ -657,7 +647,7 @@ static int __init topology_init(void) · 4 unmodified lines
657647 set_topology_timer();
658648 else
659649 topology_update_polarization_simple();
660− register_sysctl_table(topology_dir_table);
650+ register_sysctl("s390", topology_ctl_table);
661651
662652 dev_root = bus_get_dev_root(&cpu_subsys);
663653 if (dev_root) {
arch/s390/kernel/vdso32/vdso_user_wrapper.S+2−1
@@ -1,12 +1,13 @@
11 /* SPDX-License-Identifier: GPL-2.0 */
22
3+#include <linux/linkage.h>
34 #include <asm/unistd.h>
45 #include <asm/dwarf.h>
56
67 .macro vdso_syscall func,syscall
78 .globl __kernel_compat_\func
89 .type __kernel_compat_\func,@function
9− .align 8
10+ __ALIGN
1011 __kernel_compat_\func:
1112 CFI_STARTPROC
1213 svc \syscall
arch/s390/kernel/vdso64/vdso_user_wrapper.S+3−2
@@ -1,4 +1,5 @@
11 /* SPDX-License-Identifier: GPL-2.0 */
2+#include <linux/linkage.h>
23 #include <asm/vdso.h>
34 #include <asm/unistd.h>
45 #include <asm/asm-offsets.h>
@@ -16,7 +17,7 @@ · 11 unmodified lines
1617 .macro vdso_func func
1718 .globl __kernel_\func
1819 .type __kernel_\func,@function
19− .align 8
20+ __ALIGN
2021 __kernel_\func:
2122 CFI_STARTPROC
2223 aghi %r15,-WRAPPER_FRAME_SIZE
@@ -41,7 +42,7 @@ vdso_func getcpu · 18 unmodified lines
4142 .macro vdso_syscall func,syscall
4243 .globl __kernel_\func
4344 .type __kernel_\func,@function
44− .align 8
45+ __ALIGN
4546 __kernel_\func:
4647 CFI_STARTPROC
4748 svc \syscall
arch/s390/kernel/vmlinux.lds.S+9−1
@@ -14,6 +14,8 @@ · 13 unmodified lines
1414 #define BSS_FIRST_SECTIONS *(.bss..swapper_pg_dir) \
1515 *(.bss..invalid_pg_dir)
1616
17+#define RO_EXCEPTION_TABLE_ALIGN 16
18+
1719 /* Handle ro_after_init data on our own. */
1820 #define RO_AFTER_INIT_DATA
1921
@@ -66,7 +68,6 @@ SECTIONS · 46 unmodified lines
6668 *(.data..ro_after_init)
6769 JUMP_TABLE_DATA
6870 } :data
69− EXCEPTION_TABLE(16)
7071 . = ALIGN(PAGE_SIZE);
7172 __end_ro_after_init = .;
7273
@@ -219,6 +220,13 @@ SECTIONS · 146 unmodified lines
219220 QUAD(init_mm)
220221 QUAD(swapper_pg_dir)
221222 QUAD(invalid_pg_dir)
223+#ifdef CONFIG_KASAN
224+ QUAD(kasan_early_shadow_page)
225+ QUAD(kasan_early_shadow_pte)
226+ QUAD(kasan_early_shadow_pmd)
227+ QUAD(kasan_early_shadow_pud)
228+ QUAD(kasan_early_shadow_p4d)
229+#endif
222230 } :NONE
223231
224232 /* Debugging sections. */
arch/s390/lib/mem.S+17−11
@@ -14,8 +14,7 @@ · 13 unmodified lines
1414 /*
1515 * void *memmove(void *dest, const void *src, size_t n)
1616 */
17−WEAK(memmove)
18−ENTRY(__memmove)
17+SYM_FUNC_START(__memmove)
1918 ltgr %r4,%r4
2019 lgr %r1,%r2
2120 jz .Lmemmove_exit
@@ -48,7 +47,10 @@ ENTRY(__memmove) · 26 unmodified lines
4847 BR_EX %r14
4948 .Lmemmove_mvc:
5049 mvc 0(1,%r1),0(%r3)
51−ENDPROC(__memmove)
50+SYM_FUNC_END(__memmove)
51+EXPORT_SYMBOL(__memmove)
52+
53+SYM_FUNC_ALIAS(memmove, __memmove)
5254 EXPORT_SYMBOL(memmove)
5355
5456 /*
@@ -66,8 +68,7 @@ EXPORT_SYMBOL(memmove) · 11 unmodified lines
6668 * return __builtin_memset(s, c, n);
6769 * }
6870 */
69−WEAK(memset)
70−ENTRY(__memset)
71+SYM_FUNC_START(__memset)
7172 ltgr %r4,%r4
7273 jz .Lmemset_exit
7374 ltgr %r3,%r3
@@ -111,7 +112,10 @@ ENTRY(__memset) · 37 unmodified lines
111112 xc 0(1,%r1),0(%r1)
112113 .Lmemset_mvc:
113114 mvc 1(1,%r1),0(%r1)
114−ENDPROC(__memset)
115+SYM_FUNC_END(__memset)
116+EXPORT_SYMBOL(__memset)
117+
118+SYM_FUNC_ALIAS(memset, __memset)
115119 EXPORT_SYMBOL(memset)
116120
117121 /*
@@ -119,8 +123,7 @@ EXPORT_SYMBOL(memset) · 1 unmodified line
119123 *
120124 * void *memcpy(void *dest, const void *src, size_t n)
121125 */
122−WEAK(memcpy)
123−ENTRY(__memcpy)
126+SYM_FUNC_START(__memcpy)
124127 ltgr %r4,%r4
125128 jz .Lmemcpy_exit
126129 aghi %r4,-1
@@ -141,7 +144,10 @@ ENTRY(__memcpy) · 14 unmodified lines
141144 j .Lmemcpy_remainder
142145 .Lmemcpy_mvc:
143146 mvc 0(1,%r1),0(%r3)
144−ENDPROC(__memcpy)
147+SYM_FUNC_END(__memcpy)
148+EXPORT_SYMBOL(__memcpy)
149+
150+SYM_FUNC_ALIAS(memcpy, __memcpy)
145151 EXPORT_SYMBOL(memcpy)
146152
147153 /*
@@ -152,7 +158,7 @@ EXPORT_SYMBOL(memcpy) · 4 unmodified lines
152158 * void *__memset64(uint64_t *s, uint64_t v, size_t count)
153159 */
154160 .macro __MEMSET bits,bytes,insn
155−ENTRY(__memset\bits)
161+SYM_FUNC_START(__memset\bits)
156162 ltgr %r4,%r4
157163 jz .L__memset_exit\bits
158164 cghi %r4,\bytes
@@ -178,7 +184,7 @@ ENTRY(__memset\bits) · 19 unmodified lines
178184 BR_EX %r14
179185 .L__memset_mvc\bits:
180186 mvc \bytes(1,%r1),0(%r1)
181−ENDPROC(__memset\bits)
187+SYM_FUNC_END(__memset\bits)
182188 .endm
183189
184190 __MEMSET 16,2,sth
arch/s390/lib/uaccess.c+71−66
@@ -27,14 +27,13 @@ void debug_user_asce(int exit) · 26 unmodified lines
2727 "kernel: %016llx user: %016llx\n",
2828 exit ? "exit" : "entry", cr1, cr7,
2929 S390_lowcore.kernel_asce, S390_lowcore.user_asce);
30−
3130 }
3231 #endif /*CONFIG_DEBUG_ENTRY */
3332
3433 static unsigned long raw_copy_from_user_key(void *to, const void __user *from,
3534 unsigned long size, unsigned long key)
3635 {
37− unsigned long tmp1, tmp2;
36+ unsigned long rem;
3837 union oac spec = {
3938 .oac2.key = key,
4039 .oac2.as = PSW_BITS_AS_SECONDARY,
@@ -42,28 +41,30 @@ static unsigned long raw_copy_from_user_key(void *to, const void __user *from, · 1 unmodified line
4241 .oac2.a = 1,
4342 };
4443
45− tmp1 = -4096UL;
4644 asm volatile(
47− " lr 0,%[spec]\n"
48− "0: mvcos 0(%2),0(%1),%0\n"
49− "6: jz 4f\n"
50− "1: algr %0,%3\n"
51− " slgr %1,%3\n"
52− " slgr %2,%3\n"
53− " j 0b\n"
54− "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
55− " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
56− " slgr %4,%1\n"
57− " clgr %0,%4\n" /* copy crosses next page boundary? */
58− " jnh 5f\n"
59− "3: mvcos 0(%2),0(%1),%4\n"
60− "7: slgr %0,%4\n"
61− " j 5f\n"
62− "4: slgr %0,%0\n"
63− "5:\n"
64− EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
65− : "+a" (size), "+a" (from), "+a" (to), "+a" (tmp1), "=a" (tmp2)
66− : [spec] "d" (spec.val)
45+ " lr 0,%[spec]\n"
46+ "0: mvcos 0(%[to]),0(%[from]),%[size]\n"
47+ "1: jz 5f\n"
48+ " algr %[size],%[val]\n"
49+ " slgr %[from],%[val]\n"
50+ " slgr %[to],%[val]\n"
51+ " j 0b\n"
52+ "2: la %[rem],4095(%[from])\n" /* rem = from + 4095 */
53+ " nr %[rem],%[val]\n" /* rem = (from + 4095) & -4096 */
54+ " slgr %[rem],%[from]\n"
55+ " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */
56+ " jnh 6f\n"
57+ "3: mvcos 0(%[to]),0(%[from]),%[rem]\n"
58+ "4: slgr %[size],%[rem]\n"
59+ " j 6f\n"
60+ "5: slgr %[size],%[size]\n"
61+ "6:\n"
62+ EX_TABLE(0b, 2b)
63+ EX_TABLE(1b, 2b)
64+ EX_TABLE(3b, 6b)
65+ EX_TABLE(4b, 6b)
66+ : [size] "+&a" (size), [from] "+&a" (from), [to] "+&a" (to), [rem] "=&a" (rem)
67+ : [val] "a" (-4096UL), [spec] "d" (spec.val)
6768 : "cc", "memory", "0");
6869 return size;
6970 }
@@ -94,7 +95,7 @@ EXPORT_SYMBOL(_copy_from_user_key); · 24 unmodified lines
9495 static unsigned long raw_copy_to_user_key(void __user *to, const void *from,
9596 unsigned long size, unsigned long key)
9697 {
97− unsigned long tmp1, tmp2;
98+ unsigned long rem;
9899 union oac spec = {
99100 .oac1.key = key,
100101 .oac1.as = PSW_BITS_AS_SECONDARY,
@@ -102,28 +103,30 @@ static unsigned long raw_copy_to_user_key(void __user *to, const void *from, · 1 unmodified line
102103 .oac1.a = 1,
103104 };
104105
105− tmp1 = -4096UL;
106106 asm volatile(
107− " lr 0,%[spec]\n"
108− "0: mvcos 0(%1),0(%2),%0\n"
109− "6: jz 4f\n"
110− "1: algr %0,%3\n"
111− " slgr %1,%3\n"
112− " slgr %2,%3\n"
113− " j 0b\n"
114− "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
115− " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
116− " slgr %4,%1\n"
117− " clgr %0,%4\n" /* copy crosses next page boundary? */
118− " jnh 5f\n"
119− "3: mvcos 0(%1),0(%2),%4\n"
120− "7: slgr %0,%4\n"
121− " j 5f\n"
122− "4: slgr %0,%0\n"
123− "5:\n"
124− EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
125− : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
126− : [spec] "d" (spec.val)
107+ " lr 0,%[spec]\n"
108+ "0: mvcos 0(%[to]),0(%[from]),%[size]\n"
109+ "1: jz 5f\n"
110+ " algr %[size],%[val]\n"
111+ " slgr %[to],%[val]\n"
112+ " slgr %[from],%[val]\n"
113+ " j 0b\n"
114+ "2: la %[rem],4095(%[to])\n" /* rem = to + 4095 */
115+ " nr %[rem],%[val]\n" /* rem = (to + 4095) & -4096 */
116+ " slgr %[rem],%[to]\n"
117+ " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */
118+ " jnh 6f\n"
119+ "3: mvcos 0(%[to]),0(%[from]),%[rem]\n"
120+ "4: slgr %[size],%[rem]\n"
121+ " j 6f\n"
122+ "5: slgr %[size],%[size]\n"
123+ "6:\n"
124+ EX_TABLE(0b, 2b)
125+ EX_TABLE(1b, 2b)
126+ EX_TABLE(3b, 6b)
127+ EX_TABLE(4b, 6b)
128+ : [size] "+&a" (size), [to] "+&a" (to), [from] "+&a" (from), [rem] "=&a" (rem)
129+ : [val] "a" (-4096UL), [spec] "d" (spec.val)
127130 : "cc", "memory", "0");
128131 return size;
129132 }
@@ -147,33 +150,35 @@ EXPORT_SYMBOL(_copy_to_user_key); · 17 unmodified lines
147150
148151 unsigned long __clear_user(void __user *to, unsigned long size)
149152 {
150− unsigned long tmp1, tmp2;
153+ unsigned long rem;
151154 union oac spec = {
152155 .oac1.as = PSW_BITS_AS_SECONDARY,
153156 .oac1.a = 1,
154157 };
155158
156− tmp1 = -4096UL;
157159 asm volatile(
158− " lr 0,%[spec]\n"
159− "0: mvcos 0(%1),0(%4),%0\n"
160− "6: jz 4f\n"
161− "1: algr %0,%2\n"
162− " slgr %1,%2\n"
163− " j 0b\n"
164− "2: la %3,4095(%1)\n"/* %4 = to + 4095 */
165− " nr %3,%2\n" /* %4 = (to + 4095) & -4096 */
166− " slgr %3,%1\n"
167− " clgr %0,%3\n" /* copy crosses next page boundary? */
168− " jnh 5f\n"
169− "3: mvcos 0(%1),0(%4),%3\n"
170− "7: slgr %0,%3\n"
171− " j 5f\n"
172− "4: slgr %0,%0\n"
173− "5:\n"
174− EX_TABLE(0b,2b) EX_TABLE(6b,2b) EX_TABLE(3b,5b) EX_TABLE(7b,5b)
175− : "+&a" (size), "+&a" (to), "+a" (tmp1), "=&a" (tmp2)
176− : "a" (empty_zero_page), [spec] "d" (spec.val)
160+ " lr 0,%[spec]\n"
161+ "0: mvcos 0(%[to]),0(%[zeropg]),%[size]\n"
162+ "1: jz 5f\n"
163+ " algr %[size],%[val]\n"
164+ " slgr %[to],%[val]\n"
165+ " j 0b\n"
166+ "2: la %[rem],4095(%[to])\n" /* rem = to + 4095 */
167+ " nr %[rem],%[val]\n" /* rem = (to + 4095) & -4096 */
168+ " slgr %[rem],%[to]\n"
169+ " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */
170+ " jnh 6f\n"
171+ "3: mvcos 0(%[to]),0(%[zeropg]),%[rem]\n"
172+ "4: slgr %[size],%[rem]\n"
173+ " j 6f\n"
174+ "5: slgr %[size],%[size]\n"
175+ "6:\n"
176+ EX_TABLE(0b, 2b)
177+ EX_TABLE(1b, 2b)
178+ EX_TABLE(3b, 6b)
179+ EX_TABLE(4b, 6b)
180+ : [size] "+&a" (size), [to] "+&a" (to), [rem] "=&a" (rem)
181+ : [val] "a" (-4096UL), [zeropg] "a" (empty_zero_page), [spec] "d" (spec.val)
177182 : "cc", "memory", "0");
178183 return size;
179184 }
arch/s390/mm/Makefile+0−3
@@ -10,6 +10,3 @@ obj-$(CONFIG_CMM) += cmm.o · 9 unmodified lines
1010 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
1111 obj-$(CONFIG_PTDUMP_CORE) += dump_pagetables.o
1212 obj-$(CONFIG_PGSTE) += gmap.o
13−
14−KASAN_SANITIZE_kasan_init.o := n
15−obj-$(CONFIG_KASAN) += kasan_init.o
arch/s390/mm/cmm.c+1−11
@@ -335,16 +335,6 @@ static struct ctl_table cmm_table[] = { · 334 unmodified lines
335335 { }
336336 };
337337
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−
348338 #ifdef CONFIG_CMM_IUCV
349339 #define SMSG_PREFIX "CMM"
350340 static void cmm_smsg_target(const char *from, char *msg)
@@ -389,7 +379,7 @@ static int __init cmm_init(void) · 38 unmodified lines
389379 {
390380 int rc = -ENOMEM;
391381
392− cmm_sysctl_header = register_sysctl_table(cmm_dir_table);
382+ cmm_sysctl_header = register_sysctl("vm", cmm_table);
393383 if (!cmm_sysctl_header)
394384 goto out_sysctl;
395385 #ifdef CONFIG_CMM_IUCV
arch/s390/mm/init.c+2−3
@@ -176,9 +176,8 @@ void __init mem_init(void) · 175 unmodified lines
176176
177177 void free_initmem(void)
178178 {
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);
182181 free_initmem_default(POISON_FREE_INITMEM);
183182 }
184183
arch/s390/mm/kasan_init.c+0−301
@@ -1,301 +0,0 @@
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−}
arch/s390/mm/pageattr.c+86−8
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
55 */
66 #include <linux/hugetlb.h>
7+#include <linux/vmalloc.h>
78 #include <linux/mm.h>
89 #include <asm/cacheflush.h>
910 #include <asm/facility.h>
@@ -41,7 +42,7 @@ void __storage_key_init_range(unsigned long start, unsigned long end) · 31 unmodified lines
4142 }
4243
4344 #ifdef CONFIG_PROC_FS
44−atomic_long_t direct_pages_count[PG_DIRECT_MAP_MAX];
45+atomic_long_t __bootdata_preserved(direct_pages_count[PG_DIRECT_MAP_MAX]);
4546
4647 void arch_report_meminfo(struct seq_file *m)
4748 {
@@ -101,6 +102,14 @@ static int walk_pte_level(pmd_t *pmdp, unsigned long addr, unsigned long end, · 53 unmodified lines
101102 new = set_pte_bit(new, __pgprot(_PAGE_NOEXEC));
102103 else if (flags & SET_MEMORY_X)
103104 new = clear_pte_bit(new, __pgprot(_PAGE_NOEXEC));
105+ if (flags & SET_MEMORY_INV) {
106+ new = set_pte_bit(new, __pgprot(_PAGE_INVALID));
107+ } else if (flags & SET_MEMORY_DEF) {
108+ new = __pte(pte_val(new) & PAGE_MASK);
109+ new = set_pte_bit(new, PAGE_KERNEL);
110+ if (!MACHINE_HAS_NX)
111+ new = clear_pte_bit(new, __pgprot(_PAGE_NOEXEC));
112+ }
104113 pgt_set((unsigned long *)ptep, pte_val(new), addr, CRDTE_DTT_PAGE);
105114 ptep++;
106115 addr += PAGE_SIZE;
@@ -151,6 +160,14 @@ static void modify_pmd_page(pmd_t *pmdp, unsigned long addr, · 44 unmodified lines
151160 new = set_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_NOEXEC));
152161 else if (flags & SET_MEMORY_X)
153162 new = clear_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_NOEXEC));
163+ if (flags & SET_MEMORY_INV) {
164+ new = set_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_INVALID));
165+ } else if (flags & SET_MEMORY_DEF) {
166+ new = __pmd(pmd_val(new) & PMD_MASK);
167+ new = set_pmd_bit(new, SEGMENT_KERNEL);
168+ if (!MACHINE_HAS_NX)
169+ new = clear_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_NOEXEC));
170+ }
154171 pgt_set((unsigned long *)pmdp, pmd_val(new), addr, CRDTE_DTT_SEGMENT);
155172 }
156173
@@ -232,6 +249,14 @@ static void modify_pud_page(pud_t *pudp, unsigned long addr, · 75 unmodified lines
232249 new = set_pud_bit(new, __pgprot(_REGION_ENTRY_NOEXEC));
233250 else if (flags & SET_MEMORY_X)
234251 new = clear_pud_bit(new, __pgprot(_REGION_ENTRY_NOEXEC));
252+ if (flags & SET_MEMORY_INV) {
253+ new = set_pud_bit(new, __pgprot(_REGION_ENTRY_INVALID));
254+ } else if (flags & SET_MEMORY_DEF) {
255+ new = __pud(pud_val(new) & PUD_MASK);
256+ new = set_pud_bit(new, REGION3_KERNEL);
257+ if (!MACHINE_HAS_NX)
258+ new = clear_pud_bit(new, __pgprot(_REGION_ENTRY_NOEXEC));
259+ }
235260 pgt_set((unsigned long *)pudp, pud_val(new), addr, CRDTE_DTT_REGION3);
236261 }
237262
@@ -298,11 +323,6 @@ static int change_page_attr(unsigned long addr, unsigned long end, · 60 unmodified lines
298323 int rc = -EINVAL;
299324 pgd_t *pgdp;
300325
301− if (addr == end)
302− return 0;
303− if (end >= MODULES_END)
304− return -EINVAL;
305− mutex_lock(&cpa_mutex);
306326 pgdp = pgd_offset_k(addr);
307327 do {
308328 if (pgd_none(*pgdp))
@@ -313,18 +333,76 @@ static int change_page_attr(unsigned long addr, unsigned long end, · 4 unmodified lines
313333 break;
314334 cond_resched();
315335 } while (pgdp++, addr = next, addr < end && !rc);
316− mutex_unlock(&cpa_mutex);
336+ return rc;
337+}
338+
339+static int change_page_attr_alias(unsigned long addr, unsigned long end,
340+ unsigned long flags)
341+{
342+ unsigned long alias, offset, va_start, va_end;
343+ struct vm_struct *area;
344+ int rc = 0;
345+
346+ /*
347+ * Changes to read-only permissions on kernel VA mappings are also
348+ * applied to the kernel direct mapping. Execute permissions are
349+ * intentionally not transferred to keep all allocated pages within
350+ * the direct mapping non-executable.
351+ */
352+ flags &= SET_MEMORY_RO | SET_MEMORY_RW;
353+ if (!flags)
354+ return 0;
355+ area = NULL;
356+ while (addr < end) {
357+ if (!area)
358+ area = find_vm_area((void *)addr);
359+ if (!area || !(area->flags & VM_ALLOC))
360+ return 0;
361+ va_start = (unsigned long)area->addr;
362+ va_end = va_start + area->nr_pages * PAGE_SIZE;
363+ offset = (addr - va_start) >> PAGE_SHIFT;
364+ alias = (unsigned long)page_address(area->pages[offset]);
365+ rc = change_page_attr(alias, alias + PAGE_SIZE, flags);
366+ if (rc)
367+ break;
368+ addr += PAGE_SIZE;
369+ if (addr >= va_end)
370+ area = NULL;
371+ }
317372 return rc;
318373 }
319374
320375 int __set_memory(unsigned long addr, int numpages, unsigned long flags)
321376 {
377+ unsigned long end;
378+ int rc;
379+
322380 if (!MACHINE_HAS_NX)
323381 flags &= ~(SET_MEMORY_NX | SET_MEMORY_X);
324382 if (!flags)
325383 return 0;
384+ if (!numpages)
385+ return 0;
326386 addr &= PAGE_MASK;
327− return change_page_attr(addr, addr + numpages * PAGE_SIZE, flags);
387+ end = addr + numpages * PAGE_SIZE;
388+ mutex_lock(&cpa_mutex);
389+ rc = change_page_attr(addr, end, flags);
390+ if (rc)
391+ goto out;
392+ rc = change_page_attr_alias(addr, end, flags);
393+out:
394+ mutex_unlock(&cpa_mutex);
395+ return rc;
396+}
397+
398+int set_direct_map_invalid_noflush(struct page *page)
399+{
400+ return __set_memory((unsigned long)page_to_virt(page), 1, SET_MEMORY_INV);
401+}
402+
403+int set_direct_map_default_noflush(struct page *page)
404+{
405+ return __set_memory((unsigned long)page_to_virt(page), 1, SET_MEMORY_DEF);
328406 }
329407
330408 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE)
arch/s390/mm/pgalloc.c+2−18
@@ -33,19 +33,9 @@ static struct ctl_table page_table_sysctl[] = { · 32 unmodified lines
3333 { }
3434 };
3535
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−
4636 static int __init page_table_register_sysctl(void)
4737 {
48− return register_sysctl_table(page_table_sysctl_dir) ? 0 : -ENOMEM;
38+ return register_sysctl("vm", page_table_sysctl) ? 0 : -ENOMEM;
4939 }
5040 __initcall(page_table_register_sysctl);
5141
@@ -143,13 +133,7 @@ err_p4d: · 91 unmodified lines
143133
144134 static inline unsigned int atomic_xor_bits(atomic_t *v, unsigned int bits)
145135 {
146− unsigned int old, new;
147−
148− do {
149− old = atomic_read(v);
150− new = old ^ bits;
151− } while (atomic_cmpxchg(v, old, new) != old);
152− return new;
136+ return atomic_fetch_xor(bits, v) ^ bits;
153137 }
154138
155139 #ifdef CONFIG_PGSTE
arch/s390/mm/vmem.c+20−15
@@ -5,6 +5,7 @@ · 4 unmodified lines
55
66 #include <linux/memory_hotplug.h>
77 #include <linux/memblock.h>
8+#include <linux/kasan.h>
89 #include <linux/pfn.h>
910 #include <linux/mm.h>
1011 #include <linux/init.h>
@@ -664,6 +665,9 @@ static void __init memblock_region_swap(void *a, void *b, int size) · 653 unmodified lines
664665 swap(*(struct memblock_region *)a, *(struct memblock_region *)b);
665666 }
666667
668+#ifdef CONFIG_KASAN
669+#define __sha(x) ((unsigned long)kasan_mem_to_shadow((void *)x))
670+#endif
667671 /*
668672 * map whole physical memory to virtual memory (identity mapping)
669673 * we reserve enough space in the vmalloc area for vmemmap to hotplug
@@ -728,23 +732,24 @@ void __init vmem_map_init(void) · 58 unmodified lines
728732 memblock_region_cmp, memblock_region_swap);
729733 __for_each_mem_range(i, &memblock.memory, &memory_rwx,
730734 NUMA_NO_NODE, MEMBLOCK_NONE, &base, &end, NULL) {
731− __set_memory((unsigned long)__va(base),
732− (end - base) >> PAGE_SHIFT,
733− SET_MEMORY_RW | SET_MEMORY_NX);
735+ set_memory_rwnx((unsigned long)__va(base),
736+ (end - base) >> PAGE_SHIFT);
734737 }
735738
736− __set_memory((unsigned long)_stext,
737− (unsigned long)(_etext - _stext) >> PAGE_SHIFT,
738− SET_MEMORY_RO | SET_MEMORY_X);
739− __set_memory((unsigned long)_etext,
740− (unsigned long)(__end_rodata - _etext) >> PAGE_SHIFT,
741− SET_MEMORY_RO);
742− __set_memory((unsigned long)_sinittext,
743− (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT,
744− SET_MEMORY_RO | SET_MEMORY_X);
745− __set_memory(__stext_amode31,
746− (__etext_amode31 - __stext_amode31) >> PAGE_SHIFT,
747− SET_MEMORY_RO | SET_MEMORY_X);
739+#ifdef CONFIG_KASAN
740+ for_each_mem_range(i, &base, &end) {
741+ set_memory_rwnx(__sha(base),
742+ (__sha(end) - __sha(base)) >> PAGE_SHIFT);
743+ }
744+#endif
745+ set_memory_rox((unsigned long)_stext,
746+ (unsigned long)(_etext - _stext) >> PAGE_SHIFT);
747+ set_memory_ro((unsigned long)_etext,
748+ (unsigned long)(__end_rodata - _etext) >> PAGE_SHIFT);
749+ set_memory_rox((unsigned long)_sinittext,
750+ (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT);
751+ set_memory_rox(__stext_amode31,
752+ (__etext_amode31 - __stext_amode31) >> PAGE_SHIFT);
748753
749754 /* lowcore must be executable for LPSWE */
750755 if (static_key_enabled(&cpu_has_bear))
arch/s390/pci/pci.c+3−20
@@ -874,32 +874,15 @@ bool zpci_is_device_configured(struct zpci_dev *zdev) · 873 unmodified lines
874874 * @fh: The general function handle supplied by the platform
875875 *
876876 * 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.
881879 *
882880 * Return: 0 on success, or an error code otherwise
883881 */
884882 int zpci_scan_configured_device(struct zpci_dev *zdev, u32 fh)
885883 {
886− int rc;
887−
888884 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);
903886 }
904887
905888 /**
arch/s390/pci/pci_bus.c+3−8
@@ -85,9 +85,8 @@ int zpci_bus_scan_device(struct zpci_dev *zdev) · 84 unmodified lines
8585 if (!pdev)
8686 return -ENODEV;
8787
88− pci_bus_add_device(pdev);
8988 pci_lock_rescan_remove();
90− pci_bus_add_devices(zdev->zbus->bus);
89+ pci_bus_add_device(pdev);
9190 pci_unlock_rescan_remove();
9291
9392 return 0;
@@ -130,11 +129,8 @@ void zpci_bus_remove_device(struct zpci_dev *zdev, bool set_error) · 36 unmodified lines
130129 * @zbus: the zbus to be scanned
131130 *
132131 * Enables and scans all PCI functions on the bus making them available to the
133− * common PCI code. If there is no function 0 on the zbus nothing is scanned. If
134− * a function does not have a slot yet because it was added to the zbus before
135− * function 0 the slot is created. If a PCI function fails to be initialized
136− * an error will be returned but attempts will still be made for all other
137− * functions on the bus.
132+ * common PCI code. If a PCI function fails to be initialized an error will be
133+ * returned but attempts will still be made for all other functions on the bus.
138134 *
139135 * Return: 0 on success, an error value otherwise
140136 */
@@ -211,7 +207,6 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · 70 unmodified lines
211207 }
212208
213209 zbus->bus = bus;
214− pci_bus_add_devices(bus);
215210
216211 return 0;
217212 }
arch/s390/purgatory/head.S+19−43
@@ -76,9 +76,9 @@ · 75 unmodified lines
7676 diag %r0,%r1,0x308
7777 .endm
7878
79−.text
80−.align PAGE_SIZE
81−ENTRY(purgatory_start)
79+ .text
80+ .balign PAGE_SIZE
81+SYM_CODE_START(purgatory_start)
8282 /* The purgatory might be called after a diag308 so better set
8383 * architecture and addressing mode.
8484 */
@@ -245,45 +245,21 @@ ENTRY(purgatory_start) · 160 unmodified lines
245245
246246 /* start crash kernel */
247247 START_NEXT_KERNEL .base_dst 1
248−
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:
248+SYM_CODE_END(purgatory_start)
249+
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)
286262 /* The buffer to move this code must be as big as the code. */
287263 .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)
arch/s390/purgatory/kexec-purgatory.S+6−8
@@ -1,14 +1,12 @@
11 /* SPDX-License-Identifier: GPL-2.0 */
2+#include <linux/linkage.h>
23
34 .section .rodata, "a"
45
5− .align 8
6−kexec_purgatory:
7− .globl kexec_purgatory
6+ .balign 8
7+SYM_DATA_START(kexec_purgatory)
88 .incbin "arch/s390/purgatory/purgatory.ro"
9−.Lkexec_purgatroy_end:
9+SYM_DATA_END_LABEL(kexec_purgatory, SYM_L_LOCAL, kexec_purgatory_end)
1010
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)
drivers/s390/char/sclp.h+1−1
@@ -204,7 +204,7 @@ struct read_storage_sccb { · 203 unmodified lines
204204 u16 assigned;
205205 u16 standby;
206206 u16 :16;
207− u32 entries[0];
207+ u32 entries[];
208208 } __packed;
209209
210210 static inline void sclp_fill_core_info(struct sclp_core_info *info,
drivers/s390/char/sclp_cmd.c+1−1
@@ -241,7 +241,7 @@ struct attach_storage_sccb { · 240 unmodified lines
241241 u16 :16;
242242 u16 assigned;
243243 u32 :32;
244− u32 entries[0];
244+ u32 entries[];
245245 } __packed;
246246
247247 static int sclp_attach_storage(u8 id)
drivers/s390/char/sclp_early_core.c+4−4
@@ -10,7 +10,7 @@ · 9 unmodified lines
1010 #include <asm/ebcdic.h>
1111 #include <asm/irq.h>
1212 #include <asm/sections.h>
13−#include <asm/mem_detect.h>
13+#include <asm/physmem_info.h>
1414 #include <asm/facility.h>
1515 #include "sclp.h"
1616 #include "sclp_rw.h"
@@ -336,7 +336,7 @@ int __init sclp_early_get_hsa_size(unsigned long *hsa_size) · 319 unmodified lines
336336
337337 #define SCLP_STORAGE_INFO_FACILITY 0x0000400000000000UL
338338
339−void __weak __init add_mem_detect_block(u64 start, u64 end) {}
339+void __weak __init add_physmem_online_range(u64 start, u64 end) {}
340340 int __init sclp_early_read_storage_info(void)
341341 {
342342 struct read_storage_sccb *sccb = (struct read_storage_sccb *)sclp_early_sccb;
@@ -369,7 +369,7 @@ int __init sclp_early_read_storage_info(void) · 26 unmodified lines
369369 if (!sccb->entries[sn])
370370 continue;
371371 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);
373373 }
374374 break;
375375 case 0x0310:
@@ -382,6 +382,6 @@ int __init sclp_early_read_storage_info(void) · 6 unmodified lines
382382
383383 return 0;
384384 fail:
385− mem_detect.count = 0;
385+ physmem_info.range_count = 0;
386386 return -EIO;
387387 }
drivers/s390/cio/chsc.c+1−1
@@ -1171,7 +1171,7 @@ int __init chsc_get_cssid_iid(int idx, u8 *cssid, u8 *iid) · 1170 unmodified lines
11711171 u8 cssid;
11721172 u8 iid;
11731173 u32 : 16;
1174− } list[0];
1174+ } list[];
11751175 } *sdcal_area;
11761176 int ret;
11771177
drivers/s390/cio/chsc.h+1−1
@@ -120,7 +120,7 @@ struct chsc_scpd { · 119 unmodified lines
120120 u32 zeroes1;
121121 struct chsc_header response;
122122 u32:32;
123− u8 data[0];
123+ u8 data[];
124124 } __packed __aligned(PAGE_SIZE);
125125
126126 struct chsc_sda_area {
drivers/s390/crypto/ap_bus.c+151−103
@@ -122,7 +122,13 @@ static struct hrtimer ap_poll_timer; · 121 unmodified lines
122122 * In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
123123 * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.
124124 */
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;
126132
127133 /* Maximum domain id, if not given via qci */
128134 static int ap_max_domain_id = 15;
@@ -200,6 +206,18 @@ static inline int ap_qact_available(void) · 71 unmodified lines
200206 return 0;
201207 }
202208
209+/*
210+ * ap_sb_available(): Test if the AP secure binding facility is available.
211+ *
212+ * Returns 1 if secure binding facility is available.
213+ */
214+int ap_sb_available(void)
215+{
216+ if (ap_qci_info)
217+ return ap_qci_info->apsb;
218+ return 0;
219+}
220+
203221 /*
204222 * ap_fetch_qci_info(): Fetch cryptographic config info
205223 *
@@ -248,13 +266,13 @@ static void __init ap_init_qci_info(void) · 42 unmodified lines
248266 AP_DBF_INFO("%s successful fetched initial qci info\n", __func__);
249267
250268 if (ap_qci_info->apxa) {
251− if (ap_qci_info->Na) {
252− ap_max_adapter_id = ap_qci_info->Na;
269+ if (ap_qci_info->na) {
270+ ap_max_adapter_id = ap_qci_info->na;
253271 AP_DBF_INFO("%s new ap_max_adapter_id is %d\n",
254272 __func__, ap_max_adapter_id);
255273 }
256− if (ap_qci_info->Nd) {
257− ap_max_domain_id = ap_qci_info->Nd;
274+ if (ap_qci_info->nd) {
275+ ap_max_domain_id = ap_qci_info->nd;
258276 AP_DBF_INFO("%s new ap_max_domain_id is %d\n",
259277 __func__, ap_max_domain_id);
260278 }
@@ -324,35 +342,32 @@ EXPORT_SYMBOL(ap_test_config_ctrl_domain); · 63 unmodified lines
324342
325343 /*
326344 * ap_queue_info(): Check and get AP queue info.
327− * Returns true if TAPQ succeeded and the info is filled or
328− * false otherwise.
345+ * Returns: 1 if APQN exists and info is filled,
346+ * 0 if APQN seems to exit but there is no info
347+ * available (eg. caused by an asynch pending error)
348+ * -1 invalid APQN, TAPQ error or AP queue status which
349+ * indicates there is no APQN.
329350 */
330−static bool ap_queue_info(ap_qid_t qid, int *q_type, unsigned int *q_fac,
331− int *q_depth, int *q_ml, bool *q_decfg, bool *q_cstop)
351+static int ap_queue_info(ap_qid_t qid, int *q_type, unsigned int *q_fac,
352+ int *q_depth, int *q_ml, bool *q_decfg, bool *q_cstop)
332353 {
333354 struct ap_queue_status status;
334− union {
335− unsigned long value;
336− struct {
337− unsigned int fac : 32; /* facility bits */
338− unsigned int at : 8; /* ap type */
339− unsigned int _res1 : 8;
340− unsigned int _res2 : 4;
341− unsigned int ml : 4; /* apxl ml */
342− unsigned int _res3 : 4;
343− unsigned int qd : 4; /* queue depth */
344− } tapq_gr2;
345− } tapq_info;
355+ struct ap_tapq_gr2 tapq_info;
346356
347357 tapq_info.value = 0;
348358
349359 /* make sure we don't run into a specifiation exception */
350360 if (AP_QID_CARD(qid) > ap_max_adapter_id ||
351361 AP_QID_QUEUE(qid) > ap_max_domain_id)
352− return false;
362+ return -1;
353363
354364 /* call TAPQ on this APQN */
355− status = ap_test_queue(qid, ap_apft_available(), &tapq_info.value);
365+ status = ap_test_queue(qid, ap_apft_available(), &tapq_info);
366+
367+ /* handle pending async error with return 'no info available' */
368+ if (status.async)
369+ return 0;
370+
356371 switch (status.response_code) {
357372 case AP_RESPONSE_NORMAL:
358373 case AP_RESPONSE_RESET_IN_PROGRESS:
@@ -365,11 +380,11 @@ static bool ap_queue_info(ap_qid_t qid, int *q_type, unsigned int *q_fac, · 6 unmodified lines
365380 * there is at least one of the mode bits set.
366381 */
367382 if (WARN_ON_ONCE(!tapq_info.value))
368− return false;
369− *q_type = tapq_info.tapq_gr2.at;
370− *q_fac = tapq_info.tapq_gr2.fac;
371− *q_depth = tapq_info.tapq_gr2.qd;
372− *q_ml = tapq_info.tapq_gr2.ml;
383+ return 0;
384+ *q_type = tapq_info.at;
385+ *q_fac = tapq_info.fac;
386+ *q_depth = tapq_info.qd;
387+ *q_ml = tapq_info.ml;
373388 *q_decfg = status.response_code == AP_RESPONSE_DECONFIGURED;
374389 *q_cstop = status.response_code == AP_RESPONSE_CHECKSTOPPED;
375390 switch (*q_type) {
@@ -389,12 +404,12 @@ static bool ap_queue_info(ap_qid_t qid, int *q_type, unsigned int *q_fac, · 13 unmodified lines
389404 default:
390405 break;
391406 }
392− return true;
407+ return 1;
393408 default:
394409 /*
395410 * A response code which indicates, there is no info available.
396411 */
397− return false;
412+ return -1;
398413 }
399414 }
400415
@@ -412,10 +427,13 @@ void ap_wait(enum ap_sm_wait wait) · 11 unmodified lines
412427 break;
413428 }
414429 fallthrough;
415− case AP_SM_WAIT_TIMEOUT:
430+ case AP_SM_WAIT_LOW_TIMEOUT:
431+ case AP_SM_WAIT_HIGH_TIMEOUT:
416432 spin_lock_bh(&ap_poll_timer_lock);
417433 if (!hrtimer_is_queued(&ap_poll_timer)) {
418− hr_time = poll_timeout;
434+ hr_time =
435+ wait == AP_SM_WAIT_LOW_TIMEOUT ?
436+ poll_low_timeout : poll_high_timeout;
419437 hrtimer_forward_now(&ap_poll_timer, hr_time);
420438 hrtimer_restart(&ap_poll_timer);
421439 }
@@ -1168,7 +1186,7 @@ EXPORT_SYMBOL(ap_parse_mask_str); · 746 unmodified lines
11681186
11691187 static ssize_t ap_domain_show(const struct bus_type *bus, char *buf)
11701188 {
1171− return scnprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
1189+ return sysfs_emit(buf, "%d\n", ap_domain_index);
11721190 }
11731191
11741192 static ssize_t ap_domain_store(const struct bus_type *bus,
@@ -1196,14 +1214,13 @@ static BUS_ATTR_RW(ap_domain); · 21 unmodified lines
11961214 static ssize_t ap_control_domain_mask_show(const struct bus_type *bus, char *buf)
11971215 {
11981216 if (!ap_qci_info) /* QCI not supported */
1199− return scnprintf(buf, PAGE_SIZE, "not supported\n");
1217+ return sysfs_emit(buf, "not supported\n");
12001218
1201− return scnprintf(buf, PAGE_SIZE,
1202− "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1203− ap_qci_info->adm[0], ap_qci_info->adm[1],
1204− ap_qci_info->adm[2], ap_qci_info->adm[3],
1205− ap_qci_info->adm[4], ap_qci_info->adm[5],
1206− ap_qci_info->adm[6], ap_qci_info->adm[7]);
1219+ return sysfs_emit(buf, "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1220+ ap_qci_info->adm[0], ap_qci_info->adm[1],
1221+ ap_qci_info->adm[2], ap_qci_info->adm[3],
1222+ ap_qci_info->adm[4], ap_qci_info->adm[5],
1223+ ap_qci_info->adm[6], ap_qci_info->adm[7]);
12071224 }
12081225
12091226 static BUS_ATTR_RO(ap_control_domain_mask);
@@ -1211,14 +1228,13 @@ static BUS_ATTR_RO(ap_control_domain_mask); · 1 unmodified line
12111228 static ssize_t ap_usage_domain_mask_show(const struct bus_type *bus, char *buf)
12121229 {
12131230 if (!ap_qci_info) /* QCI not supported */
1214− return scnprintf(buf, PAGE_SIZE, "not supported\n");
1231+ return sysfs_emit(buf, "not supported\n");
12151232
1216− return scnprintf(buf, PAGE_SIZE,
1217− "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1218− ap_qci_info->aqm[0], ap_qci_info->aqm[1],
1219− ap_qci_info->aqm[2], ap_qci_info->aqm[3],
1220− ap_qci_info->aqm[4], ap_qci_info->aqm[5],
1221− ap_qci_info->aqm[6], ap_qci_info->aqm[7]);
1233+ return sysfs_emit(buf, "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1234+ ap_qci_info->aqm[0], ap_qci_info->aqm[1],
1235+ ap_qci_info->aqm[2], ap_qci_info->aqm[3],
1236+ ap_qci_info->aqm[4], ap_qci_info->aqm[5],
1237+ ap_qci_info->aqm[6], ap_qci_info->aqm[7]);
12221238 }
12231239
12241240 static BUS_ATTR_RO(ap_usage_domain_mask);
@@ -1226,29 +1242,27 @@ static BUS_ATTR_RO(ap_usage_domain_mask); · 1 unmodified line
12261242 static ssize_t ap_adapter_mask_show(const struct bus_type *bus, char *buf)
12271243 {
12281244 if (!ap_qci_info) /* QCI not supported */
1229− return scnprintf(buf, PAGE_SIZE, "not supported\n");
1245+ return sysfs_emit(buf, "not supported\n");
12301246
1231− return scnprintf(buf, PAGE_SIZE,
1232− "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1233− ap_qci_info->apm[0], ap_qci_info->apm[1],
1234− ap_qci_info->apm[2], ap_qci_info->apm[3],
1235− ap_qci_info->apm[4], ap_qci_info->apm[5],
1236− ap_qci_info->apm[6], ap_qci_info->apm[7]);
1247+ return sysfs_emit(buf, "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1248+ ap_qci_info->apm[0], ap_qci_info->apm[1],
1249+ ap_qci_info->apm[2], ap_qci_info->apm[3],
1250+ ap_qci_info->apm[4], ap_qci_info->apm[5],
1251+ ap_qci_info->apm[6], ap_qci_info->apm[7]);
12371252 }
12381253
12391254 static BUS_ATTR_RO(ap_adapter_mask);
12401255
12411256 static ssize_t ap_interrupts_show(const struct bus_type *bus, char *buf)
12421257 {
1243− return scnprintf(buf, PAGE_SIZE, "%d\n",
1244− ap_irq_flag ? 1 : 0);
1258+ return sysfs_emit(buf, "%d\n", ap_irq_flag ? 1 : 0);
12451259 }
12461260
12471261 static BUS_ATTR_RO(ap_interrupts);
12481262
12491263 static ssize_t config_time_show(const struct bus_type *bus, char *buf)
12501264 {
1251− return scnprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
1265+ return sysfs_emit(buf, "%d\n", ap_config_time);
12521266 }
12531267
12541268 static ssize_t config_time_store(const struct bus_type *bus,
@@ -1267,17 +1281,20 @@ static BUS_ATTR_RW(config_time); · 12 unmodified lines
12671281
12681282 static ssize_t poll_thread_show(const struct bus_type *bus, char *buf)
12691283 {
1270− return scnprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
1284+ return sysfs_emit(buf, "%d\n", ap_poll_kthread ? 1 : 0);
12711285 }
12721286
12731287 static ssize_t poll_thread_store(const struct bus_type *bus,
12741288 const char *buf, size_t count)
12751289 {
1276− int flag, rc;
1290+ bool value;
1291+ int rc;
12771292
1278− if (sscanf(buf, "%d\n", &flag) != 1)
1279− return -EINVAL;
1280− if (flag) {
1293+ rc = kstrtobool(buf, &value);
1294+ if (rc)
1295+ return rc;
1296+
1297+ if (value) {
12811298 rc = ap_poll_thread_start();
12821299 if (rc)
12831300 count = rc;
@@ -1291,21 +1308,25 @@ static BUS_ATTR_RW(poll_thread); · 7 unmodified lines
12911308
12921309 static ssize_t poll_timeout_show(const struct bus_type *bus, char *buf)
12931310 {
1294− return scnprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
1311+ return sysfs_emit(buf, "%lu\n", poll_high_timeout);
12951312 }
12961313
12971314 static ssize_t poll_timeout_store(const struct bus_type *bus, const char *buf,
12981315 size_t count)
12991316 {
1300− unsigned long long time;
1317+ unsigned long value;
13011318 ktime_t hr_time;
1319+ int rc;
1320+
1321+ rc = kstrtoul(buf, 0, &value);
1322+ if (rc)
1323+ return rc;
13021324
13031325 /* 120 seconds = maximum poll interval */
1304− if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
1305− time > 120000000000ULL)
1326+ if (value > 120000000000UL)
13061327 return -EINVAL;
1307− poll_timeout = time;
1308− hr_time = poll_timeout;
1328+ poll_high_timeout = value;
1329+ hr_time = poll_high_timeout;
13091330
13101331 spin_lock_bh(&ap_poll_timer_lock);
13111332 hrtimer_cancel(&ap_poll_timer);
@@ -1320,14 +1341,14 @@ static BUS_ATTR_RW(poll_timeout); · 8 unmodified lines
13201341
13211342 static ssize_t ap_max_domain_id_show(const struct bus_type *bus, char *buf)
13221343 {
1323− return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_domain_id);
1344+ return sysfs_emit(buf, "%d\n", ap_max_domain_id);
13241345 }
13251346
13261347 static BUS_ATTR_RO(ap_max_domain_id);
13271348
13281349 static ssize_t ap_max_adapter_id_show(const struct bus_type *bus, char *buf)
13291350 {
1330− return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_adapter_id);
1351+ return sysfs_emit(buf, "%d\n", ap_max_adapter_id);
13311352 }
13321353
13331354 static BUS_ATTR_RO(ap_max_adapter_id);
@@ -1338,10 +1359,9 @@ static ssize_t apmask_show(const struct bus_type *bus, char *buf) · 4 unmodified lines
13381359
13391360 if (mutex_lock_interruptible(&ap_perms_mutex))
13401361 return -ERESTARTSYS;
1341− rc = scnprintf(buf, PAGE_SIZE,
1342− "0x%016lx%016lx%016lx%016lx\n",
1343− ap_perms.apm[0], ap_perms.apm[1],
1344− ap_perms.apm[2], ap_perms.apm[3]);
1362+ rc = sysfs_emit(buf, "0x%016lx%016lx%016lx%016lx\n",
1363+ ap_perms.apm[0], ap_perms.apm[1],
1364+ ap_perms.apm[2], ap_perms.apm[3]);
13451365 mutex_unlock(&ap_perms_mutex);
13461366
13471367 return rc;
@@ -1431,10 +1451,9 @@ static ssize_t aqmask_show(const struct bus_type *bus, char *buf) · 83 unmodified lines
14311451
14321452 if (mutex_lock_interruptible(&ap_perms_mutex))
14331453 return -ERESTARTSYS;
1434− rc = scnprintf(buf, PAGE_SIZE,
1435− "0x%016lx%016lx%016lx%016lx\n",
1436− ap_perms.aqm[0], ap_perms.aqm[1],
1437− ap_perms.aqm[2], ap_perms.aqm[3]);
1454+ rc = sysfs_emit(buf, "0x%016lx%016lx%016lx%016lx\n",
1455+ ap_perms.aqm[0], ap_perms.aqm[1],
1456+ ap_perms.aqm[2], ap_perms.aqm[3]);
14381457 mutex_unlock(&ap_perms_mutex);
14391458
14401459 return rc;
@@ -1520,8 +1539,7 @@ static BUS_ATTR_RW(aqmask); · 79 unmodified lines
15201539
15211540 static ssize_t scans_show(const struct bus_type *bus, char *buf)
15221541 {
1523− return scnprintf(buf, PAGE_SIZE, "%llu\n",
1524− atomic64_read(&ap_scan_bus_count));
1542+ return sysfs_emit(buf, "%llu\n", atomic64_read(&ap_scan_bus_count));
15251543 }
15261544
15271545 static ssize_t scans_store(const struct bus_type *bus, const char *buf,
@@ -1543,15 +1561,40 @@ static ssize_t bindings_show(const struct bus_type *bus, char *buf) · 15 unmodified lines
15431561
15441562 ap_calc_bound_apqns(&apqns, &n);
15451563 if (atomic64_read(&ap_scan_bus_count) >= 1 && n == apqns)
1546− rc = scnprintf(buf, PAGE_SIZE, "%u/%u (complete)\n", n, apqns);
1564+ rc = sysfs_emit(buf, "%u/%u (complete)\n", n, apqns);
15471565 else
1548− rc = scnprintf(buf, PAGE_SIZE, "%u/%u\n", n, apqns);
1566+ rc = sysfs_emit(buf, "%u/%u\n", n, apqns);
15491567
15501568 return rc;
15511569 }
15521570
15531571 static BUS_ATTR_RO(bindings);
15541572
1573+static ssize_t features_show(const struct bus_type *bus, char *buf)
1574+{
1575+ int n = 0;
1576+
1577+ if (!ap_qci_info) /* QCI not supported */
1578+ return sysfs_emit(buf, "-\n");
1579+
1580+ if (ap_qci_info->apsc)
1581+ n += sysfs_emit_at(buf, n, "APSC ");
1582+ if (ap_qci_info->apxa)
1583+ n += sysfs_emit_at(buf, n, "APXA ");
1584+ if (ap_qci_info->qact)
1585+ n += sysfs_emit_at(buf, n, "QACT ");
1586+ if (ap_qci_info->rc8a)
1587+ n += sysfs_emit_at(buf, n, "RC8A ");
1588+ if (ap_qci_info->apsb)
1589+ n += sysfs_emit_at(buf, n, "APSB ");
1590+
1591+ sysfs_emit_at(buf, n == 0 ? 0 : n - 1, "\n");
1592+
1593+ return n;
1594+}
1595+
1596+static BUS_ATTR_RO(features);
1597+
15551598 static struct attribute *ap_bus_attrs[] = {
15561599 &bus_attr_ap_domain.attr,
15571600 &bus_attr_ap_control_domain_mask.attr,
@@ -1567,6 +1610,7 @@ static struct attribute *ap_bus_attrs[] = { · 9 unmodified lines
15671610 &bus_attr_aqmask.attr,
15681611 &bus_attr_scans.attr,
15691612 &bus_attr_bindings.attr,
1613+ &bus_attr_features.attr,
15701614 NULL,
15711615 };
15721616 ATTRIBUTE_GROUPS(ap_bus);
@@ -1762,12 +1806,12 @@ static inline void ap_scan_rm_card_dev_and_queue_devs(struct ap_card *ac) · 189 unmodified lines
17621806 */
17631807 static inline void ap_scan_domains(struct ap_card *ac)
17641808 {
1809+ int rc, dom, depth, type, ml;
17651810 bool decfg, chkstop;
1766− ap_qid_t qid;
1767− unsigned int func;
1768− struct device *dev;
17691811 struct ap_queue *aq;
1770− int rc, dom, depth, type, ml;
1812+ struct device *dev;
1813+ unsigned int func;
1814+ ap_qid_t qid;
17711815
17721816 /*
17731817 * Go through the configuration for the domains and compare them
@@ -1786,20 +1830,24 @@ static inline void ap_scan_domains(struct ap_card *ac) · 12 unmodified lines
17861830 AP_DBF_INFO("%s(%d,%d) not in config anymore, rm queue dev\n",
17871831 __func__, ac->id, dom);
17881832 device_unregister(dev);
1789− put_device(dev);
17901833 }
1791− continue;
1834+ goto put_dev_and_continue;
17921835 }
17931836 /* domain is valid, get info from this APQN */
1794− if (!ap_queue_info(qid, &type, &func, &depth,
1795− &ml, &decfg, &chkstop)) {
1796− if (aq) {
1837+ rc = ap_queue_info(qid, &type, &func, &depth,
1838+ &ml, &decfg, &chkstop);
1839+ switch (rc) {
1840+ case -1:
1841+ if (dev) {
17971842 AP_DBF_INFO("%s(%d,%d) queue_info() failed, rm queue dev\n",
17981843 __func__, ac->id, dom);
17991844 device_unregister(dev);
1800− put_device(dev);
18011845 }
1802− continue;
1846+ fallthrough;
1847+ case 0:
1848+ goto put_dev_and_continue;
1849+ default:
1850+ break;
18031851 }
18041852 /* if no queue device exists, create a new one */
18051853 if (!aq) {
@@ -1915,12 +1963,12 @@ put_dev_and_continue: · 109 unmodified lines
19151963 */
19161964 static inline void ap_scan_adapter(int ap)
19171965 {
1966+ int rc, dom, depth, type, comp_type, ml;
19181967 bool decfg, chkstop;
1919− ap_qid_t qid;
1920− unsigned int func;
1921− struct device *dev;
19221968 struct ap_card *ac;
1923− int rc, dom, depth, type, comp_type, ml;
1969+ struct device *dev;
1970+ unsigned int func;
1971+ ap_qid_t qid;
19241972
19251973 /* Is there currently a card device for this adapter ? */
19261974 dev = bus_find_device(&ap_bus_type, NULL,
@@ -1950,11 +1998,11 @@ static inline void ap_scan_adapter(int ap) · 23 unmodified lines
19501998 if (ap_test_config_usage_domain(dom)) {
19511999 qid = AP_MKQID(ap, dom);
19522000 if (ap_queue_info(qid, &type, &func, &depth,
1953− &ml, &decfg, &chkstop))
2001+ &ml, &decfg, &chkstop) > 0)
19542002 break;
19552003 }
19562004 if (dom > ap_max_domain_id) {
1957− /* Could not find a valid APQN for this adapter */
2005+ /* Could not find one valid APQN for this adapter */
19582006 if (ac) {
19592007 AP_DBF_INFO("%s(%d) no type info (no APQN found), rm card and queue devs\n",
19602008 __func__, ap);
@@ -1979,7 +2027,6 @@ static inline void ap_scan_adapter(int ap) · 18 unmodified lines
19792027 }
19802028 return;
19812029 }
1982−
19832030 if (ac) {
19842031 /* Check APQN against existing card device for changes */
19852032 if (ac->raw_hwtype != type) {
@@ -1988,9 +2035,10 @@ static inline void ap_scan_adapter(int ap) · 2 unmodified lines
19882035 ap_scan_rm_card_dev_and_queue_devs(ac);
19892036 put_device(dev);
19902037 ac = NULL;
1991− } else if (ac->functions != func) {
2038+ } else if ((ac->functions & TAPQ_CARD_FUNC_CMP_MASK) !=
2039+ (func & TAPQ_CARD_FUNC_CMP_MASK)) {
19922040 AP_DBF_INFO("%s(%d) functions 0x%08x changed, rm card and queue devs\n",
1993− __func__, ap, type);
2041+ __func__, ap, func);
19942042 ap_scan_rm_card_dev_and_queue_devs(ac);
19952043 put_device(dev);
19962044 ac = NULL;
@@ -2245,7 +2293,7 @@ static int __init ap_module_init(void) · 248 unmodified lines
22452293 * If we are running under z/VM adjust polling to z/VM polling rate.
22462294 */
22472295 if (MACHINE_IS_VM)
2248− poll_timeout = 1500000;
2296+ poll_high_timeout = 1500000;
22492297 hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
22502298 ap_poll_timer.function = ap_poll_timeout;
22512299
drivers/s390/crypto/ap_bus.h+44−26
@@ -39,22 +39,32 @@ static inline int ap_test_bit(unsigned int *ptr, unsigned int nr) · 38 unmodified lines
3939 return (*ptr & (0x80000000u >> nr)) != 0;
4040 }
4141
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
5868
5969 /*
6070 * Known device types
@@ -92,6 +102,7 @@ enum ap_sm_state { · 31 unmodified lines
92102 AP_SM_STATE_IDLE,
93103 AP_SM_STATE_WORKING,
94104 AP_SM_STATE_QUEUE_FULL,
105+ AP_SM_STATE_ASSOC_WAIT,
95106 NR_AP_SM_STATES
96107 };
97108
@@ -108,10 +119,11 @@ enum ap_sm_event { · 10 unmodified lines
108119 * AP queue state wait behaviour
109120 */
110121 enum ap_sm_wait {
111− AP_SM_WAIT_AGAIN = 0, /* retry immediately */
112− AP_SM_WAIT_TIMEOUT, /* wait for timeout */
113− AP_SM_WAIT_INTERRUPT, /* wait for thin interrupt (if available) */
114− AP_SM_WAIT_NONE, /* no wait */
122+ AP_SM_WAIT_AGAIN = 0, /* retry immediately */
123+ AP_SM_WAIT_HIGH_TIMEOUT, /* poll high freq, wait for timeout */
124+ AP_SM_WAIT_LOW_TIMEOUT, /* poll low freq, wait for timeout */
125+ AP_SM_WAIT_INTERRUPT, /* wait for thin interrupt (if available) */
126+ AP_SM_WAIT_NONE, /* no wait */
115127 NR_AP_SM_WAIT
116128 };
117129
@@ -178,7 +190,7 @@ struct ap_device { · 60 unmodified lines
178190 struct ap_card {
179191 struct ap_device ap_dev;
180192 int raw_hwtype; /* AP raw hardware type. */
181− unsigned int functions; /* AP device function bitfield. */
193+ unsigned int functions; /* TAPQ GR2 upper 32 facility bits */
182194 int queue_depth; /* AP queue depth.*/
183195 int id; /* AP card number. */
184196 unsigned int maxmsgsize; /* AP msg limit for this card */
@@ -187,6 +199,9 @@ struct ap_card { · 2 unmodified lines
187199 atomic64_t total_request_count; /* # requests ever for this AP device.*/
188200 };
189201
202+#define TAPQ_CARD_FUNC_CMP_MASK 0xFFFF0000
203+#define ASSOC_IDX_INVALID 0x10000
204+
190205 #define to_ap_card(x) container_of((x), struct ap_card, ap_dev.device)
191206
192207 struct ap_queue {
@@ -199,6 +214,7 @@ struct ap_queue { · 6 unmodified lines
199214 bool chkstop; /* checkstop state */
200215 ap_qid_t qid; /* AP queue id. */
201216 bool interrupt; /* indicate if interrupts are enabled */
217+ unsigned int assoc_idx; /* SE association index */
202218 int queue_count; /* # messages currently on AP queue. */
203219 int pendingq_count; /* # requests on pendingq list. */
204220 int requestq_count; /* # requests on requestq list. */
@@ -209,6 +225,7 @@ struct ap_queue { · 4 unmodified lines
209225 struct list_head requestq; /* List of message yet to be sent. */
210226 struct ap_message *reply; /* Per device reply message. */
211227 enum ap_sm_state sm_state; /* ap queue state machine state */
228+ int rapq_fbit; /* fbit arg for next rapq invocation */
212229 int last_err_rc; /* last error state response code */
213230 };
214231
@@ -242,10 +259,10 @@ enum ap_fi_flags { · 27 unmodified lines
242259
243260 struct ap_message {
244261 struct list_head list; /* Request queueing. */
245− unsigned long long psmid; /* Message id. */
262+ unsigned long psmid; /* Message id. */
246263 void *msg; /* Pointer to message buffer. */
247− unsigned int len; /* actual msg len in msg buffer */
248− unsigned int bufsize; /* allocated msg buffer size */
264+ size_t len; /* actual msg len in msg buffer */
265+ size_t bufsize; /* allocated msg buffer size */
249266 u16 flags; /* Flags, see AP_MSG_FLAG_xxx */
250267 struct ap_fi fi; /* Failure Injection cmd */
251268 int rc; /* Return code for this message */
@@ -285,8 +302,8 @@ static inline void ap_release_message(struct ap_message *ap_msg) · 33 unmodified lines
285302 * for the first time. Otherwise the ap message queue will get
286303 * confused.
287304 */
288−int ap_send(ap_qid_t, unsigned long long, void *, size_t);
289−int ap_recv(ap_qid_t, unsigned long long *, void *, size_t);
305+int ap_send(ap_qid_t qid, unsigned long psmid, void *msg, size_t msglen);
306+int ap_recv(ap_qid_t qid, unsigned long *psmid, void *msg, size_t msglen);
290307
291308 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event);
292309 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event);
@@ -296,6 +313,7 @@ void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg); · 3 unmodified lines
296313 void ap_flush_queue(struct ap_queue *aq);
297314
298315 void *ap_airq_ptr(void);
316+int ap_sb_available(void);
299317 void ap_wait(enum ap_sm_wait wait);
300318 void ap_request_timeout(struct timer_list *t);
301319 void ap_bus_force_rescan(void);
drivers/s390/crypto/ap_card.c+11−12
@@ -24,7 +24,7 @@ static ssize_t hwtype_show(struct device *dev, · 23 unmodified lines
2424 {
2525 struct ap_card *ac = to_ap_card(dev);
2626
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);
2828 }
2929
3030 static DEVICE_ATTR_RO(hwtype);
@@ -34,7 +34,7 @@ static ssize_t raw_hwtype_show(struct device *dev, · 3 unmodified lines
3434 {
3535 struct ap_card *ac = to_ap_card(dev);
3636
37− return scnprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
37+ return sysfs_emit(buf, "%d\n", ac->raw_hwtype);
3838 }
3939
4040 static DEVICE_ATTR_RO(raw_hwtype);
@@ -44,7 +44,7 @@ static ssize_t depth_show(struct device *dev, struct device_attribute *attr, · 3 unmodified lines
4444 {
4545 struct ap_card *ac = to_ap_card(dev);
4646
47− return scnprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
47+ return sysfs_emit(buf, "%d\n", ac->queue_depth);
4848 }
4949
5050 static DEVICE_ATTR_RO(depth);
@@ -54,7 +54,7 @@ static ssize_t ap_functions_show(struct device *dev, · 3 unmodified lines
5454 {
5555 struct ap_card *ac = to_ap_card(dev);
5656
57− return scnprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
57+ return sysfs_emit(buf, "0x%08X\n", ac->functions);
5858 }
5959
6060 static DEVICE_ATTR_RO(ap_functions);
@@ -70,7 +70,7 @@ static ssize_t request_count_show(struct device *dev, · 9 unmodified lines
7070 spin_lock_bh(&ap_queues_lock);
7171 req_cnt = atomic64_read(&ac->total_request_count);
7272 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);
7474 }
7575
7676 static ssize_t request_count_store(struct device *dev,
@@ -107,7 +107,7 @@ static ssize_t requestq_count_show(struct device *dev, · 30 unmodified lines
107107 if (ac == aq->card)
108108 reqq_cnt += aq->requestq_count;
109109 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);
111111 }
112112
113113 static DEVICE_ATTR_RO(requestq_count);
@@ -126,7 +126,7 @@ static ssize_t pendingq_count_show(struct device *dev, · 12 unmodified lines
126126 if (ac == aq->card)
127127 penq_cnt += aq->pendingq_count;
128128 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);
130130 }
131131
132132 static DEVICE_ATTR_RO(pendingq_count);
@@ -134,8 +134,7 @@ static DEVICE_ATTR_RO(pendingq_count); · 1 unmodified line
134134 static ssize_t modalias_show(struct device *dev,
135135 struct device_attribute *attr, char *buf)
136136 {
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);
139138 }
140139
141140 static DEVICE_ATTR_RO(modalias);
@@ -145,7 +144,7 @@ static ssize_t config_show(struct device *dev, · 3 unmodified lines
145144 {
146145 struct ap_card *ac = to_ap_card(dev);
147146
148− return scnprintf(buf, PAGE_SIZE, "%d\n", ac->config ? 1 : 0);
147+ return sysfs_emit(buf, "%d\n", ac->config ? 1 : 0);
149148 }
150149
151150 static ssize_t config_store(struct device *dev,
@@ -179,7 +178,7 @@ static ssize_t chkstop_show(struct device *dev, · 27 unmodified lines
179178 {
180179 struct ap_card *ac = to_ap_card(dev);
181180
182− return scnprintf(buf, PAGE_SIZE, "%d\n", ac->chkstop ? 1 : 0);
181+ return sysfs_emit(buf, "%d\n", ac->chkstop ? 1 : 0);
183182 }
184183
185184 static DEVICE_ATTR_RO(chkstop);
@@ -189,7 +188,7 @@ static ssize_t max_msg_size_show(struct device *dev, · 3 unmodified lines
189188 {
190189 struct ap_card *ac = to_ap_card(dev);
191190
192− return scnprintf(buf, PAGE_SIZE, "%u\n", ac->maxmsgsize);
191+ return sysfs_emit(buf, "%u\n", ac->maxmsgsize);
193192 }
194193
195194 static DEVICE_ATTR_RO(max_msg_size);
drivers/s390/crypto/ap_queue.c+348−62
@@ -18,6 +18,21 @@ · 17 unmodified lines
1818
1919 static void __ap_flush_queue(struct ap_queue *aq);
2020
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+
2136 /**
2237 * ap_queue_enable_irq(): Enable interrupt support on this AP queue.
2338 * @aq: The AP queue
@@ -35,6 +50,8 @@ static int ap_queue_enable_irq(struct ap_queue *aq, void *ind) · 11 unmodified lines
3550 qirqctrl.ir = 1;
3651 qirqctrl.isc = AP_ISC;
3752 status = ap_aqic(aq->qid, qirqctrl, virt_to_phys(ind));
53+ if (status.async)
54+ return -EPERM;
3855 switch (status.response_code) {
3956 case AP_RESPONSE_NORMAL:
4057 case AP_RESPONSE_OTHERWISE_CHANGED:
@@ -59,7 +76,7 @@ static int ap_queue_enable_irq(struct ap_queue *aq, void *ind) · 18 unmodified lines
5976 * @qid: The AP queue number
6077 * @psmid: The program supplied message identifier
6178 * @msg: The message text
62− * @length: The message length
79+ * @msglen: The message length
6380 * @special: Special Bit
6481 *
6582 * Returns AP queue status structure.
@@ -68,19 +85,21 @@ static int ap_queue_enable_irq(struct ap_queue *aq, void *ind) · 2 unmodified lines
6885 * because a segment boundary was reached. The NQAP is repeated.
6986 */
7087 static inline struct ap_queue_status
71−__ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length,
88+__ap_send(ap_qid_t qid, unsigned long psmid, void *msg, size_t msglen,
7289 int special)
7390 {
7491 if (special)
7592 qid |= 0x400000UL;
76− return ap_nqap(qid, psmid, msg, length);
93+ return ap_nqap(qid, psmid, msg, msglen);
7794 }
7895
79−int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
96+int ap_send(ap_qid_t qid, unsigned long psmid, void *msg, size_t msglen)
8097 {
8198 struct ap_queue_status status;
8299
83− status = __ap_send(qid, psmid, msg, length, 0);
100+ status = __ap_send(qid, psmid, msg, msglen, 0);
101+ if (status.async)
102+ return -EPERM;
84103 switch (status.response_code) {
85104 case AP_RESPONSE_NORMAL:
86105 return 0;
@@ -95,13 +114,15 @@ int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length) · 8 unmodified lines
95114 }
96115 EXPORT_SYMBOL(ap_send);
97116
98−int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
117+int ap_recv(ap_qid_t qid, unsigned long *psmid, void *msg, size_t msglen)
99118 {
100119 struct ap_queue_status status;
101120
102121 if (!msg)
103122 return -EINVAL;
104− status = ap_dqap(qid, psmid, msg, length, NULL, NULL);
123+ status = ap_dqap(qid, psmid, msg, msglen, NULL, NULL, NULL);
124+ if (status.async)
125+ return -EPERM;
105126 switch (status.response_code) {
106127 case AP_RESPONSE_NORMAL:
107128 return 0;
@@ -150,7 +171,7 @@ static struct ap_queue_status ap_sm_recv(struct ap_queue *aq) · 42 unmodified lines
150171 do {
151172 status = ap_dqap(aq->qid, &aq->reply->psmid,
152173 aq->reply->msg, aq->reply->bufsize,
153− &reslen, &resgr0);
174+ &aq->reply->len, &reslen, &resgr0);
154175 parts++;
155176 } while (status.response_code == 0xFF && resgr0 != 0);
156177
@@ -177,7 +198,7 @@ static struct ap_queue_status ap_sm_recv(struct ap_queue *aq) · 20 unmodified lines
177198 break;
178199 }
179200 if (!found) {
180− AP_DBF_WARN("%s unassociated reply psmid=0x%016llx on 0x%02x.%04x\n",
201+ AP_DBF_WARN("%s unassociated reply psmid=0x%016lx on 0x%02x.%04x\n",
181202 __func__, aq->reply->psmid,
182203 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
183204 }
@@ -210,6 +231,8 @@ static enum ap_sm_wait ap_sm_read(struct ap_queue *aq) · 26 unmodified lines
210231 if (!aq->reply)
211232 return AP_SM_WAIT_NONE;
212233 status = ap_sm_recv(aq);
234+ if (status.async)
235+ return AP_SM_WAIT_NONE;
213236 switch (status.response_code) {
214237 case AP_RESPONSE_NORMAL:
215238 if (aq->queue_count > 0) {
@@ -221,7 +244,7 @@ static enum ap_sm_wait ap_sm_read(struct ap_queue *aq) · 5 unmodified lines
221244 case AP_RESPONSE_NO_PENDING_REPLY:
222245 if (aq->queue_count > 0)
223246 return aq->interrupt ?
224− AP_SM_WAIT_INTERRUPT : AP_SM_WAIT_TIMEOUT;
247+ AP_SM_WAIT_INTERRUPT : AP_SM_WAIT_HIGH_TIMEOUT;
225248 aq->sm_state = AP_SM_STATE_IDLE;
226249 return AP_SM_WAIT_NONE;
227250 default:
@@ -261,6 +284,8 @@ static enum ap_sm_wait ap_sm_write(struct ap_queue *aq) · 33 unmodified lines
261284 status = __ap_send(qid, ap_msg->psmid,
262285 ap_msg->msg, ap_msg->len,
263286 ap_msg->flags & AP_MSG_FLAG_SPECIAL);
287+ if (status.async)
288+ return AP_SM_WAIT_NONE;
264289 switch (status.response_code) {
265290 case AP_RESPONSE_NORMAL:
266291 aq->queue_count = max_t(int, 1, aq->queue_count + 1);
@@ -277,10 +302,10 @@ static enum ap_sm_wait ap_sm_write(struct ap_queue *aq) · 10 unmodified lines
277302 case AP_RESPONSE_Q_FULL:
278303 aq->sm_state = AP_SM_STATE_QUEUE_FULL;
279304 return aq->interrupt ?
280− AP_SM_WAIT_INTERRUPT : AP_SM_WAIT_TIMEOUT;
305+ AP_SM_WAIT_INTERRUPT : AP_SM_WAIT_HIGH_TIMEOUT;
281306 case AP_RESPONSE_RESET_IN_PROGRESS:
282307 aq->sm_state = AP_SM_STATE_RESET_WAIT;
283− return AP_SM_WAIT_TIMEOUT;
308+ return AP_SM_WAIT_LOW_TIMEOUT;
284309 case AP_RESPONSE_INVALID_DOMAIN:
285310 AP_DBF_WARN("%s RESPONSE_INVALID_DOMAIN on NQAP\n", __func__);
286311 fallthrough;
@@ -322,13 +347,16 @@ static enum ap_sm_wait ap_sm_reset(struct ap_queue *aq) · 35 unmodified lines
322347 {
323348 struct ap_queue_status status;
324349
325− status = ap_rapq(aq->qid);
350+ status = ap_rapq(aq->qid, aq->rapq_fbit);
351+ if (status.async)
352+ return AP_SM_WAIT_NONE;
326353 switch (status.response_code) {
327354 case AP_RESPONSE_NORMAL:
328355 case AP_RESPONSE_RESET_IN_PROGRESS:
329356 aq->sm_state = AP_SM_STATE_RESET_WAIT;
330357 aq->interrupt = false;
331− return AP_SM_WAIT_TIMEOUT;
358+ aq->rapq_fbit = 0;
359+ return AP_SM_WAIT_LOW_TIMEOUT;
332360 default:
333361 aq->dev_state = AP_DEV_STATE_ERROR;
334362 aq->last_err_rc = status.response_code;
@@ -368,7 +396,7 @@ static enum ap_sm_wait ap_sm_reset_wait(struct ap_queue *aq) · 33 unmodified lines
368396 return AP_SM_WAIT_AGAIN;
369397 case AP_RESPONSE_BUSY:
370398 case AP_RESPONSE_RESET_IN_PROGRESS:
371− return AP_SM_WAIT_TIMEOUT;
399+ return AP_SM_WAIT_LOW_TIMEOUT;
372400 case AP_RESPONSE_Q_NOT_AVAIL:
373401 case AP_RESPONSE_DECONFIGURED:
374402 case AP_RESPONSE_CHECKSTOPPED:
@@ -412,7 +440,7 @@ static enum ap_sm_wait ap_sm_setirq_wait(struct ap_queue *aq) · 37 unmodified lines
412440 return AP_SM_WAIT_AGAIN;
413441 fallthrough;
414442 case AP_RESPONSE_NO_PENDING_REPLY:
415− return AP_SM_WAIT_TIMEOUT;
443+ return AP_SM_WAIT_LOW_TIMEOUT;
416444 default:
417445 aq->dev_state = AP_DEV_STATE_ERROR;
418446 aq->last_err_rc = status.response_code;
@@ -423,6 +451,59 @@ static enum ap_sm_wait ap_sm_setirq_wait(struct ap_queue *aq) · 4 unmodified lines
423451 }
424452 }
425453
454+/**
455+ * ap_sm_assoc_wait(): Test queue for completion of a pending
456+ * association request.
457+ * @aq: pointer to the AP queue
458+ */
459+static enum ap_sm_wait ap_sm_assoc_wait(struct ap_queue *aq)
460+{
461+ struct ap_queue_status status;
462+ struct ap_tapq_gr2 info;
463+
464+ status = ap_test_queue(aq->qid, 1, &info);
465+ /* handle asynchronous error on this queue */
466+ if (status.async && status.response_code) {
467+ aq->dev_state = AP_DEV_STATE_ERROR;
468+ aq->last_err_rc = status.response_code;
469+ AP_DBF_WARN("%s asynch RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n",
470+ __func__, status.response_code,
471+ AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
472+ return AP_SM_WAIT_NONE;
473+ }
474+ if (status.response_code > AP_RESPONSE_BUSY) {
475+ aq->dev_state = AP_DEV_STATE_ERROR;
476+ aq->last_err_rc = status.response_code;
477+ AP_DBF_WARN("%s RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n",
478+ __func__, status.response_code,
479+ AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
480+ return AP_SM_WAIT_NONE;
481+ }
482+
483+ /* check bs bits */
484+ switch (info.bs) {
485+ case AP_BS_Q_USABLE:
486+ /* association is through */
487+ aq->sm_state = AP_SM_STATE_IDLE;
488+ AP_DBF_DBG("%s queue 0x%02x.%04x associated with %u\n",
489+ __func__, AP_QID_CARD(aq->qid),
490+ AP_QID_QUEUE(aq->qid), aq->assoc_idx);
491+ return AP_SM_WAIT_NONE;
492+ case AP_BS_Q_USABLE_NO_SECURE_KEY:
493+ /* association still pending */
494+ return AP_SM_WAIT_LOW_TIMEOUT;
495+ default:
496+ /* reset from 'outside' happened or no idea at all */
497+ aq->assoc_idx = ASSOC_IDX_INVALID;
498+ aq->dev_state = AP_DEV_STATE_ERROR;
499+ aq->last_err_rc = status.response_code;
500+ AP_DBF_WARN("%s bs 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n",
501+ __func__, info.bs,
502+ AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
503+ return AP_SM_WAIT_NONE;
504+ }
505+}
506+
426507 /*
427508 * AP state machine jump table
428509 */
@@ -451,6 +532,10 @@ static ap_func_t *ap_jumptable[NR_AP_SM_STATES][NR_AP_SM_EVENTS] = { · 22 unmodified lines
451532 [AP_SM_EVENT_POLL] = ap_sm_read,
452533 [AP_SM_EVENT_TIMEOUT] = ap_sm_reset,
453534 },
535+ [AP_SM_STATE_ASSOC_WAIT] = {
536+ [AP_SM_EVENT_POLL] = ap_sm_assoc_wait,
537+ [AP_SM_EVENT_TIMEOUT] = ap_sm_reset,
538+ },
454539 };
455540
456541 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event)
@@ -490,9 +575,9 @@ static ssize_t request_count_show(struct device *dev, · 33 unmodified lines
490575 spin_unlock_bh(&aq->lock);
491576
492577 if (valid)
493− return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt);
578+ return sysfs_emit(buf, "%llu\n", req_cnt);
494579 else
495− return scnprintf(buf, PAGE_SIZE, "-\n");
580+ return sysfs_emit(buf, "-\n");
496581 }
497582
498583 static ssize_t request_count_store(struct device *dev,
@@ -520,7 +605,7 @@ static ssize_t requestq_count_show(struct device *dev, · 21 unmodified lines
520605 if (aq->dev_state > AP_DEV_STATE_UNINITIATED)
521606 reqq_cnt = aq->requestq_count;
522607 spin_unlock_bh(&aq->lock);
523− return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
608+ return sysfs_emit(buf, "%d\n", reqq_cnt);
524609 }
525610
526611 static DEVICE_ATTR_RO(requestq_count);
@@ -535,7 +620,7 @@ static ssize_t pendingq_count_show(struct device *dev, · 8 unmodified lines
535620 if (aq->dev_state > AP_DEV_STATE_UNINITIATED)
536621 penq_cnt = aq->pendingq_count;
537622 spin_unlock_bh(&aq->lock);
538− return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
623+ return sysfs_emit(buf, "%d\n", penq_cnt);
539624 }
540625
541626 static DEVICE_ATTR_RO(pendingq_count);
@@ -550,14 +635,14 @@ static ssize_t reset_show(struct device *dev, · 8 unmodified lines
550635 switch (aq->sm_state) {
551636 case AP_SM_STATE_RESET_START:
552637 case AP_SM_STATE_RESET_WAIT:
553− rc = scnprintf(buf, PAGE_SIZE, "Reset in progress.\n");
638+ rc = sysfs_emit(buf, "Reset in progress.\n");
554639 break;
555640 case AP_SM_STATE_WORKING:
556641 case AP_SM_STATE_QUEUE_FULL:
557− rc = scnprintf(buf, PAGE_SIZE, "Reset Timer armed.\n");
642+ rc = sysfs_emit(buf, "Reset Timer armed.\n");
558643 break;
559644 default:
560− rc = scnprintf(buf, PAGE_SIZE, "No Reset Timer set.\n");
645+ rc = sysfs_emit(buf, "No Reset Timer set.\n");
561646 }
562647 spin_unlock_bh(&aq->lock);
563648 return rc;
@@ -591,11 +676,11 @@ static ssize_t interrupt_show(struct device *dev, · 27 unmodified lines
591676
592677 spin_lock_bh(&aq->lock);
593678 if (aq->sm_state == AP_SM_STATE_SETIRQ_WAIT)
594− rc = scnprintf(buf, PAGE_SIZE, "Enable Interrupt pending.\n");
679+ rc = sysfs_emit(buf, "Enable Interrupt pending.\n");
595680 else if (aq->interrupt)
596− rc = scnprintf(buf, PAGE_SIZE, "Interrupts enabled.\n");
681+ rc = sysfs_emit(buf, "Interrupts enabled.\n");
597682 else
598− rc = scnprintf(buf, PAGE_SIZE, "Interrupts disabled.\n");
683+ rc = sysfs_emit(buf, "Interrupts disabled.\n");
599684 spin_unlock_bh(&aq->lock);
600685 return rc;
601686 }
@@ -609,7 +694,7 @@ static ssize_t config_show(struct device *dev, · 7 unmodified lines
609694 int rc;
610695
611696 spin_lock_bh(&aq->lock);
612− rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->config ? 1 : 0);
697+ rc = sysfs_emit(buf, "%d\n", aq->config ? 1 : 0);
613698 spin_unlock_bh(&aq->lock);
614699 return rc;
615700 }
@@ -623,13 +708,33 @@ static ssize_t chkstop_show(struct device *dev, · 7 unmodified lines
623708 int rc;
624709
625710 spin_lock_bh(&aq->lock);
626− rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->chkstop ? 1 : 0);
711+ rc = sysfs_emit(buf, "%d\n", aq->chkstop ? 1 : 0);
627712 spin_unlock_bh(&aq->lock);
628713 return rc;
629714 }
630715
631716 static DEVICE_ATTR_RO(chkstop);
632717
718+static ssize_t ap_functions_show(struct device *dev,
719+ struct device_attribute *attr, char *buf)
720+{
721+ struct ap_queue *aq = to_ap_queue(dev);
722+ struct ap_queue_status status;
723+ struct ap_tapq_gr2 info;
724+
725+ status = ap_test_queue(aq->qid, 1, &info);
726+ if (status.response_code > AP_RESPONSE_BUSY) {
727+ AP_DBF_DBG("%s RC 0x%02x on tapq(0x%02x.%04x)\n",
728+ __func__, status.response_code,
729+ AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
730+ return -EIO;
731+ }
732+
733+ return sysfs_emit(buf, "0x%08X\n", info.fac);
734+}
735+
736+static DEVICE_ATTR_RO(ap_functions);
737+
633738 #ifdef CONFIG_ZCRYPT_DEBUG
634739 static ssize_t states_show(struct device *dev,
635740 struct device_attribute *attr, char *buf)
@@ -641,50 +746,46 @@ static ssize_t states_show(struct device *dev, · 5 unmodified lines
641746 /* queue device state */
642747 switch (aq->dev_state) {
643748 case AP_DEV_STATE_UNINITIATED:
644− rc = scnprintf(buf, PAGE_SIZE, "UNINITIATED\n");
749+ rc = sysfs_emit(buf, "UNINITIATED\n");
645750 break;
646751 case AP_DEV_STATE_OPERATING:
647− rc = scnprintf(buf, PAGE_SIZE, "OPERATING");
752+ rc = sysfs_emit(buf, "OPERATING");
648753 break;
649754 case AP_DEV_STATE_SHUTDOWN:
650− rc = scnprintf(buf, PAGE_SIZE, "SHUTDOWN");
755+ rc = sysfs_emit(buf, "SHUTDOWN");
651756 break;
652757 case AP_DEV_STATE_ERROR:
653− rc = scnprintf(buf, PAGE_SIZE, "ERROR");
758+ rc = sysfs_emit(buf, "ERROR");
654759 break;
655760 default:
656− rc = scnprintf(buf, PAGE_SIZE, "UNKNOWN");
761+ rc = sysfs_emit(buf, "UNKNOWN");
657762 }
658763 /* state machine state */
659764 if (aq->dev_state) {
660765 switch (aq->sm_state) {
661766 case AP_SM_STATE_RESET_START:
662− rc += scnprintf(buf + rc, PAGE_SIZE - rc,
663− " [RESET_START]\n");
767+ rc += sysfs_emit_at(buf, rc, " [RESET_START]\n");
664768 break;
665769 case AP_SM_STATE_RESET_WAIT:
666− rc += scnprintf(buf + rc, PAGE_SIZE - rc,
667− " [RESET_WAIT]\n");
770+ rc += sysfs_emit_at(buf, rc, " [RESET_WAIT]\n");
668771 break;
669772 case AP_SM_STATE_SETIRQ_WAIT:
670− rc += scnprintf(buf + rc, PAGE_SIZE - rc,
671− " [SETIRQ_WAIT]\n");
773+ rc += sysfs_emit_at(buf, rc, " [SETIRQ_WAIT]\n");
672774 break;
673775 case AP_SM_STATE_IDLE:
674− rc += scnprintf(buf + rc, PAGE_SIZE - rc,
675− " [IDLE]\n");
776+ rc += sysfs_emit_at(buf, rc, " [IDLE]\n");
676777 break;
677778 case AP_SM_STATE_WORKING:
678− rc += scnprintf(buf + rc, PAGE_SIZE - rc,
679− " [WORKING]\n");
779+ rc += sysfs_emit_at(buf, rc, " [WORKING]\n");
680780 break;
681781 case AP_SM_STATE_QUEUE_FULL:
682− rc += scnprintf(buf + rc, PAGE_SIZE - rc,
683− " [FULL]\n");
782+ rc += sysfs_emit_at(buf, rc, " [FULL]\n");
783+ break;
784+ case AP_SM_STATE_ASSOC_WAIT:
785+ rc += sysfs_emit_at(buf, rc, " [ASSOC_WAIT]\n");
684786 break;
685787 default:
686− rc += scnprintf(buf + rc, PAGE_SIZE - rc,
687− " [UNKNOWN]\n");
788+ rc += sysfs_emit_at(buf, rc, " [UNKNOWN]\n");
688789 }
689790 }
690791 spin_unlock_bh(&aq->lock);
@@ -705,33 +806,33 @@ static ssize_t last_err_rc_show(struct device *dev, · 14 unmodified lines
705806
706807 switch (rc) {
707808 case AP_RESPONSE_NORMAL:
708− return scnprintf(buf, PAGE_SIZE, "NORMAL\n");
809+ return sysfs_emit(buf, "NORMAL\n");
709810 case AP_RESPONSE_Q_NOT_AVAIL:
710− return scnprintf(buf, PAGE_SIZE, "Q_NOT_AVAIL\n");
811+ return sysfs_emit(buf, "Q_NOT_AVAIL\n");
711812 case AP_RESPONSE_RESET_IN_PROGRESS:
712− return scnprintf(buf, PAGE_SIZE, "RESET_IN_PROGRESS\n");
813+ return sysfs_emit(buf, "RESET_IN_PROGRESS\n");
713814 case AP_RESPONSE_DECONFIGURED:
714− return scnprintf(buf, PAGE_SIZE, "DECONFIGURED\n");
815+ return sysfs_emit(buf, "DECONFIGURED\n");
715816 case AP_RESPONSE_CHECKSTOPPED:
716− return scnprintf(buf, PAGE_SIZE, "CHECKSTOPPED\n");
817+ return sysfs_emit(buf, "CHECKSTOPPED\n");
717818 case AP_RESPONSE_BUSY:
718− return scnprintf(buf, PAGE_SIZE, "BUSY\n");
819+ return sysfs_emit(buf, "BUSY\n");
719820 case AP_RESPONSE_INVALID_ADDRESS:
720− return scnprintf(buf, PAGE_SIZE, "INVALID_ADDRESS\n");
821+ return sysfs_emit(buf, "INVALID_ADDRESS\n");
721822 case AP_RESPONSE_OTHERWISE_CHANGED:
722− return scnprintf(buf, PAGE_SIZE, "OTHERWISE_CHANGED\n");
823+ return sysfs_emit(buf, "OTHERWISE_CHANGED\n");
723824 case AP_RESPONSE_Q_FULL:
724− return scnprintf(buf, PAGE_SIZE, "Q_FULL/NO_PENDING_REPLY\n");
825+ return sysfs_emit(buf, "Q_FULL/NO_PENDING_REPLY\n");
725826 case AP_RESPONSE_INDEX_TOO_BIG:
726− return scnprintf(buf, PAGE_SIZE, "INDEX_TOO_BIG\n");
827+ return sysfs_emit(buf, "INDEX_TOO_BIG\n");
727828 case AP_RESPONSE_NO_FIRST_PART:
728− return scnprintf(buf, PAGE_SIZE, "NO_FIRST_PART\n");
829+ return sysfs_emit(buf, "NO_FIRST_PART\n");
729830 case AP_RESPONSE_MESSAGE_TOO_BIG:
730− return scnprintf(buf, PAGE_SIZE, "MESSAGE_TOO_BIG\n");
831+ return sysfs_emit(buf, "MESSAGE_TOO_BIG\n");
731832 case AP_RESPONSE_REQ_FAC_NOT_INST:
732− return scnprintf(buf, PAGE_SIZE, "REQ_FAC_NOT_INST\n");
833+ return sysfs_emit(buf, "REQ_FAC_NOT_INST\n");
733834 default:
734− return scnprintf(buf, PAGE_SIZE, "response code %d\n", rc);
835+ return sysfs_emit(buf, "response code %d\n", rc);
735836 }
736837 }
737838 static DEVICE_ATTR_RO(last_err_rc);
@@ -745,6 +846,7 @@ static struct attribute *ap_queue_dev_attrs[] = { · 7 unmodified lines
745846 &dev_attr_interrupt.attr,
746847 &dev_attr_config.attr,
747848 &dev_attr_chkstop.attr,
849+ &dev_attr_ap_functions.attr,
748850 #ifdef CONFIG_ZCRYPT_DEBUG
749851 &dev_attr_states.attr,
750852 &dev_attr_last_err_rc.attr,
@@ -766,6 +868,186 @@ static struct device_type ap_queue_type = { · 15 unmodified lines
766868 .groups = ap_queue_dev_attr_groups,
767869 };
768870
871+static ssize_t se_bind_show(struct device *dev,
872+ struct device_attribute *attr, char *buf)
873+{
874+ struct ap_queue *aq = to_ap_queue(dev);
875+ struct ap_queue_status status;
876+ struct ap_tapq_gr2 info;
877+
878+ if (!ap_q_supports_bind(aq))
879+ return sysfs_emit(buf, "-\n");
880+
881+ status = ap_test_queue(aq->qid, 1, &info);
882+ if (status.response_code > AP_RESPONSE_BUSY) {
883+ AP_DBF_DBG("%s RC 0x%02x on tapq(0x%02x.%04x)\n",
884+ __func__, status.response_code,
885+ AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
886+ return -EIO;
887+ }
888+ switch (info.bs) {
889+ case AP_BS_Q_USABLE:
890+ case AP_BS_Q_USABLE_NO_SECURE_KEY:
891+ return sysfs_emit(buf, "bound\n");
892+ default:
893+ return sysfs_emit(buf, "unbound\n");
894+ }
895+}
896+
897+static ssize_t se_bind_store(struct device *dev,
898+ struct device_attribute *attr,
899+ const char *buf, size_t count)
900+{
901+ struct ap_queue *aq = to_ap_queue(dev);
902+ struct ap_queue_status status;
903+ bool value;
904+ int rc;
905+
906+ if (!ap_q_supports_bind(aq))
907+ return -EINVAL;
908+
909+ /* only 0 (unbind) and 1 (bind) allowed */
910+ rc = kstrtobool(buf, &value);
911+ if (rc)
912+ return rc;
913+
914+ if (value) {
915+ /* bind, do BAPQ */
916+ spin_lock_bh(&aq->lock);
917+ if (aq->sm_state < AP_SM_STATE_IDLE) {
918+ spin_unlock_bh(&aq->lock);
919+ return -EBUSY;
920+ }
921+ status = ap_bapq(aq->qid);
922+ spin_unlock_bh(&aq->lock);
923+ if (status.response_code) {
924+ AP_DBF_WARN("%s RC 0x%02x on bapq(0x%02x.%04x)\n",
925+ __func__, status.response_code,
926+ AP_QID_CARD(aq->qid),
927+ AP_QID_QUEUE(aq->qid));
928+ return -EIO;
929+ }
930+ } else {
931+ /* unbind, set F bit arg and trigger RAPQ */
932+ spin_lock_bh(&aq->lock);
933+ __ap_flush_queue(aq);
934+ aq->rapq_fbit = 1;
935+ aq->assoc_idx = ASSOC_IDX_INVALID;
936+ aq->sm_state = AP_SM_STATE_RESET_START;
937+ ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL));
938+ spin_unlock_bh(&aq->lock);
939+ }
940+
941+ return count;
942+}
943+
944+static DEVICE_ATTR_RW(se_bind);
945+
946+static ssize_t se_associate_show(struct device *dev,
947+ struct device_attribute *attr, char *buf)
948+{
949+ struct ap_queue *aq = to_ap_queue(dev);
950+ struct ap_queue_status status;
951+ struct ap_tapq_gr2 info;
952+
953+ if (!ap_q_supports_assoc(aq))
954+ return sysfs_emit(buf, "-\n");
955+
956+ status = ap_test_queue(aq->qid, 1, &info);
957+ if (status.response_code > AP_RESPONSE_BUSY) {
958+ AP_DBF_DBG("%s RC 0x%02x on tapq(0x%02x.%04x)\n",
959+ __func__, status.response_code,
960+ AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
961+ return -EIO;
962+ }
963+
964+ switch (info.bs) {
965+ case AP_BS_Q_USABLE:
966+ if (aq->assoc_idx == ASSOC_IDX_INVALID) {
967+ AP_DBF_WARN("%s AP_BS_Q_USABLE but invalid assoc_idx\n", __func__);
968+ return -EIO;
969+ }
970+ return sysfs_emit(buf, "associated %u\n", aq->assoc_idx);
971+ case AP_BS_Q_USABLE_NO_SECURE_KEY:
972+ if (aq->assoc_idx != ASSOC_IDX_INVALID)
973+ return sysfs_emit(buf, "association pending\n");
974+ fallthrough;
975+ default:
976+ return sysfs_emit(buf, "unassociated\n");
977+ }
978+}
979+
980+static ssize_t se_associate_store(struct device *dev,
981+ struct device_attribute *attr,
982+ const char *buf, size_t count)
983+{
984+ struct ap_queue *aq = to_ap_queue(dev);
985+ struct ap_queue_status status;
986+ unsigned int value;
987+ int rc;
988+
989+ if (!ap_q_supports_assoc(aq))
990+ return -EINVAL;
991+
992+ /* association index needs to be >= 0 */
993+ rc = kstrtouint(buf, 0, &value);
994+ if (rc)
995+ return rc;
996+ if (value >= ASSOC_IDX_INVALID)
997+ return -EINVAL;
998+
999+ spin_lock_bh(&aq->lock);
1000+
1001+ /* sm should be in idle state */
1002+ if (aq->sm_state != AP_SM_STATE_IDLE) {
1003+ spin_unlock_bh(&aq->lock);
1004+ return -EBUSY;
1005+ }
1006+
1007+ /* already associated or association pending ? */
1008+ if (aq->assoc_idx != ASSOC_IDX_INVALID) {
1009+ spin_unlock_bh(&aq->lock);
1010+ return -EINVAL;
1011+ }
1012+
1013+ /* trigger the asynchronous association request */
1014+ status = ap_aapq(aq->qid, value);
1015+ switch (status.response_code) {
1016+ case AP_RESPONSE_NORMAL:
1017+ case AP_RESPONSE_STATE_CHANGE_IN_PROGRESS:
1018+ aq->sm_state = AP_SM_STATE_ASSOC_WAIT;
1019+ aq->assoc_idx = value;
1020+ ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL));
1021+ spin_unlock_bh(&aq->lock);
1022+ break;
1023+ default:
1024+ spin_unlock_bh(&aq->lock);
1025+ AP_DBF_WARN("%s RC 0x%02x on aapq(0x%02x.%04x)\n",
1026+ __func__, status.response_code,
1027+ AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
1028+ return -EIO;
1029+ }
1030+
1031+ return count;
1032+}
1033+
1034+static DEVICE_ATTR_RW(se_associate);
1035+
1036+static struct attribute *ap_queue_dev_sb_attrs[] = {
1037+ &dev_attr_se_bind.attr,
1038+ &dev_attr_se_associate.attr,
1039+ NULL
1040+};
1041+
1042+static struct attribute_group ap_queue_dev_sb_attr_group = {
1043+ .attrs = ap_queue_dev_sb_attrs
1044+};
1045+
1046+static const struct attribute_group *ap_queue_dev_sb_attr_groups[] = {
1047+ &ap_queue_dev_sb_attr_group,
1048+ NULL
1049+};
1050+
7691051 static void ap_queue_device_release(struct device *dev)
7701052 {
7711053 struct ap_queue *aq = to_ap_queue(dev);
@@ -787,6 +1069,9 @@ struct ap_queue *ap_queue_create(ap_qid_t qid, int device_type) · 15 unmodified lines
7871069 aq->ap_dev.device.release = ap_queue_device_release;
7881070 aq->ap_dev.device.type = &ap_queue_type;
7891071 aq->ap_dev.device_type = device_type;
1072+ // add optional SE secure binding attributes group
1073+ if (ap_sb_available() && is_prot_virt_guest())
1074+ aq->ap_dev.device.groups = ap_queue_dev_sb_attr_groups;
7901075 aq->qid = qid;
7911076 aq->interrupt = false;
7921077 spin_lock_init(&aq->lock);
@@ -922,7 +1207,7 @@ void ap_queue_remove(struct ap_queue *aq) · 129 unmodified lines
9221207 * to the initial value AP_DEV_STATE_UNINITIATED.
9231208 */
9241209 spin_lock_bh(&aq->lock);
925− ap_zapq(aq->qid);
1210+ ap_zapq(aq->qid, 0);
9261211 aq->dev_state = AP_DEV_STATE_UNINITIATED;
9271212 spin_unlock_bh(&aq->lock);
9281213 }
@@ -933,6 +1218,7 @@ void ap_queue_init_state(struct ap_queue *aq) · 4 unmodified lines
9331218 aq->dev_state = AP_DEV_STATE_OPERATING;
9341219 aq->sm_state = AP_SM_STATE_RESET_START;
9351220 aq->last_err_rc = 0;
1221+ aq->assoc_idx = ASSOC_IDX_INVALID;
9361222 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL));
9371223 spin_unlock_bh(&aq->lock);
9381224 }
drivers/s390/crypto/vfio_ap_drv.c+0−6
@@ -60,14 +60,8 @@ static void vfio_ap_matrix_dev_release(struct device *dev) · 59 unmodified lines
6060 kfree(matrix_dev);
6161 }
6262
63−static int matrix_bus_match(struct device *dev, struct device_driver *drv)
64−{
65− return 1;
66−}
67−
6863 static struct bus_type matrix_bus = {
6964 .name = "matrix",
70− .match = &matrix_bus_match,
7165 };
7266
7367 static struct device_driver matrix_driver = {
drivers/s390/crypto/vfio_ap_ops.c+7−9
@@ -599,9 +599,9 @@ out_unlock: · 598 unmodified lines
599599 static void vfio_ap_matrix_init(struct ap_config_info *info,
600600 struct ap_matrix *matrix)
601601 {
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;
605605 }
606606
607607 static void vfio_ap_mdev_update_guest_apcb(struct ap_matrix_mdev *matrix_mdev)
@@ -1657,7 +1657,7 @@ static int vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q) · 1049 unmodified lines
16571657 if (!q)
16581658 return 0;
16591659 retry_zapq:
1660− status = ap_zapq(q->apqn);
1660+ status = ap_zapq(q->apqn, 0);
16611661 q->reset_rc = status.response_code;
16621662 switch (status.response_code) {
16631663 case AP_RESPONSE_NORMAL:
@@ -2115,8 +2115,8 @@ static void vfio_ap_filter_apid_by_qtype(unsigned long *apm, unsigned long *aqm) · 451 unmodified lines
21152115 {
21162116 bool apid_cleared;
21172117 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;
21202120
21212121 for_each_set_bit_inv(apid, apm, AP_DEVICES) {
21222122 apid_cleared = false;
@@ -2133,15 +2133,13 @@ static void vfio_ap_filter_apid_by_qtype(unsigned long *apm, unsigned long *aqm) · 10 unmodified lines
21332133 case AP_RESPONSE_DECONFIGURED:
21342134 case AP_RESPONSE_CHECKSTOPPED:
21352135 case AP_RESPONSE_BUSY:
2136− qtype = info & qtype_mask;
2137−
21382136 /*
21392137 * The vfio_ap device driver only
21402138 * supports CEX4 and newer adapters, so
21412139 * remove the APID if the adapter is
21422140 * older than a CEX4.
21432141 */
2144− if (qtype < AP_DEVICE_TYPE_CEX4) {
2142+ if (info.at < AP_DEVICE_TYPE_CEX4) {
21452143 clear_bit_inv(apid, apm);
21462144 apid_cleared = true;
21472145 }
drivers/s390/crypto/zcrypt_api.c+20−40
@@ -159,25 +159,20 @@ static ssize_t ioctlmask_show(struct device *dev, · 158 unmodified lines
159159 struct device_attribute *attr,
160160 char *buf)
161161 {
162− int i, rc;
163162 struct zcdn_device *zcdndev = to_zcdn_dev(dev);
163+ int i, n;
164164
165165 if (mutex_lock_interruptible(&ap_perms_mutex))
166166 return -ERESTARTSYS;
167167
168− buf[0] = '0';
169− buf[1] = 'x';
168+ n = sysfs_emit(buf, "0x");
170169 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");
177172
178173 mutex_unlock(&ap_perms_mutex);
179174
180− return rc;
175+ return n;
181176 }
182177
183178 static ssize_t ioctlmask_store(struct device *dev,
@@ -201,25 +196,20 @@ static ssize_t apmask_show(struct device *dev, · 17 unmodified lines
201196 struct device_attribute *attr,
202197 char *buf)
203198 {
204− int i, rc;
205199 struct zcdn_device *zcdndev = to_zcdn_dev(dev);
200+ int i, n;
206201
207202 if (mutex_lock_interruptible(&ap_perms_mutex))
208203 return -ERESTARTSYS;
209204
210− buf[0] = '0';
211− buf[1] = 'x';
205+ n = sysfs_emit(buf, "0x");
212206 for (i = 0; i < sizeof(zcdndev->perms.apm) / sizeof(long); i++)
213− snprintf(buf + 2 + 2 * i * sizeof(long),
214− PAGE_SIZE - 2 - 2 * i * sizeof(long),
215− "%016lx", zcdndev->perms.apm[i]);
216− buf[2 + 2 * i * sizeof(long)] = '\n';
217− buf[2 + 2 * i * sizeof(long) + 1] = '\0';
218− rc = 2 + 2 * i * sizeof(long) + 1;
207+ n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.apm[i]);
208+ n += sysfs_emit_at(buf, n, "\n");
219209
220210 mutex_unlock(&ap_perms_mutex);
221211
222− return rc;
212+ return n;
223213 }
224214
225215 static ssize_t apmask_store(struct device *dev,
@@ -243,25 +233,20 @@ static ssize_t aqmask_show(struct device *dev, · 17 unmodified lines
243233 struct device_attribute *attr,
244234 char *buf)
245235 {
246− int i, rc;
247236 struct zcdn_device *zcdndev = to_zcdn_dev(dev);
237+ int i, n;
248238
249239 if (mutex_lock_interruptible(&ap_perms_mutex))
250240 return -ERESTARTSYS;
251241
252− buf[0] = '0';
253− buf[1] = 'x';
242+ n = sysfs_emit(buf, "0x");
254243 for (i = 0; i < sizeof(zcdndev->perms.aqm) / sizeof(long); i++)
255− snprintf(buf + 2 + 2 * i * sizeof(long),
256− PAGE_SIZE - 2 - 2 * i * sizeof(long),
257− "%016lx", zcdndev->perms.aqm[i]);
258− buf[2 + 2 * i * sizeof(long)] = '\n';
259− buf[2 + 2 * i * sizeof(long) + 1] = '\0';
260− rc = 2 + 2 * i * sizeof(long) + 1;
244+ n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.aqm[i]);
245+ n += sysfs_emit_at(buf, n, "\n");
261246
262247 mutex_unlock(&ap_perms_mutex);
263248
264− return rc;
249+ return n;
265250 }
266251
267252 static ssize_t aqmask_store(struct device *dev,
@@ -285,25 +270,20 @@ static ssize_t admask_show(struct device *dev, · 17 unmodified lines
285270 struct device_attribute *attr,
286271 char *buf)
287272 {
288− int i, rc;
289273 struct zcdn_device *zcdndev = to_zcdn_dev(dev);
274+ int i, n;
290275
291276 if (mutex_lock_interruptible(&ap_perms_mutex))
292277 return -ERESTARTSYS;
293278
294− buf[0] = '0';
295− buf[1] = 'x';
279+ n = sysfs_emit(buf, "0x");
296280 for (i = 0; i < sizeof(zcdndev->perms.adm) / sizeof(long); i++)
297− snprintf(buf + 2 + 2 * i * sizeof(long),
298− PAGE_SIZE - 2 - 2 * i * sizeof(long),
299− "%016lx", zcdndev->perms.adm[i]);
300− buf[2 + 2 * i * sizeof(long)] = '\n';
301− buf[2 + 2 * i * sizeof(long) + 1] = '\0';
302− rc = 2 + 2 * i * sizeof(long) + 1;
281+ n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.adm[i]);
282+ n += sysfs_emit_at(buf, n, "\n");
303283
304284 mutex_unlock(&ap_perms_mutex);
305285
306− return rc;
286+ return n;
307287 }
308288
309289 static ssize_t admask_store(struct device *dev,
drivers/s390/crypto/zcrypt_card.c+3−3
@@ -41,7 +41,7 @@ static ssize_t type_show(struct device *dev, · 40 unmodified lines
4141 {
4242 struct zcrypt_card *zc = dev_get_drvdata(dev);
4343
44− return scnprintf(buf, PAGE_SIZE, "%s\n", zc->type_string);
44+ return sysfs_emit(buf, "%s\n", zc->type_string);
4545 }
4646
4747 static DEVICE_ATTR_RO(type);
@@ -54,7 +54,7 @@ static ssize_t online_show(struct device *dev, · 6 unmodified lines
5454 struct ap_card *ac = to_ap_card(dev);
5555 int online = ac->config && zc->online ? 1 : 0;
5656
57− return scnprintf(buf, PAGE_SIZE, "%d\n", online);
57+ return sysfs_emit(buf, "%d\n", online);
5858 }
5959
6060 static ssize_t online_store(struct device *dev,
@@ -118,7 +118,7 @@ static ssize_t load_show(struct device *dev, · 57 unmodified lines
118118 {
119119 struct zcrypt_card *zc = dev_get_drvdata(dev);
120120
121− return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zc->load));
121+ return sysfs_emit(buf, "%d\n", atomic_read(&zc->load));
122122 }
123123
124124 static DEVICE_ATTR_RO(load);
drivers/s390/crypto/zcrypt_cca_key.h+13−24
@@ -89,10 +89,7 @@ struct cca_pvt_ext_crt_sec { · 88 unmodified lines
8989 #define CCA_PVT_EXT_CRT_SEC_FMT_CL 0x40
9090
9191 /**
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.
9693 *
9794 * @mex: pointer to user input data
9895 * @p: pointer to memory area for the key
@@ -111,10 +108,9 @@ static inline int zcrypt_type6_mex_key_en(struct ica_rsa_modexpo *mex, void *p) · 12 unmodified lines
111108 struct t6_keyblock_hdr t6_hdr;
112109 struct cca_token_hdr pubhdr;
113110 struct cca_public_sec pubsec;
114− char exponent[0];
111+ char exponent[];
115112 } __packed *key = p;
116− unsigned char *temp;
117− int i;
113+ unsigned char *ptr;
118114
119115 /*
120116 * The inputdatalength was a selection criteria in the dispatching
@@ -131,37 +127,29 @@ static inline int zcrypt_type6_mex_key_en(struct ica_rsa_modexpo *mex, void *p) · 10 unmodified lines
131127 key->pubsec = static_pub_sec;
132128
133129 /* key parameter block */
134− temp = key->exponent;
135− if (copy_from_user(temp, mex->b_key, mex->inputdatalength))
130+ ptr = key->exponent;
131+ if (copy_from_user(ptr, mex->b_key, mex->inputdatalength))
136132 return -EFAULT;
137− /* Strip leading zeroes from b_key. */
138− for (i = 0; i < mex->inputdatalength; i++)
139− if (temp[i])
140− break;
141− if (i >= mex->inputdatalength)
142− return -EINVAL;
143− memmove(temp, temp + i, mex->inputdatalength - i);
144− temp += mex->inputdatalength - i;
133+ ptr += mex->inputdatalength;
145134 /* modulus */
146− if (copy_from_user(temp, mex->n_modulus, mex->inputdatalength))
135+ if (copy_from_user(ptr, mex->n_modulus, mex->inputdatalength))
147136 return -EFAULT;
148137
149138 key->pubsec.modulus_bit_len = 8 * mex->inputdatalength;
150139 key->pubsec.modulus_byte_len = mex->inputdatalength;
151− key->pubsec.exponent_len = mex->inputdatalength - i;
140+ key->pubsec.exponent_len = mex->inputdatalength;
152141 key->pubsec.section_length = sizeof(key->pubsec) +
153− 2 * mex->inputdatalength - i;
142+ 2 * mex->inputdatalength;
154143 key->pubhdr.token_length =
155144 key->pubsec.section_length + sizeof(key->pubhdr);
156145 key->t6_hdr.ulen = key->pubhdr.token_length + 4;
157146 key->t6_hdr.blen = key->pubhdr.token_length + 6;
158− return sizeof(*key) + 2 * mex->inputdatalength - i;
147+
148+ return sizeof(*key) + 2 * mex->inputdatalength;
159149 }
160150
161151 /**
162152 * Set up private key fields of a type6 CRT message.
163− * Note that all numerics in the key token are big-endian,
164− * while the entries in the key block header are little-endian.
165153 *
166154 * @mex: pointer to user input data
167155 * @p: pointer to memory area for the key
@@ -180,7 +168,7 @@ static inline int zcrypt_type6_crt_key(struct ica_rsa_modexpo_crt *crt, void *p) · 12 unmodified lines
180168 struct t6_keyblock_hdr t6_hdr;
181169 struct cca_token_hdr token;
182170 struct cca_pvt_ext_crt_sec pvt;
183− char key_parts[0];
171+ char key_parts[];
184172 } __packed *key = p;
185173 struct cca_public_sec *pub;
186174 int short_len, long_len, pad_len, key_len, size;
@@ -242,6 +230,7 @@ static inline int zcrypt_type6_crt_key(struct ica_rsa_modexpo_crt *crt, void *p) · 55 unmodified lines
242230 * used.
243231 */
244232 memcpy((char *)(pub + 1), pk_exponent, 3);
233+
245234 return size;
246235 }
247236
drivers/s390/crypto/zcrypt_ccamisc.c+36−38
@@ -450,18 +450,18 @@ int cca_clr2seckey(u16 cardnr, u16 domain, u32 keybitsize, · 449 unmodified lines
450450 char rule_array[8];
451451 struct lv1 {
452452 u16 len;
453− u8 clrkey[0];
453+ u8 clrkey[];
454454 } 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 */
463456 } __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;
465465 struct cmrepparm {
466466 u8 subfunc_code[2];
467467 u16 rule_array_len;
@@ -512,11 +512,11 @@ int cca_clr2seckey(u16 cardnr, u16 domain, u32 keybitsize, · 44 unmodified lines
512512 }
513513 preqparm->lv1.len = sizeof(struct lv1) + keysize;
514514 memcpy(preqparm->lv1.clrkey, clrkey, keysize);
515− plv2 = (struct lv2 *)(((u8 *)&preqparm->lv2) + keysize);
515+ plv2 = (struct lv2 *)(((u8 *)preqparm) + sizeof(*preqparm) + keysize);
516516 plv2->len = sizeof(struct lv2);
517517 plv2->keyid.len = sizeof(struct keyid);
518518 plv2->keyid.attr = 0x30;
519− preqcblk->req_parml = sizeof(struct cmreqparm) + keysize;
519+ preqcblk->req_parml = sizeof(*preqparm) + keysize + sizeof(*plv2);
520520
521521 /* fill xcrb struct */
522522 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk);
@@ -761,22 +761,22 @@ int cca_gencipherkey(u16 cardnr, u16 domain, u32 keybitsize, u32 keygenflags, · 238 unmodified lines
761761 u16 key_name_2_len;
762762 u16 user_data_1_len;
763763 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[]; */
768768 } vud;
769769 struct {
770770 u16 len;
771771 struct {
772772 u16 len;
773773 u16 flag;
774− u8 kek_id_1[0];
774+ /* u8 kek_id_1[]; */
775775 } tlv1;
776776 struct {
777777 u16 len;
778778 u16 flag;
779− u8 kek_id_2[0];
779+ /* u8 kek_id_2[]; */
780780 } tlv2;
781781 struct {
782782 u16 len;
@@ -786,17 +786,17 @@ int cca_gencipherkey(u16 cardnr, u16 domain, u32 keybitsize, u32 keygenflags, · 3 unmodified lines
786786 struct {
787787 u16 len;
788788 u16 flag;
789− u8 gen_key_id_1_label[0];
789+ /* u8 gen_key_id_1_label[]; */
790790 } tlv4;
791791 struct {
792792 u16 len;
793793 u16 flag;
794− u8 gen_key_id_2[0];
794+ /* u8 gen_key_id_2[]; */
795795 } tlv5;
796796 struct {
797797 u16 len;
798798 u16 flag;
799− u8 gen_key_id_2_label[0];
799+ /* u8 gen_key_id_2_label[]; */
800800 } tlv6;
801801 } kb;
802802 } __packed * preqparm;
@@ -811,7 +811,7 @@ int cca_gencipherkey(u16 cardnr, u16 domain, u32 keybitsize, u32 keygenflags, · 8 unmodified lines
811811 struct {
812812 u16 len;
813813 u16 flag;
814− u8 gen_key[0]; /* 120-136 bytes */
814+ u8 gen_key[]; /* 120-136 bytes */
815815 } tlv1;
816816 } kb;
817817 } __packed * prepparm;
@@ -955,7 +955,7 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain, · 137 unmodified lines
955955 struct rule_array_block {
956956 u8 subfunc_code[2];
957957 u16 rule_array_len;
958− char rule_array[0];
958+ char rule_array[];
959959 } __packed * preq_ra_block;
960960 struct vud_block {
961961 u16 len;
@@ -967,7 +967,7 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain, · 5 unmodified lines
967967 struct {
968968 u16 len;
969969 u16 flag; /* 0x0063 */
970− u8 clr_key[0]; /* clear key value bytes */
970+ u8 clr_key[]; /* clear key value bytes */
971971 } tlv2;
972972 } __packed * preq_vud_block;
973973 struct key_block {
@@ -975,7 +975,7 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain, · 1 unmodified line
975975 struct {
976976 u16 len;
977977 u16 flag; /* 0x0030 */
978− u8 key_token[0]; /* key skeleton */
978+ u8 key_token[]; /* key skeleton */
979979 } tlv1;
980980 } __packed * preq_key_block;
981981 struct iprepparm {
@@ -989,7 +989,7 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain, · 7 unmodified lines
989989 struct {
990990 u16 len;
991991 u16 flag; /* 0x0030 */
992− u8 key_token[0]; /* key token */
992+ u8 key_token[]; /* key token */
993993 } tlv1;
994994 } kb;
995995 } __packed * prepparm;
@@ -1201,7 +1201,7 @@ int cca_cipher2protkey(u16 cardnr, u16 domain, const u8 *ckey, · 205 unmodified lines
12011201 u16 len;
12021202 u16 cca_key_token_len;
12031203 u16 cca_key_token_flags;
1204− u8 cca_key_token[0]; // 64 or more
1204+ u8 cca_key_token[]; /* 64 or more */
12051205 } kb;
12061206 } __packed * preqparm;
12071207 struct aurepparm {
@@ -1370,7 +1370,7 @@ int cca_ecc2protkey(u16 cardnr, u16 domain, const u8 *key, · 162 unmodified lines
13701370 u16 len;
13711371 u16 cca_key_token_len;
13721372 u16 cca_key_token_flags;
1373− u8 cca_key_token[0];
1373+ u8 cca_key_token[];
13741374 } kb;
13751375 } __packed * preqparm;
13761376 struct aurepparm {
@@ -1387,17 +1387,15 @@ int cca_ecc2protkey(u16 cardnr, u16 domain, const u8 *key, · 10 unmodified lines
13871387 u8 form;
13881388 u8 pad1[3];
13891389 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 */
13961396 } ckb;
13971397 } vud;
1398− struct {
1399− u16 len;
1400− } kb;
1398+ /* followed by a key block */
14011399 } __packed * prepparm;
14021400 int keylen = ((struct eccprivkeytoken *)key)->len;
14031401
@@ -1525,7 +1523,7 @@ int cca_query_crypto_facility(u16 cardnr, u16 domain, · 121 unmodified lines
15251523 size_t parmbsize = sizeof(struct fqreqparm);
15261524 struct fqrepparm {
15271525 u8 subfunc_code[2];
1528− u8 lvdata[0];
1526+ u8 lvdata[];
15291527 } __packed * prepparm;
15301528
15311529 /* get already prepared memory for 2 cprbs with param block each */
drivers/s390/crypto/zcrypt_cex2c.c+31−35
@@ -75,7 +75,7 @@ static ssize_t cca_serialnr_show(struct device *dev, · 74 unmodified lines
7575 if (ap_domain_index >= 0)
7676 cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
7777
78− return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial);
78+ return sysfs_emit(buf, "%s\n", ci.serial);
7979 }
8080
8181 static struct device_attribute dev_attr_cca_serialnr =
@@ -110,51 +110,46 @@ static ssize_t cca_mkvps_show(struct device *dev, · 28 unmodified lines
110110 &ci, zq->online);
111111
112112 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);
116116 else
117− n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n");
117+ n = sysfs_emit(buf, "AES NEW: - -\n");
118118
119119 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);
124123 else
125− n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n");
124+ n += sysfs_emit_at(buf, n, "AES CUR: - -\n");
126125
127126 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);
132130 else
133− n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n");
131+ n += sysfs_emit_at(buf, n, "AES OLD: - -\n");
134132
135133 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);
140137 else
141− n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n");
138+ n += sysfs_emit_at(buf, n, "APKA NEW: - -\n");
142139
143140 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);
148144 else
149− n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n");
145+ n += sysfs_emit_at(buf, n, "APKA CUR: - -\n");
150146
151147 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);
156151 else
157− n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n");
152+ n += sysfs_emit_at(buf, n, "APKA OLD: - -\n");
158153
159154 return n;
160155 }
@@ -181,7 +176,7 @@ static const struct attribute_group cca_queue_attr_grp = { · 20 unmodified lines
181176 static int zcrypt_cex2c_rng_supported(struct ap_queue *aq)
182177 {
183178 struct ap_message ap_msg;
184− unsigned long long psmid;
179+ unsigned long psmid;
185180 unsigned int domain;
186181 struct {
187182 struct type86_hdr hdr;
@@ -203,21 +198,22 @@ static int zcrypt_cex2c_rng_supported(struct ap_queue *aq) · 15 unmodified lines
203198 ap_msg.msg = (void *)get_zeroed_page(GFP_KERNEL);
204199 if (!ap_msg.msg)
205200 return -ENOMEM;
201+ ap_msg.bufsize = PAGE_SIZE;
206202
207203 rng_type6cprb_msgx(&ap_msg, 4, &domain);
208204
209205 msg = ap_msg.msg;
210206 msg->cprbx.domain = AP_QID_QUEUE(aq->qid);
211207
212− rc = ap_send(aq->qid, 0x0102030405060708ULL, ap_msg.msg, ap_msg.len);
208+ rc = ap_send(aq->qid, 0x0102030405060708UL, ap_msg.msg, ap_msg.len);
213209 if (rc)
214210 goto out_free;
215211
216212 /* Wait for the test message to complete. */
217213 for (i = 0; i < 2 * HZ; i++) {
218214 msleep(1000 / HZ);
219− rc = ap_recv(aq->qid, &psmid, ap_msg.msg, 4096);
220− if (rc == 0 && psmid == 0x0102030405060708ULL)
215+ rc = ap_recv(aq->qid, &psmid, ap_msg.msg, ap_msg.bufsize);
216+ if (rc == 0 && psmid == 0x0102030405060708UL)
221217 break;
222218 }
223219
@@ -342,7 +338,7 @@ static int zcrypt_cex2c_queue_probe(struct ap_device *ap_dev) · 118 unmodified lines
342338 zq->queue = aq;
343339 zq->online = 1;
344340 atomic_set(&zq->load, 0);
345− ap_rapq(aq->qid);
341+ ap_rapq(aq->qid, 0);
346342 rc = zcrypt_cex2c_rng_supported(aq);
347343 if (rc < 0) {
348344 zcrypt_queue_free(zq);
drivers/s390/crypto/zcrypt_cex4.c+66−75
@@ -88,7 +88,7 @@ static ssize_t cca_serialnr_show(struct device *dev, · 87 unmodified lines
8888 if (ap_domain_index >= 0)
8989 cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
9090
91− return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial);
91+ return sysfs_emit(buf, "%s\n", ci.serial);
9292 }
9393
9494 static struct device_attribute dev_attr_cca_serialnr =
@@ -123,79 +123,70 @@ static ssize_t cca_mkvps_show(struct device *dev, · 28 unmodified lines
123123 &ci, zq->online);
124124
125125 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);
130129 else
131− n += scnprintf(buf + n, PAGE_SIZE, "AES NEW: - -\n");
130+ n += sysfs_emit_at(buf, n, "AES NEW: - -\n");
132131
133132 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);
138136 else
139− n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n");
137+ n += sysfs_emit_at(buf, n, "AES CUR: - -\n");
140138
141139 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);
146143 else
147− n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n");
144+ n += sysfs_emit_at(buf, n, "AES OLD: - -\n");
148145
149146 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);
154150 else
155− n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n");
151+ n += sysfs_emit_at(buf, n, "APKA NEW: - -\n");
156152
157153 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);
162157 else
163− n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n");
158+ n += sysfs_emit_at(buf, n, "APKA CUR: - -\n");
164159
165160 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);
170164 else
171− n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n");
165+ n += sysfs_emit_at(buf, n, "APKA OLD: - -\n");
172166
173167 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))));
179172 else
180− n += scnprintf(buf + n, PAGE_SIZE, "ASYM NEW: - -\n");
173+ n += sysfs_emit_at(buf, n, "ASYM NEW: - -\n");
181174
182175 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))));
188180 else
189− n += scnprintf(buf + n, PAGE_SIZE - n, "ASYM CUR: - -\n");
181+ n += sysfs_emit_at(buf, n, "ASYM CUR: - -\n");
190182
191183 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))));
197188 else
198− n += scnprintf(buf + n, PAGE_SIZE - n, "ASYM OLD: - -\n");
189+ n += sysfs_emit_at(buf, n, "ASYM OLD: - -\n");
199190
200191 return n;
201192 }
@@ -228,9 +219,9 @@ static ssize_t ep11_api_ordinalnr_show(struct device *dev, · 26 unmodified lines
228219 ep11_get_card_info(ac->id, &ci, zc->online);
229220
230221 if (ci.API_ord_nr > 0)
231− return scnprintf(buf, PAGE_SIZE, "%u\n", ci.API_ord_nr);
222+ return sysfs_emit(buf, "%u\n", ci.API_ord_nr);
232223 else
233− return scnprintf(buf, PAGE_SIZE, "\n");
224+ return sysfs_emit(buf, "\n");
234225 }
235226
236227 static struct device_attribute dev_attr_ep11_api_ordinalnr =
@@ -249,11 +240,11 @@ static ssize_t ep11_fw_version_show(struct device *dev, · 12 unmodified lines
249240 ep11_get_card_info(ac->id, &ci, zc->online);
250241
251242 if (ci.FW_version > 0)
252− return scnprintf(buf, PAGE_SIZE, "%d.%d\n",
253− (int)(ci.FW_version >> 8),
254− (int)(ci.FW_version & 0xFF));
243+ return sysfs_emit(buf, "%d.%d\n",
244+ (int)(ci.FW_version >> 8),
245+ (int)(ci.FW_version & 0xFF));
255246 else
256− return scnprintf(buf, PAGE_SIZE, "\n");
247+ return sysfs_emit(buf, "\n");
257248 }
258249
259250 static struct device_attribute dev_attr_ep11_fw_version =
@@ -272,9 +263,9 @@ static ssize_t ep11_serialnr_show(struct device *dev, · 12 unmodified lines
272263 ep11_get_card_info(ac->id, &ci, zc->online);
273264
274265 if (ci.serial[0])
275− return scnprintf(buf, PAGE_SIZE, "%16.16s\n", ci.serial);
266+ return sysfs_emit(buf, "%16.16s\n", ci.serial);
276267 else
277− return scnprintf(buf, PAGE_SIZE, "\n");
268+ return sysfs_emit(buf, "\n");
278269 }
279270
280271 static struct device_attribute dev_attr_ep11_serialnr =
@@ -309,11 +300,11 @@ static ssize_t ep11_card_op_modes_show(struct device *dev, · 28 unmodified lines
309300 if (ci.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
310301 if (n > 0)
311302 buf[n++] = ' ';
312− n += scnprintf(buf + n, PAGE_SIZE - n,
313− "%s", ep11_op_modes[i].mode_txt);
303+ n += sysfs_emit_at(buf, n, "%s",
304+ ep11_op_modes[i].mode_txt);
314305 }
315306 }
316− n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
307+ n += sysfs_emit_at(buf, n, "\n");
317308
318309 return n;
319310 }
@@ -356,29 +347,29 @@ static ssize_t ep11_mkvps_show(struct device *dev, · 36 unmodified lines
356347 &di);
357348
358349 if (di.cur_wk_state == '0') {
359− n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s -\n",
360− cwk_state[di.cur_wk_state - '0']);
350+ n = sysfs_emit(buf, "WK CUR: %s -\n",
351+ cwk_state[di.cur_wk_state - '0']);
361352 } else if (di.cur_wk_state == '1') {
362− n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s 0x",
363− cwk_state[di.cur_wk_state - '0']);
353+ n = sysfs_emit(buf, "WK CUR: %s 0x",
354+ cwk_state[di.cur_wk_state - '0']);
364355 bin2hex(buf + n, di.cur_wkvp, sizeof(di.cur_wkvp));
365356 n += 2 * sizeof(di.cur_wkvp);
366− n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
357+ n += sysfs_emit_at(buf, n, "\n");
367358 } else {
368− n = scnprintf(buf, PAGE_SIZE, "WK CUR: - -\n");
359+ n = sysfs_emit(buf, "WK CUR: - -\n");
369360 }
370361
371362 if (di.new_wk_state == '0') {
372− n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s -\n",
373− nwk_state[di.new_wk_state - '0']);
363+ n += sysfs_emit_at(buf, n, "WK NEW: %s -\n",
364+ nwk_state[di.new_wk_state - '0']);
374365 } else if (di.new_wk_state >= '1' && di.new_wk_state <= '2') {
375− n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s 0x",
376− nwk_state[di.new_wk_state - '0']);
366+ n += sysfs_emit_at(buf, n, "WK NEW: %s 0x",
367+ nwk_state[di.new_wk_state - '0']);
377368 bin2hex(buf + n, di.new_wkvp, sizeof(di.new_wkvp));
378369 n += 2 * sizeof(di.new_wkvp);
379− n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
370+ n += sysfs_emit_at(buf, n, "\n");
380371 } else {
381− n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: - -\n");
372+ n += sysfs_emit_at(buf, n, "WK NEW: - -\n");
382373 }
383374
384375 return n;
@@ -406,11 +397,11 @@ static ssize_t ep11_queue_op_modes_show(struct device *dev, · 21 unmodified lines
406397 if (di.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
407398 if (n > 0)
408399 buf[n++] = ' ';
409− n += scnprintf(buf + n, PAGE_SIZE - n,
410− "%s", ep11_op_modes[i].mode_txt);
400+ n += sysfs_emit_at(buf, n, "%s",
401+ ep11_op_modes[i].mode_txt);
411402 }
412403 }
413− n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
404+ n += sysfs_emit_at(buf, n, "\n");
414405
415406 return n;
416407 }
drivers/s390/crypto/zcrypt_ep11misc.c+1−1
@@ -1275,7 +1275,7 @@ int ep11_kblob2protkey(u16 card, u16 dom, const u8 *keyblob, size_t keybloblen, · 1274 unmodified lines
12751275 u32 pkeybitsize;
12761276 u64 pkeysize;
12771277 u8 res2[8];
1278− u8 pkey[0];
1278+ u8 pkey[];
12791279 } __packed * wki;
12801280 const u8 *key;
12811281 struct ep11kblob_header *hdr;
drivers/s390/crypto/zcrypt_msgtype50.c+9−6
@@ -441,14 +441,17 @@ static void zcrypt_cex2a_receive(struct ap_queue *aq, · 440 unmodified lines
441441 t80h = reply->msg;
442442 if (t80h->type == TYPE80_RSP_CODE) {
443443 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__);
445447 msg->rc = -EMSGSIZE;
446− } else {
447− memcpy(msg->msg, reply->msg, len);
448− msg->len = len;
448+ goto out;
449449 }
450+ memcpy(msg->msg, reply->msg, len);
451+ msg->len = len;
450452 } else {
451453 memcpy(msg->msg, reply->msg, sizeof(error_reply));
454+ msg->len = sizeof(error_reply);
452455 }
453456 out:
454457 complete((struct completion *)msg->private);
@@ -476,7 +479,7 @@ static long zcrypt_cex2a_modexpo(struct zcrypt_queue *zq, · 21 unmodified lines
476479 if (!ap_msg->msg)
477480 return -ENOMEM;
478481 ap_msg->receive = zcrypt_cex2a_receive;
479− ap_msg->psmid = (((unsigned long long)current->pid) << 32) +
482+ ap_msg->psmid = (((unsigned long)current->pid) << 32) +
480483 atomic_inc_return(&zcrypt_step);
481484 ap_msg->private = &work;
482485 rc = ICAMEX_msg_to_type50MEX_msg(zq, ap_msg, mex);
@@ -527,7 +530,7 @@ static long zcrypt_cex2a_modexpo_crt(struct zcrypt_queue *zq, · 44 unmodified lines
527530 if (!ap_msg->msg)
528531 return -ENOMEM;
529532 ap_msg->receive = zcrypt_cex2a_receive;
530− ap_msg->psmid = (((unsigned long long)current->pid) << 32) +
533+ ap_msg->psmid = (((unsigned long)current->pid) << 32) +
531534 atomic_inc_return(&zcrypt_step);
532535 ap_msg->private = &work;
533536 rc = ICACRT_msg_to_type50CRT_msg(zq, ap_msg, crt);
drivers/s390/crypto/zcrypt_msgtype6.c+47−92
@@ -208,7 +208,7 @@ static int icamex_msg_to_type6mex_msgx(struct zcrypt_queue *zq, · 207 unmodified lines
208208 struct CPRBX cprbx;
209209 struct function_and_rules_block fr;
210210 unsigned short length;
211− char text[0];
211+ char text[];
212212 } __packed * msg = ap_msg->msg;
213213 int size;
214214
@@ -278,7 +278,7 @@ static int icacrt_msg_to_type6crt_msgx(struct zcrypt_queue *zq, · 63 unmodified lines
278278 struct CPRBX cprbx;
279279 struct function_and_rules_block fr;
280280 unsigned short length;
281− char text[0];
281+ char text[];
282282 } __packed * msg = ap_msg->msg;
283283 int size;
284284
@@ -566,8 +566,8 @@ struct type86x_reply { · 281 unmodified lines
566566 struct type86_fmt2_ext fmt2;
567567 struct CPRBX cprbx;
568568 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[];
571571 } __packed;
572572
573573 struct type86_ep11_reply {
@@ -581,45 +581,9 @@ static int convert_type86_ica(struct zcrypt_queue *zq, · 7 unmodified lines
581581 char __user *outputdata,
582582 unsigned int outputdatalength)
583583 {
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− };
619584 struct type86x_reply *msg = reply->msg;
620585 unsigned short service_rc, service_rs;
621− unsigned int reply_len, pad_len;
622− char *data;
586+ unsigned int data_len;
623587
624588 service_rc = msg->cprbx.ccp_rtcode;
625589 if (unlikely(service_rc != 0)) {
@@ -647,32 +611,12 @@ static int convert_type86_ica(struct zcrypt_queue *zq, · 21 unmodified lines
647611 ap_send_online_uevent(&zq->queue->ap_dev, zq->online);
648612 return -EAGAIN;
649613 }
650− data = msg->text;
651− reply_len = msg->length - 2;
652− if (reply_len > outputdatalength)
653− return -EINVAL;
654− /*
655− * For all encipher requests, the length of the ciphertext (reply_len)
656− * will always equal the modulus length. For MEX decipher requests
657− * the output needs to get padded. Minimum pad size is 10.
658− *
659− * Currently, the cases where padding will be added is for:
660− * - PCIXCC_MCL2 using a CRT form token (since PKD didn't support
661− * ZERO-PAD and CRT is only supported for PKD requests)
662− * - PCICC, always
663− */
664− pad_len = outputdatalength - reply_len;
665− if (pad_len > 0) {
666− if (pad_len < 10)
667− return -EINVAL;
668− /* 'restore' padding left in the CEXXC card. */
669− if (copy_to_user(outputdata, static_pad, pad_len - 1))
670− return -EFAULT;
671− if (put_user(0, outputdata + pad_len - 1))
672− return -EFAULT;
673− }
614+ data_len = msg->length - sizeof(msg->length);
615+ if (data_len > outputdatalength)
616+ return -EMSGSIZE;
617+
674618 /* Copy the crypto response to user space. */
675− if (copy_to_user(outputdata + pad_len, data, reply_len))
619+ if (copy_to_user(outputdata, msg->data, data_len))
676620 return -EFAULT;
677621 return 0;
678622 }
@@ -926,8 +870,7 @@ static void zcrypt_msgtype6_receive(struct ap_queue *aq, · 247 unmodified lines
926870 .type = TYPE82_RSP_CODE,
927871 .reply_code = REP82_ERROR_MACHINE_FAILURE,
928872 };
929− struct response_type *resp_type =
930− (struct response_type *)msg->private;
873+ struct response_type *resp_type = msg->private;
931874 struct type86x_reply *t86r;
932875 int len;
933876
@@ -939,28 +882,37 @@ static void zcrypt_msgtype6_receive(struct ap_queue *aq, · 5 unmodified lines
939882 t86r->cprbx.cprb_ver_id == 0x02) {
940883 switch (resp_type->type) {
941884 case CEXXC_RESPONSE_TYPE_ICA:
942− len = sizeof(struct type86x_reply) + t86r->length - 2;
943− if (len > reply->bufsize || len > msg->bufsize) {
885+ len = sizeof(struct type86x_reply) + t86r->length;
886+ if (len > reply->bufsize || len > msg->bufsize ||
887+ len != reply->len) {
888+ ZCRYPT_DBF_DBG("%s len mismatch => EMSGSIZE\n", __func__);
944889 msg->rc = -EMSGSIZE;
945− } else {
946− memcpy(msg->msg, reply->msg, len);
947− msg->len = len;
890+ goto out;
948891 }
892+ memcpy(msg->msg, reply->msg, len);
893+ msg->len = len;
949894 break;
950895 case CEXXC_RESPONSE_TYPE_XCRB:
951− len = t86r->fmt2.offset2 + t86r->fmt2.count2;
952− if (len > reply->bufsize || len > msg->bufsize) {
896+ if (t86r->fmt2.count2)
897+ len = t86r->fmt2.offset2 + t86r->fmt2.count2;
898+ else
899+ len = t86r->fmt2.offset1 + t86r->fmt2.count1;
900+ if (len > reply->bufsize || len > msg->bufsize ||
901+ len != reply->len) {
902+ ZCRYPT_DBF_DBG("%s len mismatch => EMSGSIZE\n", __func__);
953903 msg->rc = -EMSGSIZE;
954− } else {
955− memcpy(msg->msg, reply->msg, len);
956− msg->len = len;
904+ goto out;
957905 }
906+ memcpy(msg->msg, reply->msg, len);
907+ msg->len = len;
958908 break;
959909 default:
960910 memcpy(msg->msg, &error_reply, sizeof(error_reply));
911+ msg->len = sizeof(error_reply);
961912 }
962913 } else {
963914 memcpy(msg->msg, reply->msg, sizeof(error_reply));
915+ msg->len = sizeof(error_reply);
964916 }
965917 out:
966918 complete(&resp_type->work);
@@ -982,8 +934,7 @@ static void zcrypt_msgtype6_receive_ep11(struct ap_queue *aq, · 15 unmodified lines
982934 .type = TYPE82_RSP_CODE,
983935 .reply_code = REP82_ERROR_MACHINE_FAILURE,
984936 };
985− struct response_type *resp_type =
986− (struct response_type *)msg->private;
937+ struct response_type *resp_type = msg->private;
987938 struct type86_ep11_reply *t86r;
988939 int len;
989940
@@ -996,18 +947,22 @@ static void zcrypt_msgtype6_receive_ep11(struct ap_queue *aq, · 6 unmodified lines
996947 switch (resp_type->type) {
997948 case CEXXC_RESPONSE_TYPE_EP11:
998949 len = t86r->fmt2.offset1 + t86r->fmt2.count1;
999− if (len > reply->bufsize || len > msg->bufsize) {
950+ if (len > reply->bufsize || len > msg->bufsize ||
951+ len != reply->len) {
952+ ZCRYPT_DBF_DBG("%s len mismatch => EMSGSIZE\n", __func__);
1000953 msg->rc = -EMSGSIZE;
1001− } else {
1002− memcpy(msg->msg, reply->msg, len);
1003− msg->len = len;
954+ goto out;
1004955 }
956+ memcpy(msg->msg, reply->msg, len);
957+ msg->len = len;
1005958 break;
1006959 default:
1007960 memcpy(msg->msg, &error_reply, sizeof(error_reply));
961+ msg->len = sizeof(error_reply);
1008962 }
1009963 } else {
1010964 memcpy(msg->msg, reply->msg, sizeof(error_reply));
965+ msg->len = sizeof(error_reply);
1011966 }
1012967 out:
1013968 complete(&resp_type->work);
@@ -1036,7 +991,7 @@ static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq, · 22 unmodified lines
1036991 return -ENOMEM;
1037992 ap_msg->bufsize = PAGE_SIZE;
1038993 ap_msg->receive = zcrypt_msgtype6_receive;
1039− ap_msg->psmid = (((unsigned long long)current->pid) << 32) +
994+ ap_msg->psmid = (((unsigned long)current->pid) << 32) +
1040995 atomic_inc_return(&zcrypt_step);
1041996 ap_msg->private = &resp_type;
1042997 rc = icamex_msg_to_type6mex_msgx(zq, ap_msg, mex);
@@ -1086,7 +1041,7 @@ static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq, · 43 unmodified lines
10861041 return -ENOMEM;
10871042 ap_msg->bufsize = PAGE_SIZE;
10881043 ap_msg->receive = zcrypt_msgtype6_receive;
1089− ap_msg->psmid = (((unsigned long long)current->pid) << 32) +
1044+ ap_msg->psmid = (((unsigned long)current->pid) << 32) +
10901045 atomic_inc_return(&zcrypt_step);
10911046 ap_msg->private = &resp_type;
10921047 rc = icacrt_msg_to_type6crt_msgx(zq, ap_msg, crt);
@@ -1137,7 +1092,7 @@ int prep_cca_ap_msg(bool userspace, struct ica_xcRB *xcrb, · 44 unmodified lines
11371092 if (!ap_msg->msg)
11381093 return -ENOMEM;
11391094 ap_msg->receive = zcrypt_msgtype6_receive;
1140− ap_msg->psmid = (((unsigned long long)current->pid) << 32) +
1095+ ap_msg->psmid = (((unsigned long)current->pid) << 32) +
11411096 atomic_inc_return(&zcrypt_step);
11421097 ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
11431098 if (!ap_msg->private)
@@ -1157,7 +1112,7 @@ static long zcrypt_msgtype6_send_cprb(bool userspace, struct zcrypt_queue *zq, · 13 unmodified lines
11571112 struct ap_message *ap_msg)
11581113 {
11591114 int rc;
1160− struct response_type *rtype = (struct response_type *)(ap_msg->private);
1115+ struct response_type *rtype = ap_msg->private;
11611116 struct {
11621117 struct type6_hdr hdr;
11631118 struct CPRBX cprbx;
@@ -1218,7 +1173,7 @@ int prep_ep11_ap_msg(bool userspace, struct ep11_urb *xcrb, · 54 unmodified lines
12181173 if (!ap_msg->msg)
12191174 return -ENOMEM;
12201175 ap_msg->receive = zcrypt_msgtype6_receive_ep11;
1221− ap_msg->psmid = (((unsigned long long)current->pid) << 32) +
1176+ ap_msg->psmid = (((unsigned long)current->pid) << 32) +
12221177 atomic_inc_return(&zcrypt_step);
12231178 ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
12241179 if (!ap_msg->private)
@@ -1240,7 +1195,7 @@ static long zcrypt_msgtype6_send_ep11_cprb(bool userspace, struct zcrypt_queue * · 15 unmodified lines
12401195 {
12411196 int rc;
12421197 unsigned int lfmt;
1243− struct response_type *rtype = (struct response_type *)(ap_msg->private);
1198+ struct response_type *rtype = ap_msg->private;
12441199 struct {
12451200 struct type6_hdr hdr;
12461201 struct ep11_cprb cprbx;
@@ -1328,7 +1283,7 @@ int prep_rng_ap_msg(struct ap_message *ap_msg, int *func_code, · 81 unmodified lines
13281283 if (!ap_msg->msg)
13291284 return -ENOMEM;
13301285 ap_msg->receive = zcrypt_msgtype6_receive;
1331− ap_msg->psmid = (((unsigned long long)current->pid) << 32) +
1286+ ap_msg->psmid = (((unsigned long)current->pid) << 32) +
13321287 atomic_inc_return(&zcrypt_step);
13331288 ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
13341289 if (!ap_msg->private)
@@ -1359,7 +1314,7 @@ static long zcrypt_msgtype6_rng(struct zcrypt_queue *zq, · 24 unmodified lines
13591314 short int verb_length;
13601315 short int key_length;
13611316 } __packed * msg = ap_msg->msg;
1362− struct response_type *rtype = (struct response_type *)(ap_msg->private);
1317+ struct response_type *rtype = ap_msg->private;
13631318 int rc;
13641319
13651320 msg->cprbx.domain = AP_QID_QUEUE(zq->queue->qid);
drivers/s390/crypto/zcrypt_queue.c+2−2
@@ -44,7 +44,7 @@ static ssize_t online_show(struct device *dev, · 43 unmodified lines
4444 struct ap_queue *aq = to_ap_queue(dev);
4545 int online = aq->config && zq->online ? 1 : 0;
4646
47− return scnprintf(buf, PAGE_SIZE, "%d\n", online);
47+ return sysfs_emit(buf, "%d\n", online);
4848 }
4949
5050 static ssize_t online_store(struct device *dev,
@@ -84,7 +84,7 @@ static ssize_t load_show(struct device *dev, · 33 unmodified lines
8484 {
8585 struct zcrypt_queue *zq = dev_get_drvdata(dev);
8686
87− return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load));
87+ return sysfs_emit(buf, "%d\n", atomic_read(&zq->load));
8888 }
8989
9090 static DEVICE_ATTR_RO(load);
kernel/stackleak.c+13−4
@@ -70,6 +70,18 @@ late_initcall(stackleak_sysctls_init); · 69 unmodified lines
7070 #define skip_erasing() false
7171 #endif /* CONFIG_STACKLEAK_RUNTIME_DISABLE */
7272
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+
7385 static __always_inline void __stackleak_erase(bool on_task_stack)
7486 {
7587 const unsigned long task_stack_low = stackleak_task_low_bound(current);
@@ -101,10 +113,7 @@ static __always_inline void __stackleak_erase(bool on_task_stack) · 25 unmodified lines
101113 else
102114 erase_high = task_stack_high;
103115
104− while (erase_low < erase_high) {
105− *(unsigned long *)erase_low = STACKLEAK_POISON;
106− erase_low += sizeof(unsigned long);
107− }
116+ __stackleak_poison(erase_low, erase_high, STACKLEAK_POISON);
108117
109118 /* Reset the 'lowest_stack' value for the next syscall */
110119 current->lowest_stack = task_stack_high;
lib/Kconfig.debug+1−1
@@ -502,7 +502,7 @@ config SECTION_MISMATCH_WARN_ONLY · 501 unmodified lines
502502
503503 config DEBUG_FORCE_FUNCTION_ALIGN_64B
504504 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)
506506 select FUNCTION_ALIGNMENT_64B
507507 help
508508 There are cases that a commit from one domain changes the function