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

Configure Feed

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

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

Pull s390 updates from Vasily Gorbik:

- Remove address space overrides using set_fs()

- Convert to generic vDSO

- Convert to generic page table dumper

- Add ARCH_HAS_DEBUG_WX support

- Add leap seconds handling support

- Add NVMe firmware-assisted kernel dump support

- Extend NVMe boot support with memory clearing control and addition of
kernel parameters

- AP bus and zcrypt api code rework. Add adapter configure/deconfigure
interface. Extend debug features. Add failure injection support

- Add ECC secure private keys support

- Add KASan support for running protected virtualization host with
4-level paging

- Utilize destroy page ultravisor call to speed up secure guests
shutdown

- Implement ioremap_wc() and ioremap_prot() with MIO in PCI code

- Various checksum improvements

- Other small various fixes and improvements all over the code

* tag 's390-5.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (85 commits)
s390/uaccess: fix indentation
s390/uaccess: add default cases for __put_user_fn()/__get_user_fn()
s390/zcrypt: fix wrong format specifications
s390/kprobes: move insn_page to text segment
s390/sie: fix typo in SIGP code description
s390/lib: fix kernel doc for memcmp()
s390/zcrypt: Introduce Failure Injection feature
s390/zcrypt: move ap_msg param one level up the call chain
s390/ap/zcrypt: revisit ap and zcrypt error handling
s390/ap: Support AP card SCLP config and deconfig operations
s390/sclp: Add support for SCLP AP adapter config/deconfig
s390/ap: add card/queue deconfig state
s390/ap: add error response code field for ap queue devices
s390/ap: split ap queue state machine state from device state
s390/zcrypt: New config switch CONFIG_ZCRYPT_DEBUG
s390/zcrypt: introduce msg tracking in zcrypt functions
s390/startup: correct early pgm check info formatting
s390: remove orphaned extern variables declarations
s390/kasan: make sure int handler always run with DAT on
s390/ipl: add support to control memory clearing for nvme re-IPL
...

+4105 -2173
+1 -1
Documentation/features/vm/ioremap_prot/arch-support.txt
··· 24 24 | parisc: | TODO | 25 25 | powerpc: | ok | 26 26 | riscv: | TODO | 27 - | s390: | TODO | 27 + | s390: | ok | 28 28 | sh: | ok | 29 29 | sparc: | TODO | 30 30 | um: | TODO |
+5
arch/s390/Kconfig
··· 60 60 def_bool y 61 61 select ARCH_BINFMT_ELF_STATE 62 62 select ARCH_HAS_DEBUG_VM_PGTABLE 63 + select ARCH_HAS_DEBUG_WX 63 64 select ARCH_HAS_DEVMEM_IS_ALLOWED 64 65 select ARCH_HAS_ELF_RANDOMIZE 65 66 select ARCH_HAS_FORTIFY_SOURCE ··· 74 73 select ARCH_HAS_STRICT_MODULE_RWX 75 74 select ARCH_HAS_SYSCALL_WRAPPER 76 75 select ARCH_HAS_UBSAN_SANITIZE_ALL 76 + select ARCH_HAS_VDSO_DATA 77 77 select ARCH_HAVE_NMI_SAFE_CMPXCHG 78 78 select ARCH_INLINE_READ_LOCK 79 79 select ARCH_INLINE_READ_LOCK_BH ··· 120 118 select GENERIC_CPU_AUTOPROBE 121 119 select GENERIC_CPU_VULNERABILITIES 122 120 select GENERIC_FIND_FIRST_BIT 121 + select GENERIC_GETTIMEOFDAY 122 + select GENERIC_PTDUMP 123 123 select GENERIC_SMP_IDLE_THREAD 124 124 select GENERIC_TIME_VSYSCALL 125 125 select HAVE_ALIGNED_STRUCT_PAGE if SLUB ··· 153 149 select HAVE_FUNCTION_TRACER 154 150 select HAVE_FUTEX_CMPXCHG if FUTEX 155 151 select HAVE_GCC_PLUGINS 152 + select HAVE_GENERIC_VDSO 156 153 select HAVE_KERNEL_BZIP2 157 154 select HAVE_KERNEL_GZIP 158 155 select HAVE_KERNEL_LZ4
-12
arch/s390/Kconfig.debug
··· 3 3 config TRACE_IRQFLAGS_SUPPORT 4 4 def_bool y 5 5 6 - config S390_PTDUMP 7 - bool "Export kernel pagetable layout to userspace via debugfs" 8 - depends on DEBUG_KERNEL 9 - select DEBUG_FS 10 - help 11 - Say Y here if you want to show the kernel pagetable layout in a 12 - debugfs file. This information is only useful for kernel developers 13 - who are working in architecture specific areas of the kernel. 14 - It is probably not a good idea to enable this feature in a production 15 - kernel. 16 - If in doubt, say "N" 17 - 18 6 config EARLY_PRINTK 19 7 def_bool y
-4
arch/s390/boot/Makefile
··· 73 73 install: 74 74 sh -x $(srctree)/$(obj)/install.sh $(KERNELRELEASE) $(obj)/bzImage \ 75 75 System.map "$(INSTALL_PATH)" 76 - 77 - chkbss := $(obj-y) 78 - chkbss-target := startup.a 79 - include $(srctree)/arch/s390/scripts/Makefile.chkbss
-4
arch/s390/boot/compressed/Makefile
··· 62 62 OBJCOPYFLAGS_piggy.o := -I binary -O elf64-s390 -B s390:64-bit --rename-section .data=.vmlinux.bin.compressed 63 63 $(obj)/piggy.o: $(obj)/vmlinux.bin$(suffix-y) FORCE 64 64 $(call if_changed,objcopy) 65 - 66 - chkbss := $(filter-out piggy.o info.o, $(obj-y)) 67 - chkbss-target := vmlinux.bin 68 - include $(srctree)/arch/s390/scripts/Makefile.chkbss
-1
arch/s390/boot/compressed/decompressor.c
··· 16 16 * gzip declarations 17 17 */ 18 18 #define STATIC static 19 - #define STATIC_RW_DATA static __section(.data) 20 19 21 20 #undef memset 22 21 #undef memcpy
+13 -9
arch/s390/boot/compressed/vmlinux.lds.S
··· 59 59 BOOT_DATA_PRESERVED 60 60 61 61 /* 62 + * This is the BSS section of the decompressor and not of the decompressed Linux kernel. 63 + * It will consume place in the decompressor's image. 64 + */ 65 + . = ALIGN(8); 66 + .bss : { 67 + _bss = . ; 68 + *(.bss) 69 + *(.bss.*) 70 + *(COMMON) 71 + _ebss = .; 72 + } 73 + 74 + /* 62 75 * uncompressed image info used by the decompressor it should match 63 76 * struct vmlinux_info. It comes from .vmlinux.info section of 64 77 * uncompressed vmlinux in a form of info.o ··· 93 80 _compressed_end = .; 94 81 FILL(0xff); 95 82 . = ALIGN(4096); 96 - } 97 - . = ALIGN(256); 98 - .bss : { 99 - _bss = . ; 100 - *(.bss) 101 - *(.bss.*) 102 - *(COMMON) 103 - . = ALIGN(8); /* For convenience during zeroing */ 104 - _ebss = .; 105 83 } 106 84 _end = .; 107 85
+11 -10
arch/s390/boot/head.S
··· 360 360 # the save area and does disabled wait with a faulty address. 361 361 # 362 362 ENTRY(startup_pgm_check_handler) 363 - stmg %r0,%r15,__LC_SAVE_AREA_SYNC 364 - la %r1,4095 365 - stctg %c0,%c15,__LC_CREGS_SAVE_AREA-4095(%r1) 366 - mvc __LC_GPREGS_SAVE_AREA-4095(128,%r1),__LC_SAVE_AREA_SYNC 367 - mvc __LC_PSW_SAVE_AREA-4095(16,%r1),__LC_PGM_OLD_PSW 363 + stmg %r8,%r15,__LC_SAVE_AREA_SYNC 364 + la %r8,4095 365 + stctg %c0,%c15,__LC_CREGS_SAVE_AREA-4095(%r8) 366 + stmg %r0,%r7,__LC_GPREGS_SAVE_AREA-4095(%r8) 367 + mvc __LC_GPREGS_SAVE_AREA-4095+64(64,%r8),__LC_SAVE_AREA_SYNC 368 + mvc __LC_PSW_SAVE_AREA-4095(16,%r8),__LC_PGM_OLD_PSW 368 369 mvc __LC_RETURN_PSW(16),__LC_PGM_OLD_PSW 369 370 ni __LC_RETURN_PSW,0xfc # remove IO and EX bits 370 371 ni __LC_RETURN_PSW+1,0xfb # remove MCHK bit 371 372 oi __LC_RETURN_PSW+1,0x2 # set wait state bit 372 - larl %r2,.Lold_psw_disabled_wait 373 - stg %r2,__LC_PGM_NEW_PSW+8 374 - l %r15,.Ldump_info_stack-.Lold_psw_disabled_wait(%r2) 373 + larl %r9,.Lold_psw_disabled_wait 374 + stg %r9,__LC_PGM_NEW_PSW+8 375 + l %r15,.Ldump_info_stack-.Lold_psw_disabled_wait(%r9) 375 376 brasl %r14,print_pgm_check_info 376 377 .Lold_psw_disabled_wait: 377 - la %r1,4095 378 - lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1) 378 + la %r8,4095 379 + lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r8) 379 380 lpswe __LC_RETURN_PSW # disabled wait 380 381 .Ldump_info_stack: 381 382 .long 0x5000 + PAGE_SIZE - STACK_FRAME_OVERHEAD
+46 -14
arch/s390/boot/ipl_parm.c
··· 21 21 int __bootdata(memory_end_set); 22 22 int __bootdata(noexec_disabled); 23 23 24 - int kaslr_enabled __section(.data); 24 + int kaslr_enabled; 25 25 26 26 static inline int __diag308(unsigned long subcode, void *addr) 27 27 { ··· 70 70 static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size, 71 71 const struct ipl_parameter_block *ipb) 72 72 { 73 - size_t count; 74 - size_t i; 73 + const __u8 *scp_data; 74 + __u32 scp_data_len; 75 75 int has_lowercase; 76 + size_t count = 0; 77 + size_t i; 76 78 77 - count = min(size - 1, scpdata_length(ipb->fcp.scp_data, 78 - ipb->fcp.scp_data_len)); 79 + switch (ipb->pb0_hdr.pbt) { 80 + case IPL_PBT_FCP: 81 + scp_data_len = ipb->fcp.scp_data_len; 82 + scp_data = ipb->fcp.scp_data; 83 + break; 84 + case IPL_PBT_NVME: 85 + scp_data_len = ipb->nvme.scp_data_len; 86 + scp_data = ipb->nvme.scp_data; 87 + break; 88 + default: 89 + goto out; 90 + } 91 + 92 + count = min(size - 1, scpdata_length(scp_data, scp_data_len)); 79 93 if (!count) 80 94 goto out; 81 95 82 96 has_lowercase = 0; 83 97 for (i = 0; i < count; i++) { 84 - if (!isascii(ipb->fcp.scp_data[i])) { 98 + if (!isascii(scp_data[i])) { 85 99 count = 0; 86 100 goto out; 87 101 } 88 - if (!has_lowercase && islower(ipb->fcp.scp_data[i])) 102 + if (!has_lowercase && islower(scp_data[i])) 89 103 has_lowercase = 1; 90 104 } 91 105 92 106 if (has_lowercase) 93 - memcpy(dest, ipb->fcp.scp_data, count); 107 + memcpy(dest, scp_data, count); 94 108 else 95 109 for (i = 0; i < count; i++) 96 - dest[i] = tolower(ipb->fcp.scp_data[i]); 110 + dest[i] = tolower(scp_data[i]); 97 111 out: 98 112 dest[count] = '\0'; 99 113 return count; ··· 129 115 parm, COMMAND_LINE_SIZE - len - 1, &ipl_block); 130 116 break; 131 117 case IPL_PBT_FCP: 118 + case IPL_PBT_NVME: 132 119 rc = ipl_block_get_ascii_scpdata( 133 120 parm, COMMAND_LINE_SIZE - len - 1, &ipl_block); 134 121 break; ··· 224 209 check_cleared_facilities(); 225 210 } 226 211 227 - static char command_line_buf[COMMAND_LINE_SIZE] __section(.data); 212 + static char command_line_buf[COMMAND_LINE_SIZE]; 228 213 void parse_boot_command_line(void) 229 214 { 230 215 char *param, *val; ··· 245 230 if (!strcmp(param, "vmalloc") && val) 246 231 vmalloc_size = round_up(memparse(val, NULL), PAGE_SIZE); 247 232 248 - if (!strcmp(param, "dfltcc")) { 233 + if (!strcmp(param, "dfltcc") && val) { 249 234 if (!strcmp(val, "off")) 250 235 zlib_dfltcc_support = ZLIB_DFLTCC_DISABLED; 251 236 else if (!strcmp(val, "on")) ··· 269 254 270 255 if (!strcmp(param, "nokaslr")) 271 256 kaslr_enabled = 0; 257 + 258 + #if IS_ENABLED(CONFIG_KVM) 259 + if (!strcmp(param, "prot_virt")) { 260 + rc = kstrtobool(val, &enabled); 261 + if (!rc && enabled) 262 + prot_virt_host = 1; 263 + } 264 + #endif 272 265 } 266 + } 267 + 268 + static inline bool is_ipl_block_dump(void) 269 + { 270 + if (ipl_block.pb0_hdr.pbt == IPL_PBT_FCP && 271 + ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP) 272 + return true; 273 + if (ipl_block.pb0_hdr.pbt == IPL_PBT_NVME && 274 + ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP) 275 + return true; 276 + return false; 273 277 } 274 278 275 279 void setup_memory_end(void) ··· 296 262 #ifdef CONFIG_CRASH_DUMP 297 263 if (OLDMEM_BASE) { 298 264 kaslr_enabled = 0; 299 - } else if (ipl_block_valid && 300 - ipl_block.pb0_hdr.pbt == IPL_PBT_FCP && 301 - ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP) { 265 + } else if (ipl_block_valid && is_ipl_block_dump()) { 302 266 kaslr_enabled = 0; 303 267 if (!sclp_early_get_hsa_size(&memory_end) && memory_end) 304 268 memory_end_set = 1;
+96 -42
arch/s390/boot/kaslr.c
··· 42 42 return PRNG_MODE_TDES; 43 43 } 44 44 45 - static unsigned long get_random(unsigned long limit) 45 + static int get_random(unsigned long limit, unsigned long *value) 46 46 { 47 47 struct prng_parm prng = { 48 48 /* initial parameter block for tdes mode, copied from libica */ ··· 84 84 (u8 *) &random, sizeof(random)); 85 85 break; 86 86 default: 87 - random = 0; 87 + return -1; 88 88 } 89 - return random % limit; 89 + *value = random % limit; 90 + return 0; 91 + } 92 + 93 + /* 94 + * To randomize kernel base address we have to consider several facts: 95 + * 1. physical online memory might not be continuous and have holes. mem_detect 96 + * info contains list of online memory ranges we should consider. 97 + * 2. we have several memory regions which are occupied and we should not 98 + * overlap and destroy them. Currently safe_addr tells us the border below 99 + * which all those occupied regions are. We are safe to use anything above 100 + * safe_addr. 101 + * 3. the upper limit might apply as well, even if memory above that limit is 102 + * online. Currently those limitations are: 103 + * 3.1. Limit set by "mem=" kernel command line option 104 + * 3.2. memory reserved at the end for kasan initialization. 105 + * 4. kernel base address must be aligned to THREAD_SIZE (kernel stack size). 106 + * Which is required for CONFIG_CHECK_STACK. Currently THREAD_SIZE is 4 pages 107 + * (16 pages when the kernel is built with kasan enabled) 108 + * Assumptions: 109 + * 1. kernel size (including .bss size) and upper memory limit are page aligned. 110 + * 2. mem_detect memory region start is THREAD_SIZE aligned / end is PAGE_SIZE 111 + * aligned (in practice memory configurations granularity on z/VM and LPAR 112 + * is 1mb). 113 + * 114 + * To guarantee uniform distribution of kernel base address among all suitable 115 + * addresses we generate random value just once. For that we need to build a 116 + * continuous range in which every value would be suitable. We can build this 117 + * range by simply counting all suitable addresses (let's call them positions) 118 + * which would be valid as kernel base address. To count positions we iterate 119 + * over online memory ranges. For each range which is big enough for the 120 + * kernel image we count all suitable addresses we can put the kernel image at 121 + * that is 122 + * (end - start - kernel_size) / THREAD_SIZE + 1 123 + * Two functions count_valid_kernel_positions and position_to_address help 124 + * to count positions in memory range given and then convert position back 125 + * to address. 126 + */ 127 + static unsigned long count_valid_kernel_positions(unsigned long kernel_size, 128 + unsigned long _min, 129 + unsigned long _max) 130 + { 131 + unsigned long start, end, pos = 0; 132 + int i; 133 + 134 + for_each_mem_detect_block(i, &start, &end) { 135 + if (_min >= end) 136 + continue; 137 + if (start >= _max) 138 + break; 139 + start = max(_min, start); 140 + end = min(_max, end); 141 + if (end - start < kernel_size) 142 + continue; 143 + pos += (end - start - kernel_size) / THREAD_SIZE + 1; 144 + } 145 + 146 + return pos; 147 + } 148 + 149 + static unsigned long position_to_address(unsigned long pos, unsigned long kernel_size, 150 + unsigned long _min, unsigned long _max) 151 + { 152 + unsigned long start, end; 153 + int i; 154 + 155 + for_each_mem_detect_block(i, &start, &end) { 156 + if (_min >= end) 157 + continue; 158 + if (start >= _max) 159 + break; 160 + start = max(_min, start); 161 + end = min(_max, end); 162 + if (end - start < kernel_size) 163 + continue; 164 + if ((end - start - kernel_size) / THREAD_SIZE + 1 >= pos) 165 + return start + (pos - 1) * THREAD_SIZE; 166 + pos -= (end - start - kernel_size) / THREAD_SIZE + 1; 167 + } 168 + 169 + return 0; 90 170 } 91 171 92 172 unsigned long get_random_base(unsigned long safe_addr) 93 173 { 94 - unsigned long memory_limit = memory_end_set ? memory_end : 0; 95 - unsigned long base, start, end, kernel_size; 96 - unsigned long block_sum, offset; 174 + unsigned long memory_limit = get_mem_detect_end(); 175 + unsigned long base_pos, max_pos, kernel_size; 97 176 unsigned long kasan_needs; 98 177 int i; 178 + 179 + if (memory_end_set) 180 + memory_limit = min(memory_limit, memory_end); 99 181 100 182 if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && INITRD_START && INITRD_SIZE) { 101 183 if (safe_addr < INITRD_START + INITRD_SIZE) ··· 208 126 } 209 127 210 128 kernel_size = vmlinux.image_size + vmlinux.bss_size; 211 - block_sum = 0; 212 - for_each_mem_detect_block(i, &start, &end) { 213 - if (memory_limit) { 214 - if (start >= memory_limit) 215 - break; 216 - if (end > memory_limit) 217 - end = memory_limit; 218 - } 219 - if (end - start < kernel_size) 220 - continue; 221 - block_sum += end - start - kernel_size; 222 - } 223 - if (!block_sum) { 129 + if (safe_addr + kernel_size > memory_limit) 130 + return 0; 131 + 132 + max_pos = count_valid_kernel_positions(kernel_size, safe_addr, memory_limit); 133 + if (!max_pos) { 224 134 sclp_early_printk("KASLR disabled: not enough memory\n"); 225 135 return 0; 226 136 } 227 137 228 - base = get_random(block_sum); 229 - if (base == 0) 138 + /* we need a value in the range [1, base_pos] inclusive */ 139 + if (get_random(max_pos, &base_pos)) 230 140 return 0; 231 - if (base < safe_addr) 232 - base = safe_addr; 233 - block_sum = offset = 0; 234 - for_each_mem_detect_block(i, &start, &end) { 235 - if (memory_limit) { 236 - if (start >= memory_limit) 237 - break; 238 - if (end > memory_limit) 239 - end = memory_limit; 240 - } 241 - if (end - start < kernel_size) 242 - continue; 243 - block_sum += end - start - kernel_size; 244 - if (base <= block_sum) { 245 - base = start + base - offset; 246 - base = ALIGN_DOWN(base, THREAD_SIZE); 247 - break; 248 - } 249 - offset = block_sum; 250 - } 251 - return base; 141 + return position_to_address(base_pos + 1, kernel_size, safe_addr, memory_limit); 252 142 }
+10 -1
arch/s390/boot/pgm_check_info.c
··· 2 2 #include <linux/kernel.h> 3 3 #include <linux/string.h> 4 4 #include <asm/lowcore.h> 5 + #include <asm/setup.h> 5 6 #include <asm/sclp.h> 6 7 #include "boot.h" 7 8 ··· 33 32 char *p; 34 33 35 34 add_str(buf, "Linux version "); 36 - strlcat(buf, kernel_version, sizeof(buf)); 35 + strlcat(buf, kernel_version, sizeof(buf) - 1); 36 + strlcat(buf, "\n", sizeof(buf)); 37 37 sclp_early_printk(buf); 38 38 39 39 p = add_str(buf, "Kernel fault: interruption code "); ··· 43 41 *p++ = hex_asc_lo(ilc); 44 42 add_str(p, "\n"); 45 43 sclp_early_printk(buf); 44 + 45 + if (kaslr_enabled) { 46 + p = add_str(buf, "Kernel random base: "); 47 + p = add_val_as_hex(p, __kaslr_offset); 48 + add_str(p, "\n"); 49 + sclp_early_printk(buf); 50 + } 46 51 47 52 p = add_str(buf, "PSW : "); 48 53 p = add_val_as_hex(p, S390_lowcore.psw_save_area.mask);
+3 -2
arch/s390/boot/startup.c
··· 48 48 }; 49 49 static struct diag210 _diag210_tmp_dma __section(.dma.data); 50 50 struct diag210 *__bootdata_preserved(__diag210_tmp_dma) = &_diag210_tmp_dma; 51 - void _swsusp_reset_dma(void); 52 - unsigned long __bootdata_preserved(__swsusp_reset_dma) = __pa(_swsusp_reset_dma); 53 51 54 52 void error(char *x) 55 53 { ··· 118 120 } 119 121 } 120 122 123 + /* 124 + * This function clears the BSS section of the decompressed Linux kernel and NOT the decompressor's. 125 + */ 121 126 static void clear_bss_section(void) 122 127 { 123 128 memset((void *)vmlinux.default_lma + vmlinux.image_size, 0, vmlinux.bss_size);
-17
arch/s390/boot/text_dma.S
··· 97 97 ENDPROC(_diag0c_dma) 98 98 99 99 /* 100 - * void _swsusp_reset_dma(void) 101 - */ 102 - ENTRY(_swsusp_reset_dma) 103 - larl %r1,restart_entry 104 - larl %r2,.Lrestart_diag308_psw 105 - og %r1,0(%r2) 106 - stg %r1,0(%r0) 107 - lghi %r0,0 108 - diag %r0,%r0,0x308 109 - restart_entry: 110 - lhi %r1,1 111 - sigp %r1,%r0,SIGP_SET_ARCHITECTURE 112 - sam64 113 - BR_EX_DMA_r14 114 - ENDPROC(_swsusp_reset_dma) 115 - 116 - /* 117 100 * void _diag308_reset_dma(void) 118 101 * 119 102 * Calls diag 308 subcode 1 and continues execution
+3
arch/s390/boot/uv.c
··· 7 7 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST 8 8 int __bootdata_preserved(prot_virt_guest); 9 9 #endif 10 + #if IS_ENABLED(CONFIG_KVM) 11 + int __bootdata_preserved(prot_virt_host); 12 + #endif 10 13 struct uv_info __bootdata_preserved(uv_info); 11 14 12 15 void uv_query_info(void)
+2 -1
arch/s390/configs/debug_defconfig
··· 775 775 CONFIG_DEBUG_PAGEALLOC=y 776 776 CONFIG_PAGE_OWNER=y 777 777 CONFIG_DEBUG_RODATA_TEST=y 778 + CONFIG_DEBUG_WX=y 779 + CONFIG_PTDUMP_DEBUGFS=y 778 780 CONFIG_DEBUG_OBJECTS=y 779 781 CONFIG_DEBUG_OBJECTS_SELFTEST=y 780 782 CONFIG_DEBUG_OBJECTS_FREE=y ··· 824 822 CONFIG_BLK_DEV_IO_TRACE=y 825 823 CONFIG_BPF_KPROBE_OVERRIDE=y 826 824 CONFIG_HIST_TRIGGERS=y 827 - CONFIG_S390_PTDUMP=y 828 825 CONFIG_NOTIFIER_ERROR_INJECTION=m 829 826 CONFIG_NETDEV_NOTIFIER_ERROR_INJECT=m 830 827 CONFIG_FAULT_INJECTION=y
+2 -1
arch/s390/configs/defconfig
··· 759 759 CONFIG_FRAME_WARN=1024 760 760 CONFIG_DEBUG_SECTION_MISMATCH=y 761 761 CONFIG_MAGIC_SYSRQ=y 762 + CONFIG_DEBUG_WX=y 763 + CONFIG_PTDUMP_DEBUGFS=y 762 764 CONFIG_DEBUG_MEMORY_INIT=y 763 765 CONFIG_PANIC_ON_OOPS=y 764 766 CONFIG_TEST_LOCKUP=m ··· 777 775 CONFIG_BLK_DEV_IO_TRACE=y 778 776 CONFIG_BPF_KPROBE_OVERRIDE=y 779 777 CONFIG_HIST_TRIGGERS=y 780 - CONFIG_S390_PTDUMP=y 781 778 CONFIG_LKDTM=m 782 779 CONFIG_PERCPU_TEST=m 783 780 CONFIG_ATOMIC64_SELFTEST=y
+61 -44
arch/s390/include/asm/checksum.h
··· 13 13 #define _S390_CHECKSUM_H 14 14 15 15 #include <linux/uaccess.h> 16 + #include <linux/in6.h> 16 17 17 18 /* 18 - * computes the checksum of a memory block at buff, length len, 19 - * and adds in "sum" (32-bit) 19 + * Computes the checksum of a memory block at buff, length len, 20 + * and adds in "sum" (32-bit). 20 21 * 21 - * returns a 32-bit number suitable for feeding into itself 22 - * or csum_tcpudp_magic 22 + * Returns a 32-bit number suitable for feeding into itself 23 + * or csum_tcpudp_magic. 23 24 * 24 - * this function must be called with even lengths, except 25 - * for the last fragment, which may be odd 25 + * This function must be called with even lengths, except 26 + * for the last fragment, which may be odd. 26 27 * 27 - * it's best to have buff aligned on a 32-bit boundary 28 + * It's best to have buff aligned on a 32-bit boundary. 28 29 */ 29 - static inline __wsum 30 - csum_partial(const void *buff, int len, __wsum sum) 30 + static inline __wsum csum_partial(const void *buff, int len, __wsum sum) 31 31 { 32 32 register unsigned long reg2 asm("2") = (unsigned long) buff; 33 33 register unsigned long reg3 asm("3") = (unsigned long) len; ··· 40 40 } 41 41 42 42 /* 43 - * Fold a partial checksum without adding pseudo headers 43 + * Fold a partial checksum without adding pseudo headers. 44 44 */ 45 45 static inline __sum16 csum_fold(__wsum sum) 46 46 { 47 47 u32 csum = (__force u32) sum; 48 48 49 - csum += (csum >> 16) + (csum << 16); 49 + csum += (csum >> 16) | (csum << 16); 50 50 csum >>= 16; 51 51 return (__force __sum16) ~csum; 52 52 } 53 53 54 54 /* 55 - * This is a version of ip_compute_csum() optimized for IP headers, 56 - * which always checksum on 4 octet boundaries. 57 - * 55 + * This is a version of ip_compute_csum() optimized for IP headers, 56 + * which always checksums on 4 octet boundaries. 58 57 */ 59 58 static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) 60 59 { 61 - return csum_fold(csum_partial(iph, ihl*4, 0)); 60 + __u64 csum = 0; 61 + __u32 *ptr = (u32 *)iph; 62 + 63 + csum += *ptr++; 64 + csum += *ptr++; 65 + csum += *ptr++; 66 + csum += *ptr++; 67 + ihl -= 4; 68 + while (ihl--) 69 + csum += *ptr++; 70 + csum += (csum >> 32) | (csum << 32); 71 + return csum_fold((__force __wsum)(csum >> 32)); 62 72 } 63 73 64 74 /* 65 - * computes the checksum of the TCP/UDP pseudo-header 66 - * returns a 32-bit checksum 75 + * Computes the checksum of the TCP/UDP pseudo-header. 76 + * Returns a 32-bit checksum. 67 77 */ 68 - static inline __wsum 69 - csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, __u8 proto, 70 - __wsum sum) 78 + static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, 79 + __u8 proto, __wsum sum) 71 80 { 72 - __u32 csum = (__force __u32)sum; 81 + __u64 csum = (__force __u64)sum; 73 82 74 83 csum += (__force __u32)saddr; 75 - if (csum < (__force __u32)saddr) 76 - csum++; 77 - 78 84 csum += (__force __u32)daddr; 79 - if (csum < (__force __u32)daddr) 80 - csum++; 81 - 82 - csum += len + proto; 83 - if (csum < len + proto) 84 - csum++; 85 - 86 - return (__force __wsum)csum; 85 + csum += len; 86 + csum += proto; 87 + csum += (csum >> 32) | (csum << 32); 88 + return (__force __wsum)(csum >> 32); 87 89 } 88 90 89 91 /* 90 - * computes the checksum of the TCP/UDP pseudo-header 91 - * returns a 16-bit checksum, already complemented 92 + * Computes the checksum of the TCP/UDP pseudo-header. 93 + * Returns a 16-bit checksum, already complemented. 92 94 */ 93 - 94 - static inline __sum16 95 - csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len, __u8 proto, 96 - __wsum sum) 95 + static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len, 96 + __u8 proto, __wsum sum) 97 97 { 98 - return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); 98 + return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum)); 99 99 } 100 100 101 101 /* 102 - * this routine is used for miscellaneous IP-like checksums, mainly 103 - * in icmp.c 102 + * Used for miscellaneous IP-like checksums, mainly icmp. 104 103 */ 105 - 106 104 static inline __sum16 ip_compute_csum(const void *buff, int len) 107 105 { 108 106 return csum_fold(csum_partial(buff, len, 0)); 109 107 } 110 108 109 + #define _HAVE_ARCH_IPV6_CSUM 110 + static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, 111 + const struct in6_addr *daddr, 112 + __u32 len, __u8 proto, __wsum csum) 113 + { 114 + __u64 sum = (__force __u64)csum; 115 + 116 + sum += (__force __u32)saddr->s6_addr32[0]; 117 + sum += (__force __u32)saddr->s6_addr32[1]; 118 + sum += (__force __u32)saddr->s6_addr32[2]; 119 + sum += (__force __u32)saddr->s6_addr32[3]; 120 + sum += (__force __u32)daddr->s6_addr32[0]; 121 + sum += (__force __u32)daddr->s6_addr32[1]; 122 + sum += (__force __u32)daddr->s6_addr32[2]; 123 + sum += (__force __u32)daddr->s6_addr32[3]; 124 + sum += len; 125 + sum += proto; 126 + sum += (sum >> 32) | (sum << 32); 127 + return csum_fold((__force __wsum)(sum >> 32)); 128 + } 129 + 111 130 #endif /* _S390_CHECKSUM_H */ 112 - 113 -
+1 -1
arch/s390/include/asm/cio.h
··· 356 356 return 8 - ffs(mask); 357 357 } 358 358 359 - void channel_subsystem_reinit(void); 360 359 extern void css_schedule_reprobe(void); 361 360 362 361 extern void *cio_dma_zalloc(size_t size); ··· 371 372 /* Function from drivers/s390/cio/chsc.c */ 372 373 int chsc_sstpc(void *page, unsigned int op, u16 ctrl, u64 *clock_delta); 373 374 int chsc_sstpi(void *page, void *result, size_t size); 375 + int chsc_stzi(void *page, void *result, size_t size); 374 376 int chsc_sgib(u32 origin); 375 377 376 378 #endif
+7
arch/s390/include/asm/clocksource.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* s390-specific clocksource additions */ 3 + 4 + #ifndef _ASM_S390_CLOCKSOURCE_H 5 + #define _ASM_S390_CLOCKSOURCE_H 6 + 7 + #endif /* _ASM_S390_CLOCKSOURCE_H */
+3
arch/s390/include/asm/clp.h
··· 5 5 /* CLP common request & response block size */ 6 6 #define CLP_BLK_SIZE PAGE_SIZE 7 7 8 + /* Call Logical Processor - Command Code */ 9 + #define CLP_SLPC 0x0001 10 + 8 11 #define CLP_LPS_BASE 0 9 12 #define CLP_LPS_PCI 2 10 13
-2
arch/s390/include/asm/gmap.h
··· 140 140 141 141 void gmap_register_pte_notifier(struct gmap_notifier *); 142 142 void gmap_unregister_pte_notifier(struct gmap_notifier *); 143 - void gmap_pte_notify(struct mm_struct *, unsigned long addr, pte_t *, 144 - unsigned long bits); 145 143 146 144 int gmap_mprotect_notify(struct gmap *, unsigned long start, 147 145 unsigned long len, int prot);
+8
arch/s390/include/asm/io.h
··· 12 12 13 13 #include <linux/kernel.h> 14 14 #include <asm/page.h> 15 + #include <asm/pgtable.h> 15 16 #include <asm/pci_io.h> 16 17 17 18 #define xlate_dev_mem_ptr xlate_dev_mem_ptr ··· 27 26 28 27 #define IO_SPACE_LIMIT 0 29 28 29 + void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot); 30 30 void __iomem *ioremap(phys_addr_t addr, size_t size); 31 + void __iomem *ioremap_wc(phys_addr_t addr, size_t size); 32 + void __iomem *ioremap_wt(phys_addr_t addr, size_t size); 31 33 void iounmap(volatile void __iomem *addr); 32 34 33 35 static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) ··· 55 51 #define pci_iounmap pci_iounmap 56 52 #define pci_iomap_wc pci_iomap_wc 57 53 #define pci_iomap_wc_range pci_iomap_wc_range 54 + 55 + #define ioremap ioremap 56 + #define ioremap_wt ioremap_wt 57 + #define ioremap_wc ioremap_wc 58 58 59 59 #define memcpy_fromio(dst, src, count) zpci_memcpy_fromio(dst, src, count) 60 60 #define memcpy_toio(dst, src, count) zpci_memcpy_toio(dst, src, count)
+7
arch/s390/include/asm/ipl.h
··· 66 66 IPL_TYPE_FCP_DUMP = 8, 67 67 IPL_TYPE_NSS = 16, 68 68 IPL_TYPE_NVME = 32, 69 + IPL_TYPE_NVME_DUMP = 64, 69 70 }; 70 71 71 72 struct ipl_info ··· 94 93 extern struct ipl_info ipl_info; 95 94 extern void setup_ipl(void); 96 95 extern void set_os_info_reipl_block(void); 96 + 97 + static inline bool is_ipl_type_dump(void) 98 + { 99 + return (ipl_info.type == IPL_TYPE_FCP_DUMP) || 100 + (ipl_info.type == IPL_TYPE_NVME_DUMP); 101 + } 97 102 98 103 struct ipl_report { 99 104 struct ipl_parameter_block *ipib;
+1
arch/s390/include/asm/kasan.h
··· 19 19 extern void kasan_early_init(void); 20 20 extern void kasan_copy_shadow(pgd_t *dst); 21 21 extern void kasan_free_early_identity(void); 22 + extern unsigned long kasan_vmax; 22 23 #else 23 24 static inline void kasan_early_init(void) { } 24 25 static inline void kasan_copy_shadow(pgd_t *dst) { }
+1 -5
arch/s390/include/asm/pci.h
··· 208 208 void zpci_remove_reserved_devices(void); 209 209 210 210 /* CLP */ 211 + int clp_setup_writeback_mio(void); 211 212 int clp_scan_pci_devices(void); 212 - int clp_rescan_pci_devices(void); 213 - int clp_rescan_pci_devices_simple(u32 *fid); 214 213 int clp_add_pci_device(u32, u32, int); 215 214 int clp_enable_fh(struct zpci_dev *, u8); 216 215 int clp_disable_fh(struct zpci_dev *); ··· 231 232 /* Error handling and recovery */ 232 233 void zpci_event_error(void *); 233 234 void zpci_event_availability(void *); 234 - void zpci_rescan(void); 235 235 bool zpci_is_enabled(void); 236 236 #else /* CONFIG_PCI */ 237 237 static inline void zpci_event_error(void *e) {} 238 238 static inline void zpci_event_availability(void *e) {} 239 - static inline void zpci_rescan(void) {} 240 239 #endif /* CONFIG_PCI */ 241 240 242 241 #ifdef CONFIG_HOTPLUG_PCI_S390 ··· 279 282 void zpci_debug_exit(void); 280 283 void zpci_debug_init_device(struct zpci_dev *, const char *); 281 284 void zpci_debug_exit_device(struct zpci_dev *); 282 - void zpci_debug_info(struct zpci_dev *, struct seq_file *); 283 285 284 286 /* Error reporting */ 285 287 int zpci_report_error(struct pci_dev *, struct zpci_report_error_header *);
+19
arch/s390/include/asm/pci_clp.h
··· 7 7 /* 8 8 * Call Logical Processor - Command Codes 9 9 */ 10 + #define CLP_SLPC 0x0001 10 11 #define CLP_LIST_PCI 0x0002 11 12 #define CLP_QUERY_PCI_FN 0x0003 12 13 #define CLP_QUERY_PCI_FNGRP 0x0004 ··· 51 50 #define CLP_PFIP_NR_SEGMENTS 4 52 51 53 52 extern bool zpci_unique_uid; 53 + 54 + struct clp_rsp_slpc_pci { 55 + struct clp_rsp_hdr hdr; 56 + u32 reserved2[4]; 57 + u32 lpif[8]; 58 + u32 reserved3[4]; 59 + u32 vwb : 1; 60 + u32 : 1; 61 + u32 mio_wb : 6; 62 + u32 : 24; 63 + u32 reserved5[3]; 64 + u32 lpic[8]; 65 + } __packed; 54 66 55 67 /* List PCI functions request */ 56 68 struct clp_req_list_pci { ··· 186 172 } __packed; 187 173 188 174 /* Combined request/response block structures used by clp insn */ 175 + struct clp_req_rsp_slpc_pci { 176 + struct clp_req_slpc request; 177 + struct clp_rsp_slpc_pci response; 178 + } __packed; 179 + 189 180 struct clp_req_rsp_list_pci { 190 181 struct clp_req_list_pci request; 191 182 struct clp_rsp_list_pci response;
-2
arch/s390/include/asm/pgalloc.h
··· 146 146 #define pte_free_kernel(mm, pte) page_table_free(mm, (unsigned long *) pte) 147 147 #define pte_free(mm, pte) page_table_free(mm, (unsigned long *) pte) 148 148 149 - extern void rcu_table_freelist_finish(void); 150 - 151 149 void vmem_map_init(void); 152 150 void *vmem_crst_alloc(unsigned long val); 153 151 pte_t *vmem_pte_alloc(void);
+9 -1
arch/s390/include/asm/pgtable.h
··· 89 89 extern unsigned long VMALLOC_END; 90 90 #define VMALLOC_DEFAULT_SIZE ((128UL << 30) - MODULES_LEN) 91 91 extern struct page *vmemmap; 92 + extern unsigned long vmemmap_size; 92 93 93 94 #define VMEM_MAX_PHYS ((unsigned long) vmemmap) 94 95 ··· 1187 1186 void gmap_pmdp_idte_local(struct mm_struct *mm, unsigned long vmaddr); 1188 1187 void gmap_pmdp_idte_global(struct mm_struct *mm, unsigned long vmaddr); 1189 1188 1189 + #define pgprot_writecombine pgprot_writecombine 1190 + pgprot_t pgprot_writecombine(pgprot_t prot); 1191 + 1192 + #define pgprot_writethrough pgprot_writethrough 1193 + pgprot_t pgprot_writethrough(pgprot_t prot); 1194 + 1190 1195 /* 1191 1196 * Certain architectures need to do special things when PTEs 1192 1197 * within a page table are directly modified. Thus, the following ··· 1216 1209 static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot) 1217 1210 { 1218 1211 pte_t __pte; 1219 - pte_val(__pte) = physpage + pgprot_val(pgprot); 1212 + 1213 + pte_val(__pte) = physpage | pgprot_val(pgprot); 1220 1214 if (!MACHINE_HAS_NX) 1221 1215 pte_val(__pte) &= ~_PAGE_NOEXEC; 1222 1216 return pte_mkyoung(__pte);
+14
arch/s390/include/asm/ptdump.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef _ASM_S390_PTDUMP_H 4 + #define _ASM_S390_PTDUMP_H 5 + 6 + void ptdump_check_wx(void); 7 + 8 + static inline void debug_checkwx(void) 9 + { 10 + if (IS_ENABLED(CONFIG_DEBUG_WX)) 11 + ptdump_check_wx(); 12 + } 13 + 14 + #endif /* _ASM_S390_PTDUMP_H */
+4 -6
arch/s390/include/asm/qdio.h
··· 26 26 27 27 /** 28 28 * struct qdesfmt0 - queue descriptor, format 0 29 - * @sliba: storage list information block address 30 - * @sla: storage list address 31 - * @slsba: storage list state block address 29 + * @sliba: absolute address of storage list information block 30 + * @sla: absolute address of storage list 31 + * @slsba: absolute address of storage list state block 32 32 * @akey: access key for SLIB 33 33 * @bkey: access key for SL 34 34 * @ckey: access key for SBALs ··· 56 56 * @oqdcnt: output queue descriptor count 57 57 * @iqdsz: input queue descriptor size 58 58 * @oqdsz: output queue descriptor size 59 - * @qiba: queue information block address 59 + * @qiba: absolute address of queue information block 60 60 * @qkey: queue information block key 61 61 * @qdf0: queue descriptions 62 62 */ ··· 327 327 * struct qdio_initialize - qdio initialization data 328 328 * @q_format: queue format 329 329 * @qdr_ac: feature flags to set 330 - * @adapter_name: name for the adapter 331 330 * @qib_param_field_format: format for qib_parm_field 332 331 * @qib_param_field: pointer to 128 bytes or NULL, if no param field 333 332 * @qib_rflags: rflags to set ··· 346 347 struct qdio_initialize { 347 348 unsigned char q_format; 348 349 unsigned char qdr_ac; 349 - unsigned char adapter_name[8]; 350 350 unsigned int qib_param_field_format; 351 351 unsigned char *qib_param_field; 352 352 unsigned char qib_rflags;
+3 -2
arch/s390/include/asm/sclp.h
··· 114 114 void sclp_early_get_ipl_info(struct sclp_ipl_info *info); 115 115 void sclp_early_detect(void); 116 116 void sclp_early_printk(const char *s); 117 - void sclp_early_printk_force(const char *s); 118 - void __sclp_early_printk(const char *s, unsigned int len, unsigned int force); 117 + void __sclp_early_printk(const char *s, unsigned int len); 119 118 120 119 int sclp_early_get_memsize(unsigned long *mem); 121 120 int sclp_early_get_hsa_size(unsigned long *hsa_size); ··· 128 129 int sclp_chp_read_info(struct sclp_chp_info *info); 129 130 int sclp_pci_configure(u32 fid); 130 131 int sclp_pci_deconfigure(u32 fid); 132 + int sclp_ap_configure(u32 apid); 133 + int sclp_ap_deconfigure(u32 apid); 131 134 int sclp_pci_report(struct zpci_report_error_header *report, u32 fh, u32 fid); 132 135 int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count); 133 136 int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count);
+4
arch/s390/include/asm/set_memory.h
··· 2 2 #ifndef _ASMS390_SET_MEMORY_H 3 3 #define _ASMS390_SET_MEMORY_H 4 4 5 + #include <linux/mutex.h> 6 + 7 + extern struct mutex cpa_mutex; 8 + 5 9 #define SET_MEMORY_RO 1UL 6 10 #define SET_MEMORY_RW 2UL 7 11 #define SET_MEMORY_NX 4UL
+3 -4
arch/s390/include/asm/setup.h
··· 92 92 extern unsigned long memory_end; 93 93 extern unsigned long vmalloc_size; 94 94 extern unsigned long max_physmem_end; 95 - extern unsigned long __swsusp_reset_dma; 95 + 96 + /* The Write Back bit position in the physaddr is given by the SLPC PCI */ 97 + extern unsigned long mio_wb_bit_mask; 96 98 97 99 #define MACHINE_IS_VM (S390_lowcore.machine_flags & MACHINE_FLAG_VM) 98 100 #define MACHINE_IS_KVM (S390_lowcore.machine_flags & MACHINE_FLAG_KVM) ··· 120 118 extern unsigned int console_mode; 121 119 extern unsigned int console_devno; 122 120 extern unsigned int console_irq; 123 - 124 - extern char vmhalt_cmd[]; 125 - extern char vmpoff_cmd[]; 126 121 127 122 #define CONSOLE_IS_UNDEFINED (console_mode == 0) 128 123 #define CONSOLE_IS_SCLP (console_mode == 1)
-1
arch/s390/include/asm/smp.h
··· 31 31 extern int smp_find_processor_id(u16 address); 32 32 extern int smp_store_status(int cpu); 33 33 extern void smp_save_dump_cpus(void); 34 - extern int smp_vcpu_scheduled(int cpu); 35 34 extern void smp_yield_cpu(int cpu); 36 35 extern void smp_cpu_set_polarization(int cpu, int val); 37 36 extern int smp_cpu_get_polarization(int cpu);
+73 -27
arch/s390/include/asm/stp.h
··· 6 6 #ifndef __S390_STP_H 7 7 #define __S390_STP_H 8 8 9 + #include <linux/compiler.h> 10 + 9 11 /* notifier for syncs */ 10 12 extern struct atomic_notifier_head s390_epoch_delta_notifier; 11 13 12 14 /* STP interruption parameter */ 13 15 struct stp_irq_parm { 14 - unsigned int _pad0 : 14; 15 - unsigned int tsc : 1; /* Timing status change */ 16 - unsigned int lac : 1; /* Link availability change */ 17 - unsigned int tcpc : 1; /* Time control parameter change */ 18 - unsigned int _pad2 : 15; 19 - } __attribute__ ((packed)); 16 + u32 : 14; 17 + u32 tsc : 1; /* Timing status change */ 18 + u32 lac : 1; /* Link availability change */ 19 + u32 tcpc : 1; /* Time control parameter change */ 20 + u32 : 15; 21 + } __packed; 20 22 21 23 #define STP_OP_SYNC 1 22 24 #define STP_OP_CTRL 3 23 25 24 26 struct stp_sstpi { 25 - unsigned int rsvd0; 26 - unsigned int rsvd1 : 8; 27 - unsigned int stratum : 8; 28 - unsigned int vbits : 16; 29 - unsigned int leaps : 16; 30 - unsigned int tmd : 4; 31 - unsigned int ctn : 4; 32 - unsigned int rsvd2 : 3; 33 - unsigned int c : 1; 34 - unsigned int tst : 4; 35 - unsigned int tzo : 16; 36 - unsigned int dsto : 16; 37 - unsigned int ctrl : 16; 38 - unsigned int rsvd3 : 16; 39 - unsigned int tto; 40 - unsigned int rsvd4; 41 - unsigned int ctnid[3]; 42 - unsigned int rsvd5; 43 - unsigned int todoff[4]; 44 - unsigned int rsvd6[48]; 45 - } __attribute__ ((packed)); 27 + u32 : 32; 28 + u32 tu : 1; 29 + u32 lu : 1; 30 + u32 : 6; 31 + u32 stratum : 8; 32 + u32 vbits : 16; 33 + u32 leaps : 16; 34 + u32 tmd : 4; 35 + u32 ctn : 4; 36 + u32 : 3; 37 + u32 c : 1; 38 + u32 tst : 4; 39 + u32 tzo : 16; 40 + u32 dsto : 16; 41 + u32 ctrl : 16; 42 + u32 : 16; 43 + u32 tto; 44 + u32 : 32; 45 + u32 ctnid[3]; 46 + u32 : 32; 47 + u32 todoff[4]; 48 + u32 rsvd[48]; 49 + } __packed; 50 + 51 + struct stp_tzib { 52 + u32 tzan : 16; 53 + u32 : 16; 54 + u32 tzo : 16; 55 + u32 dsto : 16; 56 + u32 stn; 57 + u32 dstn; 58 + u64 dst_on_alg; 59 + u64 dst_off_alg; 60 + } __packed; 61 + 62 + struct stp_tcpib { 63 + u32 atcode : 4; 64 + u32 ntcode : 4; 65 + u32 d : 1; 66 + u32 : 23; 67 + s32 tto; 68 + struct stp_tzib atzib; 69 + struct stp_tzib ntzib; 70 + s32 adst_offset : 16; 71 + s32 ndst_offset : 16; 72 + u32 rsvd1; 73 + u64 ntzib_update; 74 + u64 ndsto_update; 75 + } __packed; 76 + 77 + struct stp_lsoib { 78 + u32 p : 1; 79 + u32 : 31; 80 + s32 also : 16; 81 + s32 nlso : 16; 82 + u64 nlsout; 83 + } __packed; 84 + 85 + struct stp_stzi { 86 + u32 rsvd0[3]; 87 + u64 data_ts; 88 + u32 rsvd1[22]; 89 + struct stp_tcpib tcpib; 90 + struct stp_lsoib lsoib; 91 + } __packed; 46 92 47 93 /* Functions needed by the machine check handler */ 48 94 int stp_sync_check(void);
-2
arch/s390/include/asm/tlbflush.h
··· 30 30 : : "a" (opt), "a" (asce) : "cc"); 31 31 } 32 32 33 - void smp_ptlb_all(void); 34 - 35 33 /* 36 34 * Flush all TLB entries on all CPUs. 37 35 */
+121 -5
arch/s390/include/asm/uaccess.h
··· 60 60 #define INLINE_COPY_TO_USER 61 61 #endif 62 62 63 + int __put_user_bad(void) __attribute__((noreturn)); 64 + int __get_user_bad(void) __attribute__((noreturn)); 65 + 63 66 #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES 64 67 65 68 #define __put_get_user_asm(to, from, size, spec) \ ··· 112 109 (unsigned long *)x, 113 110 size, spec); 114 111 break; 112 + default: 113 + __put_user_bad(); 114 + break; 115 115 } 116 116 return rc; 117 117 } ··· 144 138 rc = __put_get_user_asm((unsigned long *)x, 145 139 (unsigned long __user *)ptr, 146 140 size, spec); 141 + break; 142 + default: 143 + __get_user_bad(); 147 144 break; 148 145 } 149 146 return rc; ··· 188 179 default: \ 189 180 __put_user_bad(); \ 190 181 break; \ 191 - } \ 182 + } \ 192 183 __builtin_expect(__pu_err, 0); \ 193 184 }) 194 185 ··· 198 189 __put_user(x, ptr); \ 199 190 }) 200 191 201 - 202 - int __put_user_bad(void) __attribute__((noreturn)); 203 192 204 193 #define __get_user(x, ptr) \ 205 194 ({ \ ··· 245 238 __get_user(x, ptr); \ 246 239 }) 247 240 248 - int __get_user_bad(void) __attribute__((noreturn)); 249 - 250 241 unsigned long __must_check 251 242 raw_copy_in_user(void __user *to, const void __user *from, unsigned long n); 252 243 ··· 282 277 283 278 int copy_to_user_real(void __user *dest, void *src, unsigned long count); 284 279 void *s390_kernel_write(void *dst, const void *src, size_t size); 280 + 281 + #define HAVE_GET_KERNEL_NOFAULT 282 + 283 + int __noreturn __put_kernel_bad(void); 284 + 285 + #define __put_kernel_asm(val, to, insn) \ 286 + ({ \ 287 + int __rc; \ 288 + \ 289 + asm volatile( \ 290 + "0: " insn " %2,%1\n" \ 291 + "1: xr %0,%0\n" \ 292 + "2:\n" \ 293 + ".pushsection .fixup, \"ax\"\n" \ 294 + "3: lhi %0,%3\n" \ 295 + " jg 2b\n" \ 296 + ".popsection\n" \ 297 + EX_TABLE(0b,3b) EX_TABLE(1b,3b) \ 298 + : "=d" (__rc), "+Q" (*(to)) \ 299 + : "d" (val), "K" (-EFAULT) \ 300 + : "cc"); \ 301 + __rc; \ 302 + }) 303 + 304 + #define __put_kernel_nofault(dst, src, type, err_label) \ 305 + do { \ 306 + u64 __x = (u64)(*((type *)(src))); \ 307 + int __pk_err; \ 308 + \ 309 + switch (sizeof(type)) { \ 310 + case 1: \ 311 + __pk_err = __put_kernel_asm(__x, (type *)(dst), "stc"); \ 312 + break; \ 313 + case 2: \ 314 + __pk_err = __put_kernel_asm(__x, (type *)(dst), "sth"); \ 315 + break; \ 316 + case 4: \ 317 + __pk_err = __put_kernel_asm(__x, (type *)(dst), "st"); \ 318 + break; \ 319 + case 8: \ 320 + __pk_err = __put_kernel_asm(__x, (type *)(dst), "stg"); \ 321 + break; \ 322 + default: \ 323 + __pk_err = __put_kernel_bad(); \ 324 + break; \ 325 + } \ 326 + if (unlikely(__pk_err)) \ 327 + goto err_label; \ 328 + } while (0) 329 + 330 + int __noreturn __get_kernel_bad(void); 331 + 332 + #define __get_kernel_asm(val, from, insn) \ 333 + ({ \ 334 + int __rc; \ 335 + \ 336 + asm volatile( \ 337 + "0: " insn " %1,%2\n" \ 338 + "1: xr %0,%0\n" \ 339 + "2:\n" \ 340 + ".pushsection .fixup, \"ax\"\n" \ 341 + "3: lhi %0,%3\n" \ 342 + " jg 2b\n" \ 343 + ".popsection\n" \ 344 + EX_TABLE(0b,3b) EX_TABLE(1b,3b) \ 345 + : "=d" (__rc), "+d" (val) \ 346 + : "Q" (*(from)), "K" (-EFAULT) \ 347 + : "cc"); \ 348 + __rc; \ 349 + }) 350 + 351 + #define __get_kernel_nofault(dst, src, type, err_label) \ 352 + do { \ 353 + int __gk_err; \ 354 + \ 355 + switch (sizeof(type)) { \ 356 + case 1: { \ 357 + u8 __x = 0; \ 358 + \ 359 + __gk_err = __get_kernel_asm(__x, (type *)(src), "ic"); \ 360 + *((type *)(dst)) = (type)__x; \ 361 + break; \ 362 + }; \ 363 + case 2: { \ 364 + u16 __x = 0; \ 365 + \ 366 + __gk_err = __get_kernel_asm(__x, (type *)(src), "lh"); \ 367 + *((type *)(dst)) = (type)__x; \ 368 + break; \ 369 + }; \ 370 + case 4: { \ 371 + u32 __x = 0; \ 372 + \ 373 + __gk_err = __get_kernel_asm(__x, (type *)(src), "l"); \ 374 + *((type *)(dst)) = (type)__x; \ 375 + break; \ 376 + }; \ 377 + case 8: { \ 378 + u64 __x = 0; \ 379 + \ 380 + __gk_err = __get_kernel_asm(__x, (type *)(src), "lg"); \ 381 + *((type *)(dst)) = (type)__x; \ 382 + break; \ 383 + }; \ 384 + default: \ 385 + __gk_err = __get_kernel_bad(); \ 386 + break; \ 387 + } \ 388 + if (unlikely(__gk_err)) \ 389 + goto err_label; \ 390 + } while (0) 285 391 286 392 #endif /* __S390_UACCESS_H */
+7
arch/s390/include/asm/uv.h
··· 33 33 #define UVC_CMD_DESTROY_SEC_CPU 0x0121 34 34 #define UVC_CMD_CONV_TO_SEC_STOR 0x0200 35 35 #define UVC_CMD_CONV_FROM_SEC_STOR 0x0201 36 + #define UVC_CMD_DESTR_SEC_STOR 0x0202 36 37 #define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300 37 38 #define UVC_CMD_UNPACK_IMG 0x0301 38 39 #define UVC_CMD_VERIFY_IMG 0x0302 ··· 345 344 } 346 345 347 346 int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb); 347 + int uv_destroy_page(unsigned long paddr); 348 348 int uv_convert_from_secure(unsigned long paddr); 349 349 int gmap_convert_to_secure(struct gmap *gmap, unsigned long gaddr); 350 350 ··· 355 353 #define is_prot_virt_host() 0 356 354 static inline void setup_uv(void) {} 357 355 static inline void adjust_to_uv_max(unsigned long *vmax) {} 356 + 357 + static inline int uv_destroy_page(unsigned long paddr) 358 + { 359 + return 0; 360 + } 358 361 359 362 static inline int uv_convert_from_secure(unsigned long paddr) 360 363 {
+2 -25
arch/s390/include/asm/vdso.h
··· 2 2 #ifndef __S390_VDSO_H__ 3 3 #define __S390_VDSO_H__ 4 4 5 + #include <vdso/datapage.h> 6 + 5 7 /* Default link addresses for the vDSOs */ 6 8 #define VDSO32_LBASE 0 7 9 #define VDSO64_LBASE 0 ··· 20 18 * itself and may change without notice. 21 19 */ 22 20 23 - struct vdso_data { 24 - __u64 tb_update_count; /* Timebase atomicity ctr 0x00 */ 25 - __u64 xtime_tod_stamp; /* TOD clock for xtime 0x08 */ 26 - __u64 xtime_clock_sec; /* Kernel time 0x10 */ 27 - __u64 xtime_clock_nsec; /* 0x18 */ 28 - __u64 xtime_coarse_sec; /* Coarse kernel time 0x20 */ 29 - __u64 xtime_coarse_nsec; /* 0x28 */ 30 - __u64 wtom_clock_sec; /* Wall to monotonic clock 0x30 */ 31 - __u64 wtom_clock_nsec; /* 0x38 */ 32 - __u64 wtom_coarse_sec; /* Coarse wall to monotonic 0x40 */ 33 - __u64 wtom_coarse_nsec; /* 0x48 */ 34 - __u32 tz_minuteswest; /* Minutes west of Greenwich 0x50 */ 35 - __u32 tz_dsttime; /* Type of dst correction 0x54 */ 36 - __u32 ectg_available; /* ECTG instruction present 0x58 */ 37 - __u32 tk_mult; /* Mult. used for xtime_nsec 0x5c */ 38 - __u32 tk_shift; /* Shift used for xtime_nsec 0x60 */ 39 - __u32 ts_dir; /* TOD steering direction 0x64 */ 40 - __u64 ts_end; /* TOD steering end 0x68 */ 41 - __u32 hrtimer_res; /* hrtimer resolution 0x70 */ 42 - }; 43 - 44 21 struct vdso_per_cpu_data { 45 - __u64 ectg_timer_base; 46 - __u64 ectg_user_time; 47 22 /* 48 23 * Note: node_id and cpu_nr must be at adjacent memory locations. 49 24 * VDSO userspace must read both values with a single instruction. ··· 35 56 }; 36 57 37 58 extern struct vdso_data *vdso_data; 38 - extern struct vdso_data boot_vdso_data; 39 59 40 - void vdso_alloc_boot_cpu(struct lowcore *lowcore); 41 60 int vdso_alloc_per_cpu(struct lowcore *lowcore); 42 61 void vdso_free_per_cpu(struct lowcore *lowcore); 43 62
+8
arch/s390/include/asm/vdso/clocksource.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __ASM_VDSO_CLOCKSOURCE_H 3 + #define __ASM_VDSO_CLOCKSOURCE_H 4 + 5 + #define VDSO_ARCH_CLOCKMODES \ 6 + VDSO_CLOCKMODE_TOD 7 + 8 + #endif /* __ASM_VDSO_CLOCKSOURCE_H */
+13
arch/s390/include/asm/vdso/data.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __S390_ASM_VDSO_DATA_H 3 + #define __S390_ASM_VDSO_DATA_H 4 + 5 + #include <linux/types.h> 6 + #include <vdso/datapage.h> 7 + 8 + struct arch_vdso_data { 9 + __u64 tod_steering_delta; 10 + __u64 tod_steering_end; 11 + }; 12 + 13 + #endif /* __S390_ASM_VDSO_DATA_H */
+71
arch/s390/include/asm/vdso/gettimeofday.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef ASM_VDSO_GETTIMEOFDAY_H 3 + #define ASM_VDSO_GETTIMEOFDAY_H 4 + 5 + #define VDSO_HAS_TIME 1 6 + 7 + #define VDSO_HAS_CLOCK_GETRES 1 8 + 9 + #include <asm/timex.h> 10 + #include <asm/unistd.h> 11 + #include <asm/vdso.h> 12 + #include <linux/compiler.h> 13 + 14 + #define vdso_calc_delta __arch_vdso_calc_delta 15 + static __always_inline u64 __arch_vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult) 16 + { 17 + return (cycles - last) * mult; 18 + } 19 + 20 + static __always_inline const struct vdso_data *__arch_get_vdso_data(void) 21 + { 22 + return _vdso_data; 23 + } 24 + 25 + static inline u64 __arch_get_hw_counter(s32 clock_mode, const struct vdso_data *vd) 26 + { 27 + const struct vdso_data *vdso = __arch_get_vdso_data(); 28 + u64 adj, now; 29 + 30 + now = get_tod_clock(); 31 + adj = vdso->arch_data.tod_steering_end - now; 32 + if (unlikely((s64) adj > 0)) 33 + now += (vdso->arch_data.tod_steering_delta < 0) ? (adj >> 15) : -(adj >> 15); 34 + return now; 35 + } 36 + 37 + static __always_inline 38 + long clock_gettime_fallback(clockid_t clkid, struct __kernel_timespec *ts) 39 + { 40 + register unsigned long r1 __asm__("r1") = __NR_clock_gettime; 41 + register unsigned long r2 __asm__("r2") = (unsigned long)clkid; 42 + register void *r3 __asm__("r3") = ts; 43 + 44 + asm ("svc 0\n" : "+d" (r2) : "d" (r1), "d" (r3) : "cc", "memory"); 45 + return r2; 46 + } 47 + 48 + static __always_inline 49 + long gettimeofday_fallback(register struct __kernel_old_timeval *tv, 50 + register struct timezone *tz) 51 + { 52 + register unsigned long r1 __asm__("r1") = __NR_gettimeofday; 53 + register unsigned long r2 __asm__("r2") = (unsigned long)tv; 54 + register void *r3 __asm__("r3") = tz; 55 + 56 + asm ("svc 0\n" : "+d" (r2) : "d" (r1), "d" (r3) : "cc", "memory"); 57 + return r2; 58 + } 59 + 60 + static __always_inline 61 + long clock_getres_fallback(clockid_t clkid, struct __kernel_timespec *ts) 62 + { 63 + register unsigned long r1 __asm__("r1") = __NR_clock_getres; 64 + register unsigned long r2 __asm__("r2") = (unsigned long)clkid; 65 + register void *r3 __asm__("r3") = ts; 66 + 67 + asm ("svc 0\n" : "+d" (r2) : "d" (r1), "d" (r3) : "cc", "memory"); 68 + return r2; 69 + } 70 + 71 + #endif
+7
arch/s390/include/asm/vdso/processor.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + #ifndef __ASM_VDSO_PROCESSOR_H 3 + #define __ASM_VDSO_PROCESSOR_H 4 + 5 + #define cpu_relax() barrier() 6 + 7 + #endif /* __ASM_VDSO_PROCESSOR_H */
arch/s390/include/asm/vdso/vdso.h
+26
arch/s390/include/asm/vdso/vsyscall.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __ASM_VDSO_VSYSCALL_H 3 + #define __ASM_VDSO_VSYSCALL_H 4 + 5 + #ifndef __ASSEMBLY__ 6 + 7 + #include <linux/hrtimer.h> 8 + #include <linux/timekeeper_internal.h> 9 + #include <vdso/datapage.h> 10 + #include <asm/vdso.h> 11 + /* 12 + * Update the vDSO data page to keep in sync with kernel timekeeping. 13 + */ 14 + 15 + static __always_inline struct vdso_data *__s390_get_k_vdso_data(void) 16 + { 17 + return vdso_data; 18 + } 19 + #define __arch_get_k_vdso_data __s390_get_k_vdso_data 20 + 21 + /* The asm-generic header needs to be included after the definitions above */ 22 + #include <asm-generic/vdso/vsyscall.h> 23 + 24 + #endif /* !__ASSEMBLY__ */ 25 + 26 + #endif /* __ASM_VDSO_VSYSCALL_H */
-2
arch/s390/include/asm/vtimer.h
··· 25 25 extern int mod_virt_timer(struct vtimer_list *timer, u64 expires); 26 26 extern int mod_virt_timer_periodic(struct vtimer_list *timer, u64 expires); 27 27 extern int del_virt_timer(struct vtimer_list *timer); 28 - 29 - extern void init_cpu_vtimer(void); 30 28 extern void vtime_init(void); 31 29 32 30 #endif /* _ASM_S390_TIMER_H */
+62 -15
arch/s390/include/uapi/asm/pkey.h
··· 35 35 #define PKEY_KEYTYPE_AES_128 1 36 36 #define PKEY_KEYTYPE_AES_192 2 37 37 #define PKEY_KEYTYPE_AES_256 3 38 + #define PKEY_KEYTYPE_ECC 4 38 39 39 40 /* the newer ioctls use a pkey_key_type enum for type information */ 40 41 enum pkey_key_type { 41 42 PKEY_TYPE_CCA_DATA = (__u32) 1, 42 43 PKEY_TYPE_CCA_CIPHER = (__u32) 2, 43 44 PKEY_TYPE_EP11 = (__u32) 3, 45 + PKEY_TYPE_CCA_ECC = (__u32) 0x1f, 46 + PKEY_TYPE_EP11_AES = (__u32) 6, 47 + PKEY_TYPE_EP11_ECC = (__u32) 7, 44 48 }; 45 49 46 50 /* the newer ioctls use a pkey_key_size enum for key size information */ ··· 91 87 struct pkey_clrkey { 92 88 __u8 clrkey[MAXCLRKEYSIZE]; /* 16, 24, or 32 byte clear key value */ 93 89 }; 90 + 91 + /* 92 + * EP11 key blobs of type PKEY_TYPE_EP11_AES and PKEY_TYPE_EP11_ECC 93 + * are ep11 blobs prepended by this header: 94 + */ 95 + struct ep11kblob_header { 96 + __u8 type; /* always 0x00 */ 97 + __u8 hver; /* header version, currently needs to be 0x00 */ 98 + __u16 len; /* total length in bytes (including this header) */ 99 + __u8 version; /* PKEY_TYPE_EP11_AES or PKEY_TYPE_EP11_ECC */ 100 + __u8 res0; /* unused */ 101 + __u16 bitlen; /* clear key bit len, 0 for unknown */ 102 + __u8 res1[8]; /* unused */ 103 + } __packed; 94 104 95 105 /* 96 106 * Generate CCA AES secure key. ··· 322 304 #define PKEY_VERIFYKEY2 _IOWR(PKEY_IOCTL_MAGIC, 0x17, struct pkey_verifykey2) 323 305 324 306 /* 325 - * Transform a key blob (of any type) into a protected key, version 2. 307 + * Transform a key blob into a protected key, version 2. 326 308 * There needs to be a list of apqns given with at least one entry in there. 327 309 * All apqns in the list need to be exact apqns, 0xFFFF as ANY card or domain 328 310 * is not supported. The implementation walks through the list of apqns and ··· 331 313 * list is tried until success (return 0) or the end of the list is reached 332 314 * (return -1 with errno ENODEV). You may use the PKEY_APQNS4K ioctl to 333 315 * generate a list of apqns based on the key. 316 + * Deriving ECC protected keys from ECC secure keys is not supported with 317 + * this ioctl, use PKEY_KBLOB2PROTK3 for this purpose. 334 318 */ 335 319 struct pkey_kblob2pkey2 { 336 320 __u8 __user *key; /* in: pointer to key blob */ ··· 346 326 /* 347 327 * Build a list of APQNs based on a key blob given. 348 328 * Is able to find out which type of secure key is given (CCA AES secure 349 - * key, CCA AES cipher key or EP11 AES key) and tries to find all matching 350 - * crypto cards based on the MKVP and maybe other criterias (like CCA AES 351 - * cipher keys need a CEX5C or higher, EP11 keys with BLOB_PKEY_EXTRACTABLE 352 - * need a CEX7 and EP11 api version 4). The list of APQNs is further filtered 353 - * by the key's mkvp which needs to match to either the current mkvp (CCA and 354 - * EP11) or the alternate mkvp (old mkvp, CCA adapters only) of the apqns. The 355 - * flags argument may be used to limit the matching apqns. If the 356 - * PKEY_FLAGS_MATCH_CUR_MKVP is given, only the current mkvp of each apqn is 357 - * compared. Likewise with the PKEY_FLAGS_MATCH_ALT_MKVP. If both are given, it 358 - * is assumed to return apqns where either the current or the alternate mkvp 359 - * matches. At least one of the matching flags needs to be given. 329 + * key, CCA AES cipher key, CCA ECC private key, EP11 AES key, EP11 ECC private 330 + * key) and tries to find all matching crypto cards based on the MKVP and maybe 331 + * other criterias (like CCA AES cipher keys need a CEX5C or higher, EP11 keys 332 + * with BLOB_PKEY_EXTRACTABLE need a CEX7 and EP11 api version 4). The list of 333 + * APQNs is further filtered by the key's mkvp which needs to match to either 334 + * the current mkvp (CCA and EP11) or the alternate mkvp (old mkvp, CCA adapters 335 + * only) of the apqns. The flags argument may be used to limit the matching 336 + * apqns. If the PKEY_FLAGS_MATCH_CUR_MKVP is given, only the current mkvp of 337 + * each apqn is compared. Likewise with the PKEY_FLAGS_MATCH_ALT_MKVP. If both 338 + * are given, it is assumed to return apqns where either the current or the 339 + * alternate mkvp matches. At least one of the matching flags needs to be given. 360 340 * The flags argument for EP11 keys has no further action and is currently 361 341 * ignored (but needs to be given as PKEY_FLAGS_MATCH_CUR_MKVP) as there is only 362 342 * the wkvp from the key to match against the apqn's wkvp. ··· 385 365 * restrict the list by given master key verification patterns. 386 366 * For different key types there may be different ways to match the 387 367 * master key verification patterns. For CCA keys (CCA data key and CCA 388 - * cipher key) the first 8 bytes of cur_mkvp refer to the current mkvp value 389 - * of the apqn and the first 8 bytes of the alt_mkvp refer to the old mkvp. 390 - * The flags argument controls if the apqns current and/or alternate mkvp 368 + * cipher key) the first 8 bytes of cur_mkvp refer to the current AES mkvp value 369 + * of the apqn and the first 8 bytes of the alt_mkvp refer to the old AES mkvp. 370 + * For CCA ECC keys it is similar but the match is against the APKA current/old 371 + * mkvp. The flags argument controls if the apqns current and/or alternate mkvp 391 372 * should match. If the PKEY_FLAGS_MATCH_CUR_MKVP is given, only the current 392 373 * mkvp of each apqn is compared. Likewise with the PKEY_FLAGS_MATCH_ALT_MKVP. 393 374 * If both are given, it is assumed to return apqns where either the ··· 417 396 /* out: # apqns stored into the list */ 418 397 }; 419 398 #define PKEY_APQNS4KT _IOWR(PKEY_IOCTL_MAGIC, 0x1C, struct pkey_apqns4keytype) 399 + 400 + /* 401 + * Transform a key blob into a protected key, version 3. 402 + * The difference to version 2 of this ioctl is that the protected key 403 + * buffer is now explicitly and not within a struct pkey_protkey any more. 404 + * So this ioctl is also able to handle EP11 and CCA ECC secure keys and 405 + * provide ECC protected keys. 406 + * There needs to be a list of apqns given with at least one entry in there. 407 + * All apqns in the list need to be exact apqns, 0xFFFF as ANY card or domain 408 + * is not supported. The implementation walks through the list of apqns and 409 + * tries to send the request to each apqn without any further checking (like 410 + * card type or online state). If the apqn fails, simple the next one in the 411 + * list is tried until success (return 0) or the end of the list is reached 412 + * (return -1 with errno ENODEV). You may use the PKEY_APQNS4K ioctl to 413 + * generate a list of apqns based on the key. 414 + */ 415 + struct pkey_kblob2pkey3 { 416 + __u8 __user *key; /* in: pointer to key blob */ 417 + __u32 keylen; /* in: key blob size */ 418 + struct pkey_apqn __user *apqns; /* in: ptr to list of apqn targets */ 419 + __u32 apqn_entries; /* in: # of apqn target list entries */ 420 + __u32 pkeytype; /* out: prot key type (enum pkey_key_type) */ 421 + __u32 pkeylen; /* in/out: size of pkey buffer/actual len of pkey */ 422 + __u8 __user *pkey; /* in: pkey blob buffer space ptr */ 423 + }; 424 + #define PKEY_KBLOB2PROTK3 _IOWR(PKEY_IOCTL_MAGIC, 0x1D, struct pkey_kblob2pkey3) 420 425 421 426 #endif /* _UAPI_PKEY_H */
+1 -1
arch/s390/include/uapi/asm/sie.h
··· 29 29 { 0x13, "SIGP conditional emergency signal" }, \ 30 30 { 0x15, "SIGP sense running" }, \ 31 31 { 0x16, "SIGP set multithreading"}, \ 32 - { 0x17, "SIGP store additional status ait address"} 32 + { 0x17, "SIGP store additional status at address"} 33 33 34 34 #define icpt_prog_codes \ 35 35 { 0x0001, "Prog Operation" }, \
+1
arch/s390/kernel/Makefile
··· 57 57 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 58 58 obj-$(CONFIG_STACKTRACE) += stacktrace.o 59 59 obj-$(CONFIG_KPROBES) += kprobes.o 60 + obj-$(CONFIG_KPROBES) += kprobes_insn_page.o 60 61 obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o 61 62 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o 62 63 obj-$(CONFIG_UPROBES) += uprobes.o
-20
arch/s390/kernel/asm-offsets.c
··· 59 59 OFFSET(__SF_SIE_REASON, stack_frame, empty1[2]); 60 60 OFFSET(__SF_SIE_FLAGS, stack_frame, empty1[3]); 61 61 BLANK(); 62 - /* timeval/timezone offsets for use by vdso */ 63 - OFFSET(__VDSO_UPD_COUNT, vdso_data, tb_update_count); 64 - OFFSET(__VDSO_XTIME_STAMP, vdso_data, xtime_tod_stamp); 65 - OFFSET(__VDSO_XTIME_SEC, vdso_data, xtime_clock_sec); 66 - OFFSET(__VDSO_XTIME_NSEC, vdso_data, xtime_clock_nsec); 67 - OFFSET(__VDSO_XTIME_CRS_SEC, vdso_data, xtime_coarse_sec); 68 - OFFSET(__VDSO_XTIME_CRS_NSEC, vdso_data, xtime_coarse_nsec); 69 - OFFSET(__VDSO_WTOM_SEC, vdso_data, wtom_clock_sec); 70 - OFFSET(__VDSO_WTOM_NSEC, vdso_data, wtom_clock_nsec); 71 - OFFSET(__VDSO_WTOM_CRS_SEC, vdso_data, wtom_coarse_sec); 72 - OFFSET(__VDSO_WTOM_CRS_NSEC, vdso_data, wtom_coarse_nsec); 73 - OFFSET(__VDSO_TIMEZONE, vdso_data, tz_minuteswest); 74 - OFFSET(__VDSO_ECTG_OK, vdso_data, ectg_available); 75 - OFFSET(__VDSO_TK_MULT, vdso_data, tk_mult); 76 - OFFSET(__VDSO_TK_SHIFT, vdso_data, tk_shift); 77 - OFFSET(__VDSO_TS_DIR, vdso_data, ts_dir); 78 - OFFSET(__VDSO_TS_END, vdso_data, ts_end); 79 - OFFSET(__VDSO_CLOCK_REALTIME_RES, vdso_data, hrtimer_res); 80 - OFFSET(__VDSO_ECTG_BASE, vdso_per_cpu_data, ectg_timer_base); 81 - OFFSET(__VDSO_ECTG_USER, vdso_per_cpu_data, ectg_user_time); 82 62 OFFSET(__VDSO_GETCPU_VAL, vdso_per_cpu_data, getcpu_val); 83 63 BLANK(); 84 64 /* constants used by the vdso */
+8 -8
arch/s390/kernel/crash_dump.c
··· 141 141 while (count) { 142 142 from = __pa(src); 143 143 if (!OLDMEM_BASE && from < sclp.hsa_size) { 144 - /* Copy from zfcpdump HSA area */ 144 + /* Copy from zfcp/nvme dump HSA area */ 145 145 len = min(count, sclp.hsa_size - from); 146 146 rc = memcpy_hsa_kernel(dst, from, len); 147 147 if (rc) ··· 184 184 while (count) { 185 185 from = __pa(src); 186 186 if (!OLDMEM_BASE && from < sclp.hsa_size) { 187 - /* Copy from zfcpdump HSA area */ 187 + /* Copy from zfcp/nvme dump HSA area */ 188 188 len = min(count, sclp.hsa_size - from); 189 189 rc = memcpy_hsa_user(dst, from, len); 190 190 if (rc) ··· 258 258 } 259 259 260 260 /* 261 - * Remap "oldmem" for zfcpdump 261 + * Remap "oldmem" for zfcp/nvme dump 262 262 * 263 263 * We only map available memory above HSA size. Memory below HSA size 264 264 * is read on demand using the copy_oldmem_page() function. ··· 283 283 } 284 284 285 285 /* 286 - * Remap "oldmem" for kdump or zfcpdump 286 + * Remap "oldmem" for kdump or zfcp/nvme dump 287 287 */ 288 288 int remap_oldmem_pfn_range(struct vm_area_struct *vma, unsigned long from, 289 289 unsigned long pfn, unsigned long size, pgprot_t prot) ··· 632 632 u32 alloc_size; 633 633 u64 hdr_off; 634 634 635 - /* If we are not in kdump or zfcpdump mode return */ 636 - if (!OLDMEM_BASE && ipl_info.type != IPL_TYPE_FCP_DUMP) 635 + /* If we are not in kdump or zfcp/nvme dump mode return */ 636 + if (!OLDMEM_BASE && !is_ipl_type_dump()) 637 637 return 0; 638 - /* If we cannot get HSA size for zfcpdump return error */ 639 - if (ipl_info.type == IPL_TYPE_FCP_DUMP && !sclp.hsa_size) 638 + /* If we cannot get HSA size for zfcp/nvme dump return error */ 639 + if (is_ipl_type_dump() && !sclp.hsa_size) 640 640 return -ENODEV; 641 641 642 642 /* For kdump, exclude previous crashkernel memory */
+1 -12
arch/s390/kernel/diag.c
··· 104 104 .show = show_diag_stat, 105 105 }; 106 106 107 - static int show_diag_stat_open(struct inode *inode, struct file *file) 108 - { 109 - return seq_open(file, &show_diag_stat_sops); 110 - } 111 - 112 - static const struct file_operations show_diag_stat_fops = { 113 - .open = show_diag_stat_open, 114 - .read = seq_read, 115 - .llseek = seq_lseek, 116 - .release = seq_release, 117 - }; 118 - 107 + DEFINE_SEQ_ATTRIBUTE(show_diag_stat); 119 108 120 109 static int __init show_diag_stat_init(void) 121 110 {
+14 -8
arch/s390/kernel/dis.c
··· 482 482 return (int) (ptr - buffer); 483 483 } 484 484 485 + static int copy_from_regs(struct pt_regs *regs, void *dst, void *src, int len) 486 + { 487 + if (user_mode(regs)) { 488 + if (copy_from_user(dst, (char __user *)src, len)) 489 + return -EFAULT; 490 + } else { 491 + if (copy_from_kernel_nofault(dst, src, len)) 492 + return -EFAULT; 493 + } 494 + return 0; 495 + } 496 + 485 497 void show_code(struct pt_regs *regs) 486 498 { 487 499 char *mode = user_mode(regs) ? "User" : "Krnl"; 488 500 unsigned char code[64]; 489 501 char buffer[128], *ptr; 490 - mm_segment_t old_fs; 491 502 unsigned long addr; 492 503 int start, end, opsize, hops, i; 493 504 494 505 /* Get a snapshot of the 64 bytes surrounding the fault address. */ 495 - old_fs = get_fs(); 496 - set_fs(user_mode(regs) ? USER_DS : KERNEL_DS); 497 506 for (start = 32; start && regs->psw.addr >= 34 - start; start -= 2) { 498 507 addr = regs->psw.addr - 34 + start; 499 - if (__copy_from_user(code + start - 2, 500 - (char __user *) addr, 2)) 508 + if (copy_from_regs(regs, code + start - 2, (void *)addr, 2)) 501 509 break; 502 510 } 503 511 for (end = 32; end < 64; end += 2) { 504 512 addr = regs->psw.addr + end - 32; 505 - if (__copy_from_user(code + end, 506 - (char __user *) addr, 2)) 513 + if (copy_from_regs(regs, code + end, (void *)addr, 2)) 507 514 break; 508 515 } 509 - set_fs(old_fs); 510 516 /* Code snapshot useable ? */ 511 517 if ((regs->psw.addr & 1) || start >= end) { 512 518 printk("%s Code: Bad PSW.\n", mode);
-13
arch/s390/kernel/early.c
··· 274 274 } 275 275 early_param("novx", disable_vector_extension); 276 276 277 - static int __init cad_setup(char *str) 278 - { 279 - bool enabled; 280 - int rc; 281 - 282 - rc = kstrtobool(str, &enabled); 283 - if (!rc && enabled && test_facility(128)) 284 - /* Enable problem state CAD. */ 285 - __ctl_set_bit(2, 3); 286 - return rc; 287 - } 288 - early_param("cad", cad_setup); 289 - 290 277 char __bootdata(early_command_line)[COMMAND_LINE_SIZE]; 291 278 static void __init setup_boot_command_line(void) 292 279 {
+1 -1
arch/s390/kernel/early_printk.c
··· 10 10 11 11 static void sclp_early_write(struct console *con, const char *s, unsigned int len) 12 12 { 13 - __sclp_early_printk(s, len, 0); 13 + __sclp_early_printk(s, len); 14 14 } 15 15 16 16 static struct console sclp_early_console = {
-6
arch/s390/kernel/entry.S
··· 435 435 jz .Lsysc_skip_fpu 436 436 brasl %r14,load_fpu_regs 437 437 .Lsysc_skip_fpu: 438 - lg %r14,__LC_VDSO_PER_CPU 439 438 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11) 440 439 stpt __LC_EXIT_TIMER 441 - mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER 442 440 lmg %r0,%r15,__PT_R0(%r11) 443 441 b __LC_RETURN_LPSWE 444 442 ··· 795 797 TRACE_IRQS_ON 796 798 0: 797 799 #endif 798 - lg %r14,__LC_VDSO_PER_CPU 799 800 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11) 800 801 tm __PT_PSW+1(%r11),0x01 # returning to user ? 801 802 jno .Lio_exit_kernel 802 803 BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP 803 804 stpt __LC_EXIT_TIMER 804 - mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER 805 805 .Lio_exit_kernel: 806 806 lmg %r0,%r15,__PT_R0(%r11) 807 807 b __LC_RETURN_LPSWE ··· 1209 1213 brasl %r14,s390_handle_mcck 1210 1214 TRACE_IRQS_ON 1211 1215 .Lmcck_return: 1212 - lg %r14,__LC_VDSO_PER_CPU 1213 1216 lmg %r0,%r10,__PT_R0(%r11) 1214 1217 mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW 1215 1218 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ? 1216 1219 jno 0f 1217 1220 BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP 1218 1221 stpt __LC_EXIT_TIMER 1219 - mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER 1220 1222 0: lmg %r11,%r15,__PT_R11(%r11) 1221 1223 b __LC_RETURN_MCCK_LPSWE 1222 1224
+2 -4
arch/s390/kernel/entry.h
··· 9 9 #include <asm/idle.h> 10 10 11 11 extern void *restart_stack; 12 - extern unsigned long suspend_zero_pages; 13 12 14 13 void system_call(void); 15 14 void pgm_check_handler(void); ··· 16 17 void io_int_handler(void); 17 18 void mcck_int_handler(void); 18 19 void restart_int_handler(void); 19 - void restart_call_handler(void); 20 20 21 21 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs); 22 22 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs); ··· 60 62 void __init init_IRQ(void); 61 63 void do_IRQ(struct pt_regs *regs, int irq); 62 64 void do_restart(void); 63 - void __init startup_init_nobss(void); 64 65 void __init startup_init(void); 65 66 void die(struct pt_regs *regs, const char *str); 66 67 int setup_profiling_timer(unsigned int multiplier); 67 68 void __init time_init(void); 68 - void s390_early_resume(void); 69 69 unsigned long prepare_ftrace_return(unsigned long parent, unsigned long sp, unsigned long ip); 70 70 71 71 struct s390_mmap_arg_struct; ··· 87 91 88 92 unsigned long stack_alloc(void); 89 93 void stack_free(unsigned long stack); 94 + 95 + extern char kprobes_insn_page[]; 90 96 91 97 #endif /* _ENTRY_H */
+112 -7
arch/s390/kernel/ipl.c
··· 40 40 #define IPL_FCP_STR "fcp" 41 41 #define IPL_FCP_DUMP_STR "fcp_dump" 42 42 #define IPL_NVME_STR "nvme" 43 + #define IPL_NVME_DUMP_STR "nvme_dump" 43 44 #define IPL_NSS_STR "nss" 44 45 45 46 #define DUMP_CCW_STR "ccw" 46 47 #define DUMP_FCP_STR "fcp" 48 + #define DUMP_NVME_STR "nvme" 47 49 #define DUMP_NONE_STR "none" 48 50 49 51 /* ··· 98 96 return IPL_NSS_STR; 99 97 case IPL_TYPE_NVME: 100 98 return IPL_NVME_STR; 99 + case IPL_TYPE_NVME_DUMP: 100 + return IPL_NVME_DUMP_STR; 101 101 case IPL_TYPE_UNKNOWN: 102 102 default: 103 103 return IPL_UNKNOWN_STR; ··· 110 106 DUMP_TYPE_NONE = 1, 111 107 DUMP_TYPE_CCW = 2, 112 108 DUMP_TYPE_FCP = 4, 109 + DUMP_TYPE_NVME = 8, 113 110 }; 114 111 115 112 static char *dump_type_str(enum dump_type type) ··· 122 117 return DUMP_CCW_STR; 123 118 case DUMP_TYPE_FCP: 124 119 return DUMP_FCP_STR; 120 + case DUMP_TYPE_NVME: 121 + return DUMP_NVME_STR; 125 122 default: 126 123 return NULL; 127 124 } ··· 151 144 static int dump_capabilities = DUMP_TYPE_NONE; 152 145 static enum dump_type dump_type = DUMP_TYPE_NONE; 153 146 static struct ipl_parameter_block *dump_block_fcp; 147 + static struct ipl_parameter_block *dump_block_nvme; 154 148 static struct ipl_parameter_block *dump_block_ccw; 155 149 156 150 static struct sclp_ipl_info sclp_ipl_info; 157 151 152 + static bool reipl_nvme_clear; 158 153 static bool reipl_fcp_clear; 159 154 static bool reipl_ccw_clear; 160 155 ··· 275 266 else 276 267 return IPL_TYPE_FCP; 277 268 case IPL_PBT_NVME: 278 - return IPL_TYPE_NVME; 269 + if (ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP) 270 + return IPL_TYPE_NVME_DUMP; 271 + else 272 + return IPL_TYPE_NVME; 279 273 } 280 274 return IPL_TYPE_UNKNOWN; 281 275 } ··· 336 324 case IPL_TYPE_FCP_DUMP: 337 325 return sprintf(page, "0.0.%04x\n", ipl_block.fcp.devno); 338 326 case IPL_TYPE_NVME: 327 + case IPL_TYPE_NVME_DUMP: 339 328 return sprintf(page, "%08ux\n", ipl_block.nvme.fid); 340 329 default: 341 330 return 0; ··· 544 531 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group); 545 532 break; 546 533 case IPL_TYPE_NVME: 534 + case IPL_TYPE_NVME_DUMP: 547 535 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nvme_attr_group); 548 536 break; 549 537 default: ··· 887 873 .bin_attrs = reipl_nvme_bin_attrs 888 874 }; 889 875 876 + static ssize_t reipl_nvme_clear_show(struct kobject *kobj, 877 + struct kobj_attribute *attr, char *page) 878 + { 879 + return sprintf(page, "%u\n", reipl_nvme_clear); 880 + } 881 + 882 + static ssize_t reipl_nvme_clear_store(struct kobject *kobj, 883 + struct kobj_attribute *attr, 884 + const char *buf, size_t len) 885 + { 886 + if (strtobool(buf, &reipl_nvme_clear) < 0) 887 + return -EINVAL; 888 + return len; 889 + } 890 + 891 + static struct kobj_attribute sys_reipl_nvme_clear_attr = 892 + __ATTR(clear, 0644, reipl_nvme_clear_show, reipl_nvme_clear_store); 893 + 890 894 /* CCW reipl device attributes */ 891 895 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ccw); 892 896 ··· 1131 1099 break; 1132 1100 case IPL_TYPE_NVME: 1133 1101 diag308(DIAG308_SET, reipl_block_nvme); 1134 - diag308(DIAG308_LOAD_CLEAR, NULL); 1102 + if (reipl_nvme_clear) 1103 + diag308(DIAG308_LOAD_CLEAR, NULL); 1104 + else 1105 + diag308(DIAG308_LOAD_NORMAL, NULL); 1135 1106 break; 1136 1107 case IPL_TYPE_NSS: 1137 1108 diag308(DIAG308_SET, reipl_block_nss); ··· 1144 1109 diag308(DIAG308_LOAD_CLEAR, NULL); 1145 1110 break; 1146 1111 case IPL_TYPE_FCP_DUMP: 1112 + case IPL_TYPE_NVME_DUMP: 1147 1113 break; 1148 1114 } 1149 1115 disabled_wait(); ··· 1255 1219 &sys_reipl_fcp_clear_attr.attr); 1256 1220 if (rc) 1257 1221 goto out2; 1258 - } else 1222 + } else { 1259 1223 reipl_fcp_clear = true; 1224 + } 1260 1225 1261 1226 if (ipl_info.type == IPL_TYPE_FCP) { 1262 1227 memcpy(reipl_block_fcp, &ipl_block, sizeof(ipl_block)); ··· 1303 1266 } 1304 1267 1305 1268 rc = sysfs_create_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group); 1306 - if (rc) { 1307 - kset_unregister(reipl_nvme_kset); 1308 - free_page((unsigned long) reipl_block_nvme); 1309 - return rc; 1269 + if (rc) 1270 + goto out1; 1271 + 1272 + if (test_facility(141)) { 1273 + rc = sysfs_create_file(&reipl_nvme_kset->kobj, 1274 + &sys_reipl_nvme_clear_attr.attr); 1275 + if (rc) 1276 + goto out2; 1277 + } else { 1278 + reipl_nvme_clear = true; 1310 1279 } 1311 1280 1312 1281 if (ipl_info.type == IPL_TYPE_NVME) { ··· 1333 1290 } 1334 1291 reipl_capabilities |= IPL_TYPE_NVME; 1335 1292 return 0; 1293 + 1294 + out2: 1295 + sysfs_remove_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group); 1296 + out1: 1297 + kset_unregister(reipl_nvme_kset); 1298 + free_page((unsigned long) reipl_block_nvme); 1299 + return rc; 1336 1300 } 1337 1301 1338 1302 static int __init reipl_type_init(void) ··· 1432 1382 .attrs = dump_fcp_attrs, 1433 1383 }; 1434 1384 1385 + /* NVME dump device attributes */ 1386 + DEFINE_IPL_ATTR_RW(dump_nvme, fid, "0x%08llx\n", "%llx\n", 1387 + dump_block_nvme->nvme.fid); 1388 + DEFINE_IPL_ATTR_RW(dump_nvme, nsid, "0x%08llx\n", "%llx\n", 1389 + dump_block_nvme->nvme.nsid); 1390 + DEFINE_IPL_ATTR_RW(dump_nvme, bootprog, "%lld\n", "%llx\n", 1391 + dump_block_nvme->nvme.bootprog); 1392 + DEFINE_IPL_ATTR_RW(dump_nvme, br_lba, "%lld\n", "%llx\n", 1393 + dump_block_nvme->nvme.br_lba); 1394 + 1395 + static struct attribute *dump_nvme_attrs[] = { 1396 + &sys_dump_nvme_fid_attr.attr, 1397 + &sys_dump_nvme_nsid_attr.attr, 1398 + &sys_dump_nvme_bootprog_attr.attr, 1399 + &sys_dump_nvme_br_lba_attr.attr, 1400 + NULL, 1401 + }; 1402 + 1403 + static struct attribute_group dump_nvme_attr_group = { 1404 + .name = IPL_NVME_STR, 1405 + .attrs = dump_nvme_attrs, 1406 + }; 1407 + 1435 1408 /* CCW dump device attributes */ 1436 1409 DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ccw); 1437 1410 ··· 1496 1423 rc = dump_set_type(DUMP_TYPE_CCW); 1497 1424 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0) 1498 1425 rc = dump_set_type(DUMP_TYPE_FCP); 1426 + else if (strncmp(buf, DUMP_NVME_STR, strlen(DUMP_NVME_STR)) == 0) 1427 + rc = dump_set_type(DUMP_TYPE_NVME); 1499 1428 return (rc != 0) ? rc : len; 1500 1429 } 1501 1430 ··· 1524 1449 break; 1525 1450 case DUMP_TYPE_FCP: 1526 1451 diag308_dump(dump_block_fcp); 1452 + break; 1453 + case DUMP_TYPE_NVME: 1454 + diag308_dump(dump_block_nvme); 1527 1455 break; 1528 1456 default: 1529 1457 break; ··· 1584 1506 return 0; 1585 1507 } 1586 1508 1509 + static int __init dump_nvme_init(void) 1510 + { 1511 + int rc; 1512 + 1513 + if (!sclp_ipl_info.has_dump) 1514 + return 0; /* LDIPL DUMP is not installed */ 1515 + dump_block_nvme = (void *) get_zeroed_page(GFP_KERNEL); 1516 + if (!dump_block_nvme) 1517 + return -ENOMEM; 1518 + rc = sysfs_create_group(&dump_kset->kobj, &dump_nvme_attr_group); 1519 + if (rc) { 1520 + free_page((unsigned long)dump_block_nvme); 1521 + return rc; 1522 + } 1523 + dump_block_nvme->hdr.len = IPL_BP_NVME_LEN; 1524 + dump_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION; 1525 + dump_block_nvme->fcp.len = IPL_BP0_NVME_LEN; 1526 + dump_block_nvme->fcp.pbt = IPL_PBT_NVME; 1527 + dump_block_nvme->fcp.opt = IPL_PB0_NVME_OPT_DUMP; 1528 + dump_capabilities |= DUMP_TYPE_NVME; 1529 + return 0; 1530 + } 1531 + 1587 1532 static int __init dump_init(void) 1588 1533 { 1589 1534 int rc; ··· 1623 1522 if (rc) 1624 1523 return rc; 1625 1524 rc = dump_fcp_init(); 1525 + if (rc) 1526 + return rc; 1527 + rc = dump_nvme_init(); 1626 1528 if (rc) 1627 1529 return rc; 1628 1530 dump_set_type(DUMP_TYPE_NONE); ··· 2060 1956 ipl_info.data.fcp.lun = ipl_block.fcp.lun; 2061 1957 break; 2062 1958 case IPL_TYPE_NVME: 1959 + case IPL_TYPE_NVME_DUMP: 2063 1960 ipl_info.data.nvme.fid = ipl_block.nvme.fid; 2064 1961 ipl_info.data.nvme.nsid = ipl_block.nvme.nsid; 2065 1962 break;
+39 -20
arch/s390/kernel/kprobes.c
··· 7 7 * s390 port, used ppc64 as template. Mike Grundy <grundym@us.ibm.com> 8 8 */ 9 9 10 + #include <linux/moduleloader.h> 10 11 #include <linux/kprobes.h> 11 12 #include <linux/ptrace.h> 12 13 #include <linux/preempt.h> ··· 22 21 #include <asm/set_memory.h> 23 22 #include <asm/sections.h> 24 23 #include <asm/dis.h> 24 + #include "entry.h" 25 25 26 26 DEFINE_PER_CPU(struct kprobe *, current_kprobe); 27 27 DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); ··· 32 30 DEFINE_INSN_CACHE_OPS(s390_insn); 33 31 34 32 static int insn_page_in_use; 35 - static char insn_page[PAGE_SIZE] __aligned(PAGE_SIZE); 33 + 34 + void *alloc_insn_page(void) 35 + { 36 + void *page; 37 + 38 + page = module_alloc(PAGE_SIZE); 39 + if (!page) 40 + return NULL; 41 + __set_memory((unsigned long) page, 1, SET_MEMORY_RO | SET_MEMORY_X); 42 + return page; 43 + } 44 + 45 + void free_insn_page(void *page) 46 + { 47 + module_memfree(page); 48 + } 36 49 37 50 static void *alloc_s390_insn_page(void) 38 51 { 39 52 if (xchg(&insn_page_in_use, 1) == 1) 40 53 return NULL; 41 - set_memory_x((unsigned long) &insn_page, 1); 42 - return &insn_page; 54 + return &kprobes_insn_page; 43 55 } 44 56 45 57 static void free_s390_insn_page(void *page) 46 58 { 47 - set_memory_nx((unsigned long) page, 1); 48 59 xchg(&insn_page_in_use, 0); 49 60 } 50 61 ··· 71 56 72 57 static void copy_instruction(struct kprobe *p) 73 58 { 59 + kprobe_opcode_t insn[MAX_INSN_SIZE]; 74 60 s64 disp, new_disp; 75 61 u64 addr, new_addr; 62 + unsigned int len; 76 63 77 - memcpy(p->ainsn.insn, p->addr, insn_length(*p->addr >> 8)); 78 - p->opcode = p->ainsn.insn[0]; 79 - if (!probe_is_insn_relative_long(p->ainsn.insn)) 80 - return; 81 - /* 82 - * For pc-relative instructions in RIL-b or RIL-c format patch the 83 - * RI2 displacement field. We have already made sure that the insn 84 - * slot for the patched instruction is within the same 2GB area 85 - * as the original instruction (either kernel image or module area). 86 - * Therefore the new displacement will always fit. 87 - */ 88 - disp = *(s32 *)&p->ainsn.insn[1]; 89 - addr = (u64)(unsigned long)p->addr; 90 - new_addr = (u64)(unsigned long)p->ainsn.insn; 91 - new_disp = ((addr + (disp * 2)) - new_addr) / 2; 92 - *(s32 *)&p->ainsn.insn[1] = new_disp; 64 + len = insn_length(*p->addr >> 8); 65 + memcpy(&insn, p->addr, len); 66 + p->opcode = insn[0]; 67 + if (probe_is_insn_relative_long(&insn[0])) { 68 + /* 69 + * For pc-relative instructions in RIL-b or RIL-c format patch 70 + * the RI2 displacement field. We have already made sure that 71 + * the insn slot for the patched instruction is within the same 72 + * 2GB area as the original instruction (either kernel image or 73 + * module area). Therefore the new displacement will always fit. 74 + */ 75 + disp = *(s32 *)&insn[1]; 76 + addr = (u64)(unsigned long)p->addr; 77 + new_addr = (u64)(unsigned long)p->ainsn.insn; 78 + new_disp = ((addr + (disp * 2)) - new_addr) / 2; 79 + *(s32 *)&insn[1] = new_disp; 80 + } 81 + s390_kernel_write(p->ainsn.insn, &insn, len); 93 82 } 94 83 NOKPROBE_SYMBOL(copy_instruction); 95 84
+22
arch/s390/kernel/kprobes_insn_page.S
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #include <linux/linkage.h> 4 + 5 + /* 6 + * insn_page is a special 4k aligned dummy function for kprobes. 7 + * It will contain all kprobed instructions that are out-of-line executed. 8 + * The page must be within the kernel image to guarantee that the 9 + * out-of-line instructions are within 2GB distance of their original 10 + * location. Using a dummy function ensures that the insn_page is within 11 + * the text section of the kernel and mapped read-only/executable from 12 + * the beginning on, thus avoiding to split large mappings if the page 13 + * would be in the data section instead. 14 + */ 15 + .section .kprobes.text, "ax" 16 + .align 4096 17 + ENTRY(kprobes_insn_page) 18 + .rept 2048 19 + .word 0x07fe 20 + .endr 21 + ENDPROC(kprobes_insn_page) 22 + .previous
+35 -27
arch/s390/kernel/setup.c
··· 102 102 103 103 struct exception_table_entry *__bootdata_preserved(__start_dma_ex_table); 104 104 struct exception_table_entry *__bootdata_preserved(__stop_dma_ex_table); 105 - unsigned long __bootdata_preserved(__swsusp_reset_dma); 106 105 unsigned long __bootdata_preserved(__stext_dma); 107 106 unsigned long __bootdata_preserved(__etext_dma); 108 107 unsigned long __bootdata_preserved(__sdma); ··· 118 119 119 120 struct page *vmemmap; 120 121 EXPORT_SYMBOL(vmemmap); 122 + unsigned long vmemmap_size; 121 123 122 124 unsigned long MODULES_VADDR; 123 125 unsigned long MODULES_END; ··· 126 126 /* An array with a pointer to the lowcore of every CPU. */ 127 127 struct lowcore *lowcore_ptr[NR_CPUS]; 128 128 EXPORT_SYMBOL(lowcore_ptr); 129 + 130 + /* 131 + * The Write Back bit position in the physaddr is given by the SLPC PCI. 132 + * Leaving the mask zero always uses write through which is safe 133 + */ 134 + unsigned long mio_wb_bit_mask __ro_after_init; 129 135 130 136 /* 131 137 * This is set up by the setup-routine at boot-time ··· 251 245 #ifdef CONFIG_CRASH_DUMP 252 246 static void __init setup_zfcpdump(void) 253 247 { 254 - if (ipl_info.type != IPL_TYPE_FCP_DUMP) 248 + if (!is_ipl_type_dump()) 255 249 return; 256 250 if (OLDMEM_BASE) 257 251 return; ··· 306 300 void (*pm_power_off)(void) = machine_power_off; 307 301 EXPORT_SYMBOL_GPL(pm_power_off); 308 302 309 - void *restart_stack __section(.data); 303 + void *restart_stack; 310 304 311 305 unsigned long stack_alloc(void) 312 306 { ··· 372 366 373 367 static void __init setup_lowcore_dat_off(void) 374 368 { 369 + unsigned long int_psw_mask = PSW_KERNEL_BITS; 375 370 struct lowcore *lc; 371 + 372 + if (IS_ENABLED(CONFIG_KASAN)) 373 + int_psw_mask |= PSW_MASK_DAT; 376 374 377 375 /* 378 376 * Setup lowcore for boot cpu ··· 389 379 390 380 lc->restart_psw.mask = PSW_KERNEL_BITS; 391 381 lc->restart_psw.addr = (unsigned long) restart_int_handler; 392 - lc->external_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_MCHECK; 382 + lc->external_new_psw.mask = int_psw_mask | PSW_MASK_MCHECK; 393 383 lc->external_new_psw.addr = (unsigned long) ext_int_handler; 394 - lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_MCHECK; 384 + lc->svc_new_psw.mask = int_psw_mask | PSW_MASK_MCHECK; 395 385 lc->svc_new_psw.addr = (unsigned long) system_call; 396 - lc->program_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_MCHECK; 386 + lc->program_new_psw.mask = int_psw_mask | PSW_MASK_MCHECK; 397 387 lc->program_new_psw.addr = (unsigned long) pgm_check_handler; 398 388 lc->mcck_new_psw.mask = PSW_KERNEL_BITS; 399 389 lc->mcck_new_psw.addr = (unsigned long) mcck_int_handler; 400 - lc->io_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_MCHECK; 390 + lc->io_new_psw.mask = int_psw_mask | PSW_MASK_MCHECK; 401 391 lc->io_new_psw.addr = (unsigned long) io_int_handler; 402 392 lc->clock_comparator = clock_comparator_max; 403 393 lc->nodat_stack = ((unsigned long) &init_thread_union) ··· 412 402 memcpy(lc->alt_stfle_fac_list, S390_lowcore.alt_stfle_fac_list, 413 403 sizeof(lc->alt_stfle_fac_list)); 414 404 nmi_alloc_boot_cpu(lc); 415 - vdso_alloc_boot_cpu(lc); 416 405 lc->sync_enter_timer = S390_lowcore.sync_enter_timer; 417 406 lc->async_enter_timer = S390_lowcore.async_enter_timer; 418 407 lc->exit_timer = S390_lowcore.exit_timer; ··· 561 552 unsigned long vmax, tmp; 562 553 563 554 /* Choose kernel address space layout: 3 or 4 levels. */ 564 - if (IS_ENABLED(CONFIG_KASAN)) { 565 - vmax = IS_ENABLED(CONFIG_KASAN_S390_4_LEVEL_PAGING) 566 - ? _REGION1_SIZE 567 - : _REGION2_SIZE; 568 - } else { 569 - tmp = (memory_end ?: max_physmem_end) / PAGE_SIZE; 570 - tmp = tmp * (sizeof(struct page) + PAGE_SIZE); 571 - if (tmp + vmalloc_size + MODULES_LEN <= _REGION2_SIZE) 572 - vmax = _REGION2_SIZE; /* 3-level kernel page table */ 573 - else 574 - vmax = _REGION1_SIZE; /* 4-level kernel page table */ 575 - } 576 - 555 + tmp = (memory_end ?: max_physmem_end) / PAGE_SIZE; 556 + tmp = tmp * (sizeof(struct page) + PAGE_SIZE); 557 + if (tmp + vmalloc_size + MODULES_LEN <= _REGION2_SIZE) 558 + vmax = _REGION2_SIZE; /* 3-level kernel page table */ 559 + else 560 + vmax = _REGION1_SIZE; /* 4-level kernel page table */ 577 561 if (is_prot_virt_host()) 578 562 adjust_to_uv_max(&vmax); 579 - 563 + #ifdef CONFIG_KASAN 564 + vmax = kasan_vmax; 565 + #endif 580 566 /* module area is at the end of the kernel address space. */ 581 567 MODULES_END = vmax; 582 568 MODULES_VADDR = MODULES_END - MODULES_LEN; ··· 590 586 /* Take care that memory_end is set and <= vmemmap */ 591 587 memory_end = min(memory_end ?: max_physmem_end, (unsigned long)vmemmap); 592 588 #ifdef CONFIG_KASAN 593 - /* fit in kasan shadow memory region between 1:1 and vmemmap */ 594 589 memory_end = min(memory_end, KASAN_SHADOW_START); 595 - vmemmap = max(vmemmap, (struct page *)KASAN_SHADOW_END); 590 + #endif 591 + vmemmap_size = SECTION_ALIGN_UP(memory_end / PAGE_SIZE) * sizeof(struct page); 592 + #ifdef CONFIG_KASAN 593 + /* move vmemmap above kasan shadow only if stands in a way */ 594 + if (KASAN_SHADOW_END > (unsigned long)vmemmap && 595 + (unsigned long)vmemmap + vmemmap_size > KASAN_SHADOW_START) 596 + vmemmap = max(vmemmap, (struct page *)KASAN_SHADOW_END); 596 597 #endif 597 598 max_pfn = max_low_pfn = PFN_DOWN(memory_end); 598 599 memblock_remove(memory_end, ULONG_MAX); ··· 1142 1133 free_mem_detect_info(); 1143 1134 remove_oldmem(); 1144 1135 1145 - if (is_prot_virt_host()) 1146 - setup_uv(); 1136 + setup_uv(); 1147 1137 setup_memory_end(); 1148 1138 setup_memory(); 1149 1139 dma_contiguous_reserve(memory_end); ··· 1186 1178 if (IS_ENABLED(CONFIG_EXPOLINE)) 1187 1179 nospec_init_branches(); 1188 1180 1189 - /* Setup zfcpdump support */ 1181 + /* Setup zfcp/nvme dump support */ 1190 1182 setup_zfcpdump(); 1191 1183 1192 1184 /* Add system specific data to the random pool */
+6 -6
arch/s390/kernel/smp.c
··· 606 606 /* 607 607 * Collect CPU state of the previous, crashed system. 608 608 * There are four cases: 609 - * 1) standard zfcp dump 610 - * condition: OLDMEM_BASE == NULL && ipl_info.type == IPL_TYPE_FCP_DUMP 609 + * 1) standard zfcp/nvme dump 610 + * condition: OLDMEM_BASE == NULL && is_ipl_type_dump() == true 611 611 * The state for all CPUs except the boot CPU needs to be collected 612 612 * with sigp stop-and-store-status. The boot CPU state is located in 613 613 * the absolute lowcore of the memory stored in the HSA. The zcore code 614 614 * will copy the boot CPU state from the HSA. 615 - * 2) stand-alone kdump for SCSI (zfcp dump with swapped memory) 616 - * condition: OLDMEM_BASE != NULL && ipl_info.type == IPL_TYPE_FCP_DUMP 615 + * 2) stand-alone kdump for SCSI/NVMe (zfcp/nvme dump with swapped memory) 616 + * condition: OLDMEM_BASE != NULL && is_ipl_type_dump() == true 617 617 * The state for all CPUs except the boot CPU needs to be collected 618 618 * with sigp stop-and-store-status. The firmware or the boot-loader 619 619 * stored the registers of the boot CPU in the absolute lowcore in the ··· 660 660 unsigned long page; 661 661 bool is_boot_cpu; 662 662 663 - if (!(OLDMEM_BASE || ipl_info.type == IPL_TYPE_FCP_DUMP)) 663 + if (!(OLDMEM_BASE || is_ipl_type_dump())) 664 664 /* No previous system present, normal boot. */ 665 665 return; 666 666 /* Allocate a page as dumping area for the store status sigps */ ··· 686 686 /* Get the vector registers */ 687 687 smp_save_cpu_vxrs(sa, addr, is_boot_cpu, page); 688 688 /* 689 - * For a zfcp dump OLDMEM_BASE == NULL and the registers 689 + * For a zfcp/nvme dump OLDMEM_BASE == NULL and the registers 690 690 * of the boot CPU are stored in the HSA. To retrieve 691 691 * these registers an SCLP request is required which is 692 692 * done by drivers/s390/char/zcore.c:init_cpu_info()
+214 -104
arch/s390/kernel/time.c
··· 41 41 #include <linux/gfp.h> 42 42 #include <linux/kprobes.h> 43 43 #include <linux/uaccess.h> 44 + #include <vdso/vsyscall.h> 45 + #include <vdso/clocksource.h> 46 + #include <vdso/helpers.h> 44 47 #include <asm/facility.h> 45 48 #include <asm/delay.h> 46 49 #include <asm/div64.h> ··· 87 84 88 85 /* Initialize TOD steering parameters */ 89 86 tod_steering_end = *(unsigned long long *) &tod_clock_base[1]; 90 - vdso_data->ts_end = tod_steering_end; 87 + vdso_data->arch_data.tod_steering_end = tod_steering_end; 91 88 92 89 if (!test_facility(28)) 93 90 return; ··· 260 257 .mult = 1000, 261 258 .shift = 12, 262 259 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 260 + .vdso_clock_mode = VDSO_CLOCKMODE_TOD, 263 261 }; 264 262 265 263 struct clocksource * __init clocksource_default_clock(void) 266 264 { 267 265 return &clocksource_tod; 268 - } 269 - 270 - void update_vsyscall(struct timekeeper *tk) 271 - { 272 - u64 nsecps; 273 - 274 - if (tk->tkr_mono.clock != &clocksource_tod) 275 - return; 276 - 277 - /* Make userspace gettimeofday spin until we're done. */ 278 - ++vdso_data->tb_update_count; 279 - smp_wmb(); 280 - vdso_data->xtime_tod_stamp = tk->tkr_mono.cycle_last; 281 - vdso_data->xtime_clock_sec = tk->xtime_sec; 282 - vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec; 283 - vdso_data->wtom_clock_sec = 284 - tk->xtime_sec + tk->wall_to_monotonic.tv_sec; 285 - vdso_data->wtom_clock_nsec = tk->tkr_mono.xtime_nsec + 286 - + ((u64) tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift); 287 - nsecps = (u64) NSEC_PER_SEC << tk->tkr_mono.shift; 288 - while (vdso_data->wtom_clock_nsec >= nsecps) { 289 - vdso_data->wtom_clock_nsec -= nsecps; 290 - vdso_data->wtom_clock_sec++; 291 - } 292 - 293 - vdso_data->xtime_coarse_sec = tk->xtime_sec; 294 - vdso_data->xtime_coarse_nsec = 295 - (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift); 296 - vdso_data->wtom_coarse_sec = 297 - vdso_data->xtime_coarse_sec + tk->wall_to_monotonic.tv_sec; 298 - vdso_data->wtom_coarse_nsec = 299 - vdso_data->xtime_coarse_nsec + tk->wall_to_monotonic.tv_nsec; 300 - while (vdso_data->wtom_coarse_nsec >= NSEC_PER_SEC) { 301 - vdso_data->wtom_coarse_nsec -= NSEC_PER_SEC; 302 - vdso_data->wtom_coarse_sec++; 303 - } 304 - 305 - vdso_data->tk_mult = tk->tkr_mono.mult; 306 - vdso_data->tk_shift = tk->tkr_mono.shift; 307 - vdso_data->hrtimer_res = hrtimer_resolution; 308 - smp_wmb(); 309 - ++vdso_data->tb_update_count; 310 - } 311 - 312 - extern struct timezone sys_tz; 313 - 314 - void update_vsyscall_tz(void) 315 - { 316 - vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; 317 - vdso_data->tz_dsttime = sys_tz.tz_dsttime; 318 266 } 319 267 320 268 /* ··· 296 342 } 297 343 298 344 static DEFINE_PER_CPU(atomic_t, clock_sync_word); 299 - static DEFINE_MUTEX(clock_sync_mutex); 345 + static DEFINE_MUTEX(stp_mutex); 300 346 static unsigned long clock_sync_flags; 301 347 302 - #define CLOCK_SYNC_HAS_STP 0 303 - #define CLOCK_SYNC_STP 1 348 + #define CLOCK_SYNC_HAS_STP 0 349 + #define CLOCK_SYNC_STP 1 350 + #define CLOCK_SYNC_STPINFO_VALID 2 304 351 305 352 /* 306 353 * The get_clock function for the physical clock. It will get the current ··· 386 431 /* Epoch overflow */ 387 432 tod_clock_base[0]++; 388 433 /* Adjust TOD steering parameters. */ 389 - vdso_data->tb_update_count++; 390 434 now = get_tod_clock(); 391 435 adj = tod_steering_end - now; 392 436 if (unlikely((s64) adj >= 0)) ··· 397 443 panic("TOD clock sync offset %lli is too large to drift\n", 398 444 tod_steering_delta); 399 445 tod_steering_end = now + (abs(tod_steering_delta) << 15); 400 - vdso_data->ts_dir = (tod_steering_delta < 0) ? 0 : 1; 401 - vdso_data->ts_end = tod_steering_end; 402 - vdso_data->tb_update_count++; 446 + vdso_data->arch_data.tod_steering_end = tod_steering_end; 447 + 403 448 /* Update LPAR offset. */ 404 449 if (ptff_query(PTFF_QTO) && ptff(&qto, sizeof(qto), PTFF_QTO) == 0) 405 450 lpar_offset = qto.tod_epoch_difference; ··· 445 492 static void *stp_page; 446 493 447 494 static void stp_work_fn(struct work_struct *work); 448 - static DEFINE_MUTEX(stp_work_mutex); 449 495 static DECLARE_WORK(stp_work, stp_work_fn); 450 496 static struct timer_list stp_timer; 451 497 ··· 535 583 queue_work(time_sync_wq, &stp_work); 536 584 } 537 585 586 + static int __store_stpinfo(void) 587 + { 588 + int rc = chsc_sstpi(stp_page, &stp_info, sizeof(struct stp_sstpi)); 589 + 590 + if (rc) 591 + clear_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags); 592 + else 593 + set_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags); 594 + return rc; 595 + } 596 + 597 + static int stpinfo_valid(void) 598 + { 599 + return stp_online && test_bit(CLOCK_SYNC_STPINFO_VALID, &clock_sync_flags); 600 + } 601 + 538 602 static int stp_sync_clock(void *data) 539 603 { 540 604 struct clock_sync_data *sync = data; 541 - unsigned long long clock_delta; 605 + unsigned long long clock_delta, flags; 542 606 static int first; 543 607 int rc; 544 608 ··· 567 599 if (stp_info.todoff[0] || stp_info.todoff[1] || 568 600 stp_info.todoff[2] || stp_info.todoff[3] || 569 601 stp_info.tmd != 2) { 602 + flags = vdso_update_begin(); 570 603 rc = chsc_sstpc(stp_page, STP_OP_SYNC, 0, 571 604 &clock_delta); 572 605 if (rc == 0) { 573 606 sync->clock_delta = clock_delta; 574 607 clock_sync_global(clock_delta); 575 - rc = chsc_sstpi(stp_page, &stp_info, 576 - sizeof(struct stp_sstpi)); 608 + rc = __store_stpinfo(); 577 609 if (rc == 0 && stp_info.tmd != 2) 578 610 rc = -EAGAIN; 579 611 } 612 + vdso_update_end(flags); 580 613 } 581 614 sync->in_sync = rc ? -EAGAIN : 1; 582 615 xchg(&first, 0); ··· 597 628 return 0; 598 629 } 599 630 631 + static int stp_clear_leap(void) 632 + { 633 + struct __kernel_timex txc; 634 + int ret; 635 + 636 + memset(&txc, 0, sizeof(txc)); 637 + 638 + ret = do_adjtimex(&txc); 639 + if (ret < 0) 640 + return ret; 641 + 642 + txc.modes = ADJ_STATUS; 643 + txc.status &= ~(STA_INS|STA_DEL); 644 + return do_adjtimex(&txc); 645 + } 646 + 647 + static void stp_check_leap(void) 648 + { 649 + struct stp_stzi stzi; 650 + struct stp_lsoib *lsoib = &stzi.lsoib; 651 + struct __kernel_timex txc; 652 + int64_t timediff; 653 + int leapdiff, ret; 654 + 655 + if (!stp_info.lu || !check_sync_clock()) { 656 + /* 657 + * Either a scheduled leap second was removed by the operator, 658 + * or STP is out of sync. In both cases, clear the leap second 659 + * kernel flags. 660 + */ 661 + if (stp_clear_leap() < 0) 662 + pr_err("failed to clear leap second flags\n"); 663 + return; 664 + } 665 + 666 + if (chsc_stzi(stp_page, &stzi, sizeof(stzi))) { 667 + pr_err("stzi failed\n"); 668 + return; 669 + } 670 + 671 + timediff = tod_to_ns(lsoib->nlsout - get_tod_clock()) / NSEC_PER_SEC; 672 + leapdiff = lsoib->nlso - lsoib->also; 673 + 674 + if (leapdiff != 1 && leapdiff != -1) { 675 + pr_err("Cannot schedule %d leap seconds\n", leapdiff); 676 + return; 677 + } 678 + 679 + if (timediff < 0) { 680 + if (stp_clear_leap() < 0) 681 + pr_err("failed to clear leap second flags\n"); 682 + } else if (timediff < 7200) { 683 + memset(&txc, 0, sizeof(txc)); 684 + ret = do_adjtimex(&txc); 685 + if (ret < 0) 686 + return; 687 + 688 + txc.modes = ADJ_STATUS; 689 + if (leapdiff > 0) 690 + txc.status |= STA_INS; 691 + else 692 + txc.status |= STA_DEL; 693 + ret = do_adjtimex(&txc); 694 + if (ret < 0) 695 + pr_err("failed to set leap second flags\n"); 696 + /* arm Timer to clear leap second flags */ 697 + mod_timer(&stp_timer, jiffies + msecs_to_jiffies(14400 * MSEC_PER_SEC)); 698 + } else { 699 + /* The day the leap second is scheduled for hasn't been reached. Retry 700 + * in one hour. 701 + */ 702 + mod_timer(&stp_timer, jiffies + msecs_to_jiffies(3600 * MSEC_PER_SEC)); 703 + } 704 + } 705 + 600 706 /* 601 707 * STP work. Check for the STP state and take over the clock 602 708 * synchronization if the STP clock source is usable. ··· 682 638 int rc; 683 639 684 640 /* prevent multiple execution. */ 685 - mutex_lock(&stp_work_mutex); 641 + mutex_lock(&stp_mutex); 686 642 687 643 if (!stp_online) { 688 644 chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000, NULL); ··· 690 646 goto out_unlock; 691 647 } 692 648 693 - rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0xb0e0, NULL); 649 + rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0xf0e0, NULL); 694 650 if (rc) 695 651 goto out_unlock; 696 652 697 - rc = chsc_sstpi(stp_page, &stp_info, sizeof(struct stp_sstpi)); 653 + rc = __store_stpinfo(); 698 654 if (rc || stp_info.c == 0) 699 655 goto out_unlock; 700 656 701 657 /* Skip synchronization if the clock is already in sync. */ 702 - if (check_sync_clock()) 703 - goto out_unlock; 704 - 705 - memset(&stp_sync, 0, sizeof(stp_sync)); 706 - cpus_read_lock(); 707 - atomic_set(&stp_sync.cpus, num_online_cpus() - 1); 708 - stop_machine_cpuslocked(stp_sync_clock, &stp_sync, cpu_online_mask); 709 - cpus_read_unlock(); 658 + if (!check_sync_clock()) { 659 + memset(&stp_sync, 0, sizeof(stp_sync)); 660 + cpus_read_lock(); 661 + atomic_set(&stp_sync.cpus, num_online_cpus() - 1); 662 + stop_machine_cpuslocked(stp_sync_clock, &stp_sync, cpu_online_mask); 663 + cpus_read_unlock(); 664 + } 710 665 711 666 if (!check_sync_clock()) 712 667 /* ··· 713 670 * Retry after a second. 714 671 */ 715 672 mod_timer(&stp_timer, jiffies + msecs_to_jiffies(MSEC_PER_SEC)); 673 + else if (stp_info.lu) 674 + stp_check_leap(); 716 675 717 676 out_unlock: 718 - mutex_unlock(&stp_work_mutex); 677 + mutex_unlock(&stp_mutex); 719 678 } 720 679 721 680 /* ··· 732 687 struct device_attribute *attr, 733 688 char *buf) 734 689 { 735 - if (!stp_online) 736 - return -ENODATA; 737 - return sprintf(buf, "%016llx\n", 738 - *(unsigned long long *) stp_info.ctnid); 690 + ssize_t ret = -ENODATA; 691 + 692 + mutex_lock(&stp_mutex); 693 + if (stpinfo_valid()) 694 + ret = sprintf(buf, "%016llx\n", 695 + *(unsigned long long *) stp_info.ctnid); 696 + mutex_unlock(&stp_mutex); 697 + return ret; 739 698 } 740 699 741 700 static DEVICE_ATTR_RO(ctn_id); ··· 748 699 struct device_attribute *attr, 749 700 char *buf) 750 701 { 751 - if (!stp_online) 752 - return -ENODATA; 753 - return sprintf(buf, "%i\n", stp_info.ctn); 702 + ssize_t ret = -ENODATA; 703 + 704 + mutex_lock(&stp_mutex); 705 + if (stpinfo_valid()) 706 + ret = sprintf(buf, "%i\n", stp_info.ctn); 707 + mutex_unlock(&stp_mutex); 708 + return ret; 754 709 } 755 710 756 711 static DEVICE_ATTR_RO(ctn_type); ··· 763 710 struct device_attribute *attr, 764 711 char *buf) 765 712 { 766 - if (!stp_online || !(stp_info.vbits & 0x2000)) 767 - return -ENODATA; 768 - return sprintf(buf, "%i\n", (int)(s16) stp_info.dsto); 713 + ssize_t ret = -ENODATA; 714 + 715 + mutex_lock(&stp_mutex); 716 + if (stpinfo_valid() && (stp_info.vbits & 0x2000)) 717 + ret = sprintf(buf, "%i\n", (int)(s16) stp_info.dsto); 718 + mutex_unlock(&stp_mutex); 719 + return ret; 769 720 } 770 721 771 722 static DEVICE_ATTR_RO(dst_offset); ··· 778 721 struct device_attribute *attr, 779 722 char *buf) 780 723 { 781 - if (!stp_online || !(stp_info.vbits & 0x8000)) 782 - return -ENODATA; 783 - return sprintf(buf, "%i\n", (int)(s16) stp_info.leaps); 724 + ssize_t ret = -ENODATA; 725 + 726 + mutex_lock(&stp_mutex); 727 + if (stpinfo_valid() && (stp_info.vbits & 0x8000)) 728 + ret = sprintf(buf, "%i\n", (int)(s16) stp_info.leaps); 729 + mutex_unlock(&stp_mutex); 730 + return ret; 784 731 } 785 732 786 733 static DEVICE_ATTR_RO(leap_seconds); 734 + 735 + static ssize_t leap_seconds_scheduled_show(struct device *dev, 736 + struct device_attribute *attr, 737 + char *buf) 738 + { 739 + struct stp_stzi stzi; 740 + ssize_t ret; 741 + 742 + mutex_lock(&stp_mutex); 743 + if (!stpinfo_valid() || !(stp_info.vbits & 0x8000) || !stp_info.lu) { 744 + mutex_unlock(&stp_mutex); 745 + return -ENODATA; 746 + } 747 + 748 + ret = chsc_stzi(stp_page, &stzi, sizeof(stzi)); 749 + mutex_unlock(&stp_mutex); 750 + if (ret < 0) 751 + return ret; 752 + 753 + if (!stzi.lsoib.p) 754 + return sprintf(buf, "0,0\n"); 755 + 756 + return sprintf(buf, "%llu,%d\n", 757 + tod_to_ns(stzi.lsoib.nlsout - TOD_UNIX_EPOCH) / NSEC_PER_SEC, 758 + stzi.lsoib.nlso - stzi.lsoib.also); 759 + } 760 + 761 + static DEVICE_ATTR_RO(leap_seconds_scheduled); 787 762 788 763 static ssize_t stratum_show(struct device *dev, 789 764 struct device_attribute *attr, 790 765 char *buf) 791 766 { 792 - if (!stp_online) 793 - return -ENODATA; 794 - return sprintf(buf, "%i\n", (int)(s16) stp_info.stratum); 767 + ssize_t ret = -ENODATA; 768 + 769 + mutex_lock(&stp_mutex); 770 + if (stpinfo_valid()) 771 + ret = sprintf(buf, "%i\n", (int)(s16) stp_info.stratum); 772 + mutex_unlock(&stp_mutex); 773 + return ret; 795 774 } 796 775 797 776 static DEVICE_ATTR_RO(stratum); ··· 836 743 struct device_attribute *attr, 837 744 char *buf) 838 745 { 839 - if (!stp_online || !(stp_info.vbits & 0x0800)) 840 - return -ENODATA; 841 - return sprintf(buf, "%i\n", (int) stp_info.tto); 746 + ssize_t ret = -ENODATA; 747 + 748 + mutex_lock(&stp_mutex); 749 + if (stpinfo_valid() && (stp_info.vbits & 0x0800)) 750 + ret = sprintf(buf, "%i\n", (int) stp_info.tto); 751 + mutex_unlock(&stp_mutex); 752 + return ret; 842 753 } 843 754 844 755 static DEVICE_ATTR_RO(time_offset); ··· 851 754 struct device_attribute *attr, 852 755 char *buf) 853 756 { 854 - if (!stp_online || !(stp_info.vbits & 0x4000)) 855 - return -ENODATA; 856 - return sprintf(buf, "%i\n", (int)(s16) stp_info.tzo); 757 + ssize_t ret = -ENODATA; 758 + 759 + mutex_lock(&stp_mutex); 760 + if (stpinfo_valid() && (stp_info.vbits & 0x4000)) 761 + ret = sprintf(buf, "%i\n", (int)(s16) stp_info.tzo); 762 + mutex_unlock(&stp_mutex); 763 + return ret; 857 764 } 858 765 859 766 static DEVICE_ATTR_RO(time_zone_offset); ··· 866 765 struct device_attribute *attr, 867 766 char *buf) 868 767 { 869 - if (!stp_online) 870 - return -ENODATA; 871 - return sprintf(buf, "%i\n", stp_info.tmd); 768 + ssize_t ret = -ENODATA; 769 + 770 + mutex_lock(&stp_mutex); 771 + if (stpinfo_valid()) 772 + ret = sprintf(buf, "%i\n", stp_info.tmd); 773 + mutex_unlock(&stp_mutex); 774 + return ret; 872 775 } 873 776 874 777 static DEVICE_ATTR_RO(timing_mode); ··· 881 776 struct device_attribute *attr, 882 777 char *buf) 883 778 { 884 - if (!stp_online) 885 - return -ENODATA; 886 - return sprintf(buf, "%i\n", stp_info.tst); 779 + ssize_t ret = -ENODATA; 780 + 781 + mutex_lock(&stp_mutex); 782 + if (stpinfo_valid()) 783 + ret = sprintf(buf, "%i\n", stp_info.tst); 784 + mutex_unlock(&stp_mutex); 785 + return ret; 887 786 } 888 787 889 788 static DEVICE_ATTR_RO(timing_state); ··· 910 801 return -EINVAL; 911 802 if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags)) 912 803 return -EOPNOTSUPP; 913 - mutex_lock(&clock_sync_mutex); 804 + mutex_lock(&stp_mutex); 914 805 stp_online = value; 915 806 if (stp_online) 916 807 set_bit(CLOCK_SYNC_STP, &clock_sync_flags); 917 808 else 918 809 clear_bit(CLOCK_SYNC_STP, &clock_sync_flags); 919 810 queue_work(time_sync_wq, &stp_work); 920 - mutex_unlock(&clock_sync_mutex); 811 + mutex_unlock(&stp_mutex); 921 812 return count; 922 813 } 923 814 ··· 933 824 &dev_attr_dst_offset, 934 825 &dev_attr_leap_seconds, 935 826 &dev_attr_online, 827 + &dev_attr_leap_seconds_scheduled, 936 828 &dev_attr_stratum, 937 829 &dev_attr_time_offset, 938 830 &dev_attr_time_zone_offset,
+41 -25
arch/s390/kernel/uv.c
··· 26 26 struct uv_info __bootdata_preserved(uv_info); 27 27 28 28 #if IS_ENABLED(CONFIG_KVM) 29 - int prot_virt_host; 29 + int __bootdata_preserved(prot_virt_host); 30 30 EXPORT_SYMBOL(prot_virt_host); 31 31 EXPORT_SYMBOL(uv_info); 32 - 33 - static int __init prot_virt_setup(char *val) 34 - { 35 - bool enabled; 36 - int rc; 37 - 38 - rc = kstrtobool(val, &enabled); 39 - if (!rc && enabled) 40 - prot_virt_host = 1; 41 - 42 - if (is_prot_virt_guest() && prot_virt_host) { 43 - prot_virt_host = 0; 44 - pr_warn("Protected virtualization not available in protected guests."); 45 - } 46 - 47 - if (prot_virt_host && !test_facility(158)) { 48 - prot_virt_host = 0; 49 - pr_warn("Protected virtualization not supported by the hardware."); 50 - } 51 - 52 - return rc; 53 - } 54 - early_param("prot_virt", prot_virt_setup); 55 32 56 33 static int __init uv_init(unsigned long stor_base, unsigned long stor_len) 57 34 { ··· 50 73 void __init setup_uv(void) 51 74 { 52 75 unsigned long uv_stor_base; 76 + 77 + /* 78 + * keep these conditions in line with kasan init code has_uv_sec_stor_limit() 79 + */ 80 + if (!is_prot_virt_host()) 81 + return; 82 + 83 + if (is_prot_virt_guest()) { 84 + prot_virt_host = 0; 85 + pr_warn("Protected virtualization not available in protected guests."); 86 + return; 87 + } 88 + 89 + if (!test_facility(158)) { 90 + prot_virt_host = 0; 91 + pr_warn("Protected virtualization not supported by the hardware."); 92 + return; 93 + } 53 94 54 95 uv_stor_base = (unsigned long)memblock_alloc_try_nid( 55 96 uv_info.uv_base_stor_len, SZ_1M, SZ_2G, ··· 93 98 94 99 void adjust_to_uv_max(unsigned long *vmax) 95 100 { 96 - *vmax = min_t(unsigned long, *vmax, uv_info.max_sec_stor_addr); 101 + if (uv_info.max_sec_stor_addr) 102 + *vmax = min_t(unsigned long, *vmax, uv_info.max_sec_stor_addr); 97 103 } 98 104 99 105 /* ··· 107 111 .header.cmd = UVC_CMD_PIN_PAGE_SHARED, 108 112 .header.len = sizeof(uvcb), 109 113 .paddr = paddr, 114 + }; 115 + 116 + if (uv_call(0, (u64)&uvcb)) 117 + return -EINVAL; 118 + return 0; 119 + } 120 + 121 + /* 122 + * Requests the Ultravisor to destroy a guest page and make it 123 + * accessible to the host. The destroy clears the page instead of 124 + * exporting. 125 + * 126 + * @paddr: Absolute host address of page to be destroyed 127 + */ 128 + int uv_destroy_page(unsigned long paddr) 129 + { 130 + struct uv_cb_cfs uvcb = { 131 + .header.cmd = UVC_CMD_DESTR_SEC_STOR, 132 + .header.len = sizeof(uvcb), 133 + .paddr = paddr 110 134 }; 111 135 112 136 if (uv_call(0, (u64)&uvcb))
+3 -26
arch/s390/kernel/vdso.c
··· 20 20 #include <linux/security.h> 21 21 #include <linux/memblock.h> 22 22 #include <linux/compat.h> 23 + #include <linux/binfmts.h> 24 + #include <vdso/datapage.h> 23 25 #include <asm/asm-offsets.h> 24 26 #include <asm/processor.h> 25 27 #include <asm/mmu.h> ··· 98 96 struct vdso_data data; 99 97 u8 page[PAGE_SIZE]; 100 98 } vdso_data_store __page_aligned_data; 101 - struct vdso_data *vdso_data = &vdso_data_store.data; 102 - 103 - /* 104 - * Setup vdso data page. 105 - */ 106 - static void __init vdso_init_data(struct vdso_data *vd) 107 - { 108 - vd->ectg_available = test_facility(31); 109 - } 110 - 99 + struct vdso_data *vdso_data = (struct vdso_data *)&vdso_data_store.data; 111 100 /* 112 101 * Allocate/free per cpu vdso data. 113 102 */ 114 103 #define SEGMENT_ORDER 2 115 - 116 - /* 117 - * The initial vdso_data structure for the boot CPU. Eventually 118 - * it is replaced with a properly allocated structure in vdso_init. 119 - * This is necessary because a valid S390_lowcore.vdso_per_cpu_data 120 - * pointer is required to be able to return from an interrupt or 121 - * program check. See the exit paths in entry.S. 122 - */ 123 - struct vdso_data boot_vdso_data __initdata; 124 - 125 - void __init vdso_alloc_boot_cpu(struct lowcore *lowcore) 126 - { 127 - lowcore->vdso_per_cpu_data = (unsigned long) &boot_vdso_data; 128 - } 129 104 130 105 int vdso_alloc_per_cpu(struct lowcore *lowcore) 131 106 { ··· 224 245 static int __init vdso_init(void) 225 246 { 226 247 int i; 227 - 228 - vdso_init_data(vdso_data); 229 248 230 249 /* Calculate the size of the 64 bit vDSO */ 231 250 vdso64_pages = ((&vdso64_end - &vdso64_start
+16 -5
arch/s390/kernel/vdso64/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - # List of files in the vdso, has to be asm only for now 2 + # List of files in the vdso 3 3 4 4 KCOV_INSTRUMENT := n 5 + ARCH_REL_TYPE_ABS := R_390_COPY|R_390_GLOB_DAT|R_390_JMP_SLOT|R_390_RELATIVE 6 + ARCH_REL_TYPE_ABS += R_390_GOT|R_390_PLT 5 7 6 - obj-vdso64 = gettimeofday.o clock_getres.o clock_gettime.o note.o getcpu.o 8 + include $(srctree)/lib/vdso/Makefile 9 + obj-vdso64 = vdso_user_wrapper.o note.o getcpu.o 10 + obj-cvdso64 = vdso64_generic.o 11 + CFLAGS_REMOVE_vdso64_generic.o = -pg $(CC_FLAGS_FTRACE) $(CC_FLAGS_EXPOLINE) 7 12 8 13 # Build rules 9 14 10 - targets := $(obj-vdso64) vdso64.so vdso64.so.dbg 15 + targets := $(obj-vdso64) $(obj-cvdso64) vdso64.so vdso64.so.dbg 11 16 obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) 17 + obj-cvdso64 := $(addprefix $(obj)/, $(obj-cvdso64)) 12 18 13 19 KBUILD_AFLAGS += -DBUILD_VDSO 14 - KBUILD_CFLAGS += -DBUILD_VDSO 20 + KBUILD_CFLAGS += -DBUILD_VDSO -DDISABLE_BRANCH_PROFILING 15 21 16 22 KBUILD_AFLAGS_64 := $(filter-out -m64,$(KBUILD_AFLAGS)) 17 23 KBUILD_AFLAGS_64 += -m64 -s ··· 43 37 $(obj)/vdso64_wrapper.o : $(obj)/vdso64.so 44 38 45 39 # link rule for the .so file, .lds has to be first 46 - $(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) FORCE 40 + $(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) $(obj-cvdso64) FORCE 47 41 $(call if_changed,ld) 48 42 49 43 # strip rule for the .so file ··· 55 49 $(obj-vdso64): %.o: %.S FORCE 56 50 $(call if_changed_dep,vdso64as) 57 51 52 + $(obj-cvdso64): %.o: %.c FORCE 53 + $(call if_changed_dep,vdso64cc) 54 + 58 55 # actual build commands 59 56 quiet_cmd_vdso64as = VDSO64A $@ 60 57 cmd_vdso64as = $(CC) $(a_flags) -c -o $@ $< 58 + quiet_cmd_vdso64cc = VDSO64C $@ 59 + cmd_vdso64cc = $(CC) $(c_flags) -c -o $@ $< 61 60 62 61 # install commands for the unstripped file 63 62 quiet_cmd_vdso_install = INSTALL $@
-50
arch/s390/kernel/vdso64/clock_getres.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * Userland implementation of clock_getres() for 64 bits processes in a 4 - * s390 kernel for use in the vDSO 5 - * 6 - * Copyright IBM Corp. 2008 7 - * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) 8 - */ 9 - #include <asm/vdso.h> 10 - #include <asm/asm-offsets.h> 11 - #include <asm/unistd.h> 12 - #include <asm/dwarf.h> 13 - 14 - .text 15 - .align 4 16 - .globl __kernel_clock_getres 17 - .type __kernel_clock_getres,@function 18 - __kernel_clock_getres: 19 - CFI_STARTPROC 20 - larl %r1,3f 21 - lg %r0,0(%r1) 22 - cghi %r2,__CLOCK_REALTIME_COARSE 23 - je 0f 24 - cghi %r2,__CLOCK_MONOTONIC_COARSE 25 - je 0f 26 - larl %r1,_vdso_data 27 - llgf %r0,__VDSO_CLOCK_REALTIME_RES(%r1) 28 - cghi %r2,__CLOCK_REALTIME 29 - je 0f 30 - cghi %r2,__CLOCK_MONOTONIC 31 - je 0f 32 - cghi %r2,__CLOCK_THREAD_CPUTIME_ID 33 - je 0f 34 - cghi %r2,-2 /* Per-thread CPUCLOCK with PID=0, VIRT=1 */ 35 - jne 2f 36 - larl %r5,_vdso_data 37 - icm %r0,15,__LC_ECTG_OK(%r5) 38 - jz 2f 39 - 0: ltgr %r3,%r3 40 - jz 1f /* res == NULL */ 41 - xc 0(8,%r3),0(%r3) /* set tp->tv_sec to zero */ 42 - stg %r0,8(%r3) /* store tp->tv_usec */ 43 - 1: lghi %r2,0 44 - br %r14 45 - 2: lghi %r1,__NR_clock_getres /* fallback to svc */ 46 - svc 0 47 - br %r14 48 - CFI_ENDPROC 49 - 3: .quad __CLOCK_COARSE_RES 50 - .size __kernel_clock_getres,.-__kernel_clock_getres
-163
arch/s390/kernel/vdso64/clock_gettime.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * Userland implementation of clock_gettime() for 64 bits processes in a 4 - * s390 kernel for use in the vDSO 5 - * 6 - * Copyright IBM Corp. 2008 7 - * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) 8 - */ 9 - #include <asm/vdso.h> 10 - #include <asm/asm-offsets.h> 11 - #include <asm/unistd.h> 12 - #include <asm/dwarf.h> 13 - #include <asm/ptrace.h> 14 - 15 - .text 16 - .align 4 17 - .globl __kernel_clock_gettime 18 - .type __kernel_clock_gettime,@function 19 - __kernel_clock_gettime: 20 - CFI_STARTPROC 21 - aghi %r15,-16 22 - CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD+16 23 - CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD 24 - larl %r5,_vdso_data 25 - cghi %r2,__CLOCK_REALTIME_COARSE 26 - je 4f 27 - cghi %r2,__CLOCK_REALTIME 28 - je 5f 29 - cghi %r2,-3 /* Per-thread CPUCLOCK with PID=0, VIRT=1 */ 30 - je 9f 31 - cghi %r2,__CLOCK_MONOTONIC_COARSE 32 - je 3f 33 - cghi %r2,__CLOCK_MONOTONIC 34 - jne 12f 35 - 36 - /* CLOCK_MONOTONIC */ 37 - 0: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */ 38 - tmll %r4,0x0001 /* pending update ? loop */ 39 - jnz 0b 40 - stcke 0(%r15) /* Store TOD clock */ 41 - lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */ 42 - lg %r0,__VDSO_WTOM_SEC(%r5) 43 - lg %r1,1(%r15) 44 - sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 45 - msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */ 46 - alg %r1,__VDSO_WTOM_NSEC(%r5) 47 - srlg %r1,%r1,0(%r2) /* >> tk->shift */ 48 - clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */ 49 - jne 0b 50 - larl %r5,13f 51 - 1: clg %r1,0(%r5) 52 - jl 2f 53 - slg %r1,0(%r5) 54 - aghi %r0,1 55 - j 1b 56 - 2: stg %r0,0(%r3) /* store tp->tv_sec */ 57 - stg %r1,8(%r3) /* store tp->tv_nsec */ 58 - lghi %r2,0 59 - aghi %r15,16 60 - CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD 61 - CFI_RESTORE 15 62 - br %r14 63 - 64 - /* CLOCK_MONOTONIC_COARSE */ 65 - CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD+16 66 - CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD 67 - 3: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */ 68 - tmll %r4,0x0001 /* pending update ? loop */ 69 - jnz 3b 70 - lg %r0,__VDSO_WTOM_CRS_SEC(%r5) 71 - lg %r1,__VDSO_WTOM_CRS_NSEC(%r5) 72 - clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */ 73 - jne 3b 74 - j 2b 75 - 76 - /* CLOCK_REALTIME_COARSE */ 77 - 4: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */ 78 - tmll %r4,0x0001 /* pending update ? loop */ 79 - jnz 4b 80 - lg %r0,__VDSO_XTIME_CRS_SEC(%r5) 81 - lg %r1,__VDSO_XTIME_CRS_NSEC(%r5) 82 - clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */ 83 - jne 4b 84 - j 7f 85 - 86 - /* CLOCK_REALTIME */ 87 - 5: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */ 88 - tmll %r4,0x0001 /* pending update ? loop */ 89 - jnz 5b 90 - stcke 0(%r15) /* Store TOD clock */ 91 - lg %r1,1(%r15) 92 - lg %r0,__VDSO_TS_END(%r5) /* TOD steering end time */ 93 - slgr %r0,%r1 /* now - ts_steering_end */ 94 - ltgr %r0,%r0 /* past end of steering ? */ 95 - jm 17f 96 - srlg %r0,%r0,15 /* 1 per 2^16 */ 97 - tm __VDSO_TS_DIR+3(%r5),0x01 /* steering direction? */ 98 - jz 18f 99 - lcgr %r0,%r0 /* negative TOD offset */ 100 - 18: algr %r1,%r0 /* add steering offset */ 101 - 17: lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */ 102 - sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 103 - msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */ 104 - alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */ 105 - srlg %r1,%r1,0(%r2) /* >> tk->shift */ 106 - lg %r0,__VDSO_XTIME_SEC(%r5) /* tk->xtime_sec */ 107 - clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */ 108 - jne 5b 109 - larl %r5,13f 110 - 6: clg %r1,0(%r5) 111 - jl 7f 112 - slg %r1,0(%r5) 113 - aghi %r0,1 114 - j 6b 115 - 7: stg %r0,0(%r3) /* store tp->tv_sec */ 116 - stg %r1,8(%r3) /* store tp->tv_nsec */ 117 - lghi %r2,0 118 - aghi %r15,16 119 - CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD 120 - CFI_RESTORE 15 121 - br %r14 122 - 123 - /* CPUCLOCK_VIRT for this thread */ 124 - CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD+16 125 - CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD 126 - 9: lghi %r4,0 127 - icm %r0,15,__VDSO_ECTG_OK(%r5) 128 - jz 12f 129 - sacf 256 /* Magic ectg instruction */ 130 - .insn ssf,0xc80100000000,__VDSO_ECTG_BASE(4),__VDSO_ECTG_USER(4),4 131 - sacf 0 132 - algr %r1,%r0 /* r1 = cputime as TOD value */ 133 - mghi %r1,1000 /* convert to nanoseconds */ 134 - srlg %r1,%r1,12 /* r1 = cputime in nanosec */ 135 - lgr %r4,%r1 136 - larl %r5,13f 137 - srlg %r1,%r1,9 /* divide by 1000000000 */ 138 - mlg %r0,8(%r5) 139 - srlg %r0,%r0,11 /* r0 = tv_sec */ 140 - stg %r0,0(%r3) 141 - msg %r0,0(%r5) /* calculate tv_nsec */ 142 - slgr %r4,%r0 /* r4 = tv_nsec */ 143 - stg %r4,8(%r3) 144 - lghi %r2,0 145 - aghi %r15,16 146 - CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD 147 - CFI_RESTORE 15 148 - br %r14 149 - 150 - /* Fallback to system call */ 151 - CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD+16 152 - CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD 153 - 12: lghi %r1,__NR_clock_gettime 154 - svc 0 155 - aghi %r15,16 156 - CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD 157 - CFI_RESTORE 15 158 - br %r14 159 - CFI_ENDPROC 160 - 161 - 13: .quad 1000000000 162 - 14: .quad 19342813113834067 163 - .size __kernel_clock_gettime,.-__kernel_clock_gettime
-71
arch/s390/kernel/vdso64/gettimeofday.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * Userland implementation of gettimeofday() for 64 bits processes in a 4 - * s390 kernel for use in the vDSO 5 - * 6 - * Copyright IBM Corp. 2008 7 - * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) 8 - */ 9 - #include <asm/vdso.h> 10 - #include <asm/asm-offsets.h> 11 - #include <asm/unistd.h> 12 - #include <asm/dwarf.h> 13 - #include <asm/ptrace.h> 14 - 15 - .text 16 - .align 4 17 - .globl __kernel_gettimeofday 18 - .type __kernel_gettimeofday,@function 19 - __kernel_gettimeofday: 20 - CFI_STARTPROC 21 - aghi %r15,-16 22 - CFI_ADJUST_CFA_OFFSET 16 23 - CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD 24 - larl %r5,_vdso_data 25 - 0: ltgr %r3,%r3 /* check if tz is NULL */ 26 - je 1f 27 - mvc 0(8,%r3),__VDSO_TIMEZONE(%r5) 28 - 1: ltgr %r2,%r2 /* check if tv is NULL */ 29 - je 4f 30 - lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */ 31 - tmll %r4,0x0001 /* pending update ? loop */ 32 - jnz 0b 33 - stcke 0(%r15) /* Store TOD clock */ 34 - lg %r1,1(%r15) 35 - lg %r0,__VDSO_TS_END(%r5) /* TOD steering end time */ 36 - slgr %r0,%r1 /* now - ts_steering_end */ 37 - ltgr %r0,%r0 /* past end of steering ? */ 38 - jm 6f 39 - srlg %r0,%r0,15 /* 1 per 2^16 */ 40 - tm __VDSO_TS_DIR+3(%r5),0x01 /* steering direction? */ 41 - jz 7f 42 - lcgr %r0,%r0 /* negative TOD offset */ 43 - 7: algr %r1,%r0 /* add steering offset */ 44 - 6: sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 45 - msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */ 46 - alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */ 47 - lg %r0,__VDSO_XTIME_SEC(%r5) /* tk->xtime_sec */ 48 - clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */ 49 - jne 0b 50 - lgf %r5,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */ 51 - srlg %r1,%r1,0(%r5) /* >> tk->shift */ 52 - larl %r5,5f 53 - 2: clg %r1,0(%r5) 54 - jl 3f 55 - slg %r1,0(%r5) 56 - aghi %r0,1 57 - j 2b 58 - 3: stg %r0,0(%r2) /* store tv->tv_sec */ 59 - slgr %r0,%r0 /* tv_nsec -> tv_usec */ 60 - ml %r0,8(%r5) 61 - srlg %r0,%r0,6 62 - stg %r0,8(%r2) /* store tv->tv_usec */ 63 - 4: lghi %r2,0 64 - aghi %r15,16 65 - CFI_ADJUST_CFA_OFFSET -16 66 - CFI_RESTORE 15 67 - br %r14 68 - CFI_ENDPROC 69 - 5: .quad 1000000000 70 - .long 274877907 71 - .size __kernel_gettimeofday,.-__kernel_gettimeofday
+18
arch/s390/kernel/vdso64/vdso64_generic.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include "../../../../lib/vdso/gettimeofday.c" 3 + 4 + int __s390_vdso_gettimeofday(struct __kernel_old_timeval *tv, 5 + struct timezone *tz) 6 + { 7 + return __cvdso_gettimeofday(tv, tz); 8 + } 9 + 10 + int __s390_vdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts) 11 + { 12 + return __cvdso_clock_gettime(clock, ts); 13 + } 14 + 15 + int __s390_vdso_clock_getres(clockid_t clock, struct __kernel_timespec *ts) 16 + { 17 + return __cvdso_clock_getres(clock, ts); 18 + }
+38
arch/s390/kernel/vdso64/vdso_user_wrapper.S
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #include <asm/vdso.h> 3 + #include <asm/unistd.h> 4 + #include <asm/asm-offsets.h> 5 + #include <asm/dwarf.h> 6 + #include <asm/ptrace.h> 7 + 8 + #define WRAPPER_FRAME_SIZE (STACK_FRAME_OVERHEAD+8) 9 + 10 + /* 11 + * Older glibc version called vdso without allocating a stackframe. This wrapper 12 + * is just used to allocate a stackframe. See 13 + * https://sourceware.org/git/?p=glibc.git;a=commit;h=478593e6374f3818da39332260dc453cb19cfa1e 14 + * for details. 15 + */ 16 + .macro vdso_func func 17 + .globl __kernel_\func 18 + .type __kernel_\func,@function 19 + .align 8 20 + __kernel_\func: 21 + CFI_STARTPROC 22 + aghi %r15,-WRAPPER_FRAME_SIZE 23 + CFI_DEF_CFA_OFFSET (STACK_FRAME_OVERHEAD + WRAPPER_FRAME_SIZE) 24 + CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD 25 + stg %r14,STACK_FRAME_OVERHEAD(%r15) 26 + brasl %r14,__s390_vdso_\func 27 + lg %r14,STACK_FRAME_OVERHEAD(%r15) 28 + aghi %r15,WRAPPER_FRAME_SIZE 29 + CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD 30 + CFI_RESTORE 15 31 + br %r14 32 + CFI_ENDPROC 33 + .size __kernel_\func,.-__kernel_\func 34 + .endm 35 + 36 + vdso_func gettimeofday 37 + vdso_func clock_getres 38 + vdso_func clock_gettime
+1 -1
arch/s390/lib/string.c
··· 333 333 * memcmp - Compare two areas of memory 334 334 * @s1: One area of memory 335 335 * @s2: Another area of memory 336 - * @count: The size of the area. 336 + * @n: The size of the area. 337 337 */ 338 338 #ifdef __HAVE_ARCH_MEMCMP 339 339 int memcmp(const void *s1, const void *s2, size_t n)
+1 -1
arch/s390/mm/Makefile
··· 8 8 9 9 obj-$(CONFIG_CMM) += cmm.o 10 10 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o 11 - obj-$(CONFIG_S390_PTDUMP) += dump_pagetables.o 11 + obj-$(CONFIG_PTDUMP_CORE) += dump_pagetables.o 12 12 obj-$(CONFIG_PGSTE) += gmap.o 13 13 14 14 KASAN_SANITIZE_kasan_init.o := n
+171 -191
arch/s390/mm/dump_pagetables.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/set_memory.h> 3 + #include <linux/ptdump.h> 2 4 #include <linux/seq_file.h> 3 5 #include <linux/debugfs.h> 4 - #include <linux/sched.h> 5 6 #include <linux/mm.h> 6 7 #include <linux/kasan.h> 8 + #include <asm/ptdump.h> 7 9 #include <asm/kasan.h> 8 10 #include <asm/sections.h> 9 11 ··· 17 15 }; 18 16 19 17 enum address_markers_idx { 20 - IDENTITY_NR = 0, 18 + IDENTITY_BEFORE_NR = 0, 19 + IDENTITY_BEFORE_END_NR, 21 20 KERNEL_START_NR, 22 21 KERNEL_END_NR, 22 + IDENTITY_AFTER_NR, 23 + IDENTITY_AFTER_END_NR, 23 24 #ifdef CONFIG_KASAN 24 25 KASAN_SHADOW_START_NR, 25 26 KASAN_SHADOW_END_NR, 26 27 #endif 27 28 VMEMMAP_NR, 29 + VMEMMAP_END_NR, 28 30 VMALLOC_NR, 31 + VMALLOC_END_NR, 29 32 MODULES_NR, 33 + MODULES_END_NR, 30 34 }; 31 35 32 36 static struct addr_marker address_markers[] = { 33 - [IDENTITY_NR] = {0, "Identity Mapping"}, 37 + [IDENTITY_BEFORE_NR] = {0, "Identity Mapping Start"}, 38 + [IDENTITY_BEFORE_END_NR] = {(unsigned long)_stext, "Identity Mapping End"}, 34 39 [KERNEL_START_NR] = {(unsigned long)_stext, "Kernel Image Start"}, 35 40 [KERNEL_END_NR] = {(unsigned long)_end, "Kernel Image End"}, 41 + [IDENTITY_AFTER_NR] = {(unsigned long)_end, "Identity Mapping Start"}, 42 + [IDENTITY_AFTER_END_NR] = {0, "Identity Mapping End"}, 36 43 #ifdef CONFIG_KASAN 37 44 [KASAN_SHADOW_START_NR] = {KASAN_SHADOW_START, "Kasan Shadow Start"}, 38 45 [KASAN_SHADOW_END_NR] = {KASAN_SHADOW_END, "Kasan Shadow End"}, 39 46 #endif 40 - [VMEMMAP_NR] = {0, "vmemmap Area"}, 41 - [VMALLOC_NR] = {0, "vmalloc Area"}, 42 - [MODULES_NR] = {0, "Modules Area"}, 47 + [VMEMMAP_NR] = {0, "vmemmap Area Start"}, 48 + [VMEMMAP_END_NR] = {0, "vmemmap Area End"}, 49 + [VMALLOC_NR] = {0, "vmalloc Area Start"}, 50 + [VMALLOC_END_NR] = {0, "vmalloc Area End"}, 51 + [MODULES_NR] = {0, "Modules Area Start"}, 52 + [MODULES_END_NR] = {0, "Modules Area End"}, 43 53 { -1, NULL } 44 54 }; 45 55 46 56 struct pg_state { 57 + struct ptdump_state ptdump; 58 + struct seq_file *seq; 47 59 int level; 48 60 unsigned int current_prot; 61 + bool check_wx; 62 + unsigned long wx_pages; 49 63 unsigned long start_address; 50 - unsigned long current_address; 51 64 const struct addr_marker *marker; 52 65 }; 66 + 67 + #define pt_dump_seq_printf(m, fmt, args...) \ 68 + ({ \ 69 + struct seq_file *__m = (m); \ 70 + \ 71 + if (__m) \ 72 + seq_printf(__m, fmt, ##args); \ 73 + }) 74 + 75 + #define pt_dump_seq_puts(m, fmt) \ 76 + ({ \ 77 + struct seq_file *__m = (m); \ 78 + \ 79 + if (__m) \ 80 + seq_printf(__m, fmt); \ 81 + }) 53 82 54 83 static void print_prot(struct seq_file *m, unsigned int pr, int level) 55 84 { 56 85 static const char * const level_name[] = 57 86 { "ASCE", "PGD", "PUD", "PMD", "PTE" }; 58 87 59 - seq_printf(m, "%s ", level_name[level]); 88 + pt_dump_seq_printf(m, "%s ", level_name[level]); 60 89 if (pr & _PAGE_INVALID) { 61 - seq_printf(m, "I\n"); 90 + pt_dump_seq_printf(m, "I\n"); 62 91 return; 63 92 } 64 - seq_puts(m, (pr & _PAGE_PROTECT) ? "RO " : "RW "); 65 - seq_puts(m, (pr & _PAGE_NOEXEC) ? "NX\n" : "X\n"); 93 + pt_dump_seq_puts(m, (pr & _PAGE_PROTECT) ? "RO " : "RW "); 94 + pt_dump_seq_puts(m, (pr & _PAGE_NOEXEC) ? "NX\n" : "X\n"); 66 95 } 67 96 68 - static void note_page(struct seq_file *m, struct pg_state *st, 69 - unsigned int new_prot, int level) 97 + static void note_prot_wx(struct pg_state *st, unsigned long addr) 70 98 { 71 - static const char units[] = "KMGTPE"; 99 + #ifdef CONFIG_DEBUG_WX 100 + if (!st->check_wx) 101 + return; 102 + if (st->current_prot & _PAGE_INVALID) 103 + return; 104 + if (st->current_prot & _PAGE_PROTECT) 105 + return; 106 + if (st->current_prot & _PAGE_NOEXEC) 107 + return; 108 + /* The first lowcore page is currently still W+X. */ 109 + if (addr == PAGE_SIZE) 110 + return; 111 + WARN_ONCE(1, "s390/mm: Found insecure W+X mapping at address %pS\n", 112 + (void *)st->start_address); 113 + st->wx_pages += (addr - st->start_address) / PAGE_SIZE; 114 + #endif /* CONFIG_DEBUG_WX */ 115 + } 116 + 117 + static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, u64 val) 118 + { 72 119 int width = sizeof(unsigned long) * 2; 120 + static const char units[] = "KMGTPE"; 73 121 const char *unit = units; 74 - unsigned int prot, cur; 75 122 unsigned long delta; 123 + struct pg_state *st; 124 + struct seq_file *m; 125 + unsigned int prot; 76 126 77 - /* 78 - * If we have a "break" in the series, we need to flush the state 79 - * that we have now. "break" is either changing perms, levels or 80 - * address space marker. 81 - */ 82 - prot = new_prot; 83 - cur = st->current_prot; 84 - 85 - if (!st->level) { 86 - /* First entry */ 87 - st->current_prot = new_prot; 127 + st = container_of(pt_st, struct pg_state, ptdump); 128 + m = st->seq; 129 + prot = val & (_PAGE_PROTECT | _PAGE_NOEXEC); 130 + if (level == 4 && (val & _PAGE_INVALID)) 131 + prot = _PAGE_INVALID; 132 + /* For pmd_none() & friends val gets passed as zero. */ 133 + if (level != 4 && !val) 134 + prot = _PAGE_INVALID; 135 + /* Final flush from generic code. */ 136 + if (level == -1) 137 + addr = max_addr; 138 + if (st->level == -1) { 139 + pt_dump_seq_printf(m, "---[ %s ]---\n", st->marker->name); 140 + st->start_address = addr; 141 + st->current_prot = prot; 88 142 st->level = level; 89 - st->marker = address_markers; 90 - seq_printf(m, "---[ %s ]---\n", st->marker->name); 91 - } else if (prot != cur || level != st->level || 92 - st->current_address >= st->marker[1].start_address) { 93 - /* Print the actual finished series */ 94 - seq_printf(m, "0x%0*lx-0x%0*lx ", 95 - width, st->start_address, 96 - width, st->current_address); 97 - delta = (st->current_address - st->start_address) >> 10; 143 + } else if (prot != st->current_prot || level != st->level || 144 + addr >= st->marker[1].start_address) { 145 + note_prot_wx(st, addr); 146 + pt_dump_seq_printf(m, "0x%0*lx-0x%0*lx ", 147 + width, st->start_address, 148 + width, addr); 149 + delta = (addr - st->start_address) >> 10; 98 150 while (!(delta & 0x3ff) && unit[1]) { 99 151 delta >>= 10; 100 152 unit++; 101 153 } 102 - seq_printf(m, "%9lu%c ", delta, *unit); 154 + pt_dump_seq_printf(m, "%9lu%c ", delta, *unit); 103 155 print_prot(m, st->current_prot, st->level); 104 - while (st->current_address >= st->marker[1].start_address) { 156 + while (addr >= st->marker[1].start_address) { 105 157 st->marker++; 106 - seq_printf(m, "---[ %s ]---\n", st->marker->name); 158 + pt_dump_seq_printf(m, "---[ %s ]---\n", st->marker->name); 107 159 } 108 - st->start_address = st->current_address; 109 - st->current_prot = new_prot; 160 + st->start_address = addr; 161 + st->current_prot = prot; 110 162 st->level = level; 111 163 } 112 164 } 113 165 114 - #ifdef CONFIG_KASAN 115 - static void note_kasan_early_shadow_page(struct seq_file *m, 116 - struct pg_state *st) 166 + #ifdef CONFIG_DEBUG_WX 167 + void ptdump_check_wx(void) 117 168 { 118 - unsigned int prot; 169 + struct pg_state st = { 170 + .ptdump = { 171 + .note_page = note_page, 172 + .range = (struct ptdump_range[]) { 173 + {.start = 0, .end = max_addr}, 174 + {.start = 0, .end = 0}, 175 + } 176 + }, 177 + .seq = NULL, 178 + .level = -1, 179 + .current_prot = 0, 180 + .check_wx = true, 181 + .wx_pages = 0, 182 + .start_address = 0, 183 + .marker = (struct addr_marker[]) { 184 + { .start_address = 0, .name = NULL}, 185 + { .start_address = -1, .name = NULL}, 186 + }, 187 + }; 119 188 120 - prot = pte_val(*kasan_early_shadow_pte) & 121 - (_PAGE_PROTECT | _PAGE_INVALID | _PAGE_NOEXEC); 122 - note_page(m, st, prot, 4); 123 - } 124 - #endif 125 - 126 - /* 127 - * The actual page table walker functions. In order to keep the 128 - * implementation of print_prot() short, we only check and pass 129 - * _PAGE_INVALID and _PAGE_PROTECT flags to note_page() if a region, 130 - * segment or page table entry is invalid or read-only. 131 - * After all it's just a hint that the current level being walked 132 - * contains an invalid or read-only entry. 133 - */ 134 - static void walk_pte_level(struct seq_file *m, struct pg_state *st, 135 - pmd_t *pmd, unsigned long addr) 136 - { 137 - unsigned int prot; 138 - pte_t *pte; 139 - int i; 140 - 141 - for (i = 0; i < PTRS_PER_PTE && addr < max_addr; i++) { 142 - st->current_address = addr; 143 - pte = pte_offset_kernel(pmd, addr); 144 - prot = pte_val(*pte) & 145 - (_PAGE_PROTECT | _PAGE_INVALID | _PAGE_NOEXEC); 146 - note_page(m, st, prot, 4); 147 - addr += PAGE_SIZE; 148 - } 149 - } 150 - 151 - static void walk_pmd_level(struct seq_file *m, struct pg_state *st, 152 - pud_t *pud, unsigned long addr) 153 - { 154 - unsigned int prot; 155 - pmd_t *pmd; 156 - int i; 157 - 158 - #ifdef CONFIG_KASAN 159 - if ((pud_val(*pud) & PAGE_MASK) == __pa(kasan_early_shadow_pmd)) { 160 - note_kasan_early_shadow_page(m, st); 189 + if (!MACHINE_HAS_NX) 161 190 return; 162 - } 163 - #endif 164 - 165 - pmd = pmd_offset(pud, addr); 166 - for (i = 0; i < PTRS_PER_PMD && addr < max_addr; i++, pmd++) { 167 - st->current_address = addr; 168 - if (!pmd_none(*pmd)) { 169 - if (pmd_large(*pmd)) { 170 - prot = pmd_val(*pmd) & 171 - (_SEGMENT_ENTRY_PROTECT | 172 - _SEGMENT_ENTRY_NOEXEC); 173 - note_page(m, st, prot, 3); 174 - } else 175 - walk_pte_level(m, st, pmd, addr); 176 - } else 177 - note_page(m, st, _PAGE_INVALID, 3); 178 - addr += PMD_SIZE; 179 - } 191 + ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); 192 + if (st.wx_pages) 193 + pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found\n", st.wx_pages); 194 + else 195 + pr_info("Checked W+X mappings: passed, no unexpected W+X pages found\n"); 180 196 } 197 + #endif /* CONFIG_DEBUG_WX */ 181 198 182 - static void walk_pud_level(struct seq_file *m, struct pg_state *st, 183 - p4d_t *p4d, unsigned long addr) 184 - { 185 - unsigned int prot; 186 - pud_t *pud; 187 - int i; 188 - 189 - #ifdef CONFIG_KASAN 190 - if ((p4d_val(*p4d) & PAGE_MASK) == __pa(kasan_early_shadow_pud)) { 191 - note_kasan_early_shadow_page(m, st); 192 - return; 193 - } 194 - #endif 195 - 196 - pud = pud_offset(p4d, addr); 197 - for (i = 0; i < PTRS_PER_PUD && addr < max_addr; i++, pud++) { 198 - st->current_address = addr; 199 - if (!pud_none(*pud)) 200 - if (pud_large(*pud)) { 201 - prot = pud_val(*pud) & 202 - (_REGION_ENTRY_PROTECT | 203 - _REGION_ENTRY_NOEXEC); 204 - note_page(m, st, prot, 2); 205 - } else 206 - walk_pmd_level(m, st, pud, addr); 207 - else 208 - note_page(m, st, _PAGE_INVALID, 2); 209 - addr += PUD_SIZE; 210 - } 211 - } 212 - 213 - static void walk_p4d_level(struct seq_file *m, struct pg_state *st, 214 - pgd_t *pgd, unsigned long addr) 215 - { 216 - p4d_t *p4d; 217 - int i; 218 - 219 - #ifdef CONFIG_KASAN 220 - if ((pgd_val(*pgd) & PAGE_MASK) == __pa(kasan_early_shadow_p4d)) { 221 - note_kasan_early_shadow_page(m, st); 222 - return; 223 - } 224 - #endif 225 - 226 - p4d = p4d_offset(pgd, addr); 227 - for (i = 0; i < PTRS_PER_P4D && addr < max_addr; i++, p4d++) { 228 - st->current_address = addr; 229 - if (!p4d_none(*p4d)) 230 - walk_pud_level(m, st, p4d, addr); 231 - else 232 - note_page(m, st, _PAGE_INVALID, 2); 233 - addr += P4D_SIZE; 234 - } 235 - } 236 - 237 - static void walk_pgd_level(struct seq_file *m) 238 - { 239 - unsigned long addr = 0; 240 - struct pg_state st; 241 - pgd_t *pgd; 242 - int i; 243 - 244 - memset(&st, 0, sizeof(st)); 245 - for (i = 0; i < PTRS_PER_PGD && addr < max_addr; i++) { 246 - st.current_address = addr; 247 - pgd = pgd_offset_k(addr); 248 - if (!pgd_none(*pgd)) 249 - walk_p4d_level(m, &st, pgd, addr); 250 - else 251 - note_page(m, &st, _PAGE_INVALID, 1); 252 - addr += PGDIR_SIZE; 253 - cond_resched(); 254 - } 255 - /* Flush out the last page */ 256 - st.current_address = max_addr; 257 - note_page(m, &st, 0, 0); 258 - } 259 - 199 + #ifdef CONFIG_PTDUMP_DEBUGFS 260 200 static int ptdump_show(struct seq_file *m, void *v) 261 201 { 262 - walk_pgd_level(m); 202 + struct pg_state st = { 203 + .ptdump = { 204 + .note_page = note_page, 205 + .range = (struct ptdump_range[]) { 206 + {.start = 0, .end = max_addr}, 207 + {.start = 0, .end = 0}, 208 + } 209 + }, 210 + .seq = m, 211 + .level = -1, 212 + .current_prot = 0, 213 + .check_wx = false, 214 + .wx_pages = 0, 215 + .start_address = 0, 216 + .marker = address_markers, 217 + }; 218 + 219 + get_online_mems(); 220 + mutex_lock(&cpa_mutex); 221 + ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); 222 + mutex_unlock(&cpa_mutex); 223 + put_online_mems(); 263 224 return 0; 264 225 } 226 + DEFINE_SHOW_ATTRIBUTE(ptdump); 227 + #endif /* CONFIG_PTDUMP_DEBUGFS */ 265 228 266 - static int ptdump_open(struct inode *inode, struct file *filp) 229 + /* 230 + * Heapsort from lib/sort.c is not a stable sorting algorithm, do a simple 231 + * insertion sort to preserve the original order of markers with the same 232 + * start address. 233 + */ 234 + static void sort_address_markers(void) 267 235 { 268 - return single_open(filp, ptdump_show, NULL); 269 - } 236 + struct addr_marker tmp; 237 + int i, j; 270 238 271 - static const struct file_operations ptdump_fops = { 272 - .open = ptdump_open, 273 - .read = seq_read, 274 - .llseek = seq_lseek, 275 - .release = single_release, 276 - }; 239 + for (i = 1; i < ARRAY_SIZE(address_markers) - 1; i++) { 240 + tmp = address_markers[i]; 241 + for (j = i - 1; j >= 0 && address_markers[j].start_address > tmp.start_address; j--) 242 + address_markers[j + 1] = address_markers[j]; 243 + address_markers[j + 1] = tmp; 244 + } 245 + } 277 246 278 247 static int pt_dump_init(void) 279 248 { ··· 255 282 */ 256 283 max_addr = (S390_lowcore.kernel_asce & _REGION_ENTRY_TYPE_MASK) >> 2; 257 284 max_addr = 1UL << (max_addr * 11 + 31); 285 + address_markers[IDENTITY_AFTER_END_NR].start_address = memory_end; 258 286 address_markers[MODULES_NR].start_address = MODULES_VADDR; 287 + address_markers[MODULES_END_NR].start_address = MODULES_END; 259 288 address_markers[VMEMMAP_NR].start_address = (unsigned long) vmemmap; 289 + address_markers[VMEMMAP_END_NR].start_address = (unsigned long)vmemmap + vmemmap_size; 260 290 address_markers[VMALLOC_NR].start_address = VMALLOC_START; 291 + address_markers[VMALLOC_END_NR].start_address = VMALLOC_END; 292 + sort_address_markers(); 293 + #ifdef CONFIG_PTDUMP_DEBUGFS 261 294 debugfs_create_file("kernel_page_tables", 0400, NULL, NULL, &ptdump_fops); 295 + #endif /* CONFIG_PTDUMP_DEBUGFS */ 262 296 return 0; 263 297 } 264 298 device_initcall(pt_dump_init);
+1 -1
arch/s390/mm/gmap.c
··· 2679 2679 pte_t pte = READ_ONCE(*ptep); 2680 2680 2681 2681 if (pte_present(pte)) 2682 - WARN_ON_ONCE(uv_convert_from_secure(pte_val(pte) & PAGE_MASK)); 2682 + WARN_ON_ONCE(uv_destroy_page(pte_val(pte) & PAGE_MASK)); 2683 2683 return 0; 2684 2684 } 2685 2685
+2
arch/s390/mm/init.c
··· 34 34 #include <asm/processor.h> 35 35 #include <linux/uaccess.h> 36 36 #include <asm/pgalloc.h> 37 + #include <asm/ptdump.h> 37 38 #include <asm/dma.h> 38 39 #include <asm/lowcore.h> 39 40 #include <asm/tlb.h> ··· 130 129 131 130 set_memory_ro((unsigned long)__start_ro_after_init, size >> PAGE_SHIFT); 132 131 pr_info("Write protected read-only-after-init data: %luk\n", size >> 10); 132 + debug_checkwx(); 133 133 } 134 134 135 135 int set_memory_encrypted(unsigned long addr, int numpages)
+36 -8
arch/s390/mm/kasan_init.c
··· 11 11 #include <asm/facility.h> 12 12 #include <asm/sections.h> 13 13 #include <asm/setup.h> 14 + #include <asm/uv.h> 14 15 16 + unsigned long kasan_vmax; 15 17 static unsigned long segment_pos __initdata; 16 18 static unsigned long segment_low __initdata; 17 19 static unsigned long pgalloc_pos __initdata; ··· 101 99 pgt_prot_zero = pgprot_val(PAGE_KERNEL_RO); 102 100 if (!has_nx) 103 101 pgt_prot_zero &= ~_PAGE_NOEXEC; 104 - pgt_prot = pgprot_val(PAGE_KERNEL_EXEC); 105 - sgt_prot = pgprot_val(SEGMENT_KERNEL_EXEC); 102 + pgt_prot = pgprot_val(PAGE_KERNEL); 103 + sgt_prot = pgprot_val(SEGMENT_KERNEL); 104 + if (!has_nx || mode == POPULATE_ONE2ONE) { 105 + pgt_prot &= ~_PAGE_NOEXEC; 106 + sgt_prot &= ~_SEGMENT_ENTRY_NOEXEC; 107 + } 106 108 107 109 while (address < end) { 108 110 pg_dir = pgd_offset_k(address); ··· 258 252 } 259 253 } 260 254 255 + static bool __init has_uv_sec_stor_limit(void) 256 + { 257 + /* 258 + * keep these conditions in line with setup_uv() 259 + */ 260 + if (!is_prot_virt_host()) 261 + return false; 262 + 263 + if (is_prot_virt_guest()) 264 + return false; 265 + 266 + if (!test_facility(158)) 267 + return false; 268 + 269 + return !!uv_info.max_sec_stor_addr; 270 + } 271 + 261 272 void __init kasan_early_init(void) 262 273 { 263 274 unsigned long untracked_mem_end; 264 275 unsigned long shadow_alloc_size; 276 + unsigned long vmax_unlimited; 265 277 unsigned long initrd_end; 266 278 unsigned long asce_type; 267 279 unsigned long memsize; 268 - unsigned long vmax; 269 280 unsigned long pgt_prot = pgprot_val(PAGE_KERNEL_RO); 270 281 pte_t pte_z; 271 282 pmd_t pmd_z = __pmd(__pa(kasan_early_shadow_pte) | _SEGMENT_ENTRY); ··· 310 287 BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, P4D_SIZE)); 311 288 crst_table_init((unsigned long *)early_pg_dir, 312 289 _REGION2_ENTRY_EMPTY); 313 - untracked_mem_end = vmax = _REGION1_SIZE; 290 + untracked_mem_end = kasan_vmax = vmax_unlimited = _REGION1_SIZE; 291 + if (has_uv_sec_stor_limit()) 292 + kasan_vmax = min(vmax_unlimited, uv_info.max_sec_stor_addr); 314 293 asce_type = _ASCE_TYPE_REGION2; 315 294 } else { 316 295 /* 3 level paging */ ··· 320 295 BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PUD_SIZE)); 321 296 crst_table_init((unsigned long *)early_pg_dir, 322 297 _REGION3_ENTRY_EMPTY); 323 - untracked_mem_end = vmax = _REGION2_SIZE; 298 + untracked_mem_end = kasan_vmax = vmax_unlimited = _REGION2_SIZE; 324 299 asce_type = _ASCE_TYPE_REGION3; 325 300 } 326 301 ··· 390 365 /* populate kasan shadow (for identity mapping and zero page mapping) */ 391 366 kasan_early_vmemmap_populate(__sha(0), __sha(memsize), POPULATE_MAP); 392 367 if (IS_ENABLED(CONFIG_MODULES)) 393 - untracked_mem_end = vmax - MODULES_LEN; 368 + untracked_mem_end = kasan_vmax - MODULES_LEN; 394 369 if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) { 395 - untracked_mem_end = vmax - vmalloc_size - MODULES_LEN; 370 + untracked_mem_end = kasan_vmax - vmalloc_size - MODULES_LEN; 396 371 /* shallowly populate kasan shadow for vmalloc and modules */ 397 372 kasan_early_vmemmap_populate(__sha(untracked_mem_end), 398 - __sha(vmax), POPULATE_SHALLOW); 373 + __sha(kasan_vmax), POPULATE_SHALLOW); 399 374 } 400 375 /* populate kasan shadow for untracked memory */ 401 376 kasan_early_vmemmap_populate(__sha(max_physmem_end), 402 377 __sha(untracked_mem_end), 378 + POPULATE_ZERO_SHADOW); 379 + kasan_early_vmemmap_populate(__sha(kasan_vmax), 380 + __sha(vmax_unlimited), 403 381 POPULATE_ZERO_SHADOW); 404 382 /* memory allocated for identity mapping structs will be freed later */ 405 383 pgalloc_freeable = pgalloc_pos;
+1 -1
arch/s390/mm/pageattr.c
··· 278 278 return rc; 279 279 } 280 280 281 - static DEFINE_MUTEX(cpa_mutex); 281 + DEFINE_MUTEX(cpa_mutex); 282 282 283 283 static int change_page_attr(unsigned long addr, unsigned long end, 284 284 unsigned long flags)
+20
arch/s390/mm/pgtable.c
··· 24 24 #include <asm/mmu_context.h> 25 25 #include <asm/page-states.h> 26 26 27 + pgprot_t pgprot_writecombine(pgprot_t prot) 28 + { 29 + /* 30 + * mio_wb_bit_mask may be set on a different CPU, but it is only set 31 + * once at init and only read afterwards. 32 + */ 33 + return __pgprot(pgprot_val(prot) | mio_wb_bit_mask); 34 + } 35 + EXPORT_SYMBOL_GPL(pgprot_writecombine); 36 + 37 + pgprot_t pgprot_writethrough(pgprot_t prot) 38 + { 39 + /* 40 + * mio_wb_bit_mask may be set on a different CPU, but it is only set 41 + * once at init and only read afterwards. 42 + */ 43 + return __pgprot(pgprot_val(prot) & ~mio_wb_bit_mask); 44 + } 45 + EXPORT_SYMBOL_GPL(pgprot_writethrough); 46 + 27 47 static inline void ptep_ipte_local(struct mm_struct *mm, unsigned long addr, 28 48 pte_t *ptep, int nodat) 29 49 {
+1
arch/s390/pci/Makefile
··· 6 6 obj-$(CONFIG_PCI) += pci.o pci_irq.o pci_dma.o pci_clp.o pci_sysfs.o \ 7 7 pci_event.o pci_debug.o pci_insn.o pci_mmio.o \ 8 8 pci_bus.o 9 + obj-$(CONFIG_PCI_IOV) += pci_iov.o
+31 -28
arch/s390/pci/pci.c
··· 37 37 #include <asm/pci_dma.h> 38 38 39 39 #include "pci_bus.h" 40 + #include "pci_iov.h" 40 41 41 42 /* list of all detected zpci devices */ 42 43 static LIST_HEAD(zpci_list); ··· 227 226 zpci_memcpy_toio(to, from, count); 228 227 } 229 228 230 - void __iomem *ioremap(phys_addr_t addr, size_t size) 229 + static void __iomem *__ioremap(phys_addr_t addr, size_t size, pgprot_t prot) 231 230 { 232 231 unsigned long offset, vaddr; 233 232 struct vm_struct *area; ··· 248 247 return NULL; 249 248 250 249 vaddr = (unsigned long) area->addr; 251 - if (ioremap_page_range(vaddr, vaddr + size, addr, PAGE_KERNEL)) { 250 + if (ioremap_page_range(vaddr, vaddr + size, addr, prot)) { 252 251 free_vm_area(area); 253 252 return NULL; 254 253 } 255 254 return (void __iomem *) ((unsigned long) area->addr + offset); 256 255 } 256 + 257 + void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) 258 + { 259 + return __ioremap(addr, size, __pgprot(prot)); 260 + } 261 + EXPORT_SYMBOL(ioremap_prot); 262 + 263 + void __iomem *ioremap(phys_addr_t addr, size_t size) 264 + { 265 + return __ioremap(addr, size, PAGE_KERNEL); 266 + } 257 267 EXPORT_SYMBOL(ioremap); 268 + 269 + void __iomem *ioremap_wc(phys_addr_t addr, size_t size) 270 + { 271 + return __ioremap(addr, size, pgprot_writecombine(PAGE_KERNEL)); 272 + } 273 + EXPORT_SYMBOL(ioremap_wc); 274 + 275 + void __iomem *ioremap_wt(phys_addr_t addr, size_t size) 276 + { 277 + return __ioremap(addr, size, pgprot_writethrough(PAGE_KERNEL)); 278 + } 279 + EXPORT_SYMBOL(ioremap_wt); 258 280 259 281 void iounmap(volatile void __iomem *addr) 260 282 { ··· 414 390 .write = pci_write, 415 391 }; 416 392 417 - #ifdef CONFIG_PCI_IOV 418 - static struct resource iov_res = { 419 - .name = "PCI IOV res", 420 - .start = 0, 421 - .end = -1, 422 - .flags = IORESOURCE_MEM, 423 - }; 424 - #endif 425 - 426 393 static void zpci_map_resources(struct pci_dev *pdev) 427 394 { 428 395 struct zpci_dev *zdev = to_zpci(pdev); ··· 434 419 pdev->resource[i].end = pdev->resource[i].start + len - 1; 435 420 } 436 421 437 - #ifdef CONFIG_PCI_IOV 438 - for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { 439 - int bar = i + PCI_IOV_RESOURCES; 440 - 441 - len = pci_resource_len(pdev, bar); 442 - if (!len) 443 - continue; 444 - pdev->resource[bar].parent = &iov_res; 445 - } 446 - #endif 422 + zpci_iov_map_resources(pdev); 447 423 } 448 424 449 425 static void zpci_unmap_resources(struct pci_dev *pdev) ··· 690 684 pdev = pci_get_slot(zbus->bus, zdev->devfn); 691 685 if (pdev) { 692 686 if (pdev->is_virtfn) 693 - return zpci_remove_virtfn(pdev, zdev->vfn); 687 + return zpci_iov_remove_virtfn(pdev, zdev->vfn); 694 688 pci_stop_and_remove_bus_device_locked(pdev); 695 689 } 696 690 } ··· 794 788 if (!zpci_iomap_bitmap) 795 789 goto error_iomap_bitmap; 796 790 791 + if (static_branch_likely(&have_mio)) 792 + clp_setup_writeback_mio(); 793 + 797 794 return 0; 798 795 error_iomap_bitmap: 799 796 kfree(zpci_iomap_start); ··· 894 885 return rc; 895 886 } 896 887 subsys_initcall_sync(pci_base_init); 897 - 898 - void zpci_rescan(void) 899 - { 900 - if (zpci_is_enabled()) 901 - clp_rescan_pci_devices_simple(NULL); 902 - }
+2 -64
arch/s390/pci/pci_bus.c
··· 24 24 #include <asm/pci_dma.h> 25 25 26 26 #include "pci_bus.h" 27 + #include "pci_iov.h" 27 28 28 29 static LIST_HEAD(zbus_list); 29 30 static DEFINE_SPINLOCK(zbus_list_lock); ··· 127 126 return zbus; 128 127 } 129 128 130 - #ifdef CONFIG_PCI_IOV 131 - static int zpci_bus_link_virtfn(struct pci_dev *pdev, 132 - struct pci_dev *virtfn, int vfid) 133 - { 134 - int rc; 135 - 136 - rc = pci_iov_sysfs_link(pdev, virtfn, vfid); 137 - if (rc) 138 - return rc; 139 - 140 - virtfn->is_virtfn = 1; 141 - virtfn->multifunction = 0; 142 - virtfn->physfn = pci_dev_get(pdev); 143 - 144 - return 0; 145 - } 146 - 147 - static int zpci_bus_setup_virtfn(struct zpci_bus *zbus, 148 - struct pci_dev *virtfn, int vfn) 149 - { 150 - int i, cand_devfn; 151 - struct zpci_dev *zdev; 152 - struct pci_dev *pdev; 153 - int vfid = vfn - 1; /* Linux' vfid's start at 0 vfn at 1*/ 154 - int rc = 0; 155 - 156 - if (!zbus->multifunction) 157 - return 0; 158 - 159 - /* If the parent PF for the given VF is also configured in the 160 - * instance, it must be on the same zbus. 161 - * We can then identify the parent PF by checking what 162 - * devfn the VF would have if it belonged to that PF using the PF's 163 - * stride and offset. Only if this candidate devfn matches the 164 - * actual devfn will we link both functions. 165 - */ 166 - for (i = 0; i < ZPCI_FUNCTIONS_PER_BUS; i++) { 167 - zdev = zbus->function[i]; 168 - if (zdev && zdev->is_physfn) { 169 - pdev = pci_get_slot(zbus->bus, zdev->devfn); 170 - if (!pdev) 171 - continue; 172 - cand_devfn = pci_iov_virtfn_devfn(pdev, vfid); 173 - if (cand_devfn == virtfn->devfn) { 174 - rc = zpci_bus_link_virtfn(pdev, virtfn, vfid); 175 - /* balance pci_get_slot() */ 176 - pci_dev_put(pdev); 177 - break; 178 - } 179 - /* balance pci_get_slot() */ 180 - pci_dev_put(pdev); 181 - } 182 - } 183 - return rc; 184 - } 185 - #else 186 - static inline int zpci_bus_setup_virtfn(struct zpci_bus *zbus, 187 - struct pci_dev *virtfn, int vfn) 188 - { 189 - return 0; 190 - } 191 - #endif 192 - 193 129 void pcibios_bus_add_device(struct pci_dev *pdev) 194 130 { 195 131 struct zpci_dev *zdev = to_zpci(pdev); ··· 136 198 * perform PF/VF linking. 137 199 */ 138 200 if (zdev->vfn) 139 - zpci_bus_setup_virtfn(zdev->zbus, pdev, zdev->vfn); 201 + zpci_iov_setup_virtfn(zdev->zbus, pdev, zdev->vfn); 140 202 141 203 } 142 204
-13
arch/s390/pci/pci_bus.h
··· 9 9 10 10 int zpci_bus_device_register(struct zpci_dev *zdev, struct pci_ops *ops); 11 11 void zpci_bus_device_unregister(struct zpci_dev *zdev); 12 - int zpci_bus_init(void); 13 12 14 13 void zpci_release_device(struct kref *kref); 15 14 static inline void zpci_zdev_put(struct zpci_dev *zdev) ··· 29 30 return (devfn >= ZPCI_FUNCTIONS_PER_BUS) ? NULL : zbus->function[devfn]; 30 31 } 31 32 32 - #ifdef CONFIG_PCI_IOV 33 - static inline void zpci_remove_virtfn(struct pci_dev *pdev, int vfn) 34 - { 35 - 36 - pci_lock_rescan_remove(); 37 - /* Linux' vfid's start at 0 vfn at 1 */ 38 - pci_iov_remove_virtfn(pdev->physfn, vfn - 1); 39 - pci_unlock_rescan_remove(); 40 - } 41 - #else /* CONFIG_PCI_IOV */ 42 - static inline void zpci_remove_virtfn(struct pci_dev *pdev, int vfn) {} 43 - #endif /* CONFIG_PCI_IOV */
+50 -35
arch/s390/pci/pci_clp.c
··· 244 244 return rc; 245 245 } 246 246 247 + static int clp_refresh_fh(u32 fid); 247 248 /* 248 249 * Enable/Disable a given PCI function and update its function handle if 249 250 * necessary ··· 287 286 } else if (!rc && rrb->response.hdr.rsp == CLP_RC_SETPCIFN_ALRDY && 288 287 rrb->response.fh == 0) { 289 288 /* Function is already in desired state - update handle */ 290 - rc = clp_rescan_pci_devices_simple(&fid); 289 + rc = clp_refresh_fh(fid); 290 + } 291 + clp_free_block(rrb); 292 + return rc; 293 + } 294 + 295 + int clp_setup_writeback_mio(void) 296 + { 297 + struct clp_req_rsp_slpc_pci *rrb; 298 + u8 wb_bit_pos; 299 + int rc; 300 + 301 + rrb = clp_alloc_block(GFP_KERNEL); 302 + if (!rrb) 303 + return -ENOMEM; 304 + 305 + memset(rrb, 0, sizeof(*rrb)); 306 + rrb->request.hdr.len = sizeof(rrb->request); 307 + rrb->request.hdr.cmd = CLP_SLPC; 308 + rrb->response.hdr.len = sizeof(rrb->response); 309 + 310 + rc = clp_req(rrb, CLP_LPS_PCI); 311 + if (!rc && rrb->response.hdr.rsp == CLP_RC_OK) { 312 + if (rrb->response.vwb) { 313 + wb_bit_pos = rrb->response.mio_wb; 314 + set_bit_inv(wb_bit_pos, &mio_wb_bit_mask); 315 + zpci_dbg(3, "wb bit: %d\n", wb_bit_pos); 316 + } else { 317 + zpci_dbg(3, "wb bit: n.a.\n"); 318 + } 319 + 320 + } else { 321 + zpci_err("SLPC PCI:\n"); 322 + zpci_err_clp(rrb->response.hdr.rsp, rc); 323 + rc = -EIO; 291 324 } 292 325 clp_free_block(rrb); 293 326 return rc; ··· 409 374 clp_add_pci_device(entry->fid, entry->fh, entry->config_state); 410 375 } 411 376 412 - static void __clp_update(struct clp_fh_list_entry *entry, void *data) 413 - { 414 - struct zpci_dev *zdev; 415 - u32 *fid = data; 416 - 417 - if (!entry->vendor_id) 418 - return; 419 - 420 - if (fid && *fid != entry->fid) 421 - return; 422 - 423 - zdev = get_zdev_by_fid(entry->fid); 424 - if (!zdev) 425 - return; 426 - 427 - zdev->fh = entry->fh; 428 - } 429 - 430 377 int clp_scan_pci_devices(void) 431 378 { 432 379 struct clp_req_rsp_list_pci *rrb; ··· 424 407 return rc; 425 408 } 426 409 427 - int clp_rescan_pci_devices(void) 410 + static void __clp_refresh_fh(struct clp_fh_list_entry *entry, void *data) 428 411 { 429 - struct clp_req_rsp_list_pci *rrb; 430 - int rc; 412 + struct zpci_dev *zdev; 413 + u32 fid = *((u32 *)data); 431 414 432 - zpci_remove_reserved_devices(); 415 + if (!entry->vendor_id || fid != entry->fid) 416 + return; 433 417 434 - rrb = clp_alloc_block(GFP_KERNEL); 435 - if (!rrb) 436 - return -ENOMEM; 418 + zdev = get_zdev_by_fid(fid); 419 + if (!zdev) 420 + return; 437 421 438 - rc = clp_list_pci(rrb, NULL, __clp_add); 439 - 440 - clp_free_block(rrb); 441 - return rc; 422 + zdev->fh = entry->fh; 442 423 } 443 424 444 - /* Rescan PCI functions and refresh function handles. If fid is non-NULL only 445 - * refresh the handle of the function matching @fid 425 + /* 426 + * Refresh the function handle of the function matching @fid 446 427 */ 447 - int clp_rescan_pci_devices_simple(u32 *fid) 428 + static int clp_refresh_fh(u32 fid) 448 429 { 449 430 struct clp_req_rsp_list_pci *rrb; 450 431 int rc; ··· 451 436 if (!rrb) 452 437 return -ENOMEM; 453 438 454 - rc = clp_list_pci(rrb, fid, __clp_update); 439 + rc = clp_list_pci(rrb, &fid, __clp_refresh_fh); 455 440 456 441 clp_free_block(rrb); 457 442 return rc; ··· 510 495 } 511 496 } 512 497 513 - static int clp_pci_slpc(struct clp_req *req, struct clp_req_rsp_slpc *lpcb) 498 + static int clp_pci_slpc(struct clp_req *req, struct clp_req_rsp_slpc_pci *lpcb) 514 499 { 515 500 unsigned long limit = PAGE_SIZE - sizeof(lpcb->request); 516 501
+2 -1
arch/s390/pci/pci_event.c
··· 152 152 } 153 153 break; 154 154 case 0x0306: /* 0x308 or 0x302 for multiple devices */ 155 - clp_rescan_pci_devices(); 155 + zpci_remove_reserved_devices(); 156 + clp_scan_pci_devices(); 156 157 break; 157 158 case 0x0308: /* Standby -> Reserved */ 158 159 if (!zdev)
+99
arch/s390/pci/pci_iov.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright IBM Corp. 2020 4 + * 5 + * Author(s): 6 + * Niklas Schnelle <schnelle@linux.ibm.com> 7 + * 8 + */ 9 + 10 + #define KMSG_COMPONENT "zpci" 11 + #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 12 + 13 + #include <linux/kernel.h> 14 + #include <linux/pci.h> 15 + 16 + #include "pci_iov.h" 17 + 18 + static struct resource iov_res = { 19 + .name = "PCI IOV res", 20 + .start = 0, 21 + .end = -1, 22 + .flags = IORESOURCE_MEM, 23 + }; 24 + 25 + void zpci_iov_map_resources(struct pci_dev *pdev) 26 + { 27 + resource_size_t len; 28 + int i; 29 + 30 + for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { 31 + int bar = i + PCI_IOV_RESOURCES; 32 + 33 + len = pci_resource_len(pdev, bar); 34 + if (!len) 35 + continue; 36 + pdev->resource[bar].parent = &iov_res; 37 + } 38 + } 39 + 40 + void zpci_iov_remove_virtfn(struct pci_dev *pdev, int vfn) 41 + { 42 + pci_lock_rescan_remove(); 43 + /* Linux' vfid's start at 0 vfn at 1 */ 44 + pci_iov_remove_virtfn(pdev->physfn, vfn - 1); 45 + pci_unlock_rescan_remove(); 46 + } 47 + 48 + static int zpci_iov_link_virtfn(struct pci_dev *pdev, struct pci_dev *virtfn, int vfid) 49 + { 50 + int rc; 51 + 52 + rc = pci_iov_sysfs_link(pdev, virtfn, vfid); 53 + if (rc) 54 + return rc; 55 + 56 + virtfn->is_virtfn = 1; 57 + virtfn->multifunction = 0; 58 + virtfn->physfn = pci_dev_get(pdev); 59 + 60 + return 0; 61 + } 62 + 63 + int zpci_iov_setup_virtfn(struct zpci_bus *zbus, struct pci_dev *virtfn, int vfn) 64 + { 65 + int i, cand_devfn; 66 + struct zpci_dev *zdev; 67 + struct pci_dev *pdev; 68 + int vfid = vfn - 1; /* Linux' vfid's start at 0 vfn at 1*/ 69 + int rc = 0; 70 + 71 + if (!zbus->multifunction) 72 + return 0; 73 + 74 + /* If the parent PF for the given VF is also configured in the 75 + * instance, it must be on the same zbus. 76 + * We can then identify the parent PF by checking what 77 + * devfn the VF would have if it belonged to that PF using the PF's 78 + * stride and offset. Only if this candidate devfn matches the 79 + * actual devfn will we link both functions. 80 + */ 81 + for (i = 0; i < ZPCI_FUNCTIONS_PER_BUS; i++) { 82 + zdev = zbus->function[i]; 83 + if (zdev && zdev->is_physfn) { 84 + pdev = pci_get_slot(zbus->bus, zdev->devfn); 85 + if (!pdev) 86 + continue; 87 + cand_devfn = pci_iov_virtfn_devfn(pdev, vfid); 88 + if (cand_devfn == virtfn->devfn) { 89 + rc = zpci_iov_link_virtfn(pdev, virtfn, vfid); 90 + /* balance pci_get_slot() */ 91 + pci_dev_put(pdev); 92 + break; 93 + } 94 + /* balance pci_get_slot() */ 95 + pci_dev_put(pdev); 96 + } 97 + } 98 + return rc; 99 + }
+30
arch/s390/pci/pci_iov.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright IBM Corp. 2020 4 + * 5 + * Author(s): 6 + * Niklas Schnelle <schnelle@linux.ibm.com> 7 + * 8 + */ 9 + 10 + #ifndef __S390_PCI_IOV_H 11 + #define __S390_PCI_IOV_H 12 + 13 + #ifdef CONFIG_PCI_IOV 14 + void zpci_iov_remove_virtfn(struct pci_dev *pdev, int vfn); 15 + 16 + void zpci_iov_map_resources(struct pci_dev *pdev); 17 + 18 + int zpci_iov_setup_virtfn(struct zpci_bus *zbus, struct pci_dev *virtfn, int vfn); 19 + 20 + #else /* CONFIG_PCI_IOV */ 21 + static inline void zpci_iov_remove_virtfn(struct pci_dev *pdev, int vfn) {} 22 + 23 + static inline void zpci_iov_map_resources(struct pci_dev *pdev) {} 24 + 25 + static inline int zpci_iov_setup_virtfn(struct zpci_bus *zbus, struct pci_dev *virtfn, int vfn) 26 + { 27 + return 0; 28 + } 29 + #endif /* CONFIG_PCI_IOV */ 30 + #endif /* __S390_PCI_IOV_h */
-20
arch/s390/scripts/Makefile.chkbss
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - 3 - chkbss-target ?= built-in.a 4 - $(obj)/$(chkbss-target): chkbss 5 - 6 - chkbss-files := $(addsuffix .chkbss, $(chkbss)) 7 - clean-files += $(chkbss-files) 8 - 9 - PHONY += chkbss 10 - chkbss: $(addprefix $(obj)/, $(chkbss-files)) 11 - 12 - quiet_cmd_chkbss = CHKBSS $< 13 - cmd_chkbss = \ 14 - if ! $(OBJSIZE) --common $< | $(AWK) 'END { if ($$3) exit 1 }'; then \ 15 - echo "error: $< .bss section is not empty" >&2; exit 1; \ 16 - fi; \ 17 - touch $@; 18 - 19 - $(obj)/%.o.chkbss: $(obj)/%.o 20 - $(call cmd,chkbss)
+20 -4
drivers/crypto/Kconfig
··· 71 71 help 72 72 Select this option if you want to enable support for 73 73 s390 cryptographic adapters like: 74 - + PCI-X Cryptographic Coprocessor (PCIXCC) 75 - + Crypto Express 2,3,4 or 5 Coprocessor (CEXxC) 76 - + Crypto Express 2,3,4 or 5 Accelerator (CEXxA) 77 - + Crypto Express 4 or 5 EP11 Coprocessor (CEXxP) 74 + + Crypto Express 2 up to 7 Coprocessor (CEXxC) 75 + + Crypto Express 2 up to 7 Accelerator (CEXxA) 76 + + Crypto Express 4 up to 7 EP11 Coprocessor (CEXxP) 77 + 78 + config ZCRYPT_DEBUG 79 + bool "Enable debug features for s390 cryptographic adapters" 80 + default n 81 + depends on DEBUG_KERNEL 82 + depends on ZCRYPT 83 + help 84 + Say 'Y' here to enable some additional debug features on the 85 + s390 cryptographic adapters driver. 86 + 87 + There will be some more sysfs attributes displayed for ap cards 88 + and queues and some flags on crypto requests are interpreted as 89 + debugging messages to force error injection. 90 + 91 + Do not enable on production level kernel build. 92 + 93 + If unsure, say N. 78 94 79 95 config ZCRYPT_MULTIDEVNODES 80 96 bool "Support for multiple zcrypt device nodes"
+2
drivers/s390/char/Makefile
··· 34 34 35 35 obj-$(CONFIG_PCI) += sclp_pci.o 36 36 37 + obj-$(subst m,y,$(CONFIG_ZCRYPT)) += sclp_ap.o 38 + 37 39 obj-$(CONFIG_VMLOGRDR) += vmlogrdr.o 38 40 obj-$(CONFIG_VMCP) += vmcp.o 39 41
+1 -6
drivers/s390/char/con3215.c
··· 978 978 static int tty3215_open(struct tty_struct *tty, struct file * filp) 979 979 { 980 980 struct raw3215_info *raw = tty->driver_data; 981 - int retval; 982 981 983 982 tty_port_tty_set(&raw->port, tty); 984 983 ··· 985 986 /* 986 987 * Start up 3215 device 987 988 */ 988 - retval = raw3215_startup(raw); 989 - if (retval) 990 - return retval; 991 - 992 - return 0; 989 + return raw3215_startup(raw); 993 990 } 994 991 995 992 /*
-1
drivers/s390/char/raw3270.h
··· 110 110 }; 111 111 112 112 struct raw3270_request *raw3270_request_alloc(size_t size); 113 - struct raw3270_request *raw3270_request_alloc_bootmem(size_t size); 114 113 void raw3270_request_free(struct raw3270_request *); 115 114 void raw3270_request_reset(struct raw3270_request *); 116 115 void raw3270_request_set_cmd(struct raw3270_request *, u8 cmd);
+1 -3
drivers/s390/char/sclp.h
··· 229 229 #define SCLP_HAS_CPU_INFO (sclp.facilities & 0x0800000000000000ULL) 230 230 #define SCLP_HAS_CPU_RECONFIG (sclp.facilities & 0x0400000000000000ULL) 231 231 #define SCLP_HAS_PCI_RECONFIG (sclp.facilities & 0x0000000040000000ULL) 232 - 232 + #define SCLP_HAS_AP_RECONFIG (sclp.facilities & 0x0000000100000000ULL) 233 233 234 234 struct gds_subvector { 235 235 u8 length; ··· 305 305 int sclp_reactivate(void); 306 306 int sclp_sync_request(sclp_cmdw_t command, void *sccb); 307 307 int sclp_sync_request_timeout(sclp_cmdw_t command, void *sccb, int timeout); 308 - 309 308 int sclp_sdias_init(void); 310 - void sclp_sdias_exit(void); 311 309 312 310 enum { 313 311 sclp_init_state_uninitialized,
+63
drivers/s390/char/sclp_ap.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * s390 crypto adapter related sclp functions. 4 + * 5 + * Copyright IBM Corp. 2020 6 + */ 7 + #define KMSG_COMPONENT "sclp_cmd" 8 + #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 9 + 10 + #include <linux/export.h> 11 + #include <linux/slab.h> 12 + #include <asm/sclp.h> 13 + #include "sclp.h" 14 + 15 + #define SCLP_CMDW_CONFIGURE_AP 0x001f0001 16 + #define SCLP_CMDW_DECONFIGURE_AP 0x001e0001 17 + 18 + struct ap_cfg_sccb { 19 + struct sccb_header header; 20 + } __packed; 21 + 22 + static int do_ap_configure(sclp_cmdw_t cmd, u32 apid) 23 + { 24 + struct ap_cfg_sccb *sccb; 25 + int rc; 26 + 27 + if (!SCLP_HAS_AP_RECONFIG) 28 + return -EOPNOTSUPP; 29 + 30 + sccb = (struct ap_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA); 31 + if (!sccb) 32 + return -ENOMEM; 33 + 34 + sccb->header.length = PAGE_SIZE; 35 + cmd |= (apid & 0xFF) << 8; 36 + rc = sclp_sync_request(cmd, sccb); 37 + if (rc) 38 + goto out; 39 + switch (sccb->header.response_code) { 40 + case 0x0020: case 0x0120: case 0x0440: case 0x0450: 41 + break; 42 + default: 43 + pr_warn("configure AP adapter %u failed: cmd=0x%08x response=0x%04x\n", 44 + apid, cmd, sccb->header.response_code); 45 + rc = -EIO; 46 + break; 47 + } 48 + out: 49 + free_page((unsigned long) sccb); 50 + return rc; 51 + } 52 + 53 + int sclp_ap_configure(u32 apid) 54 + { 55 + return do_ap_configure(SCLP_CMDW_CONFIGURE_AP, apid); 56 + } 57 + EXPORT_SYMBOL(sclp_ap_configure); 58 + 59 + int sclp_ap_deconfigure(u32 apid) 60 + { 61 + return do_ap_configure(SCLP_CMDW_DECONFIGURE_AP, apid); 62 + } 63 + EXPORT_SYMBOL(sclp_ap_deconfigure);
+5 -10
drivers/s390/char/sclp_early_core.c
··· 17 17 static struct read_info_sccb __bootdata(sclp_info_sccb); 18 18 static int __bootdata(sclp_info_sccb_valid); 19 19 char *sclp_early_sccb = (char *) EARLY_SCCB_OFFSET; 20 - int sclp_init_state __section(.data) = sclp_init_state_uninitialized; 20 + int sclp_init_state = sclp_init_state_uninitialized; 21 21 /* 22 22 * Used to keep track of the size of the event masks. Qemu until version 2.11 23 23 * only supports 4 and needs a workaround. 24 24 */ 25 - bool sclp_mask_compat_mode __section(.data); 25 + bool sclp_mask_compat_mode; 26 26 27 27 void sclp_early_wait_irq(void) 28 28 { ··· 214 214 * Output one or more lines of text on the SCLP console (VT220 and / 215 215 * or line-mode). 216 216 */ 217 - void __sclp_early_printk(const char *str, unsigned int len, unsigned int force) 217 + void __sclp_early_printk(const char *str, unsigned int len) 218 218 { 219 219 int have_linemode, have_vt220; 220 220 221 - if (!force && sclp_init_state != sclp_init_state_uninitialized) 221 + if (sclp_init_state != sclp_init_state_uninitialized) 222 222 return; 223 223 if (sclp_early_setup(0, &have_linemode, &have_vt220) != 0) 224 224 return; ··· 231 231 232 232 void sclp_early_printk(const char *str) 233 233 { 234 - __sclp_early_printk(str, strlen(str), 0); 235 - } 236 - 237 - void sclp_early_printk_force(const char *str) 238 - { 239 - __sclp_early_printk(str, strlen(str), 1); 234 + __sclp_early_printk(str, strlen(str)); 240 235 } 241 236 242 237 int __init sclp_early_read_info(void)
-18
drivers/s390/char/sclp_rw.c
··· 337 337 } 338 338 339 339 /* 340 - * sets or provides some values that influence the drivers behaviour 341 - */ 342 - void 343 - sclp_set_columns(struct sclp_buffer *buffer, unsigned short columns) 344 - { 345 - buffer->columns = columns; 346 - if (buffer->current_line != NULL && 347 - buffer->current_length > buffer->columns) 348 - sclp_finalize_mto(buffer); 349 - } 350 - 351 - void 352 - sclp_set_htab(struct sclp_buffer *buffer, unsigned short htab) 353 - { 354 - buffer->htab = htab; 355 - } 356 - 357 - /* 358 340 * called by sclp_console_init and/or sclp_tty_init 359 341 */ 360 342 int
-2
drivers/s390/char/sclp_rw.h
··· 86 86 int sclp_buffer_space(struct sclp_buffer *); 87 87 int sclp_write(struct sclp_buffer *buffer, const unsigned char *, int); 88 88 int sclp_emit_buffer(struct sclp_buffer *,void (*)(struct sclp_buffer *,int)); 89 - void sclp_set_columns(struct sclp_buffer *, unsigned short); 90 - void sclp_set_htab(struct sclp_buffer *, unsigned short); 91 89 int sclp_chars_in_buffer(struct sclp_buffer *); 92 90 93 91 #ifdef CONFIG_SCLP_CONSOLE
+1 -7
drivers/s390/char/sclp_sdias.c
··· 257 257 258 258 int __init sclp_sdias_init(void) 259 259 { 260 - if (ipl_info.type != IPL_TYPE_FCP_DUMP) 260 + if (!is_ipl_type_dump()) 261 261 return 0; 262 262 sclp_sdias_sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA); 263 263 BUG_ON(!sclp_sdias_sccb); ··· 274 274 out: 275 275 TRACE("init done\n"); 276 276 return 0; 277 - } 278 - 279 - void __exit sclp_sdias_exit(void) 280 - { 281 - debug_unregister(sdias_dbf); 282 - sclp_unregister(&sclp_sdias_register); 283 277 }
-3
drivers/s390/char/tape.h
··· 238 238 extern int tape_do_io_async(struct tape_device *, struct tape_request *); 239 239 extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *); 240 240 extern int tape_cancel_io(struct tape_device *, struct tape_request *); 241 - void tape_hotplug_event(struct tape_device *, int major, int action); 242 241 243 242 static inline int 244 243 tape_do_io_free(struct tape_device *device, struct tape_request *request) ··· 257 258 tape_do_io_async(device, request); 258 259 } 259 260 260 - extern int tape_oper_handler(int irq, int status); 261 - extern void tape_noper_handler(int irq, int status); 262 261 extern int tape_open(struct tape_device *); 263 262 extern int tape_release(struct tape_device *); 264 263 extern int tape_mtop(struct tape_device *, int, int);
-12
drivers/s390/char/tape_std.h
··· 101 101 void tape_std_read_backward(struct tape_device *device, 102 102 struct tape_request *request); 103 103 struct tape_request *tape_std_write_block(struct tape_device *, size_t); 104 - void tape_std_check_locate(struct tape_device *, struct tape_request *); 105 104 106 105 /* Some non-mtop commands. */ 107 106 int tape_std_assign(struct tape_device *); ··· 130 131 int tape_std_mtweof(struct tape_device *, int); 131 132 132 133 /* Event handlers */ 133 - void tape_std_default_handler(struct tape_device *); 134 - void tape_std_unexpect_uchk_handler(struct tape_device *); 135 - void tape_std_irq(struct tape_device *); 136 134 void tape_std_process_eov(struct tape_device *); 137 - 138 - // the error recovery stuff: 139 - void tape_std_error_recovery(struct tape_device *); 140 - void tape_std_error_recovery_has_failed(struct tape_device *,int error_id); 141 - void tape_std_error_recovery_succeded(struct tape_device *); 142 - void tape_std_error_recovery_do_retry(struct tape_device *); 143 - void tape_std_error_recovery_read_opposite(struct tape_device *); 144 - void tape_std_error_recovery_HWBUG(struct tape_device *, int condno); 145 135 146 136 /* S390 tape types */ 147 137 enum s390_tape_type {
+12 -5
drivers/s390/char/zcore.c
··· 1 1 // SPDX-License-Identifier: GPL-1.0+ 2 2 /* 3 3 * zcore module to export memory content and register sets for creating system 4 - * dumps on SCSI disks (zfcpdump). 4 + * dumps on SCSI/NVMe disks (zfcp/nvme dump). 5 5 * 6 6 * For more information please refer to Documentation/s390/zfcpdump.rst 7 7 * ··· 243 243 unsigned char arch; 244 244 int rc; 245 245 246 - if (ipl_info.type != IPL_TYPE_FCP_DUMP) 246 + if (!is_ipl_type_dump()) 247 247 return -ENODATA; 248 248 if (OLDMEM_BASE) 249 249 return -ENODATA; ··· 252 252 debug_register_view(zcore_dbf, &debug_sprintf_view); 253 253 debug_set_level(zcore_dbf, 6); 254 254 255 - TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno); 256 - TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn); 257 - TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun); 255 + if (ipl_info.type == IPL_TYPE_FCP_DUMP) { 256 + TRACE("type: fcp\n"); 257 + TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno); 258 + TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn); 259 + TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun); 260 + } else if (ipl_info.type == IPL_TYPE_NVME_DUMP) { 261 + TRACE("type: nvme\n"); 262 + TRACE("fid: %x\n", ipl_info.data.nvme.fid); 263 + TRACE("nsid: %x\n", ipl_info.data.nvme.nsid); 264 + } 258 265 259 266 rc = sclp_sdias_init(); 260 267 if (rc)
+21
drivers/s390/cio/chsc.c
··· 1265 1265 return (rr->response.code == 0x0001) ? 0 : -EIO; 1266 1266 } 1267 1267 1268 + int chsc_stzi(void *page, void *result, size_t size) 1269 + { 1270 + struct { 1271 + struct chsc_header request; 1272 + unsigned int rsvd0[3]; 1273 + struct chsc_header response; 1274 + char data[]; 1275 + } *rr; 1276 + int rc; 1277 + 1278 + memset(page, 0, PAGE_SIZE); 1279 + rr = page; 1280 + rr->request.length = 0x0010; 1281 + rr->request.code = 0x003e; 1282 + rc = chsc(rr); 1283 + if (rc) 1284 + return -EIO; 1285 + memcpy(result, &rr->data, size); 1286 + return (rr->response.code == 0x0001) ? 0 : -EIO; 1287 + } 1288 + 1268 1289 int chsc_siosl(struct subchannel_id schid) 1269 1290 { 1270 1291 struct {
-14
drivers/s390/cio/css.c
··· 1355 1355 } 1356 1356 subsys_initcall_sync(channel_subsystem_init_sync); 1357 1357 1358 - void channel_subsystem_reinit(void) 1359 - { 1360 - struct channel_path *chp; 1361 - struct chp_id chpid; 1362 - 1363 - chsc_enable_facility(CHSC_SDA_OC_MSS); 1364 - chp_id_for_each(&chpid) { 1365 - chp = chpid_to_chp(chpid); 1366 - if (chp) 1367 - chp_update_desc(chp); 1368 - } 1369 - cmf_reactivate(); 1370 - } 1371 - 1372 1358 #ifdef CONFIG_PROC_FS 1373 1359 static ssize_t cio_settle_write(struct file *file, const char __user *buf, 1374 1360 size_t count, loff_t *ppos)
-1
drivers/s390/cio/device.h
··· 96 96 int ccw_device_offline(struct ccw_device *); 97 97 void ccw_device_update_sense_data(struct ccw_device *); 98 98 int ccw_device_test_sense_data(struct ccw_device *); 99 - void ccw_device_schedule_sch_unregister(struct ccw_device *); 100 99 int ccw_purge_blacklisted(void); 101 100 void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo); 102 101 struct ccw_device *get_ccwdev_by_dev_id(struct ccw_dev_id *dev_id);
+20 -23
drivers/s390/cio/qdio_main.c
··· 531 531 return 1; 532 532 } 533 533 534 - static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count) 535 - { 536 - unsigned char state = 0; 537 - int j, b = start; 538 - 539 - for (j = 0; j < count; ++j) { 540 - get_buf_state(q, b, &state, 0); 541 - if (state == SLSB_P_OUTPUT_PENDING) { 542 - struct qaob *aob = q->u.out.aobs[b]; 543 - if (aob == NULL) 544 - continue; 545 - 546 - q->u.out.sbal_state[b].flags |= 547 - QDIO_OUTBUF_STATE_FLAG_PENDING; 548 - q->u.out.aobs[b] = NULL; 549 - } 550 - b = next_buf(b); 551 - } 552 - } 553 - 554 534 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q, 555 535 int bufnr) 556 536 { ··· 620 640 __qdio_inbound_processing(q); 621 641 } 622 642 643 + static void qdio_check_pending(struct qdio_q *q, unsigned int index) 644 + { 645 + unsigned char state; 646 + 647 + if (get_buf_state(q, index, &state, 0) > 0 && 648 + state == SLSB_P_OUTPUT_PENDING && 649 + q->u.out.aobs[index]) { 650 + q->u.out.sbal_state[index].flags |= 651 + QDIO_OUTBUF_STATE_FLAG_PENDING; 652 + q->u.out.aobs[index] = NULL; 653 + } 654 + } 655 + 623 656 static int get_outbound_buffer_frontier(struct qdio_q *q, unsigned int start) 624 657 { 625 658 unsigned char state = 0; ··· 705 712 706 713 if (count) { 707 714 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr); 708 - if (q->u.out.use_cq) 709 - qdio_handle_aobs(q, start, count); 715 + 716 + if (q->u.out.use_cq) { 717 + unsigned int i; 718 + 719 + for (i = 0; i < count; i++) 720 + qdio_check_pending(q, QDIO_BUFNR(start + i)); 721 + } 710 722 } 711 723 712 724 return count; ··· 1219 1221 struct qdio_initialize *data) 1220 1222 { 1221 1223 DBF_DEV_EVENT(DBF_ERR, irq, "qfmt:%1u", data->q_format); 1222 - DBF_DEV_HEX(irq, data->adapter_name, 8, DBF_ERR); 1223 1224 DBF_DEV_EVENT(DBF_ERR, irq, "qpff%4x", data->qib_param_field_format); 1224 1225 DBF_DEV_HEX(irq, &data->qib_param_field, sizeof(void *), DBF_ERR); 1225 1226 DBF_DEV_HEX(irq, &data->input_slib_elements, sizeof(void *), DBF_ERR);
+16 -20
drivers/s390/cio/qdio_setup.c
··· 9 9 #include <linux/slab.h> 10 10 #include <linux/export.h> 11 11 #include <linux/io.h> 12 + 13 + #include <asm/ebcdic.h> 12 14 #include <asm/qdio.h> 13 15 14 16 #include "cio.h" ··· 405 403 } 406 404 } 407 405 408 - static void __qdio_allocate_fill_qdr(struct qdio_irq *irq_ptr, 409 - struct qdio_q **irq_ptr_qs, 410 - int i, int nr) 406 + static void qdio_fill_qdr_desc(struct qdesfmt0 *desc, struct qdio_q *queue) 411 407 { 412 - irq_ptr->qdr->qdf0[i + nr].sliba = 413 - (unsigned long)irq_ptr_qs[i]->slib; 408 + desc->sliba = virt_to_phys(queue->slib); 409 + desc->sla = virt_to_phys(queue->sl); 410 + desc->slsba = virt_to_phys(&queue->slsb); 414 411 415 - irq_ptr->qdr->qdf0[i + nr].sla = 416 - (unsigned long)irq_ptr_qs[i]->sl; 417 - 418 - irq_ptr->qdr->qdf0[i + nr].slsba = 419 - (unsigned long)&irq_ptr_qs[i]->slsb.val[0]; 420 - 421 - irq_ptr->qdr->qdf0[i + nr].akey = PAGE_DEFAULT_KEY >> 4; 422 - irq_ptr->qdr->qdf0[i + nr].bkey = PAGE_DEFAULT_KEY >> 4; 423 - irq_ptr->qdr->qdf0[i + nr].ckey = PAGE_DEFAULT_KEY >> 4; 424 - irq_ptr->qdr->qdf0[i + nr].dkey = PAGE_DEFAULT_KEY >> 4; 412 + desc->akey = PAGE_DEFAULT_KEY >> 4; 413 + desc->bkey = PAGE_DEFAULT_KEY >> 4; 414 + desc->ckey = PAGE_DEFAULT_KEY >> 4; 415 + desc->dkey = PAGE_DEFAULT_KEY >> 4; 425 416 } 426 417 427 418 static void setup_qdr(struct qdio_irq *irq_ptr, 428 419 struct qdio_initialize *qdio_init) 429 420 { 421 + struct qdesfmt0 *desc = &irq_ptr->qdr->qdf0[0]; 430 422 int i; 431 423 432 424 irq_ptr->qdr->qfmt = qdio_init->q_format; ··· 429 433 irq_ptr->qdr->oqdcnt = qdio_init->no_output_qs; 430 434 irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4; /* size in words */ 431 435 irq_ptr->qdr->oqdsz = sizeof(struct qdesfmt0) / 4; 432 - irq_ptr->qdr->qiba = (unsigned long)&irq_ptr->qib; 436 + irq_ptr->qdr->qiba = virt_to_phys(&irq_ptr->qib); 433 437 irq_ptr->qdr->qkey = PAGE_DEFAULT_KEY >> 4; 434 438 435 439 for (i = 0; i < qdio_init->no_input_qs; i++) 436 - __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->input_qs, i, 0); 440 + qdio_fill_qdr_desc(desc++, irq_ptr->input_qs[i]); 437 441 438 442 for (i = 0; i < qdio_init->no_output_qs; i++) 439 - __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->output_qs, i, 440 - qdio_init->no_input_qs); 443 + qdio_fill_qdr_desc(desc++, irq_ptr->output_qs[i]); 441 444 } 442 445 443 446 static void setup_qib(struct qdio_irq *irq_ptr, ··· 454 459 if (init_data->no_output_qs) 455 460 irq_ptr->qib.osliba = 456 461 (unsigned long)(irq_ptr->output_qs[0]->slib); 457 - memcpy(irq_ptr->qib.ebcnam, init_data->adapter_name, 8); 462 + memcpy(irq_ptr->qib.ebcnam, dev_name(&irq_ptr->cdev->dev), 8); 463 + ASCEBC(irq_ptr->qib.ebcnam, 8); 458 464 } 459 465 460 466 int qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data)
+274 -145
drivers/s390/crypto/ap_bus.c
··· 214 214 static void __init ap_init_qci_info(void) 215 215 { 216 216 if (!ap_qci_available()) { 217 - AP_DBF(DBF_INFO, "%s QCI not supported\n", __func__); 217 + AP_DBF_INFO("%s QCI not supported\n", __func__); 218 218 return; 219 219 } 220 220 ··· 226 226 ap_qci_info = NULL; 227 227 return; 228 228 } 229 - AP_DBF(DBF_INFO, "%s successful fetched initial qci info\n", __func__); 229 + AP_DBF_INFO("%s successful fetched initial qci info\n", __func__); 230 230 231 231 if (ap_qci_info->apxa) { 232 232 if (ap_qci_info->Na) { 233 233 ap_max_adapter_id = ap_qci_info->Na; 234 - AP_DBF(DBF_INFO, "%s new ap_max_adapter_id is %d\n", 235 - __func__, ap_max_adapter_id); 234 + AP_DBF_INFO("%s new ap_max_adapter_id is %d\n", 235 + __func__, ap_max_adapter_id); 236 236 } 237 237 if (ap_qci_info->Nd) { 238 238 ap_max_domain_id = ap_qci_info->Nd; 239 - AP_DBF(DBF_INFO, "%s new ap_max_domain_id is %d\n", 240 - __func__, ap_max_domain_id); 239 + AP_DBF_INFO("%s new ap_max_domain_id is %d\n", 240 + __func__, ap_max_domain_id); 241 241 } 242 242 } 243 243 } ··· 307 307 * false otherwise. 308 308 */ 309 309 static bool ap_queue_info(ap_qid_t qid, int *q_type, 310 - unsigned int *q_fac, int *q_depth) 310 + unsigned int *q_fac, int *q_depth, bool *q_decfg) 311 311 { 312 312 struct ap_queue_status status; 313 313 unsigned long info = 0; ··· 322 322 switch (status.response_code) { 323 323 case AP_RESPONSE_NORMAL: 324 324 case AP_RESPONSE_RESET_IN_PROGRESS: 325 + case AP_RESPONSE_DECONFIGURED: 326 + case AP_RESPONSE_CHECKSTOPPED: 327 + case AP_RESPONSE_BUSY: 325 328 /* 326 329 * According to the architecture in all these cases the 327 330 * info should be filled. All bits 0 is not possible as ··· 335 332 *q_type = (int)((info >> 24) & 0xff); 336 333 *q_fac = (unsigned int)(info >> 32); 337 334 *q_depth = (int)(info & 0xff); 335 + *q_decfg = status.response_code == AP_RESPONSE_DECONFIGURED; 338 336 switch (*q_type) { 339 337 /* For CEX2 and CEX3 the available functions 340 338 * are not reflected by the facilities bits. ··· 622 618 drvres = to_ap_drv(dev->driver)->flags 623 619 & AP_DRIVER_FLAG_DEFAULT; 624 620 if (!!devres != !!drvres) { 625 - AP_DBF(DBF_DEBUG, "reprobing queue=%02x.%04x\n", 626 - card, queue); 621 + AP_DBF_DBG("reprobing queue=%02x.%04x\n", 622 + card, queue); 627 623 rc = device_reprobe(dev); 628 624 } 629 625 } ··· 800 796 */ 801 797 void ap_bus_cfg_chg(void) 802 798 { 803 - AP_DBF(DBF_INFO, "%s config change, forcing bus rescan\n", __func__); 799 + AP_DBF_DBG("%s config change, forcing bus rescan\n", __func__); 804 800 805 801 ap_bus_force_rescan(); 806 802 } ··· 951 947 ap_domain_index = domain; 952 948 spin_unlock_bh(&ap_domain_lock); 953 949 954 - AP_DBF(DBF_INFO, "stored new default domain=%d\n", domain); 950 + AP_DBF_INFO("stored new default domain=%d\n", domain); 955 951 956 952 return count; 957 953 } ··· 1212 1208 } 1213 1209 if (dom <= ap_max_domain_id) { 1214 1210 ap_domain_index = dom; 1215 - AP_DBF(DBF_DEBUG, "%s new default domain is %d\n", 1216 - __func__, ap_domain_index); 1211 + AP_DBF_INFO("%s new default domain is %d\n", 1212 + __func__, ap_domain_index); 1217 1213 } 1218 1214 out: 1219 1215 spin_unlock_bh(&ap_domain_lock); ··· 1229 1225 int comp_type = 0; 1230 1226 1231 1227 /* < CEX2A is not supported */ 1232 - if (rawtype < AP_DEVICE_TYPE_CEX2A) 1228 + if (rawtype < AP_DEVICE_TYPE_CEX2A) { 1229 + AP_DBF_WARN("get_comp_type queue=%02x.%04x unsupported type %d\n", 1230 + AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype); 1233 1231 return 0; 1232 + } 1234 1233 /* up to CEX7 known and fully supported */ 1235 1234 if (rawtype <= AP_DEVICE_TYPE_CEX7) 1236 1235 return rawtype; ··· 1255 1248 comp_type = apinfo.cat; 1256 1249 } 1257 1250 if (!comp_type) 1258 - AP_DBF(DBF_WARN, "queue=%02x.%04x unable to map type %d\n", 1259 - AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype); 1251 + AP_DBF_WARN("get_comp_type queue=%02x.%04x unable to map type %d\n", 1252 + AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype); 1260 1253 else if (comp_type != rawtype) 1261 - AP_DBF(DBF_INFO, "queue=%02x.%04x map type %d to %d\n", 1262 - AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype, comp_type); 1254 + AP_DBF_INFO("get_comp_type queue=%02x.%04x map type %d to %d\n", 1255 + AP_QID_CARD(qid), AP_QID_QUEUE(qid), 1256 + rawtype, comp_type); 1263 1257 return comp_type; 1264 1258 } 1265 1259 ··· 1294 1286 1295 1287 /* 1296 1288 * Helper function for ap_scan_bus(). 1297 - * Does the scan bus job for the given adapter id. 1289 + * Remove card device and associated queue devices. 1298 1290 */ 1299 - static void _ap_scan_bus_adapter(int id) 1291 + static inline void ap_scan_rm_card_dev_and_queue_devs(struct ap_card *ac) 1300 1292 { 1301 - bool broken; 1293 + bus_for_each_dev(&ap_bus_type, NULL, 1294 + (void *)(long) ac->id, 1295 + __ap_queue_devices_with_id_unregister); 1296 + device_unregister(&ac->ap_dev.device); 1297 + } 1298 + 1299 + /* 1300 + * Helper function for ap_scan_bus(). 1301 + * Does the scan bus job for all the domains within 1302 + * a valid adapter given by an ap_card ptr. 1303 + */ 1304 + static inline void ap_scan_domains(struct ap_card *ac) 1305 + { 1306 + bool decfg; 1302 1307 ap_qid_t qid; 1303 1308 unsigned int func; 1304 - struct ap_card *ac; 1305 1309 struct device *dev; 1306 1310 struct ap_queue *aq; 1307 - int rc, dom, depth, type, comp_type; 1308 - 1309 - /* check if there is a card device registered with this id */ 1310 - dev = bus_find_device(&ap_bus_type, NULL, 1311 - (void *)(long) id, 1312 - __match_card_device_with_id); 1313 - ac = dev ? to_ap_card(dev) : NULL; 1314 - if (!ap_test_config_card_id(id)) { 1315 - if (dev) { 1316 - /* Card device has been removed from configuration */ 1317 - bus_for_each_dev(&ap_bus_type, NULL, 1318 - (void *)(long) id, 1319 - __ap_queue_devices_with_id_unregister); 1320 - device_unregister(dev); 1321 - put_device(dev); 1322 - } 1323 - return; 1324 - } 1311 + int rc, dom, depth, type; 1325 1312 1326 1313 /* 1327 - * This card id is enabled in the configuration. If we already have 1328 - * a card device with this id, check if type and functions are still 1329 - * the very same. Also verify that at least one queue is available. 1314 + * Go through the configuration for the domains and compare them 1315 + * to the existing queue devices. Also take care of the config 1316 + * and error state for the queue devices. 1330 1317 */ 1331 - if (ac) { 1332 - /* find the first valid queue */ 1333 - for (dom = 0; dom < AP_DOMAINS; dom++) { 1334 - qid = AP_MKQID(id, dom); 1335 - if (ap_queue_info(qid, &type, &func, &depth)) 1336 - break; 1337 - } 1338 - broken = false; 1339 - if (dom >= AP_DOMAINS) { 1340 - /* no accessible queue on this card */ 1341 - broken = true; 1342 - } else if (ac->raw_hwtype != type) { 1343 - /* card type has changed */ 1344 - AP_DBF(DBF_INFO, "card=%02x type changed.\n", id); 1345 - broken = true; 1346 - } else if (ac->functions != func) { 1347 - /* card functions have changed */ 1348 - AP_DBF(DBF_INFO, "card=%02x functions changed.\n", id); 1349 - broken = true; 1350 - } 1351 - if (broken) { 1352 - /* unregister card device and associated queues */ 1353 - bus_for_each_dev(&ap_bus_type, NULL, 1354 - (void *)(long) id, 1355 - __ap_queue_devices_with_id_unregister); 1356 - device_unregister(dev); 1357 - put_device(dev); 1358 - /* go back if there is no valid queue on this card */ 1359 - if (dom >= AP_DOMAINS) 1360 - return; 1361 - ac = NULL; 1362 - } 1363 - } 1364 1318 1365 - /* 1366 - * Go through all possible queue ids. Check and maybe create or release 1367 - * queue devices for this card. If there exists no card device yet, 1368 - * create a card device also. 1369 - */ 1370 - for (dom = 0; dom < AP_DOMAINS; dom++) { 1371 - qid = AP_MKQID(id, dom); 1319 + for (dom = 0; dom <= ap_max_domain_id; dom++) { 1320 + qid = AP_MKQID(ac->id, dom); 1372 1321 dev = bus_find_device(&ap_bus_type, NULL, 1373 1322 (void *)(long) qid, 1374 1323 __match_queue_device_with_qid); 1375 1324 aq = dev ? to_ap_queue(dev) : NULL; 1376 1325 if (!ap_test_config_usage_domain(dom)) { 1377 1326 if (dev) { 1378 - /* Queue device exists but has been 1379 - * removed from configuration. 1380 - */ 1327 + AP_DBF_INFO("%s(%d,%d) not in config any more, rm queue device\n", 1328 + __func__, ac->id, dom); 1381 1329 device_unregister(dev); 1382 1330 put_device(dev); 1383 1331 } 1384 1332 continue; 1385 1333 } 1386 - /* try to fetch infos about this queue */ 1387 - broken = !ap_queue_info(qid, &type, &func, &depth); 1388 - if (dev) { 1389 - if (!broken) { 1390 - spin_lock_bh(&aq->lock); 1391 - broken = aq->sm_state == AP_SM_STATE_BORKED; 1392 - spin_unlock_bh(&aq->lock); 1393 - } 1394 - if (broken) { 1395 - /* Remove broken device */ 1396 - AP_DBF(DBF_DEBUG, 1397 - "removing broken queue=%02x.%04x\n", 1398 - id, dom); 1334 + /* domain is valid, get info from this APQN */ 1335 + if (!ap_queue_info(qid, &type, &func, &depth, &decfg)) { 1336 + if (aq) { 1337 + AP_DBF_INFO( 1338 + "%s(%d,%d) ap_queue_info() not successful, rm queue device\n", 1339 + __func__, ac->id, dom); 1399 1340 device_unregister(dev); 1341 + put_device(dev); 1400 1342 } 1401 - put_device(dev); 1402 1343 continue; 1403 1344 } 1404 - if (broken) 1405 - continue; 1406 - /* a new queue device is needed, check out comp type */ 1407 - comp_type = ap_get_compatible_type(qid, type, func); 1408 - if (!comp_type) 1409 - continue; 1410 - /* maybe a card device needs to be created first */ 1411 - if (!ac) { 1412 - ac = ap_card_create(id, depth, type, comp_type, func); 1413 - if (!ac) 1345 + /* if no queue device exists, create a new one */ 1346 + if (!aq) { 1347 + aq = ap_queue_create(qid, ac->ap_dev.device_type); 1348 + if (!aq) { 1349 + AP_DBF_WARN("%s(%d,%d) ap_queue_create() failed\n", 1350 + __func__, ac->id, dom); 1414 1351 continue; 1415 - ac->ap_dev.device.bus = &ap_bus_type; 1416 - ac->ap_dev.device.parent = ap_root_device; 1417 - dev_set_name(&ac->ap_dev.device, "card%02x", id); 1418 - /* Register card device with AP bus */ 1419 - rc = device_register(&ac->ap_dev.device); 1420 - if (rc) { 1421 - put_device(&ac->ap_dev.device); 1422 - ac = NULL; 1423 - break; 1424 1352 } 1425 - /* get it and thus adjust reference counter */ 1426 - get_device(&ac->ap_dev.device); 1353 + aq->card = ac; 1354 + aq->config = !decfg; 1355 + dev = &aq->ap_dev.device; 1356 + dev->bus = &ap_bus_type; 1357 + dev->parent = &ac->ap_dev.device; 1358 + dev_set_name(dev, "%02x.%04x", ac->id, dom); 1359 + /* register queue device */ 1360 + rc = device_register(dev); 1361 + if (rc) { 1362 + AP_DBF_WARN("%s(%d,%d) device_register() failed\n", 1363 + __func__, ac->id, dom); 1364 + goto put_dev_and_continue; 1365 + } 1366 + if (decfg) 1367 + AP_DBF_INFO("%s(%d,%d) new (decfg) queue device created\n", 1368 + __func__, ac->id, dom); 1369 + else 1370 + AP_DBF_INFO("%s(%d,%d) new queue device created\n", 1371 + __func__, ac->id, dom); 1372 + goto put_dev_and_continue; 1427 1373 } 1428 - /* now create the new queue device */ 1429 - aq = ap_queue_create(qid, comp_type); 1430 - if (!aq) 1431 - continue; 1432 - aq->card = ac; 1433 - aq->ap_dev.device.bus = &ap_bus_type; 1434 - aq->ap_dev.device.parent = &ac->ap_dev.device; 1435 - dev_set_name(&aq->ap_dev.device, "%02x.%04x", id, dom); 1436 - /* Register queue device */ 1437 - rc = device_register(&aq->ap_dev.device); 1438 - if (rc) { 1439 - put_device(&aq->ap_dev.device); 1440 - continue; 1374 + /* Check config state on the already existing queue device */ 1375 + spin_lock_bh(&aq->lock); 1376 + if (decfg && aq->config) { 1377 + /* config off this queue device */ 1378 + aq->config = false; 1379 + if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { 1380 + aq->dev_state = AP_DEV_STATE_ERROR; 1381 + aq->last_err_rc = AP_RESPONSE_DECONFIGURED; 1382 + } 1383 + spin_unlock_bh(&aq->lock); 1384 + AP_DBF_INFO("%s(%d,%d) queue device config off\n", 1385 + __func__, ac->id, dom); 1386 + /* 'receive' pending messages with -EAGAIN */ 1387 + ap_flush_queue(aq); 1388 + goto put_dev_and_continue; 1441 1389 } 1442 - } /* end domain loop */ 1390 + if (!decfg && !aq->config) { 1391 + /* config on this queue device */ 1392 + aq->config = true; 1393 + if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { 1394 + aq->dev_state = AP_DEV_STATE_OPERATING; 1395 + aq->sm_state = AP_SM_STATE_RESET_START; 1396 + } 1397 + spin_unlock_bh(&aq->lock); 1398 + AP_DBF_INFO("%s(%d,%d) queue device config on\n", 1399 + __func__, ac->id, dom); 1400 + goto put_dev_and_continue; 1401 + } 1402 + /* handle other error states */ 1403 + if (!decfg && aq->dev_state == AP_DEV_STATE_ERROR) { 1404 + spin_unlock_bh(&aq->lock); 1405 + /* 'receive' pending messages with -EAGAIN */ 1406 + ap_flush_queue(aq); 1407 + /* re-init (with reset) the queue device */ 1408 + ap_queue_init_state(aq); 1409 + AP_DBF_INFO("%s(%d,%d) queue device reinit enforced\n", 1410 + __func__, ac->id, dom); 1411 + goto put_dev_and_continue; 1412 + } 1413 + spin_unlock_bh(&aq->lock); 1414 + put_dev_and_continue: 1415 + put_device(dev); 1416 + } 1417 + } 1443 1418 1444 - if (ac) 1445 - put_device(&ac->ap_dev.device); 1419 + /* 1420 + * Helper function for ap_scan_bus(). 1421 + * Does the scan bus job for the given adapter id. 1422 + */ 1423 + static inline void ap_scan_adapter(int ap) 1424 + { 1425 + bool decfg; 1426 + ap_qid_t qid; 1427 + unsigned int func; 1428 + struct device *dev; 1429 + struct ap_card *ac; 1430 + int rc, dom, depth, type, comp_type; 1431 + 1432 + /* Is there currently a card device for this adapter ? */ 1433 + dev = bus_find_device(&ap_bus_type, NULL, 1434 + (void *)(long) ap, 1435 + __match_card_device_with_id); 1436 + ac = dev ? to_ap_card(dev) : NULL; 1437 + 1438 + /* Adapter not in configuration ? */ 1439 + if (!ap_test_config_card_id(ap)) { 1440 + if (ac) { 1441 + AP_DBF_INFO("%s(%d) ap not in config any more, rm card and queue devices\n", 1442 + __func__, ap); 1443 + ap_scan_rm_card_dev_and_queue_devs(ac); 1444 + put_device(dev); 1445 + } 1446 + return; 1447 + } 1448 + 1449 + /* 1450 + * Adapter ap is valid in the current configuration. So do some checks: 1451 + * If no card device exists, build one. If a card device exists, check 1452 + * for type and functions changed. For all this we need to find a valid 1453 + * APQN first. 1454 + */ 1455 + 1456 + for (dom = 0; dom <= ap_max_domain_id; dom++) 1457 + if (ap_test_config_usage_domain(dom)) { 1458 + qid = AP_MKQID(ap, dom); 1459 + if (ap_queue_info(qid, &type, &func, &depth, &decfg)) 1460 + break; 1461 + } 1462 + if (dom > ap_max_domain_id) { 1463 + /* Could not find a valid APQN for this adapter */ 1464 + if (ac) { 1465 + AP_DBF_INFO( 1466 + "%s(%d) no type info (no APQN found), rm card and queue devices\n", 1467 + __func__, ap); 1468 + ap_scan_rm_card_dev_and_queue_devs(ac); 1469 + put_device(dev); 1470 + } else { 1471 + AP_DBF_DBG("%s(%d) no type info (no APQN found), ignored\n", 1472 + __func__, ap); 1473 + } 1474 + return; 1475 + } 1476 + if (!type) { 1477 + /* No apdater type info available, an unusable adapter */ 1478 + if (ac) { 1479 + AP_DBF_INFO("%s(%d) no valid type (0) info, rm card and queue devices\n", 1480 + __func__, ap); 1481 + ap_scan_rm_card_dev_and_queue_devs(ac); 1482 + put_device(dev); 1483 + } else { 1484 + AP_DBF_DBG("%s(%d) no valid type (0) info, ignored\n", 1485 + __func__, ap); 1486 + } 1487 + return; 1488 + } 1489 + 1490 + if (ac) { 1491 + /* Check APQN against existing card device for changes */ 1492 + if (ac->raw_hwtype != type) { 1493 + AP_DBF_INFO("%s(%d) hwtype %d changed, rm card and queue devices\n", 1494 + __func__, ap, type); 1495 + ap_scan_rm_card_dev_and_queue_devs(ac); 1496 + put_device(dev); 1497 + ac = NULL; 1498 + } else if (ac->functions != func) { 1499 + AP_DBF_INFO("%s(%d) functions 0x%08x changed, rm card and queue devices\n", 1500 + __func__, ap, type); 1501 + ap_scan_rm_card_dev_and_queue_devs(ac); 1502 + put_device(dev); 1503 + ac = NULL; 1504 + } else { 1505 + if (decfg && ac->config) { 1506 + ac->config = false; 1507 + AP_DBF_INFO("%s(%d) card device config off\n", 1508 + __func__, ap); 1509 + 1510 + } 1511 + if (!decfg && !ac->config) { 1512 + ac->config = true; 1513 + AP_DBF_INFO("%s(%d) card device config on\n", 1514 + __func__, ap); 1515 + } 1516 + } 1517 + } 1518 + 1519 + if (!ac) { 1520 + /* Build a new card device */ 1521 + comp_type = ap_get_compatible_type(qid, type, func); 1522 + if (!comp_type) { 1523 + AP_DBF_WARN("%s(%d) type %d, can't get compatibility type\n", 1524 + __func__, ap, type); 1525 + return; 1526 + } 1527 + ac = ap_card_create(ap, depth, type, comp_type, func); 1528 + if (!ac) { 1529 + AP_DBF_WARN("%s(%d) ap_card_create() failed\n", 1530 + __func__, ap); 1531 + return; 1532 + } 1533 + ac->config = !decfg; 1534 + dev = &ac->ap_dev.device; 1535 + dev->bus = &ap_bus_type; 1536 + dev->parent = ap_root_device; 1537 + dev_set_name(dev, "card%02x", ap); 1538 + /* Register the new card device with AP bus */ 1539 + rc = device_register(dev); 1540 + if (rc) { 1541 + AP_DBF_WARN("%s(%d) device_register() failed\n", 1542 + __func__, ap); 1543 + put_device(dev); 1544 + return; 1545 + } 1546 + /* get it and thus adjust reference counter */ 1547 + get_device(dev); 1548 + if (decfg) 1549 + AP_DBF_INFO("%s(%d) new (decfg) card device type=%d func=0x%08x created\n", 1550 + __func__, ap, type, func); 1551 + else 1552 + AP_DBF_INFO("%s(%d) new card device type=%d func=0x%08x created\n", 1553 + __func__, ap, type, func); 1554 + } 1555 + 1556 + /* Verify the domains and the queue devices for this card */ 1557 + ap_scan_domains(ac); 1558 + 1559 + /* release the card device */ 1560 + put_device(&ac->ap_dev.device); 1446 1561 } 1447 1562 1448 1563 /** ··· 1574 1443 */ 1575 1444 static void ap_scan_bus(struct work_struct *unused) 1576 1445 { 1577 - int id; 1446 + int ap; 1578 1447 1579 1448 ap_fetch_qci_info(ap_qci_info); 1580 1449 ap_select_domain(); 1581 1450 1582 - AP_DBF(DBF_DEBUG, "%s running\n", __func__); 1451 + AP_DBF_DBG("%s running\n", __func__); 1583 1452 1584 1453 /* loop over all possible adapters */ 1585 - for (id = 0; id < AP_DEVICES; id++) 1586 - _ap_scan_bus_adapter(id); 1454 + for (ap = 0; ap <= ap_max_adapter_id; ap++) 1455 + ap_scan_adapter(ap); 1587 1456 1588 1457 /* check if there is at least one queue available with default domain */ 1589 1458 if (ap_domain_index >= 0) { ··· 1594 1463 if (dev) 1595 1464 put_device(dev); 1596 1465 else 1597 - AP_DBF(DBF_INFO, 1598 - "no queue device with default domain %d available\n", 1599 - ap_domain_index); 1466 + AP_DBF_INFO("no queue device with default domain %d available\n", 1467 + ap_domain_index); 1600 1468 } 1601 1469 1602 1470 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ); ··· 1705 1575 */ 1706 1576 if (MACHINE_IS_VM) 1707 1577 poll_timeout = 1500000; 1708 - spin_lock_init(&ap_poll_timer_lock); 1709 1578 hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 1710 1579 ap_poll_timer.function = ap_poll_timeout; 1711 1580
+46 -8
drivers/s390/crypto/ap_bus.h
··· 50 50 #define AP_RESPONSE_NO_FIRST_PART 0x13 51 51 #define AP_RESPONSE_MESSAGE_TOO_BIG 0x15 52 52 #define AP_RESPONSE_REQ_FAC_NOT_INST 0x16 53 + #define AP_RESPONSE_INVALID_DOMAIN 0x42 53 54 54 55 /* 55 56 * Known device types ··· 87 86 * AP queue state machine states 88 87 */ 89 88 enum ap_sm_state { 90 - AP_SM_STATE_RESET_START, 89 + AP_SM_STATE_RESET_START = 0, 91 90 AP_SM_STATE_RESET_WAIT, 92 91 AP_SM_STATE_SETIRQ_WAIT, 93 92 AP_SM_STATE_IDLE, 94 93 AP_SM_STATE_WORKING, 95 94 AP_SM_STATE_QUEUE_FULL, 96 - AP_SM_STATE_REMOVE, /* about to be removed from driver */ 97 - AP_SM_STATE_UNBOUND, /* momentary not bound to a driver */ 98 - AP_SM_STATE_BORKED, /* broken */ 99 95 NR_AP_SM_STATES 100 96 }; 101 97 ··· 114 116 AP_SM_WAIT_INTERRUPT, /* wait for thin interrupt (if available) */ 115 117 AP_SM_WAIT_NONE, /* no wait */ 116 118 NR_AP_SM_WAIT 119 + }; 120 + 121 + /* 122 + * AP queue device states 123 + */ 124 + enum ap_dev_state { 125 + AP_DEV_STATE_UNINITIATED = 0, /* fresh and virgin, not touched */ 126 + AP_DEV_STATE_OPERATING, /* queue dev is working normal */ 127 + AP_DEV_STATE_SHUTDOWN, /* remove/unbind/shutdown in progress */ 128 + AP_DEV_STATE_ERROR, /* device is in error state */ 129 + NR_AP_DEV_STATES 117 130 }; 118 131 119 132 struct ap_device; ··· 167 158 unsigned int functions; /* AP device function bitfield. */ 168 159 int queue_depth; /* AP queue depth.*/ 169 160 int id; /* AP card number. */ 161 + bool config; /* configured state */ 170 162 atomic64_t total_request_count; /* # requests ever for this AP device.*/ 171 163 }; 172 164 ··· 179 169 struct ap_card *card; /* Ptr to assoc. AP card. */ 180 170 spinlock_t lock; /* Per device lock. */ 181 171 void *private; /* ap driver private pointer. */ 172 + enum ap_dev_state dev_state; /* queue device state */ 173 + bool config; /* configured state */ 182 174 ap_qid_t qid; /* AP queue id. */ 183 175 int interrupt; /* indicate if interrupts are enabled */ 184 176 int queue_count; /* # messages currently on AP queue. */ 185 - enum ap_sm_state sm_state; /* ap queue state machine state */ 186 177 int pendingq_count; /* # requests on pendingq list. */ 187 178 int requestq_count; /* # requests on requestq list. */ 188 179 u64 total_request_count; /* # requests ever for this AP device.*/ ··· 192 181 struct list_head pendingq; /* List of message sent to AP queue. */ 193 182 struct list_head requestq; /* List of message yet to be sent. */ 194 183 struct ap_message *reply; /* Per device reply message. */ 184 + enum ap_sm_state sm_state; /* ap queue state machine state */ 185 + int last_err_rc; /* last error state response code */ 195 186 }; 196 187 197 188 #define to_ap_queue(x) container_of((x), struct ap_queue, ap_dev.device) 198 189 199 190 typedef enum ap_sm_wait (ap_func_t)(struct ap_queue *queue); 200 191 192 + /* failure injection cmd struct */ 193 + struct ap_fi { 194 + union { 195 + u16 cmd; /* fi flags + action */ 196 + struct { 197 + u8 flags; /* fi flags only */ 198 + u8 action; /* fi action only */ 199 + }; 200 + }; 201 + }; 202 + 203 + /* all currently known fi actions */ 204 + enum ap_fi_actions { 205 + AP_FI_ACTION_CCA_AGENT_FF = 0x01, 206 + AP_FI_ACTION_CCA_DOM_INVAL = 0x02, 207 + AP_FI_ACTION_NQAP_QID_INVAL = 0x03, 208 + }; 209 + 210 + /* all currently known fi flags */ 211 + enum ap_fi_flags { 212 + AP_FI_FLAG_NO_RETRY = 0x01, 213 + AP_FI_FLAG_TOGGLE_SPECIAL = 0x02, 214 + }; 215 + 201 216 struct ap_message { 202 217 struct list_head list; /* Request queueing. */ 203 218 unsigned long long psmid; /* Message id. */ 204 219 void *msg; /* Pointer to message buffer. */ 205 220 unsigned int len; /* Message length. */ 206 - u32 flags; /* Flags, see AP_MSG_FLAG_xxx */ 221 + u16 flags; /* Flags, see AP_MSG_FLAG_xxx */ 222 + struct ap_fi fi; /* Failure Injection cmd */ 207 223 int rc; /* Return code for this message */ 208 224 void *private; /* ap driver private pointer. */ 209 225 /* receive is called from tasklet context */ ··· 238 200 struct ap_message *); 239 201 }; 240 202 241 - #define AP_MSG_FLAG_SPECIAL (1 << 16) /* flag msg as 'special' with NQAP */ 203 + #define AP_MSG_FLAG_SPECIAL 1 /* flag msg as 'special' with NQAP */ 242 204 243 205 /** 244 206 * ap_init_message() - Initialize ap_message. ··· 272 234 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event); 273 235 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event); 274 236 275 - void ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg); 237 + int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg); 276 238 void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg); 277 239 void ap_flush_queue(struct ap_queue *aq); 278 240
+34
drivers/s390/crypto/ap_card.c
··· 12 12 #include <linux/init.h> 13 13 #include <linux/slab.h> 14 14 #include <asm/facility.h> 15 + #include <asm/sclp.h> 15 16 16 17 #include "ap_bus.h" 17 18 ··· 140 139 141 140 static DEVICE_ATTR_RO(modalias); 142 141 142 + static ssize_t config_show(struct device *dev, 143 + struct device_attribute *attr, char *buf) 144 + { 145 + struct ap_card *ac = to_ap_card(dev); 146 + 147 + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->config ? 1 : 0); 148 + } 149 + 150 + static ssize_t config_store(struct device *dev, 151 + struct device_attribute *attr, 152 + const char *buf, size_t count) 153 + { 154 + int rc = 0, cfg; 155 + struct ap_card *ac = to_ap_card(dev); 156 + 157 + if (sscanf(buf, "%d\n", &cfg) != 1 || cfg < 0 || cfg > 1) 158 + return -EINVAL; 159 + 160 + if (cfg && !ac->config) 161 + rc = sclp_ap_configure(ac->id); 162 + else if (!cfg && ac->config) 163 + rc = sclp_ap_deconfigure(ac->id); 164 + if (rc) 165 + return rc; 166 + 167 + ac->config = cfg ? true : false; 168 + 169 + return count; 170 + } 171 + 172 + static DEVICE_ATTR_RW(config); 173 + 143 174 static struct attribute *ap_card_dev_attrs[] = { 144 175 &dev_attr_hwtype.attr, 145 176 &dev_attr_raw_hwtype.attr, ··· 181 148 &dev_attr_requestq_count.attr, 182 149 &dev_attr_pendingq_count.attr, 183 150 &dev_attr_modalias.attr, 151 + &dev_attr_config.attr, 184 152 NULL 185 153 }; 186 154
+8
drivers/s390/crypto/ap_debug.h
··· 20 20 21 21 #define AP_DBF(...) \ 22 22 debug_sprintf_event(ap_dbf_info, ##__VA_ARGS__) 23 + #define AP_DBF_ERR(...) \ 24 + debug_sprintf_event(ap_dbf_info, DBF_ERR, ##__VA_ARGS__) 25 + #define AP_DBF_WARN(...) \ 26 + debug_sprintf_event(ap_dbf_info, DBF_WARN, ##__VA_ARGS__) 27 + #define AP_DBF_INFO(...) \ 28 + debug_sprintf_event(ap_dbf_info, DBF_INFO, ##__VA_ARGS__) 29 + #define AP_DBF_DBG(...) \ 30 + debug_sprintf_event(ap_dbf_info, DBF_DEBUG, ##__VA_ARGS__) 23 31 24 32 extern debug_info_t *ap_dbf_info; 25 33
+206 -46
drivers/s390/crypto/ap_queue.c
··· 195 195 aq->sm_state = AP_SM_STATE_IDLE; 196 196 return AP_SM_WAIT_NONE; 197 197 default: 198 - aq->sm_state = AP_SM_STATE_BORKED; 198 + aq->dev_state = AP_DEV_STATE_ERROR; 199 + aq->last_err_rc = status.response_code; 200 + AP_DBF_WARN("%s RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 201 + __func__, status.response_code, 202 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 199 203 return AP_SM_WAIT_NONE; 200 204 } 201 205 } ··· 214 210 { 215 211 struct ap_queue_status status; 216 212 struct ap_message *ap_msg; 213 + ap_qid_t qid = aq->qid; 217 214 218 215 if (aq->requestq_count <= 0) 219 216 return AP_SM_WAIT_NONE; 220 217 /* Start the next request on the queue. */ 221 218 ap_msg = list_entry(aq->requestq.next, struct ap_message, list); 222 - status = __ap_send(aq->qid, ap_msg->psmid, 219 + #ifdef CONFIG_ZCRYPT_DEBUG 220 + if (ap_msg->fi.action == AP_FI_ACTION_NQAP_QID_INVAL) { 221 + AP_DBF_WARN("%s fi cmd 0x%04x: forcing invalid qid 0xFF00\n", 222 + __func__, ap_msg->fi.cmd); 223 + qid = 0xFF00; 224 + } 225 + #endif 226 + status = __ap_send(qid, ap_msg->psmid, 223 227 ap_msg->msg, ap_msg->len, 224 228 ap_msg->flags & AP_MSG_FLAG_SPECIAL); 225 229 switch (status.response_code) { ··· 249 237 case AP_RESPONSE_RESET_IN_PROGRESS: 250 238 aq->sm_state = AP_SM_STATE_RESET_WAIT; 251 239 return AP_SM_WAIT_TIMEOUT; 240 + case AP_RESPONSE_INVALID_DOMAIN: 241 + AP_DBF(DBF_WARN, "AP_RESPONSE_INVALID_DOMAIN on NQAP\n"); 242 + fallthrough; 252 243 case AP_RESPONSE_MESSAGE_TOO_BIG: 253 244 case AP_RESPONSE_REQ_FAC_NOT_INST: 254 245 list_del_init(&ap_msg->list); ··· 260 245 ap_msg->receive(aq, ap_msg, NULL); 261 246 return AP_SM_WAIT_AGAIN; 262 247 default: 263 - aq->sm_state = AP_SM_STATE_BORKED; 248 + aq->dev_state = AP_DEV_STATE_ERROR; 249 + aq->last_err_rc = status.response_code; 250 + AP_DBF_WARN("%s RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 251 + __func__, status.response_code, 252 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 264 253 return AP_SM_WAIT_NONE; 265 254 } 266 255 } ··· 297 278 aq->sm_state = AP_SM_STATE_RESET_WAIT; 298 279 aq->interrupt = AP_INTR_DISABLED; 299 280 return AP_SM_WAIT_TIMEOUT; 300 - case AP_RESPONSE_BUSY: 301 - return AP_SM_WAIT_TIMEOUT; 302 - case AP_RESPONSE_Q_NOT_AVAIL: 303 - case AP_RESPONSE_DECONFIGURED: 304 - case AP_RESPONSE_CHECKSTOPPED: 305 281 default: 306 - aq->sm_state = AP_SM_STATE_BORKED; 282 + aq->dev_state = AP_DEV_STATE_ERROR; 283 + aq->last_err_rc = status.response_code; 284 + AP_DBF_WARN("%s RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 285 + __func__, status.response_code, 286 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 307 287 return AP_SM_WAIT_NONE; 308 288 } 309 289 } ··· 341 323 case AP_RESPONSE_DECONFIGURED: 342 324 case AP_RESPONSE_CHECKSTOPPED: 343 325 default: 344 - aq->sm_state = AP_SM_STATE_BORKED; 326 + aq->dev_state = AP_DEV_STATE_ERROR; 327 + aq->last_err_rc = status.response_code; 328 + AP_DBF_WARN("%s RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 329 + __func__, status.response_code, 330 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 345 331 return AP_SM_WAIT_NONE; 346 332 } 347 333 } ··· 382 360 case AP_RESPONSE_NO_PENDING_REPLY: 383 361 return AP_SM_WAIT_TIMEOUT; 384 362 default: 385 - aq->sm_state = AP_SM_STATE_BORKED; 363 + aq->dev_state = AP_DEV_STATE_ERROR; 364 + aq->last_err_rc = status.response_code; 365 + AP_DBF_WARN("%s RC 0x%02x on 0x%02x.%04x -> AP_DEV_STATE_ERROR\n", 366 + __func__, status.response_code, 367 + AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); 386 368 return AP_SM_WAIT_NONE; 387 369 } 388 370 } ··· 419 393 [AP_SM_EVENT_POLL] = ap_sm_read, 420 394 [AP_SM_EVENT_TIMEOUT] = ap_sm_reset, 421 395 }, 422 - [AP_SM_STATE_REMOVE] = { 423 - [AP_SM_EVENT_POLL] = ap_sm_nop, 424 - [AP_SM_EVENT_TIMEOUT] = ap_sm_nop, 425 - }, 426 - [AP_SM_STATE_UNBOUND] = { 427 - [AP_SM_EVENT_POLL] = ap_sm_nop, 428 - [AP_SM_EVENT_TIMEOUT] = ap_sm_nop, 429 - }, 430 - [AP_SM_STATE_BORKED] = { 431 - [AP_SM_EVENT_POLL] = ap_sm_nop, 432 - [AP_SM_EVENT_TIMEOUT] = ap_sm_nop, 433 - }, 434 396 }; 435 397 436 398 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event) 437 399 { 438 - return ap_jumptable[aq->sm_state][event](aq); 400 + if (aq->dev_state > AP_DEV_STATE_UNINITIATED) 401 + return ap_jumptable[aq->sm_state][event](aq); 402 + else 403 + return AP_SM_WAIT_NONE; 439 404 } 440 405 441 406 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event) ··· 446 429 char *buf) 447 430 { 448 431 struct ap_queue *aq = to_ap_queue(dev); 432 + bool valid = false; 449 433 u64 req_cnt; 450 434 451 435 spin_lock_bh(&aq->lock); 452 - req_cnt = aq->total_request_count; 436 + if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { 437 + req_cnt = aq->total_request_count; 438 + valid = true; 439 + } 453 440 spin_unlock_bh(&aq->lock); 454 - return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); 441 + 442 + if (valid) 443 + return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); 444 + else 445 + return scnprintf(buf, PAGE_SIZE, "-\n"); 455 446 } 456 447 457 448 static ssize_t request_count_store(struct device *dev, ··· 484 459 unsigned int reqq_cnt = 0; 485 460 486 461 spin_lock_bh(&aq->lock); 487 - reqq_cnt = aq->requestq_count; 462 + if (aq->dev_state > AP_DEV_STATE_UNINITIATED) 463 + reqq_cnt = aq->requestq_count; 488 464 spin_unlock_bh(&aq->lock); 489 465 return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); 490 466 } ··· 499 473 unsigned int penq_cnt = 0; 500 474 501 475 spin_lock_bh(&aq->lock); 502 - penq_cnt = aq->pendingq_count; 476 + if (aq->dev_state > AP_DEV_STATE_UNINITIATED) 477 + penq_cnt = aq->pendingq_count; 503 478 spin_unlock_bh(&aq->lock); 504 479 return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); 505 480 } ··· 569 542 570 543 static DEVICE_ATTR_RO(interrupt); 571 544 545 + static ssize_t config_show(struct device *dev, 546 + struct device_attribute *attr, char *buf) 547 + { 548 + struct ap_queue *aq = to_ap_queue(dev); 549 + int rc; 550 + 551 + spin_lock_bh(&aq->lock); 552 + rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->config ? 1 : 0); 553 + spin_unlock_bh(&aq->lock); 554 + return rc; 555 + } 556 + 557 + static DEVICE_ATTR_RO(config); 558 + 559 + #ifdef CONFIG_ZCRYPT_DEBUG 560 + static ssize_t states_show(struct device *dev, 561 + struct device_attribute *attr, char *buf) 562 + { 563 + struct ap_queue *aq = to_ap_queue(dev); 564 + int rc = 0; 565 + 566 + spin_lock_bh(&aq->lock); 567 + /* queue device state */ 568 + switch (aq->dev_state) { 569 + case AP_DEV_STATE_UNINITIATED: 570 + rc = scnprintf(buf, PAGE_SIZE, "UNINITIATED\n"); 571 + break; 572 + case AP_DEV_STATE_OPERATING: 573 + rc = scnprintf(buf, PAGE_SIZE, "OPERATING"); 574 + break; 575 + case AP_DEV_STATE_SHUTDOWN: 576 + rc = scnprintf(buf, PAGE_SIZE, "SHUTDOWN"); 577 + break; 578 + case AP_DEV_STATE_ERROR: 579 + rc = scnprintf(buf, PAGE_SIZE, "ERROR"); 580 + break; 581 + default: 582 + rc = scnprintf(buf, PAGE_SIZE, "UNKNOWN"); 583 + } 584 + /* state machine state */ 585 + if (aq->dev_state) { 586 + switch (aq->sm_state) { 587 + case AP_SM_STATE_RESET_START: 588 + rc += scnprintf(buf + rc, PAGE_SIZE - rc, 589 + " [RESET_START]\n"); 590 + break; 591 + case AP_SM_STATE_RESET_WAIT: 592 + rc += scnprintf(buf + rc, PAGE_SIZE - rc, 593 + " [RESET_WAIT]\n"); 594 + break; 595 + case AP_SM_STATE_SETIRQ_WAIT: 596 + rc += scnprintf(buf + rc, PAGE_SIZE - rc, 597 + " [SETIRQ_WAIT]\n"); 598 + break; 599 + case AP_SM_STATE_IDLE: 600 + rc += scnprintf(buf + rc, PAGE_SIZE - rc, 601 + " [IDLE]\n"); 602 + break; 603 + case AP_SM_STATE_WORKING: 604 + rc += scnprintf(buf + rc, PAGE_SIZE - rc, 605 + " [WORKING]\n"); 606 + break; 607 + case AP_SM_STATE_QUEUE_FULL: 608 + rc += scnprintf(buf + rc, PAGE_SIZE - rc, 609 + " [FULL]\n"); 610 + break; 611 + default: 612 + rc += scnprintf(buf + rc, PAGE_SIZE - rc, 613 + " [UNKNOWN]\n"); 614 + } 615 + } 616 + spin_unlock_bh(&aq->lock); 617 + 618 + return rc; 619 + } 620 + static DEVICE_ATTR_RO(states); 621 + 622 + static ssize_t last_err_rc_show(struct device *dev, 623 + struct device_attribute *attr, char *buf) 624 + { 625 + struct ap_queue *aq = to_ap_queue(dev); 626 + int rc; 627 + 628 + spin_lock_bh(&aq->lock); 629 + rc = aq->last_err_rc; 630 + spin_unlock_bh(&aq->lock); 631 + 632 + switch (rc) { 633 + case AP_RESPONSE_NORMAL: 634 + return scnprintf(buf, PAGE_SIZE, "NORMAL\n"); 635 + case AP_RESPONSE_Q_NOT_AVAIL: 636 + return scnprintf(buf, PAGE_SIZE, "Q_NOT_AVAIL\n"); 637 + case AP_RESPONSE_RESET_IN_PROGRESS: 638 + return scnprintf(buf, PAGE_SIZE, "RESET_IN_PROGRESS\n"); 639 + case AP_RESPONSE_DECONFIGURED: 640 + return scnprintf(buf, PAGE_SIZE, "DECONFIGURED\n"); 641 + case AP_RESPONSE_CHECKSTOPPED: 642 + return scnprintf(buf, PAGE_SIZE, "CHECKSTOPPED\n"); 643 + case AP_RESPONSE_BUSY: 644 + return scnprintf(buf, PAGE_SIZE, "BUSY\n"); 645 + case AP_RESPONSE_INVALID_ADDRESS: 646 + return scnprintf(buf, PAGE_SIZE, "INVALID_ADDRESS\n"); 647 + case AP_RESPONSE_OTHERWISE_CHANGED: 648 + return scnprintf(buf, PAGE_SIZE, "OTHERWISE_CHANGED\n"); 649 + case AP_RESPONSE_Q_FULL: 650 + return scnprintf(buf, PAGE_SIZE, "Q_FULL/NO_PENDING_REPLY\n"); 651 + case AP_RESPONSE_INDEX_TOO_BIG: 652 + return scnprintf(buf, PAGE_SIZE, "INDEX_TOO_BIG\n"); 653 + case AP_RESPONSE_NO_FIRST_PART: 654 + return scnprintf(buf, PAGE_SIZE, "NO_FIRST_PART\n"); 655 + case AP_RESPONSE_MESSAGE_TOO_BIG: 656 + return scnprintf(buf, PAGE_SIZE, "MESSAGE_TOO_BIG\n"); 657 + case AP_RESPONSE_REQ_FAC_NOT_INST: 658 + return scnprintf(buf, PAGE_SIZE, "REQ_FAC_NOT_INST\n"); 659 + default: 660 + return scnprintf(buf, PAGE_SIZE, "response code %d\n", rc); 661 + } 662 + } 663 + static DEVICE_ATTR_RO(last_err_rc); 664 + #endif 665 + 572 666 static struct attribute *ap_queue_dev_attrs[] = { 573 667 &dev_attr_request_count.attr, 574 668 &dev_attr_requestq_count.attr, 575 669 &dev_attr_pendingq_count.attr, 576 670 &dev_attr_reset.attr, 577 671 &dev_attr_interrupt.attr, 672 + &dev_attr_config.attr, 673 + #ifdef CONFIG_ZCRYPT_DEBUG 674 + &dev_attr_states.attr, 675 + &dev_attr_last_err_rc.attr, 676 + #endif 578 677 NULL 579 678 }; 580 679 ··· 740 587 aq->ap_dev.device.type = &ap_queue_type; 741 588 aq->ap_dev.device_type = device_type; 742 589 aq->qid = qid; 743 - aq->sm_state = AP_SM_STATE_UNBOUND; 744 590 aq->interrupt = AP_INTR_DISABLED; 745 591 spin_lock_init(&aq->lock); 746 592 INIT_LIST_HEAD(&aq->pendingq); ··· 764 612 * @aq: The AP device to queue the message to 765 613 * @ap_msg: The message that is to be added 766 614 */ 767 - void ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg) 615 + int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg) 768 616 { 769 - /* For asynchronous message handling a valid receive-callback 770 - * is required. 771 - */ 617 + int rc = 0; 618 + 619 + /* msg needs to have a valid receive-callback */ 772 620 BUG_ON(!ap_msg->receive); 773 621 774 622 spin_lock_bh(&aq->lock); 775 - /* Queue the message. */ 776 - list_add_tail(&ap_msg->list, &aq->requestq); 777 - aq->requestq_count++; 778 - aq->total_request_count++; 779 - atomic64_inc(&aq->card->total_request_count); 623 + 624 + /* only allow to queue new messages if device state is ok */ 625 + if (aq->dev_state == AP_DEV_STATE_OPERATING) { 626 + list_add_tail(&ap_msg->list, &aq->requestq); 627 + aq->requestq_count++; 628 + aq->total_request_count++; 629 + atomic64_inc(&aq->card->total_request_count); 630 + } else 631 + rc = -ENODEV; 632 + 780 633 /* Send/receive as many request from the queue as possible. */ 781 634 ap_wait(ap_sm_event_loop(aq, AP_SM_EVENT_POLL)); 635 + 782 636 spin_unlock_bh(&aq->lock); 637 + 638 + return rc; 783 639 } 784 640 EXPORT_SYMBOL(ap_queue_message); 785 641 ··· 858 698 spin_lock_bh(&aq->lock); 859 699 /* flush queue */ 860 700 __ap_flush_queue(aq); 861 - /* set REMOVE state to prevent new messages are queued in */ 862 - aq->sm_state = AP_SM_STATE_REMOVE; 701 + /* move queue device state to SHUTDOWN in progress */ 702 + aq->dev_state = AP_DEV_STATE_SHUTDOWN; 863 703 spin_unlock_bh(&aq->lock); 864 704 del_timer_sync(&aq->timeout); 865 705 } ··· 867 707 void ap_queue_remove(struct ap_queue *aq) 868 708 { 869 709 /* 870 - * all messages have been flushed and the state is 871 - * AP_SM_STATE_REMOVE. Now reset with zero which also 872 - * clears the irq registration and move the state 873 - * to AP_SM_STATE_UNBOUND to signal that this queue 874 - * is not used by any driver currently. 710 + * all messages have been flushed and the device state 711 + * is SHUTDOWN. Now reset with zero which also clears 712 + * the irq registration and move the device state 713 + * to the initial value AP_DEV_STATE_UNINITIATED. 875 714 */ 876 715 spin_lock_bh(&aq->lock); 877 716 ap_zapq(aq->qid); 878 - aq->sm_state = AP_SM_STATE_UNBOUND; 717 + aq->dev_state = AP_DEV_STATE_UNINITIATED; 879 718 spin_unlock_bh(&aq->lock); 880 719 } 881 720 882 721 void ap_queue_init_state(struct ap_queue *aq) 883 722 { 884 723 spin_lock_bh(&aq->lock); 724 + aq->dev_state = AP_DEV_STATE_OPERATING; 885 725 aq->sm_state = AP_SM_STATE_RESET_START; 886 726 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); 887 727 spin_unlock_bh(&aq->lock);
+241 -21
drivers/s390/crypto/pkey_api.c
··· 31 31 MODULE_AUTHOR("IBM Corporation"); 32 32 MODULE_DESCRIPTION("s390 protected key interface"); 33 33 34 - #define KEYBLOBBUFSIZE 8192 /* key buffer size used for internal processing */ 35 - #define MAXAPQNSINLIST 64 /* max 64 apqns within a apqn list */ 34 + #define KEYBLOBBUFSIZE 8192 /* key buffer size used for internal processing */ 35 + #define PROTKEYBLOBBUFSIZE 256 /* protected key buffer size used internal */ 36 + #define MAXAPQNSINLIST 64 /* max 64 apqns within a apqn list */ 36 37 37 38 /* mask of available pckmo subfunctions, fetched once at module init */ 38 39 static cpacf_mask_t pckmo_functions; ··· 238 237 for (rc = -ENODEV, i = 0; i < nr_apqns; i++) { 239 238 card = apqns[i] >> 16; 240 239 dom = apqns[i] & 0xFFFF; 241 - rc = ep11_key2protkey(card, dom, key, kb->head.len, 242 - pkey->protkey, &pkey->len, &pkey->type); 240 + pkey->len = sizeof(pkey->protkey); 241 + rc = ep11_kblob2protkey(card, dom, key, kb->head.len, 242 + pkey->protkey, &pkey->len, &pkey->type); 243 243 if (rc == 0) 244 244 break; 245 245 } ··· 451 449 break; 452 450 } 453 451 case TOKVER_EP11_AES: { 454 - if (keylen < MINEP11AESKEYBLOBSIZE) 455 - goto out; 456 452 /* check ep11 key for exportable as protected key */ 457 - rc = ep11_check_aeskeyblob(debug_info, 3, key, 0, 1); 453 + rc = ep11_check_aes_key(debug_info, 3, key, keylen, 1); 458 454 if (rc) 459 455 goto out; 460 456 rc = pkey_ep11key2pkey(key, protkey); 461 457 break; 462 458 } 459 + case TOKVER_EP11_AES_WITH_HEADER: 460 + /* check ep11 key with header for exportable as protected key */ 461 + rc = ep11_check_aes_key_with_hdr(debug_info, 3, key, keylen, 1); 462 + if (rc) 463 + goto out; 464 + rc = pkey_ep11key2pkey(key + sizeof(struct ep11kblob_header), 465 + protkey); 466 + break; 463 467 default: 464 468 DEBUG_ERR("%s unknown/unsupported non-CCA token version %d\n", 465 469 __func__, hdr->version); ··· 669 661 *ksize = (enum pkey_key_size) t->bitsize; 670 662 671 663 rc = cca_findcard2(&_apqns, &_nr_apqns, *cardnr, *domain, 672 - ZCRYPT_CEX3C, t->mkvp, 0, 1); 664 + ZCRYPT_CEX3C, AES_MK_SET, t->mkvp, 0, 1); 673 665 if (rc == 0 && flags) 674 666 *flags = PKEY_FLAGS_MATCH_CUR_MKVP; 675 667 if (rc == -ENODEV) { 676 668 rc = cca_findcard2(&_apqns, &_nr_apqns, 677 669 *cardnr, *domain, 678 - ZCRYPT_CEX3C, 0, t->mkvp, 1); 670 + ZCRYPT_CEX3C, AES_MK_SET, 671 + 0, t->mkvp, 1); 679 672 if (rc == 0 && flags) 680 673 *flags = PKEY_FLAGS_MATCH_ALT_MKVP; 681 674 } ··· 706 697 } 707 698 708 699 rc = cca_findcard2(&_apqns, &_nr_apqns, *cardnr, *domain, 709 - ZCRYPT_CEX6, t->mkvp0, 0, 1); 700 + ZCRYPT_CEX6, AES_MK_SET, t->mkvp0, 0, 1); 710 701 if (rc == 0 && flags) 711 702 *flags = PKEY_FLAGS_MATCH_CUR_MKVP; 712 703 if (rc == -ENODEV) { 713 704 rc = cca_findcard2(&_apqns, &_nr_apqns, 714 705 *cardnr, *domain, 715 - ZCRYPT_CEX6, 0, t->mkvp0, 1); 706 + ZCRYPT_CEX6, AES_MK_SET, 707 + 0, t->mkvp0, 1); 716 708 if (rc == 0 && flags) 717 709 *flags = PKEY_FLAGS_MATCH_ALT_MKVP; 718 710 } ··· 727 717 && hdr->version == TOKVER_EP11_AES) { 728 718 struct ep11keyblob *kb = (struct ep11keyblob *)key; 729 719 730 - rc = ep11_check_aeskeyblob(debug_info, 3, key, 0, 1); 720 + rc = ep11_check_aes_key(debug_info, 3, key, keylen, 1); 731 721 if (rc) 732 722 goto out; 733 723 if (ktype) ··· 788 778 if (hdr->version == TOKVER_EP11_AES) { 789 779 if (keylen < sizeof(struct ep11keyblob)) 790 780 return -EINVAL; 791 - if (ep11_check_aeskeyblob(debug_info, 3, key, 0, 1)) 781 + if (ep11_check_aes_key(debug_info, 3, key, keylen, 1)) 792 782 return -EINVAL; 793 783 } else { 794 784 return pkey_nonccatok2pkey(key, keylen, pkey); ··· 814 804 else { /* EP11 AES secure key blob */ 815 805 struct ep11keyblob *kb = (struct ep11keyblob *) key; 816 806 817 - rc = ep11_key2protkey(card, dom, key, kb->head.len, 818 - pkey->protkey, &pkey->len, 819 - &pkey->type); 807 + pkey->len = sizeof(pkey->protkey); 808 + rc = ep11_kblob2protkey(card, dom, key, kb->head.len, 809 + pkey->protkey, &pkey->len, 810 + &pkey->type); 820 811 } 821 812 if (rc == 0) 822 813 break; ··· 836 825 if (keylen < sizeof(struct keytoken_header) || flags == 0) 837 826 return -EINVAL; 838 827 839 - if (hdr->type == TOKTYPE_NON_CCA && hdr->version == TOKVER_EP11_AES) { 828 + if (hdr->type == TOKTYPE_NON_CCA 829 + && (hdr->version == TOKVER_EP11_AES_WITH_HEADER 830 + || hdr->version == TOKVER_EP11_ECC_WITH_HEADER) 831 + && is_ep11_keyblob(key + sizeof(struct ep11kblob_header))) { 832 + int minhwtype = 0, api = 0; 833 + struct ep11keyblob *kb = (struct ep11keyblob *) 834 + (key + sizeof(struct ep11kblob_header)); 835 + 836 + if (flags != PKEY_FLAGS_MATCH_CUR_MKVP) 837 + return -EINVAL; 838 + if (kb->attr & EP11_BLOB_PKEY_EXTRACTABLE) { 839 + minhwtype = ZCRYPT_CEX7; 840 + api = EP11_API_V; 841 + } 842 + rc = ep11_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF, 843 + minhwtype, api, kb->wkvp); 844 + if (rc) 845 + goto out; 846 + } else if (hdr->type == TOKTYPE_NON_CCA 847 + && hdr->version == TOKVER_EP11_AES 848 + && is_ep11_keyblob(key)) { 840 849 int minhwtype = 0, api = 0; 841 850 struct ep11keyblob *kb = (struct ep11keyblob *) key; 842 851 ··· 894 863 return -EINVAL; 895 864 } 896 865 rc = cca_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF, 897 - minhwtype, cur_mkvp, old_mkvp, 1); 866 + minhwtype, AES_MK_SET, 867 + cur_mkvp, old_mkvp, 1); 868 + if (rc) 869 + goto out; 870 + } else if (hdr->type == TOKTYPE_CCA_INTERNAL_PKA) { 871 + u64 cur_mkvp = 0, old_mkvp = 0; 872 + struct eccprivkeytoken *t = (struct eccprivkeytoken *)key; 873 + 874 + if (t->secid == 0x20) { 875 + if (flags & PKEY_FLAGS_MATCH_CUR_MKVP) 876 + cur_mkvp = t->mkvp; 877 + if (flags & PKEY_FLAGS_MATCH_ALT_MKVP) 878 + old_mkvp = t->mkvp; 879 + } else { 880 + /* unknown cca internal 2 token type */ 881 + return -EINVAL; 882 + } 883 + rc = cca_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF, 884 + ZCRYPT_CEX7, APKA_MK_SET, 885 + cur_mkvp, old_mkvp, 1); 898 886 if (rc) 899 887 goto out; 900 888 } else ··· 950 900 if (ktype == PKEY_TYPE_CCA_CIPHER) 951 901 minhwtype = ZCRYPT_CEX6; 952 902 rc = cca_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF, 953 - minhwtype, cur_mkvp, old_mkvp, 1); 903 + minhwtype, AES_MK_SET, 904 + cur_mkvp, old_mkvp, 1); 954 905 if (rc) 955 906 goto out; 956 - } else if (ktype == PKEY_TYPE_EP11) { 907 + } else if (ktype == PKEY_TYPE_CCA_ECC) { 908 + u64 cur_mkvp = 0, old_mkvp = 0; 909 + 910 + if (flags & PKEY_FLAGS_MATCH_CUR_MKVP) 911 + cur_mkvp = *((u64 *) cur_mkvp); 912 + if (flags & PKEY_FLAGS_MATCH_ALT_MKVP) 913 + old_mkvp = *((u64 *) alt_mkvp); 914 + rc = cca_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF, 915 + ZCRYPT_CEX7, APKA_MK_SET, 916 + cur_mkvp, old_mkvp, 1); 917 + if (rc) 918 + goto out; 919 + 920 + } else if (ktype == PKEY_TYPE_EP11 || 921 + ktype == PKEY_TYPE_EP11_AES || 922 + ktype == PKEY_TYPE_EP11_ECC) { 957 923 u8 *wkvp = NULL; 958 924 959 925 if (flags & PKEY_FLAGS_MATCH_CUR_MKVP) ··· 992 926 993 927 out: 994 928 kfree(_apqns); 929 + return rc; 930 + } 931 + 932 + static int pkey_keyblob2pkey3(const struct pkey_apqn *apqns, size_t nr_apqns, 933 + const u8 *key, size_t keylen, u32 *protkeytype, 934 + u8 *protkey, u32 *protkeylen) 935 + { 936 + int i, card, dom, rc; 937 + struct keytoken_header *hdr = (struct keytoken_header *)key; 938 + 939 + /* check for at least one apqn given */ 940 + if (!apqns || !nr_apqns) 941 + return -EINVAL; 942 + 943 + if (keylen < sizeof(struct keytoken_header)) 944 + return -EINVAL; 945 + 946 + if (hdr->type == TOKTYPE_NON_CCA 947 + && hdr->version == TOKVER_EP11_AES_WITH_HEADER 948 + && is_ep11_keyblob(key + sizeof(struct ep11kblob_header))) { 949 + /* EP11 AES key blob with header */ 950 + if (ep11_check_aes_key_with_hdr(debug_info, 3, key, keylen, 1)) 951 + return -EINVAL; 952 + } else if (hdr->type == TOKTYPE_NON_CCA 953 + && hdr->version == TOKVER_EP11_ECC_WITH_HEADER 954 + && is_ep11_keyblob(key + sizeof(struct ep11kblob_header))) { 955 + /* EP11 ECC key blob with header */ 956 + if (ep11_check_ecc_key_with_hdr(debug_info, 3, key, keylen, 1)) 957 + return -EINVAL; 958 + } else if (hdr->type == TOKTYPE_NON_CCA 959 + && hdr->version == TOKVER_EP11_AES 960 + && is_ep11_keyblob(key)) { 961 + /* EP11 AES key blob with header in session field */ 962 + if (ep11_check_aes_key(debug_info, 3, key, keylen, 1)) 963 + return -EINVAL; 964 + } else if (hdr->type == TOKTYPE_CCA_INTERNAL) { 965 + if (hdr->version == TOKVER_CCA_AES) { 966 + /* CCA AES data key */ 967 + if (keylen != sizeof(struct secaeskeytoken)) 968 + return -EINVAL; 969 + if (cca_check_secaeskeytoken(debug_info, 3, key, 0)) 970 + return -EINVAL; 971 + } else if (hdr->version == TOKVER_CCA_VLSC) { 972 + /* CCA AES cipher key */ 973 + if (keylen < hdr->len || keylen > MAXCCAVLSCTOKENSIZE) 974 + return -EINVAL; 975 + if (cca_check_secaescipherkey(debug_info, 3, key, 0, 1)) 976 + return -EINVAL; 977 + } else { 978 + DEBUG_ERR("%s unknown CCA internal token version %d\n", 979 + __func__, hdr->version); 980 + return -EINVAL; 981 + } 982 + } else if (hdr->type == TOKTYPE_CCA_INTERNAL_PKA) { 983 + /* CCA ECC (private) key */ 984 + if (keylen < sizeof(struct eccprivkeytoken)) 985 + return -EINVAL; 986 + if (cca_check_sececckeytoken(debug_info, 3, key, keylen, 1)) 987 + return -EINVAL; 988 + } else if (hdr->type == TOKTYPE_NON_CCA) { 989 + struct pkey_protkey pkey; 990 + 991 + rc = pkey_nonccatok2pkey(key, keylen, &pkey); 992 + if (rc) 993 + return rc; 994 + memcpy(protkey, pkey.protkey, pkey.len); 995 + *protkeylen = pkey.len; 996 + *protkeytype = pkey.type; 997 + return 0; 998 + } else { 999 + DEBUG_ERR("%s unknown/unsupported blob type %d\n", 1000 + __func__, hdr->type); 1001 + return -EINVAL; 1002 + } 1003 + 1004 + /* simple try all apqns from the list */ 1005 + for (rc = -ENODEV, i = 0; rc && i < nr_apqns; i++) { 1006 + card = apqns[i].card; 1007 + dom = apqns[i].domain; 1008 + if (hdr->type == TOKTYPE_NON_CCA 1009 + && (hdr->version == TOKVER_EP11_AES_WITH_HEADER 1010 + || hdr->version == TOKVER_EP11_ECC_WITH_HEADER) 1011 + && is_ep11_keyblob(key + sizeof(struct ep11kblob_header))) 1012 + rc = ep11_kblob2protkey(card, dom, key, hdr->len, 1013 + protkey, protkeylen, protkeytype); 1014 + else if (hdr->type == TOKTYPE_NON_CCA 1015 + && hdr->version == TOKVER_EP11_AES 1016 + && is_ep11_keyblob(key)) 1017 + rc = ep11_kblob2protkey(card, dom, key, hdr->len, 1018 + protkey, protkeylen, protkeytype); 1019 + else if (hdr->type == TOKTYPE_CCA_INTERNAL && 1020 + hdr->version == TOKVER_CCA_AES) 1021 + rc = cca_sec2protkey(card, dom, key, protkey, 1022 + protkeylen, protkeytype); 1023 + else if (hdr->type == TOKTYPE_CCA_INTERNAL && 1024 + hdr->version == TOKVER_CCA_VLSC) 1025 + rc = cca_cipher2protkey(card, dom, key, protkey, 1026 + protkeylen, protkeytype); 1027 + else if (hdr->type == TOKTYPE_CCA_INTERNAL_PKA) 1028 + rc = cca_ecc2protkey(card, dom, key, protkey, 1029 + protkeylen, protkeytype); 1030 + else 1031 + return -EINVAL; 1032 + } 1033 + 995 1034 return rc; 996 1035 } 997 1036 ··· 1500 1329 kfree(apqns); 1501 1330 break; 1502 1331 } 1332 + case PKEY_KBLOB2PROTK3: { 1333 + struct pkey_kblob2pkey3 __user *utp = (void __user *) arg; 1334 + struct pkey_kblob2pkey3 ktp; 1335 + struct pkey_apqn *apqns = NULL; 1336 + u32 protkeylen = PROTKEYBLOBBUFSIZE; 1337 + u8 *kkey, *protkey; 1338 + 1339 + if (copy_from_user(&ktp, utp, sizeof(ktp))) 1340 + return -EFAULT; 1341 + apqns = _copy_apqns_from_user(ktp.apqns, ktp.apqn_entries); 1342 + if (IS_ERR(apqns)) 1343 + return PTR_ERR(apqns); 1344 + kkey = _copy_key_from_user(ktp.key, ktp.keylen); 1345 + if (IS_ERR(kkey)) { 1346 + kfree(apqns); 1347 + return PTR_ERR(kkey); 1348 + } 1349 + protkey = kmalloc(protkeylen, GFP_KERNEL); 1350 + if (!protkey) { 1351 + kfree(apqns); 1352 + kfree(kkey); 1353 + return -ENOMEM; 1354 + } 1355 + rc = pkey_keyblob2pkey3(apqns, ktp.apqn_entries, kkey, 1356 + ktp.keylen, &ktp.pkeytype, 1357 + protkey, &protkeylen); 1358 + DEBUG_DBG("%s pkey_keyblob2pkey3()=%d\n", __func__, rc); 1359 + kfree(apqns); 1360 + kfree(kkey); 1361 + if (rc) { 1362 + kfree(protkey); 1363 + break; 1364 + } 1365 + if (ktp.pkey && ktp.pkeylen) { 1366 + if (protkeylen > ktp.pkeylen) { 1367 + kfree(protkey); 1368 + return -EINVAL; 1369 + } 1370 + if (copy_to_user(ktp.pkey, protkey, protkeylen)) { 1371 + kfree(protkey); 1372 + return -EFAULT; 1373 + } 1374 + } 1375 + kfree(protkey); 1376 + ktp.pkeylen = protkeylen; 1377 + if (copy_to_user(utp, &ktp, sizeof(ktp))) 1378 + return -EFAULT; 1379 + break; 1380 + } 1503 1381 default: 1504 1382 /* unknown/unsupported ioctl cmd */ 1505 1383 return -ENOTTY; ··· 1809 1589 1810 1590 /* build a list of apqns able to generate an cipher key */ 1811 1591 rc = cca_findcard2(&apqns, &nr_apqns, 0xFFFF, 0xFFFF, 1812 - ZCRYPT_CEX6, 0, 0, 0); 1592 + ZCRYPT_CEX6, 0, 0, 0, 0); 1813 1593 if (rc) 1814 1594 return rc; 1815 1595
+309 -107
drivers/s390/crypto/zcrypt_api.c
··· 25 25 #include <linux/debugfs.h> 26 26 #include <linux/cdev.h> 27 27 #include <linux/ctype.h> 28 + #include <linux/capability.h> 28 29 #include <asm/debug.h> 29 30 30 31 #define CREATE_TRACE_POINTS ··· 603 602 unsigned int pref_weight) 604 603 { 605 604 if (!pref_zc) 606 - return false; 605 + return true; 607 606 weight += atomic_read(&zc->load); 608 607 pref_weight += atomic_read(&pref_zc->load); 609 608 if (weight == pref_weight) 610 - return atomic64_read(&zc->card->total_request_count) > 609 + return atomic64_read(&zc->card->total_request_count) < 611 610 atomic64_read(&pref_zc->card->total_request_count); 612 - return weight > pref_weight; 611 + return weight < pref_weight; 613 612 } 614 613 615 614 static inline bool zcrypt_queue_compare(struct zcrypt_queue *zq, ··· 618 617 unsigned int pref_weight) 619 618 { 620 619 if (!pref_zq) 621 - return false; 620 + return true; 622 621 weight += atomic_read(&zq->load); 623 622 pref_weight += atomic_read(&pref_zq->load); 624 623 if (weight == pref_weight) 625 - return zq->queue->total_request_count > 624 + return zq->queue->total_request_count < 626 625 pref_zq->queue->total_request_count; 627 - return weight > pref_weight; 626 + return weight < pref_weight; 628 627 } 629 628 630 629 /* 631 630 * zcrypt ioctls. 632 631 */ 633 632 static long zcrypt_rsa_modexpo(struct ap_perms *perms, 633 + struct zcrypt_track *tr, 634 634 struct ica_rsa_modexpo *mex) 635 635 { 636 636 struct zcrypt_card *zc, *pref_zc; 637 637 struct zcrypt_queue *zq, *pref_zq; 638 - unsigned int weight = 0, pref_weight = 0; 638 + struct ap_message ap_msg; 639 + unsigned int wgt = 0, pref_wgt = 0; 639 640 unsigned int func_code; 640 - int qid = 0, rc = -ENODEV; 641 + int cpen, qpen, qid = 0, rc = -ENODEV; 641 642 struct module *mod; 642 643 643 644 trace_s390_zcrypt_req(mex, TP_ICARSAMODEXPO); 645 + 646 + ap_init_message(&ap_msg); 647 + 648 + #ifdef CONFIG_ZCRYPT_DEBUG 649 + if (tr && tr->fi.cmd) 650 + ap_msg.fi.cmd = tr->fi.cmd; 651 + #endif 644 652 645 653 if (mex->outputdatalength < mex->inputdatalength) { 646 654 func_code = 0; ··· 672 662 pref_zq = NULL; 673 663 spin_lock(&zcrypt_list_lock); 674 664 for_each_zcrypt_card(zc) { 675 - /* Check for online accelarator and CCA cards */ 676 - if (!zc->online || !(zc->card->functions & 0x18000000)) 665 + /* Check for useable accelarator or CCA card */ 666 + if (!zc->online || !zc->card->config || 667 + !(zc->card->functions & 0x18000000)) 677 668 continue; 678 669 /* Check for size limits */ 679 670 if (zc->min_mod_size > mex->inputdatalength || ··· 684 673 if (!zcrypt_check_card(perms, zc->card->id)) 685 674 continue; 686 675 /* get weight index of the card device */ 687 - weight = zc->speed_rating[func_code]; 688 - if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight)) 676 + wgt = zc->speed_rating[func_code]; 677 + /* penalty if this msg was previously sent via this card */ 678 + cpen = (tr && tr->again_counter && tr->last_qid && 679 + AP_QID_CARD(tr->last_qid) == zc->card->id) ? 680 + TRACK_AGAIN_CARD_WEIGHT_PENALTY : 0; 681 + if (!zcrypt_card_compare(zc, pref_zc, wgt + cpen, pref_wgt)) 689 682 continue; 690 683 for_each_zcrypt_queue(zq, zc) { 691 - /* check if device is online and eligible */ 692 - if (!zq->online || !zq->ops->rsa_modexpo) 684 + /* check if device is useable and eligible */ 685 + if (!zq->online || !zq->ops->rsa_modexpo || 686 + !zq->queue->config) 693 687 continue; 694 688 /* check if device node has admission for this queue */ 695 689 if (!zcrypt_check_queue(perms, 696 690 AP_QID_QUEUE(zq->queue->qid))) 697 691 continue; 698 - if (zcrypt_queue_compare(zq, pref_zq, 699 - weight, pref_weight)) 692 + /* penalty if the msg was previously sent at this qid */ 693 + qpen = (tr && tr->again_counter && tr->last_qid && 694 + tr->last_qid == zq->queue->qid) ? 695 + TRACK_AGAIN_QUEUE_WEIGHT_PENALTY : 0; 696 + if (!zcrypt_queue_compare(zq, pref_zq, 697 + wgt + cpen + qpen, pref_wgt)) 700 698 continue; 701 699 pref_zc = zc; 702 700 pref_zq = zq; 703 - pref_weight = weight; 701 + pref_wgt = wgt + cpen + qpen; 704 702 } 705 703 } 706 - pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, weight); 704 + pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt); 707 705 spin_unlock(&zcrypt_list_lock); 708 706 709 707 if (!pref_zq) { ··· 721 701 } 722 702 723 703 qid = pref_zq->queue->qid; 724 - rc = pref_zq->ops->rsa_modexpo(pref_zq, mex); 704 + rc = pref_zq->ops->rsa_modexpo(pref_zq, mex, &ap_msg); 725 705 726 706 spin_lock(&zcrypt_list_lock); 727 - zcrypt_drop_queue(pref_zc, pref_zq, mod, weight); 707 + zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt); 728 708 spin_unlock(&zcrypt_list_lock); 729 709 730 710 out: 711 + ap_release_message(&ap_msg); 712 + if (tr) { 713 + tr->last_rc = rc; 714 + tr->last_qid = qid; 715 + } 731 716 trace_s390_zcrypt_rep(mex, func_code, rc, 732 717 AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 733 718 return rc; 734 719 } 735 720 736 721 static long zcrypt_rsa_crt(struct ap_perms *perms, 722 + struct zcrypt_track *tr, 737 723 struct ica_rsa_modexpo_crt *crt) 738 724 { 739 725 struct zcrypt_card *zc, *pref_zc; 740 726 struct zcrypt_queue *zq, *pref_zq; 741 - unsigned int weight = 0, pref_weight = 0; 727 + struct ap_message ap_msg; 728 + unsigned int wgt = 0, pref_wgt = 0; 742 729 unsigned int func_code; 743 - int qid = 0, rc = -ENODEV; 730 + int cpen, qpen, qid = 0, rc = -ENODEV; 744 731 struct module *mod; 745 732 746 733 trace_s390_zcrypt_req(crt, TP_ICARSACRT); 734 + 735 + ap_init_message(&ap_msg); 736 + 737 + #ifdef CONFIG_ZCRYPT_DEBUG 738 + if (tr && tr->fi.cmd) 739 + ap_msg.fi.cmd = tr->fi.cmd; 740 + #endif 747 741 748 742 if (crt->outputdatalength < crt->inputdatalength) { 749 743 func_code = 0; ··· 780 746 pref_zq = NULL; 781 747 spin_lock(&zcrypt_list_lock); 782 748 for_each_zcrypt_card(zc) { 783 - /* Check for online accelarator and CCA cards */ 784 - if (!zc->online || !(zc->card->functions & 0x18000000)) 749 + /* Check for useable accelarator or CCA card */ 750 + if (!zc->online || !zc->card->config || 751 + !(zc->card->functions & 0x18000000)) 785 752 continue; 786 753 /* Check for size limits */ 787 754 if (zc->min_mod_size > crt->inputdatalength || ··· 792 757 if (!zcrypt_check_card(perms, zc->card->id)) 793 758 continue; 794 759 /* get weight index of the card device */ 795 - weight = zc->speed_rating[func_code]; 796 - if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight)) 760 + wgt = zc->speed_rating[func_code]; 761 + /* penalty if this msg was previously sent via this card */ 762 + cpen = (tr && tr->again_counter && tr->last_qid && 763 + AP_QID_CARD(tr->last_qid) == zc->card->id) ? 764 + TRACK_AGAIN_CARD_WEIGHT_PENALTY : 0; 765 + if (!zcrypt_card_compare(zc, pref_zc, wgt + cpen, pref_wgt)) 797 766 continue; 798 767 for_each_zcrypt_queue(zq, zc) { 799 - /* check if device is online and eligible */ 800 - if (!zq->online || !zq->ops->rsa_modexpo_crt) 768 + /* check if device is useable and eligible */ 769 + if (!zq->online || !zq->ops->rsa_modexpo_crt || 770 + !zq->queue->config) 801 771 continue; 802 772 /* check if device node has admission for this queue */ 803 773 if (!zcrypt_check_queue(perms, 804 774 AP_QID_QUEUE(zq->queue->qid))) 805 775 continue; 806 - if (zcrypt_queue_compare(zq, pref_zq, 807 - weight, pref_weight)) 776 + /* penalty if the msg was previously sent at this qid */ 777 + qpen = (tr && tr->again_counter && tr->last_qid && 778 + tr->last_qid == zq->queue->qid) ? 779 + TRACK_AGAIN_QUEUE_WEIGHT_PENALTY : 0; 780 + if (!zcrypt_queue_compare(zq, pref_zq, 781 + wgt + cpen + qpen, pref_wgt)) 808 782 continue; 809 783 pref_zc = zc; 810 784 pref_zq = zq; 811 - pref_weight = weight; 785 + pref_wgt = wgt + cpen + qpen; 812 786 } 813 787 } 814 - pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, weight); 788 + pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt); 815 789 spin_unlock(&zcrypt_list_lock); 816 790 817 791 if (!pref_zq) { ··· 829 785 } 830 786 831 787 qid = pref_zq->queue->qid; 832 - rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt); 788 + rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt, &ap_msg); 833 789 834 790 spin_lock(&zcrypt_list_lock); 835 - zcrypt_drop_queue(pref_zc, pref_zq, mod, weight); 791 + zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt); 836 792 spin_unlock(&zcrypt_list_lock); 837 793 838 794 out: 795 + ap_release_message(&ap_msg); 796 + if (tr) { 797 + tr->last_rc = rc; 798 + tr->last_qid = qid; 799 + } 839 800 trace_s390_zcrypt_rep(crt, func_code, rc, 840 801 AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 841 802 return rc; 842 803 } 843 804 844 - static long _zcrypt_send_cprb(struct ap_perms *perms, 805 + static long _zcrypt_send_cprb(bool userspace, struct ap_perms *perms, 806 + struct zcrypt_track *tr, 845 807 struct ica_xcRB *xcRB) 846 808 { 847 809 struct zcrypt_card *zc, *pref_zc; 848 810 struct zcrypt_queue *zq, *pref_zq; 849 811 struct ap_message ap_msg; 850 - unsigned int weight = 0, pref_weight = 0; 812 + unsigned int wgt = 0, pref_wgt = 0; 851 813 unsigned int func_code; 852 814 unsigned short *domain, tdom; 853 - int qid = 0, rc = -ENODEV; 815 + int cpen, qpen, qid = 0, rc = -ENODEV; 854 816 struct module *mod; 855 817 856 818 trace_s390_zcrypt_req(xcRB, TB_ZSECSENDCPRB); 857 819 858 820 xcRB->status = 0; 859 821 ap_init_message(&ap_msg); 860 - rc = get_cprb_fc(xcRB, &ap_msg, &func_code, &domain); 822 + 823 + #ifdef CONFIG_ZCRYPT_DEBUG 824 + if (tr && tr->fi.cmd) 825 + ap_msg.fi.cmd = tr->fi.cmd; 826 + if (tr && tr->fi.action == AP_FI_ACTION_CCA_AGENT_FF) { 827 + ZCRYPT_DBF_WARN("%s fi cmd 0x%04x: forcing invalid agent_ID 'FF'\n", 828 + __func__, tr->fi.cmd); 829 + xcRB->agent_ID = 0x4646; 830 + } 831 + #endif 832 + 833 + rc = get_cprb_fc(userspace, xcRB, &ap_msg, &func_code, &domain); 861 834 if (rc) 862 835 goto out; 863 836 ··· 893 832 pref_zq = NULL; 894 833 spin_lock(&zcrypt_list_lock); 895 834 for_each_zcrypt_card(zc) { 896 - /* Check for online CCA cards */ 897 - if (!zc->online || !(zc->card->functions & 0x10000000)) 835 + /* Check for useable CCA card */ 836 + if (!zc->online || !zc->card->config || 837 + !(zc->card->functions & 0x10000000)) 898 838 continue; 899 839 /* Check for user selected CCA card */ 900 840 if (xcRB->user_defined != AUTOSELECT && ··· 905 843 if (!zcrypt_check_card(perms, zc->card->id)) 906 844 continue; 907 845 /* get weight index of the card device */ 908 - weight = speed_idx_cca(func_code) * zc->speed_rating[SECKEY]; 909 - if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight)) 846 + wgt = speed_idx_cca(func_code) * zc->speed_rating[SECKEY]; 847 + /* penalty if this msg was previously sent via this card */ 848 + cpen = (tr && tr->again_counter && tr->last_qid && 849 + AP_QID_CARD(tr->last_qid) == zc->card->id) ? 850 + TRACK_AGAIN_CARD_WEIGHT_PENALTY : 0; 851 + if (!zcrypt_card_compare(zc, pref_zc, wgt + cpen, pref_wgt)) 910 852 continue; 911 853 for_each_zcrypt_queue(zq, zc) { 912 - /* check if device is online and eligible */ 854 + /* check for device useable and eligible */ 913 855 if (!zq->online || 914 856 !zq->ops->send_cprb || 857 + !zq->queue->config || 915 858 (tdom != AUTOSEL_DOM && 916 859 tdom != AP_QID_QUEUE(zq->queue->qid))) 917 860 continue; ··· 924 857 if (!zcrypt_check_queue(perms, 925 858 AP_QID_QUEUE(zq->queue->qid))) 926 859 continue; 927 - if (zcrypt_queue_compare(zq, pref_zq, 928 - weight, pref_weight)) 860 + /* penalty if the msg was previously sent at this qid */ 861 + qpen = (tr && tr->again_counter && tr->last_qid && 862 + tr->last_qid == zq->queue->qid) ? 863 + TRACK_AGAIN_QUEUE_WEIGHT_PENALTY : 0; 864 + if (!zcrypt_queue_compare(zq, pref_zq, 865 + wgt + cpen + qpen, pref_wgt)) 929 866 continue; 930 867 pref_zc = zc; 931 868 pref_zq = zq; 932 - pref_weight = weight; 869 + pref_wgt = wgt + cpen + qpen; 933 870 } 934 871 } 935 - pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, weight); 872 + pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt); 936 873 spin_unlock(&zcrypt_list_lock); 937 874 938 875 if (!pref_zq) { ··· 949 878 if (*domain == AUTOSEL_DOM) 950 879 *domain = AP_QID_QUEUE(qid); 951 880 952 - rc = pref_zq->ops->send_cprb(pref_zq, xcRB, &ap_msg); 881 + #ifdef CONFIG_ZCRYPT_DEBUG 882 + if (tr && tr->fi.action == AP_FI_ACTION_CCA_DOM_INVAL) { 883 + ZCRYPT_DBF_WARN("%s fi cmd 0x%04x: forcing invalid domain\n", 884 + __func__, tr->fi.cmd); 885 + *domain = 99; 886 + } 887 + #endif 888 + 889 + rc = pref_zq->ops->send_cprb(userspace, pref_zq, xcRB, &ap_msg); 953 890 954 891 spin_lock(&zcrypt_list_lock); 955 - zcrypt_drop_queue(pref_zc, pref_zq, mod, weight); 892 + zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt); 956 893 spin_unlock(&zcrypt_list_lock); 957 894 958 895 out: 959 896 ap_release_message(&ap_msg); 897 + if (tr) { 898 + tr->last_rc = rc; 899 + tr->last_qid = qid; 900 + } 960 901 trace_s390_zcrypt_rep(xcRB, func_code, rc, 961 902 AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 962 903 return rc; ··· 976 893 977 894 long zcrypt_send_cprb(struct ica_xcRB *xcRB) 978 895 { 979 - return _zcrypt_send_cprb(&ap_perms, xcRB); 896 + return _zcrypt_send_cprb(false, &ap_perms, NULL, xcRB); 980 897 } 981 898 EXPORT_SYMBOL(zcrypt_send_cprb); 982 899 ··· 1007 924 return false; 1008 925 } 1009 926 1010 - static long _zcrypt_send_ep11_cprb(struct ap_perms *perms, 927 + static long _zcrypt_send_ep11_cprb(bool userspace, struct ap_perms *perms, 928 + struct zcrypt_track *tr, 1011 929 struct ep11_urb *xcrb) 1012 930 { 1013 931 struct zcrypt_card *zc, *pref_zc; 1014 932 struct zcrypt_queue *zq, *pref_zq; 1015 933 struct ep11_target_dev *targets; 1016 934 unsigned short target_num; 1017 - unsigned int weight = 0, pref_weight = 0; 935 + unsigned int wgt = 0, pref_wgt = 0; 1018 936 unsigned int func_code; 1019 937 struct ap_message ap_msg; 1020 - int qid = 0, rc = -ENODEV; 938 + int cpen, qpen, qid = 0, rc = -ENODEV; 1021 939 struct module *mod; 1022 940 1023 941 trace_s390_zcrypt_req(xcrb, TP_ZSENDEP11CPRB); 1024 942 1025 943 ap_init_message(&ap_msg); 944 + 945 + #ifdef CONFIG_ZCRYPT_DEBUG 946 + if (tr && tr->fi.cmd) 947 + ap_msg.fi.cmd = tr->fi.cmd; 948 + #endif 1026 949 1027 950 target_num = (unsigned short) xcrb->targets_num; 1028 951 ··· 1045 956 } 1046 957 1047 958 uptr = (struct ep11_target_dev __force __user *) xcrb->targets; 1048 - if (copy_from_user(targets, uptr, 959 + if (z_copy_from_user(userspace, targets, uptr, 1049 960 target_num * sizeof(*targets))) { 1050 961 func_code = 0; 1051 962 rc = -EFAULT; ··· 1053 964 } 1054 965 } 1055 966 1056 - rc = get_ep11cprb_fc(xcrb, &ap_msg, &func_code); 967 + rc = get_ep11cprb_fc(userspace, xcrb, &ap_msg, &func_code); 1057 968 if (rc) 1058 969 goto out_free; 1059 970 ··· 1061 972 pref_zq = NULL; 1062 973 spin_lock(&zcrypt_list_lock); 1063 974 for_each_zcrypt_card(zc) { 1064 - /* Check for online EP11 cards */ 1065 - if (!zc->online || !(zc->card->functions & 0x04000000)) 975 + /* Check for useable EP11 card */ 976 + if (!zc->online || !zc->card->config || 977 + !(zc->card->functions & 0x04000000)) 1066 978 continue; 1067 979 /* Check for user selected EP11 card */ 1068 980 if (targets && ··· 1073 983 if (!zcrypt_check_card(perms, zc->card->id)) 1074 984 continue; 1075 985 /* get weight index of the card device */ 1076 - weight = speed_idx_ep11(func_code) * zc->speed_rating[SECKEY]; 1077 - if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight)) 986 + wgt = speed_idx_ep11(func_code) * zc->speed_rating[SECKEY]; 987 + /* penalty if this msg was previously sent via this card */ 988 + cpen = (tr && tr->again_counter && tr->last_qid && 989 + AP_QID_CARD(tr->last_qid) == zc->card->id) ? 990 + TRACK_AGAIN_CARD_WEIGHT_PENALTY : 0; 991 + if (!zcrypt_card_compare(zc, pref_zc, wgt + cpen, pref_wgt)) 1078 992 continue; 1079 993 for_each_zcrypt_queue(zq, zc) { 1080 - /* check if device is online and eligible */ 994 + /* check if device is useable and eligible */ 1081 995 if (!zq->online || 1082 996 !zq->ops->send_ep11_cprb || 997 + !zq->queue->config || 1083 998 (targets && 1084 999 !is_desired_ep11_queue(zq->queue->qid, 1085 1000 target_num, targets))) ··· 1093 998 if (!zcrypt_check_queue(perms, 1094 999 AP_QID_QUEUE(zq->queue->qid))) 1095 1000 continue; 1096 - if (zcrypt_queue_compare(zq, pref_zq, 1097 - weight, pref_weight)) 1001 + /* penalty if the msg was previously sent at this qid */ 1002 + qpen = (tr && tr->again_counter && tr->last_qid && 1003 + tr->last_qid == zq->queue->qid) ? 1004 + TRACK_AGAIN_QUEUE_WEIGHT_PENALTY : 0; 1005 + if (!zcrypt_queue_compare(zq, pref_zq, 1006 + wgt + cpen + qpen, pref_wgt)) 1098 1007 continue; 1099 1008 pref_zc = zc; 1100 1009 pref_zq = zq; 1101 - pref_weight = weight; 1010 + pref_wgt = wgt + cpen + qpen; 1102 1011 } 1103 1012 } 1104 - pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, weight); 1013 + pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt); 1105 1014 spin_unlock(&zcrypt_list_lock); 1106 1015 1107 1016 if (!pref_zq) { ··· 1114 1015 } 1115 1016 1116 1017 qid = pref_zq->queue->qid; 1117 - rc = pref_zq->ops->send_ep11_cprb(pref_zq, xcrb, &ap_msg); 1018 + rc = pref_zq->ops->send_ep11_cprb(userspace, pref_zq, xcrb, &ap_msg); 1118 1019 1119 1020 spin_lock(&zcrypt_list_lock); 1120 - zcrypt_drop_queue(pref_zc, pref_zq, mod, weight); 1021 + zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt); 1121 1022 spin_unlock(&zcrypt_list_lock); 1122 1023 1123 1024 out_free: 1124 1025 kfree(targets); 1125 1026 out: 1126 1027 ap_release_message(&ap_msg); 1028 + if (tr) { 1029 + tr->last_rc = rc; 1030 + tr->last_qid = qid; 1031 + } 1127 1032 trace_s390_zcrypt_rep(xcrb, func_code, rc, 1128 1033 AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 1129 1034 return rc; ··· 1135 1032 1136 1033 long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb) 1137 1034 { 1138 - return _zcrypt_send_ep11_cprb(&ap_perms, xcrb); 1035 + return _zcrypt_send_ep11_cprb(false, &ap_perms, NULL, xcrb); 1139 1036 } 1140 1037 EXPORT_SYMBOL(zcrypt_send_ep11_cprb); 1141 1038 ··· 1143 1040 { 1144 1041 struct zcrypt_card *zc, *pref_zc; 1145 1042 struct zcrypt_queue *zq, *pref_zq; 1146 - unsigned int weight = 0, pref_weight = 0; 1043 + unsigned int wgt = 0, pref_wgt = 0; 1147 1044 unsigned int func_code; 1148 1045 struct ap_message ap_msg; 1149 1046 unsigned int domain; ··· 1161 1058 pref_zq = NULL; 1162 1059 spin_lock(&zcrypt_list_lock); 1163 1060 for_each_zcrypt_card(zc) { 1164 - /* Check for online CCA cards */ 1165 - if (!zc->online || !(zc->card->functions & 0x10000000)) 1061 + /* Check for useable CCA card */ 1062 + if (!zc->online || !zc->card->config || 1063 + !(zc->card->functions & 0x10000000)) 1166 1064 continue; 1167 1065 /* get weight index of the card device */ 1168 - weight = zc->speed_rating[func_code]; 1169 - if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight)) 1066 + wgt = zc->speed_rating[func_code]; 1067 + if (!zcrypt_card_compare(zc, pref_zc, wgt, pref_wgt)) 1170 1068 continue; 1171 1069 for_each_zcrypt_queue(zq, zc) { 1172 - /* check if device is online and eligible */ 1173 - if (!zq->online || !zq->ops->rng) 1070 + /* check if device is useable and eligible */ 1071 + if (!zq->online || !zq->ops->rng || 1072 + !zq->queue->config) 1174 1073 continue; 1175 - if (zcrypt_queue_compare(zq, pref_zq, 1176 - weight, pref_weight)) 1074 + if (!zcrypt_queue_compare(zq, pref_zq, wgt, pref_wgt)) 1177 1075 continue; 1178 1076 pref_zc = zc; 1179 1077 pref_zq = zq; 1180 - pref_weight = weight; 1078 + pref_wgt = wgt; 1181 1079 } 1182 1080 } 1183 - pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, weight); 1081 + pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, &mod, wgt); 1184 1082 spin_unlock(&zcrypt_list_lock); 1185 1083 1186 1084 if (!pref_zq) { ··· 1193 1089 rc = pref_zq->ops->rng(pref_zq, buffer, &ap_msg); 1194 1090 1195 1091 spin_lock(&zcrypt_list_lock); 1196 - zcrypt_drop_queue(pref_zc, pref_zq, mod, weight); 1092 + zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt); 1197 1093 spin_unlock(&zcrypt_list_lock); 1198 1094 1199 1095 out: ··· 1405 1301 static int icarsamodexpo_ioctl(struct ap_perms *perms, unsigned long arg) 1406 1302 { 1407 1303 int rc; 1304 + struct zcrypt_track tr; 1408 1305 struct ica_rsa_modexpo mex; 1409 1306 struct ica_rsa_modexpo __user *umex = (void __user *) arg; 1410 1307 1308 + memset(&tr, 0, sizeof(tr)); 1411 1309 if (copy_from_user(&mex, umex, sizeof(mex))) 1412 1310 return -EFAULT; 1311 + 1312 + #ifdef CONFIG_ZCRYPT_DEBUG 1313 + if (mex.inputdatalength & (1U << 31)) { 1314 + if (!capable(CAP_SYS_ADMIN)) 1315 + return -EPERM; 1316 + tr.fi.cmd = (u16)(mex.inputdatalength >> 16); 1317 + } 1318 + mex.inputdatalength &= 0x0000FFFF; 1319 + #endif 1320 + 1413 1321 do { 1414 - rc = zcrypt_rsa_modexpo(perms, &mex); 1415 - } while (rc == -EAGAIN); 1322 + rc = zcrypt_rsa_modexpo(perms, &tr, &mex); 1323 + if (rc == -EAGAIN) 1324 + tr.again_counter++; 1325 + #ifdef CONFIG_ZCRYPT_DEBUG 1326 + if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY)) 1327 + break; 1328 + #endif 1329 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1416 1330 /* on failure: retry once again after a requested rescan */ 1417 1331 if ((rc == -ENODEV) && (zcrypt_process_rescan())) 1418 1332 do { 1419 - rc = zcrypt_rsa_modexpo(perms, &mex); 1420 - } while (rc == -EAGAIN); 1333 + rc = zcrypt_rsa_modexpo(perms, &tr, &mex); 1334 + if (rc == -EAGAIN) 1335 + tr.again_counter++; 1336 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1421 1337 if (rc) { 1422 1338 ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSAMODEXPO rc=%d\n", rc); 1423 1339 return rc; ··· 1448 1324 static int icarsacrt_ioctl(struct ap_perms *perms, unsigned long arg) 1449 1325 { 1450 1326 int rc; 1327 + struct zcrypt_track tr; 1451 1328 struct ica_rsa_modexpo_crt crt; 1452 1329 struct ica_rsa_modexpo_crt __user *ucrt = (void __user *) arg; 1453 1330 1331 + memset(&tr, 0, sizeof(tr)); 1454 1332 if (copy_from_user(&crt, ucrt, sizeof(crt))) 1455 1333 return -EFAULT; 1334 + 1335 + #ifdef CONFIG_ZCRYPT_DEBUG 1336 + if (crt.inputdatalength & (1U << 31)) { 1337 + if (!capable(CAP_SYS_ADMIN)) 1338 + return -EPERM; 1339 + tr.fi.cmd = (u16)(crt.inputdatalength >> 16); 1340 + } 1341 + crt.inputdatalength &= 0x0000FFFF; 1342 + #endif 1343 + 1456 1344 do { 1457 - rc = zcrypt_rsa_crt(perms, &crt); 1458 - } while (rc == -EAGAIN); 1345 + rc = zcrypt_rsa_crt(perms, &tr, &crt); 1346 + if (rc == -EAGAIN) 1347 + tr.again_counter++; 1348 + #ifdef CONFIG_ZCRYPT_DEBUG 1349 + if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY)) 1350 + break; 1351 + #endif 1352 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1459 1353 /* on failure: retry once again after a requested rescan */ 1460 1354 if ((rc == -ENODEV) && (zcrypt_process_rescan())) 1461 1355 do { 1462 - rc = zcrypt_rsa_crt(perms, &crt); 1463 - } while (rc == -EAGAIN); 1356 + rc = zcrypt_rsa_crt(perms, &tr, &crt); 1357 + if (rc == -EAGAIN) 1358 + tr.again_counter++; 1359 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1464 1360 if (rc) { 1465 1361 ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSACRT rc=%d\n", rc); 1466 1362 return rc; ··· 1492 1348 { 1493 1349 int rc; 1494 1350 struct ica_xcRB xcRB; 1351 + struct zcrypt_track tr; 1495 1352 struct ica_xcRB __user *uxcRB = (void __user *) arg; 1496 1353 1354 + memset(&tr, 0, sizeof(tr)); 1497 1355 if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB))) 1498 1356 return -EFAULT; 1357 + 1358 + #ifdef CONFIG_ZCRYPT_DEBUG 1359 + if (xcRB.status & (1U << 31)) { 1360 + if (!capable(CAP_SYS_ADMIN)) 1361 + return -EPERM; 1362 + tr.fi.cmd = (u16)(xcRB.status >> 16); 1363 + } 1364 + xcRB.status &= 0x0000FFFF; 1365 + #endif 1366 + 1499 1367 do { 1500 - rc = _zcrypt_send_cprb(perms, &xcRB); 1501 - } while (rc == -EAGAIN); 1368 + rc = _zcrypt_send_cprb(true, perms, &tr, &xcRB); 1369 + if (rc == -EAGAIN) 1370 + tr.again_counter++; 1371 + #ifdef CONFIG_ZCRYPT_DEBUG 1372 + if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY)) 1373 + break; 1374 + #endif 1375 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1502 1376 /* on failure: retry once again after a requested rescan */ 1503 1377 if ((rc == -ENODEV) && (zcrypt_process_rescan())) 1504 1378 do { 1505 - rc = _zcrypt_send_cprb(perms, &xcRB); 1506 - } while (rc == -EAGAIN); 1379 + rc = _zcrypt_send_cprb(true, perms, &tr, &xcRB); 1380 + if (rc == -EAGAIN) 1381 + tr.again_counter++; 1382 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1507 1383 if (rc) 1508 1384 ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDCPRB rc=%d status=0x%x\n", 1509 1385 rc, xcRB.status); ··· 1536 1372 { 1537 1373 int rc; 1538 1374 struct ep11_urb xcrb; 1375 + struct zcrypt_track tr; 1539 1376 struct ep11_urb __user *uxcrb = (void __user *)arg; 1540 1377 1378 + memset(&tr, 0, sizeof(tr)); 1541 1379 if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb))) 1542 1380 return -EFAULT; 1381 + 1382 + #ifdef CONFIG_ZCRYPT_DEBUG 1383 + if (xcrb.req_len & (1ULL << 63)) { 1384 + if (!capable(CAP_SYS_ADMIN)) 1385 + return -EPERM; 1386 + tr.fi.cmd = (u16)(xcrb.req_len >> 48); 1387 + } 1388 + xcrb.req_len &= 0x0000FFFFFFFFFFFFULL; 1389 + #endif 1390 + 1543 1391 do { 1544 - rc = _zcrypt_send_ep11_cprb(perms, &xcrb); 1545 - } while (rc == -EAGAIN); 1392 + rc = _zcrypt_send_ep11_cprb(true, perms, &tr, &xcrb); 1393 + if (rc == -EAGAIN) 1394 + tr.again_counter++; 1395 + #ifdef CONFIG_ZCRYPT_DEBUG 1396 + if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY)) 1397 + break; 1398 + #endif 1399 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1546 1400 /* on failure: retry once again after a requested rescan */ 1547 1401 if ((rc == -ENODEV) && (zcrypt_process_rescan())) 1548 1402 do { 1549 - rc = _zcrypt_send_ep11_cprb(perms, &xcrb); 1550 - } while (rc == -EAGAIN); 1403 + rc = _zcrypt_send_ep11_cprb(true, perms, &tr, &xcrb); 1404 + if (rc == -EAGAIN) 1405 + tr.again_counter++; 1406 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1551 1407 if (rc) 1552 1408 ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDEP11CPRB rc=%d\n", rc); 1553 1409 if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb))) ··· 1720 1536 struct compat_ica_rsa_modexpo __user *umex32 = compat_ptr(arg); 1721 1537 struct compat_ica_rsa_modexpo mex32; 1722 1538 struct ica_rsa_modexpo mex64; 1539 + struct zcrypt_track tr; 1723 1540 long rc; 1724 1541 1542 + memset(&tr, 0, sizeof(tr)); 1725 1543 if (copy_from_user(&mex32, umex32, sizeof(mex32))) 1726 1544 return -EFAULT; 1727 1545 mex64.inputdata = compat_ptr(mex32.inputdata); ··· 1733 1547 mex64.b_key = compat_ptr(mex32.b_key); 1734 1548 mex64.n_modulus = compat_ptr(mex32.n_modulus); 1735 1549 do { 1736 - rc = zcrypt_rsa_modexpo(perms, &mex64); 1737 - } while (rc == -EAGAIN); 1550 + rc = zcrypt_rsa_modexpo(perms, &tr, &mex64); 1551 + if (rc == -EAGAIN) 1552 + tr.again_counter++; 1553 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1738 1554 /* on failure: retry once again after a requested rescan */ 1739 1555 if ((rc == -ENODEV) && (zcrypt_process_rescan())) 1740 1556 do { 1741 - rc = zcrypt_rsa_modexpo(perms, &mex64); 1742 - } while (rc == -EAGAIN); 1557 + rc = zcrypt_rsa_modexpo(perms, &tr, &mex64); 1558 + if (rc == -EAGAIN) 1559 + tr.again_counter++; 1560 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1743 1561 if (rc) 1744 1562 return rc; 1745 1563 return put_user(mex64.outputdatalength, ··· 1768 1578 struct compat_ica_rsa_modexpo_crt __user *ucrt32 = compat_ptr(arg); 1769 1579 struct compat_ica_rsa_modexpo_crt crt32; 1770 1580 struct ica_rsa_modexpo_crt crt64; 1581 + struct zcrypt_track tr; 1771 1582 long rc; 1772 1583 1584 + memset(&tr, 0, sizeof(tr)); 1773 1585 if (copy_from_user(&crt32, ucrt32, sizeof(crt32))) 1774 1586 return -EFAULT; 1775 1587 crt64.inputdata = compat_ptr(crt32.inputdata); ··· 1784 1592 crt64.nq_prime = compat_ptr(crt32.nq_prime); 1785 1593 crt64.u_mult_inv = compat_ptr(crt32.u_mult_inv); 1786 1594 do { 1787 - rc = zcrypt_rsa_crt(perms, &crt64); 1788 - } while (rc == -EAGAIN); 1595 + rc = zcrypt_rsa_crt(perms, &tr, &crt64); 1596 + if (rc == -EAGAIN) 1597 + tr.again_counter++; 1598 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1789 1599 /* on failure: retry once again after a requested rescan */ 1790 1600 if ((rc == -ENODEV) && (zcrypt_process_rescan())) 1791 1601 do { 1792 - rc = zcrypt_rsa_crt(perms, &crt64); 1793 - } while (rc == -EAGAIN); 1602 + rc = zcrypt_rsa_crt(perms, &tr, &crt64); 1603 + if (rc == -EAGAIN) 1604 + tr.again_counter++; 1605 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1794 1606 if (rc) 1795 1607 return rc; 1796 1608 return put_user(crt64.outputdatalength, ··· 1826 1630 { 1827 1631 struct compat_ica_xcRB __user *uxcRB32 = compat_ptr(arg); 1828 1632 struct compat_ica_xcRB xcRB32; 1633 + struct zcrypt_track tr; 1829 1634 struct ica_xcRB xcRB64; 1830 1635 long rc; 1831 1636 1637 + memset(&tr, 0, sizeof(tr)); 1832 1638 if (copy_from_user(&xcRB32, uxcRB32, sizeof(xcRB32))) 1833 1639 return -EFAULT; 1834 1640 xcRB64.agent_ID = xcRB32.agent_ID; ··· 1854 1656 xcRB64.priority_window = xcRB32.priority_window; 1855 1657 xcRB64.status = xcRB32.status; 1856 1658 do { 1857 - rc = _zcrypt_send_cprb(perms, &xcRB64); 1858 - } while (rc == -EAGAIN); 1659 + rc = _zcrypt_send_cprb(true, perms, &tr, &xcRB64); 1660 + if (rc == -EAGAIN) 1661 + tr.again_counter++; 1662 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1859 1663 /* on failure: retry once again after a requested rescan */ 1860 1664 if ((rc == -ENODEV) && (zcrypt_process_rescan())) 1861 1665 do { 1862 - rc = _zcrypt_send_cprb(perms, &xcRB64); 1863 - } while (rc == -EAGAIN); 1666 + rc = _zcrypt_send_cprb(true, perms, &tr, &xcRB64); 1667 + if (rc == -EAGAIN) 1668 + tr.again_counter++; 1669 + } while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX); 1864 1670 xcRB32.reply_control_blk_length = xcRB64.reply_control_blk_length; 1865 1671 xcRB32.reply_data_length = xcRB64.reply_data_length; 1866 1672 xcRB32.status = xcRB64.status;
+44 -5
drivers/s390/crypto/zcrypt_api.h
··· 55 55 56 56 struct zcrypt_queue; 57 57 58 + /* struct to hold tracking information for a userspace request/response */ 59 + struct zcrypt_track { 60 + int again_counter; /* retry attempts counter */ 61 + int last_qid; /* last qid used */ 62 + int last_rc; /* last return code */ 63 + #ifdef CONFIG_ZCRYPT_DEBUG 64 + struct ap_fi fi; /* failure injection cmd */ 65 + #endif 66 + }; 67 + 68 + /* defines related to message tracking */ 69 + #define TRACK_AGAIN_MAX 10 70 + #define TRACK_AGAIN_CARD_WEIGHT_PENALTY 1000 71 + #define TRACK_AGAIN_QUEUE_WEIGHT_PENALTY 10000 72 + 58 73 struct zcrypt_ops { 59 - long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *); 74 + long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *, 75 + struct ap_message *); 60 76 long (*rsa_modexpo_crt)(struct zcrypt_queue *, 61 - struct ica_rsa_modexpo_crt *); 62 - long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *, 77 + struct ica_rsa_modexpo_crt *, 78 + struct ap_message *); 79 + long (*send_cprb)(bool userspace, struct zcrypt_queue *, struct ica_xcRB *, 63 80 struct ap_message *); 64 - long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *, 81 + long (*send_ep11_cprb)(bool userspace, struct zcrypt_queue *, struct ep11_urb *, 65 82 struct ap_message *); 66 83 long (*rng)(struct zcrypt_queue *, char *, struct ap_message *); 67 84 struct list_head list; /* zcrypt ops list. */ ··· 99 82 int min_mod_size; /* Min number of bits. */ 100 83 int max_mod_size; /* Max number of bits. */ 101 84 int max_exp_bit_length; 102 - int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */ 85 + const int *speed_rating; /* Speed idx of crypto ops. */ 103 86 atomic_t load; /* Utilization of the crypto device */ 104 87 105 88 int request_count; /* # current requests. */ ··· 161 144 void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext *devstatus); 162 145 int zcrypt_device_status_ext(int card, int queue, 163 146 struct zcrypt_device_status_ext *devstatus); 147 + 148 + static inline unsigned long z_copy_from_user(bool userspace, 149 + void *to, 150 + const void __user *from, 151 + unsigned long n) 152 + { 153 + if (likely(userspace)) 154 + return copy_from_user(to, from, n); 155 + memcpy(to, (void __force *) from, n); 156 + return 0; 157 + } 158 + 159 + static inline unsigned long z_copy_to_user(bool userspace, 160 + void __user *to, 161 + const void *from, 162 + unsigned long n) 163 + { 164 + if (likely(userspace)) 165 + return copy_to_user(to, from, n); 166 + memcpy((void __force *) to, from, n); 167 + return 0; 168 + } 164 169 165 170 #endif /* _ZCRYPT_API_H_ */
+9 -3
drivers/s390/crypto/zcrypt_card.c
··· 50 50 struct device_attribute *attr, 51 51 char *buf) 52 52 { 53 - struct zcrypt_card *zc = to_ap_card(dev)->private; 53 + struct ap_card *ac = to_ap_card(dev); 54 + struct zcrypt_card *zc = ac->private; 55 + int online = ac->config && zc->online ? 1 : 0; 54 56 55 - return scnprintf(buf, PAGE_SIZE, "%d\n", zc->online); 57 + return scnprintf(buf, PAGE_SIZE, "%d\n", online); 56 58 } 57 59 58 60 static ssize_t online_store(struct device *dev, 59 61 struct device_attribute *attr, 60 62 const char *buf, size_t count) 61 63 { 62 - struct zcrypt_card *zc = to_ap_card(dev)->private; 64 + struct ap_card *ac = to_ap_card(dev); 65 + struct zcrypt_card *zc = ac->private; 63 66 struct zcrypt_queue *zq; 64 67 int online, id; 65 68 66 69 if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1) 67 70 return -EINVAL; 71 + 72 + if (online && !ac->config) 73 + return -ENODEV; 68 74 69 75 zc->online = online; 70 76 id = zc->card->id;
+304 -107
drivers/s390/crypto/zcrypt_ccamisc.c
··· 173 173 EXPORT_SYMBOL(cca_check_secaescipherkey); 174 174 175 175 /* 176 + * Simple check if the token is a valid CCA secure ECC private 177 + * key token. Returns 0 on success or errno value on failure. 178 + */ 179 + int cca_check_sececckeytoken(debug_info_t *dbg, int dbflvl, 180 + const u8 *token, size_t keysize, 181 + int checkcpacfexport) 182 + { 183 + struct eccprivkeytoken *t = (struct eccprivkeytoken *) token; 184 + 185 + #define DBF(...) debug_sprintf_event(dbg, dbflvl, ##__VA_ARGS__) 186 + 187 + if (t->type != TOKTYPE_CCA_INTERNAL_PKA) { 188 + if (dbg) 189 + DBF("%s token check failed, type 0x%02x != 0x%02x\n", 190 + __func__, (int) t->type, TOKTYPE_CCA_INTERNAL_PKA); 191 + return -EINVAL; 192 + } 193 + if (t->len > keysize) { 194 + if (dbg) 195 + DBF("%s token check failed, len %d > keysize %zu\n", 196 + __func__, (int) t->len, keysize); 197 + return -EINVAL; 198 + } 199 + if (t->secid != 0x20) { 200 + if (dbg) 201 + DBF("%s token check failed, secid 0x%02x != 0x20\n", 202 + __func__, (int) t->secid); 203 + return -EINVAL; 204 + } 205 + if (checkcpacfexport && !(t->kutc & 0x01)) { 206 + if (dbg) 207 + DBF("%s token check failed, XPRTCPAC bit is 0\n", 208 + __func__); 209 + return -EINVAL; 210 + } 211 + 212 + #undef DBF 213 + 214 + return 0; 215 + } 216 + EXPORT_SYMBOL(cca_check_sececckeytoken); 217 + 218 + /* 176 219 * Allocate consecutive memory for request CPRB, request param 177 220 * block, reply CPRB and reply param block and fill in values 178 221 * for the common fields. Returns 0 on success or errno value ··· 289 246 pxcrb->request_control_blk_addr = (void __user *) preqcblk; 290 247 pxcrb->reply_control_blk_length = preqcblk->rpl_msgbl; 291 248 pxcrb->reply_control_blk_addr = (void __user *) prepcblk; 292 - } 293 - 294 - /* 295 - * Helper function which calls zcrypt_send_cprb with 296 - * memory management segment adjusted to kernel space 297 - * so that the copy_from_user called within this 298 - * function do in fact copy from kernel space. 299 - */ 300 - static inline int _zcrypt_send_cprb(struct ica_xcRB *xcrb) 301 - { 302 - int rc; 303 - mm_segment_t old_fs = get_fs(); 304 - 305 - set_fs(KERNEL_DS); 306 - rc = zcrypt_send_cprb(xcrb); 307 - set_fs(old_fs); 308 - 309 - return rc; 310 249 } 311 250 312 251 /* ··· 384 359 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); 385 360 386 361 /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */ 387 - rc = _zcrypt_send_cprb(&xcrb); 362 + rc = zcrypt_send_cprb(&xcrb); 388 363 if (rc) { 389 364 DEBUG_ERR("%s zcrypt_send_cprb (cardnr=%d domain=%d) failed, errno %d\n", 390 365 __func__, (int) cardnr, (int) domain, rc); ··· 522 497 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); 523 498 524 499 /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */ 525 - rc = _zcrypt_send_cprb(&xcrb); 500 + rc = zcrypt_send_cprb(&xcrb); 526 501 if (rc) { 527 502 DEBUG_ERR("%s zcrypt_send_cprb (cardnr=%d domain=%d) failed, rc=%d\n", 528 503 __func__, (int) cardnr, (int) domain, rc); ··· 649 624 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); 650 625 651 626 /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */ 652 - rc = _zcrypt_send_cprb(&xcrb); 627 + rc = zcrypt_send_cprb(&xcrb); 653 628 if (rc) { 654 629 DEBUG_ERR("%s zcrypt_send_cprb (cardnr=%d domain=%d) failed, rc=%d\n", 655 630 __func__, (int) cardnr, (int) domain, rc); ··· 875 850 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); 876 851 877 852 /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */ 878 - rc = _zcrypt_send_cprb(&xcrb); 853 + rc = zcrypt_send_cprb(&xcrb); 879 854 if (rc) { 880 855 DEBUG_ERR( 881 856 "%s zcrypt_send_cprb (cardnr=%d domain=%d) failed, rc=%d\n", ··· 1043 1018 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); 1044 1019 1045 1020 /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */ 1046 - rc = _zcrypt_send_cprb(&xcrb); 1021 + rc = zcrypt_send_cprb(&xcrb); 1047 1022 if (rc) { 1048 1023 DEBUG_ERR( 1049 1024 "%s zcrypt_send_cprb (cardnr=%d domain=%d) failed, rc=%d\n", ··· 1260 1235 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); 1261 1236 1262 1237 /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */ 1263 - rc = _zcrypt_send_cprb(&xcrb); 1238 + rc = zcrypt_send_cprb(&xcrb); 1264 1239 if (rc) { 1265 1240 DEBUG_ERR( 1266 1241 "%s zcrypt_send_cprb (cardnr=%d domain=%d) failed, rc=%d\n", ··· 1341 1316 EXPORT_SYMBOL(cca_cipher2protkey); 1342 1317 1343 1318 /* 1319 + * Derive protected key from CCA ECC secure private key. 1320 + */ 1321 + int cca_ecc2protkey(u16 cardnr, u16 domain, const u8 *key, 1322 + u8 *protkey, u32 *protkeylen, u32 *protkeytype) 1323 + { 1324 + int rc; 1325 + u8 *mem, *ptr; 1326 + struct CPRBX *preqcblk, *prepcblk; 1327 + struct ica_xcRB xcrb; 1328 + struct aureqparm { 1329 + u8 subfunc_code[2]; 1330 + u16 rule_array_len; 1331 + u8 rule_array[8]; 1332 + struct { 1333 + u16 len; 1334 + u16 tk_blob_len; 1335 + u16 tk_blob_tag; 1336 + u8 tk_blob[66]; 1337 + } vud; 1338 + struct { 1339 + u16 len; 1340 + u16 cca_key_token_len; 1341 + u16 cca_key_token_flags; 1342 + u8 cca_key_token[0]; 1343 + } kb; 1344 + } __packed * preqparm; 1345 + struct aurepparm { 1346 + u8 subfunc_code[2]; 1347 + u16 rule_array_len; 1348 + struct { 1349 + u16 len; 1350 + u16 sublen; 1351 + u16 tag; 1352 + struct cpacfkeyblock { 1353 + u8 version; /* version of this struct */ 1354 + u8 flags[2]; 1355 + u8 algo; 1356 + u8 form; 1357 + u8 pad1[3]; 1358 + u16 keylen; 1359 + u8 key[0]; /* the key (keylen bytes) */ 1360 + u16 keyattrlen; 1361 + u8 keyattr[32]; 1362 + u8 pad2[1]; 1363 + u8 vptype; 1364 + u8 vp[32]; /* verification pattern */ 1365 + } ckb; 1366 + } vud; 1367 + struct { 1368 + u16 len; 1369 + } kb; 1370 + } __packed * prepparm; 1371 + int keylen = ((struct eccprivkeytoken *)key)->len; 1372 + 1373 + /* get already prepared memory for 2 cprbs with param block each */ 1374 + rc = alloc_and_prep_cprbmem(PARMBSIZE, &mem, &preqcblk, &prepcblk); 1375 + if (rc) 1376 + return rc; 1377 + 1378 + /* fill request cprb struct */ 1379 + preqcblk->domain = domain; 1380 + 1381 + /* fill request cprb param block with AU request */ 1382 + preqparm = (struct aureqparm __force *) preqcblk->req_parmb; 1383 + memcpy(preqparm->subfunc_code, "AU", 2); 1384 + preqparm->rule_array_len = 1385 + sizeof(preqparm->rule_array_len) 1386 + + sizeof(preqparm->rule_array); 1387 + memcpy(preqparm->rule_array, "EXPT-SK ", 8); 1388 + /* vud, tk blob */ 1389 + preqparm->vud.len = sizeof(preqparm->vud); 1390 + preqparm->vud.tk_blob_len = sizeof(preqparm->vud.tk_blob) 1391 + + 2 * sizeof(uint16_t); 1392 + preqparm->vud.tk_blob_tag = 0x00C2; 1393 + /* kb, cca token */ 1394 + preqparm->kb.len = keylen + 3 * sizeof(uint16_t); 1395 + preqparm->kb.cca_key_token_len = keylen + 2 * sizeof(uint16_t); 1396 + memcpy(preqparm->kb.cca_key_token, key, keylen); 1397 + /* now fill length of param block into cprb */ 1398 + preqcblk->req_parml = sizeof(struct aureqparm) + keylen; 1399 + 1400 + /* fill xcrb struct */ 1401 + prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); 1402 + 1403 + /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */ 1404 + rc = zcrypt_send_cprb(&xcrb); 1405 + if (rc) { 1406 + DEBUG_ERR( 1407 + "%s zcrypt_send_cprb (cardnr=%d domain=%d) failed, rc=%d\n", 1408 + __func__, (int) cardnr, (int) domain, rc); 1409 + goto out; 1410 + } 1411 + 1412 + /* check response returncode and reasoncode */ 1413 + if (prepcblk->ccp_rtcode != 0) { 1414 + DEBUG_ERR( 1415 + "%s unwrap secure key failure, card response %d/%d\n", 1416 + __func__, 1417 + (int) prepcblk->ccp_rtcode, 1418 + (int) prepcblk->ccp_rscode); 1419 + rc = -EIO; 1420 + goto out; 1421 + } 1422 + if (prepcblk->ccp_rscode != 0) { 1423 + DEBUG_WARN( 1424 + "%s unwrap secure key warning, card response %d/%d\n", 1425 + __func__, 1426 + (int) prepcblk->ccp_rtcode, 1427 + (int) prepcblk->ccp_rscode); 1428 + } 1429 + 1430 + /* process response cprb param block */ 1431 + ptr = ((u8 *) prepcblk) + sizeof(struct CPRBX); 1432 + prepcblk->rpl_parmb = (u8 __user *) ptr; 1433 + prepparm = (struct aurepparm *) ptr; 1434 + 1435 + /* check the returned keyblock */ 1436 + if (prepparm->vud.ckb.version != 0x02) { 1437 + DEBUG_ERR("%s reply param keyblock version mismatch 0x%02x != 0x02\n", 1438 + __func__, (int) prepparm->vud.ckb.version); 1439 + rc = -EIO; 1440 + goto out; 1441 + } 1442 + if (prepparm->vud.ckb.algo != 0x81) { 1443 + DEBUG_ERR( 1444 + "%s reply param keyblock algo mismatch 0x%02x != 0x81\n", 1445 + __func__, (int) prepparm->vud.ckb.algo); 1446 + rc = -EIO; 1447 + goto out; 1448 + } 1449 + 1450 + /* copy the translated protected key */ 1451 + if (prepparm->vud.ckb.keylen > *protkeylen) { 1452 + DEBUG_ERR("%s prot keylen mismatch %d > buffersize %u\n", 1453 + __func__, prepparm->vud.ckb.keylen, *protkeylen); 1454 + rc = -EIO; 1455 + goto out; 1456 + } 1457 + memcpy(protkey, prepparm->vud.ckb.key, prepparm->vud.ckb.keylen); 1458 + *protkeylen = prepparm->vud.ckb.keylen; 1459 + if (protkeytype) 1460 + *protkeytype = PKEY_KEYTYPE_ECC; 1461 + 1462 + out: 1463 + free_cprbmem(mem, PARMBSIZE, 0); 1464 + return rc; 1465 + } 1466 + EXPORT_SYMBOL(cca_ecc2protkey); 1467 + 1468 + /* 1344 1469 * query cryptographic facility from CCA adapter 1345 1470 */ 1346 1471 int cca_query_crypto_facility(u16 cardnr, u16 domain, ··· 1541 1366 prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk); 1542 1367 1543 1368 /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */ 1544 - rc = _zcrypt_send_cprb(&xcrb); 1369 + rc = zcrypt_send_cprb(&xcrb); 1545 1370 if (rc) { 1546 1371 DEBUG_ERR("%s zcrypt_send_cprb (cardnr=%d domain=%d) failed, rc=%d\n", 1547 1372 __func__, (int) cardnr, (int) domain, rc); ··· 1699 1524 rarray, &rlen, varray, &vlen); 1700 1525 if (rc == 0 && rlen >= 10*8 && vlen >= 204) { 1701 1526 memcpy(ci->serial, rarray, 8); 1702 - ci->new_mk_state = (char) rarray[7*8]; 1703 - ci->cur_mk_state = (char) rarray[8*8]; 1704 - ci->old_mk_state = (char) rarray[9*8]; 1705 - if (ci->old_mk_state == '2') 1706 - memcpy(&ci->old_mkvp, varray + 172, 8); 1707 - if (ci->cur_mk_state == '2') 1708 - memcpy(&ci->cur_mkvp, varray + 184, 8); 1709 - if (ci->new_mk_state == '3') 1710 - memcpy(&ci->new_mkvp, varray + 196, 8); 1711 - found = 1; 1527 + ci->new_aes_mk_state = (char) rarray[7*8]; 1528 + ci->cur_aes_mk_state = (char) rarray[8*8]; 1529 + ci->old_aes_mk_state = (char) rarray[9*8]; 1530 + if (ci->old_aes_mk_state == '2') 1531 + memcpy(&ci->old_aes_mkvp, varray + 172, 8); 1532 + if (ci->cur_aes_mk_state == '2') 1533 + memcpy(&ci->cur_aes_mkvp, varray + 184, 8); 1534 + if (ci->new_aes_mk_state == '3') 1535 + memcpy(&ci->new_aes_mkvp, varray + 196, 8); 1536 + found++; 1537 + } 1538 + if (!found) 1539 + goto out; 1540 + rlen = vlen = PAGE_SIZE/2; 1541 + rc = cca_query_crypto_facility(cardnr, domain, "STATICSB", 1542 + rarray, &rlen, varray, &vlen); 1543 + if (rc == 0 && rlen >= 10*8 && vlen >= 240) { 1544 + ci->new_apka_mk_state = (char) rarray[7*8]; 1545 + ci->cur_apka_mk_state = (char) rarray[8*8]; 1546 + ci->old_apka_mk_state = (char) rarray[9*8]; 1547 + if (ci->old_apka_mk_state == '2') 1548 + memcpy(&ci->old_apka_mkvp, varray + 208, 8); 1549 + if (ci->cur_apka_mk_state == '2') 1550 + memcpy(&ci->cur_apka_mkvp, varray + 220, 8); 1551 + if (ci->new_apka_mk_state == '3') 1552 + memcpy(&ci->new_apka_mkvp, varray + 232, 8); 1553 + found++; 1712 1554 } 1713 1555 1556 + out: 1714 1557 free_page((unsigned long) pg); 1715 - 1716 - return found ? 0 : -ENOENT; 1558 + return found == 2 ? 0 : -ENOENT; 1717 1559 } 1718 1560 1719 1561 /* ··· 1784 1592 /* enabled CCA card, check current mkvp from cache */ 1785 1593 if (cca_info_cache_fetch(card, dom, &ci) == 0 && 1786 1594 ci.hwtype >= minhwtype && 1787 - ci.cur_mk_state == '2' && 1788 - ci.cur_mkvp == mkvp) { 1595 + ci.cur_aes_mk_state == '2' && 1596 + ci.cur_aes_mkvp == mkvp) { 1789 1597 if (!verify) 1790 1598 break; 1791 1599 /* verify: refresh card info */ 1792 1600 if (fetch_cca_info(card, dom, &ci) == 0) { 1793 1601 cca_info_cache_update(card, dom, &ci); 1794 1602 if (ci.hwtype >= minhwtype && 1795 - ci.cur_mk_state == '2' && 1796 - ci.cur_mkvp == mkvp) 1603 + ci.cur_aes_mk_state == '2' && 1604 + ci.cur_aes_mkvp == mkvp) 1797 1605 break; 1798 1606 } 1799 1607 } ··· 1815 1623 if (fetch_cca_info(card, dom, &ci) == 0) { 1816 1624 cca_info_cache_update(card, dom, &ci); 1817 1625 if (ci.hwtype >= minhwtype && 1818 - ci.cur_mk_state == '2' && 1819 - ci.cur_mkvp == mkvp) 1626 + ci.cur_aes_mk_state == '2' && 1627 + ci.cur_aes_mkvp == mkvp) 1820 1628 break; 1821 1629 if (ci.hwtype >= minhwtype && 1822 - ci.old_mk_state == '2' && 1823 - ci.old_mkvp == mkvp && 1630 + ci.old_aes_mk_state == '2' && 1631 + ci.old_aes_mkvp == mkvp && 1824 1632 oi < 0) 1825 1633 oi = i; 1826 1634 } ··· 1874 1682 EXPORT_SYMBOL(cca_findcard); 1875 1683 1876 1684 int cca_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain, 1877 - int minhwtype, u64 cur_mkvp, u64 old_mkvp, int verify) 1685 + int minhwtype, int mktype, u64 cur_mkvp, u64 old_mkvp, 1686 + int verify) 1878 1687 { 1879 1688 struct zcrypt_device_status_ext *device_status; 1880 - int i, n, card, dom, curmatch, oldmatch, rc = 0; 1689 + u32 *_apqns = NULL, _nr_apqns = 0; 1690 + int i, card, dom, curmatch, oldmatch, rc = 0; 1881 1691 struct cca_info ci; 1882 - 1883 - *apqns = NULL; 1884 - *nr_apqns = 0; 1885 1692 1886 1693 /* fetch status of all crypto cards */ 1887 1694 device_status = kvmalloc_array(MAX_ZDEV_ENTRIES_EXT, ··· 1890 1699 return -ENOMEM; 1891 1700 zcrypt_device_status_mask_ext(device_status); 1892 1701 1893 - /* loop two times: first gather eligible apqns, then store them */ 1894 - while (1) { 1895 - n = 0; 1896 - /* walk through all the crypto cards */ 1897 - for (i = 0; i < MAX_ZDEV_ENTRIES_EXT; i++) { 1898 - card = AP_QID_CARD(device_status[i].qid); 1899 - dom = AP_QID_QUEUE(device_status[i].qid); 1900 - /* check online state */ 1901 - if (!device_status[i].online) 1902 - continue; 1903 - /* check for cca functions */ 1904 - if (!(device_status[i].functions & 0x04)) 1905 - continue; 1906 - /* check cardnr */ 1907 - if (cardnr != 0xFFFF && card != cardnr) 1908 - continue; 1909 - /* check domain */ 1910 - if (domain != 0xFFFF && dom != domain) 1911 - continue; 1912 - /* get cca info on this apqn */ 1913 - if (cca_get_info(card, dom, &ci, verify)) 1914 - continue; 1915 - /* current master key needs to be valid */ 1916 - if (ci.cur_mk_state != '2') 1917 - continue; 1918 - /* check min hardware type */ 1919 - if (minhwtype > 0 && minhwtype > ci.hwtype) 1920 - continue; 1921 - if (cur_mkvp || old_mkvp) { 1922 - /* check mkvps */ 1923 - curmatch = oldmatch = 0; 1924 - if (cur_mkvp && cur_mkvp == ci.cur_mkvp) 1702 + /* allocate 1k space for up to 256 apqns */ 1703 + _apqns = kmalloc_array(256, sizeof(u32), GFP_KERNEL); 1704 + if (!_apqns) { 1705 + kvfree(device_status); 1706 + return -ENOMEM; 1707 + } 1708 + 1709 + /* walk through all the crypto apqnss */ 1710 + for (i = 0; i < MAX_ZDEV_ENTRIES_EXT; i++) { 1711 + card = AP_QID_CARD(device_status[i].qid); 1712 + dom = AP_QID_QUEUE(device_status[i].qid); 1713 + /* check online state */ 1714 + if (!device_status[i].online) 1715 + continue; 1716 + /* check for cca functions */ 1717 + if (!(device_status[i].functions & 0x04)) 1718 + continue; 1719 + /* check cardnr */ 1720 + if (cardnr != 0xFFFF && card != cardnr) 1721 + continue; 1722 + /* check domain */ 1723 + if (domain != 0xFFFF && dom != domain) 1724 + continue; 1725 + /* get cca info on this apqn */ 1726 + if (cca_get_info(card, dom, &ci, verify)) 1727 + continue; 1728 + /* current master key needs to be valid */ 1729 + if (mktype == AES_MK_SET && ci.cur_aes_mk_state != '2') 1730 + continue; 1731 + if (mktype == APKA_MK_SET && ci.cur_apka_mk_state != '2') 1732 + continue; 1733 + /* check min hardware type */ 1734 + if (minhwtype > 0 && minhwtype > ci.hwtype) 1735 + continue; 1736 + if (cur_mkvp || old_mkvp) { 1737 + /* check mkvps */ 1738 + curmatch = oldmatch = 0; 1739 + if (mktype == AES_MK_SET) { 1740 + if (cur_mkvp && cur_mkvp == ci.cur_aes_mkvp) 1925 1741 curmatch = 1; 1926 - if (old_mkvp && ci.old_mk_state == '2' && 1927 - old_mkvp == ci.old_mkvp) 1742 + if (old_mkvp && ci.old_aes_mk_state == '2' && 1743 + old_mkvp == ci.old_aes_mkvp) 1928 1744 oldmatch = 1; 1929 - if ((cur_mkvp || old_mkvp) && 1930 - (curmatch + oldmatch < 1)) 1931 - continue; 1745 + } else { 1746 + if (cur_mkvp && cur_mkvp == ci.cur_apka_mkvp) 1747 + curmatch = 1; 1748 + if (old_mkvp && ci.old_apka_mk_state == '2' && 1749 + old_mkvp == ci.old_apka_mkvp) 1750 + oldmatch = 1; 1932 1751 } 1933 - /* apqn passed all filtering criterons */ 1934 - if (*apqns && n < *nr_apqns) 1935 - (*apqns)[n] = (((u16)card) << 16) | ((u16) dom); 1936 - n++; 1752 + if (curmatch + oldmatch < 1) 1753 + continue; 1937 1754 } 1938 - /* loop 2nd time: array has been filled */ 1939 - if (*apqns) 1940 - break; 1941 - /* loop 1st time: have # of eligible apqns in n */ 1942 - if (!n) { 1943 - rc = -ENODEV; /* no eligible apqns found */ 1944 - break; 1945 - } 1946 - *nr_apqns = n; 1947 - /* allocate array to store n apqns into */ 1948 - *apqns = kmalloc_array(n, sizeof(u32), GFP_KERNEL); 1949 - if (!*apqns) { 1950 - rc = -ENOMEM; 1951 - break; 1952 - } 1953 - verify = 0; 1755 + /* apqn passed all filtering criterons, add to the array */ 1756 + if (_nr_apqns < 256) 1757 + _apqns[_nr_apqns++] = (((u16)card) << 16) | ((u16) dom); 1758 + } 1759 + 1760 + /* nothing found ? */ 1761 + if (!_nr_apqns) { 1762 + kfree(_apqns); 1763 + rc = -ENODEV; 1764 + } else { 1765 + /* no re-allocation, simple return the _apqns array */ 1766 + *apqns = _apqns; 1767 + *nr_apqns = _nr_apqns; 1768 + rc = 0; 1954 1769 } 1955 1770 1956 1771 kvfree(device_status);
+63 -11
drivers/s390/crypto/zcrypt_ccamisc.h
··· 14 14 #include <asm/pkey.h> 15 15 16 16 /* Key token types */ 17 - #define TOKTYPE_NON_CCA 0x00 /* Non-CCA key token */ 18 - #define TOKTYPE_CCA_INTERNAL 0x01 /* CCA internal key token */ 17 + #define TOKTYPE_NON_CCA 0x00 /* Non-CCA key token */ 18 + #define TOKTYPE_CCA_INTERNAL 0x01 /* CCA internal sym key token */ 19 + #define TOKTYPE_CCA_INTERNAL_PKA 0x1f /* CCA internal asym key token */ 19 20 20 21 /* For TOKTYPE_NON_CCA: */ 21 22 #define TOKVER_PROTECTED_KEY 0x01 /* Protected key token */ ··· 94 93 u8 vdata[]; /* variable part data follows */ 95 94 } __packed; 96 95 96 + /* inside view of an CCA secure ECC private key */ 97 + struct eccprivkeytoken { 98 + u8 type; /* 0x1f for internal asym key token */ 99 + u8 version; /* should be 0x00 */ 100 + u16 len; /* total key token length in bytes */ 101 + u8 res1[4]; 102 + u8 secid; /* 0x20 for ECC priv key section marker */ 103 + u8 secver; /* section version */ 104 + u16 seclen; /* section length */ 105 + u8 wtype; /* wrapping method, 0x00 clear, 0x01 AES */ 106 + u8 htype; /* hash method, 0x02 for SHA-256 */ 107 + u8 res2[2]; 108 + u8 kutc; /* key usage and translation control */ 109 + u8 ctype; /* curve type */ 110 + u8 kfs; /* key format and security */ 111 + u8 ksrc; /* key source */ 112 + u16 pbitlen; /* length of prime p in bits */ 113 + u16 ibmadlen; /* IBM associated data length in bytes */ 114 + u64 mkvp; /* master key verification pattern */ 115 + u8 opk[48]; /* encrypted object protection key data */ 116 + u16 adatalen; /* associated data length in bytes */ 117 + u16 fseclen; /* formated section length in bytes */ 118 + u8 more_data[]; /* more data follows */ 119 + } __packed; 120 + 97 121 /* Some defines for the CCA AES cipherkeytoken kmf1 field */ 98 122 #define KMF1_XPRT_SYM 0x8000 99 123 #define KMF1_XPRT_UASY 0x4000 ··· 147 121 int cca_check_secaescipherkey(debug_info_t *dbg, int dbflvl, 148 122 const u8 *token, int keybitsize, 149 123 int checkcpacfexport); 124 + 125 + /* 126 + * Simple check if the token is a valid CCA secure ECC private 127 + * key token. Returns 0 on success or errno value on failure. 128 + */ 129 + int cca_check_sececckeytoken(debug_info_t *dbg, int dbflvl, 130 + const u8 *token, size_t keysize, 131 + int checkcpacfexport); 150 132 151 133 /* 152 134 * Generate (random) CCA AES DATA secure key. ··· 193 159 const u8 *clrkey, u8 *keybuf, size_t *keybufsize); 194 160 195 161 /* 162 + * Derive proteced key from CCA ECC secure private key. 163 + */ 164 + int cca_ecc2protkey(u16 cardnr, u16 domain, const u8 *key, 165 + u8 *protkey, u32 *protkeylen, u32 *protkeytype); 166 + 167 + /* 196 168 * Query cryptographic facility from CCA adapter 197 169 */ 198 170 int cca_query_crypto_facility(u16 cardnr, u16 domain, ··· 226 186 * - if verify is enabled and a cur_mkvp and/or old_mkvp 227 187 * value is given, then refetch the cca_info and make sure the current 228 188 * cur_mkvp or old_mkvp values of the apqn are used. 189 + * The mktype determines which set of master keys to use: 190 + * 0 = AES_MK_SET - AES MK set, 1 = APKA MK_SET - APKA MK set 229 191 * The array of apqn entries is allocated with kmalloc and returned in *apqns; 230 192 * the number of apqns stored into the list is returned in *nr_apqns. One apqn 231 193 * entry is simple a 32 bit value with 16 bit cardnr and 16 bit domain nr and ··· 236 194 * -ENODEV is returned. 237 195 */ 238 196 int cca_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain, 239 - int minhwtype, u64 cur_mkvp, u64 old_mkvp, int verify); 197 + int minhwtype, int mktype, u64 cur_mkvp, u64 old_mkvp, 198 + int verify); 199 + 200 + #define AES_MK_SET 0 201 + #define APKA_MK_SET 1 240 202 241 203 /* struct to hold info for each CCA queue */ 242 204 struct cca_info { 243 - int hwtype; /* one of the defined AP_DEVICE_TYPE_* */ 244 - char new_mk_state; /* '1' empty, '2' partially full, '3' full */ 245 - char cur_mk_state; /* '1' invalid, '2' valid */ 246 - char old_mk_state; /* '1' invalid, '2' valid */ 247 - u64 new_mkvp; /* truncated sha256 hash of new master key */ 248 - u64 cur_mkvp; /* truncated sha256 hash of current master key */ 249 - u64 old_mkvp; /* truncated sha256 hash of old master key */ 250 - char serial[9]; /* serial number string (8 ascii numbers + 0x00) */ 205 + int hwtype; /* one of the defined AP_DEVICE_TYPE_* */ 206 + char new_aes_mk_state; /* '1' empty, '2' partially full, '3' full */ 207 + char cur_aes_mk_state; /* '1' invalid, '2' valid */ 208 + char old_aes_mk_state; /* '1' invalid, '2' valid */ 209 + char new_apka_mk_state; /* '1' empty, '2' partially full, '3' full */ 210 + char cur_apka_mk_state; /* '1' invalid, '2' valid */ 211 + char old_apka_mk_state; /* '1' invalid, '2' valid */ 212 + u64 new_aes_mkvp; /* truncated sha256 of new aes master key */ 213 + u64 cur_aes_mkvp; /* truncated sha256 of current aes master key */ 214 + u64 old_aes_mkvp; /* truncated sha256 of old aes master key */ 215 + u64 new_apka_mkvp; /* truncated sha256 of new apka master key */ 216 + u64 cur_apka_mkvp; /* truncated sha256 of current apka mk */ 217 + u64 old_apka_mkvp; /* truncated sha256 of old apka mk */ 218 + char serial[9]; /* serial number (8 ascii numbers + 0x00) */ 251 219 }; 252 220 253 221 /*
+2 -4
drivers/s390/crypto/zcrypt_cex2a.c
··· 94 94 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX2A) { 95 95 zc->min_mod_size = CEX2A_MIN_MOD_SIZE; 96 96 zc->max_mod_size = CEX2A_MAX_MOD_SIZE; 97 - memcpy(zc->speed_rating, CEX2A_SPEED_IDX, 98 - sizeof(CEX2A_SPEED_IDX)); 97 + zc->speed_rating = CEX2A_SPEED_IDX; 99 98 zc->max_exp_bit_length = CEX2A_MAX_MOD_SIZE; 100 99 zc->type_string = "CEX2A"; 101 100 zc->user_space_type = ZCRYPT_CEX2A; ··· 107 108 zc->max_mod_size = CEX3A_MAX_MOD_SIZE; 108 109 zc->max_exp_bit_length = CEX3A_MAX_MOD_SIZE; 109 110 } 110 - memcpy(zc->speed_rating, CEX3A_SPEED_IDX, 111 - sizeof(CEX3A_SPEED_IDX)); 111 + zc->speed_rating = CEX3A_SPEED_IDX; 112 112 zc->type_string = "CEX3A"; 113 113 zc->user_space_type = ZCRYPT_CEX3A; 114 114 } else {
+35 -10
drivers/s390/crypto/zcrypt_cex2c.c
··· 109 109 AP_QID_QUEUE(zq->queue->qid), 110 110 &ci, zq->online); 111 111 112 - if (ci.new_mk_state >= '1' && ci.new_mk_state <= '3') 112 + if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3') 113 113 n = scnprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n", 114 - new_state[ci.new_mk_state - '1'], ci.new_mkvp); 114 + new_state[ci.new_aes_mk_state - '1'], 115 + ci.new_aes_mkvp); 115 116 else 116 117 n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n"); 117 118 118 - if (ci.cur_mk_state >= '1' && ci.cur_mk_state <= '2') 119 + if (ci.cur_aes_mk_state >= '1' && ci.cur_aes_mk_state <= '2') 119 120 n += scnprintf(buf + n, PAGE_SIZE - n, 120 121 "AES CUR: %s 0x%016llx\n", 121 - cao_state[ci.cur_mk_state - '1'], ci.cur_mkvp); 122 + cao_state[ci.cur_aes_mk_state - '1'], 123 + ci.cur_aes_mkvp); 122 124 else 123 125 n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n"); 124 126 125 - if (ci.old_mk_state >= '1' && ci.old_mk_state <= '2') 127 + if (ci.old_aes_mk_state >= '1' && ci.old_aes_mk_state <= '2') 126 128 n += scnprintf(buf + n, PAGE_SIZE - n, 127 129 "AES OLD: %s 0x%016llx\n", 128 - cao_state[ci.old_mk_state - '1'], ci.old_mkvp); 130 + cao_state[ci.old_aes_mk_state - '1'], 131 + ci.old_aes_mkvp); 129 132 else 130 133 n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n"); 134 + 135 + 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); 140 + else 141 + n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n"); 142 + 143 + 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); 148 + else 149 + n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n"); 150 + 151 + 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); 156 + else 157 + n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n"); 131 158 132 159 return n; 133 160 } ··· 266 239 case AP_DEVICE_TYPE_CEX2C: 267 240 zc->user_space_type = ZCRYPT_CEX2C; 268 241 zc->type_string = "CEX2C"; 269 - memcpy(zc->speed_rating, CEX2C_SPEED_IDX, 270 - sizeof(CEX2C_SPEED_IDX)); 242 + zc->speed_rating = CEX2C_SPEED_IDX; 271 243 zc->min_mod_size = CEX2C_MIN_MOD_SIZE; 272 244 zc->max_mod_size = CEX2C_MAX_MOD_SIZE; 273 245 zc->max_exp_bit_length = CEX2C_MAX_MOD_SIZE; ··· 274 248 case AP_DEVICE_TYPE_CEX3C: 275 249 zc->user_space_type = ZCRYPT_CEX3C; 276 250 zc->type_string = "CEX3C"; 277 - memcpy(zc->speed_rating, CEX3C_SPEED_IDX, 278 - sizeof(CEX3C_SPEED_IDX)); 251 + zc->speed_rating = CEX3C_SPEED_IDX; 279 252 zc->min_mod_size = CEX3C_MIN_MOD_SIZE; 280 253 zc->max_mod_size = CEX3C_MAX_MOD_SIZE; 281 254 zc->max_exp_bit_length = CEX3C_MAX_MOD_SIZE;
+56 -41
drivers/s390/crypto/zcrypt_cex4.c
··· 121 121 AP_QID_QUEUE(zq->queue->qid), 122 122 &ci, zq->online); 123 123 124 - if (ci.new_mk_state >= '1' && ci.new_mk_state <= '3') 124 + if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3') 125 125 n = scnprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n", 126 - new_state[ci.new_mk_state - '1'], ci.new_mkvp); 126 + new_state[ci.new_aes_mk_state - '1'], 127 + ci.new_aes_mkvp); 127 128 else 128 129 n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n"); 129 130 130 - if (ci.cur_mk_state >= '1' && ci.cur_mk_state <= '2') 131 + if (ci.cur_aes_mk_state >= '1' && ci.cur_aes_mk_state <= '2') 131 132 n += scnprintf(buf + n, PAGE_SIZE - n, 132 133 "AES CUR: %s 0x%016llx\n", 133 - cao_state[ci.cur_mk_state - '1'], ci.cur_mkvp); 134 + cao_state[ci.cur_aes_mk_state - '1'], 135 + ci.cur_aes_mkvp); 134 136 else 135 137 n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n"); 136 138 137 - if (ci.old_mk_state >= '1' && ci.old_mk_state <= '2') 139 + if (ci.old_aes_mk_state >= '1' && ci.old_aes_mk_state <= '2') 138 140 n += scnprintf(buf + n, PAGE_SIZE - n, 139 141 "AES OLD: %s 0x%016llx\n", 140 - cao_state[ci.old_mk_state - '1'], ci.old_mkvp); 142 + cao_state[ci.old_aes_mk_state - '1'], 143 + ci.old_aes_mkvp); 141 144 else 142 145 n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n"); 146 + 147 + if (ci.new_apka_mk_state >= '1' && ci.new_apka_mk_state <= '3') 148 + n += scnprintf(buf + n, PAGE_SIZE - n, 149 + "APKA NEW: %s 0x%016llx\n", 150 + new_state[ci.new_apka_mk_state - '1'], 151 + ci.new_apka_mkvp); 152 + else 153 + n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n"); 154 + 155 + if (ci.cur_apka_mk_state >= '1' && ci.cur_apka_mk_state <= '2') 156 + n += scnprintf(buf + n, PAGE_SIZE - n, 157 + "APKA CUR: %s 0x%016llx\n", 158 + cao_state[ci.cur_apka_mk_state - '1'], 159 + ci.cur_apka_mkvp); 160 + else 161 + n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n"); 162 + 163 + if (ci.old_apka_mk_state >= '1' && ci.old_apka_mk_state <= '2') 164 + n += scnprintf(buf + n, PAGE_SIZE - n, 165 + "APKA OLD: %s 0x%016llx\n", 166 + cao_state[ci.old_apka_mk_state - '1'], 167 + ci.old_apka_mkvp); 168 + else 169 + n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n"); 143 170 144 171 return n; 145 172 } ··· 409 382 * Normalized speed ratings per crypto adapter 410 383 * MEX_1k, MEX_2k, MEX_4k, CRT_1k, CRT_2k, CRT_4k, RNG, SECKEY 411 384 */ 412 - static const int CEX4A_SPEED_IDX[] = { 385 + static const int CEX4A_SPEED_IDX[NUM_OPS] = { 413 386 14, 19, 249, 42, 228, 1458, 0, 0}; 414 - static const int CEX5A_SPEED_IDX[] = { 387 + static const int CEX5A_SPEED_IDX[NUM_OPS] = { 415 388 8, 9, 20, 18, 66, 458, 0, 0}; 416 - static const int CEX6A_SPEED_IDX[] = { 389 + static const int CEX6A_SPEED_IDX[NUM_OPS] = { 417 390 6, 9, 20, 17, 65, 438, 0, 0}; 418 - static const int CEX7A_SPEED_IDX[] = { 391 + static const int CEX7A_SPEED_IDX[NUM_OPS] = { 419 392 6, 8, 17, 15, 54, 362, 0, 0}; 420 393 421 - static const int CEX4C_SPEED_IDX[] = { 394 + static const int CEX4C_SPEED_IDX[NUM_OPS] = { 422 395 59, 69, 308, 83, 278, 2204, 209, 40}; 423 396 static const int CEX5C_SPEED_IDX[] = { 424 397 24, 31, 50, 37, 90, 479, 27, 10}; 425 - static const int CEX6C_SPEED_IDX[] = { 398 + static const int CEX6C_SPEED_IDX[NUM_OPS] = { 426 399 16, 20, 32, 27, 77, 455, 24, 9}; 427 - static const int CEX7C_SPEED_IDX[] = { 400 + static const int CEX7C_SPEED_IDX[NUM_OPS] = { 428 401 14, 16, 26, 23, 64, 376, 23, 8}; 429 402 430 - static const int CEX4P_SPEED_IDX[] = { 403 + static const int CEX4P_SPEED_IDX[NUM_OPS] = { 431 404 0, 0, 0, 0, 0, 0, 0, 50}; 432 - static const int CEX5P_SPEED_IDX[] = { 405 + static const int CEX5P_SPEED_IDX[NUM_OPS] = { 433 406 0, 0, 0, 0, 0, 0, 0, 10}; 434 - static const int CEX6P_SPEED_IDX[] = { 407 + static const int CEX6P_SPEED_IDX[NUM_OPS] = { 435 408 0, 0, 0, 0, 0, 0, 0, 9}; 436 - static const int CEX7P_SPEED_IDX[] = { 409 + static const int CEX7P_SPEED_IDX[NUM_OPS] = { 437 410 0, 0, 0, 0, 0, 0, 0, 8}; 438 411 439 412 struct ap_card *ac = to_ap_card(&ap_dev->device); ··· 449 422 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) { 450 423 zc->type_string = "CEX4A"; 451 424 zc->user_space_type = ZCRYPT_CEX4; 452 - memcpy(zc->speed_rating, CEX4A_SPEED_IDX, 453 - sizeof(CEX4A_SPEED_IDX)); 425 + zc->speed_rating = CEX4A_SPEED_IDX; 454 426 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) { 455 427 zc->type_string = "CEX5A"; 456 428 zc->user_space_type = ZCRYPT_CEX5; 457 - memcpy(zc->speed_rating, CEX5A_SPEED_IDX, 458 - sizeof(CEX5A_SPEED_IDX)); 429 + zc->speed_rating = CEX5A_SPEED_IDX; 459 430 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) { 460 431 zc->type_string = "CEX6A"; 461 432 zc->user_space_type = ZCRYPT_CEX6; 462 - memcpy(zc->speed_rating, CEX6A_SPEED_IDX, 463 - sizeof(CEX6A_SPEED_IDX)); 433 + zc->speed_rating = CEX6A_SPEED_IDX; 464 434 } else { 465 435 zc->type_string = "CEX7A"; 466 436 /* wrong user space type, just for compatibility 467 437 * with the ZCRYPT_STATUS_MASK ioctl. 468 438 */ 469 439 zc->user_space_type = ZCRYPT_CEX6; 470 - memcpy(zc->speed_rating, CEX7A_SPEED_IDX, 471 - sizeof(CEX7A_SPEED_IDX)); 440 + zc->speed_rating = CEX7A_SPEED_IDX; 472 441 } 473 442 zc->min_mod_size = CEX4A_MIN_MOD_SIZE; 474 443 if (ap_test_bit(&ac->functions, AP_FUNC_MEX4K) && ··· 484 461 * just keep it for cca compatibility 485 462 */ 486 463 zc->user_space_type = ZCRYPT_CEX3C; 487 - memcpy(zc->speed_rating, CEX4C_SPEED_IDX, 488 - sizeof(CEX4C_SPEED_IDX)); 464 + zc->speed_rating = CEX4C_SPEED_IDX; 489 465 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) { 490 466 zc->type_string = "CEX5C"; 491 467 /* wrong user space type, must be CEX5 492 468 * just keep it for cca compatibility 493 469 */ 494 470 zc->user_space_type = ZCRYPT_CEX3C; 495 - memcpy(zc->speed_rating, CEX5C_SPEED_IDX, 496 - sizeof(CEX5C_SPEED_IDX)); 471 + zc->speed_rating = CEX5C_SPEED_IDX; 497 472 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) { 498 473 zc->type_string = "CEX6C"; 499 474 /* wrong user space type, must be CEX6 500 475 * just keep it for cca compatibility 501 476 */ 502 477 zc->user_space_type = ZCRYPT_CEX3C; 503 - memcpy(zc->speed_rating, CEX6C_SPEED_IDX, 504 - sizeof(CEX6C_SPEED_IDX)); 478 + zc->speed_rating = CEX6C_SPEED_IDX; 505 479 } else { 506 480 zc->type_string = "CEX7C"; 507 481 /* wrong user space type, must be CEX7 508 482 * just keep it for cca compatibility 509 483 */ 510 484 zc->user_space_type = ZCRYPT_CEX3C; 511 - memcpy(zc->speed_rating, CEX7C_SPEED_IDX, 512 - sizeof(CEX7C_SPEED_IDX)); 485 + zc->speed_rating = CEX7C_SPEED_IDX; 513 486 } 514 487 zc->min_mod_size = CEX4C_MIN_MOD_SIZE; 515 488 zc->max_mod_size = CEX4C_MAX_MOD_SIZE; ··· 514 495 if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) { 515 496 zc->type_string = "CEX4P"; 516 497 zc->user_space_type = ZCRYPT_CEX4; 517 - memcpy(zc->speed_rating, CEX4P_SPEED_IDX, 518 - sizeof(CEX4P_SPEED_IDX)); 498 + zc->speed_rating = CEX4P_SPEED_IDX; 519 499 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) { 520 500 zc->type_string = "CEX5P"; 521 501 zc->user_space_type = ZCRYPT_CEX5; 522 - memcpy(zc->speed_rating, CEX5P_SPEED_IDX, 523 - sizeof(CEX5P_SPEED_IDX)); 502 + zc->speed_rating = CEX5P_SPEED_IDX; 524 503 } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) { 525 504 zc->type_string = "CEX6P"; 526 505 zc->user_space_type = ZCRYPT_CEX6; 527 - memcpy(zc->speed_rating, CEX6P_SPEED_IDX, 528 - sizeof(CEX6P_SPEED_IDX)); 506 + zc->speed_rating = CEX6P_SPEED_IDX; 529 507 } else { 530 508 zc->type_string = "CEX7P"; 531 509 /* wrong user space type, just for compatibility 532 510 * with the ZCRYPT_STATUS_MASK ioctl. 533 511 */ 534 512 zc->user_space_type = ZCRYPT_CEX6; 535 - memcpy(zc->speed_rating, CEX7P_SPEED_IDX, 536 - sizeof(CEX7P_SPEED_IDX)); 513 + zc->speed_rating = CEX7P_SPEED_IDX; 537 514 } 538 515 zc->min_mod_size = CEX4C_MIN_MOD_SIZE; 539 516 zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
+8
drivers/s390/crypto/zcrypt_debug.h
··· 21 21 22 22 #define ZCRYPT_DBF(...) \ 23 23 debug_sprintf_event(zcrypt_dbf_info, ##__VA_ARGS__) 24 + #define ZCRYPT_DBF_ERR(...) \ 25 + debug_sprintf_event(zcrypt_dbf_info, DBF_ERR, ##__VA_ARGS__) 26 + #define ZCRYPT_DBF_WARN(...) \ 27 + debug_sprintf_event(zcrypt_dbf_info, DBF_WARN, ##__VA_ARGS__) 28 + #define ZCRYPT_DBF_INFO(...) \ 29 + debug_sprintf_event(zcrypt_dbf_info, DBF_INFO, ##__VA_ARGS__) 30 + #define ZCRYPT_DBF_DBG(...) \ 31 + debug_sprintf_event(zcrypt_dbf_info, DBF_DEBUG, ##__VA_ARGS__) 24 32 25 33 extern debug_info_t *zcrypt_dbf_info; 26 34
+252 -74
drivers/s390/crypto/zcrypt_ep11misc.c
··· 15 15 #include <linux/random.h> 16 16 #include <asm/zcrypt.h> 17 17 #include <asm/pkey.h> 18 + #include <crypto/aes.h> 18 19 19 20 #include "ap_bus.h" 20 21 #include "zcrypt_api.h" ··· 114 113 } 115 114 116 115 /* 117 - * Simple check if the key blob is a valid EP11 secure AES key. 116 + * Simple check if the key blob is a valid EP11 AES key blob with header. 118 117 */ 119 - int ep11_check_aeskeyblob(debug_info_t *dbg, int dbflvl, 120 - const u8 *key, int keybitsize, 121 - int checkcpacfexport) 118 + int ep11_check_aes_key_with_hdr(debug_info_t *dbg, int dbflvl, 119 + const u8 *key, size_t keylen, int checkcpacfexp) 120 + { 121 + struct ep11kblob_header *hdr = (struct ep11kblob_header *) key; 122 + struct ep11keyblob *kb = (struct ep11keyblob *) (key + sizeof(*hdr)); 123 + 124 + #define DBF(...) debug_sprintf_event(dbg, dbflvl, ##__VA_ARGS__) 125 + 126 + if (keylen < sizeof(*hdr) + sizeof(*kb)) { 127 + DBF("%s key check failed, keylen %zu < %zu\n", 128 + __func__, keylen, sizeof(*hdr) + sizeof(*kb)); 129 + return -EINVAL; 130 + } 131 + 132 + if (hdr->type != TOKTYPE_NON_CCA) { 133 + if (dbg) 134 + DBF("%s key check failed, type 0x%02x != 0x%02x\n", 135 + __func__, (int) hdr->type, TOKTYPE_NON_CCA); 136 + return -EINVAL; 137 + } 138 + if (hdr->hver != 0x00) { 139 + if (dbg) 140 + DBF("%s key check failed, header version 0x%02x != 0x00\n", 141 + __func__, (int) hdr->hver); 142 + return -EINVAL; 143 + } 144 + if (hdr->version != TOKVER_EP11_AES_WITH_HEADER) { 145 + if (dbg) 146 + DBF("%s key check failed, version 0x%02x != 0x%02x\n", 147 + __func__, (int) hdr->version, TOKVER_EP11_AES_WITH_HEADER); 148 + return -EINVAL; 149 + } 150 + if (hdr->len > keylen) { 151 + if (dbg) 152 + DBF("%s key check failed, header len %d keylen %zu mismatch\n", 153 + __func__, (int) hdr->len, keylen); 154 + return -EINVAL; 155 + } 156 + if (hdr->len < sizeof(*hdr) + sizeof(*kb)) { 157 + if (dbg) 158 + DBF("%s key check failed, header len %d < %zu\n", 159 + __func__, (int) hdr->len, sizeof(*hdr) + sizeof(*kb)); 160 + return -EINVAL; 161 + } 162 + 163 + if (kb->version != EP11_STRUCT_MAGIC) { 164 + if (dbg) 165 + DBF("%s key check failed, blob magic 0x%04x != 0x%04x\n", 166 + __func__, (int) kb->version, EP11_STRUCT_MAGIC); 167 + return -EINVAL; 168 + } 169 + if (checkcpacfexp && !(kb->attr & EP11_BLOB_PKEY_EXTRACTABLE)) { 170 + if (dbg) 171 + DBF("%s key check failed, PKEY_EXTRACTABLE is off\n", 172 + __func__); 173 + return -EINVAL; 174 + } 175 + 176 + #undef DBF 177 + 178 + return 0; 179 + } 180 + EXPORT_SYMBOL(ep11_check_aes_key_with_hdr); 181 + 182 + /* 183 + * Simple check if the key blob is a valid EP11 ECC key blob with header. 184 + */ 185 + int ep11_check_ecc_key_with_hdr(debug_info_t *dbg, int dbflvl, 186 + const u8 *key, size_t keylen, int checkcpacfexp) 187 + { 188 + struct ep11kblob_header *hdr = (struct ep11kblob_header *) key; 189 + struct ep11keyblob *kb = (struct ep11keyblob *) (key + sizeof(*hdr)); 190 + 191 + #define DBF(...) debug_sprintf_event(dbg, dbflvl, ##__VA_ARGS__) 192 + 193 + if (keylen < sizeof(*hdr) + sizeof(*kb)) { 194 + DBF("%s key check failed, keylen %zu < %zu\n", 195 + __func__, keylen, sizeof(*hdr) + sizeof(*kb)); 196 + return -EINVAL; 197 + } 198 + 199 + if (hdr->type != TOKTYPE_NON_CCA) { 200 + if (dbg) 201 + DBF("%s key check failed, type 0x%02x != 0x%02x\n", 202 + __func__, (int) hdr->type, TOKTYPE_NON_CCA); 203 + return -EINVAL; 204 + } 205 + if (hdr->hver != 0x00) { 206 + if (dbg) 207 + DBF("%s key check failed, header version 0x%02x != 0x00\n", 208 + __func__, (int) hdr->hver); 209 + return -EINVAL; 210 + } 211 + if (hdr->version != TOKVER_EP11_ECC_WITH_HEADER) { 212 + if (dbg) 213 + DBF("%s key check failed, version 0x%02x != 0x%02x\n", 214 + __func__, (int) hdr->version, TOKVER_EP11_ECC_WITH_HEADER); 215 + return -EINVAL; 216 + } 217 + if (hdr->len > keylen) { 218 + if (dbg) 219 + DBF("%s key check failed, header len %d keylen %zu mismatch\n", 220 + __func__, (int) hdr->len, keylen); 221 + return -EINVAL; 222 + } 223 + if (hdr->len < sizeof(*hdr) + sizeof(*kb)) { 224 + if (dbg) 225 + DBF("%s key check failed, header len %d < %zu\n", 226 + __func__, (int) hdr->len, sizeof(*hdr) + sizeof(*kb)); 227 + return -EINVAL; 228 + } 229 + 230 + if (kb->version != EP11_STRUCT_MAGIC) { 231 + if (dbg) 232 + DBF("%s key check failed, blob magic 0x%04x != 0x%04x\n", 233 + __func__, (int) kb->version, EP11_STRUCT_MAGIC); 234 + return -EINVAL; 235 + } 236 + if (checkcpacfexp && !(kb->attr & EP11_BLOB_PKEY_EXTRACTABLE)) { 237 + if (dbg) 238 + DBF("%s key check failed, PKEY_EXTRACTABLE is off\n", 239 + __func__); 240 + return -EINVAL; 241 + } 242 + 243 + #undef DBF 244 + 245 + return 0; 246 + } 247 + EXPORT_SYMBOL(ep11_check_ecc_key_with_hdr); 248 + 249 + /* 250 + * Simple check if the key blob is a valid EP11 AES key blob with 251 + * the header in the session field (old style EP11 AES key). 252 + */ 253 + int ep11_check_aes_key(debug_info_t *dbg, int dbflvl, 254 + const u8 *key, size_t keylen, int checkcpacfexp) 122 255 { 123 256 struct ep11keyblob *kb = (struct ep11keyblob *) key; 124 257 125 258 #define DBF(...) debug_sprintf_event(dbg, dbflvl, ##__VA_ARGS__) 259 + 260 + if (keylen < sizeof(*kb)) { 261 + DBF("%s key check failed, keylen %zu < %zu\n", 262 + __func__, keylen, sizeof(*kb)); 263 + return -EINVAL; 264 + } 126 265 127 266 if (kb->head.type != TOKTYPE_NON_CCA) { 128 267 if (dbg) ··· 276 135 __func__, (int) kb->head.version, TOKVER_EP11_AES); 277 136 return -EINVAL; 278 137 } 138 + if (kb->head.len > keylen) { 139 + if (dbg) 140 + DBF("%s key check failed, header len %d keylen %zu mismatch\n", 141 + __func__, (int) kb->head.len, keylen); 142 + return -EINVAL; 143 + } 144 + if (kb->head.len < sizeof(*kb)) { 145 + if (dbg) 146 + DBF("%s key check failed, header len %d < %zu\n", 147 + __func__, (int) kb->head.len, sizeof(*kb)); 148 + return -EINVAL; 149 + } 150 + 279 151 if (kb->version != EP11_STRUCT_MAGIC) { 280 152 if (dbg) 281 - DBF("%s key check failed, magic 0x%04x != 0x%04x\n", 153 + DBF("%s key check failed, blob magic 0x%04x != 0x%04x\n", 282 154 __func__, (int) kb->version, EP11_STRUCT_MAGIC); 283 155 return -EINVAL; 284 156 } 285 - switch (kb->head.keybitlen) { 286 - case 128: 287 - case 192: 288 - case 256: 289 - break; 290 - default: 157 + if (checkcpacfexp && !(kb->attr & EP11_BLOB_PKEY_EXTRACTABLE)) { 291 158 if (dbg) 292 - DBF("%s key check failed, keybitlen %d invalid\n", 293 - __func__, (int) kb->head.keybitlen); 294 - return -EINVAL; 295 - } 296 - if (keybitsize > 0 && keybitsize != (int) kb->head.keybitlen) { 297 - DBF("%s key check failed, keybitsize %d\n", 298 - __func__, keybitsize); 299 - return -EINVAL; 300 - } 301 - if (checkcpacfexport && !(kb->attr & EP11_BLOB_PKEY_EXTRACTABLE)) { 302 - if (dbg) 303 - DBF("%s key check failed, PKEY_EXTRACTABLE is 0\n", 159 + DBF("%s key check failed, PKEY_EXTRACTABLE is off\n", 304 160 __func__); 305 161 return -EINVAL; 306 162 } 163 + 307 164 #undef DBF 308 165 309 166 return 0; 310 167 } 311 - EXPORT_SYMBOL(ep11_check_aeskeyblob); 312 - 313 - /* 314 - * Helper function which calls zcrypt_send_ep11_cprb with 315 - * memory management segment adjusted to kernel space 316 - * so that the copy_from_user called within this 317 - * function do in fact copy from kernel space. 318 - */ 319 - static inline int _zcrypt_send_ep11_cprb(struct ep11_urb *urb) 320 - { 321 - int rc; 322 - mm_segment_t old_fs = get_fs(); 323 - 324 - set_fs(KERNEL_DS); 325 - rc = zcrypt_send_ep11_cprb(urb); 326 - set_fs(old_fs); 327 - 328 - return rc; 329 - } 168 + EXPORT_SYMBOL(ep11_check_aes_key); 330 169 331 170 /* 332 171 * Allocate and prepare ep11 cprb plus additional payload. ··· 520 399 req, sizeof(*req) + sizeof(*req_pl), 521 400 rep, sizeof(*rep) + sizeof(*rep_pl) + buflen); 522 401 523 - rc = _zcrypt_send_ep11_cprb(urb); 402 + rc = zcrypt_send_ep11_cprb(urb); 524 403 if (rc) { 525 404 DEBUG_ERR( 526 405 "%s zcrypt_send_ep11_cprb(card=%d dom=%d) failed, rc=%d\n", ··· 758 637 req, sizeof(*req) + sizeof(*req_pl), 759 638 rep, sizeof(*rep) + sizeof(*rep_pl)); 760 639 761 - rc = _zcrypt_send_ep11_cprb(urb); 640 + rc = zcrypt_send_ep11_cprb(urb); 762 641 if (rc) { 763 642 DEBUG_ERR( 764 643 "%s zcrypt_send_ep11_cprb(card=%d dom=%d) failed, rc=%d\n", ··· 878 757 req, sizeof(*req) + req_pl_size, 879 758 rep, sizeof(*rep) + rep_pl_size); 880 759 881 - rc = _zcrypt_send_ep11_cprb(urb); 760 + rc = zcrypt_send_ep11_cprb(urb); 882 761 if (rc) { 883 762 DEBUG_ERR( 884 763 "%s zcrypt_send_ep11_cprb(card=%d dom=%d) failed, rc=%d\n", ··· 1026 905 req, sizeof(*req) + req_pl_size, 1027 906 rep, sizeof(*rep) + sizeof(*rep_pl)); 1028 907 1029 - rc = _zcrypt_send_ep11_cprb(urb); 908 + rc = zcrypt_send_ep11_cprb(urb); 1030 909 if (rc) { 1031 910 DEBUG_ERR( 1032 911 "%s zcrypt_send_ep11_cprb(card=%d dom=%d) failed, rc=%d\n", ··· 1093 972 u8 data_tag; 1094 973 u8 data_lenfmt; 1095 974 u16 data_len; 1096 - u8 data[512]; 975 + u8 data[1024]; 1097 976 } __packed * rep_pl; 1098 977 struct ep11_cprb *req = NULL, *rep = NULL; 1099 978 struct ep11_target_dev target; ··· 1101 980 struct ep11keyblob *kb; 1102 981 size_t req_pl_size; 1103 982 int api, rc = -ENOMEM; 983 + bool has_header = false; 1104 984 u8 *p; 985 + 986 + /* maybe the session field holds a header with key info */ 987 + kb = (struct ep11keyblob *) key; 988 + if (kb->head.type == TOKTYPE_NON_CCA && 989 + kb->head.version == TOKVER_EP11_AES) { 990 + has_header = true; 991 + keysize = kb->head.len < keysize ? kb->head.len : keysize; 992 + } 1105 993 1106 994 /* request cprb and payload */ 1107 995 req_pl_size = sizeof(struct wk_req_pl) + (iv ? 16 : 0) ··· 1137 1007 /* key blob */ 1138 1008 p += asn1tag_write(p, 0x04, key, keysize); 1139 1009 /* maybe the key argument needs the head data cleaned out */ 1140 - kb = (struct ep11keyblob *)(p - keysize); 1141 - if (kb->head.version == TOKVER_EP11_AES) 1010 + if (has_header) { 1011 + kb = (struct ep11keyblob *)(p - keysize); 1142 1012 memset(&kb->head, 0, sizeof(kb->head)); 1013 + } 1143 1014 /* empty kek tag */ 1144 1015 *p++ = 0x04; 1145 1016 *p++ = 0; ··· 1164 1033 req, sizeof(*req) + req_pl_size, 1165 1034 rep, sizeof(*rep) + sizeof(*rep_pl)); 1166 1035 1167 - rc = _zcrypt_send_ep11_cprb(urb); 1036 + rc = zcrypt_send_ep11_cprb(urb); 1168 1037 if (rc) { 1169 1038 DEBUG_ERR( 1170 1039 "%s zcrypt_send_ep11_cprb(card=%d dom=%d) failed, rc=%d\n", ··· 1263 1132 } 1264 1133 EXPORT_SYMBOL(ep11_clr2keyblob); 1265 1134 1266 - int ep11_key2protkey(u16 card, u16 dom, const u8 *key, size_t keylen, 1267 - u8 *protkey, u32 *protkeylen, u32 *protkeytype) 1135 + int ep11_kblob2protkey(u16 card, u16 dom, const u8 *keyblob, size_t keybloblen, 1136 + u8 *protkey, u32 *protkeylen, u32 *protkeytype) 1268 1137 { 1269 1138 int rc = -EIO; 1270 1139 u8 *wkbuf = NULL; 1271 - size_t wkbuflen = 256; 1140 + size_t wkbuflen, keylen; 1272 1141 struct wk_info { 1273 1142 u16 version; 1274 1143 u8 res1[16]; ··· 1278 1147 u8 res2[8]; 1279 1148 u8 pkey[0]; 1280 1149 } __packed * wki; 1150 + const u8 *key; 1151 + struct ep11kblob_header *hdr; 1152 + 1153 + /* key with or without header ? */ 1154 + hdr = (struct ep11kblob_header *) keyblob; 1155 + if (hdr->type == TOKTYPE_NON_CCA 1156 + && (hdr->version == TOKVER_EP11_AES_WITH_HEADER 1157 + || hdr->version == TOKVER_EP11_ECC_WITH_HEADER) 1158 + && is_ep11_keyblob(keyblob + sizeof(struct ep11kblob_header))) { 1159 + /* EP11 AES or ECC key with header */ 1160 + key = keyblob + sizeof(struct ep11kblob_header); 1161 + keylen = hdr->len - sizeof(struct ep11kblob_header); 1162 + } else if (hdr->type == TOKTYPE_NON_CCA 1163 + && hdr->version == TOKVER_EP11_AES 1164 + && is_ep11_keyblob(keyblob)) { 1165 + /* EP11 AES key (old style) */ 1166 + key = keyblob; 1167 + keylen = hdr->len; 1168 + } else if (is_ep11_keyblob(keyblob)) { 1169 + /* raw EP11 key blob */ 1170 + key = keyblob; 1171 + keylen = keybloblen; 1172 + } else 1173 + return -EINVAL; 1281 1174 1282 1175 /* alloc temp working buffer */ 1176 + wkbuflen = (keylen + AES_BLOCK_SIZE) & (~(AES_BLOCK_SIZE - 1)); 1283 1177 wkbuf = kmalloc(wkbuflen, GFP_ATOMIC); 1284 1178 if (!wkbuf) 1285 1179 return -ENOMEM; ··· 1321 1165 wki = (struct wk_info *) wkbuf; 1322 1166 1323 1167 /* check struct version and pkey type */ 1324 - if (wki->version != 1 || wki->pkeytype != 1) { 1168 + if (wki->version != 1 || wki->pkeytype < 1 || wki->pkeytype > 5) { 1325 1169 DEBUG_ERR("%s wk info version %d or pkeytype %d mismatch.\n", 1326 1170 __func__, (int) wki->version, (int) wki->pkeytype); 1327 1171 rc = -EIO; 1328 1172 goto out; 1329 1173 } 1330 1174 1331 - /* copy the tanslated protected key */ 1332 - switch (wki->pkeysize) { 1333 - case 16+32: 1334 - /* AES 128 protected key */ 1335 - if (protkeytype) 1336 - *protkeytype = PKEY_KEYTYPE_AES_128; 1175 + /* check protected key type field */ 1176 + switch (wki->pkeytype) { 1177 + case 1: /* AES */ 1178 + switch (wki->pkeysize) { 1179 + case 16+32: 1180 + /* AES 128 protected key */ 1181 + if (protkeytype) 1182 + *protkeytype = PKEY_KEYTYPE_AES_128; 1183 + break; 1184 + case 24+32: 1185 + /* AES 192 protected key */ 1186 + if (protkeytype) 1187 + *protkeytype = PKEY_KEYTYPE_AES_192; 1188 + break; 1189 + case 32+32: 1190 + /* AES 256 protected key */ 1191 + if (protkeytype) 1192 + *protkeytype = PKEY_KEYTYPE_AES_256; 1193 + break; 1194 + default: 1195 + DEBUG_ERR("%s unknown/unsupported AES pkeysize %d\n", 1196 + __func__, (int) wki->pkeysize); 1197 + rc = -EIO; 1198 + goto out; 1199 + } 1337 1200 break; 1338 - case 24+32: 1339 - /* AES 192 protected key */ 1201 + case 3: /* EC-P */ 1202 + case 4: /* EC-ED */ 1203 + case 5: /* EC-BP */ 1340 1204 if (protkeytype) 1341 - *protkeytype = PKEY_KEYTYPE_AES_192; 1205 + *protkeytype = PKEY_KEYTYPE_ECC; 1342 1206 break; 1343 - case 32+32: 1344 - /* AES 256 protected key */ 1345 - if (protkeytype) 1346 - *protkeytype = PKEY_KEYTYPE_AES_256; 1347 - break; 1207 + case 2: /* TDES */ 1348 1208 default: 1349 - DEBUG_ERR("%s unknown/unsupported pkeysize %d\n", 1350 - __func__, (int) wki->pkeysize); 1209 + DEBUG_ERR("%s unknown/unsupported key type %d\n", 1210 + __func__, (int) wki->pkeytype); 1351 1211 rc = -EIO; 1352 1212 goto out; 1353 1213 } 1214 + 1215 + /* copy the tanslated protected key */ 1216 + if (wki->pkeysize > *protkeylen) { 1217 + DEBUG_ERR("%s wk info pkeysize %llu > protkeysize %u\n", 1218 + __func__, wki->pkeysize, *protkeylen); 1219 + rc = -EINVAL; 1220 + goto out; 1221 + } 1354 1222 memcpy(protkey, wki->pkey, wki->pkeysize); 1355 - if (protkeylen) 1356 - *protkeylen = (u32) wki->pkeysize; 1357 - rc = 0; 1223 + *protkeylen = wki->pkeysize; 1358 1224 1359 1225 out: 1360 1226 kfree(wkbuf); 1361 1227 return rc; 1362 1228 } 1363 - EXPORT_SYMBOL(ep11_key2protkey); 1229 + EXPORT_SYMBOL(ep11_kblob2protkey); 1364 1230 1365 1231 int ep11_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain, 1366 1232 int minhwtype, int minapi, const u8 *wkvp)
+47 -16
drivers/s390/crypto/zcrypt_ep11misc.h
··· 12 12 #include <asm/zcrypt.h> 13 13 #include <asm/pkey.h> 14 14 15 - #define TOKVER_EP11_AES 0x03 /* EP11 AES key blob */ 16 - 17 15 #define EP11_API_V 4 /* highest known and supported EP11 API version */ 18 - 19 16 #define EP11_STRUCT_MAGIC 0x1234 20 - #define EP11_BLOB_PKEY_EXTRACTABLE 0x200000 17 + #define EP11_BLOB_PKEY_EXTRACTABLE 0x00200000 18 + 19 + /* 20 + * Internal used values for the version field of the key header. 21 + * Should match to the enum pkey_key_type in pkey.h. 22 + */ 23 + #define TOKVER_EP11_AES 0x03 /* EP11 AES key blob (old style) */ 24 + #define TOKVER_EP11_AES_WITH_HEADER 0x06 /* EP11 AES key blob with header */ 25 + #define TOKVER_EP11_ECC_WITH_HEADER 0x07 /* EP11 ECC key blob with header */ 21 26 22 27 /* inside view of an EP11 secure key blob */ 23 28 struct ep11keyblob { 24 29 union { 25 30 u8 session[32]; 31 + /* only used for PKEY_TYPE_EP11: */ 26 32 struct { 27 33 u8 type; /* 0x00 (TOKTYPE_NON_CCA) */ 28 34 u8 res0; /* unused */ 29 35 u16 len; /* total length in bytes of this blob */ 30 - u8 version; /* 0x06 (TOKVER_EP11_AES) */ 36 + u8 version; /* 0x03 (TOKVER_EP11_AES) */ 31 37 u8 res1; /* unused */ 32 38 u16 keybitlen; /* clear key bit len, 0 for unknown */ 33 39 } head; ··· 47 41 u8 mac[32]; 48 42 } __packed; 49 43 44 + /* check ep11 key magic to find out if this is an ep11 key blob */ 45 + static inline bool is_ep11_keyblob(const u8 *key) 46 + { 47 + struct ep11keyblob *kb = (struct ep11keyblob *) key; 48 + 49 + return (kb->version == EP11_STRUCT_MAGIC); 50 + } 51 + 50 52 /* 51 - * Simple check if the key blob is a valid EP11 secure AES key. 52 - * If keybitsize is given, the bitsize of the key is also checked. 53 + * Simple check if the key blob is a valid EP11 AES key blob with header. 53 54 * If checkcpacfexport is enabled, the key is also checked for the 54 55 * attributes needed to export this key for CPACF use. 55 56 * Returns 0 on success or errno value on failure. 56 57 */ 57 - int ep11_check_aeskeyblob(debug_info_t *dbg, int dbflvl, 58 - const u8 *key, int keybitsize, 59 - int checkcpacfexport); 58 + int ep11_check_aes_key_with_hdr(debug_info_t *dbg, int dbflvl, 59 + const u8 *key, size_t keylen, int checkcpacfexp); 60 + 61 + /* 62 + * Simple check if the key blob is a valid EP11 ECC key blob with header. 63 + * If checkcpacfexport is enabled, the key is also checked for the 64 + * attributes needed to export this key for CPACF use. 65 + * Returns 0 on success or errno value on failure. 66 + */ 67 + int ep11_check_ecc_key_with_hdr(debug_info_t *dbg, int dbflvl, 68 + const u8 *key, size_t keylen, int checkcpacfexp); 69 + 70 + /* 71 + * Simple check if the key blob is a valid EP11 AES key blob with 72 + * the header in the session field (old style EP11 AES key). 73 + * If checkcpacfexport is enabled, the key is also checked for the 74 + * attributes needed to export this key for CPACF use. 75 + * Returns 0 on success or errno value on failure. 76 + */ 77 + int ep11_check_aes_key(debug_info_t *dbg, int dbflvl, 78 + const u8 *key, size_t keylen, int checkcpacfexp); 60 79 61 80 /* EP11 card info struct */ 62 81 struct ep11_card_info { ··· 123 92 const u8 *clrkey, u8 *keybuf, size_t *keybufsize); 124 93 125 94 /* 126 - * Derive proteced key from EP11 AES secure key blob. 127 - */ 128 - int ep11_key2protkey(u16 cardnr, u16 domain, const u8 *key, size_t keylen, 129 - u8 *protkey, u32 *protkeylen, u32 *protkeytype); 130 - 131 - /* 132 95 * Build a list of ep11 apqns meeting the following constrains: 133 96 * - apqn is online and is in fact an EP11 apqn 134 97 * - if cardnr is not FFFF only apqns with this cardnr ··· 143 118 */ 144 119 int ep11_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain, 145 120 int minhwtype, int minapi, const u8 *wkvp); 121 + 122 + /* 123 + * Derive proteced key from EP11 key blob (AES and ECC keys). 124 + */ 125 + int ep11_kblob2protkey(u16 card, u16 dom, const u8 *key, size_t keylen, 126 + u8 *protkey, u32 *protkeylen, u32 *protkeytype); 146 127 147 128 void zcrypt_ep11misc_exit(void); 148 129
+32 -56
drivers/s390/crypto/zcrypt_error.h
··· 52 52 #define REP82_ERROR_INVALID_COMMAND 0x30 53 53 #define REP82_ERROR_MALFORMED_MSG 0x40 54 54 #define REP82_ERROR_INVALID_SPECIAL_CMD 0x41 55 - #define REP82_ERROR_INVALID_DOMAIN_PRECHECK 0x42 56 55 #define REP82_ERROR_RESERVED_FIELDO 0x50 /* old value */ 57 56 #define REP82_ERROR_WORD_ALIGNMENT 0x60 58 57 #define REP82_ERROR_MESSAGE_LENGTH 0x80 ··· 66 67 #define REP82_ERROR_ZERO_BUFFER_LEN 0xB0 67 68 68 69 #define REP88_ERROR_MODULE_FAILURE 0x10 69 - 70 70 #define REP88_ERROR_MESSAGE_TYPE 0x20 71 71 #define REP88_ERROR_MESSAGE_MALFORMD 0x22 72 72 #define REP88_ERROR_MESSAGE_LENGTH 0x23 ··· 83 85 int queue = AP_QID_QUEUE(zq->queue->qid); 84 86 85 87 switch (ehdr->reply_code) { 86 - case REP82_ERROR_OPERAND_INVALID: 87 - case REP82_ERROR_OPERAND_SIZE: 88 - case REP82_ERROR_EVEN_MOD_IN_OPND: 89 - case REP88_ERROR_MESSAGE_MALFORMD: 90 - case REP82_ERROR_INVALID_DOMAIN_PRECHECK: 91 - case REP82_ERROR_INVALID_DOMAIN_PENDING: 92 - case REP82_ERROR_INVALID_SPECIAL_CMD: 93 - case REP82_ERROR_FILTERED_BY_HYPERVISOR: 94 - // REP88_ERROR_INVALID_KEY // '82' CEX2A 95 - // REP88_ERROR_OPERAND // '84' CEX2A 96 - // REP88_ERROR_OPERAND_EVEN_MOD // '85' CEX2A 97 - /* Invalid input data. */ 88 + case REP82_ERROR_INVALID_MSG_LEN: /* 0x23 */ 89 + case REP82_ERROR_RESERVD_FIELD: /* 0x24 */ 90 + case REP82_ERROR_FORMAT_FIELD: /* 0x29 */ 91 + case REP82_ERROR_MALFORMED_MSG: /* 0x40 */ 92 + case REP82_ERROR_INVALID_SPECIAL_CMD: /* 0x41 */ 93 + case REP82_ERROR_MESSAGE_LENGTH: /* 0x80 */ 94 + case REP82_ERROR_OPERAND_INVALID: /* 0x82 */ 95 + case REP82_ERROR_OPERAND_SIZE: /* 0x84 */ 96 + case REP82_ERROR_EVEN_MOD_IN_OPND: /* 0x85 */ 97 + case REP82_ERROR_INVALID_DOMAIN_PENDING: /* 0x8A */ 98 + case REP82_ERROR_FILTERED_BY_HYPERVISOR: /* 0x8B */ 99 + case REP82_ERROR_PACKET_TRUNCATED: /* 0xA0 */ 100 + case REP88_ERROR_MESSAGE_MALFORMD: /* 0x22 */ 101 + case REP88_ERROR_KEY_TYPE: /* 0x34 */ 102 + /* RY indicates malformed request */ 98 103 ZCRYPT_DBF(DBF_WARN, 99 - "device=%02x.%04x reply=0x%02x => rc=EINVAL\n", 104 + "dev=%02x.%04x RY=0x%02x => rc=EINVAL\n", 100 105 card, queue, ehdr->reply_code); 101 106 return -EINVAL; 102 - case REP82_ERROR_MESSAGE_TYPE: 103 - // REP88_ERROR_MESSAGE_TYPE // '20' CEX2A 107 + case REP82_ERROR_MACHINE_FAILURE: /* 0x10 */ 108 + case REP82_ERROR_MESSAGE_TYPE: /* 0x20 */ 109 + case REP82_ERROR_TRANSPORT_FAIL: /* 0x90 */ 104 110 /* 105 - * To sent a message of the wrong type is a bug in the 106 - * device driver. Send error msg, disable the device 107 - * and then repeat the request. 111 + * Msg to wrong type or card/infrastructure failure. 112 + * Trigger rescan of the ap bus, trigger retry request. 108 113 */ 109 114 atomic_set(&zcrypt_rescan_req, 1); 110 - zq->online = 0; 111 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 112 - card, queue); 113 - ZCRYPT_DBF(DBF_ERR, 114 - "device=%02x.%04x reply=0x%02x => online=0 rc=EAGAIN\n", 115 - card, queue, ehdr->reply_code); 116 - return -EAGAIN; 117 - case REP82_ERROR_TRANSPORT_FAIL: 118 - /* Card or infrastructure failure, disable card */ 119 - atomic_set(&zcrypt_rescan_req, 1); 120 - zq->online = 0; 121 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 122 - card, queue); 123 115 /* For type 86 response show the apfs value (failure reason) */ 124 - if (ehdr->type == TYPE86_RSP_CODE) { 116 + if (ehdr->reply_code == REP82_ERROR_TRANSPORT_FAIL && 117 + ehdr->type == TYPE86_RSP_CODE) { 125 118 struct { 126 119 struct type86_hdr hdr; 127 120 struct type86_fmt2_ext fmt2; 128 121 } __packed * head = reply->msg; 129 122 unsigned int apfs = *((u32 *)head->fmt2.apfs); 130 123 131 - ZCRYPT_DBF(DBF_ERR, 132 - "device=%02x.%04x reply=0x%02x apfs=0x%x => online=0 rc=EAGAIN\n", 133 - card, queue, apfs, ehdr->reply_code); 124 + ZCRYPT_DBF(DBF_WARN, 125 + "dev=%02x.%04x RY=0x%02x apfs=0x%x => bus rescan, rc=EAGAIN\n", 126 + card, queue, ehdr->reply_code, apfs); 134 127 } else 135 - ZCRYPT_DBF(DBF_ERR, 136 - "device=%02x.%04x reply=0x%02x => online=0 rc=EAGAIN\n", 128 + ZCRYPT_DBF(DBF_WARN, 129 + "dev=%02x.%04x RY=0x%02x => bus rescan, rc=EAGAIN\n", 137 130 card, queue, ehdr->reply_code); 138 131 return -EAGAIN; 139 - case REP82_ERROR_MACHINE_FAILURE: 140 - // REP88_ERROR_MODULE_FAILURE // '10' CEX2A 141 - /* If a card fails disable it and repeat the request. */ 142 - atomic_set(&zcrypt_rescan_req, 1); 143 - zq->online = 0; 144 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 145 - card, queue); 146 - ZCRYPT_DBF(DBF_ERR, 147 - "device=%02x.%04x reply=0x%02x => online=0 rc=EAGAIN\n", 132 + default: 133 + /* Assume request is valid and a retry will be worth it */ 134 + ZCRYPT_DBF(DBF_WARN, 135 + "dev=%02x.%04x RY=0x%02x => rc=EAGAIN\n", 148 136 card, queue, ehdr->reply_code); 149 137 return -EAGAIN; 150 - default: 151 - zq->online = 0; 152 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 153 - card, queue); 154 - ZCRYPT_DBF(DBF_ERR, 155 - "device=%02x.%04x reply=0x%02x => online=0 rc=EAGAIN\n", 156 - card, queue, ehdr->reply_code); 157 - return -EAGAIN; /* repeat the request on a different device. */ 158 138 } 159 139 } 160 140
+73 -58
drivers/s390/crypto/zcrypt_msgtype50.c
··· 246 246 copy_from_user(exp, mex->b_key, mod_len) || 247 247 copy_from_user(inp, mex->inputdata, mod_len)) 248 248 return -EFAULT; 249 + 250 + #ifdef CONFIG_ZCRYPT_DEBUG 251 + if (ap_msg->fi.flags & AP_FI_FLAG_TOGGLE_SPECIAL) 252 + ap_msg->flags ^= AP_MSG_FLAG_SPECIAL; 253 + #endif 254 + 249 255 return 0; 250 256 } 251 257 ··· 338 332 copy_from_user(inp, crt->inputdata, mod_len)) 339 333 return -EFAULT; 340 334 335 + #ifdef CONFIG_ZCRYPT_DEBUG 336 + if (ap_msg->fi.flags & AP_FI_FLAG_TOGGLE_SPECIAL) 337 + ap_msg->flags ^= AP_MSG_FLAG_SPECIAL; 338 + #endif 339 + 341 340 return 0; 342 341 } 343 342 ··· 367 356 if (t80h->len < sizeof(*t80h) + outputdatalength) { 368 357 /* The result is too short, the CEXxA card may not do that.. */ 369 358 zq->online = 0; 370 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 359 + pr_err("Crypto dev=%02x.%04x code=0x%02x => online=0 rc=EAGAIN\n", 371 360 AP_QID_CARD(zq->queue->qid), 372 - AP_QID_QUEUE(zq->queue->qid)); 373 - ZCRYPT_DBF(DBF_ERR, 374 - "device=%02x.%04x code=0x%02x => online=0 rc=EAGAIN\n", 375 - AP_QID_CARD(zq->queue->qid), 376 - AP_QID_QUEUE(zq->queue->qid), 377 - t80h->code); 378 - return -EAGAIN; /* repeat the request on a different device. */ 361 + AP_QID_QUEUE(zq->queue->qid), 362 + t80h->code); 363 + ZCRYPT_DBF_ERR("dev=%02x.%04x code=0x%02x => online=0 rc=EAGAIN\n", 364 + AP_QID_CARD(zq->queue->qid), 365 + AP_QID_QUEUE(zq->queue->qid), 366 + t80h->code); 367 + return -EAGAIN; 379 368 } 380 369 if (zq->zcard->user_space_type == ZCRYPT_CEX2A) 381 370 BUG_ON(t80h->len > CEX2A_MAX_RESPONSE_SIZE); ··· 387 376 return 0; 388 377 } 389 378 390 - static int convert_response(struct zcrypt_queue *zq, 391 - struct ap_message *reply, 392 - char __user *outputdata, 393 - unsigned int outputdatalength) 379 + static int convert_response_cex2a(struct zcrypt_queue *zq, 380 + struct ap_message *reply, 381 + char __user *outputdata, 382 + unsigned int outputdatalength) 394 383 { 395 384 /* Response type byte is the second byte in the response. */ 396 385 unsigned char rtype = ((unsigned char *) reply->msg)[1]; ··· 404 393 outputdata, outputdatalength); 405 394 default: /* Unknown response type, this should NEVER EVER happen */ 406 395 zq->online = 0; 407 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 396 + pr_err("Crypto dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 408 397 AP_QID_CARD(zq->queue->qid), 409 - AP_QID_QUEUE(zq->queue->qid)); 410 - ZCRYPT_DBF(DBF_ERR, 411 - "device=%02x.%04x rtype=0x%02x => online=0 rc=EAGAIN\n", 412 - AP_QID_CARD(zq->queue->qid), 413 - AP_QID_QUEUE(zq->queue->qid), 414 - (unsigned int) rtype); 415 - return -EAGAIN; /* repeat the request on a different device. */ 398 + AP_QID_QUEUE(zq->queue->qid), 399 + (int) rtype); 400 + ZCRYPT_DBF_ERR("dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 401 + AP_QID_CARD(zq->queue->qid), 402 + AP_QID_QUEUE(zq->queue->qid), 403 + (int) rtype); 404 + return -EAGAIN; 416 405 } 417 406 } 418 407 ··· 461 450 * @mex: pointer to the modexpo request buffer 462 451 */ 463 452 static long zcrypt_cex2a_modexpo(struct zcrypt_queue *zq, 464 - struct ica_rsa_modexpo *mex) 453 + struct ica_rsa_modexpo *mex, 454 + struct ap_message *ap_msg) 465 455 { 466 - struct ap_message ap_msg; 467 456 struct completion work; 468 457 int rc; 469 458 470 - ap_init_message(&ap_msg); 471 459 if (zq->zcard->user_space_type == ZCRYPT_CEX2A) 472 - ap_msg.msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL); 460 + ap_msg->msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL); 473 461 else 474 - ap_msg.msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL); 475 - if (!ap_msg.msg) 462 + ap_msg->msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL); 463 + if (!ap_msg->msg) 476 464 return -ENOMEM; 477 - ap_msg.receive = zcrypt_cex2a_receive; 478 - ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 479 - atomic_inc_return(&zcrypt_step); 480 - ap_msg.private = &work; 481 - rc = ICAMEX_msg_to_type50MEX_msg(zq, &ap_msg, mex); 465 + ap_msg->receive = zcrypt_cex2a_receive; 466 + ap_msg->psmid = (((unsigned long long) current->pid) << 32) + 467 + atomic_inc_return(&zcrypt_step); 468 + ap_msg->private = &work; 469 + rc = ICAMEX_msg_to_type50MEX_msg(zq, ap_msg, mex); 482 470 if (rc) 483 - goto out_free; 471 + goto out; 484 472 init_completion(&work); 485 - ap_queue_message(zq->queue, &ap_msg); 473 + rc = ap_queue_message(zq->queue, ap_msg); 474 + if (rc) 475 + goto out; 486 476 rc = wait_for_completion_interruptible(&work); 487 477 if (rc == 0) { 488 - rc = ap_msg.rc; 478 + rc = ap_msg->rc; 489 479 if (rc == 0) 490 - rc = convert_response(zq, &ap_msg, mex->outputdata, 491 - mex->outputdatalength); 480 + rc = convert_response_cex2a(zq, ap_msg, 481 + mex->outputdata, 482 + mex->outputdatalength); 492 483 } else 493 484 /* Signal pending. */ 494 - ap_cancel_message(zq->queue, &ap_msg); 495 - out_free: 496 - kfree(ap_msg.msg); 485 + ap_cancel_message(zq->queue, ap_msg); 486 + out: 487 + ap_msg->private = NULL; 497 488 return rc; 498 489 } 499 490 ··· 507 494 * @crt: pointer to the modexpoc_crt request buffer 508 495 */ 509 496 static long zcrypt_cex2a_modexpo_crt(struct zcrypt_queue *zq, 510 - struct ica_rsa_modexpo_crt *crt) 497 + struct ica_rsa_modexpo_crt *crt, 498 + struct ap_message *ap_msg) 511 499 { 512 - struct ap_message ap_msg; 513 500 struct completion work; 514 501 int rc; 515 502 516 - ap_init_message(&ap_msg); 517 503 if (zq->zcard->user_space_type == ZCRYPT_CEX2A) 518 - ap_msg.msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL); 504 + ap_msg->msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL); 519 505 else 520 - ap_msg.msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL); 521 - if (!ap_msg.msg) 506 + ap_msg->msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL); 507 + if (!ap_msg->msg) 522 508 return -ENOMEM; 523 - ap_msg.receive = zcrypt_cex2a_receive; 524 - ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 525 - atomic_inc_return(&zcrypt_step); 526 - ap_msg.private = &work; 527 - rc = ICACRT_msg_to_type50CRT_msg(zq, &ap_msg, crt); 509 + ap_msg->receive = zcrypt_cex2a_receive; 510 + ap_msg->psmid = (((unsigned long long) current->pid) << 32) + 511 + atomic_inc_return(&zcrypt_step); 512 + ap_msg->private = &work; 513 + rc = ICACRT_msg_to_type50CRT_msg(zq, ap_msg, crt); 528 514 if (rc) 529 - goto out_free; 515 + goto out; 530 516 init_completion(&work); 531 - ap_queue_message(zq->queue, &ap_msg); 517 + rc = ap_queue_message(zq->queue, ap_msg); 518 + if (rc) 519 + goto out; 532 520 rc = wait_for_completion_interruptible(&work); 533 521 if (rc == 0) { 534 - rc = ap_msg.rc; 522 + rc = ap_msg->rc; 535 523 if (rc == 0) 536 - rc = convert_response(zq, &ap_msg, crt->outputdata, 537 - crt->outputdatalength); 524 + rc = convert_response_cex2a(zq, ap_msg, 525 + crt->outputdata, 526 + crt->outputdatalength); 538 527 } else 539 528 /* Signal pending. */ 540 - ap_cancel_message(zq->queue, &ap_msg); 541 - out_free: 542 - kfree(ap_msg.msg); 529 + ap_cancel_message(zq->queue, ap_msg); 530 + out: 531 + ap_msg->private = NULL; 543 532 return rc; 544 533 } 545 534
+143 -121
drivers/s390/crypto/zcrypt_msgtype6.c
··· 388 388 struct type86_fmt2_ext fmt2; 389 389 } __packed; 390 390 391 - static int XCRB_msg_to_type6CPRB_msgX(struct ap_message *ap_msg, 391 + static int XCRB_msg_to_type6CPRB_msgX(bool userspace, struct ap_message *ap_msg, 392 392 struct ica_xcRB *xcRB, 393 393 unsigned int *fcode, 394 394 unsigned short **dom) ··· 465 465 msg->hdr.FromCardLen2 = xcRB->reply_data_length; 466 466 467 467 /* prepare CPRB */ 468 - if (copy_from_user(&(msg->cprbx), xcRB->request_control_blk_addr, 469 - xcRB->request_control_blk_length)) 468 + if (z_copy_from_user(userspace, &(msg->cprbx), xcRB->request_control_blk_addr, 469 + xcRB->request_control_blk_length)) 470 470 return -EFAULT; 471 471 if (msg->cprbx.cprb_len + sizeof(msg->hdr.function_code) > 472 472 xcRB->request_control_blk_length) ··· 482 482 || memcmp(function_code, "AU", 2) == 0) 483 483 ap_msg->flags |= AP_MSG_FLAG_SPECIAL; 484 484 485 + #ifdef CONFIG_ZCRYPT_DEBUG 486 + if (ap_msg->fi.flags & AP_FI_FLAG_TOGGLE_SPECIAL) 487 + ap_msg->flags ^= AP_MSG_FLAG_SPECIAL; 488 + #endif 489 + 485 490 /* copy data block */ 486 491 if (xcRB->request_data_length && 487 - copy_from_user(req_data, xcRB->request_data_address, 488 - xcRB->request_data_length)) 492 + z_copy_from_user(userspace, req_data, xcRB->request_data_address, 493 + xcRB->request_data_length)) 489 494 return -EFAULT; 490 495 491 496 return 0; 492 497 } 493 498 494 - static int xcrb_msg_to_type6_ep11cprb_msgx(struct ap_message *ap_msg, 495 - struct ep11_urb *xcRB, 496 - unsigned int *fcode) 499 + static int xcrb_msg_to_type6_ep11cprb_msgx(bool userspace, struct ap_message *ap_msg, 500 + struct ep11_urb *xcRB, 501 + unsigned int *fcode) 497 502 { 498 503 unsigned int lfmt; 499 504 static struct type6_hdr static_type6_ep11_hdr = { ··· 548 543 msg->hdr.FromCardLen1 = xcRB->resp_len; 549 544 550 545 /* Import CPRB data from the ioctl input parameter */ 551 - if (copy_from_user(&(msg->cprbx.cprb_len), 552 - (char __force __user *)xcRB->req, xcRB->req_len)) { 546 + if (z_copy_from_user(userspace, &(msg->cprbx.cprb_len), 547 + (char __force __user *)xcRB->req, xcRB->req_len)) { 553 548 return -EFAULT; 554 549 } 555 550 ··· 573 568 /* enable special processing based on the cprbs flags special bit */ 574 569 if (msg->cprbx.flags & 0x20) 575 570 ap_msg->flags |= AP_MSG_FLAG_SPECIAL; 571 + 572 + #ifdef CONFIG_ZCRYPT_DEBUG 573 + if (ap_msg->fi.flags & AP_FI_FLAG_TOGGLE_SPECIAL) 574 + ap_msg->flags ^= AP_MSG_FLAG_SPECIAL; 575 + #endif 576 576 577 577 return 0; 578 578 } ··· 660 650 (service_rc == 8 && service_rs == 72) || 661 651 (service_rc == 8 && service_rs == 770) || 662 652 (service_rc == 12 && service_rs == 769)) { 663 - ZCRYPT_DBF(DBF_DEBUG, 664 - "device=%02x.%04x rc/rs=%d/%d => rc=EINVAL\n", 665 - AP_QID_CARD(zq->queue->qid), 666 - AP_QID_QUEUE(zq->queue->qid), 667 - (int) service_rc, (int) service_rs); 653 + ZCRYPT_DBF_WARN("dev=%02x.%04x rc/rs=%d/%d => rc=EINVAL\n", 654 + AP_QID_CARD(zq->queue->qid), 655 + AP_QID_QUEUE(zq->queue->qid), 656 + (int) service_rc, (int) service_rs); 668 657 return -EINVAL; 669 658 } 670 659 zq->online = 0; 671 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 660 + pr_err("Crypto dev=%02x.%04x rc/rs=%d/%d online=0 rc=EAGAIN\n", 672 661 AP_QID_CARD(zq->queue->qid), 673 - AP_QID_QUEUE(zq->queue->qid)); 674 - ZCRYPT_DBF(DBF_ERR, 675 - "device=%02x.%04x rc/rs=%d/%d => online=0 rc=EAGAIN\n", 676 - AP_QID_CARD(zq->queue->qid), 677 - AP_QID_QUEUE(zq->queue->qid), 678 - (int) service_rc, (int) service_rs); 679 - return -EAGAIN; /* repeat the request on a different device. */ 662 + AP_QID_QUEUE(zq->queue->qid), 663 + (int) service_rc, (int) service_rs); 664 + ZCRYPT_DBF_ERR("dev=%02x.%04x rc/rs=%d/%d => online=0 rc=EAGAIN\n", 665 + AP_QID_CARD(zq->queue->qid), 666 + AP_QID_QUEUE(zq->queue->qid), 667 + (int) service_rc, (int) service_rs); 668 + return -EAGAIN; 680 669 } 681 670 data = msg->text; 682 671 reply_len = msg->length - 2; ··· 716 707 * 717 708 * Returns 0 on success or -EINVAL, -EFAULT, -EAGAIN in case of an error. 718 709 */ 719 - static int convert_type86_xcrb(struct zcrypt_queue *zq, 710 + static int convert_type86_xcrb(bool userspace, struct zcrypt_queue *zq, 720 711 struct ap_message *reply, 721 712 struct ica_xcRB *xcRB) 722 713 { ··· 724 715 char *data = reply->msg; 725 716 726 717 /* Copy CPRB to user */ 727 - if (copy_to_user(xcRB->reply_control_blk_addr, 728 - data + msg->fmt2.offset1, msg->fmt2.count1)) 718 + if (z_copy_to_user(userspace, xcRB->reply_control_blk_addr, 719 + data + msg->fmt2.offset1, msg->fmt2.count1)) 729 720 return -EFAULT; 730 721 xcRB->reply_control_blk_length = msg->fmt2.count1; 731 722 732 723 /* Copy data buffer to user */ 733 724 if (msg->fmt2.count2) 734 - if (copy_to_user(xcRB->reply_data_addr, 735 - data + msg->fmt2.offset2, msg->fmt2.count2)) 725 + if (z_copy_to_user(userspace, xcRB->reply_data_addr, 726 + data + msg->fmt2.offset2, msg->fmt2.count2)) 736 727 return -EFAULT; 737 728 xcRB->reply_data_length = msg->fmt2.count2; 738 729 return 0; ··· 747 738 * 748 739 * Returns 0 on success or -EINVAL, -EFAULT, -EAGAIN in case of an error. 749 740 */ 750 - static int convert_type86_ep11_xcrb(struct zcrypt_queue *zq, 741 + static int convert_type86_ep11_xcrb(bool userspace, struct zcrypt_queue *zq, 751 742 struct ap_message *reply, 752 743 struct ep11_urb *xcRB) 753 744 { ··· 758 749 return -EINVAL; 759 750 760 751 /* Copy response CPRB to user */ 761 - if (copy_to_user((char __force __user *)xcRB->resp, 762 - data + msg->fmt2.offset1, msg->fmt2.count1)) 752 + if (z_copy_to_user(userspace, (char __force __user *)xcRB->resp, 753 + data + msg->fmt2.offset1, msg->fmt2.count1)) 763 754 return -EFAULT; 764 755 xcRB->resp_len = msg->fmt2.count1; 765 756 return 0; ··· 809 800 return convert_type86_ica(zq, reply, 810 801 outputdata, outputdatalength); 811 802 fallthrough; /* wrong cprb version is an unknown response */ 812 - default: /* Unknown response type, this should NEVER EVER happen */ 803 + default: 804 + /* Unknown response type, this should NEVER EVER happen */ 813 805 zq->online = 0; 814 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 806 + pr_err("Crypto dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 815 807 AP_QID_CARD(zq->queue->qid), 816 - AP_QID_QUEUE(zq->queue->qid)); 817 - ZCRYPT_DBF(DBF_ERR, 818 - "device=%02x.%04x rtype=0x%02x => online=0 rc=EAGAIN\n", 819 - AP_QID_CARD(zq->queue->qid), 820 - AP_QID_QUEUE(zq->queue->qid), 821 - (int) msg->hdr.type); 822 - return -EAGAIN; /* repeat the request on a different device. */ 808 + AP_QID_QUEUE(zq->queue->qid), 809 + (int) msg->hdr.type); 810 + ZCRYPT_DBF_ERR("dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 811 + AP_QID_CARD(zq->queue->qid), 812 + AP_QID_QUEUE(zq->queue->qid), 813 + (int) msg->hdr.type); 814 + return -EAGAIN; 823 815 } 824 816 } 825 817 826 - static int convert_response_xcrb(struct zcrypt_queue *zq, 827 - struct ap_message *reply, 828 - struct ica_xcRB *xcRB) 818 + static int convert_response_xcrb(bool userspace, struct zcrypt_queue *zq, 819 + struct ap_message *reply, 820 + struct ica_xcRB *xcRB) 829 821 { 830 822 struct type86x_reply *msg = reply->msg; 831 823 ··· 841 831 return convert_error(zq, reply); 842 832 } 843 833 if (msg->cprbx.cprb_ver_id == 0x02) 844 - return convert_type86_xcrb(zq, reply, xcRB); 834 + return convert_type86_xcrb(userspace, zq, reply, xcRB); 845 835 fallthrough; /* wrong cprb version is an unknown response */ 846 836 default: /* Unknown response type, this should NEVER EVER happen */ 847 837 xcRB->status = 0x0008044DL; /* HDD_InvalidParm */ 848 838 zq->online = 0; 849 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 839 + pr_err("Crypto dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 850 840 AP_QID_CARD(zq->queue->qid), 851 - AP_QID_QUEUE(zq->queue->qid)); 852 - ZCRYPT_DBF(DBF_ERR, 853 - "device=%02x.%04x rtype=0x%02x => online=0 rc=EAGAIN\n", 854 - AP_QID_CARD(zq->queue->qid), 855 - AP_QID_QUEUE(zq->queue->qid), 856 - (int) msg->hdr.type); 857 - return -EAGAIN; /* repeat the request on a different device. */ 841 + AP_QID_QUEUE(zq->queue->qid), 842 + (int) msg->hdr.type); 843 + ZCRYPT_DBF_ERR("dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 844 + AP_QID_CARD(zq->queue->qid), 845 + AP_QID_QUEUE(zq->queue->qid), 846 + (int) msg->hdr.type); 847 + return -EAGAIN; 858 848 } 859 849 } 860 850 861 - static int convert_response_ep11_xcrb(struct zcrypt_queue *zq, 862 - struct ap_message *reply, struct ep11_urb *xcRB) 851 + static int convert_response_ep11_xcrb(bool userspace, struct zcrypt_queue *zq, 852 + struct ap_message *reply, struct ep11_urb *xcRB) 863 853 { 864 854 struct type86_ep11_reply *msg = reply->msg; 865 855 ··· 871 861 if (msg->hdr.reply_code) 872 862 return convert_error(zq, reply); 873 863 if (msg->cprbx.cprb_ver_id == 0x04) 874 - return convert_type86_ep11_xcrb(zq, reply, xcRB); 864 + return convert_type86_ep11_xcrb(userspace, zq, reply, xcRB); 875 865 fallthrough; /* wrong cprb version is an unknown resp */ 876 866 default: /* Unknown response type, this should NEVER EVER happen */ 877 867 zq->online = 0; 878 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 868 + pr_err("Crypto dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 879 869 AP_QID_CARD(zq->queue->qid), 880 - AP_QID_QUEUE(zq->queue->qid)); 881 - ZCRYPT_DBF(DBF_ERR, 882 - "device=%02x.%04x rtype=0x%02x => online=0 rc=EAGAIN\n", 883 - AP_QID_CARD(zq->queue->qid), 884 - AP_QID_QUEUE(zq->queue->qid), 885 - (int) msg->hdr.type); 886 - return -EAGAIN; /* repeat the request on a different device. */ 870 + AP_QID_QUEUE(zq->queue->qid), 871 + (int) msg->hdr.type); 872 + ZCRYPT_DBF_ERR("dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 873 + AP_QID_CARD(zq->queue->qid), 874 + AP_QID_QUEUE(zq->queue->qid), 875 + (int) msg->hdr.type); 876 + return -EAGAIN; 887 877 } 888 878 } 889 879 ··· 905 895 fallthrough; /* wrong cprb version is an unknown response */ 906 896 default: /* Unknown response type, this should NEVER EVER happen */ 907 897 zq->online = 0; 908 - pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 898 + pr_err("Crypto dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 909 899 AP_QID_CARD(zq->queue->qid), 910 - AP_QID_QUEUE(zq->queue->qid)); 911 - ZCRYPT_DBF(DBF_ERR, 912 - "device=%02x.%04x rtype=0x%02x => online=0 rc=EAGAIN\n", 913 - AP_QID_CARD(zq->queue->qid), 914 - AP_QID_QUEUE(zq->queue->qid), 915 - (int) msg->hdr.type); 916 - return -EAGAIN; /* repeat the request on a different device. */ 900 + AP_QID_QUEUE(zq->queue->qid), 901 + (int) msg->hdr.type); 902 + ZCRYPT_DBF_ERR("dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n", 903 + AP_QID_CARD(zq->queue->qid), 904 + AP_QID_QUEUE(zq->queue->qid), 905 + (int) msg->hdr.type); 906 + return -EAGAIN; 917 907 } 918 908 } 919 909 ··· 1017 1007 * @mex: pointer to the modexpo request buffer 1018 1008 */ 1019 1009 static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq, 1020 - struct ica_rsa_modexpo *mex) 1010 + struct ica_rsa_modexpo *mex, 1011 + struct ap_message *ap_msg) 1021 1012 { 1022 - struct ap_message ap_msg; 1023 1013 struct response_type resp_type = { 1024 1014 .type = CEXXC_RESPONSE_TYPE_ICA, 1025 1015 }; 1026 1016 int rc; 1027 1017 1028 - ap_init_message(&ap_msg); 1029 - ap_msg.msg = (void *) get_zeroed_page(GFP_KERNEL); 1030 - if (!ap_msg.msg) 1018 + ap_msg->msg = (void *) get_zeroed_page(GFP_KERNEL); 1019 + if (!ap_msg->msg) 1031 1020 return -ENOMEM; 1032 - ap_msg.receive = zcrypt_msgtype6_receive; 1033 - ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 1034 - atomic_inc_return(&zcrypt_step); 1035 - ap_msg.private = &resp_type; 1036 - rc = ICAMEX_msg_to_type6MEX_msgX(zq, &ap_msg, mex); 1021 + ap_msg->receive = zcrypt_msgtype6_receive; 1022 + ap_msg->psmid = (((unsigned long long) current->pid) << 32) + 1023 + atomic_inc_return(&zcrypt_step); 1024 + ap_msg->private = &resp_type; 1025 + rc = ICAMEX_msg_to_type6MEX_msgX(zq, ap_msg, mex); 1037 1026 if (rc) 1038 1027 goto out_free; 1039 1028 init_completion(&resp_type.work); 1040 - ap_queue_message(zq->queue, &ap_msg); 1029 + rc = ap_queue_message(zq->queue, ap_msg); 1030 + if (rc) 1031 + goto out_free; 1041 1032 rc = wait_for_completion_interruptible(&resp_type.work); 1042 1033 if (rc == 0) { 1043 - rc = ap_msg.rc; 1034 + rc = ap_msg->rc; 1044 1035 if (rc == 0) 1045 - rc = convert_response_ica(zq, &ap_msg, 1036 + rc = convert_response_ica(zq, ap_msg, 1046 1037 mex->outputdata, 1047 1038 mex->outputdatalength); 1048 1039 } else 1049 1040 /* Signal pending. */ 1050 - ap_cancel_message(zq->queue, &ap_msg); 1041 + ap_cancel_message(zq->queue, ap_msg); 1051 1042 out_free: 1052 - free_page((unsigned long) ap_msg.msg); 1043 + free_page((unsigned long) ap_msg->msg); 1044 + ap_msg->private = NULL; 1045 + ap_msg->msg = NULL; 1053 1046 return rc; 1054 1047 } 1055 1048 ··· 1064 1051 * @crt: pointer to the modexpoc_crt request buffer 1065 1052 */ 1066 1053 static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq, 1067 - struct ica_rsa_modexpo_crt *crt) 1054 + struct ica_rsa_modexpo_crt *crt, 1055 + struct ap_message *ap_msg) 1068 1056 { 1069 - struct ap_message ap_msg; 1070 1057 struct response_type resp_type = { 1071 1058 .type = CEXXC_RESPONSE_TYPE_ICA, 1072 1059 }; 1073 1060 int rc; 1074 1061 1075 - ap_init_message(&ap_msg); 1076 - ap_msg.msg = (void *) get_zeroed_page(GFP_KERNEL); 1077 - if (!ap_msg.msg) 1062 + ap_msg->msg = (void *) get_zeroed_page(GFP_KERNEL); 1063 + if (!ap_msg->msg) 1078 1064 return -ENOMEM; 1079 - ap_msg.receive = zcrypt_msgtype6_receive; 1080 - ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 1081 - atomic_inc_return(&zcrypt_step); 1082 - ap_msg.private = &resp_type; 1083 - rc = ICACRT_msg_to_type6CRT_msgX(zq, &ap_msg, crt); 1065 + ap_msg->receive = zcrypt_msgtype6_receive; 1066 + ap_msg->psmid = (((unsigned long long) current->pid) << 32) + 1067 + atomic_inc_return(&zcrypt_step); 1068 + ap_msg->private = &resp_type; 1069 + rc = ICACRT_msg_to_type6CRT_msgX(zq, ap_msg, crt); 1084 1070 if (rc) 1085 1071 goto out_free; 1086 1072 init_completion(&resp_type.work); 1087 - ap_queue_message(zq->queue, &ap_msg); 1073 + rc = ap_queue_message(zq->queue, ap_msg); 1074 + if (rc) 1075 + goto out_free; 1088 1076 rc = wait_for_completion_interruptible(&resp_type.work); 1089 1077 if (rc == 0) { 1090 - rc = ap_msg.rc; 1078 + rc = ap_msg->rc; 1091 1079 if (rc == 0) 1092 - rc = convert_response_ica(zq, &ap_msg, 1080 + rc = convert_response_ica(zq, ap_msg, 1093 1081 crt->outputdata, 1094 1082 crt->outputdatalength); 1095 1083 } else { 1096 1084 /* Signal pending. */ 1097 - ap_cancel_message(zq->queue, &ap_msg); 1085 + ap_cancel_message(zq->queue, ap_msg); 1098 1086 } 1099 1087 out_free: 1100 - free_page((unsigned long) ap_msg.msg); 1088 + free_page((unsigned long) ap_msg->msg); 1089 + ap_msg->private = NULL; 1090 + ap_msg->msg = NULL; 1101 1091 return rc; 1102 1092 } 1103 1093 ··· 1111 1095 * by the caller with ap_init_message(). Also the caller has to 1112 1096 * make sure ap_release_message() is always called even on failure. 1113 1097 */ 1114 - unsigned int get_cprb_fc(struct ica_xcRB *xcRB, 1115 - struct ap_message *ap_msg, 1116 - unsigned int *func_code, unsigned short **dom) 1098 + unsigned int get_cprb_fc(bool userspace, struct ica_xcRB *xcRB, 1099 + struct ap_message *ap_msg, 1100 + unsigned int *func_code, unsigned short **dom) 1117 1101 { 1118 1102 struct response_type resp_type = { 1119 1103 .type = CEXXC_RESPONSE_TYPE_XCRB, ··· 1128 1112 ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL); 1129 1113 if (!ap_msg->private) 1130 1114 return -ENOMEM; 1131 - return XCRB_msg_to_type6CPRB_msgX(ap_msg, xcRB, func_code, dom); 1115 + return XCRB_msg_to_type6CPRB_msgX(userspace, ap_msg, xcRB, func_code, dom); 1132 1116 } 1133 1117 1134 1118 /** ··· 1138 1122 * CEXxC device to the request distributor 1139 1123 * @xcRB: pointer to the send_cprb request buffer 1140 1124 */ 1141 - static long zcrypt_msgtype6_send_cprb(struct zcrypt_queue *zq, 1142 - struct ica_xcRB *xcRB, 1143 - struct ap_message *ap_msg) 1125 + static long zcrypt_msgtype6_send_cprb(bool userspace, struct zcrypt_queue *zq, 1126 + struct ica_xcRB *xcRB, 1127 + struct ap_message *ap_msg) 1144 1128 { 1145 1129 int rc; 1146 1130 struct response_type *rtype = (struct response_type *)(ap_msg->private); 1147 1131 1148 1132 init_completion(&rtype->work); 1149 - ap_queue_message(zq->queue, ap_msg); 1133 + rc = ap_queue_message(zq->queue, ap_msg); 1134 + if (rc) 1135 + goto out; 1150 1136 rc = wait_for_completion_interruptible(&rtype->work); 1151 1137 if (rc == 0) { 1152 1138 rc = ap_msg->rc; 1153 1139 if (rc == 0) 1154 - rc = convert_response_xcrb(zq, ap_msg, xcRB); 1140 + rc = convert_response_xcrb(userspace, zq, ap_msg, xcRB); 1155 1141 } else 1156 1142 /* Signal pending. */ 1157 1143 ap_cancel_message(zq->queue, ap_msg); 1158 - 1144 + out: 1159 1145 return rc; 1160 1146 } 1161 1147 ··· 1168 1150 * by the caller with ap_init_message(). Also the caller has to 1169 1151 * make sure ap_release_message() is always called even on failure. 1170 1152 */ 1171 - unsigned int get_ep11cprb_fc(struct ep11_urb *xcrb, 1172 - struct ap_message *ap_msg, 1173 - unsigned int *func_code) 1153 + unsigned int get_ep11cprb_fc(bool userspace, struct ep11_urb *xcrb, 1154 + struct ap_message *ap_msg, 1155 + unsigned int *func_code) 1174 1156 { 1175 1157 struct response_type resp_type = { 1176 1158 .type = CEXXC_RESPONSE_TYPE_EP11, ··· 1185 1167 ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL); 1186 1168 if (!ap_msg->private) 1187 1169 return -ENOMEM; 1188 - return xcrb_msg_to_type6_ep11cprb_msgx(ap_msg, xcrb, func_code); 1170 + return xcrb_msg_to_type6_ep11cprb_msgx(userspace, ap_msg, xcrb, func_code); 1189 1171 } 1190 1172 1191 1173 /** ··· 1195 1177 * CEX4P device to the request distributor 1196 1178 * @xcRB: pointer to the ep11 user request block 1197 1179 */ 1198 - static long zcrypt_msgtype6_send_ep11_cprb(struct zcrypt_queue *zq, 1180 + static long zcrypt_msgtype6_send_ep11_cprb(bool userspace, struct zcrypt_queue *zq, 1199 1181 struct ep11_urb *xcrb, 1200 1182 struct ap_message *ap_msg) 1201 1183 { ··· 1250 1232 } 1251 1233 1252 1234 init_completion(&rtype->work); 1253 - ap_queue_message(zq->queue, ap_msg); 1235 + rc = ap_queue_message(zq->queue, ap_msg); 1236 + if (rc) 1237 + goto out; 1254 1238 rc = wait_for_completion_interruptible(&rtype->work); 1255 1239 if (rc == 0) { 1256 1240 rc = ap_msg->rc; 1257 1241 if (rc == 0) 1258 - rc = convert_response_ep11_xcrb(zq, ap_msg, xcrb); 1242 + rc = convert_response_ep11_xcrb(userspace, zq, ap_msg, xcrb); 1259 1243 } else 1260 1244 /* Signal pending. */ 1261 1245 ap_cancel_message(zq->queue, ap_msg); 1262 - 1246 + out: 1263 1247 return rc; 1264 1248 } 1265 1249 ··· 1313 1293 msg->cprbx.domain = AP_QID_QUEUE(zq->queue->qid); 1314 1294 1315 1295 init_completion(&rtype->work); 1316 - ap_queue_message(zq->queue, ap_msg); 1296 + rc = ap_queue_message(zq->queue, ap_msg); 1297 + if (rc) 1298 + goto out; 1317 1299 rc = wait_for_completion_interruptible(&rtype->work); 1318 1300 if (rc == 0) { 1319 1301 rc = ap_msg->rc; ··· 1324 1302 } else 1325 1303 /* Signal pending. */ 1326 1304 ap_cancel_message(zq->queue, ap_msg); 1327 - 1305 + out: 1328 1306 return rc; 1329 1307 } 1330 1308
+2 -2
drivers/s390/crypto/zcrypt_msgtype6.h
··· 96 96 unsigned int offset4; /* 0x00000000 */ 97 97 } __packed; 98 98 99 - unsigned int get_cprb_fc(struct ica_xcRB *, struct ap_message *, 99 + unsigned int get_cprb_fc(bool userspace, struct ica_xcRB *, struct ap_message *, 100 100 unsigned int *, unsigned short **); 101 - unsigned int get_ep11cprb_fc(struct ep11_urb *, struct ap_message *, 101 + unsigned int get_ep11cprb_fc(bool userspace, struct ep11_urb *, struct ap_message *, 102 102 unsigned int *); 103 103 unsigned int get_rng_fc(struct ap_message *, int *, unsigned int *); 104 104
+8 -3
drivers/s390/crypto/zcrypt_queue.c
··· 40 40 struct device_attribute *attr, 41 41 char *buf) 42 42 { 43 - struct zcrypt_queue *zq = to_ap_queue(dev)->private; 43 + struct ap_queue *aq = to_ap_queue(dev); 44 + struct zcrypt_queue *zq = aq->private; 45 + int online = aq->config && zq->online ? 1 : 0; 44 46 45 - return scnprintf(buf, PAGE_SIZE, "%d\n", zq->online); 47 + return scnprintf(buf, PAGE_SIZE, "%d\n", online); 46 48 } 47 49 48 50 static ssize_t online_store(struct device *dev, 49 51 struct device_attribute *attr, 50 52 const char *buf, size_t count) 51 53 { 52 - struct zcrypt_queue *zq = to_ap_queue(dev)->private; 54 + struct ap_queue *aq = to_ap_queue(dev); 55 + struct zcrypt_queue *zq = aq->private; 53 56 struct zcrypt_card *zc = zq->zcard; 54 57 int online; 55 58 56 59 if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1) 57 60 return -EINVAL; 58 61 62 + if (online && (!aq->config || !aq->card->config)) 63 + return -ENODEV; 59 64 if (online && !zc->online) 60 65 return -EINVAL; 61 66 zq->online = online;
-2
drivers/s390/scsi/zfcp_qdio.c
··· 380 380 &qdio->adapter->status); 381 381 382 382 init_data.q_format = QDIO_ZFCP_QFMT; 383 - memcpy(init_data.adapter_name, dev_name(&cdev->dev), 8); 384 - ASCEBC(init_data.adapter_name, 8); 385 383 init_data.qib_rflags = QIB_RFLAGS_ENABLE_DATA_DIV; 386 384 if (enable_multibuffer) 387 385 init_data.qdr_ac |= QDR_AC_MULTI_BUFFER_ENABLE;