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

Merge tag 'powerpc-5.14-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux

Pull powerpc updates from Michael Ellerman:

- A big series refactoring parts of our KVM code, and converting some
to C.

- Support for ARCH_HAS_SET_MEMORY, and ARCH_HAS_STRICT_MODULE_RWX on
some CPUs.

- Support for the Microwatt soft-core.

- Optimisations to our interrupt return path on 64-bit.

- Support for userspace access to the NX GZIP accelerator on PowerVM on
Power10.

- Enable KUAP and KUEP by default on 32-bit Book3S CPUs.

- Other smaller features, fixes & cleanups.

Thanks to: Andy Shevchenko, Aneesh Kumar K.V, Arnd Bergmann, Athira
Rajeev, Baokun Li, Benjamin Herrenschmidt, Bharata B Rao, Christophe
Leroy, Daniel Axtens, Daniel Henrique Barboza, Finn Thain, Geoff Levand,
Haren Myneni, Jason Wang, Jiapeng Chong, Joel Stanley, Jordan Niethe,
Kajol Jain, Nathan Chancellor, Nathan Lynch, Naveen N. Rao, Nicholas
Piggin, Nick Desaulniers, Paul Mackerras, Russell Currey, Sathvika
Vasireddy, Shaokun Zhang, Stephen Rothwell, Sudeep Holla, Suraj Jitindar
Singh, Tom Rix, Vaibhav Jain, YueHaibing, Zhang Jianhua, and Zhen Lei.

* tag 'powerpc-5.14-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (218 commits)
powerpc: Only build restart_table.c for 64s
powerpc/64s: move ret_from_fork etc above __end_soft_masked
powerpc/64s/interrupt: clean up interrupt return labels
powerpc/64/interrupt: add missing kprobe annotations on interrupt exit symbols
powerpc/64: enable MSR[EE] in irq replay pt_regs
powerpc/64s/interrupt: preserve regs->softe for NMI interrupts
powerpc/64s: add a table of implicit soft-masked addresses
powerpc/64e: remove implicit soft-masking and interrupt exit restart logic
powerpc/64e: fix CONFIG_RELOCATABLE build warnings
powerpc/64s: fix hash page fault interrupt handler
powerpc/4xx: Fix setup_kuep() on SMP
powerpc/32s: Fix setup_{kuap/kuep}() on SMP
powerpc/interrupt: Use names in check_return_regs_valid()
powerpc/interrupt: Also use exit_must_hard_disable() on PPC32
powerpc/sysfs: Replace sizeof(arr)/sizeof(arr[0]) with ARRAY_SIZE
powerpc/ptrace: Refactor regs_set_return_{msr/ip}
powerpc/ptrace: Move set_return_regs_changed() before regs_set_return_{msr/ip}
powerpc/stacktrace: Fix spurious "stale" traces in raise_backtrace_ipi()
powerpc/pseries/vas: Include irqdomain.h
powerpc: mark local variables around longjmp as volatile
...

+6775 -3668
+5 -3
Documentation/ABI/testing/sysfs-bus-papr-pmem
··· 39 39 Contact: linuxppc-dev <linuxppc-dev@lists.ozlabs.org>, nvdimm@lists.linux.dev, 40 40 Description: 41 41 (RO) Report various performance stats related to papr-scm NVDIMM 42 - device. Each stat is reported on a new line with each line 43 - composed of a stat-identifier followed by it value. Below are 44 - currently known dimm performance stats which are reported: 42 + device. This attribute is only available for NVDIMM devices 43 + that support reporting NVDIMM performance stats. Each stat is 44 + reported on a new line with each line composed of a 45 + stat-identifier followed by it value. Below are currently known 46 + dimm performance stats which are reported: 45 47 46 48 * "CtlResCt" : Controller Reset Count 47 49 * "CtlResTm" : Controller Reset Elapsed Time
+5 -1
arch/powerpc/Kconfig
··· 140 140 select ARCH_HAS_PTE_DEVMAP if PPC_BOOK3S_64 141 141 select ARCH_HAS_PTE_SPECIAL 142 142 select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE && PPC_BOOK3S_64 143 + select ARCH_HAS_SET_MEMORY 143 144 select ARCH_HAS_STRICT_KERNEL_RWX if ((PPC_BOOK3S_64 || PPC32) && !HIBERNATION) 145 + select ARCH_HAS_STRICT_MODULE_RWX if ARCH_HAS_STRICT_KERNEL_RWX && !PPC_BOOK3S_32 144 146 select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST 145 147 select ARCH_HAS_UACCESS_FLUSHCACHE 146 148 select ARCH_HAS_UBSAN_SANITIZE_ALL ··· 268 266 select PPC_DAWR if PPC64 269 267 select RTC_LIB 270 268 select SPARSE_IRQ 269 + select STRICT_KERNEL_RWX if STRICT_MODULE_RWX 271 270 select SYSCTL_EXCEPTION_TRACE 272 271 select THREAD_INFO_IN_TASK 273 272 select VIRT_TO_BUS if !PPC64 ··· 292 289 config COMPAT 293 290 bool "Enable support for 32bit binaries" 294 291 depends on PPC64 292 + depends on !CC_IS_CLANG || CLANG_VERSION >= 120000 295 293 default y if !CPU_LITTLE_ENDIAN 296 294 select ARCH_WANT_OLD_COMPAT_IPC 297 295 select COMPAT_OLD_SIGACTION ··· 426 422 427 423 config MATH_EMULATION 428 424 bool "Math emulation" 429 - depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE 425 + depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE || PPC_MICROWATT 430 426 select PPC_FPU_REGS 431 427 help 432 428 Some PowerPC chips designed for embedded applications do not have
+5
arch/powerpc/Kconfig.debug
··· 84 84 85 85 config PPC_IRQ_SOFT_MASK_DEBUG 86 86 bool "Include extra checks for powerpc irq soft masking" 87 + depends on PPC64 88 + 89 + config PPC_RFI_SRR_DEBUG 90 + bool "Include extra checks for RFI SRR register validity" 91 + depends on PPC_BOOK3S_64 87 92 88 93 config XMON 89 94 bool "Include xmon kernel debugger"
+10
arch/powerpc/Makefile
··· 376 376 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/85xx-64bit.config \ 377 377 -f $(srctree)/Makefile allmodconfig 378 378 379 + PHONY += ppc32_randconfig 380 + ppc32_randconfig: 381 + $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/32-bit.config \ 382 + -f $(srctree)/Makefile randconfig 383 + 384 + PHONY += ppc64_randconfig 385 + ppc64_randconfig: 386 + $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/64-bit.config \ 387 + -f $(srctree)/Makefile randconfig 388 + 379 389 define archhelp 380 390 @echo '* zImage - Build default images selected by kernel config' 381 391 @echo ' zImage.* - Compressed kernel image (arch/$(ARCH)/boot/zImage.*)'
+5 -1
arch/powerpc/boot/Makefile
··· 163 163 src-plat-$(CONFIG_PPC_IBM_CELL_BLADE) += pseries-head.S 164 164 src-plat-$(CONFIG_MVME7100) += motload-head.S mvme7100.c 165 165 166 + src-plat-$(CONFIG_PPC_MICROWATT) += fixed-head.S microwatt.c 167 + 166 168 src-wlib := $(sort $(src-wlib-y)) 167 169 src-plat := $(sort $(src-plat-y)) 168 170 src-boot := $(src-wlib) $(src-plat) empty.c ··· 229 227 230 228 hostprogs := addnote hack-coff mktree 231 229 232 - targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a) 230 + targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a) zImage.lds 233 231 extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \ 234 232 $(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds 235 233 ··· 356 354 357 355 # Board port in arch/powerpc/platform/amigaone/Kconfig 358 356 image-$(CONFIG_AMIGAONE) += cuImage.amigaone 357 + 358 + image-$(CONFIG_PPC_MICROWATT) += dtbImage.microwatt 359 359 360 360 # For 32-bit powermacs, build the COFF and miboot images 361 361 # as well as the ELF images.
+2 -2
arch/powerpc/boot/decompress.c
··· 99 99 * partial_decompress - decompresses part or all of a compressed buffer 100 100 * @inbuf: input buffer 101 101 * @input_size: length of the input buffer 102 - * @outbuf: input buffer 103 - * @output_size: length of the input buffer 102 + * @outbuf: output buffer 103 + * @output_size: length of the output buffer 104 104 * @skip number of output bytes to ignore 105 105 * 106 106 * This function takes compressed data from inbuf, decompresses and write it to
+34 -25
arch/powerpc/boot/devtree.c
··· 13 13 #include "string.h" 14 14 #include "stdio.h" 15 15 #include "ops.h" 16 + #include "of.h" 16 17 17 18 void dt_fixup_memory(u64 start, u64 size) 18 19 { ··· 24 23 root = finddevice("/"); 25 24 if (getprop(root, "#address-cells", &naddr, sizeof(naddr)) < 0) 26 25 naddr = 2; 26 + else 27 + naddr = be32_to_cpu(naddr); 27 28 if (naddr < 1 || naddr > 2) 28 29 fatal("Can't cope with #address-cells == %d in /\n\r", naddr); 29 30 30 31 if (getprop(root, "#size-cells", &nsize, sizeof(nsize)) < 0) 31 32 nsize = 1; 33 + else 34 + nsize = be32_to_cpu(nsize); 32 35 if (nsize < 1 || nsize > 2) 33 36 fatal("Can't cope with #size-cells == %d in /\n\r", nsize); 34 37 35 38 i = 0; 36 39 if (naddr == 2) 37 - memreg[i++] = start >> 32; 38 - memreg[i++] = start & 0xffffffff; 40 + memreg[i++] = cpu_to_be32(start >> 32); 41 + memreg[i++] = cpu_to_be32(start & 0xffffffff); 39 42 if (nsize == 2) 40 - memreg[i++] = size >> 32; 41 - memreg[i++] = size & 0xffffffff; 43 + memreg[i++] = cpu_to_be32(size >> 32); 44 + memreg[i++] = cpu_to_be32(size & 0xffffffff); 42 45 43 46 memory = finddevice("/memory"); 44 47 if (! memory) { ··· 50 45 setprop_str(memory, "device_type", "memory"); 51 46 } 52 47 53 - printf("Memory <- <0x%x", memreg[0]); 48 + printf("Memory <- <0x%x", be32_to_cpu(memreg[0])); 54 49 for (i = 1; i < (naddr + nsize); i++) 55 - printf(" 0x%x", memreg[i]); 50 + printf(" 0x%x", be32_to_cpu(memreg[i])); 56 51 printf("> (%ldMB)\n\r", (unsigned long)(size >> 20)); 57 52 58 53 setprop(memory, "reg", memreg, (naddr + nsize)*sizeof(u32)); ··· 70 65 printf("CPU bus-frequency <- 0x%x (%dMHz)\n\r", bus, MHZ(bus)); 71 66 72 67 while ((devp = find_node_by_devtype(devp, "cpu"))) { 73 - setprop_val(devp, "clock-frequency", cpu); 74 - setprop_val(devp, "timebase-frequency", tb); 68 + setprop_val(devp, "clock-frequency", cpu_to_be32(cpu)); 69 + setprop_val(devp, "timebase-frequency", cpu_to_be32(tb)); 75 70 if (bus > 0) 76 - setprop_val(devp, "bus-frequency", bus); 71 + setprop_val(devp, "bus-frequency", cpu_to_be32(bus)); 77 72 } 78 73 79 74 timebase_period_ns = 1000000000 / tb; ··· 85 80 86 81 if (devp) { 87 82 printf("%s: clock-frequency <- %x (%dMHz)\n\r", path, freq, MHZ(freq)); 88 - setprop_val(devp, "clock-frequency", freq); 83 + setprop_val(devp, "clock-frequency", cpu_to_be32(freq)); 89 84 } 90 85 } 91 86 ··· 138 133 { 139 134 if (getprop(node, "#address-cells", naddr, 4) != 4) 140 135 *naddr = 2; 136 + else 137 + *naddr = be32_to_cpu(*naddr); 141 138 if (getprop(node, "#size-cells", nsize, 4) != 4) 142 139 *nsize = 1; 140 + else 141 + *nsize = be32_to_cpu(*nsize); 143 142 } 144 143 145 144 static void copy_val(u32 *dest, u32 *src, int naddr) ··· 172 163 int i, carry = 0; 173 164 174 165 for (i = MAX_ADDR_CELLS - 1; i >= MAX_ADDR_CELLS - naddr; i--) { 175 - u64 tmp = (u64)reg[i] + add[i] + carry; 166 + u64 tmp = (u64)be32_to_cpu(reg[i]) + be32_to_cpu(add[i]) + carry; 176 167 carry = tmp >> 32; 177 - reg[i] = (u32)tmp; 168 + reg[i] = cpu_to_be32((u32)tmp); 178 169 } 179 170 180 171 return !carry; ··· 189 180 u32 end; 190 181 191 182 for (i = 0; i < MAX_ADDR_CELLS; i++) { 192 - if (reg[i] < range[i]) 183 + if (be32_to_cpu(reg[i]) < be32_to_cpu(range[i])) 193 184 return 0; 194 - if (reg[i] > range[i]) 185 + if (be32_to_cpu(reg[i]) > be32_to_cpu(range[i])) 195 186 break; 196 187 } 197 188 198 189 for (i = 0; i < MAX_ADDR_CELLS; i++) { 199 - end = range[i] + rangesize[i]; 190 + end = be32_to_cpu(range[i]) + be32_to_cpu(rangesize[i]); 200 191 201 - if (reg[i] < end) 192 + if (be32_to_cpu(reg[i]) < end) 202 193 break; 203 - if (reg[i] > end) 194 + if (be32_to_cpu(reg[i]) > end) 204 195 return 0; 205 196 } 206 197 ··· 249 240 return 0; 250 241 251 242 dt_get_reg_format(parent, &naddr, &nsize); 252 - 253 243 if (nsize > 2) 254 244 return 0; 255 245 ··· 260 252 261 253 copy_val(last_addr, prop_buf + offset, naddr); 262 254 263 - ret_size = prop_buf[offset + naddr]; 255 + ret_size = be32_to_cpu(prop_buf[offset + naddr]); 264 256 if (nsize == 2) { 265 257 ret_size <<= 32; 266 - ret_size |= prop_buf[offset + naddr + 1]; 258 + ret_size |= be32_to_cpu(prop_buf[offset + naddr + 1]); 267 259 } 268 260 269 261 for (;;) { ··· 286 278 287 279 offset = find_range(last_addr, prop_buf, prev_naddr, 288 280 naddr, prev_nsize, buflen / 4); 289 - 290 281 if (offset < 0) 291 282 return 0; 292 283 ··· 303 296 if (naddr > 2) 304 297 return 0; 305 298 306 - ret_addr = ((u64)last_addr[2] << 32) | last_addr[3]; 307 - 299 + ret_addr = ((u64)be32_to_cpu(last_addr[2]) << 32) | be32_to_cpu(last_addr[3]); 308 300 if (sizeof(void *) == 4 && 309 301 (ret_addr >= 0x100000000ULL || ret_size > 0x100000000ULL || 310 302 ret_addr + ret_size > 0x100000000ULL)) ··· 356 350 int dt_get_virtual_reg(void *node, void **addr, int nres) 357 351 { 358 352 unsigned long xaddr; 359 - int n; 353 + int n, i; 360 354 361 355 n = getprop(node, "virtual-reg", addr, nres * 4); 362 - if (n > 0) 356 + if (n > 0) { 357 + for (i = 0; i < n/4; i ++) 358 + ((u32 *)addr)[i] = be32_to_cpu(((u32 *)addr)[i]); 363 359 return n / 4; 360 + } 364 361 365 362 for (n = 0; n < nres; n++) { 366 363 if (!dt_xlate_reg(node, n, &xaddr, NULL))
+138
arch/powerpc/boot/dts/microwatt.dts
··· 1 + /dts-v1/; 2 + 3 + / { 4 + #size-cells = <0x02>; 5 + #address-cells = <0x02>; 6 + model-name = "microwatt"; 7 + compatible = "microwatt-soc"; 8 + 9 + aliases { 10 + serial0 = &UART0; 11 + }; 12 + 13 + reserved-memory { 14 + #size-cells = <0x02>; 15 + #address-cells = <0x02>; 16 + ranges; 17 + }; 18 + 19 + memory@0 { 20 + device_type = "memory"; 21 + reg = <0x00000000 0x00000000 0x00000000 0x10000000>; 22 + }; 23 + 24 + cpus { 25 + #size-cells = <0x00>; 26 + #address-cells = <0x01>; 27 + 28 + ibm,powerpc-cpu-features { 29 + display-name = "Microwatt"; 30 + isa = <3000>; 31 + device_type = "cpu-features"; 32 + compatible = "ibm,powerpc-cpu-features"; 33 + 34 + mmu-radix { 35 + isa = <3000>; 36 + usable-privilege = <2>; 37 + }; 38 + 39 + little-endian { 40 + isa = <2050>; 41 + usable-privilege = <3>; 42 + hwcap-bit-nr = <1>; 43 + }; 44 + 45 + cache-inhibited-large-page { 46 + isa = <2040>; 47 + usable-privilege = <2>; 48 + }; 49 + 50 + fixed-point-v3 { 51 + isa = <3000>; 52 + usable-privilege = <3>; 53 + }; 54 + 55 + no-execute { 56 + isa = <2010>; 57 + usable-privilege = <2>; 58 + }; 59 + 60 + floating-point { 61 + hwcap-bit-nr = <27>; 62 + isa = <0>; 63 + usable-privilege = <3>; 64 + }; 65 + }; 66 + 67 + PowerPC,Microwatt@0 { 68 + i-cache-sets = <2>; 69 + ibm,dec-bits = <64>; 70 + reservation-granule-size = <64>; 71 + clock-frequency = <100000000>; 72 + timebase-frequency = <100000000>; 73 + i-tlb-sets = <1>; 74 + ibm,ppc-interrupt-server#s = <0>; 75 + i-cache-block-size = <64>; 76 + d-cache-block-size = <64>; 77 + d-cache-sets = <2>; 78 + i-tlb-size = <64>; 79 + cpu-version = <0x990000>; 80 + status = "okay"; 81 + i-cache-size = <0x1000>; 82 + ibm,processor-radix-AP-encodings = <0x0c 0xa0000010 0x20000015 0x4000001e>; 83 + tlb-size = <0>; 84 + tlb-sets = <0>; 85 + device_type = "cpu"; 86 + d-tlb-size = <128>; 87 + d-tlb-sets = <2>; 88 + reg = <0>; 89 + general-purpose; 90 + 64-bit; 91 + d-cache-size = <0x1000>; 92 + ibm,chip-id = <0>; 93 + }; 94 + }; 95 + 96 + soc@c0000000 { 97 + compatible = "simple-bus"; 98 + #address-cells = <1>; 99 + #size-cells = <1>; 100 + interrupt-parent = <&ICS>; 101 + 102 + ranges = <0 0 0xc0000000 0x40000000>; 103 + 104 + interrupt-controller@4000 { 105 + compatible = "openpower,xics-presentation", "ibm,ppc-xicp"; 106 + ibm,interrupt-server-ranges = <0x0 0x1>; 107 + reg = <0x4000 0x100>; 108 + }; 109 + 110 + ICS: interrupt-controller@5000 { 111 + compatible = "openpower,xics-sources"; 112 + interrupt-controller; 113 + interrupt-ranges = <0x10 0x10>; 114 + reg = <0x5000 0x100>; 115 + #address-cells = <0>; 116 + #size-cells = <0>; 117 + #interrupt-cells = <2>; 118 + }; 119 + 120 + UART0: serial@2000 { 121 + device_type = "serial"; 122 + compatible = "ns16550"; 123 + reg = <0x2000 0x8>; 124 + clock-frequency = <100000000>; 125 + current-speed = <115200>; 126 + reg-shift = <2>; 127 + fifo-size = <16>; 128 + interrupts = <0x10 0x1>; 129 + }; 130 + }; 131 + 132 + chosen { 133 + bootargs = ""; 134 + ibm,architecture-vec-5 = [19 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 135 + 00 00 00 00 00 00 00 00 40 00 40]; 136 + stdout-path = &UART0; 137 + }; 138 + };
+24
arch/powerpc/boot/microwatt.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <stddef.h> 4 + #include "stdio.h" 5 + #include "types.h" 6 + #include "io.h" 7 + #include "ops.h" 8 + 9 + BSS_STACK(8192); 10 + 11 + void platform_init(unsigned long r3, unsigned long r4, unsigned long r5) 12 + { 13 + unsigned long heapsize = 16*1024*1024 - (unsigned long)_end; 14 + 15 + /* 16 + * Disable interrupts and turn off MSR_RI, since we'll 17 + * shortly be overwriting the interrupt vectors. 18 + */ 19 + __asm__ volatile("mtmsrd %0,1" : : "r" (0)); 20 + 21 + simple_alloc_init(_end, heapsize, 32, 64); 22 + fdt_init(_dtb_start); 23 + serial_console_init(); 24 + }
+7 -2
arch/powerpc/boot/ns16550.c
··· 15 15 #include "stdio.h" 16 16 #include "io.h" 17 17 #include "ops.h" 18 + #include "of.h" 18 19 19 20 #define UART_DLL 0 /* Out: Divisor Latch Low */ 20 21 #define UART_DLM 1 /* Out: Divisor Latch High */ ··· 59 58 int n; 60 59 u32 reg_offset; 61 60 62 - if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1) 61 + if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1) { 62 + printf("virt reg parse fail...\r\n"); 63 63 return -1; 64 + } 64 65 65 66 n = getprop(devp, "reg-offset", &reg_offset, sizeof(reg_offset)); 66 67 if (n == sizeof(reg_offset)) 67 - reg_base += reg_offset; 68 + reg_base += be32_to_cpu(reg_offset); 68 69 69 70 n = getprop(devp, "reg-shift", &reg_shift, sizeof(reg_shift)); 70 71 if (n != sizeof(reg_shift)) 71 72 reg_shift = 0; 73 + else 74 + reg_shift = be32_to_cpu(reg_shift); 72 75 73 76 scdp->open = ns16550_open; 74 77 scdp->putc = ns16550_putc;
+5
arch/powerpc/boot/wrapper
··· 342 342 link_address='0x600000' 343 343 platformo="$object/$platform-head.o $object/$platform.o" 344 344 ;; 345 + microwatt) 346 + link_address='0x500000' 347 + platformo="$object/fixed-head.o $object/$platform.o" 348 + binary=y 349 + ;; 345 350 treeboot-currituck) 346 351 link_address='0x1000000' 347 352 ;;
+1 -1
arch/powerpc/boot/zImage.ps3.lds.S
··· 8 8 .kernel:vmlinux.bin : { *(.kernel:vmlinux.bin) } 9 9 _vmlinux_end = .; 10 10 11 - . = ALIGN(4096); 11 + . = ALIGN(8); 12 12 _dtb_start = .; 13 13 .kernel:dtb : { *(.kernel:dtb) } 14 14 _dtb_end = .;
+1
arch/powerpc/configs/32-bit.config
··· 1 + # CONFIG_PPC64 is not set
+1
arch/powerpc/configs/64-bit.config
··· 1 + CONFIG_PPC64=y
+98
arch/powerpc/configs/microwatt_defconfig
··· 1 + # CONFIG_SWAP is not set 2 + # CONFIG_CROSS_MEMORY_ATTACH is not set 3 + CONFIG_HIGH_RES_TIMERS=y 4 + CONFIG_PREEMPT_VOLUNTARY=y 5 + CONFIG_TICK_CPU_ACCOUNTING=y 6 + CONFIG_LOG_BUF_SHIFT=16 7 + CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=12 8 + CONFIG_BLK_DEV_INITRD=y 9 + CONFIG_CC_OPTIMIZE_FOR_SIZE=y 10 + CONFIG_KALLSYMS_ALL=y 11 + CONFIG_EMBEDDED=y 12 + # CONFIG_VM_EVENT_COUNTERS is not set 13 + # CONFIG_SLUB_DEBUG is not set 14 + # CONFIG_COMPAT_BRK is not set 15 + # CONFIG_SLAB_MERGE_DEFAULT is not set 16 + CONFIG_PPC64=y 17 + # CONFIG_PPC_KUEP is not set 18 + # CONFIG_PPC_KUAP is not set 19 + CONFIG_CPU_LITTLE_ENDIAN=y 20 + CONFIG_NR_IRQS=64 21 + CONFIG_PANIC_TIMEOUT=10 22 + # CONFIG_PPC_POWERNV is not set 23 + # CONFIG_PPC_PSERIES is not set 24 + CONFIG_PPC_MICROWATT=y 25 + # CONFIG_PPC_OF_BOOT_TRAMPOLINE is not set 26 + CONFIG_CPU_FREQ=y 27 + CONFIG_HZ_100=y 28 + # CONFIG_PPC_MEM_KEYS is not set 29 + # CONFIG_SECCOMP is not set 30 + # CONFIG_MQ_IOSCHED_KYBER is not set 31 + # CONFIG_COREDUMP is not set 32 + # CONFIG_COMPACTION is not set 33 + # CONFIG_MIGRATION is not set 34 + CONFIG_NET=y 35 + CONFIG_PACKET=y 36 + CONFIG_PACKET_DIAG=y 37 + CONFIG_UNIX=y 38 + CONFIG_UNIX_DIAG=y 39 + CONFIG_INET=y 40 + CONFIG_INET_UDP_DIAG=y 41 + CONFIG_INET_RAW_DIAG=y 42 + # CONFIG_WIRELESS is not set 43 + CONFIG_DEVTMPFS=y 44 + CONFIG_DEVTMPFS_MOUNT=y 45 + # CONFIG_STANDALONE is not set 46 + # CONFIG_PREVENT_FIRMWARE_BUILD is not set 47 + # CONFIG_FW_LOADER is not set 48 + # CONFIG_ALLOW_DEV_COREDUMP is not set 49 + CONFIG_MTD=y 50 + CONFIG_MTD_BLOCK=y 51 + CONFIG_MTD_PARTITIONED_MASTER=y 52 + CONFIG_MTD_SPI_NOR=y 53 + CONFIG_BLK_DEV_LOOP=y 54 + CONFIG_BLK_DEV_RAM=y 55 + CONFIG_NETDEVICES=y 56 + # CONFIG_WLAN is not set 57 + # CONFIG_INPUT is not set 58 + # CONFIG_SERIO is not set 59 + # CONFIG_VT is not set 60 + CONFIG_SERIAL_8250=y 61 + # CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set 62 + CONFIG_SERIAL_8250_CONSOLE=y 63 + CONFIG_SERIAL_OF_PLATFORM=y 64 + CONFIG_SERIAL_NONSTANDARD=y 65 + # CONFIG_NVRAM is not set 66 + CONFIG_RANDOM_TRUST_CPU=y 67 + CONFIG_SPI=y 68 + CONFIG_SPI_DEBUG=y 69 + CONFIG_SPI_BITBANG=y 70 + CONFIG_SPI_SPIDEV=y 71 + # CONFIG_HWMON is not set 72 + # CONFIG_USB_SUPPORT is not set 73 + # CONFIG_VIRTIO_MENU is not set 74 + # CONFIG_IOMMU_SUPPORT is not set 75 + # CONFIG_NVMEM is not set 76 + CONFIG_EXT4_FS=y 77 + # CONFIG_FILE_LOCKING is not set 78 + # CONFIG_DNOTIFY is not set 79 + # CONFIG_INOTIFY_USER is not set 80 + # CONFIG_MISC_FILESYSTEMS is not set 81 + # CONFIG_CRYPTO_HW is not set 82 + # CONFIG_XZ_DEC_X86 is not set 83 + # CONFIG_XZ_DEC_IA64 is not set 84 + # CONFIG_XZ_DEC_ARM is not set 85 + # CONFIG_XZ_DEC_ARMTHUMB is not set 86 + # CONFIG_XZ_DEC_SPARC is not set 87 + CONFIG_PRINTK_TIME=y 88 + # CONFIG_SYMBOLIC_ERRNAME is not set 89 + # CONFIG_DEBUG_BUGVERBOSE is not set 90 + # CONFIG_DEBUG_MISC is not set 91 + # CONFIG_SCHED_DEBUG is not set 92 + # CONFIG_FTRACE is not set 93 + # CONFIG_STRICT_DEVMEM is not set 94 + CONFIG_PPC_DISABLE_WERROR=y 95 + CONFIG_XMON=y 96 + CONFIG_XMON_DEFAULT=y 97 + # CONFIG_XMON_DEFAULT_RO_MODE is not set 98 + # CONFIG_RUNTIME_TESTING_MENU is not set
+25
arch/powerpc/configs/mpc885_ads_defconfig
··· 57 57 CONFIG_DEBUG_INFO=y 58 58 CONFIG_MAGIC_SYSRQ=y 59 59 CONFIG_DETECT_HUNG_TASK=y 60 + CONFIG_PPC_16K_PAGES=y 61 + CONFIG_DEBUG_KERNEL=y 62 + CONFIG_DEBUG_FS=y 63 + CONFIG_PPC_PTDUMP=y 64 + CONFIG_MODULES=y 65 + CONFIG_SPI=y 66 + CONFIG_SPI_FSL_SPI=y 67 + CONFIG_CRYPTO=y 68 + CONFIG_CRYPTO_DEV_TALITOS=y 69 + CONFIG_8xx_GPIO=y 70 + CONFIG_WATCHDOG=y 71 + CONFIG_8xxx_WDT=y 72 + CONFIG_SMC_UCODE_PATCH=y 73 + CONFIG_ADVANCED_OPTIONS=y 74 + CONFIG_PIN_TLB=y 75 + CONFIG_PERF_EVENTS=y 76 + CONFIG_MATH_EMULATION=y 77 + CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y 78 + CONFIG_STRICT_KERNEL_RWX=y 79 + CONFIG_IPV6=y 80 + CONFIG_BPF_JIT=y 81 + CONFIG_DEBUG_VM_PGTABLE=y 82 + CONFIG_BDI_SWITCH=y 83 + CONFIG_PPC_EARLY_DEBUG=y 84 + CONFIG_PPC_EARLY_DEBUG_CPM_ADDR=0xff002008
+1
arch/powerpc/configs/powernv_defconfig
··· 309 309 CONFIG_HARDLOCKUP_DETECTOR=y 310 310 CONFIG_FUNCTION_TRACER=y 311 311 CONFIG_SCHED_TRACER=y 312 + CONFIG_STACK_TRACER=y 312 313 CONFIG_FTRACE_SYSCALLS=y 313 314 CONFIG_BLK_DEV_IO_TRACE=y 314 315 CONFIG_PPC_EMULATED_STATS=y
+2
arch/powerpc/configs/ppc64_defconfig
··· 368 368 CONFIG_HARDLOCKUP_DETECTOR=y 369 369 CONFIG_DEBUG_MUTEXES=y 370 370 CONFIG_FUNCTION_TRACER=y 371 + CONFIG_FTRACE_SYSCALLS=y 371 372 CONFIG_SCHED_TRACER=y 373 + CONFIG_STACK_TRACER=y 372 374 CONFIG_BLK_DEV_IO_TRACE=y 373 375 CONFIG_CODE_PATCHING_SELFTEST=y 374 376 CONFIG_FTR_FIXUP_SELFTEST=y
+2
arch/powerpc/configs/pseries_defconfig
··· 289 289 CONFIG_SOFTLOCKUP_DETECTOR=y 290 290 CONFIG_HARDLOCKUP_DETECTOR=y 291 291 CONFIG_FUNCTION_TRACER=y 292 + CONFIG_FTRACE_SYSCALLS=y 292 293 CONFIG_SCHED_TRACER=y 294 + CONFIG_STACK_TRACER=y 293 295 CONFIG_BLK_DEV_IO_TRACE=y 294 296 CONFIG_CODE_PATCHING_SELFTEST=y 295 297 CONFIG_FTR_FIXUP_SELFTEST=y
+7 -2
arch/powerpc/include/asm/asm-prototypes.h
··· 71 71 #endif 72 72 long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, unsigned long r0, struct pt_regs *regs); 73 73 notrace unsigned long syscall_exit_prepare(unsigned long r3, struct pt_regs *regs, long scv); 74 - notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long msr); 75 - notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsigned long msr); 74 + notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs); 75 + notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs); 76 + #ifdef CONFIG_PPC64 77 + unsigned long syscall_exit_restart(unsigned long r3, struct pt_regs *regs); 78 + unsigned long interrupt_exit_user_restart(struct pt_regs *regs); 79 + unsigned long interrupt_exit_kernel_restart(struct pt_regs *regs); 80 + #endif 76 81 77 82 long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low, 78 83 u32 len_high, u32 len_low);
+2
arch/powerpc/include/asm/barrier.h
··· 46 46 # define SMPWMB eieio 47 47 #endif 48 48 49 + /* clang defines this macro for a builtin, which will not work with runtime patching */ 50 + #undef __lwsync 49 51 #define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory") 50 52 #define dma_rmb() __lwsync() 51 53 #define dma_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
-45
arch/powerpc/include/asm/book3s/32/hash.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _ASM_POWERPC_BOOK3S_32_HASH_H 3 - #define _ASM_POWERPC_BOOK3S_32_HASH_H 4 - #ifdef __KERNEL__ 5 - 6 - /* 7 - * The "classic" 32-bit implementation of the PowerPC MMU uses a hash 8 - * table containing PTEs, together with a set of 16 segment registers, 9 - * to define the virtual to physical address mapping. 10 - * 11 - * We use the hash table as an extended TLB, i.e. a cache of currently 12 - * active mappings. We maintain a two-level page table tree, much 13 - * like that used by the i386, for the sake of the Linux memory 14 - * management code. Low-level assembler code in hash_low_32.S 15 - * (procedure hash_page) is responsible for extracting ptes from the 16 - * tree and putting them into the hash table when necessary, and 17 - * updating the accessed and modified bits in the page table tree. 18 - */ 19 - 20 - #define _PAGE_PRESENT 0x001 /* software: pte contains a translation */ 21 - #define _PAGE_HASHPTE 0x002 /* hash_page has made an HPTE for this pte */ 22 - #define _PAGE_USER 0x004 /* usermode access allowed */ 23 - #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */ 24 - #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */ 25 - #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */ 26 - #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */ 27 - #define _PAGE_DIRTY 0x080 /* C: page changed */ 28 - #define _PAGE_ACCESSED 0x100 /* R: page referenced */ 29 - #define _PAGE_EXEC 0x200 /* software: exec allowed */ 30 - #define _PAGE_RW 0x400 /* software: user write access allowed */ 31 - #define _PAGE_SPECIAL 0x800 /* software: Special page */ 32 - 33 - #ifdef CONFIG_PTE_64BIT 34 - /* We never clear the high word of the pte */ 35 - #define _PTE_NONE_MASK (0xffffffff00000000ULL | _PAGE_HASHPTE) 36 - #else 37 - #define _PTE_NONE_MASK _PAGE_HASHPTE 38 - #endif 39 - 40 - #define _PMD_PRESENT 0 41 - #define _PMD_PRESENT_MASK (PAGE_MASK) 42 - #define _PMD_BAD (~PAGE_MASK) 43 - 44 - #endif /* __KERNEL__ */ 45 - #endif /* _ASM_POWERPC_BOOK3S_32_HASH_H */
+130 -67
arch/powerpc/include/asm/book3s/32/kup.h
··· 7 7 8 8 #ifndef __ASSEMBLY__ 9 9 10 + #include <linux/jump_label.h> 11 + 12 + extern struct static_key_false disable_kuap_key; 13 + extern struct static_key_false disable_kuep_key; 14 + 15 + static __always_inline bool kuap_is_disabled(void) 16 + { 17 + return !IS_ENABLED(CONFIG_PPC_KUAP) || static_branch_unlikely(&disable_kuap_key); 18 + } 19 + 20 + static __always_inline bool kuep_is_disabled(void) 21 + { 22 + return !IS_ENABLED(CONFIG_PPC_KUEP) || static_branch_unlikely(&disable_kuep_key); 23 + } 24 + 25 + static inline void kuep_lock(void) 26 + { 27 + if (kuep_is_disabled()) 28 + return; 29 + 30 + update_user_segments(mfsr(0) | SR_NX); 31 + } 32 + 33 + static inline void kuep_unlock(void) 34 + { 35 + if (kuep_is_disabled()) 36 + return; 37 + 38 + update_user_segments(mfsr(0) & ~SR_NX); 39 + } 40 + 10 41 #ifdef CONFIG_PPC_KUAP 11 42 12 43 #include <linux/sched.h> 13 44 14 - static inline void kuap_update_sr(u32 sr, u32 addr, u32 end) 45 + #define KUAP_NONE (~0UL) 46 + #define KUAP_ALL (~1UL) 47 + 48 + static inline void kuap_lock_one(unsigned long addr) 15 49 { 16 - addr &= 0xf0000000; /* align addr to start of segment */ 17 - barrier(); /* make sure thread.kuap is updated before playing with SRs */ 18 - while (addr < end) { 19 - mtsr(sr, addr); 20 - sr += 0x111; /* next VSID */ 21 - sr &= 0xf0ffffff; /* clear VSID overflow */ 22 - addr += 0x10000000; /* address of next segment */ 23 - } 50 + mtsr(mfsr(addr) | SR_KS, addr); 24 51 isync(); /* Context sync required after mtsr() */ 52 + } 53 + 54 + static inline void kuap_unlock_one(unsigned long addr) 55 + { 56 + mtsr(mfsr(addr) & ~SR_KS, addr); 57 + isync(); /* Context sync required after mtsr() */ 58 + } 59 + 60 + static inline void kuap_lock_all(void) 61 + { 62 + update_user_segments(mfsr(0) | SR_KS); 63 + isync(); /* Context sync required after mtsr() */ 64 + } 65 + 66 + static inline void kuap_unlock_all(void) 67 + { 68 + update_user_segments(mfsr(0) & ~SR_KS); 69 + isync(); /* Context sync required after mtsr() */ 70 + } 71 + 72 + void kuap_lock_all_ool(void); 73 + void kuap_unlock_all_ool(void); 74 + 75 + static inline void kuap_lock(unsigned long addr, bool ool) 76 + { 77 + if (likely(addr != KUAP_ALL)) 78 + kuap_lock_one(addr); 79 + else if (!ool) 80 + kuap_lock_all(); 81 + else 82 + kuap_lock_all_ool(); 83 + } 84 + 85 + static inline void kuap_unlock(unsigned long addr, bool ool) 86 + { 87 + if (likely(addr != KUAP_ALL)) 88 + kuap_unlock_one(addr); 89 + else if (!ool) 90 + kuap_unlock_all(); 91 + else 92 + kuap_unlock_all_ool(); 25 93 } 26 94 27 95 static inline void kuap_save_and_lock(struct pt_regs *regs) 28 96 { 29 97 unsigned long kuap = current->thread.kuap; 30 - u32 addr = kuap & 0xf0000000; 31 - u32 end = kuap << 28; 32 98 33 - regs->kuap = kuap; 34 - if (unlikely(!kuap)) 99 + if (kuap_is_disabled()) 35 100 return; 36 101 37 - current->thread.kuap = 0; 38 - kuap_update_sr(mfsr(addr) | SR_KS, addr, end); /* Set Ks */ 102 + regs->kuap = kuap; 103 + if (unlikely(kuap == KUAP_NONE)) 104 + return; 105 + 106 + current->thread.kuap = KUAP_NONE; 107 + kuap_lock(kuap, false); 39 108 } 40 109 41 110 static inline void kuap_user_restore(struct pt_regs *regs) ··· 113 44 114 45 static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap) 115 46 { 116 - u32 addr = regs->kuap & 0xf0000000; 117 - u32 end = regs->kuap << 28; 47 + if (kuap_is_disabled()) 48 + return; 118 49 119 50 current->thread.kuap = regs->kuap; 120 51 121 - if (unlikely(regs->kuap == kuap)) 122 - return; 123 - 124 - kuap_update_sr(mfsr(addr) & ~SR_KS, addr, end); /* Clear Ks */ 52 + kuap_unlock(regs->kuap, false); 125 53 } 126 54 127 55 static inline unsigned long kuap_get_and_assert_locked(void) 128 56 { 129 57 unsigned long kuap = current->thread.kuap; 130 58 131 - WARN_ON_ONCE(IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && kuap != 0); 59 + if (kuap_is_disabled()) 60 + return KUAP_NONE; 61 + 62 + WARN_ON_ONCE(IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && kuap != KUAP_NONE); 132 63 133 64 return kuap; 134 65 } ··· 141 72 static __always_inline void allow_user_access(void __user *to, const void __user *from, 142 73 u32 size, unsigned long dir) 143 74 { 144 - u32 addr, end; 75 + if (kuap_is_disabled()) 76 + return; 145 77 146 78 BUILD_BUG_ON(!__builtin_constant_p(dir)); 147 - BUILD_BUG_ON(dir & ~KUAP_READ_WRITE); 148 79 149 80 if (!(dir & KUAP_WRITE)) 150 81 return; 151 82 152 - addr = (__force u32)to; 153 - 154 - if (unlikely(addr >= TASK_SIZE || !size)) 155 - return; 156 - 157 - end = min(addr + size, TASK_SIZE); 158 - 159 - current->thread.kuap = (addr & 0xf0000000) | ((((end - 1) >> 28) + 1) & 0xf); 160 - kuap_update_sr(mfsr(addr) & ~SR_KS, addr, end); /* Clear Ks */ 83 + current->thread.kuap = (__force u32)to; 84 + kuap_unlock_one((__force u32)to); 161 85 } 162 86 163 - static __always_inline void prevent_user_access(void __user *to, const void __user *from, 164 - u32 size, unsigned long dir) 87 + static __always_inline void prevent_user_access(unsigned long dir) 165 88 { 166 - u32 addr, end; 89 + u32 kuap = current->thread.kuap; 90 + 91 + if (kuap_is_disabled()) 92 + return; 167 93 168 94 BUILD_BUG_ON(!__builtin_constant_p(dir)); 169 95 170 - if (dir & KUAP_CURRENT_WRITE) { 171 - u32 kuap = current->thread.kuap; 172 - 173 - if (unlikely(!kuap)) 174 - return; 175 - 176 - addr = kuap & 0xf0000000; 177 - end = kuap << 28; 178 - } else if (dir & KUAP_WRITE) { 179 - addr = (__force u32)to; 180 - end = min(addr + size, TASK_SIZE); 181 - 182 - if (unlikely(addr >= TASK_SIZE || !size)) 183 - return; 184 - } else { 96 + if (!(dir & KUAP_WRITE)) 185 97 return; 186 - } 187 98 188 - current->thread.kuap = 0; 189 - kuap_update_sr(mfsr(addr) | SR_KS, addr, end); /* set Ks */ 99 + current->thread.kuap = KUAP_NONE; 100 + kuap_lock(kuap, true); 190 101 } 191 102 192 103 static inline unsigned long prevent_user_access_return(void) 193 104 { 194 105 unsigned long flags = current->thread.kuap; 195 - unsigned long addr = flags & 0xf0000000; 196 - unsigned long end = flags << 28; 197 - void __user *to = (__force void __user *)addr; 198 106 199 - if (flags) 200 - prevent_user_access(to, to, end - addr, KUAP_READ_WRITE); 107 + if (kuap_is_disabled()) 108 + return KUAP_NONE; 109 + 110 + if (flags != KUAP_NONE) { 111 + current->thread.kuap = KUAP_NONE; 112 + kuap_lock(flags, true); 113 + } 201 114 202 115 return flags; 203 116 } 204 117 205 118 static inline void restore_user_access(unsigned long flags) 206 119 { 207 - unsigned long addr = flags & 0xf0000000; 208 - unsigned long end = flags << 28; 209 - void __user *to = (__force void __user *)addr; 120 + if (kuap_is_disabled()) 121 + return; 210 122 211 - if (flags) 212 - allow_user_access(to, to, end - addr, KUAP_READ_WRITE); 123 + if (flags != KUAP_NONE) { 124 + current->thread.kuap = flags; 125 + kuap_unlock(flags, true); 126 + } 213 127 } 214 128 215 129 static inline bool 216 130 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) 217 131 { 218 - unsigned long begin = regs->kuap & 0xf0000000; 219 - unsigned long end = regs->kuap << 28; 132 + unsigned long kuap = regs->kuap; 220 133 221 - return is_write && (address < begin || address >= end); 134 + if (kuap_is_disabled()) 135 + return false; 136 + 137 + if (!is_write || kuap == KUAP_ALL) 138 + return false; 139 + if (kuap == KUAP_NONE) 140 + return true; 141 + 142 + /* If faulting address doesn't match unlocked segment, unlock all */ 143 + if ((kuap ^ address) & 0xf0000000) 144 + regs->kuap = KUAP_ALL; 145 + 146 + return false; 222 147 } 223 148 224 149 #endif /* CONFIG_PPC_KUAP */
+41
arch/powerpc/include/asm/book3s/32/mmu-hash.h
··· 67 67 #ifndef __ASSEMBLY__ 68 68 69 69 /* 70 + * This macro defines the mapping from contexts to VSIDs (virtual 71 + * segment IDs). We use a skew on both the context and the high 4 bits 72 + * of the 32-bit virtual address (the "effective segment ID") in order 73 + * to spread out the entries in the MMU hash table. Note, if this 74 + * function is changed then hash functions will have to be 75 + * changed to correspond. 76 + */ 77 + #define CTX_TO_VSID(c, id) ((((c) * (897 * 16)) + (id * 0x111)) & 0xffffff) 78 + 79 + /* 70 80 * Hardware Page Table Entry 71 81 * Note that the xpn and x bitfields are used only by processors that 72 82 * support extended addressing; otherwise, those bits are reserved. ··· 111 101 extern s32 patch__hash_page_B, patch__hash_page_C; 112 102 extern s32 patch__flush_hash_A0, patch__flush_hash_A1, patch__flush_hash_A2; 113 103 extern s32 patch__flush_hash_B; 104 + 105 + #include <asm/reg.h> 106 + #include <asm/task_size_32.h> 107 + 108 + static __always_inline void update_user_segment(u32 n, u32 val) 109 + { 110 + if (n << 28 < TASK_SIZE) 111 + mtsr(val + n * 0x111, n << 28); 112 + } 113 + 114 + static __always_inline void update_user_segments(u32 val) 115 + { 116 + val &= 0xf0ffffff; 117 + 118 + update_user_segment(0, val); 119 + update_user_segment(1, val); 120 + update_user_segment(2, val); 121 + update_user_segment(3, val); 122 + update_user_segment(4, val); 123 + update_user_segment(5, val); 124 + update_user_segment(6, val); 125 + update_user_segment(7, val); 126 + update_user_segment(8, val); 127 + update_user_segment(9, val); 128 + update_user_segment(10, val); 129 + update_user_segment(11, val); 130 + update_user_segment(12, val); 131 + update_user_segment(13, val); 132 + update_user_segment(14, val); 133 + update_user_segment(15, val); 134 + } 114 135 115 136 #endif /* !__ASSEMBLY__ */ 116 137
+37 -1
arch/powerpc/include/asm/book3s/32/pgtable.h
··· 4 4 5 5 #include <asm-generic/pgtable-nopmd.h> 6 6 7 - #include <asm/book3s/32/hash.h> 7 + /* 8 + * The "classic" 32-bit implementation of the PowerPC MMU uses a hash 9 + * table containing PTEs, together with a set of 16 segment registers, 10 + * to define the virtual to physical address mapping. 11 + * 12 + * We use the hash table as an extended TLB, i.e. a cache of currently 13 + * active mappings. We maintain a two-level page table tree, much 14 + * like that used by the i386, for the sake of the Linux memory 15 + * management code. Low-level assembler code in hash_low_32.S 16 + * (procedure hash_page) is responsible for extracting ptes from the 17 + * tree and putting them into the hash table when necessary, and 18 + * updating the accessed and modified bits in the page table tree. 19 + */ 20 + 21 + #define _PAGE_PRESENT 0x001 /* software: pte contains a translation */ 22 + #define _PAGE_HASHPTE 0x002 /* hash_page has made an HPTE for this pte */ 23 + #define _PAGE_USER 0x004 /* usermode access allowed */ 24 + #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */ 25 + #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */ 26 + #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */ 27 + #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */ 28 + #define _PAGE_DIRTY 0x080 /* C: page changed */ 29 + #define _PAGE_ACCESSED 0x100 /* R: page referenced */ 30 + #define _PAGE_EXEC 0x200 /* software: exec allowed */ 31 + #define _PAGE_RW 0x400 /* software: user write access allowed */ 32 + #define _PAGE_SPECIAL 0x800 /* software: Special page */ 33 + 34 + #ifdef CONFIG_PTE_64BIT 35 + /* We never clear the high word of the pte */ 36 + #define _PTE_NONE_MASK (0xffffffff00000000ULL | _PAGE_HASHPTE) 37 + #else 38 + #define _PTE_NONE_MASK _PAGE_HASHPTE 39 + #endif 40 + 41 + #define _PMD_PRESENT 0 42 + #define _PMD_PRESENT_MASK (PAGE_MASK) 43 + #define _PMD_BAD (~PAGE_MASK) 8 44 9 45 /* And here we include common definitions */ 10 46
+1 -2
arch/powerpc/include/asm/book3s/64/kup.h
··· 398 398 399 399 #endif /* !CONFIG_PPC_KUAP */ 400 400 401 - static inline void prevent_user_access(void __user *to, const void __user *from, 402 - unsigned long size, unsigned long dir) 401 + static inline void prevent_user_access(unsigned long dir) 403 402 { 404 403 set_kuap(AMR_KUAP_BLOCKED); 405 404 if (static_branch_unlikely(&uaccess_flush_key))
+3
arch/powerpc/include/asm/book3s/64/pgtable.h
··· 232 232 #define PTRS_PER_PUD (1 << PUD_INDEX_SIZE) 233 233 #define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) 234 234 235 + #define MAX_PTRS_PER_PGD (1 << (H_PGD_INDEX_SIZE > RADIX_PGD_INDEX_SIZE ? \ 236 + H_PGD_INDEX_SIZE : RADIX_PGD_INDEX_SIZE)) 237 + 235 238 /* PMD_SHIFT determines what a second-level page table entry can map */ 236 239 #define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE) 237 240 #define PMD_SIZE (1UL << PMD_SHIFT)
+1 -1
arch/powerpc/include/asm/checksum.h
··· 91 91 } 92 92 93 93 #define HAVE_ARCH_CSUM_ADD 94 - static inline __wsum csum_add(__wsum csum, __wsum addend) 94 + static __always_inline __wsum csum_add(__wsum csum, __wsum addend) 95 95 { 96 96 #ifdef __powerpc64__ 97 97 u64 res = (__force u64)csum;
+15 -19
arch/powerpc/include/asm/code-patching.h
··· 23 23 #define BRANCH_ABSOLUTE 0x2 24 24 25 25 bool is_offset_in_branch_range(long offset); 26 - int create_branch(struct ppc_inst *instr, const struct ppc_inst *addr, 26 + int create_branch(struct ppc_inst *instr, const u32 *addr, 27 27 unsigned long target, int flags); 28 - int create_cond_branch(struct ppc_inst *instr, const struct ppc_inst *addr, 28 + int create_cond_branch(struct ppc_inst *instr, const u32 *addr, 29 29 unsigned long target, int flags); 30 - int patch_branch(struct ppc_inst *addr, unsigned long target, int flags); 31 - int patch_instruction(struct ppc_inst *addr, struct ppc_inst instr); 32 - int raw_patch_instruction(struct ppc_inst *addr, struct ppc_inst instr); 30 + int patch_branch(u32 *addr, unsigned long target, int flags); 31 + int patch_instruction(u32 *addr, struct ppc_inst instr); 32 + int raw_patch_instruction(u32 *addr, struct ppc_inst instr); 33 33 34 34 static inline unsigned long patch_site_addr(s32 *site) 35 35 { ··· 38 38 39 39 static inline int patch_instruction_site(s32 *site, struct ppc_inst instr) 40 40 { 41 - return patch_instruction((struct ppc_inst *)patch_site_addr(site), instr); 41 + return patch_instruction((u32 *)patch_site_addr(site), instr); 42 42 } 43 43 44 44 static inline int patch_branch_site(s32 *site, unsigned long target, int flags) 45 45 { 46 - return patch_branch((struct ppc_inst *)patch_site_addr(site), target, flags); 46 + return patch_branch((u32 *)patch_site_addr(site), target, flags); 47 47 } 48 48 49 49 static inline int modify_instruction(unsigned int *addr, unsigned int clr, 50 50 unsigned int set) 51 51 { 52 - return patch_instruction((struct ppc_inst *)addr, ppc_inst((*addr & ~clr) | set)); 52 + return patch_instruction(addr, ppc_inst((*addr & ~clr) | set)); 53 53 } 54 54 55 55 static inline int modify_instruction_site(s32 *site, unsigned int clr, unsigned int set) ··· 59 59 60 60 int instr_is_relative_branch(struct ppc_inst instr); 61 61 int instr_is_relative_link_branch(struct ppc_inst instr); 62 - int instr_is_branch_to_addr(const struct ppc_inst *instr, unsigned long addr); 63 - unsigned long branch_target(const struct ppc_inst *instr); 64 - int translate_branch(struct ppc_inst *instr, const struct ppc_inst *dest, 65 - const struct ppc_inst *src); 62 + unsigned long branch_target(const u32 *instr); 63 + int translate_branch(struct ppc_inst *instr, const u32 *dest, const u32 *src); 66 64 extern bool is_conditional_branch(struct ppc_inst instr); 67 65 #ifdef CONFIG_PPC_BOOK3E_64 68 66 void __patch_exception(int exc, unsigned long addr); ··· 71 73 #endif 72 74 73 75 #define OP_RT_RA_MASK 0xffff0000UL 74 - #define LIS_R2 (PPC_INST_ADDIS | __PPC_RT(R2)) 75 - #define ADDIS_R2_R12 (PPC_INST_ADDIS | __PPC_RT(R2) | __PPC_RA(R12)) 76 - #define ADDI_R2_R2 (PPC_INST_ADDI | __PPC_RT(R2) | __PPC_RA(R2)) 76 + #define LIS_R2 (PPC_RAW_LIS(_R2, 0)) 77 + #define ADDIS_R2_R12 (PPC_RAW_ADDIS(_R2, _R12, 0)) 78 + #define ADDI_R2_R2 (PPC_RAW_ADDI(_R2, _R2, 0)) 77 79 78 80 79 81 static inline unsigned long ppc_function_entry(void *func) ··· 178 180 #define R2_STACK_OFFSET 40 179 181 #endif 180 182 181 - #define PPC_INST_LD_TOC (PPC_INST_LD | ___PPC_RT(__REG_R2) | \ 182 - ___PPC_RA(__REG_R1) | R2_STACK_OFFSET) 183 + #define PPC_INST_LD_TOC PPC_RAW_LD(_R2, _R1, R2_STACK_OFFSET) 183 184 184 185 /* usually preceded by a mflr r0 */ 185 - #define PPC_INST_STD_LR (PPC_INST_STD | ___PPC_RS(__REG_R0) | \ 186 - ___PPC_RA(__REG_R1) | PPC_LR_STKOFF) 186 + #define PPC_INST_STD_LR PPC_RAW_STD(_R0, _R1, PPC_LR_STKOFF) 187 187 #endif /* CONFIG_PPC64 */ 188 188 189 189 #endif /* _ASM_POWERPC_CODE_PATCHING_H */
+1 -1
arch/powerpc/include/asm/head-64.h
··· 16 16 .section ".head.data.\name\()","a",@progbits 17 17 .endm 18 18 .macro use_ftsec name 19 - .section ".head.text.\name\()" 19 + .section ".head.text.\name\()","ax",@progbits 20 20 .endm 21 21 22 22 /*
+10
arch/powerpc/include/asm/hvcall.h
··· 294 294 #define H_RESIZE_HPT_COMMIT 0x370 295 295 #define H_REGISTER_PROC_TBL 0x37C 296 296 #define H_SIGNAL_SYS_RESET 0x380 297 + #define H_ALLOCATE_VAS_WINDOW 0x388 298 + #define H_MODIFY_VAS_WINDOW 0x38C 299 + #define H_DEALLOCATE_VAS_WINDOW 0x390 300 + #define H_QUERY_VAS_WINDOW 0x394 301 + #define H_QUERY_VAS_CAPABILITIES 0x398 302 + #define H_QUERY_NX_CAPABILITIES 0x39C 303 + #define H_GET_NX_FAULT 0x3A0 297 304 #define H_INT_GET_SOURCE_INFO 0x3A8 298 305 #define H_INT_SET_SOURCE_CONFIG 0x3AC 299 306 #define H_INT_GET_SOURCE_CONFIG 0x3B0 ··· 400 393 #define H_CPU_BEHAV_FAVOUR_SECURITY_H (1ull << 60) // IBM bit 3 401 394 #define H_CPU_BEHAV_FLUSH_COUNT_CACHE (1ull << 58) // IBM bit 5 402 395 #define H_CPU_BEHAV_FLUSH_LINK_STACK (1ull << 57) // IBM bit 6 396 + #define H_CPU_BEHAV_NO_L1D_FLUSH_ENTRY (1ull << 56) // IBM bit 7 397 + #define H_CPU_BEHAV_NO_L1D_FLUSH_UACCESS (1ull << 55) // IBM bit 8 398 + #define H_CPU_BEHAV_NO_STF_BARRIER (1ull << 54) // IBM bit 9 403 399 404 400 /* Flag values used in H_REGISTER_PROC_TBL hcall */ 405 401 #define PROC_TABLE_OP_MASK 0x18
+20 -3
arch/powerpc/include/asm/hw_irq.h
··· 18 18 * PACA flags in paca->irq_happened. 19 19 * 20 20 * This bits are set when interrupts occur while soft-disabled 21 - * and allow a proper replay. Additionally, PACA_IRQ_HARD_DIS 22 - * is set whenever we manually hard disable. 21 + * and allow a proper replay. 22 + * 23 + * The PACA_IRQ_HARD_DIS is set whenever we hard disable. It is almost 24 + * always in synch with the MSR[EE] state, except: 25 + * - A window in interrupt entry, where hardware disables MSR[EE] and that 26 + * must be "reconciled" with the soft mask state. 27 + * - NMI interrupts that hit in awkward places, until they fix the state. 28 + * - When local irqs are being enabled and state is being fixed up. 29 + * - When returning from an interrupt there are some windows where this 30 + * can become out of synch, but gets fixed before the RFI or before 31 + * executing the next user instruction (see arch/powerpc/kernel/interrupt.c). 23 32 */ 24 33 #define PACA_IRQ_HARD_DIS 0x01 25 34 #define PACA_IRQ_DBELL 0x02 ··· 398 389 return !(regs->msr & MSR_EE); 399 390 } 400 391 401 - static inline void may_hard_irq_enable(void) { } 392 + static inline bool may_hard_irq_enable(void) 393 + { 394 + return false; 395 + } 396 + 397 + static inline void do_hard_irq_enable(void) 398 + { 399 + BUILD_BUG(); 400 + } 402 401 403 402 static inline void irq_soft_mask_regs_set_state(struct pt_regs *regs, unsigned long val) 404 403 {
+37 -61
arch/powerpc/include/asm/inst.h
··· 8 8 9 9 #define ___get_user_instr(gu_op, dest, ptr) \ 10 10 ({ \ 11 - long __gui_ret = 0; \ 12 - unsigned long __gui_ptr = (unsigned long)ptr; \ 11 + long __gui_ret; \ 12 + u32 __user *__gui_ptr = (u32 __user *)ptr; \ 13 13 struct ppc_inst __gui_inst; \ 14 14 unsigned int __prefix, __suffix; \ 15 - __gui_ret = gu_op(__prefix, (unsigned int __user *)__gui_ptr); \ 15 + \ 16 + __chk_user_ptr(ptr); \ 17 + __gui_ret = gu_op(__prefix, __gui_ptr); \ 16 18 if (__gui_ret == 0) { \ 17 19 if ((__prefix >> 26) == OP_PREFIX) { \ 18 - __gui_ret = gu_op(__suffix, \ 19 - (unsigned int __user *)__gui_ptr + 1); \ 20 - __gui_inst = ppc_inst_prefix(__prefix, \ 21 - __suffix); \ 20 + __gui_ret = gu_op(__suffix, __gui_ptr + 1); \ 21 + __gui_inst = ppc_inst_prefix(__prefix, __suffix); \ 22 22 } else { \ 23 23 __gui_inst = ppc_inst(__prefix); \ 24 24 } \ ··· 29 29 }) 30 30 #else /* !CONFIG_PPC64 */ 31 31 #define ___get_user_instr(gu_op, dest, ptr) \ 32 - gu_op((dest).val, (u32 __user *)(ptr)) 32 + ({ \ 33 + __chk_user_ptr(ptr); \ 34 + gu_op((dest).val, (u32 __user *)(ptr)); \ 35 + }) 33 36 #endif /* CONFIG_PPC64 */ 34 37 35 - #define get_user_instr(x, ptr) \ 36 - ___get_user_instr(get_user, x, ptr) 38 + #define get_user_instr(x, ptr) ___get_user_instr(get_user, x, ptr) 37 39 38 - #define __get_user_instr(x, ptr) \ 39 - ___get_user_instr(__get_user, x, ptr) 40 + #define __get_user_instr(x, ptr) ___get_user_instr(__get_user, x, ptr) 40 41 41 42 /* 42 43 * Instruction data type for POWER ··· 60 59 return ppc_inst_val(x) >> 26; 61 60 } 62 61 63 - #ifdef CONFIG_PPC64 64 - #define ppc_inst(x) ((struct ppc_inst){ .val = (x), .suffix = 0xff }) 62 + #define ppc_inst(x) ((struct ppc_inst){ .val = (x) }) 65 63 64 + #ifdef CONFIG_PPC64 66 65 #define ppc_inst_prefix(x, y) ((struct ppc_inst){ .val = (x), .suffix = (y) }) 67 66 68 67 static inline u32 ppc_inst_suffix(struct ppc_inst x) ··· 70 69 return x.suffix; 71 70 } 72 71 73 - static inline bool ppc_inst_prefixed(struct ppc_inst x) 74 - { 75 - return (ppc_inst_primary_opcode(x) == 1) && ppc_inst_suffix(x) != 0xff; 76 - } 77 - 78 - static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x) 79 - { 80 - return ppc_inst_prefix(swab32(ppc_inst_val(x)), 81 - swab32(ppc_inst_suffix(x))); 82 - } 83 - 84 - static inline struct ppc_inst ppc_inst_read(const struct ppc_inst *ptr) 85 - { 86 - u32 val, suffix; 87 - 88 - val = *(u32 *)ptr; 89 - if ((val >> 26) == OP_PREFIX) { 90 - suffix = *((u32 *)ptr + 1); 91 - return ppc_inst_prefix(val, suffix); 92 - } else { 93 - return ppc_inst(val); 94 - } 95 - } 96 - 97 - static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y) 98 - { 99 - return *(u64 *)&x == *(u64 *)&y; 100 - } 101 - 102 72 #else 103 - 104 - #define ppc_inst(x) ((struct ppc_inst){ .val = x }) 105 - 106 73 #define ppc_inst_prefix(x, y) ppc_inst(x) 107 - 108 - static inline bool ppc_inst_prefixed(struct ppc_inst x) 109 - { 110 - return false; 111 - } 112 74 113 75 static inline u32 ppc_inst_suffix(struct ppc_inst x) 114 76 { 115 77 return 0; 116 78 } 117 79 118 - static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x) 80 + #endif /* CONFIG_PPC64 */ 81 + 82 + static inline struct ppc_inst ppc_inst_read(const u32 *ptr) 119 83 { 120 - return ppc_inst(swab32(ppc_inst_val(x))); 84 + if (IS_ENABLED(CONFIG_PPC64) && (*ptr >> 26) == OP_PREFIX) 85 + return ppc_inst_prefix(*ptr, *(ptr + 1)); 86 + else 87 + return ppc_inst(*ptr); 121 88 } 122 89 123 - static inline struct ppc_inst ppc_inst_read(const struct ppc_inst *ptr) 90 + static inline bool ppc_inst_prefixed(struct ppc_inst x) 124 91 { 125 - return *ptr; 92 + return IS_ENABLED(CONFIG_PPC64) && ppc_inst_primary_opcode(x) == OP_PREFIX; 93 + } 94 + 95 + static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x) 96 + { 97 + return ppc_inst_prefix(swab32(ppc_inst_val(x)), swab32(ppc_inst_suffix(x))); 126 98 } 127 99 128 100 static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y) 129 101 { 130 - return ppc_inst_val(x) == ppc_inst_val(y); 102 + if (ppc_inst_val(x) != ppc_inst_val(y)) 103 + return false; 104 + if (!ppc_inst_prefixed(x)) 105 + return true; 106 + return ppc_inst_suffix(x) == ppc_inst_suffix(y); 131 107 } 132 - 133 - #endif /* CONFIG_PPC64 */ 134 108 135 109 static inline int ppc_inst_len(struct ppc_inst x) 136 110 { ··· 116 140 * Return the address of the next instruction, if the instruction @value was 117 141 * located at @location. 118 142 */ 119 - static inline struct ppc_inst *ppc_inst_next(void *location, struct ppc_inst *value) 143 + static inline u32 *ppc_inst_next(u32 *location, u32 *value) 120 144 { 121 145 struct ppc_inst tmp; 122 146 123 147 tmp = ppc_inst_read(value); 124 148 125 - return location + ppc_inst_len(tmp); 149 + return (void *)location + ppc_inst_len(tmp); 126 150 } 127 151 128 152 static inline unsigned long ppc_inst_as_ulong(struct ppc_inst x) ··· 154 178 __str; \ 155 179 }) 156 180 157 - int copy_inst_from_kernel_nofault(struct ppc_inst *inst, struct ppc_inst *src); 181 + int copy_inst_from_kernel_nofault(struct ppc_inst *inst, u32 *src); 158 182 159 183 #endif /* _ASM_POWERPC_INST_H */
+61 -6
arch/powerpc/include/asm/interrupt.h
··· 73 73 #include <asm/kprobes.h> 74 74 #include <asm/runlatch.h> 75 75 76 + #ifdef CONFIG_PPC_BOOK3S_64 77 + extern char __end_soft_masked[]; 78 + bool search_kernel_soft_mask_table(unsigned long addr); 79 + unsigned long search_kernel_restart_table(unsigned long addr); 80 + 81 + DECLARE_STATIC_KEY_FALSE(interrupt_exit_not_reentrant); 82 + 83 + static inline bool is_implicit_soft_masked(struct pt_regs *regs) 84 + { 85 + if (regs->msr & MSR_PR) 86 + return false; 87 + 88 + if (regs->nip >= (unsigned long)__end_soft_masked) 89 + return false; 90 + 91 + return search_kernel_soft_mask_table(regs->nip); 92 + } 93 + 94 + static inline void srr_regs_clobbered(void) 95 + { 96 + local_paca->srr_valid = 0; 97 + local_paca->hsrr_valid = 0; 98 + } 99 + #else 100 + static inline bool is_implicit_soft_masked(struct pt_regs *regs) 101 + { 102 + return false; 103 + } 104 + 105 + static inline void srr_regs_clobbered(void) 106 + { 107 + } 108 + #endif 109 + 76 110 static inline void nap_adjust_return(struct pt_regs *regs) 77 111 { 78 112 #ifdef CONFIG_PPC_970_NAP 79 113 if (unlikely(test_thread_local_flags(_TLF_NAPPING))) { 80 114 /* Can avoid a test-and-clear because NMIs do not call this */ 81 115 clear_thread_local_flags(_TLF_NAPPING); 82 - regs->nip = (unsigned long)power4_idle_nap_return; 116 + regs_set_return_ip(regs, (unsigned long)power4_idle_nap_return); 83 117 } 84 118 #endif 85 119 } ··· 163 129 * CT_WARN_ON comes here via program_check_exception, 164 130 * so avoid recursion. 165 131 */ 166 - if (TRAP(regs) != INTERRUPT_PROGRAM) 132 + if (TRAP(regs) != INTERRUPT_PROGRAM) { 167 133 CT_WARN_ON(ct_state() != CONTEXT_KERNEL); 134 + BUG_ON(is_implicit_soft_masked(regs)); 135 + } 136 + #ifdef CONFIG_PPC_BOOK3S 137 + /* Move this under a debugging check */ 138 + if (arch_irq_disabled_regs(regs)) 139 + BUG_ON(search_kernel_restart_table(regs->nip)); 140 + #endif 168 141 } 142 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 143 + BUG_ON(!arch_irq_disabled_regs(regs) && !(regs->msr & MSR_EE)); 169 144 #endif 170 145 171 146 booke_restore_dbcr0(); ··· 229 186 u8 irq_soft_mask; 230 187 u8 irq_happened; 231 188 u8 ftrace_enabled; 189 + u64 softe; 232 190 #endif 233 191 }; 234 192 ··· 255 211 #ifdef CONFIG_PPC64 256 212 state->irq_soft_mask = local_paca->irq_soft_mask; 257 213 state->irq_happened = local_paca->irq_happened; 214 + state->softe = regs->softe; 258 215 259 216 /* 260 217 * Set IRQS_ALL_DISABLED unconditionally so irqs_disabled() does ··· 265 220 local_paca->irq_soft_mask = IRQS_ALL_DISABLED; 266 221 local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 267 222 268 - if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !(regs->msr & MSR_PR) && 269 - regs->nip < (unsigned long)__end_interrupts) { 270 - // Kernel code running below __end_interrupts is 271 - // implicitly soft-masked. 223 + if (is_implicit_soft_masked(regs)) { 224 + // Adjust regs->softe soft implicit soft-mask, so 225 + // arch_irq_disabled_regs(regs) behaves as expected. 272 226 regs->softe = IRQS_ALL_DISABLED; 273 227 } 228 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 229 + BUG_ON(!arch_irq_disabled_regs(regs) && !(regs->msr & MSR_EE)); 274 230 275 231 /* Don't do any per-CPU operations until interrupt state is fixed */ 276 232 ··· 304 258 */ 305 259 306 260 #ifdef CONFIG_PPC64 261 + #ifdef CONFIG_PPC_BOOK3S 262 + if (arch_irq_disabled_regs(regs)) { 263 + unsigned long rst = search_kernel_restart_table(regs->nip); 264 + if (rst) 265 + regs_set_return_ip(regs, rst); 266 + } 267 + #endif 268 + 307 269 if (nmi_disables_ftrace(regs)) 308 270 this_cpu_set_ftrace_enabled(state->ftrace_enabled); 309 271 310 272 /* Check we didn't change the pending interrupt mask. */ 311 273 WARN_ON_ONCE((state->irq_happened | PACA_IRQ_HARD_DIS) != local_paca->irq_happened); 274 + regs->softe = state->softe; 312 275 local_paca->irq_happened = state->irq_happened; 313 276 local_paca->irq_soft_mask = state->irq_soft_mask; 314 277 #endif
+19 -31
arch/powerpc/include/asm/kup.h
··· 5 5 #define KUAP_READ 1 6 6 #define KUAP_WRITE 2 7 7 #define KUAP_READ_WRITE (KUAP_READ | KUAP_WRITE) 8 - /* 9 - * For prevent_user_access() only. 10 - * Use the current saved situation instead of the to/from/size params. 11 - * Used on book3s/32 12 - */ 13 - #define KUAP_CURRENT_READ 4 14 - #define KUAP_CURRENT_WRITE 8 15 - #define KUAP_CURRENT (KUAP_CURRENT_READ | KUAP_CURRENT_WRITE) 16 8 17 9 #ifdef CONFIG_PPC_BOOK3S_64 18 10 #include <asm/book3s/64/kup.h> ··· 38 46 static inline void setup_kuep(bool disabled) { } 39 47 #endif /* CONFIG_PPC_KUEP */ 40 48 41 - #if defined(CONFIG_PPC_KUEP) && defined(CONFIG_PPC_BOOK3S_32) 42 - void kuep_lock(void); 43 - void kuep_unlock(void); 44 - #else 49 + #ifndef CONFIG_PPC_BOOK3S_32 45 50 static inline void kuep_lock(void) { } 46 51 static inline void kuep_unlock(void) { } 47 52 #endif ··· 72 83 #ifndef CONFIG_PPC_BOOK3S_64 73 84 static inline void allow_user_access(void __user *to, const void __user *from, 74 85 unsigned long size, unsigned long dir) { } 75 - static inline void prevent_user_access(void __user *to, const void __user *from, 76 - unsigned long size, unsigned long dir) { } 86 + static inline void prevent_user_access(unsigned long dir) { } 77 87 static inline unsigned long prevent_user_access_return(void) { return 0UL; } 78 88 static inline void restore_user_access(unsigned long flags) { } 79 89 #endif /* CONFIG_PPC_BOOK3S_64 */ ··· 84 96 setup_kuap(disable_kuap); 85 97 } 86 98 87 - static inline void allow_read_from_user(const void __user *from, unsigned long size) 99 + static __always_inline void allow_read_from_user(const void __user *from, unsigned long size) 88 100 { 89 101 barrier_nospec(); 90 102 allow_user_access(NULL, from, size, KUAP_READ); 91 103 } 92 104 93 - static inline void allow_write_to_user(void __user *to, unsigned long size) 105 + static __always_inline void allow_write_to_user(void __user *to, unsigned long size) 94 106 { 95 107 allow_user_access(to, NULL, size, KUAP_WRITE); 96 108 } 97 109 98 - static inline void allow_read_write_user(void __user *to, const void __user *from, 99 - unsigned long size) 110 + static __always_inline void allow_read_write_user(void __user *to, const void __user *from, 111 + unsigned long size) 100 112 { 101 113 barrier_nospec(); 102 114 allow_user_access(to, from, size, KUAP_READ_WRITE); 103 115 } 104 116 105 - static inline void prevent_read_from_user(const void __user *from, unsigned long size) 117 + static __always_inline void prevent_read_from_user(const void __user *from, unsigned long size) 106 118 { 107 - prevent_user_access(NULL, from, size, KUAP_READ); 119 + prevent_user_access(KUAP_READ); 108 120 } 109 121 110 - static inline void prevent_write_to_user(void __user *to, unsigned long size) 122 + static __always_inline void prevent_write_to_user(void __user *to, unsigned long size) 111 123 { 112 - prevent_user_access(to, NULL, size, KUAP_WRITE); 124 + prevent_user_access(KUAP_WRITE); 113 125 } 114 126 115 - static inline void prevent_read_write_user(void __user *to, const void __user *from, 116 - unsigned long size) 127 + static __always_inline void prevent_read_write_user(void __user *to, const void __user *from, 128 + unsigned long size) 117 129 { 118 - prevent_user_access(to, from, size, KUAP_READ_WRITE); 130 + prevent_user_access(KUAP_READ_WRITE); 119 131 } 120 132 121 - static inline void prevent_current_access_user(void) 133 + static __always_inline void prevent_current_access_user(void) 122 134 { 123 - prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT); 135 + prevent_user_access(KUAP_READ_WRITE); 124 136 } 125 137 126 - static inline void prevent_current_read_from_user(void) 138 + static __always_inline void prevent_current_read_from_user(void) 127 139 { 128 - prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT_READ); 140 + prevent_user_access(KUAP_READ); 129 141 } 130 142 131 - static inline void prevent_current_write_to_user(void) 143 + static __always_inline void prevent_current_write_to_user(void) 132 144 { 133 - prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT_WRITE); 145 + prevent_user_access(KUAP_WRITE); 134 146 } 135 147 136 148 #endif /* !__ASSEMBLY__ */
+2 -2
arch/powerpc/include/asm/kvm_guest.h
··· 16 16 return static_branch_unlikely(&kvm_guest); 17 17 } 18 18 19 - bool check_kvm_guest(void); 19 + int check_kvm_guest(void); 20 20 #else 21 21 static inline bool is_kvm_guest(void) { return false; } 22 - static inline bool check_kvm_guest(void) { return false; } 22 + static inline int check_kvm_guest(void) { return 0; } 23 23 #endif 24 24 25 25 #endif /* _ASM_POWERPC_KVM_GUEST_H_ */
+1 -1
arch/powerpc/include/asm/livepatch.h
··· 16 16 { 17 17 struct pt_regs *regs = ftrace_get_regs(fregs); 18 18 19 - regs->nip = ip; 19 + regs_set_return_ip(regs, ip); 20 20 } 21 21 22 22 #define klp_get_ftrace_location klp_get_ftrace_location
+6 -13
arch/powerpc/include/asm/mmu.h
··· 220 220 #elif defined(CONFIG_44x) 221 221 #define MMU_FTRS_ALWAYS MMU_FTR_TYPE_44x 222 222 #endif 223 - #if defined(CONFIG_E200) || defined(CONFIG_E500) 223 + #ifdef CONFIG_E500 224 224 #define MMU_FTRS_ALWAYS MMU_FTR_TYPE_FSL_E 225 225 #endif 226 226 ··· 324 324 } 325 325 #endif /* !CONFIG_DEBUG_VM */ 326 326 327 - #ifdef CONFIG_PPC_RADIX_MMU 328 327 static inline bool radix_enabled(void) 329 328 { 330 329 return mmu_has_feature(MMU_FTR_TYPE_RADIX); ··· 333 334 { 334 335 return early_mmu_has_feature(MMU_FTR_TYPE_RADIX); 335 336 } 336 - #else 337 - static inline bool radix_enabled(void) 338 - { 339 - return false; 340 - } 341 - 342 - static inline bool early_radix_enabled(void) 343 - { 344 - return false; 345 - } 346 - #endif 347 337 348 338 #ifdef CONFIG_STRICT_KERNEL_RWX 349 339 static inline bool strict_kernel_rwx_enabled(void) ··· 345 357 return false; 346 358 } 347 359 #endif 360 + 361 + static inline bool strict_module_rwx_enabled(void) 362 + { 363 + return IS_ENABLED(CONFIG_STRICT_MODULE_RWX) && strict_kernel_rwx_enabled(); 364 + } 348 365 #endif /* !__ASSEMBLY__ */ 349 366 350 367 /* The kernel use the constants below to index in the page sizes array.
-1
arch/powerpc/include/asm/mmu_context.h
··· 57 57 static inline void mm_iommu_init(struct mm_struct *mm) { } 58 58 #endif 59 59 extern void switch_slb(struct task_struct *tsk, struct mm_struct *mm); 60 - extern void set_context(unsigned long id, pgd_t *pgd); 61 60 62 61 #ifdef CONFIG_PPC_BOOK3S_64 63 62 extern void radix__switch_mmu_context(struct mm_struct *prev,
+41 -5
arch/powerpc/include/asm/nohash/32/kup-8xx.h
··· 9 9 10 10 #ifndef __ASSEMBLY__ 11 11 12 + #include <linux/jump_label.h> 13 + 12 14 #include <asm/reg.h> 15 + 16 + extern struct static_key_false disable_kuap_key; 17 + 18 + static __always_inline bool kuap_is_disabled(void) 19 + { 20 + return static_branch_unlikely(&disable_kuap_key); 21 + } 13 22 14 23 static inline void kuap_save_and_lock(struct pt_regs *regs) 15 24 { 25 + if (kuap_is_disabled()) 26 + return; 27 + 16 28 regs->kuap = mfspr(SPRN_MD_AP); 17 29 mtspr(SPRN_MD_AP, MD_APG_KUAP); 18 30 } ··· 35 23 36 24 static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap) 37 25 { 26 + if (kuap_is_disabled()) 27 + return; 28 + 38 29 mtspr(SPRN_MD_AP, regs->kuap); 39 30 } 40 31 41 32 static inline unsigned long kuap_get_and_assert_locked(void) 42 33 { 43 - unsigned long kuap = mfspr(SPRN_MD_AP); 34 + unsigned long kuap; 35 + 36 + if (kuap_is_disabled()) 37 + return MD_APG_INIT; 38 + 39 + kuap = mfspr(SPRN_MD_AP); 44 40 45 41 if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) 46 42 WARN_ON_ONCE(kuap >> 16 != MD_APG_KUAP >> 16); ··· 58 38 59 39 static inline void kuap_assert_locked(void) 60 40 { 61 - if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) 41 + if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && !kuap_is_disabled()) 62 42 kuap_get_and_assert_locked(); 63 43 } 64 44 65 45 static inline void allow_user_access(void __user *to, const void __user *from, 66 46 unsigned long size, unsigned long dir) 67 47 { 48 + if (kuap_is_disabled()) 49 + return; 50 + 68 51 mtspr(SPRN_MD_AP, MD_APG_INIT); 69 52 } 70 53 71 - static inline void prevent_user_access(void __user *to, const void __user *from, 72 - unsigned long size, unsigned long dir) 54 + static inline void prevent_user_access(unsigned long dir) 73 55 { 56 + if (kuap_is_disabled()) 57 + return; 58 + 74 59 mtspr(SPRN_MD_AP, MD_APG_KUAP); 75 60 } 76 61 77 62 static inline unsigned long prevent_user_access_return(void) 78 63 { 79 - unsigned long flags = mfspr(SPRN_MD_AP); 64 + unsigned long flags; 65 + 66 + if (kuap_is_disabled()) 67 + return MD_APG_INIT; 68 + 69 + flags = mfspr(SPRN_MD_AP); 80 70 81 71 mtspr(SPRN_MD_AP, MD_APG_KUAP); 82 72 ··· 95 65 96 66 static inline void restore_user_access(unsigned long flags) 97 67 { 68 + if (kuap_is_disabled()) 69 + return; 70 + 98 71 mtspr(SPRN_MD_AP, flags); 99 72 } 100 73 101 74 static inline bool 102 75 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) 103 76 { 77 + if (kuap_is_disabled()) 78 + return false; 79 + 104 80 return !((regs->kuap ^ MD_APG_KUAP) & 0xff000000); 105 81 } 106 82
+1
arch/powerpc/include/asm/nohash/32/mmu-44x.h
··· 113 113 114 114 /* patch sites */ 115 115 extern s32 patch__tlb_44x_hwater_D, patch__tlb_44x_hwater_I; 116 + extern s32 patch__tlb_44x_kuep, patch__tlb_47x_kuep; 116 117 117 118 #endif /* !__ASSEMBLY__ */ 118 119
+7 -2
arch/powerpc/include/asm/paca.h
··· 149 149 #endif /* CONFIG_PPC_BOOK3E */ 150 150 151 151 #ifdef CONFIG_PPC_BOOK3S 152 - mm_context_id_t mm_ctx_id; 153 152 #ifdef CONFIG_PPC_MM_SLICES 154 153 unsigned char mm_ctx_low_slices_psize[BITS_PER_LONG / BITS_PER_BYTE]; 155 154 unsigned char mm_ctx_high_slices_psize[SLICE_ARRAY_SIZE]; 156 - unsigned long mm_ctx_slb_addr_limit; 157 155 #else 158 156 u16 mm_ctx_user_psize; 159 157 u16 mm_ctx_sllp; ··· 165 167 u64 kstack; /* Saved Kernel stack addr */ 166 168 u64 saved_r1; /* r1 save for RTAS calls or PM or EE=0 */ 167 169 u64 saved_msr; /* MSR saved here by enter_rtas */ 170 + #ifdef CONFIG_PPC64 171 + u64 exit_save_r1; /* Syscall/interrupt R1 save */ 172 + #endif 168 173 #ifdef CONFIG_PPC_BOOK3E 169 174 u16 trap_save; /* Used when bad stack is encountered */ 175 + #endif 176 + #ifdef CONFIG_PPC_BOOK3S_64 177 + u8 hsrr_valid; /* HSRRs set for HRFID */ 178 + u8 srr_valid; /* SRRs set for RFID */ 170 179 #endif 171 180 u8 irq_soft_mask; /* mask for irq soft masking */ 172 181 u8 irq_happened; /* irq happened while soft-disabled */
+5
arch/powerpc/include/asm/pgtable.h
··· 41 41 42 42 #ifndef __ASSEMBLY__ 43 43 44 + #ifndef MAX_PTRS_PER_PGD 45 + #define MAX_PTRS_PER_PGD PTRS_PER_PGD 46 + #endif 47 + 44 48 /* Keep these as a macros to avoid include dependency mess */ 45 49 #define pte_page(x) pfn_to_page(pte_pfn(x)) 46 50 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) ··· 76 72 extern pgd_t swapper_pg_dir[]; 77 73 78 74 extern void paging_init(void); 75 + void poking_init(void); 79 76 80 77 extern unsigned long ioremap_bot; 81 78
+58 -26
arch/powerpc/include/asm/ppc-opcode.h
··· 76 76 #define __REGA0_R30 30 77 77 #define __REGA0_R31 31 78 78 79 + /* For use with PPC_RAW_() macros */ 80 + #define _R0 0 81 + #define _R1 1 82 + #define _R2 2 83 + #define _R3 3 84 + #define _R4 4 85 + #define _R5 5 86 + #define _R6 6 87 + #define _R7 7 88 + #define _R8 8 89 + #define _R9 9 90 + #define _R10 10 91 + #define _R11 11 92 + #define _R12 12 93 + #define _R13 13 94 + #define _R14 14 95 + #define _R15 15 96 + #define _R16 16 97 + #define _R17 17 98 + #define _R18 18 99 + #define _R19 19 100 + #define _R20 20 101 + #define _R21 21 102 + #define _R22 22 103 + #define _R23 23 104 + #define _R24 24 105 + #define _R25 25 106 + #define _R26 26 107 + #define _R27 27 108 + #define _R28 28 109 + #define _R29 29 110 + #define _R30 30 111 + #define _R31 31 112 + 79 113 #define IMM_L(i) ((uintptr_t)(i) & 0xffff) 80 114 #define IMM_DS(i) ((uintptr_t)(i) & 0xfffc) 81 115 #define IMM_DQ(i) ((uintptr_t)(i) & 0xfff0) ··· 256 222 #define PPC_INST_LWSYNC 0x7c2004ac 257 223 #define PPC_INST_SYNC 0x7c0004ac 258 224 #define PPC_INST_SYNC_MASK 0xfc0007fe 259 - #define PPC_INST_ISYNC 0x4c00012c 260 225 #define PPC_INST_MCRXR 0x7c000400 261 226 #define PPC_INST_MCRXR_MASK 0xfc0007fe 262 227 #define PPC_INST_MFSPR_PVR 0x7c1f42a6 263 228 #define PPC_INST_MFSPR_PVR_MASK 0xfc1ffffe 264 229 #define PPC_INST_MTMSRD 0x7c000164 265 - #define PPC_INST_NOP 0x60000000 266 230 #define PPC_INST_POPCNTB 0x7c0000f4 267 231 #define PPC_INST_POPCNTB_MASK 0xfc0007fe 268 232 #define PPC_INST_RFEBB 0x4c000124 ··· 273 241 #define PPC_INST_MFSPR_DSCR_USER_MASK 0xfc1ffffe 274 242 #define PPC_INST_MTSPR_DSCR_USER 0x7c0303a6 275 243 #define PPC_INST_MTSPR_DSCR_USER_MASK 0xfc1ffffe 276 - #define PPC_INST_SC 0x44000002 277 244 #define PPC_INST_STRING 0x7c00042a 278 245 #define PPC_INST_STRING_MASK 0xfc0007fe 279 246 #define PPC_INST_STRING_GEN_MASK 0xfc00067e 247 + #define PPC_INST_SETB 0x7c000100 280 248 #define PPC_INST_STSWI 0x7c0005aa 281 249 #define PPC_INST_STSWX 0x7c00052a 282 250 #define PPC_INST_TRECHKPT 0x7c0007dd ··· 284 252 #define PPC_INST_TSR 0x7c0005dd 285 253 #define PPC_INST_LD 0xe8000000 286 254 #define PPC_INST_STD 0xf8000000 287 - #define PPC_INST_MFLR 0x7c0802a6 288 - #define PPC_INST_MTCTR 0x7c0903a6 289 - #define PPC_INST_ADDI 0x38000000 290 255 #define PPC_INST_ADDIS 0x3c000000 291 256 #define PPC_INST_ADD 0x7c000214 292 - #define PPC_INST_BLR 0x4e800020 293 - #define PPC_INST_BCTR 0x4e800420 294 - #define PPC_INST_BCTRL 0x4e800421 295 257 #define PPC_INST_DIVD 0x7c0003d2 296 - #define PPC_INST_RLDICR 0x78000004 297 - #define PPC_INST_ORI 0x60000000 298 - #define PPC_INST_ORIS 0x64000000 299 258 #define PPC_INST_BRANCH 0x48000000 300 259 #define PPC_INST_BL 0x48000001 301 260 #define PPC_INST_BRANCH_COND 0x40800000 ··· 346 323 #define PPC_LO(v) ((v) & 0xffff) 347 324 #define PPC_HI(v) (((v) >> 16) & 0xffff) 348 325 #define PPC_HA(v) PPC_HI((v) + 0x8000) 326 + #define PPC_HIGHER(v) (((v) >> 32) & 0xffff) 327 + #define PPC_HIGHEST(v) (((v) >> 48) & 0xffff) 349 328 350 329 /* 351 330 * Only use the larx hint bit on 64bit CPUs. e500v1/v2 based CPUs will treat a ··· 408 383 #define PPC_RAW_STBCIX(s, a, b) (0x7c0007aa | __PPC_RS(s) | __PPC_RA(a) | __PPC_RB(b)) 409 384 #define PPC_RAW_DCBFPS(a, b) (0x7c0000ac | ___PPC_RA(a) | ___PPC_RB(b) | (4 << 21)) 410 385 #define PPC_RAW_DCBSTPS(a, b) (0x7c0000ac | ___PPC_RA(a) | ___PPC_RB(b) | (6 << 21)) 386 + #define PPC_RAW_SC() (0x44000002) 387 + #define PPC_RAW_SYNC() (0x7c0004ac) 388 + #define PPC_RAW_ISYNC() (0x4c00012c) 389 + 411 390 /* 412 391 * Define what the VSX XX1 form instructions will look like, then add 413 392 * the 128 bit load store instructions based on that. ··· 433 404 #define PPC_RAW_STXVP(xsp, a, i) (0x18000001 | __PPC_XSP(xsp) | ___PPC_RA(a) | IMM_DQ(i)) 434 405 #define PPC_RAW_LXVPX(xtp, a, b) (0x7c00029a | __PPC_XTP(xtp) | ___PPC_RA(a) | ___PPC_RB(b)) 435 406 #define PPC_RAW_STXVPX(xsp, a, b) (0x7c00039a | __PPC_XSP(xsp) | ___PPC_RA(a) | ___PPC_RB(b)) 436 - #define PPC_RAW_PLXVP(xtp, i, a, pr) \ 437 - ((PPC_PREFIX_8LS | __PPC_PRFX_R(pr) | IMM_D0(i)) << 32 | (0xe8000000 | __PPC_XTP(xtp) | ___PPC_RA(a) | IMM_D1(i))) 438 - #define PPC_RAW_PSTXVP(xsp, i, a, pr) \ 439 - ((PPC_PREFIX_8LS | __PPC_PRFX_R(pr) | IMM_D0(i)) << 32 | (0xf8000000 | __PPC_XSP(xsp) | ___PPC_RA(a) | IMM_D1(i))) 407 + #define PPC_RAW_PLXVP_P(xtp, i, a, pr) (PPC_PREFIX_8LS | __PPC_PRFX_R(pr) | IMM_D0(i)) 408 + #define PPC_RAW_PLXVP_S(xtp, i, a, pr) (0xe8000000 | __PPC_XTP(xtp) | ___PPC_RA(a) | IMM_D1(i)) 409 + #define PPC_RAW_PSTXVP_P(xsp, i, a, pr) (PPC_PREFIX_8LS | __PPC_PRFX_R(pr) | IMM_D0(i)) 410 + #define PPC_RAW_PSTXVP_S(xsp, i, a, pr) (0xf8000000 | __PPC_XSP(xsp) | ___PPC_RA(a) | IMM_D1(i)) 440 411 #define PPC_RAW_NAP (0x4c000364) 441 412 #define PPC_RAW_SLEEP (0x4c0003a4) 442 413 #define PPC_RAW_WINKLE (0x4c0003e4) ··· 474 445 #define PPC_RAW_ADD_DOT(t, a, b) (PPC_INST_ADD | ___PPC_RT(t) | ___PPC_RA(a) | ___PPC_RB(b) | 0x1) 475 446 #define PPC_RAW_ADDC(t, a, b) (0x7c000014 | ___PPC_RT(t) | ___PPC_RA(a) | ___PPC_RB(b)) 476 447 #define PPC_RAW_ADDC_DOT(t, a, b) (0x7c000014 | ___PPC_RT(t) | ___PPC_RA(a) | ___PPC_RB(b) | 0x1) 477 - #define PPC_RAW_NOP() (PPC_INST_NOP) 478 - #define PPC_RAW_BLR() (PPC_INST_BLR) 448 + #define PPC_RAW_NOP() PPC_RAW_ORI(0, 0, 0) 449 + #define PPC_RAW_BLR() (0x4e800020) 479 450 #define PPC_RAW_BLRL() (0x4e800021) 480 451 #define PPC_RAW_MTLR(r) (0x7c0803a6 | ___PPC_RT(r)) 481 - #define PPC_RAW_MFLR(t) (PPC_INST_MFLR | ___PPC_RT(t)) 482 - #define PPC_RAW_BCTR() (PPC_INST_BCTR) 483 - #define PPC_RAW_MTCTR(r) (PPC_INST_MTCTR | ___PPC_RT(r)) 484 - #define PPC_RAW_ADDI(d, a, i) (PPC_INST_ADDI | ___PPC_RT(d) | ___PPC_RA(a) | IMM_L(i)) 452 + #define PPC_RAW_MFLR(t) (0x7c0802a6 | ___PPC_RT(t)) 453 + #define PPC_RAW_BCTR() (0x4e800420) 454 + #define PPC_RAW_BCTRL() (0x4e800421) 455 + #define PPC_RAW_MTCTR(r) (0x7c0903a6 | ___PPC_RT(r)) 456 + #define PPC_RAW_ADDI(d, a, i) (0x38000000 | ___PPC_RT(d) | ___PPC_RA(a) | IMM_L(i)) 485 457 #define PPC_RAW_LI(r, i) PPC_RAW_ADDI(r, 0, i) 486 - #define PPC_RAW_ADDIS(d, a, i) (PPC_INST_ADDIS | ___PPC_RT(d) | ___PPC_RA(a) | IMM_L(i)) 458 + #define PPC_RAW_ADDIS(d, a, i) (0x3c000000 | ___PPC_RT(d) | ___PPC_RA(a) | IMM_L(i)) 487 459 #define PPC_RAW_ADDIC(d, a, i) (0x30000000 | ___PPC_RT(d) | ___PPC_RA(a) | IMM_L(i)) 488 460 #define PPC_RAW_ADDIC_DOT(d, a, i) (0x34000000 | ___PPC_RT(d) | ___PPC_RA(a) | IMM_L(i)) 489 461 #define PPC_RAW_LIS(r, i) PPC_RAW_ADDIS(r, 0, i) ··· 529 499 #define PPC_RAW_AND_DOT(d, a, b) (0x7c000039 | ___PPC_RA(d) | ___PPC_RS(a) | ___PPC_RB(b)) 530 500 #define PPC_RAW_OR(d, a, b) (0x7c000378 | ___PPC_RA(d) | ___PPC_RS(a) | ___PPC_RB(b)) 531 501 #define PPC_RAW_MR(d, a) PPC_RAW_OR(d, a, a) 532 - #define PPC_RAW_ORI(d, a, i) (PPC_INST_ORI | ___PPC_RA(d) | ___PPC_RS(a) | IMM_L(i)) 533 - #define PPC_RAW_ORIS(d, a, i) (PPC_INST_ORIS | ___PPC_RA(d) | ___PPC_RS(a) | IMM_L(i)) 502 + #define PPC_RAW_ORI(d, a, i) (0x60000000 | ___PPC_RA(d) | ___PPC_RS(a) | IMM_L(i)) 503 + #define PPC_RAW_ORIS(d, a, i) (0x64000000 | ___PPC_RA(d) | ___PPC_RS(a) | IMM_L(i)) 534 504 #define PPC_RAW_NOR(d, a, b) (0x7c0000f8 | ___PPC_RA(d) | ___PPC_RS(a) | ___PPC_RB(b)) 535 505 #define PPC_RAW_XOR(d, a, b) (0x7c000278 | ___PPC_RA(d) | ___PPC_RS(a) | ___PPC_RB(b)) 536 506 #define PPC_RAW_XORI(d, a, i) (0x68000000 | ___PPC_RA(d) | ___PPC_RS(a) | IMM_L(i)) ··· 549 519 (0x54000001 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH(i) | __PPC_MB(mb) | __PPC_ME(me)) 550 520 #define PPC_RAW_RLWIMI(d, a, i, mb, me) (0x50000000 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH(i) | __PPC_MB(mb) | __PPC_ME(me)) 551 521 #define PPC_RAW_RLDICL(d, a, i, mb) (0x78000000 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH64(i) | __PPC_MB64(mb)) 552 - #define PPC_RAW_RLDICR(d, a, i, me) (PPC_INST_RLDICR | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH64(i) | __PPC_ME64(me)) 522 + #define PPC_RAW_RLDICR(d, a, i, me) (0x78000004 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH64(i) | __PPC_ME64(me)) 553 523 554 524 /* slwi = rlwinm Rx, Ry, n, 0, 31-n */ 555 525 #define PPC_RAW_SLWI(d, a, i) PPC_RAW_RLWINM(d, a, i, 0, 31-(i)) ··· 563 533 #define PPC_RAW_NEG(d, a) (0x7c0000d0 | ___PPC_RT(d) | ___PPC_RA(a)) 564 534 565 535 #define PPC_RAW_MFSPR(d, spr) (0x7c0002a6 | ___PPC_RT(d) | __PPC_SPR(spr)) 536 + #define PPC_RAW_MTSPR(spr, d) (0x7c0003a6 | ___PPC_RS(d) | __PPC_SPR(spr)) 537 + #define PPC_RAW_EIEIO() (0x7c0006ac) 566 538 567 539 /* Deal with instructions that older assemblers aren't aware of */ 568 540 #define PPC_BCCTR_FLUSH stringify_in_c(.long PPC_INST_BCCTR_FLUSH)
+15
arch/powerpc/include/asm/ppc_asm.h
··· 762 762 stringify_in_c(.long (_target) - . ;) \ 763 763 stringify_in_c(.previous) 764 764 765 + #define SOFT_MASK_TABLE(_start, _end) \ 766 + stringify_in_c(.section __soft_mask_table,"a";)\ 767 + stringify_in_c(.balign 8;) \ 768 + stringify_in_c(.llong (_start);) \ 769 + stringify_in_c(.llong (_end);) \ 770 + stringify_in_c(.previous) 771 + 772 + #define RESTART_TABLE(_start, _end, _target) \ 773 + stringify_in_c(.section __restart_table,"a";)\ 774 + stringify_in_c(.balign 8;) \ 775 + stringify_in_c(.llong (_start);) \ 776 + stringify_in_c(.llong (_end);) \ 777 + stringify_in_c(.llong (_target);) \ 778 + stringify_in_c(.previous) 779 + 765 780 #ifdef CONFIG_PPC_FSL_BOOK3E 766 781 #define BTB_FLUSH(reg) \ 767 782 lis reg,BUCSR_INIT@h; \
+2 -2
arch/powerpc/include/asm/probes.h
··· 34 34 /* Enable single stepping for the current task */ 35 35 static inline void enable_single_step(struct pt_regs *regs) 36 36 { 37 - regs->msr |= MSR_SINGLESTEP; 37 + regs_set_return_msr(regs, regs->msr | MSR_SINGLESTEP); 38 38 #ifdef CONFIG_PPC_ADV_DEBUG_REGS 39 39 /* 40 40 * We turn off Critical Input Exception(CE) to ensure that the single 41 41 * step will be for the instruction we have the probe on; if we don't, 42 42 * it is possible we'd get the single step reported for CE. 43 43 */ 44 - regs->msr &= ~MSR_CE; 44 + regs_set_return_msr(regs, regs->msr & ~MSR_CE); 45 45 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM); 46 46 #ifdef CONFIG_PPC_47x 47 47 isync();
+9 -12
arch/powerpc/include/asm/processor.h
··· 276 276 #define SPEFSCR_INIT 277 277 #endif 278 278 279 - #ifdef CONFIG_PPC32 279 + #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP) 280 + #define INIT_THREAD { \ 281 + .ksp = INIT_SP, \ 282 + .pgdir = swapper_pg_dir, \ 283 + .kuap = ~0UL, /* KUAP_NONE */ \ 284 + .fpexc_mode = MSR_FE0 | MSR_FE1, \ 285 + SPEFSCR_INIT \ 286 + } 287 + #elif defined(CONFIG_PPC32) 280 288 #define INIT_THREAD { \ 281 289 .ksp = INIT_SP, \ 282 290 .pgdir = swapper_pg_dir, \ ··· 346 338 #define spin_cpu_relax() barrier() 347 339 348 340 #define spin_end() HMT_medium() 349 - 350 - #define spin_until_cond(cond) \ 351 - do { \ 352 - if (unlikely(!(cond))) { \ 353 - spin_begin(); \ 354 - do { \ 355 - spin_cpu_relax(); \ 356 - } while (!(cond)); \ 357 - spin_end(); \ 358 - } \ 359 - } while (0) 360 341 361 342 #endif 362 343
+3 -1
arch/powerpc/include/asm/ps3.h
··· 71 71 * @bus_addr: The 'translated' bus address of the region. 72 72 * @len: The length in bytes of the region. 73 73 * @offset: The offset from the start of memory of the region. 74 + * @dma_mask: Device dma_mask. 74 75 * @ioid: The IOID of the device who owns this region 75 76 * @chunk_list: Opaque variable used by the ioc page manager. 76 77 * @region_ops: struct ps3_dma_region_ops - dma region operations ··· 86 85 enum ps3_dma_region_type region_type; 87 86 unsigned long len; 88 87 unsigned long offset; 88 + u64 dma_mask; 89 89 90 90 /* driver variables (set by ps3_dma_region_create) */ 91 91 unsigned long bus_addr; ··· 234 232 235 233 static inline const char* ps3_result(int result) 236 234 { 237 - #if defined(DEBUG) || defined(PS3_VERBOSE_RESULT) 235 + #if defined(DEBUG) || defined(PS3_VERBOSE_RESULT) || defined(CONFIG_PS3_VERBOSE_RESULT) 238 236 switch (result) { 239 237 case LV1_SUCCESS: 240 238 return "LV1_SUCCESS (0)";
+39 -11
arch/powerpc/include/asm/ptrace.h
··· 48 48 unsigned long result; 49 49 }; 50 50 }; 51 - 51 + #if defined(CONFIG_PPC64) || defined(CONFIG_PPC_KUAP) 52 52 union { 53 53 struct { 54 54 #ifdef CONFIG_PPC64 55 55 unsigned long ppr; 56 + unsigned long exit_result; 56 57 #endif 57 58 union { 58 59 #ifdef CONFIG_PPC_KUAP ··· 69 68 }; 70 69 unsigned long __pad[4]; /* Maintain 16 byte interrupt stack alignment */ 71 70 }; 71 + #endif 72 72 }; 73 73 #endif 74 74 ··· 124 122 #endif /* __powerpc64__ */ 125 123 126 124 #ifndef __ASSEMBLY__ 125 + #include <asm/paca.h> 126 + 127 + #ifdef CONFIG_SMP 128 + extern unsigned long profile_pc(struct pt_regs *regs); 129 + #else 130 + #define profile_pc(regs) instruction_pointer(regs) 131 + #endif 132 + 133 + long do_syscall_trace_enter(struct pt_regs *regs); 134 + void do_syscall_trace_leave(struct pt_regs *regs); 135 + 136 + static inline void set_return_regs_changed(void) 137 + { 138 + #ifdef CONFIG_PPC_BOOK3S_64 139 + local_paca->hsrr_valid = 0; 140 + local_paca->srr_valid = 0; 141 + #endif 142 + } 143 + 144 + static inline void regs_set_return_ip(struct pt_regs *regs, unsigned long ip) 145 + { 146 + regs->nip = ip; 147 + set_return_regs_changed(); 148 + } 149 + 150 + static inline void regs_set_return_msr(struct pt_regs *regs, unsigned long msr) 151 + { 152 + regs->msr = msr; 153 + set_return_regs_changed(); 154 + } 155 + 156 + static inline void regs_add_return_ip(struct pt_regs *regs, long offset) 157 + { 158 + regs_set_return_ip(regs, regs->nip + offset); 159 + } 127 160 128 161 static inline unsigned long instruction_pointer(struct pt_regs *regs) 129 162 { ··· 168 131 static inline void instruction_pointer_set(struct pt_regs *regs, 169 132 unsigned long val) 170 133 { 171 - regs->nip = val; 134 + regs_set_return_ip(regs, val); 172 135 } 173 136 174 137 static inline unsigned long user_stack_pointer(struct pt_regs *regs) ··· 180 143 { 181 144 return 0; 182 145 } 183 - 184 - #ifdef CONFIG_SMP 185 - extern unsigned long profile_pc(struct pt_regs *regs); 186 - #else 187 - #define profile_pc(regs) instruction_pointer(regs) 188 - #endif 189 - 190 - long do_syscall_trace_enter(struct pt_regs *regs); 191 - void do_syscall_trace_leave(struct pt_regs *regs); 192 146 193 147 #ifdef __powerpc64__ 194 148 #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
+1 -12
arch/powerpc/include/asm/reg.h
··· 393 393 #define SPRN_PMMAR 0x356 /* Power Management Memory Activity Register */ 394 394 #define SPRN_PSSCR 0x357 /* Processor Stop Status and Control Register (ISA 3.0) */ 395 395 #define SPRN_PSSCR_PR 0x337 /* PSSCR ISA 3.0, privileged mode access */ 396 + #define SPRN_TRIG2 0x372 396 397 #define SPRN_PMCR 0x374 /* Power Management Control Register */ 397 398 #define SPRN_RWMR 0x375 /* Region-Weighting Mode Register */ 398 399 ··· 1436 1435 } 1437 1436 #endif 1438 1437 1439 - #define proc_trap() asm volatile("trap") 1440 - 1441 1438 extern unsigned long current_stack_frame(void); 1442 1439 1443 1440 register unsigned long current_stack_pointer asm("r1"); ··· 1446 1447 struct pt_regs; 1447 1448 1448 1449 extern void ppc_save_regs(struct pt_regs *regs); 1449 - 1450 - static inline void update_power8_hid0(unsigned long hid0) 1451 - { 1452 - /* 1453 - * The HID0 update on Power8 should at the very least be 1454 - * preceded by a SYNC instruction followed by an ISYNC 1455 - * instruction 1456 - */ 1457 - asm volatile("sync; mtspr %0,%1; isync":: "i"(SPRN_HID0), "r"(hid0)); 1458 - } 1459 1450 #endif /* __ASSEMBLY__ */ 1460 1451 #endif /* __KERNEL__ */ 1461 1452 #endif /* _ASM_POWERPC_REG_H */
+4
arch/powerpc/include/asm/security_features.h
··· 92 92 // The L1-D cache should be flushed after user accesses from the kernel 93 93 #define SEC_FTR_L1D_FLUSH_UACCESS 0x0000000000008000ull 94 94 95 + // The STF flush should be executed on privilege state switch 96 + #define SEC_FTR_STF_BARRIER 0x0000000000010000ull 97 + 95 98 // Features enabled by default 96 99 #define SEC_FTR_DEFAULT \ 97 100 (SEC_FTR_L1D_FLUSH_HV | \ ··· 102 99 SEC_FTR_BNDS_CHK_SPEC_BAR | \ 103 100 SEC_FTR_L1D_FLUSH_ENTRY | \ 104 101 SEC_FTR_L1D_FLUSH_UACCESS | \ 102 + SEC_FTR_STF_BARRIER | \ 105 103 SEC_FTR_FAVOUR_SECURITY) 106 104 107 105 #endif /* _ASM_POWERPC_SECURITY_FEATURES_H */
+34
arch/powerpc/include/asm/set_memory.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _ASM_POWERPC_SET_MEMORY_H 3 + #define _ASM_POWERPC_SET_MEMORY_H 4 + 5 + #define SET_MEMORY_RO 0 6 + #define SET_MEMORY_RW 1 7 + #define SET_MEMORY_NX 2 8 + #define SET_MEMORY_X 3 9 + 10 + int change_memory_attr(unsigned long addr, int numpages, long action); 11 + 12 + static inline int set_memory_ro(unsigned long addr, int numpages) 13 + { 14 + return change_memory_attr(addr, numpages, SET_MEMORY_RO); 15 + } 16 + 17 + static inline int set_memory_rw(unsigned long addr, int numpages) 18 + { 19 + return change_memory_attr(addr, numpages, SET_MEMORY_RW); 20 + } 21 + 22 + static inline int set_memory_nx(unsigned long addr, int numpages) 23 + { 24 + return change_memory_attr(addr, numpages, SET_MEMORY_NX); 25 + } 26 + 27 + static inline int set_memory_x(unsigned long addr, int numpages) 28 + { 29 + return change_memory_attr(addr, numpages, SET_MEMORY_X); 30 + } 31 + 32 + int set_memory_attr(unsigned long addr, int numpages, pgprot_t prot); 33 + 34 + #endif
-1
arch/powerpc/include/asm/setup.h
··· 10 10 extern unsigned int rtas_data; 11 11 extern unsigned long long memory_limit; 12 12 extern bool init_mem_is_free; 13 - extern unsigned long klimit; 14 13 extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask); 15 14 16 15 struct device_node;
+3 -4
arch/powerpc/include/asm/sstep.h
··· 13 13 * we don't allow putting a breakpoint on an mtmsrd instruction. 14 14 * Similarly we don't allow breakpoints on rfid instructions. 15 15 * These macros tell us if an instruction is a mtmsrd or rfid. 16 - * Note that IS_MTMSRD returns true for both an mtmsr (32-bit) 17 - * and an mtmsrd (64-bit). 16 + * Note that these return true for both mtmsr/rfi (32-bit) 17 + * and mtmsrd/rfid (64-bit). 18 18 */ 19 19 #define IS_MTMSRD(instr) ((ppc_inst_val(instr) & 0xfc0007be) == 0x7c000124) 20 - #define IS_RFID(instr) ((ppc_inst_val(instr) & 0xfc0007fe) == 0x4c000024) 21 - #define IS_RFI(instr) ((ppc_inst_val(instr) & 0xfc0007fe) == 0x4c000064) 20 + #define IS_RFID(instr) ((ppc_inst_val(instr) & 0xfc0007be) == 0x4c000024) 22 21 23 22 enum instruction_type { 24 23 COMPUTE, /* arith/logical/CR op, etc. */
+2 -2
arch/powerpc/include/asm/uprobes.h
··· 24 24 25 25 struct arch_uprobe { 26 26 union { 27 - struct ppc_inst insn; 28 - struct ppc_inst ixol; 27 + u32 insn[2]; 28 + u32 ixol[2]; 29 29 }; 30 30 }; 31 31
+106 -3
arch/powerpc/include/asm/vas.h
··· 5 5 6 6 #ifndef _ASM_POWERPC_VAS_H 7 7 #define _ASM_POWERPC_VAS_H 8 - 9 - struct vas_window; 8 + #include <linux/sched/mm.h> 9 + #include <linux/mmu_context.h> 10 + #include <asm/icswx.h> 11 + #include <uapi/asm/vas-api.h> 10 12 11 13 /* 12 14 * Min and max FIFO sizes are based on Version 1.05 Section 3.1.4.25 ··· 49 47 VAS_COP_TYPE_FTW, 50 48 VAS_COP_TYPE_MAX, 51 49 }; 50 + 51 + /* 52 + * User space VAS windows are opened by tasks and take references 53 + * to pid and mm until windows are closed. 54 + * Stores pid, mm, and tgid for each window. 55 + */ 56 + struct vas_user_win_ref { 57 + struct pid *pid; /* PID of owner */ 58 + struct pid *tgid; /* Thread group ID of owner */ 59 + struct mm_struct *mm; /* Linux process mm_struct */ 60 + }; 61 + 62 + /* 63 + * Common VAS window struct on PowerNV and PowerVM 64 + */ 65 + struct vas_window { 66 + u32 winid; 67 + u32 wcreds_max; /* Window credits */ 68 + enum vas_cop_type cop; 69 + struct vas_user_win_ref task_ref; 70 + char *dbgname; 71 + struct dentry *dbgdir; 72 + }; 73 + 74 + /* 75 + * User space window operations used for powernv and powerVM 76 + */ 77 + struct vas_user_win_ops { 78 + struct vas_window * (*open_win)(int vas_id, u64 flags, 79 + enum vas_cop_type); 80 + u64 (*paste_addr)(struct vas_window *); 81 + int (*close_win)(struct vas_window *); 82 + }; 83 + 84 + static inline void put_vas_user_win_ref(struct vas_user_win_ref *ref) 85 + { 86 + /* Drop references to pid, tgid, and mm */ 87 + put_pid(ref->pid); 88 + put_pid(ref->tgid); 89 + if (ref->mm) 90 + mmdrop(ref->mm); 91 + } 92 + 93 + static inline void vas_user_win_add_mm_context(struct vas_user_win_ref *ref) 94 + { 95 + mm_context_add_vas_window(ref->mm); 96 + /* 97 + * Even a process that has no foreign real address mapping can 98 + * use an unpaired COPY instruction (to no real effect). Issue 99 + * CP_ABORT to clear any pending COPY and prevent a covert 100 + * channel. 101 + * 102 + * __switch_to() will issue CP_ABORT on future context switches 103 + * if process / thread has any open VAS window (Use 104 + * current->mm->context.vas_windows). 105 + */ 106 + asm volatile(PPC_CP_ABORT); 107 + } 52 108 53 109 /* 54 110 * Receive window attributes specified by the (in-kernel) owner of window. ··· 160 100 bool rx_win_ord_mode; 161 101 }; 162 102 103 + #ifdef CONFIG_PPC_POWERNV 163 104 /* 164 105 * Helper to map a chip id to VAS id. 165 106 * For POWER9, this is a 1:1 mapping. In the future this maybe a 1:N ··· 223 162 */ 224 163 int vas_paste_crb(struct vas_window *win, int offset, bool re); 225 164 165 + int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, 166 + const char *name); 167 + void vas_unregister_api_powernv(void); 168 + #endif 169 + 170 + #ifdef CONFIG_PPC_PSERIES 171 + 172 + /* VAS Capabilities */ 173 + #define VAS_GZIP_QOS_FEAT 0x1 174 + #define VAS_GZIP_DEF_FEAT 0x2 175 + #define VAS_GZIP_QOS_FEAT_BIT PPC_BIT(VAS_GZIP_QOS_FEAT) /* Bit 1 */ 176 + #define VAS_GZIP_DEF_FEAT_BIT PPC_BIT(VAS_GZIP_DEF_FEAT) /* Bit 2 */ 177 + 178 + /* NX Capabilities */ 179 + #define VAS_NX_GZIP_FEAT 0x1 180 + #define VAS_NX_GZIP_FEAT_BIT PPC_BIT(VAS_NX_GZIP_FEAT) /* Bit 1 */ 181 + 182 + /* 183 + * These structs are used to retrieve overall VAS capabilities that 184 + * the hypervisor provides. 185 + */ 186 + struct hv_vas_all_caps { 187 + __be64 descriptor; 188 + __be64 feat_type; 189 + } __packed __aligned(0x1000); 190 + 191 + struct vas_all_caps { 192 + u64 descriptor; 193 + u64 feat_type; 194 + }; 195 + 196 + int h_query_vas_capabilities(const u64 hcall, u8 query_type, u64 result); 197 + int vas_register_api_pseries(struct module *mod, 198 + enum vas_cop_type cop_type, const char *name); 199 + void vas_unregister_api_pseries(void); 200 + #endif 201 + 226 202 /* 227 203 * Register / unregister coprocessor type to VAS API which will be exported 228 204 * to user space. Applications can use this API to open / close window ··· 269 171 * used for others in future. 270 172 */ 271 173 int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, 272 - const char *name); 174 + const char *name, 175 + const struct vas_user_win_ops *vops); 273 176 void vas_unregister_coproc_api(void); 274 177 178 + int get_vas_user_win_ref(struct vas_user_win_ref *task_ref); 179 + void vas_update_csb(struct coprocessor_request_block *crb, 180 + struct vas_user_win_ref *task_ref); 181 + void vas_dump_crb(struct coprocessor_request_block *crb); 275 182 #endif /* __ASM_POWERPC_VAS_H */
+4
arch/powerpc/include/asm/xics.h
··· 65 65 66 66 extern const struct icp_ops *icp_ops; 67 67 68 + #ifdef CONFIG_PPC_ICS_NATIVE 68 69 /* Native ICS */ 69 70 extern int ics_native_init(void); 71 + #else 72 + static inline int ics_native_init(void) { return -ENODEV; } 73 + #endif 70 74 71 75 /* RTAS ICS */ 72 76 #ifdef CONFIG_PPC_ICS_RTAS
+6
arch/powerpc/include/uapi/asm/papr_pdsm.h
··· 77 77 /* Indicate that the 'dimm_fuel_gauge' field is valid */ 78 78 #define PDSM_DIMM_HEALTH_RUN_GAUGE_VALID 1 79 79 80 + /* Indicate that the 'dimm_dsc' field is valid */ 81 + #define PDSM_DIMM_DSC_VALID 2 82 + 80 83 /* 81 84 * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH 82 85 * Various flags indicate the health status of the dimm. ··· 108 105 109 106 /* Extension flag PDSM_DIMM_HEALTH_RUN_GAUGE_VALID */ 110 107 __u16 dimm_fuel_gauge; 108 + 109 + /* Extension flag PDSM_DIMM_DSC_VALID */ 110 + __u64 dimm_dsc; 111 111 }; 112 112 __u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE]; 113 113 };
+5 -1
arch/powerpc/include/uapi/asm/vas-api.h
··· 13 13 #define VAS_MAGIC 'v' 14 14 #define VAS_TX_WIN_OPEN _IOW(VAS_MAGIC, 0x20, struct vas_tx_win_open_attr) 15 15 16 + /* Flags to VAS TX open window ioctl */ 17 + /* To allocate a window with QoS credit, otherwise use default credit */ 18 + #define VAS_TX_WIN_FLAG_QOS_CREDIT 0x0000000000000001 19 + 16 20 struct vas_tx_win_open_attr { 17 21 __u32 version; 18 22 __s16 vas_id; /* specific instance of vas or -1 for default */ 19 23 __u16 reserved1; 20 - __u64 flags; /* Future use */ 24 + __u64 flags; 21 25 __u64 reserved2[6]; 22 26 }; 23 27
+8 -65
arch/powerpc/kernel/asm-offsets.c
··· 86 86 OFFSET(PACA_CANARY, paca_struct, canary); 87 87 #endif 88 88 #endif 89 - OFFSET(MMCONTEXTID, mm_struct, context.id); 90 - #ifdef CONFIG_PPC64 91 - DEFINE(SIGSEGV, SIGSEGV); 92 - DEFINE(NMI_MASK, NMI_MASK); 93 - #else 89 + #ifdef CONFIG_PPC32 94 90 #ifdef CONFIG_PPC_RTAS 95 91 OFFSET(RTAS_SP, thread_struct, rtas_sp); 96 92 #endif ··· 115 119 #ifdef CONFIG_ALTIVEC 116 120 OFFSET(THREAD_VRSTATE, thread_struct, vr_state.vr); 117 121 OFFSET(THREAD_VRSAVEAREA, thread_struct, vr_save_area); 118 - OFFSET(THREAD_VRSAVE, thread_struct, vrsave); 119 122 OFFSET(THREAD_USED_VR, thread_struct, used_vr); 120 123 OFFSET(VRSTATE_VSCR, thread_vr_state, vscr); 121 124 OFFSET(THREAD_LOAD_VEC, thread_struct, load_vec); ··· 145 150 #ifdef CONFIG_SPE 146 151 OFFSET(THREAD_EVR0, thread_struct, evr[0]); 147 152 OFFSET(THREAD_ACC, thread_struct, acc); 148 - OFFSET(THREAD_SPEFSCR, thread_struct, spefscr); 149 153 OFFSET(THREAD_USED_SPE, thread_struct, used_spe); 150 154 #endif /* CONFIG_SPE */ 151 155 #endif /* CONFIG_PPC64 */ 152 - #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE) 153 - OFFSET(THREAD_DBCR0, thread_struct, debug.dbcr0); 154 - #endif 155 156 #ifdef CONFIG_KVM_BOOK3S_32_HANDLER 156 157 OFFSET(THREAD_KVM_SVCPU, thread_struct, kvm_shadow_vcpu); 157 158 #endif 158 159 #if defined(CONFIG_KVM) && defined(CONFIG_BOOKE) 159 160 OFFSET(THREAD_KVM_VCPU, thread_struct, kvm_vcpu); 160 - #endif 161 - #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP) 162 - OFFSET(KUAP, thread_struct, kuap); 163 161 #endif 164 162 165 163 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM ··· 173 185 sizeof(struct pt_regs) + 16); 174 186 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 175 187 176 - OFFSET(TI_FLAGS, thread_info, flags); 177 188 OFFSET(TI_LOCAL_FLAGS, thread_info, local_flags); 178 - OFFSET(TI_PREEMPT, thread_info, preempt_count); 179 189 180 190 #ifdef CONFIG_PPC64 181 191 OFFSET(DCACHEL1BLOCKSIZE, ppc64_caches, l1d.block_size); 182 192 OFFSET(DCACHEL1LOGBLOCKSIZE, ppc64_caches, l1d.log_block_size); 183 - OFFSET(DCACHEL1BLOCKSPERPAGE, ppc64_caches, l1d.blocks_per_page); 184 - OFFSET(ICACHEL1BLOCKSIZE, ppc64_caches, l1i.block_size); 185 - OFFSET(ICACHEL1LOGBLOCKSIZE, ppc64_caches, l1i.log_block_size); 186 - OFFSET(ICACHEL1BLOCKSPERPAGE, ppc64_caches, l1i.blocks_per_page); 187 193 /* paca */ 188 - DEFINE(PACA_SIZE, sizeof(struct paca_struct)); 189 194 OFFSET(PACAPACAINDEX, paca_struct, paca_index); 190 195 OFFSET(PACAPROCSTART, paca_struct, cpu_start); 191 196 OFFSET(PACAKSAVE, paca_struct, kstack); ··· 190 209 OFFSET(PACATOC, paca_struct, kernel_toc); 191 210 OFFSET(PACAKBASE, paca_struct, kernelbase); 192 211 OFFSET(PACAKMSR, paca_struct, kernel_msr); 212 + #ifdef CONFIG_PPC_BOOK3S_64 213 + OFFSET(PACAHSRR_VALID, paca_struct, hsrr_valid); 214 + OFFSET(PACASRR_VALID, paca_struct, srr_valid); 215 + #endif 193 216 OFFSET(PACAIRQSOFTMASK, paca_struct, irq_soft_mask); 194 217 OFFSET(PACAIRQHAPPENED, paca_struct, irq_happened); 195 218 OFFSET(PACA_FTRACE_ENABLED, paca_struct, ftrace_enabled); 196 - #ifdef CONFIG_PPC_BOOK3S 197 - OFFSET(PACACONTEXTID, paca_struct, mm_ctx_id); 198 - #ifdef CONFIG_PPC_MM_SLICES 199 - OFFSET(PACALOWSLICESPSIZE, paca_struct, mm_ctx_low_slices_psize); 200 - OFFSET(PACAHIGHSLICEPSIZE, paca_struct, mm_ctx_high_slices_psize); 201 - OFFSET(PACA_SLB_ADDR_LIMIT, paca_struct, mm_ctx_slb_addr_limit); 202 - DEFINE(MMUPSIZEDEFSIZE, sizeof(struct mmu_psize_def)); 203 - #endif /* CONFIG_PPC_MM_SLICES */ 204 - #endif 205 219 206 220 #ifdef CONFIG_PPC_BOOK3E 207 221 OFFSET(PACAPGD, paca_struct, pgd); ··· 217 241 #endif /* CONFIG_PPC_BOOK3E */ 218 242 219 243 #ifdef CONFIG_PPC_BOOK3S_64 220 - OFFSET(PACASLBCACHE, paca_struct, slb_cache); 221 - OFFSET(PACASLBCACHEPTR, paca_struct, slb_cache_ptr); 222 - OFFSET(PACASTABRR, paca_struct, stab_rr); 223 - OFFSET(PACAVMALLOCSLLP, paca_struct, vmalloc_sllp); 224 - #ifdef CONFIG_PPC_MM_SLICES 225 - OFFSET(MMUPSIZESLLP, mmu_psize_def, sllp); 226 - #else 227 - OFFSET(PACACONTEXTSLLP, paca_struct, mm_ctx_sllp); 228 - #endif /* CONFIG_PPC_MM_SLICES */ 229 244 OFFSET(PACA_EXGEN, paca_struct, exgen); 230 245 OFFSET(PACA_EXMC, paca_struct, exmc); 231 246 OFFSET(PACA_EXNMI, paca_struct, exnmi); 232 - #ifdef CONFIG_PPC_PSERIES 233 - OFFSET(PACALPPACAPTR, paca_struct, lppaca_ptr); 234 - #endif 235 247 OFFSET(PACA_SLBSHADOWPTR, paca_struct, slb_shadow_ptr); 236 248 OFFSET(SLBSHADOW_STACKVSID, slb_shadow, save_area[SLB_NUM_BOLTED - 1].vsid); 237 249 OFFSET(SLBSHADOW_STACKESID, slb_shadow, save_area[SLB_NUM_BOLTED - 1].esid); ··· 228 264 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 229 265 OFFSET(PACA_PMCINUSE, paca_struct, pmcregs_in_use); 230 266 #endif 231 - OFFSET(LPPACA_DTLIDX, lppaca, dtl_idx); 232 267 OFFSET(LPPACA_YIELDCOUNT, lppaca, yield_count); 233 - OFFSET(PACA_DTL_RIDX, paca_struct, dtl_ridx); 234 268 #endif /* CONFIG_PPC_BOOK3S_64 */ 235 269 OFFSET(PACAEMERGSP, paca_struct, emergency_sp); 236 270 #ifdef CONFIG_PPC_BOOK3S_64 ··· 244 282 OFFSET(PACAHWCPUID, paca_struct, hw_cpu_id); 245 283 OFFSET(PACAKEXECSTATE, paca_struct, kexec_state); 246 284 OFFSET(PACA_DSCR_DEFAULT, paca_struct, dscr_default); 285 + #ifdef CONFIG_PPC64 286 + OFFSET(PACA_EXIT_SAVE_R1, paca_struct, exit_save_r1); 287 + #endif 247 288 #ifdef CONFIG_PPC_BOOK3E 248 289 OFFSET(PACA_TRAP_SAVE, paca_struct, trap_save); 249 290 #endif ··· 308 343 STACK_PT_REGS_OFFSET(STACK_REGS_AMR, amr); 309 344 STACK_PT_REGS_OFFSET(STACK_REGS_IAMR, iamr); 310 345 #endif 311 - #ifdef CONFIG_PPC_KUAP 312 - STACK_PT_REGS_OFFSET(STACK_REGS_KUAP, kuap); 313 - #endif 314 - 315 346 316 347 #if defined(CONFIG_PPC32) 317 348 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x) ··· 328 367 DEFINE(_DSRR1, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, dsrr1)); 329 368 #endif 330 369 #endif 331 - 332 - #ifndef CONFIG_PPC64 333 - OFFSET(MM_PGD, mm_struct, pgd); 334 - #endif /* ! CONFIG_PPC64 */ 335 370 336 371 /* About the CPU features table */ 337 372 OFFSET(CPU_SPEC_FEATURES, cpu_spec, cpu_features); ··· 360 403 #ifdef CONFIG_BUG 361 404 DEFINE(BUG_ENTRY_SIZE, sizeof(struct bug_entry)); 362 405 #endif 363 - 364 - #ifdef CONFIG_PPC_BOOK3S_64 365 - DEFINE(PGD_TABLE_SIZE, (sizeof(pgd_t) << max(RADIX_PGD_INDEX_SIZE, H_PGD_INDEX_SIZE))); 366 - #else 367 - DEFINE(PGD_TABLE_SIZE, PGD_TABLE_SIZE); 368 - #endif 369 - DEFINE(PTE_SIZE, sizeof(pte_t)); 370 406 371 407 #ifdef CONFIG_KVM 372 408 OFFSET(VCPU_HOST_STACK, kvm_vcpu, arch.host_stack); ··· 432 482 OFFSET(KVM_HOST_LPID, kvm, arch.host_lpid); 433 483 OFFSET(KVM_HOST_LPCR, kvm, arch.host_lpcr); 434 484 OFFSET(KVM_HOST_SDR1, kvm, arch.host_sdr1); 435 - OFFSET(KVM_NEED_FLUSH, kvm, arch.need_tlb_flush.bits); 436 485 OFFSET(KVM_ENABLED_HCALLS, kvm, arch.enabled_hcalls); 437 486 OFFSET(KVM_VRMA_SLB_V, kvm, arch.vrma_slb_v); 438 487 OFFSET(KVM_RADIX, kvm, arch.radix); 439 - OFFSET(KVM_FWNMI, kvm, arch.fwnmi_enabled); 440 488 OFFSET(KVM_SECURE_GUEST, kvm, arch.secure_guest); 441 489 OFFSET(VCPU_DSISR, kvm_vcpu, arch.shregs.dsisr); 442 490 OFFSET(VCPU_DAR, kvm_vcpu, arch.shregs.dar); ··· 462 514 OFFSET(VCPU_DAWRX1, kvm_vcpu, arch.dawrx1); 463 515 OFFSET(VCPU_CIABR, kvm_vcpu, arch.ciabr); 464 516 OFFSET(VCPU_HFLAGS, kvm_vcpu, arch.hflags); 465 - OFFSET(VCPU_DEC, kvm_vcpu, arch.dec); 466 517 OFFSET(VCPU_DEC_EXPIRES, kvm_vcpu, arch.dec_expires); 467 518 OFFSET(VCPU_PENDING_EXC, kvm_vcpu, arch.pending_exceptions); 468 519 OFFSET(VCPU_CEDED, kvm_vcpu, arch.ceded); ··· 472 525 OFFSET(VCPU_MMCRA, kvm_vcpu, arch.mmcra); 473 526 OFFSET(VCPU_MMCRS, kvm_vcpu, arch.mmcrs); 474 527 OFFSET(VCPU_PMC, kvm_vcpu, arch.pmc); 475 - OFFSET(VCPU_SPMC, kvm_vcpu, arch.spmc); 476 528 OFFSET(VCPU_SIAR, kvm_vcpu, arch.siar); 477 529 OFFSET(VCPU_SDAR, kvm_vcpu, arch.sdar); 478 530 OFFSET(VCPU_SIER, kvm_vcpu, arch.sier); ··· 591 645 HSTATE_FIELD(HSTATE_HWTHREAD_STATE, hwthread_state); 592 646 HSTATE_FIELD(HSTATE_KVM_VCPU, kvm_vcpu); 593 647 HSTATE_FIELD(HSTATE_KVM_VCORE, kvm_vcore); 594 - HSTATE_FIELD(HSTATE_XICS_PHYS, xics_phys); 595 648 HSTATE_FIELD(HSTATE_XIVE_TIMA_PHYS, xive_tima_phys); 596 649 HSTATE_FIELD(HSTATE_XIVE_TIMA_VIRT, xive_tima_virt); 597 - HSTATE_FIELD(HSTATE_SAVED_XIRR, saved_xirr); 598 650 HSTATE_FIELD(HSTATE_HOST_IPI, host_ipi); 599 651 HSTATE_FIELD(HSTATE_PTID, ptid); 600 652 HSTATE_FIELD(HSTATE_FAKE_SUSPEND, fake_suspend); ··· 700 756 #endif 701 757 702 758 DEFINE(PPC_DBELL_SERVER, PPC_DBELL_SERVER); 703 - DEFINE(PPC_DBELL_MSGTYPE, PPC_DBELL_MSGTYPE); 704 759 705 760 #ifdef CONFIG_PPC_8xx 706 761 DEFINE(VIRT_IMMR_BASE, (u64)__fix_to_virt(FIX_IMMR_BASE));
+3 -3
arch/powerpc/kernel/crash_dump.c
··· 35 35 36 36 static void __init create_trampoline(unsigned long addr) 37 37 { 38 - struct ppc_inst *p = (struct ppc_inst *)addr; 38 + u32 *p = (u32 *)addr; 39 39 40 40 /* The maximum range of a single instruction branch, is the current 41 41 * instruction's address + (32 MB - 4) bytes. For the trampoline we ··· 45 45 * branch to "addr" we jump to ("addr" + 32 MB). Although it requires 46 46 * two instructions it doesn't require any registers. 47 47 */ 48 - patch_instruction(p, ppc_inst(PPC_INST_NOP)); 49 - patch_branch((void *)p + 4, addr + PHYSICAL_START, 0); 48 + patch_instruction(p, ppc_inst(PPC_RAW_NOP())); 49 + patch_branch(p + 1, addr + PHYSICAL_START, 0); 50 50 } 51 51 52 52 void __init setup_kdump_trampoline(void)
+19 -35
arch/powerpc/kernel/entry_32.S
··· 32 32 #include <asm/barrier.h> 33 33 #include <asm/kup.h> 34 34 #include <asm/bug.h> 35 + #include <asm/interrupt.h> 35 36 36 37 #include "head_32.h" 37 38 ··· 75 74 76 75 .globl transfer_to_syscall 77 76 transfer_to_syscall: 77 + stw r11, GPR1(r1) 78 + stw r11, 0(r1) 79 + mflr r12 80 + stw r12, _LINK(r1) 81 + #if defined(CONFIG_BOOKE) || defined(CONFIG_40x) 82 + rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ 83 + #endif 84 + lis r12,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */ 85 + SAVE_GPR(2, r1) 86 + addi r12,r12,STACK_FRAME_REGS_MARKER@l 87 + stw r9,_MSR(r1) 88 + li r2, INTERRUPT_SYSCALL 89 + stw r12,8(r1) 90 + stw r2,_TRAP(r1) 91 + SAVE_GPR(0, r1) 92 + SAVE_4GPRS(3, r1) 93 + SAVE_2GPRS(7, r1) 94 + addi r2,r10,-THREAD 78 95 SAVE_NVGPRS(r1) 79 96 80 97 /* Calling convention has r9 = orig r0, r10 = regs */ ··· 195 176 /* r3-r12 are caller saved -- Cort */ 196 177 SAVE_NVGPRS(r1) 197 178 stw r0,_NIP(r1) /* Return to switch caller */ 198 - mfmsr r11 199 - li r0,MSR_FP /* Disable floating-point */ 200 - #ifdef CONFIG_ALTIVEC 201 - BEGIN_FTR_SECTION 202 - oris r0,r0,MSR_VEC@h /* Disable altivec */ 203 - mfspr r12,SPRN_VRSAVE /* save vrsave register value */ 204 - stw r12,THREAD+THREAD_VRSAVE(r2) 205 - END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 206 - #endif /* CONFIG_ALTIVEC */ 207 - #ifdef CONFIG_SPE 208 - BEGIN_FTR_SECTION 209 - oris r0,r0,MSR_SPE@h /* Disable SPE */ 210 - mfspr r12,SPRN_SPEFSCR /* save spefscr register value */ 211 - stw r12,THREAD+THREAD_SPEFSCR(r2) 212 - END_FTR_SECTION_IFSET(CPU_FTR_SPE) 213 - #endif /* CONFIG_SPE */ 214 - and. r0,r0,r11 /* FP or altivec or SPE enabled? */ 215 - beq+ 1f 216 - andc r11,r11,r0 217 - mtmsr r11 218 - isync 219 - 1: stw r11,_MSR(r1) 220 179 mfcr r10 221 180 stw r10,_CCR(r1) 222 181 stw r1,KSP(r3) /* Set old stack pointer */ ··· 214 217 /* save the old current 'last' for return value */ 215 218 mr r3,r2 216 219 addi r2,r4,-THREAD /* Update current */ 217 - 218 - #ifdef CONFIG_ALTIVEC 219 - BEGIN_FTR_SECTION 220 - lwz r0,THREAD+THREAD_VRSAVE(r2) 221 - mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */ 222 - END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 223 - #endif /* CONFIG_ALTIVEC */ 224 - #ifdef CONFIG_SPE 225 - BEGIN_FTR_SECTION 226 - lwz r0,THREAD+THREAD_SPEFSCR(r2) 227 - mtspr SPRN_SPEFSCR,r0 /* restore SPEFSCR reg */ 228 - END_FTR_SECTION_IFSET(CPU_FTR_SPE) 229 - #endif /* CONFIG_SPE */ 230 220 231 221 lwz r0,_CCR(r1) 232 222 mtcrf 0xFF,r0
-516
arch/powerpc/kernel/entry_64.S
··· 32 32 #include <asm/irqflags.h> 33 33 #include <asm/hw_irq.h> 34 34 #include <asm/context_tracking.h> 35 - #include <asm/tm.h> 36 35 #include <asm/ppc-opcode.h> 37 36 #include <asm/barrier.h> 38 37 #include <asm/export.h> ··· 47 48 /* 48 49 * System calls. 49 50 */ 50 - .section ".toc","aw" 51 - SYS_CALL_TABLE: 52 - .tc sys_call_table[TC],sys_call_table 53 - 54 - #ifdef CONFIG_COMPAT 55 - COMPAT_SYS_CALL_TABLE: 56 - .tc compat_sys_call_table[TC],compat_sys_call_table 57 - #endif 58 - 59 - /* This value is used to mark exception frames on the stack. */ 60 - exception_marker: 61 - .tc ID_EXC_MARKER[TC],STACK_FRAME_REGS_MARKER 62 - 63 51 .section ".text" 64 - .align 7 65 - 66 - #ifdef CONFIG_PPC_BOOK3S 67 - .macro system_call_vectored name trapnr 68 - .globl system_call_vectored_\name 69 - system_call_vectored_\name: 70 - _ASM_NOKPROBE_SYMBOL(system_call_vectored_\name) 71 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 72 - BEGIN_FTR_SECTION 73 - extrdi. r10, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */ 74 - bne .Ltabort_syscall 75 - END_FTR_SECTION_IFSET(CPU_FTR_TM) 76 - #endif 77 - SCV_INTERRUPT_TO_KERNEL 78 - mr r10,r1 79 - ld r1,PACAKSAVE(r13) 80 - std r10,0(r1) 81 - std r11,_NIP(r1) 82 - std r12,_MSR(r1) 83 - std r0,GPR0(r1) 84 - std r10,GPR1(r1) 85 - std r2,GPR2(r1) 86 - ld r2,PACATOC(r13) 87 - mfcr r12 88 - li r11,0 89 - /* Can we avoid saving r3-r8 in common case? */ 90 - std r3,GPR3(r1) 91 - std r4,GPR4(r1) 92 - std r5,GPR5(r1) 93 - std r6,GPR6(r1) 94 - std r7,GPR7(r1) 95 - std r8,GPR8(r1) 96 - /* Zero r9-r12, this should only be required when restoring all GPRs */ 97 - std r11,GPR9(r1) 98 - std r11,GPR10(r1) 99 - std r11,GPR11(r1) 100 - std r11,GPR12(r1) 101 - std r9,GPR13(r1) 102 - SAVE_NVGPRS(r1) 103 - std r11,_XER(r1) 104 - std r11,_LINK(r1) 105 - std r11,_CTR(r1) 106 - 107 - li r11,\trapnr 108 - std r11,_TRAP(r1) 109 - std r12,_CCR(r1) 110 - addi r10,r1,STACK_FRAME_OVERHEAD 111 - ld r11,exception_marker@toc(r2) 112 - std r11,-16(r10) /* "regshere" marker */ 113 - 114 - BEGIN_FTR_SECTION 115 - HMT_MEDIUM 116 - END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 117 - 118 - /* 119 - * scv enters with MSR[EE]=1 and is immediately considered soft-masked. 120 - * The entry vector already sets PACAIRQSOFTMASK to IRQS_ALL_DISABLED, 121 - * and interrupts may be masked and pending already. 122 - * system_call_exception() will call trace_hardirqs_off() which means 123 - * interrupts could already have been blocked before trace_hardirqs_off, 124 - * but this is the best we can do. 125 - */ 126 - 127 - /* Calling convention has r9 = orig r0, r10 = regs */ 128 - mr r9,r0 129 - bl system_call_exception 130 - 131 - .Lsyscall_vectored_\name\()_exit: 132 - addi r4,r1,STACK_FRAME_OVERHEAD 133 - li r5,1 /* scv */ 134 - bl syscall_exit_prepare 135 - 136 - ld r2,_CCR(r1) 137 - ld r4,_NIP(r1) 138 - ld r5,_MSR(r1) 139 - 140 - BEGIN_FTR_SECTION 141 - stdcx. r0,0,r1 /* to clear the reservation */ 142 - END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 143 - 144 - BEGIN_FTR_SECTION 145 - HMT_MEDIUM_LOW 146 - END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 147 - 148 - cmpdi r3,0 149 - bne .Lsyscall_vectored_\name\()_restore_regs 150 - 151 - /* rfscv returns with LR->NIA and CTR->MSR */ 152 - mtlr r4 153 - mtctr r5 154 - 155 - /* Could zero these as per ABI, but we may consider a stricter ABI 156 - * which preserves these if libc implementations can benefit, so 157 - * restore them for now until further measurement is done. */ 158 - ld r0,GPR0(r1) 159 - ld r4,GPR4(r1) 160 - ld r5,GPR5(r1) 161 - ld r6,GPR6(r1) 162 - ld r7,GPR7(r1) 163 - ld r8,GPR8(r1) 164 - /* Zero volatile regs that may contain sensitive kernel data */ 165 - li r9,0 166 - li r10,0 167 - li r11,0 168 - li r12,0 169 - mtspr SPRN_XER,r0 170 - 171 - /* 172 - * We don't need to restore AMR on the way back to userspace for KUAP. 173 - * The value of AMR only matters while we're in the kernel. 174 - */ 175 - mtcr r2 176 - ld r2,GPR2(r1) 177 - ld r3,GPR3(r1) 178 - ld r13,GPR13(r1) 179 - ld r1,GPR1(r1) 180 - RFSCV_TO_USER 181 - b . /* prevent speculative execution */ 182 - 183 - .Lsyscall_vectored_\name\()_restore_regs: 184 - li r3,0 185 - mtmsrd r3,1 186 - mtspr SPRN_SRR0,r4 187 - mtspr SPRN_SRR1,r5 188 - 189 - ld r3,_CTR(r1) 190 - ld r4,_LINK(r1) 191 - ld r5,_XER(r1) 192 - 193 - REST_NVGPRS(r1) 194 - ld r0,GPR0(r1) 195 - mtcr r2 196 - mtctr r3 197 - mtlr r4 198 - mtspr SPRN_XER,r5 199 - REST_10GPRS(2, r1) 200 - REST_2GPRS(12, r1) 201 - ld r1,GPR1(r1) 202 - RFI_TO_USER 203 - .endm 204 - 205 - system_call_vectored common 0x3000 206 - /* 207 - * We instantiate another entry copy for the SIGILL variant, with TRAP=0x7ff0 208 - * which is tested by system_call_exception when r0 is -1 (as set by vector 209 - * entry code). 210 - */ 211 - system_call_vectored sigill 0x7ff0 212 - 213 - 214 - /* 215 - * Entered via kernel return set up by kernel/sstep.c, must match entry regs 216 - */ 217 - .globl system_call_vectored_emulate 218 - system_call_vectored_emulate: 219 - _ASM_NOKPROBE_SYMBOL(system_call_vectored_emulate) 220 - li r10,IRQS_ALL_DISABLED 221 - stb r10,PACAIRQSOFTMASK(r13) 222 - b system_call_vectored_common 223 - #endif 224 - 225 - .balign IFETCH_ALIGN_BYTES 226 - .globl system_call_common_real 227 - system_call_common_real: 228 - ld r10,PACAKMSR(r13) /* get MSR value for kernel */ 229 - mtmsrd r10 230 - 231 - .balign IFETCH_ALIGN_BYTES 232 - .globl system_call_common 233 - system_call_common: 234 - _ASM_NOKPROBE_SYMBOL(system_call_common) 235 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 236 - BEGIN_FTR_SECTION 237 - extrdi. r10, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */ 238 - bne .Ltabort_syscall 239 - END_FTR_SECTION_IFSET(CPU_FTR_TM) 240 - #endif 241 - mr r10,r1 242 - ld r1,PACAKSAVE(r13) 243 - std r10,0(r1) 244 - std r11,_NIP(r1) 245 - std r12,_MSR(r1) 246 - std r0,GPR0(r1) 247 - std r10,GPR1(r1) 248 - std r2,GPR2(r1) 249 - #ifdef CONFIG_PPC_FSL_BOOK3E 250 - START_BTB_FLUSH_SECTION 251 - BTB_FLUSH(r10) 252 - END_BTB_FLUSH_SECTION 253 - #endif 254 - ld r2,PACATOC(r13) 255 - mfcr r12 256 - li r11,0 257 - /* Can we avoid saving r3-r8 in common case? */ 258 - std r3,GPR3(r1) 259 - std r4,GPR4(r1) 260 - std r5,GPR5(r1) 261 - std r6,GPR6(r1) 262 - std r7,GPR7(r1) 263 - std r8,GPR8(r1) 264 - /* Zero r9-r12, this should only be required when restoring all GPRs */ 265 - std r11,GPR9(r1) 266 - std r11,GPR10(r1) 267 - std r11,GPR11(r1) 268 - std r11,GPR12(r1) 269 - std r9,GPR13(r1) 270 - SAVE_NVGPRS(r1) 271 - std r11,_XER(r1) 272 - std r11,_CTR(r1) 273 - mflr r10 274 - 275 - /* 276 - * This clears CR0.SO (bit 28), which is the error indication on 277 - * return from this system call. 278 - */ 279 - rldimi r12,r11,28,(63-28) 280 - li r11,0xc00 281 - std r10,_LINK(r1) 282 - std r11,_TRAP(r1) 283 - std r12,_CCR(r1) 284 - addi r10,r1,STACK_FRAME_OVERHEAD 285 - ld r11,exception_marker@toc(r2) 286 - std r11,-16(r10) /* "regshere" marker */ 287 - 288 - /* 289 - * We always enter kernel from userspace with irq soft-mask enabled and 290 - * nothing pending. system_call_exception() will call 291 - * trace_hardirqs_off(). 292 - */ 293 - li r11,IRQS_ALL_DISABLED 294 - li r12,PACA_IRQ_HARD_DIS 295 - stb r11,PACAIRQSOFTMASK(r13) 296 - stb r12,PACAIRQHAPPENED(r13) 297 - 298 - /* Calling convention has r9 = orig r0, r10 = regs */ 299 - mr r9,r0 300 - bl system_call_exception 301 - 302 - .Lsyscall_exit: 303 - addi r4,r1,STACK_FRAME_OVERHEAD 304 - li r5,0 /* !scv */ 305 - bl syscall_exit_prepare 306 - 307 - ld r2,_CCR(r1) 308 - ld r4,_NIP(r1) 309 - ld r5,_MSR(r1) 310 - ld r6,_LINK(r1) 311 - 312 - BEGIN_FTR_SECTION 313 - stdcx. r0,0,r1 /* to clear the reservation */ 314 - END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 315 - 316 - mtspr SPRN_SRR0,r4 317 - mtspr SPRN_SRR1,r5 318 - mtlr r6 319 - 320 - cmpdi r3,0 321 - bne .Lsyscall_restore_regs 322 - /* Zero volatile regs that may contain sensitive kernel data */ 323 - li r0,0 324 - li r4,0 325 - li r5,0 326 - li r6,0 327 - li r7,0 328 - li r8,0 329 - li r9,0 330 - li r10,0 331 - li r11,0 332 - li r12,0 333 - mtctr r0 334 - mtspr SPRN_XER,r0 335 - .Lsyscall_restore_regs_cont: 336 - 337 - BEGIN_FTR_SECTION 338 - HMT_MEDIUM_LOW 339 - END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 340 - 341 - /* 342 - * We don't need to restore AMR on the way back to userspace for KUAP. 343 - * The value of AMR only matters while we're in the kernel. 344 - */ 345 - mtcr r2 346 - ld r2,GPR2(r1) 347 - ld r3,GPR3(r1) 348 - ld r13,GPR13(r1) 349 - ld r1,GPR1(r1) 350 - RFI_TO_USER 351 - b . /* prevent speculative execution */ 352 - 353 - .Lsyscall_restore_regs: 354 - ld r3,_CTR(r1) 355 - ld r4,_XER(r1) 356 - REST_NVGPRS(r1) 357 - mtctr r3 358 - mtspr SPRN_XER,r4 359 - ld r0,GPR0(r1) 360 - REST_8GPRS(4, r1) 361 - ld r12,GPR12(r1) 362 - b .Lsyscall_restore_regs_cont 363 - 364 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 365 - .Ltabort_syscall: 366 - /* Firstly we need to enable TM in the kernel */ 367 - mfmsr r10 368 - li r9, 1 369 - rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG 370 - mtmsrd r10, 0 371 - 372 - /* tabort, this dooms the transaction, nothing else */ 373 - li r9, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT) 374 - TABORT(R9) 375 - 376 - /* 377 - * Return directly to userspace. We have corrupted user register state, 378 - * but userspace will never see that register state. Execution will 379 - * resume after the tbegin of the aborted transaction with the 380 - * checkpointed register state. 381 - */ 382 - li r9, MSR_RI 383 - andc r10, r10, r9 384 - mtmsrd r10, 1 385 - mtspr SPRN_SRR0, r11 386 - mtspr SPRN_SRR1, r12 387 - RFI_TO_USER 388 - b . /* prevent speculative execution */ 389 - #endif 390 - 391 - #ifdef CONFIG_PPC_BOOK3S 392 - _GLOBAL(ret_from_fork_scv) 393 - bl schedule_tail 394 - REST_NVGPRS(r1) 395 - li r3,0 /* fork() return value */ 396 - b .Lsyscall_vectored_common_exit 397 - #endif 398 - 399 - _GLOBAL(ret_from_fork) 400 - bl schedule_tail 401 - REST_NVGPRS(r1) 402 - li r3,0 /* fork() return value */ 403 - b .Lsyscall_exit 404 - 405 - _GLOBAL(ret_from_kernel_thread) 406 - bl schedule_tail 407 - REST_NVGPRS(r1) 408 - mtctr r14 409 - mr r3,r15 410 - #ifdef PPC64_ELF_ABI_v2 411 - mr r12,r14 412 - #endif 413 - bctrl 414 - li r3,0 415 - b .Lsyscall_exit 416 52 417 53 #ifdef CONFIG_PPC_BOOK3S_64 418 54 ··· 263 629 mtlr r7 264 630 addi r1,r1,SWITCH_FRAME_SIZE 265 631 blr 266 - 267 - /* 268 - * If MSR EE/RI was never enabled, IRQs not reconciled, NVGPRs not 269 - * touched, no exit work created, then this can be used. 270 - */ 271 - .balign IFETCH_ALIGN_BYTES 272 - .globl fast_interrupt_return 273 - fast_interrupt_return: 274 - _ASM_NOKPROBE_SYMBOL(fast_interrupt_return) 275 - kuap_check_amr r3, r4 276 - ld r5,_MSR(r1) 277 - andi. r0,r5,MSR_PR 278 - #ifdef CONFIG_PPC_BOOK3S 279 - bne .Lfast_user_interrupt_return_amr 280 - kuap_kernel_restore r3, r4 281 - andi. r0,r5,MSR_RI 282 - li r3,0 /* 0 return value, no EMULATE_STACK_STORE */ 283 - bne+ .Lfast_kernel_interrupt_return 284 - addi r3,r1,STACK_FRAME_OVERHEAD 285 - bl unrecoverable_exception 286 - b . /* should not get here */ 287 - #else 288 - bne .Lfast_user_interrupt_return 289 - b .Lfast_kernel_interrupt_return 290 - #endif 291 - 292 - .balign IFETCH_ALIGN_BYTES 293 - .globl interrupt_return 294 - interrupt_return: 295 - _ASM_NOKPROBE_SYMBOL(interrupt_return) 296 - ld r4,_MSR(r1) 297 - andi. r0,r4,MSR_PR 298 - beq .Lkernel_interrupt_return 299 - addi r3,r1,STACK_FRAME_OVERHEAD 300 - bl interrupt_exit_user_prepare 301 - cmpdi r3,0 302 - bne- .Lrestore_nvgprs 303 - 304 - #ifdef CONFIG_PPC_BOOK3S 305 - .Lfast_user_interrupt_return_amr: 306 - kuap_user_restore r3, r4 307 - #endif 308 - .Lfast_user_interrupt_return: 309 - ld r11,_NIP(r1) 310 - ld r12,_MSR(r1) 311 - BEGIN_FTR_SECTION 312 - ld r10,_PPR(r1) 313 - mtspr SPRN_PPR,r10 314 - END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 315 - mtspr SPRN_SRR0,r11 316 - mtspr SPRN_SRR1,r12 317 - 318 - BEGIN_FTR_SECTION 319 - stdcx. r0,0,r1 /* to clear the reservation */ 320 - FTR_SECTION_ELSE 321 - ldarx r0,0,r1 322 - ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 323 - 324 - ld r3,_CCR(r1) 325 - ld r4,_LINK(r1) 326 - ld r5,_CTR(r1) 327 - ld r6,_XER(r1) 328 - li r0,0 329 - 330 - REST_4GPRS(7, r1) 331 - REST_2GPRS(11, r1) 332 - REST_GPR(13, r1) 333 - 334 - mtcr r3 335 - mtlr r4 336 - mtctr r5 337 - mtspr SPRN_XER,r6 338 - 339 - REST_4GPRS(2, r1) 340 - REST_GPR(6, r1) 341 - REST_GPR(0, r1) 342 - REST_GPR(1, r1) 343 - RFI_TO_USER 344 - b . /* prevent speculative execution */ 345 - 346 - .Lrestore_nvgprs: 347 - REST_NVGPRS(r1) 348 - b .Lfast_user_interrupt_return 349 - 350 - .balign IFETCH_ALIGN_BYTES 351 - .Lkernel_interrupt_return: 352 - addi r3,r1,STACK_FRAME_OVERHEAD 353 - bl interrupt_exit_kernel_prepare 354 - 355 - .Lfast_kernel_interrupt_return: 356 - cmpdi cr1,r3,0 357 - ld r11,_NIP(r1) 358 - ld r12,_MSR(r1) 359 - mtspr SPRN_SRR0,r11 360 - mtspr SPRN_SRR1,r12 361 - 362 - BEGIN_FTR_SECTION 363 - stdcx. r0,0,r1 /* to clear the reservation */ 364 - FTR_SECTION_ELSE 365 - ldarx r0,0,r1 366 - ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 367 - 368 - ld r3,_LINK(r1) 369 - ld r4,_CTR(r1) 370 - ld r5,_XER(r1) 371 - ld r6,_CCR(r1) 372 - li r0,0 373 - 374 - REST_4GPRS(7, r1) 375 - REST_2GPRS(11, r1) 376 - 377 - mtlr r3 378 - mtctr r4 379 - mtspr SPRN_XER,r5 380 - 381 - /* 382 - * Leaving a stale exception_marker on the stack can confuse 383 - * the reliable stack unwinder later on. Clear it. 384 - */ 385 - std r0,STACK_FRAME_OVERHEAD-16(r1) 386 - 387 - REST_4GPRS(2, r1) 388 - 389 - bne- cr1,1f /* emulate stack store */ 390 - mtcr r6 391 - REST_GPR(6, r1) 392 - REST_GPR(0, r1) 393 - REST_GPR(1, r1) 394 - RFI_TO_KERNEL 395 - b . /* prevent speculative execution */ 396 - 397 - 1: /* 398 - * Emulate stack store with update. New r1 value was already calculated 399 - * and updated in our interrupt regs by emulate_loadstore, but we can't 400 - * store the previous value of r1 to the stack before re-loading our 401 - * registers from it, otherwise they could be clobbered. Use 402 - * PACA_EXGEN as temporary storage to hold the store data, as 403 - * interrupts are disabled here so it won't be clobbered. 404 - */ 405 - mtcr r6 406 - std r9,PACA_EXGEN+0(r13) 407 - addi r9,r1,INT_FRAME_SIZE /* get original r1 */ 408 - REST_GPR(6, r1) 409 - REST_GPR(0, r1) 410 - REST_GPR(1, r1) 411 - std r9,0(r1) /* perform store component of stdu */ 412 - ld r9,PACA_EXGEN+0(r13) 413 - 414 - RFI_TO_KERNEL 415 - b . /* prevent speculative execution */ 416 632 417 633 #ifdef CONFIG_PPC_RTAS 418 634 /*
+2 -2
arch/powerpc/kernel/epapr_paravirt.c
··· 38 38 39 39 for (i = 0; i < (len / 4); i++) { 40 40 struct ppc_inst inst = ppc_inst(be32_to_cpu(insts[i])); 41 - patch_instruction((struct ppc_inst *)(epapr_hypercall_start + i), inst); 41 + patch_instruction(epapr_hypercall_start + i, inst); 42 42 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) 43 - patch_instruction((struct ppc_inst *)(epapr_ev_idle_start + i), inst); 43 + patch_instruction(epapr_ev_idle_start + i, inst); 44 44 #endif 45 45 } 46 46
+50 -2
arch/powerpc/kernel/exceptions-64e.S
··· 26 26 #include <asm/feature-fixups.h> 27 27 #include <asm/context_tracking.h> 28 28 29 + /* 64e interrupt returns always use SRR registers */ 30 + #define fast_interrupt_return fast_interrupt_return_srr 31 + #define interrupt_return interrupt_return_srr 32 + 29 33 /* XXX This will ultimately add space for a special exception save 30 34 * structure used to save things like SRR0/SRR1, SPRGs, MAS, etc... 31 35 * when taking special interrupts. For now we don't support that, ··· 901 897 bl unknown_exception 902 898 b interrupt_return 903 899 900 + .macro SEARCH_RESTART_TABLE 901 + #ifdef CONFIG_RELOCATABLE 902 + ld r11,PACATOC(r13) 903 + ld r14,__start___restart_table@got(r11) 904 + ld r15,__stop___restart_table@got(r11) 905 + #else 906 + LOAD_REG_IMMEDIATE_SYM(r14, r11, __start___restart_table) 907 + LOAD_REG_IMMEDIATE_SYM(r15, r11, __stop___restart_table) 908 + #endif 909 + 300: 910 + cmpd r14,r15 911 + beq 302f 912 + ld r11,0(r14) 913 + cmpld r10,r11 914 + blt 301f 915 + ld r11,8(r14) 916 + cmpld r10,r11 917 + bge 301f 918 + ld r11,16(r14) 919 + b 303f 920 + 301: 921 + addi r14,r14,24 922 + b 300b 923 + 302: 924 + li r11,0 925 + 303: 926 + .endm 927 + 904 928 /* 905 929 * An interrupt came in while soft-disabled; We mark paca->irq_happened 906 930 * accordingly and if the interrupt is level sensitive, we hard disable ··· 937 905 */ 938 906 939 907 .macro masked_interrupt_book3e paca_irq full_mask 908 + std r14,PACA_EXGEN+EX_R14(r13) 909 + std r15,PACA_EXGEN+EX_R15(r13) 910 + 940 911 lbz r10,PACAIRQHAPPENED(r13) 941 912 .if \full_mask == 1 942 913 ori r10,r10,\paca_irq | PACA_IRQ_HARD_DIS ··· 949 914 stb r10,PACAIRQHAPPENED(r13) 950 915 951 916 .if \full_mask == 1 952 - rldicl r10,r11,48,1 /* clear MSR_EE */ 953 - rotldi r11,r10,16 917 + xori r11,r11,MSR_EE /* clear MSR_EE */ 954 918 mtspr SPRN_SRR1,r11 955 919 .endif 920 + 921 + mfspr r10,SPRN_SRR0 922 + SEARCH_RESTART_TABLE 923 + cmpdi r11,0 924 + beq 1f 925 + mtspr SPRN_SRR0,r11 /* return to restart address */ 926 + 1: 956 927 957 928 lwz r11,PACA_EXGEN+EX_CR(r13) 958 929 mtcr r11 959 930 ld r10,PACA_EXGEN+EX_R10(r13) 960 931 ld r11,PACA_EXGEN+EX_R11(r13) 932 + ld r14,PACA_EXGEN+EX_R14(r13) 933 + ld r15,PACA_EXGEN+EX_R15(r13) 961 934 mfspr r13,SPRN_SPRG_GEN_SCRATCH 962 935 rfi 963 936 b . ··· 1325 1282 a2_tlbinit_after_linear_map: 1326 1283 1327 1284 /* Now we branch the new virtual address mapped by this entry */ 1285 + #ifdef CONFIG_RELOCATABLE 1286 + ld r5,PACATOC(r13) 1287 + ld r3,1f@got(r5) 1288 + #else 1328 1289 LOAD_REG_IMMEDIATE_SYM(r3, r5, 1f) 1290 + #endif 1329 1291 mtctr r3 1330 1292 bctr 1331 1293
+186 -63
arch/powerpc/kernel/exceptions-64s.S
··· 428 428 429 429 /* If coming from user, skip soft-mask tests. */ 430 430 andi. r10,r12,MSR_PR 431 - bne 2f 431 + bne 3f 432 432 433 - /* Kernel code running below __end_interrupts is implicitly 434 - * soft-masked */ 435 - LOAD_HANDLER(r10, __end_interrupts) 433 + /* 434 + * Kernel code running below __end_soft_masked may be 435 + * implicitly soft-masked if it is within the regions 436 + * in the soft mask table. 437 + */ 438 + LOAD_HANDLER(r10, __end_soft_masked) 436 439 cmpld r11,r10 440 + bge+ 1f 441 + 442 + /* SEARCH_SOFT_MASK_TABLE clobbers r9,r10,r12 */ 443 + mtctr r12 444 + stw r9,PACA_EXGEN+EX_CCR(r13) 445 + SEARCH_SOFT_MASK_TABLE 446 + cmpdi r12,0 447 + mfctr r12 /* Restore r12 to SRR1 */ 448 + lwz r9,PACA_EXGEN+EX_CCR(r13) 449 + beq 1f /* Not in soft-mask table */ 437 450 li r10,IMASK 438 - blt- 1f 451 + b 2f /* In soft-mask table, always mask */ 439 452 440 453 /* Test the soft mask state against our interrupt's bit */ 441 - lbz r10,PACAIRQSOFTMASK(r13) 442 - 1: andi. r10,r10,IMASK 454 + 1: lbz r10,PACAIRQSOFTMASK(r13) 455 + 2: andi. r10,r10,IMASK 443 456 /* Associate vector numbers with bits in paca->irq_happened */ 444 457 .if IVEC == 0x500 || IVEC == 0xea0 445 458 li r10,PACA_IRQ_EE ··· 483 470 484 471 .if ISTACK 485 472 andi. r10,r12,MSR_PR /* See if coming from user */ 486 - 2: mr r10,r1 /* Save r1 */ 473 + 3: mr r10,r1 /* Save r1 */ 487 474 subi r1,r1,INT_FRAME_SIZE /* alloc frame on kernel stack */ 488 475 beq- 100f 489 476 ld r1,PACAKSAVE(r13) /* kernel stack to use */ ··· 497 484 std r10,0(r1) /* make stack chain pointer */ 498 485 std r0,GPR0(r1) /* save r0 in stackframe */ 499 486 std r10,GPR1(r1) /* save r1 in stackframe */ 487 + 488 + /* Mark our [H]SRRs valid for return */ 489 + li r10,1 490 + .if IHSRR_IF_HVMODE 491 + BEGIN_FTR_SECTION 492 + stb r10,PACAHSRR_VALID(r13) 493 + FTR_SECTION_ELSE 494 + stb r10,PACASRR_VALID(r13) 495 + ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 496 + .elseif IHSRR 497 + stb r10,PACAHSRR_VALID(r13) 498 + .else 499 + stb r10,PACASRR_VALID(r13) 500 + .endif 500 501 501 502 .if ISET_RI 502 503 li r10,MSR_RI ··· 604 577 __GEN_COMMON_BODY \name 605 578 .endm 606 579 580 + .macro SEARCH_RESTART_TABLE 581 + #ifdef CONFIG_RELOCATABLE 582 + mr r12,r2 583 + ld r2,PACATOC(r13) 584 + LOAD_REG_ADDR(r9, __start___restart_table) 585 + LOAD_REG_ADDR(r10, __stop___restart_table) 586 + mr r2,r12 587 + #else 588 + LOAD_REG_IMMEDIATE_SYM(r9, r12, __start___restart_table) 589 + LOAD_REG_IMMEDIATE_SYM(r10, r12, __stop___restart_table) 590 + #endif 591 + 300: 592 + cmpd r9,r10 593 + beq 302f 594 + ld r12,0(r9) 595 + cmpld r11,r12 596 + blt 301f 597 + ld r12,8(r9) 598 + cmpld r11,r12 599 + bge 301f 600 + ld r12,16(r9) 601 + b 303f 602 + 301: 603 + addi r9,r9,24 604 + b 300b 605 + 302: 606 + li r12,0 607 + 303: 608 + .endm 609 + 610 + .macro SEARCH_SOFT_MASK_TABLE 611 + #ifdef CONFIG_RELOCATABLE 612 + mr r12,r2 613 + ld r2,PACATOC(r13) 614 + LOAD_REG_ADDR(r9, __start___soft_mask_table) 615 + LOAD_REG_ADDR(r10, __stop___soft_mask_table) 616 + mr r2,r12 617 + #else 618 + LOAD_REG_IMMEDIATE_SYM(r9, r12, __start___soft_mask_table) 619 + LOAD_REG_IMMEDIATE_SYM(r10, r12, __stop___soft_mask_table) 620 + #endif 621 + 300: 622 + cmpd r9,r10 623 + beq 302f 624 + ld r12,0(r9) 625 + cmpld r11,r12 626 + blt 301f 627 + ld r12,8(r9) 628 + cmpld r11,r12 629 + bge 301f 630 + li r12,1 631 + b 303f 632 + 301: 633 + addi r9,r9,16 634 + b 300b 635 + 302: 636 + li r12,0 637 + 303: 638 + .endm 639 + 607 640 /* 608 641 * Restore all registers including H/SRR0/1 saved in a stack frame of a 609 642 * standard exception. ··· 671 584 .macro EXCEPTION_RESTORE_REGS hsrr=0 672 585 /* Move original SRR0 and SRR1 into the respective regs */ 673 586 ld r9,_MSR(r1) 587 + li r10,0 674 588 .if \hsrr 675 589 mtspr SPRN_HSRR1,r9 590 + stb r10,PACAHSRR_VALID(r13) 676 591 .else 677 592 mtspr SPRN_SRR1,r9 593 + stb r10,PACASRR_VALID(r13) 678 594 .endif 679 595 ld r9,_NIP(r1) 680 596 .if \hsrr ··· 794 704 * scv instructions enter the kernel without changing EE, RI, ME, or HV. 795 705 * In particular, this means we can take a maskable interrupt at any point 796 706 * in the scv handler, which is unlike any other interrupt. This is solved 797 - * by treating the instruction addresses below __end_interrupts as being 798 - * soft-masked. 707 + * by treating the instruction addresses in the handler as being soft-masked, 708 + * by adding a SOFT_MASK_TABLE entry for them. 799 709 * 800 710 * AIL-0 mode scv exceptions go to 0x17000-0x17fff, but we set AIL-3 and 801 711 * ensure scv is never executed with relocation off, which means AIL-0 802 712 * should never happen. 803 713 * 804 - * Before leaving the below __end_interrupts text, at least of the following 805 - * must be true: 714 + * Before leaving the following inside-__end_soft_masked text, at least of the 715 + * following must be true: 806 716 * - MSR[PR]=1 (i.e., return to userspace) 807 - * - MSR_EE|MSR_RI is set (no reentrant exceptions) 717 + * - MSR_EE|MSR_RI is clear (no reentrant exceptions) 808 718 * - Standard kernel environment is set up (stack, paca, etc) 809 719 * 810 720 * Call convention: ··· 812 722 * syscall register convention is in Documentation/powerpc/syscall64-abi.rst 813 723 */ 814 724 EXC_VIRT_BEGIN(system_call_vectored, 0x3000, 0x1000) 725 + 1: 815 726 /* SCV 0 */ 816 727 mr r9,r13 817 728 GET_PACA(r13) ··· 842 751 b system_call_vectored_sigill 843 752 #endif 844 753 .endr 754 + 2: 845 755 EXC_VIRT_END(system_call_vectored, 0x3000, 0x1000) 756 + 757 + SOFT_MASK_TABLE(1b, 2b) // Treat scv vectors as soft-masked, see comment above. 846 758 847 759 #ifdef CONFIG_RELOCATABLE 848 760 TRAMP_VIRT_BEGIN(system_call_vectored_tramp) ··· 1243 1149 mtmsrd r10,1 1244 1150 addi r3,r1,STACK_FRAME_OVERHEAD 1245 1151 bl machine_check_exception 1246 - b interrupt_return 1152 + b interrupt_return_srr 1247 1153 1248 1154 1249 1155 #ifdef CONFIG_PPC_P7_NAP ··· 1369 1275 MMU_FTR_SECTION_ELSE 1370 1276 bl do_page_fault 1371 1277 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) 1372 - b interrupt_return 1278 + b interrupt_return_srr 1373 1279 1374 1280 1: bl do_break 1375 1281 /* ··· 1377 1283 * If so, we need to restore them with their updated values. 1378 1284 */ 1379 1285 REST_NVGPRS(r1) 1380 - b interrupt_return 1286 + b interrupt_return_srr 1381 1287 1382 1288 1383 1289 /** ··· 1417 1323 bl do_slb_fault 1418 1324 cmpdi r3,0 1419 1325 bne- 1f 1420 - b fast_interrupt_return 1326 + b fast_interrupt_return_srr 1421 1327 1: /* Error case */ 1422 1328 MMU_FTR_SECTION_ELSE 1423 1329 /* Radix case, access is outside page table range */ ··· 1426 1332 std r3,RESULT(r1) 1427 1333 addi r3,r1,STACK_FRAME_OVERHEAD 1428 1334 bl do_bad_slb_fault 1429 - b interrupt_return 1335 + b interrupt_return_srr 1430 1336 1431 1337 1432 1338 /** ··· 1462 1368 MMU_FTR_SECTION_ELSE 1463 1369 bl do_page_fault 1464 1370 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) 1465 - b interrupt_return 1371 + b interrupt_return_srr 1466 1372 1467 1373 1468 1374 /** ··· 1497 1403 bl do_slb_fault 1498 1404 cmpdi r3,0 1499 1405 bne- 1f 1500 - b fast_interrupt_return 1406 + b fast_interrupt_return_srr 1501 1407 1: /* Error case */ 1502 1408 MMU_FTR_SECTION_ELSE 1503 1409 /* Radix case, access is outside page table range */ ··· 1506 1412 std r3,RESULT(r1) 1507 1413 addi r3,r1,STACK_FRAME_OVERHEAD 1508 1414 bl do_bad_slb_fault 1509 - b interrupt_return 1415 + b interrupt_return_srr 1510 1416 1511 1417 1512 1418 /** ··· 1550 1456 GEN_COMMON hardware_interrupt 1551 1457 addi r3,r1,STACK_FRAME_OVERHEAD 1552 1458 bl do_IRQ 1553 - b interrupt_return 1459 + BEGIN_FTR_SECTION 1460 + b interrupt_return_hsrr 1461 + FTR_SECTION_ELSE 1462 + b interrupt_return_srr 1463 + ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 1554 1464 1555 1465 1556 1466 /** ··· 1581 1483 addi r3,r1,STACK_FRAME_OVERHEAD 1582 1484 bl alignment_exception 1583 1485 REST_NVGPRS(r1) /* instruction emulation may change GPRs */ 1584 - b interrupt_return 1486 + b interrupt_return_srr 1585 1487 1586 1488 1587 1489 /** ··· 1688 1590 addi r3,r1,STACK_FRAME_OVERHEAD 1689 1591 bl program_check_exception 1690 1592 REST_NVGPRS(r1) /* instruction emulation may change GPRs */ 1691 - b interrupt_return 1593 + b interrupt_return_srr 1692 1594 1693 1595 1694 1596 /* ··· 1731 1633 END_FTR_SECTION_IFSET(CPU_FTR_TM) 1732 1634 #endif 1733 1635 bl load_up_fpu 1734 - b fast_interrupt_return 1636 + b fast_interrupt_return_srr 1735 1637 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1736 1638 2: /* User process was in a transaction */ 1737 1639 addi r3,r1,STACK_FRAME_OVERHEAD 1738 1640 bl fp_unavailable_tm 1739 - b interrupt_return 1641 + b interrupt_return_srr 1740 1642 #endif 1741 1643 1742 1644 ··· 1775 1677 GEN_COMMON decrementer 1776 1678 addi r3,r1,STACK_FRAME_OVERHEAD 1777 1679 bl timer_interrupt 1778 - b interrupt_return 1680 + b interrupt_return_srr 1779 1681 1780 1682 1781 1683 /** ··· 1812 1714 * 1813 1715 * Be careful to avoid touching the kernel stack. 1814 1716 */ 1717 + li r10,0 1718 + stb r10,PACAHSRR_VALID(r13) 1815 1719 ld r10,PACA_EXGEN+EX_CTR(r13) 1816 1720 mtctr r10 1817 1721 mtcrf 0x80,r9 ··· 1861 1761 #else 1862 1762 bl unknown_async_exception 1863 1763 #endif 1864 - b interrupt_return 1764 + b interrupt_return_srr 1865 1765 1866 1766 1867 1767 EXC_REAL_NONE(0xb00, 0x100) ··· 1938 1838 mtctr r10 1939 1839 bctr 1940 1840 .else 1941 - li r10,MSR_RI 1942 - mtmsrd r10,1 /* Set RI (EE=0) */ 1943 1841 #ifdef CONFIG_RELOCATABLE 1944 1842 __LOAD_HANDLER(r10, system_call_common) 1945 1843 mtctr r10 ··· 2023 1925 GEN_COMMON single_step 2024 1926 addi r3,r1,STACK_FRAME_OVERHEAD 2025 1927 bl single_step_exception 2026 - b interrupt_return 1928 + b interrupt_return_srr 2027 1929 2028 1930 2029 1931 /** ··· 2061 1963 MMU_FTR_SECTION_ELSE 2062 1964 bl unknown_exception 2063 1965 ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX) 2064 - b interrupt_return 1966 + b interrupt_return_hsrr 2065 1967 2066 1968 2067 1969 /** ··· 2086 1988 GEN_COMMON h_instr_storage 2087 1989 addi r3,r1,STACK_FRAME_OVERHEAD 2088 1990 bl unknown_exception 2089 - b interrupt_return 1991 + b interrupt_return_hsrr 2090 1992 2091 1993 2092 1994 /** ··· 2110 2012 addi r3,r1,STACK_FRAME_OVERHEAD 2111 2013 bl emulation_assist_interrupt 2112 2014 REST_NVGPRS(r1) /* instruction emulation may change GPRs */ 2113 - b interrupt_return 2015 + b interrupt_return_hsrr 2114 2016 2115 2017 2116 2018 /** ··· 2187 2089 GEN_COMMON hmi_exception 2188 2090 addi r3,r1,STACK_FRAME_OVERHEAD 2189 2091 bl handle_hmi_exception 2190 - b interrupt_return 2092 + b interrupt_return_hsrr 2191 2093 2192 2094 2193 2095 /** ··· 2217 2119 #else 2218 2120 bl unknown_async_exception 2219 2121 #endif 2220 - b interrupt_return 2122 + b interrupt_return_hsrr 2221 2123 2222 2124 2223 2125 /** ··· 2243 2145 GEN_COMMON h_virt_irq 2244 2146 addi r3,r1,STACK_FRAME_OVERHEAD 2245 2147 bl do_IRQ 2246 - b interrupt_return 2148 + b interrupt_return_hsrr 2247 2149 2248 2150 2249 2151 EXC_REAL_NONE(0xec0, 0x20) ··· 2286 2188 GEN_COMMON performance_monitor 2287 2189 addi r3,r1,STACK_FRAME_OVERHEAD 2288 2190 bl performance_monitor_exception 2289 - b interrupt_return 2191 + b interrupt_return_srr 2290 2192 2291 2193 2292 2194 /** ··· 2323 2225 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69) 2324 2226 #endif 2325 2227 bl load_up_altivec 2326 - b fast_interrupt_return 2228 + b fast_interrupt_return_srr 2327 2229 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 2328 2230 2: /* User process was in a transaction */ 2329 2231 addi r3,r1,STACK_FRAME_OVERHEAD 2330 2232 bl altivec_unavailable_tm 2331 - b interrupt_return 2233 + b interrupt_return_srr 2332 2234 #endif 2333 2235 1: 2334 2236 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 2335 2237 #endif 2336 2238 addi r3,r1,STACK_FRAME_OVERHEAD 2337 2239 bl altivec_unavailable_exception 2338 - b interrupt_return 2240 + b interrupt_return_srr 2339 2241 2340 2242 2341 2243 /** ··· 2376 2278 2: /* User process was in a transaction */ 2377 2279 addi r3,r1,STACK_FRAME_OVERHEAD 2378 2280 bl vsx_unavailable_tm 2379 - b interrupt_return 2281 + b interrupt_return_srr 2380 2282 #endif 2381 2283 1: 2382 2284 END_FTR_SECTION_IFSET(CPU_FTR_VSX) 2383 2285 #endif 2384 2286 addi r3,r1,STACK_FRAME_OVERHEAD 2385 2287 bl vsx_unavailable_exception 2386 - b interrupt_return 2288 + b interrupt_return_srr 2387 2289 2388 2290 2389 2291 /** ··· 2411 2313 addi r3,r1,STACK_FRAME_OVERHEAD 2412 2314 bl facility_unavailable_exception 2413 2315 REST_NVGPRS(r1) /* instruction emulation may change GPRs */ 2414 - b interrupt_return 2316 + b interrupt_return_srr 2415 2317 2416 2318 2417 2319 /** ··· 2439 2341 addi r3,r1,STACK_FRAME_OVERHEAD 2440 2342 bl facility_unavailable_exception 2441 2343 REST_NVGPRS(r1) /* XXX Shouldn't be necessary in practice */ 2442 - b interrupt_return 2344 + b interrupt_return_hsrr 2443 2345 2444 2346 2445 2347 EXC_REAL_NONE(0xfa0, 0x20) ··· 2468 2370 GEN_COMMON cbe_system_error 2469 2371 addi r3,r1,STACK_FRAME_OVERHEAD 2470 2372 bl cbe_system_error_exception 2471 - b interrupt_return 2373 + b interrupt_return_hsrr 2472 2374 2473 2375 #else /* CONFIG_CBE_RAS */ 2474 2376 EXC_REAL_NONE(0x1200, 0x100) ··· 2499 2401 GEN_COMMON instruction_breakpoint 2500 2402 addi r3,r1,STACK_FRAME_OVERHEAD 2501 2403 bl instruction_breakpoint_exception 2502 - b interrupt_return 2404 + b interrupt_return_srr 2503 2405 2504 2406 2505 2407 EXC_REAL_NONE(0x1400, 0x100) ··· 2607 2509 ld r10,PACA_EXGEN+EX_CFAR(r13) 2608 2510 mtspr SPRN_CFAR,r10 2609 2511 END_FTR_SECTION_IFSET(CPU_FTR_CFAR) 2512 + li r10,0 2513 + stb r10,PACAHSRR_VALID(r13) 2610 2514 ld r10,PACA_EXGEN+EX_R10(r13) 2611 2515 ld r11,PACA_EXGEN+EX_R11(r13) 2612 2516 ld r12,PACA_EXGEN+EX_R12(r13) ··· 2621 2521 GEN_COMMON denorm_exception 2622 2522 addi r3,r1,STACK_FRAME_OVERHEAD 2623 2523 bl unknown_exception 2624 - b interrupt_return 2524 + b interrupt_return_hsrr 2625 2525 2626 2526 2627 2527 #ifdef CONFIG_CBE_RAS ··· 2638 2538 GEN_COMMON cbe_maintenance 2639 2539 addi r3,r1,STACK_FRAME_OVERHEAD 2640 2540 bl cbe_maintenance_exception 2641 - b interrupt_return 2541 + b interrupt_return_hsrr 2642 2542 2643 2543 #else /* CONFIG_CBE_RAS */ 2644 2544 EXC_REAL_NONE(0x1600, 0x100) ··· 2668 2568 #else 2669 2569 bl unknown_exception 2670 2570 #endif 2671 - b interrupt_return 2571 + b interrupt_return_srr 2672 2572 2673 2573 2674 2574 #ifdef CONFIG_CBE_RAS ··· 2685 2585 GEN_COMMON cbe_thermal 2686 2586 addi r3,r1,STACK_FRAME_OVERHEAD 2687 2587 bl cbe_thermal_exception 2688 - b interrupt_return 2588 + b interrupt_return_hsrr 2689 2589 2690 2590 #else /* CONFIG_CBE_RAS */ 2691 2591 EXC_REAL_NONE(0x1800, 0x100) ··· 2710 2610 * and run it entirely with interrupts hard disabled. 2711 2611 */ 2712 2612 EXC_COMMON_BEGIN(soft_nmi_common) 2713 - mfspr r11,SPRN_SRR0 2714 2613 mr r10,r1 2715 2614 ld r1,PACAEMERGSP(r13) 2716 2615 subi r1,r1,INT_FRAME_SIZE ··· 2723 2624 mtmsrd r9,1 2724 2625 2725 2626 kuap_kernel_restore r9, r10 2627 + 2726 2628 EXCEPTION_RESTORE_REGS hsrr=0 2727 2629 RFI_TO_KERNEL 2728 2630 ··· 2745 2645 .else 2746 2646 masked_interrupt: 2747 2647 .endif 2748 - lbz r11,PACAIRQHAPPENED(r13) 2749 - or r11,r11,r10 2750 - stb r11,PACAIRQHAPPENED(r13) 2648 + stw r9,PACA_EXGEN+EX_CCR(r13) 2649 + lbz r9,PACAIRQHAPPENED(r13) 2650 + or r9,r9,r10 2651 + stb r9,PACAIRQHAPPENED(r13) 2652 + 2653 + .if ! \hsrr 2751 2654 cmpwi r10,PACA_IRQ_DEC 2752 2655 bne 1f 2753 - lis r10,0x7fff 2754 - ori r10,r10,0xffff 2755 - mtspr SPRN_DEC,r10 2656 + LOAD_REG_IMMEDIATE(r9, 0x7fffffff) 2657 + mtspr SPRN_DEC,r9 2756 2658 #ifdef CONFIG_PPC_WATCHDOG 2659 + lwz r9,PACA_EXGEN+EX_CCR(r13) 2757 2660 b soft_nmi_common 2758 2661 #else 2759 2662 b 2f 2760 2663 #endif 2664 + .endif 2665 + 2761 2666 1: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK 2762 2667 beq 2f 2763 2668 xori r12,r12,MSR_EE /* clear MSR_EE */ ··· 2771 2666 .else 2772 2667 mtspr SPRN_SRR1,r12 2773 2668 .endif 2774 - ori r11,r11,PACA_IRQ_HARD_DIS 2775 - stb r11,PACAIRQHAPPENED(r13) 2669 + ori r9,r9,PACA_IRQ_HARD_DIS 2670 + stb r9,PACAIRQHAPPENED(r13) 2776 2671 2: /* done */ 2777 - ld r10,PACA_EXGEN+EX_CTR(r13) 2778 - mtctr r10 2672 + li r9,0 2673 + .if \hsrr 2674 + stb r9,PACAHSRR_VALID(r13) 2675 + .else 2676 + stb r9,PACASRR_VALID(r13) 2677 + .endif 2678 + 2679 + SEARCH_RESTART_TABLE 2680 + cmpdi r12,0 2681 + beq 3f 2682 + .if \hsrr 2683 + mtspr SPRN_HSRR0,r12 2684 + .else 2685 + mtspr SPRN_SRR0,r12 2686 + .endif 2687 + 3: 2688 + 2689 + ld r9,PACA_EXGEN+EX_CTR(r13) 2690 + mtctr r9 2691 + lwz r9,PACA_EXGEN+EX_CCR(r13) 2779 2692 mtcrf 0x80,r9 2780 2693 std r1,PACAR1(r13) 2781 2694 ld r9,PACA_EXGEN+EX_R9(r13) ··· 3004 2881 3005 2882 USE_FIXED_SECTION(virt_trampolines) 3006 2883 /* 3007 - * All code below __end_interrupts is treated as soft-masked. If 2884 + * All code below __end_soft_masked is treated as soft-masked. If 3008 2885 * any code runs here with MSR[EE]=1, it must then cope with pending 3009 2886 * soft interrupt being raised (i.e., by ensuring it is replayed). 3010 2887 *
+6 -4
arch/powerpc/kernel/firmware.c
··· 23 23 24 24 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_KVM_GUEST) 25 25 DEFINE_STATIC_KEY_FALSE(kvm_guest); 26 - bool check_kvm_guest(void) 26 + int __init check_kvm_guest(void) 27 27 { 28 28 struct device_node *hyper_node; 29 29 30 30 hyper_node = of_find_node_by_path("/hypervisor"); 31 31 if (!hyper_node) 32 - return false; 32 + return 0; 33 33 34 34 if (!of_device_is_compatible(hyper_node, "linux,kvm")) 35 - return false; 35 + return 0; 36 36 37 37 static_branch_enable(&kvm_guest); 38 - return true; 38 + 39 + return 0; 39 40 } 41 + core_initcall(check_kvm_guest); // before kvm_guest_init() 40 42 #endif
+4
arch/powerpc/kernel/fpu.S
··· 103 103 ori r12,r12,MSR_FP 104 104 or r12,r12,r4 105 105 std r12,_MSR(r1) 106 + #ifdef CONFIG_PPC_BOOK3S_64 107 + li r4,0 108 + stb r4,PACASRR_VALID(r13) 109 + #endif 106 110 #endif 107 111 li r4,1 108 112 stb r4,THREAD_LOAD_FP(r5)
+11 -30
arch/powerpc/kernel/head_32.h
··· 142 142 143 143 .macro SYSCALL_ENTRY trapno 144 144 mfspr r9, SPRN_SRR1 145 - mfspr r10, SPRN_SRR0 145 + mfspr r12, SPRN_SRR0 146 146 LOAD_REG_IMMEDIATE(r11, MSR_KERNEL) /* can take exceptions */ 147 - lis r12, 1f@h 148 - ori r12, r12, 1f@l 147 + lis r10, 1f@h 148 + ori r10, r10, 1f@l 149 149 mtspr SPRN_SRR1, r11 150 - mtspr SPRN_SRR0, r12 151 - mfspr r12,SPRN_SPRG_THREAD 150 + mtspr SPRN_SRR0, r10 151 + mfspr r10,SPRN_SPRG_THREAD 152 152 mr r11, r1 153 - lwz r1,TASK_STACK-THREAD(r12) 154 - tovirt(r12, r12) 153 + lwz r1,TASK_STACK-THREAD(r10) 154 + tovirt(r10, r10) 155 155 addi r1, r1, THREAD_SIZE - INT_FRAME_SIZE 156 156 rfi 157 157 1: 158 - stw r11,GPR1(r1) 159 - stw r11,0(r1) 160 - mr r11, r1 161 - stw r10,_NIP(r11) 162 - mflr r10 163 - stw r10, _LINK(r11) 164 - mfcr r10 165 - rlwinm r10,r10,0,4,2 /* Clear SO bit in CR */ 166 - stw r10,_CCR(r11) /* save registers */ 167 - #ifdef CONFIG_40x 168 - rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ 169 - #endif 170 - lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */ 171 - stw r2,GPR2(r11) 172 - addi r10,r10,STACK_FRAME_REGS_MARKER@l 173 - stw r9,_MSR(r11) 174 - li r2, \trapno 175 - stw r10,8(r11) 176 - stw r2,_TRAP(r11) 177 - SAVE_GPR(0, r11) 178 - SAVE_4GPRS(3, r11) 179 - SAVE_2GPRS(7, r11) 180 - addi r2,r12,-THREAD 158 + stw r12,_NIP(r1) 159 + mfcr r12 160 + rlwinm r12,r12,0,4,2 /* Clear SO bit in CR */ 161 + stw r12,_CCR(r1) 181 162 b transfer_to_syscall /* jump to handler */ 182 163 .endm 183 164
-36
arch/powerpc/kernel/head_40x.S
··· 701 701 mfspr r13,SPRN_DBCR0 702 702 oris r13,r13,DBCR0_RST_SYSTEM@h 703 703 mtspr SPRN_DBCR0,r13 704 - 705 - _GLOBAL(set_context) 706 - 707 - #ifdef CONFIG_BDI_SWITCH 708 - /* Context switch the PTE pointer for the Abatron BDI2000. 709 - * The PGDIR is the second parameter. 710 - */ 711 - lis r5, abatron_pteptrs@ha 712 - stw r4, abatron_pteptrs@l + 0x4(r5) 713 - #endif 714 - sync 715 - mtspr SPRN_PID,r3 716 - isync /* Need an isync to flush shadow */ 717 - /* TLBs after changing PID */ 718 - blr 719 - 720 - /* We put a few things here that have to be page-aligned. This stuff 721 - * goes at the beginning of the data segment, which is page-aligned. 722 - */ 723 - .data 724 - .align 12 725 - .globl sdata 726 - sdata: 727 - .globl empty_zero_page 728 - empty_zero_page: 729 - .space 4096 730 - EXPORT_SYMBOL(empty_zero_page) 731 - .globl swapper_pg_dir 732 - swapper_pg_dir: 733 - .space PGD_TABLE_SIZE 734 - 735 - /* Room for two PTE pointers, usually the kernel and current user pointers 736 - * to their respective root page table. 737 - */ 738 - abatron_pteptrs: 739 - .space 8
+9 -41
arch/powerpc/kernel/head_44x.S
··· 532 532 andi. r10,r12,_PAGE_USER /* User page ? */ 533 533 beq 1f /* nope, leave U bits empty */ 534 534 rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ 535 + #ifdef CONFIG_PPC_KUEP 536 + 0: rlwinm r11,r11,0,~PPC44x_TLB_SX /* Clear SX if User page */ 537 + patch_site 0b, patch__tlb_44x_kuep 538 + #endif 535 539 1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */ 536 540 537 541 /* Done...restore registers and get out of here. ··· 747 743 andi. r10,r12,_PAGE_USER /* User page ? */ 748 744 beq 1f /* nope, leave U bits empty */ 749 745 rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ 746 + #ifdef CONFIG_PPC_KUEP 747 + 0: rlwinm r11,r11,0,~PPC47x_TLB2_SX /* Clear SX if User page */ 748 + patch_site 0b, patch__tlb_47x_kuep 749 + #endif 750 750 1: tlbwe r11,r13,2 751 751 752 752 /* Done...restore registers and get out of here. ··· 786 778 li r3,MachineCheckA@l 787 779 mtspr SPRN_IVOR1,r3 788 780 sync 789 - blr 790 - 791 - _GLOBAL(set_context) 792 - 793 - #ifdef CONFIG_BDI_SWITCH 794 - /* Context switch the PTE pointer for the Abatron BDI2000. 795 - * The PGDIR is the second parameter. 796 - */ 797 - lis r5, abatron_pteptrs@h 798 - ori r5, r5, abatron_pteptrs@l 799 - stw r4, 0x4(r5) 800 - #endif 801 - mtspr SPRN_PID,r3 802 - isync /* Force context change */ 803 781 blr 804 782 805 783 /* ··· 1233 1239 isync 1234 1240 blr 1235 1241 1236 - /* 1237 - * We put a few things here that have to be page-aligned. This stuff 1238 - * goes at the beginning of the data segment, which is page-aligned. 1239 - */ 1240 - .data 1241 - .align PAGE_SHIFT 1242 - .globl sdata 1243 - sdata: 1244 - .globl empty_zero_page 1245 - empty_zero_page: 1246 - .space PAGE_SIZE 1247 - EXPORT_SYMBOL(empty_zero_page) 1248 - 1249 - /* 1250 - * To support >32-bit physical addresses, we use an 8KB pgdir. 1251 - */ 1252 - .globl swapper_pg_dir 1253 - swapper_pg_dir: 1254 - .space PGD_TABLE_SIZE 1255 - 1256 - /* 1257 - * Room for two PTE pointers, usually the kernel and current user pointers 1258 - * to their respective root page table. 1259 - */ 1260 - abatron_pteptrs: 1261 - .space 8 1262 - 1263 1242 #ifdef CONFIG_SMP 1243 + .data 1264 1244 .align 12 1265 1245 temp_boot_stack: 1266 1246 .space 1024
+4 -21
arch/powerpc/kernel/head_64.S
··· 194 194 195 195 /* This value is used to mark exception frames on the stack. */ 196 196 .section ".toc","aw" 197 + /* This value is used to mark exception frames on the stack. */ 197 198 exception_marker: 198 - .tc ID_72656773_68657265[TC],0x7265677368657265 199 + .tc ID_EXC_MARKER[TC],STACK_FRAME_REGS_MARKER 199 200 .previous 200 201 201 202 /* ··· 211 210 #endif 212 211 213 212 USE_TEXT_SECTION() 213 + 214 + #include "interrupt_64.S" 214 215 215 216 #ifdef CONFIG_PPC_BOOK3E 216 217 /* ··· 1000 997 0: trap 1001 998 EMIT_BUG_ENTRY 0b, __FILE__, __LINE__, 0 1002 999 .previous 1003 - 1004 - /* 1005 - * We put a few things here that have to be page-aligned. 1006 - * This stuff goes at the beginning of the bss, which is page-aligned. 1007 - */ 1008 - .section ".bss" 1009 - /* 1010 - * pgd dir should be aligned to PGD_TABLE_SIZE which is 64K. 1011 - * We will need to find a better way to fix this 1012 - */ 1013 - .align 16 1014 - 1015 - .globl swapper_pg_dir 1016 - swapper_pg_dir: 1017 - .space PGD_TABLE_SIZE 1018 - 1019 - .globl empty_zero_page 1020 - empty_zero_page: 1021 - .space PAGE_SIZE 1022 - EXPORT_SYMBOL(empty_zero_page)
-25
arch/powerpc/kernel/head_8xx.S
··· 786 786 mtspr SPRN_SRR1, r10 787 787 mtspr SPRN_SRR0, r11 788 788 rfi 789 - 790 - /* 791 - * We put a few things here that have to be page-aligned. 792 - * This stuff goes at the beginning of the data segment, 793 - * which is page-aligned. 794 - */ 795 - .data 796 - .globl sdata 797 - sdata: 798 - .globl empty_zero_page 799 - .align PAGE_SHIFT 800 - empty_zero_page: 801 - .space PAGE_SIZE 802 - EXPORT_SYMBOL(empty_zero_page) 803 - 804 - .globl swapper_pg_dir 805 - swapper_pg_dir: 806 - .space PGD_TABLE_SIZE 807 - 808 - /* Room for two PTE table pointers, usually the kernel and current user 809 - * pointer to their respective root page table (pgdir). 810 - */ 811 - .globl abatron_pteptrs 812 - abatron_pteptrs: 813 - .space 8
+16 -123
arch/powerpc/kernel/head_book3s_32.S
··· 518 518 rlwinm r1,r1,0,~_PAGE_COHERENT /* clear M (coherence not required) */ 519 519 END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT) 520 520 mtspr SPRN_RPA,r1 521 - mfspr r2,SPRN_SRR1 /* Need to restore CR0 */ 522 - mtcrf 0x80,r2 523 521 BEGIN_MMU_FTR_SECTION 524 522 li r0,1 525 523 mfspr r1,SPRN_SPRG_603_LRU ··· 529 531 mfspr r2,SPRN_SRR1 530 532 rlwimi r2,r0,31-14,14,14 531 533 mtspr SPRN_SRR1,r2 532 - END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU) 534 + mtcrf 0x80,r2 533 535 tlbld r3 534 536 rfi 537 + MMU_FTR_SECTION_ELSE 538 + mfspr r2,SPRN_SRR1 /* Need to restore CR0 */ 539 + mtcrf 0x80,r2 540 + tlbld r3 541 + rfi 542 + ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_NEED_DTLB_SW_LRU) 535 543 DataAddressInvalid: 536 544 mfspr r3,SPRN_SRR1 537 545 rlwinm r1,r3,9,6,6 /* Get load/store bit */ ··· 611 607 mfspr r2,SPRN_SRR1 612 608 rlwimi r2,r0,31-14,14,14 613 609 mtspr SPRN_SRR1,r2 614 - END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU) 610 + mtcrf 0x80,r2 615 611 tlbld r3 616 612 rfi 613 + MMU_FTR_SECTION_ELSE 614 + mfspr r2,SPRN_SRR1 /* Need to restore CR0 */ 615 + mtcrf 0x80,r2 616 + tlbld r3 617 + rfi 618 + ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_NEED_DTLB_SW_LRU) 617 619 618 620 #ifndef CONFIG_ALTIVEC 619 621 #define altivec_assist_exception unknown_exception ··· 766 756 * the kernel image to physical address PHYSICAL_START. 767 757 */ 768 758 relocate_kernel: 769 - addis r9,r26,klimit@ha /* fetch klimit */ 770 - lwz r25,klimit@l(r9) 771 - addis r25,r25,-KERNELBASE@h 772 759 lis r3,PHYSICAL_START@h /* Destination base address */ 773 760 li r6,0 /* Destination offset */ 774 761 li r5,0x4000 /* # bytes of memory to copy */ ··· 773 766 addi r0,r3,4f@l /* jump to the address of 4f */ 774 767 mtctr r0 /* in copy and do the rest. */ 775 768 bctr /* jump to the copy */ 776 - 4: mr r5,r25 769 + 4: lis r5,_end-KERNELBASE@h 770 + ori r5,r5,_end-KERNELBASE@l 777 771 bl copy_and_flush /* copy the rest */ 778 772 b turn_on_mmu 779 773 ··· 932 924 li r0, NUM_USER_SEGMENTS /* load up user segment register values */ 933 925 mtctr r0 /* for context 0 */ 934 926 li r3, 0 /* Kp = 0, Ks = 0, VSID = 0 */ 935 - #ifdef CONFIG_PPC_KUEP 936 - oris r3, r3, SR_NX@h /* Set Nx */ 937 - #endif 938 - #ifdef CONFIG_PPC_KUAP 939 - oris r3, r3, SR_KS@h /* Set Ks */ 940 - #endif 941 927 li r4, 0 942 928 3: mtsrin r3, r4 943 929 addi r3, r3, 0x111 /* increment VSID */ ··· 1024 1022 mtspr SPRN_SRR0,r3 1025 1023 mtspr SPRN_SRR1,r4 1026 1024 rfi 1027 - 1028 - /* 1029 - * void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next); 1030 - * 1031 - * Set up the segment registers for a new context. 1032 - */ 1033 - _ENTRY(switch_mmu_context) 1034 - lwz r3,MMCONTEXTID(r4) 1035 - cmpwi cr0,r3,0 1036 - blt- 4f 1037 - mulli r3,r3,897 /* multiply context by skew factor */ 1038 - rlwinm r3,r3,4,8,27 /* VSID = (context & 0xfffff) << 4 */ 1039 - #ifdef CONFIG_PPC_KUEP 1040 - oris r3, r3, SR_NX@h /* Set Nx */ 1041 - #endif 1042 - #ifdef CONFIG_PPC_KUAP 1043 - oris r3, r3, SR_KS@h /* Set Ks */ 1044 - #endif 1045 - li r0,NUM_USER_SEGMENTS 1046 - mtctr r0 1047 - 1048 - #ifdef CONFIG_BDI_SWITCH 1049 - /* Context switch the PTE pointer for the Abatron BDI2000. 1050 - * The PGDIR is passed as second argument. 1051 - */ 1052 - lwz r4, MM_PGD(r4) 1053 - lis r5, abatron_pteptrs@ha 1054 - stw r4, abatron_pteptrs@l + 0x4(r5) 1055 - #endif 1056 - BEGIN_MMU_FTR_SECTION 1057 - #ifndef CONFIG_BDI_SWITCH 1058 - lwz r4, MM_PGD(r4) 1059 - #endif 1060 - tophys(r4, r4) 1061 - rlwinm r4, r4, 4, 0xffff01ff 1062 - mtspr SPRN_SDR1, r4 1063 - END_MMU_FTR_SECTION_IFCLR(MMU_FTR_HPTE_TABLE) 1064 - li r4,0 1065 - isync 1066 - 3: 1067 - mtsrin r3,r4 1068 - addi r3,r3,0x111 /* next VSID */ 1069 - rlwinm r3,r3,0,8,3 /* clear out any overflow from VSID field */ 1070 - addis r4,r4,0x1000 /* address of next segment */ 1071 - bdnz 3b 1072 - sync 1073 - isync 1074 - blr 1075 - 4: trap 1076 - EMIT_BUG_ENTRY 4b,__FILE__,__LINE__,0 1077 - blr 1078 - EXPORT_SYMBOL(switch_mmu_context) 1079 1025 1080 1026 /* 1081 1027 * An undocumented "feature" of 604e requires that the v bit ··· 1206 1256 blr 1207 1257 #endif 1208 1258 1209 - #ifdef CONFIG_8260 1210 - /* Jump into the system reset for the rom. 1211 - * We first disable the MMU, and then jump to the ROM reset address. 1212 - * 1213 - * r3 is the board info structure, r4 is the location for starting. 1214 - * I use this for building a small kernel that can load other kernels, 1215 - * rather than trying to write or rely on a rom monitor that can tftp load. 1216 - */ 1217 - .globl m8260_gorom 1218 - m8260_gorom: 1219 - mfmsr r0 1220 - rlwinm r0,r0,0,17,15 /* clear MSR_EE in r0 */ 1221 - sync 1222 - mtmsr r0 1223 - sync 1224 - mfspr r11, SPRN_HID0 1225 - lis r10, 0 1226 - ori r10,r10,HID0_ICE|HID0_DCE 1227 - andc r11, r11, r10 1228 - mtspr SPRN_HID0, r11 1229 - isync 1230 - li r5, MSR_ME|MSR_RI 1231 - lis r6,2f@h 1232 - addis r6,r6,-KERNELBASE@h 1233 - ori r6,r6,2f@l 1234 - mtspr SPRN_SRR0,r6 1235 - mtspr SPRN_SRR1,r5 1236 - isync 1237 - sync 1238 - rfi 1239 - 2: 1240 - mtlr r4 1241 - blr 1242 - #endif 1243 - 1244 - 1245 - /* 1246 - * We put a few things here that have to be page-aligned. 1247 - * This stuff goes at the beginning of the data segment, 1248 - * which is page-aligned. 1249 - */ 1250 1259 .data 1251 - .globl sdata 1252 - sdata: 1253 - .globl empty_zero_page 1254 - empty_zero_page: 1255 - .space 4096 1256 - EXPORT_SYMBOL(empty_zero_page) 1257 - 1258 - .globl swapper_pg_dir 1259 - swapper_pg_dir: 1260 - .space PGD_TABLE_SIZE 1261 - 1262 - /* Room for two PTE pointers, usually the kernel and current user pointers 1263 - * to their respective root page table. 1264 - */ 1265 - abatron_pteptrs: 1266 - .space 8
+7 -24
arch/powerpc/kernel/head_booke.h
··· 128 128 mr r12, r13 129 129 lwz r13, THREAD_NORMSAVE(2)(r10) 130 130 FTR_SECTION_ELSE 131 - #endif 132 131 mfcr r12 133 - #ifdef CONFIG_KVM_BOOKE_HV 134 132 ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV) 133 + #else 134 + mfcr r12 135 135 #endif 136 136 mfspr r9, SPRN_SRR1 137 137 BOOKE_CLEAR_BTB(r11) 138 - lwz r11, TASK_STACK - THREAD(r10) 138 + mr r11, r1 139 + lwz r1, TASK_STACK - THREAD(r10) 139 140 rlwinm r12,r12,0,4,2 /* Clear SO bit in CR */ 140 - ALLOC_STACK_FRAME(r11, THREAD_SIZE - INT_FRAME_SIZE) 141 - stw r12, _CCR(r11) /* save various registers */ 142 - mflr r12 143 - stw r12,_LINK(r11) 141 + ALLOC_STACK_FRAME(r1, THREAD_SIZE - INT_FRAME_SIZE) 142 + stw r12, _CCR(r1) 144 143 mfspr r12,SPRN_SRR0 145 - stw r1, GPR1(r11) 146 - stw r1, 0(r11) 147 - mr r1, r11 148 - stw r12,_NIP(r11) 149 - rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ 150 - lis r12, STACK_FRAME_REGS_MARKER@ha /* exception frame marker */ 151 - stw r2,GPR2(r11) 152 - addi r12, r12, STACK_FRAME_REGS_MARKER@l 153 - stw r9,_MSR(r11) 154 - li r2, \trapno 155 - stw r12, 8(r11) 156 - stw r2,_TRAP(r11) 157 - SAVE_GPR(0, r11) 158 - SAVE_4GPRS(3, r11) 159 - SAVE_2GPRS(7, r11) 160 - 161 - addi r2,r10,-THREAD 144 + stw r12,_NIP(r1) 162 145 b transfer_to_syscall /* jump to handler */ 163 146 .endm 164 147
-37
arch/powerpc/kernel/head_fsl_booke.S
··· 985 985 mtspr SPRN_DBCR0,r13 986 986 isync 987 987 988 - _GLOBAL(set_context) 989 - 990 - #ifdef CONFIG_BDI_SWITCH 991 - /* Context switch the PTE pointer for the Abatron BDI2000. 992 - * The PGDIR is the second parameter. 993 - */ 994 - lis r5, abatron_pteptrs@h 995 - ori r5, r5, abatron_pteptrs@l 996 - stw r4, 0x4(r5) 997 - #endif 998 - mtspr SPRN_PID,r3 999 - isync /* Force context change */ 1000 - blr 1001 - 1002 988 #ifdef CONFIG_SMP 1003 989 /* When we get here, r24 needs to hold the CPU # */ 1004 990 .globl __secondary_start ··· 1212 1226 */ 1213 1227 3: mr r3,r5 1214 1228 bl _start 1215 - 1216 - /* 1217 - * We put a few things here that have to be page-aligned. This stuff 1218 - * goes at the beginning of the data segment, which is page-aligned. 1219 - */ 1220 - .data 1221 - .align 12 1222 - .globl sdata 1223 - sdata: 1224 - .globl empty_zero_page 1225 - empty_zero_page: 1226 - .space 4096 1227 - EXPORT_SYMBOL(empty_zero_page) 1228 - .globl swapper_pg_dir 1229 - swapper_pg_dir: 1230 - .space PGD_TABLE_SIZE 1231 - 1232 - /* 1233 - * Room for two PTE pointers, usually the kernel and current user pointers 1234 - * to their respective root page table. 1235 - */ 1236 - abatron_pteptrs: 1237 - .space 8
+2 -2
arch/powerpc/kernel/hw_breakpoint.c
··· 486 486 return; 487 487 488 488 reset: 489 - regs->msr &= ~MSR_SE; 489 + regs_set_return_msr(regs, regs->msr & ~MSR_SE); 490 490 for (i = 0; i < nr_wp_slots(); i++) { 491 491 info = counter_arch_bp(__this_cpu_read(bp_per_reg[i])); 492 492 __set_breakpoint(i, info); ··· 537 537 current->thread.last_hit_ubp[i] = bp[i]; 538 538 info[i] = NULL; 539 539 } 540 - regs->msr |= MSR_SE; 540 + regs_set_return_msr(regs, regs->msr | MSR_SE); 541 541 return false; 542 542 } 543 543
+334 -196
arch/powerpc/kernel/interrupt.c
··· 3 3 #include <linux/context_tracking.h> 4 4 #include <linux/err.h> 5 5 #include <linux/compat.h> 6 + #include <linux/sched/debug.h> /* for show_regs */ 6 7 7 8 #include <asm/asm-prototypes.h> 8 9 #include <asm/kup.h> ··· 26 25 #endif 27 26 28 27 typedef long (*syscall_fn)(long, long, long, long, long, long); 28 + 29 + #ifdef CONFIG_PPC_BOOK3S_64 30 + DEFINE_STATIC_KEY_FALSE(interrupt_exit_not_reentrant); 31 + static inline bool exit_must_hard_disable(void) 32 + { 33 + return static_branch_unlikely(&interrupt_exit_not_reentrant); 34 + } 35 + #else 36 + static inline bool exit_must_hard_disable(void) 37 + { 38 + return true; 39 + } 40 + #endif 41 + 42 + /* 43 + * local irqs must be disabled. Returns false if the caller must re-enable 44 + * them, check for new work, and try again. 45 + * 46 + * This should be called with local irqs disabled, but if they were previously 47 + * enabled when the interrupt handler returns (indicating a process-context / 48 + * synchronous interrupt) then irqs_enabled should be true. 49 + * 50 + * restartable is true then EE/RI can be left on because interrupts are handled 51 + * with a restart sequence. 52 + */ 53 + static notrace __always_inline bool prep_irq_for_enabled_exit(bool restartable) 54 + { 55 + /* This must be done with RI=1 because tracing may touch vmaps */ 56 + trace_hardirqs_on(); 57 + 58 + if (exit_must_hard_disable() || !restartable) 59 + __hard_EE_RI_disable(); 60 + 61 + #ifdef CONFIG_PPC64 62 + /* This pattern matches prep_irq_for_idle */ 63 + if (unlikely(lazy_irq_pending_nocheck())) { 64 + if (exit_must_hard_disable() || !restartable) { 65 + local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 66 + __hard_RI_enable(); 67 + } 68 + trace_hardirqs_off(); 69 + 70 + return false; 71 + } 72 + #endif 73 + return true; 74 + } 29 75 30 76 /* Has to run notrace because it is entered not completely "reconciled" */ 31 77 notrace long system_call_exception(long r3, long r4, long r5, ··· 192 144 return f(r3, r4, r5, r6, r7, r8); 193 145 } 194 146 195 - /* 196 - * local irqs must be disabled. Returns false if the caller must re-enable 197 - * them, check for new work, and try again. 198 - * 199 - * This should be called with local irqs disabled, but if they were previously 200 - * enabled when the interrupt handler returns (indicating a process-context / 201 - * synchronous interrupt) then irqs_enabled should be true. 202 - */ 203 - static notrace __always_inline bool __prep_irq_for_enabled_exit(bool clear_ri) 204 - { 205 - /* This must be done with RI=1 because tracing may touch vmaps */ 206 - trace_hardirqs_on(); 207 - 208 - /* This pattern matches prep_irq_for_idle */ 209 - if (clear_ri) 210 - __hard_EE_RI_disable(); 211 - else 212 - __hard_irq_disable(); 213 - #ifdef CONFIG_PPC64 214 - if (unlikely(lazy_irq_pending_nocheck())) { 215 - /* Took an interrupt, may have more exit work to do. */ 216 - if (clear_ri) 217 - __hard_RI_enable(); 218 - trace_hardirqs_off(); 219 - local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 220 - 221 - return false; 222 - } 223 - local_paca->irq_happened = 0; 224 - irq_soft_mask_set(IRQS_ENABLED); 225 - #endif 226 - return true; 227 - } 228 - 229 - static notrace inline bool prep_irq_for_enabled_exit(bool clear_ri, bool irqs_enabled) 230 - { 231 - if (__prep_irq_for_enabled_exit(clear_ri)) 232 - return true; 233 - 234 - /* 235 - * Must replay pending soft-masked interrupts now. Don't just 236 - * local_irq_enabe(); local_irq_disable(); because if we are 237 - * returning from an asynchronous interrupt here, another one 238 - * might hit after irqs are enabled, and it would exit via this 239 - * same path allowing another to fire, and so on unbounded. 240 - * 241 - * If interrupts were enabled when this interrupt exited, 242 - * indicating a process context (synchronous) interrupt, 243 - * local_irq_enable/disable can be used, which will enable 244 - * interrupts rather than keeping them masked (unclear how 245 - * much benefit this is over just replaying for all cases, 246 - * because we immediately disable again, so all we're really 247 - * doing is allowing hard interrupts to execute directly for 248 - * a very small time, rather than being masked and replayed). 249 - */ 250 - if (irqs_enabled) { 251 - local_irq_enable(); 252 - local_irq_disable(); 253 - } else { 254 - replay_soft_interrupts(); 255 - } 256 - 257 - return false; 258 - } 259 - 260 147 static notrace void booke_load_dbcr0(void) 261 148 { 262 149 #ifdef CONFIG_PPC_ADV_DEBUG_REGS ··· 212 229 mtspr(SPRN_DBCR0, dbcr0); 213 230 mtspr(SPRN_DBSR, -1); 214 231 #endif 232 + } 233 + 234 + static void check_return_regs_valid(struct pt_regs *regs) 235 + { 236 + #ifdef CONFIG_PPC_BOOK3S_64 237 + unsigned long trap, srr0, srr1; 238 + static bool warned; 239 + u8 *validp; 240 + char *h; 241 + 242 + if (trap_is_scv(regs)) 243 + return; 244 + 245 + trap = regs->trap; 246 + // EE in HV mode sets HSRRs like 0xea0 247 + if (cpu_has_feature(CPU_FTR_HVMODE) && trap == INTERRUPT_EXTERNAL) 248 + trap = 0xea0; 249 + 250 + switch (trap) { 251 + case 0x980: 252 + case INTERRUPT_H_DATA_STORAGE: 253 + case 0xe20: 254 + case 0xe40: 255 + case INTERRUPT_HMI: 256 + case 0xe80: 257 + case 0xea0: 258 + case INTERRUPT_H_FAC_UNAVAIL: 259 + case 0x1200: 260 + case 0x1500: 261 + case 0x1600: 262 + case 0x1800: 263 + validp = &local_paca->hsrr_valid; 264 + if (!*validp) 265 + return; 266 + 267 + srr0 = mfspr(SPRN_HSRR0); 268 + srr1 = mfspr(SPRN_HSRR1); 269 + h = "H"; 270 + 271 + break; 272 + default: 273 + validp = &local_paca->srr_valid; 274 + if (!*validp) 275 + return; 276 + 277 + srr0 = mfspr(SPRN_SRR0); 278 + srr1 = mfspr(SPRN_SRR1); 279 + h = ""; 280 + break; 281 + } 282 + 283 + if (srr0 == regs->nip && srr1 == regs->msr) 284 + return; 285 + 286 + /* 287 + * A NMI / soft-NMI interrupt may have come in after we found 288 + * srr_valid and before the SRRs are loaded. The interrupt then 289 + * comes in and clobbers SRRs and clears srr_valid. Then we load 290 + * the SRRs here and test them above and find they don't match. 291 + * 292 + * Test validity again after that, to catch such false positives. 293 + * 294 + * This test in general will have some window for false negatives 295 + * and may not catch and fix all such cases if an NMI comes in 296 + * later and clobbers SRRs without clearing srr_valid, but hopefully 297 + * such things will get caught most of the time, statistically 298 + * enough to be able to get a warning out. 299 + */ 300 + barrier(); 301 + 302 + if (!*validp) 303 + return; 304 + 305 + if (!warned) { 306 + warned = true; 307 + printk("%sSRR0 was: %lx should be: %lx\n", h, srr0, regs->nip); 308 + printk("%sSRR1 was: %lx should be: %lx\n", h, srr1, regs->msr); 309 + show_regs(regs); 310 + } 311 + 312 + *validp = 0; /* fixup */ 313 + #endif 314 + } 315 + 316 + static notrace unsigned long 317 + interrupt_exit_user_prepare_main(unsigned long ret, struct pt_regs *regs) 318 + { 319 + unsigned long ti_flags; 320 + 321 + again: 322 + ti_flags = READ_ONCE(current_thread_info()->flags); 323 + while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) { 324 + local_irq_enable(); 325 + if (ti_flags & _TIF_NEED_RESCHED) { 326 + schedule(); 327 + } else { 328 + /* 329 + * SIGPENDING must restore signal handler function 330 + * argument GPRs, and some non-volatiles (e.g., r1). 331 + * Restore all for now. This could be made lighter. 332 + */ 333 + if (ti_flags & _TIF_SIGPENDING) 334 + ret |= _TIF_RESTOREALL; 335 + do_notify_resume(regs, ti_flags); 336 + } 337 + local_irq_disable(); 338 + ti_flags = READ_ONCE(current_thread_info()->flags); 339 + } 340 + 341 + if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) { 342 + if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) && 343 + unlikely((ti_flags & _TIF_RESTORE_TM))) { 344 + restore_tm_state(regs); 345 + } else { 346 + unsigned long mathflags = MSR_FP; 347 + 348 + if (cpu_has_feature(CPU_FTR_VSX)) 349 + mathflags |= MSR_VEC | MSR_VSX; 350 + else if (cpu_has_feature(CPU_FTR_ALTIVEC)) 351 + mathflags |= MSR_VEC; 352 + 353 + /* 354 + * If userspace MSR has all available FP bits set, 355 + * then they are live and no need to restore. If not, 356 + * it means the regs were given up and restore_math 357 + * may decide to restore them (to avoid taking an FP 358 + * fault). 359 + */ 360 + if ((regs->msr & mathflags) != mathflags) 361 + restore_math(regs); 362 + } 363 + } 364 + 365 + check_return_regs_valid(regs); 366 + 367 + user_enter_irqoff(); 368 + if (!prep_irq_for_enabled_exit(true)) { 369 + user_exit_irqoff(); 370 + local_irq_enable(); 371 + local_irq_disable(); 372 + goto again; 373 + } 374 + 375 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 376 + local_paca->tm_scratch = regs->msr; 377 + #endif 378 + 379 + booke_load_dbcr0(); 380 + 381 + account_cpu_user_exit(); 382 + 383 + /* Restore user access locks last */ 384 + kuap_user_restore(regs); 385 + kuep_unlock(); 386 + 387 + return ret; 215 388 } 216 389 217 390 /* ··· 421 282 } 422 283 423 284 local_irq_disable(); 285 + ret = interrupt_exit_user_prepare_main(ret, regs); 424 286 425 - again: 426 - ti_flags = READ_ONCE(current_thread_info()->flags); 427 - while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) { 428 - local_irq_enable(); 429 - if (ti_flags & _TIF_NEED_RESCHED) { 430 - schedule(); 431 - } else { 432 - /* 433 - * SIGPENDING must restore signal handler function 434 - * argument GPRs, and some non-volatiles (e.g., r1). 435 - * Restore all for now. This could be made lighter. 436 - */ 437 - if (ti_flags & _TIF_SIGPENDING) 438 - ret |= _TIF_RESTOREALL; 439 - do_notify_resume(regs, ti_flags); 440 - } 441 - local_irq_disable(); 442 - ti_flags = READ_ONCE(current_thread_info()->flags); 443 - } 444 - 445 - if (IS_ENABLED(CONFIG_PPC_BOOK3S) && IS_ENABLED(CONFIG_PPC_FPU)) { 446 - if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) && 447 - unlikely((ti_flags & _TIF_RESTORE_TM))) { 448 - restore_tm_state(regs); 449 - } else { 450 - unsigned long mathflags = MSR_FP; 451 - 452 - if (cpu_has_feature(CPU_FTR_VSX)) 453 - mathflags |= MSR_VEC | MSR_VSX; 454 - else if (cpu_has_feature(CPU_FTR_ALTIVEC)) 455 - mathflags |= MSR_VEC; 456 - 457 - /* 458 - * If userspace MSR has all available FP bits set, 459 - * then they are live and no need to restore. If not, 460 - * it means the regs were given up and restore_math 461 - * may decide to restore them (to avoid taking an FP 462 - * fault). 463 - */ 464 - if ((regs->msr & mathflags) != mathflags) 465 - restore_math(regs); 466 - } 467 - } 468 - 469 - user_enter_irqoff(); 470 - 471 - /* scv need not set RI=0 because SRRs are not used */ 472 - if (unlikely(!__prep_irq_for_enabled_exit(is_not_scv))) { 473 - user_exit_irqoff(); 474 - local_irq_enable(); 475 - local_irq_disable(); 476 - goto again; 477 - } 478 - 479 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 480 - local_paca->tm_scratch = regs->msr; 287 + #ifdef CONFIG_PPC64 288 + regs->exit_result = ret; 481 289 #endif 482 - 483 - booke_load_dbcr0(); 484 - 485 - account_cpu_user_exit(); 486 - 487 - /* Restore user access locks last */ 488 - kuap_user_restore(regs); 489 - kuep_unlock(); 490 290 491 291 return ret; 492 292 } 493 293 494 - notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long msr) 294 + #ifdef CONFIG_PPC64 295 + notrace unsigned long syscall_exit_restart(unsigned long r3, struct pt_regs *regs) 495 296 { 496 - unsigned long ti_flags; 497 - unsigned long flags; 498 - unsigned long ret = 0; 297 + /* 298 + * This is called when detecting a soft-pending interrupt as well as 299 + * an alternate-return interrupt. So we can't just have the alternate 300 + * return path clear SRR1[MSR] and set PACA_IRQ_HARD_DIS (unless 301 + * the soft-pending case were to fix things up as well). RI might be 302 + * disabled, in which case it gets re-enabled by __hard_irq_disable(). 303 + */ 304 + __hard_irq_disable(); 305 + local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 306 + 307 + #ifdef CONFIG_PPC_BOOK3S_64 308 + set_kuap(AMR_KUAP_BLOCKED); 309 + #endif 310 + 311 + trace_hardirqs_off(); 312 + user_exit_irqoff(); 313 + account_cpu_user_entry(); 314 + 315 + BUG_ON(!user_mode(regs)); 316 + 317 + regs->exit_result = interrupt_exit_user_prepare_main(regs->exit_result, regs); 318 + 319 + return regs->exit_result; 320 + } 321 + #endif 322 + 323 + notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs) 324 + { 325 + unsigned long ret; 499 326 500 327 if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x)) 501 328 BUG_ON(!(regs->msr & MSR_RI)); ··· 475 370 */ 476 371 kuap_assert_locked(); 477 372 478 - local_irq_save(flags); 373 + local_irq_disable(); 479 374 480 - again: 481 - ti_flags = READ_ONCE(current_thread_info()->flags); 482 - while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) { 483 - local_irq_enable(); /* returning to user: may enable */ 484 - if (ti_flags & _TIF_NEED_RESCHED) { 485 - schedule(); 486 - } else { 487 - if (ti_flags & _TIF_SIGPENDING) 488 - ret |= _TIF_RESTOREALL; 489 - do_notify_resume(regs, ti_flags); 490 - } 491 - local_irq_disable(); 492 - ti_flags = READ_ONCE(current_thread_info()->flags); 493 - } 375 + ret = interrupt_exit_user_prepare_main(0, regs); 494 376 495 - if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) { 496 - if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) && 497 - unlikely((ti_flags & _TIF_RESTORE_TM))) { 498 - restore_tm_state(regs); 499 - } else { 500 - unsigned long mathflags = MSR_FP; 501 - 502 - if (cpu_has_feature(CPU_FTR_VSX)) 503 - mathflags |= MSR_VEC | MSR_VSX; 504 - else if (cpu_has_feature(CPU_FTR_ALTIVEC)) 505 - mathflags |= MSR_VEC; 506 - 507 - /* See above restore_math comment */ 508 - if ((regs->msr & mathflags) != mathflags) 509 - restore_math(regs); 510 - } 511 - } 512 - 513 - user_enter_irqoff(); 514 - 515 - if (unlikely(!__prep_irq_for_enabled_exit(true))) { 516 - user_exit_irqoff(); 517 - local_irq_enable(); 518 - local_irq_disable(); 519 - goto again; 520 - } 521 - 522 - booke_load_dbcr0(); 523 - 524 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 525 - local_paca->tm_scratch = regs->msr; 377 + #ifdef CONFIG_PPC64 378 + regs->exit_result = ret; 526 379 #endif 527 - 528 - account_cpu_user_exit(); 529 - 530 - /* Restore user access locks last */ 531 - kuap_user_restore(regs); 532 - kuep_unlock(); 533 380 534 381 return ret; 535 382 } 536 383 537 384 void preempt_schedule_irq(void); 538 385 539 - notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsigned long msr) 386 + notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs) 540 387 { 541 388 unsigned long flags; 542 389 unsigned long ret = 0; 543 390 unsigned long kuap; 391 + bool stack_store = current_thread_info()->flags & 392 + _TIF_EMULATE_STACK_STORE; 544 393 545 394 if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x) && 546 395 unlikely(!(regs->msr & MSR_RI))) ··· 508 449 CT_WARN_ON(ct_state() == CONTEXT_USER); 509 450 510 451 kuap = kuap_get_and_assert_locked(); 511 - 512 - if (unlikely(current_thread_info()->flags & _TIF_EMULATE_STACK_STORE)) { 513 - clear_bits(_TIF_EMULATE_STACK_STORE, &current_thread_info()->flags); 514 - ret = 1; 515 - } 516 452 517 453 local_irq_save(flags); 518 454 ··· 523 469 } 524 470 } 525 471 526 - if (unlikely(!prep_irq_for_enabled_exit(true, !irqs_disabled_flags(flags)))) 472 + check_return_regs_valid(regs); 473 + 474 + /* 475 + * Stack store exit can't be restarted because the interrupt 476 + * stack frame might have been clobbered. 477 + */ 478 + if (!prep_irq_for_enabled_exit(unlikely(stack_store))) { 479 + /* 480 + * Replay pending soft-masked interrupts now. Don't 481 + * just local_irq_enabe(); local_irq_disable(); because 482 + * if we are returning from an asynchronous interrupt 483 + * here, another one might hit after irqs are enabled, 484 + * and it would exit via this same path allowing 485 + * another to fire, and so on unbounded. 486 + */ 487 + hard_irq_disable(); 488 + replay_soft_interrupts(); 489 + /* Took an interrupt, may have more exit work to do. */ 527 490 goto again; 528 - } else { 529 - /* Returning to a kernel context with local irqs disabled. */ 530 - __hard_EE_RI_disable(); 491 + } 531 492 #ifdef CONFIG_PPC64 493 + /* 494 + * An interrupt may clear MSR[EE] and set this concurrently, 495 + * but it will be marked pending and the exit will be retried. 496 + * This leaves a racy window where MSR[EE]=0 and HARD_DIS is 497 + * clear, until interrupt_exit_kernel_restart() calls 498 + * hard_irq_disable(), which will set HARD_DIS again. 499 + */ 500 + local_paca->irq_happened &= ~PACA_IRQ_HARD_DIS; 501 + 502 + } else { 503 + check_return_regs_valid(regs); 504 + 505 + if (unlikely(stack_store)) 506 + __hard_EE_RI_disable(); 507 + /* 508 + * Returning to a kernel context with local irqs disabled. 509 + * Here, if EE was enabled in the interrupted context, enable 510 + * it on return as well. A problem exists here where a soft 511 + * masked interrupt may have cleared MSR[EE] and set HARD_DIS 512 + * here, and it will still exist on return to the caller. This 513 + * will be resolved by the masked interrupt firing again. 514 + */ 532 515 if (regs->msr & MSR_EE) 533 516 local_paca->irq_happened &= ~PACA_IRQ_HARD_DIS; 534 - #endif 517 + #endif /* CONFIG_PPC64 */ 535 518 } 536 519 520 + if (unlikely(stack_store)) { 521 + clear_bits(_TIF_EMULATE_STACK_STORE, &current_thread_info()->flags); 522 + ret = 1; 523 + } 537 524 538 525 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 539 526 local_paca->tm_scratch = regs->msr; ··· 589 494 590 495 return ret; 591 496 } 497 + 498 + #ifdef CONFIG_PPC64 499 + notrace unsigned long interrupt_exit_user_restart(struct pt_regs *regs) 500 + { 501 + __hard_irq_disable(); 502 + local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 503 + 504 + #ifdef CONFIG_PPC_BOOK3S_64 505 + set_kuap(AMR_KUAP_BLOCKED); 506 + #endif 507 + 508 + trace_hardirqs_off(); 509 + user_exit_irqoff(); 510 + account_cpu_user_entry(); 511 + 512 + BUG_ON(!user_mode(regs)); 513 + 514 + regs->exit_result |= interrupt_exit_user_prepare(regs); 515 + 516 + return regs->exit_result; 517 + } 518 + 519 + /* 520 + * No real need to return a value here because the stack store case does not 521 + * get restarted. 522 + */ 523 + notrace unsigned long interrupt_exit_kernel_restart(struct pt_regs *regs) 524 + { 525 + __hard_irq_disable(); 526 + local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 527 + 528 + #ifdef CONFIG_PPC_BOOK3S_64 529 + set_kuap(AMR_KUAP_BLOCKED); 530 + #endif 531 + 532 + if (regs->softe == IRQS_ENABLED) 533 + trace_hardirqs_off(); 534 + 535 + BUG_ON(user_mode(regs)); 536 + 537 + return interrupt_exit_kernel_prepare(regs); 538 + } 539 + #endif
+770
arch/powerpc/kernel/interrupt_64.S
··· 1 + #include <asm/asm-offsets.h> 2 + #include <asm/bug.h> 3 + #ifdef CONFIG_PPC_BOOK3S 4 + #include <asm/exception-64s.h> 5 + #else 6 + #include <asm/exception-64e.h> 7 + #endif 8 + #include <asm/feature-fixups.h> 9 + #include <asm/head-64.h> 10 + #include <asm/hw_irq.h> 11 + #include <asm/kup.h> 12 + #include <asm/mmu.h> 13 + #include <asm/ppc_asm.h> 14 + #include <asm/ptrace.h> 15 + #include <asm/tm.h> 16 + 17 + .section ".toc","aw" 18 + SYS_CALL_TABLE: 19 + .tc sys_call_table[TC],sys_call_table 20 + 21 + #ifdef CONFIG_COMPAT 22 + COMPAT_SYS_CALL_TABLE: 23 + .tc compat_sys_call_table[TC],compat_sys_call_table 24 + #endif 25 + .previous 26 + 27 + .align 7 28 + 29 + .macro DEBUG_SRR_VALID srr 30 + #ifdef CONFIG_PPC_RFI_SRR_DEBUG 31 + .ifc \srr,srr 32 + mfspr r11,SPRN_SRR0 33 + ld r12,_NIP(r1) 34 + 100: tdne r11,r12 35 + EMIT_BUG_ENTRY 100b,__FILE__,__LINE__,(BUGFLAG_WARNING | BUGFLAG_ONCE) 36 + mfspr r11,SPRN_SRR1 37 + ld r12,_MSR(r1) 38 + 100: tdne r11,r12 39 + EMIT_BUG_ENTRY 100b,__FILE__,__LINE__,(BUGFLAG_WARNING | BUGFLAG_ONCE) 40 + .else 41 + mfspr r11,SPRN_HSRR0 42 + ld r12,_NIP(r1) 43 + 100: tdne r11,r12 44 + EMIT_BUG_ENTRY 100b,__FILE__,__LINE__,(BUGFLAG_WARNING | BUGFLAG_ONCE) 45 + mfspr r11,SPRN_HSRR1 46 + ld r12,_MSR(r1) 47 + 100: tdne r11,r12 48 + EMIT_BUG_ENTRY 100b,__FILE__,__LINE__,(BUGFLAG_WARNING | BUGFLAG_ONCE) 49 + .endif 50 + #endif 51 + .endm 52 + 53 + #ifdef CONFIG_PPC_BOOK3S 54 + .macro system_call_vectored name trapnr 55 + .globl system_call_vectored_\name 56 + system_call_vectored_\name: 57 + _ASM_NOKPROBE_SYMBOL(system_call_vectored_\name) 58 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 59 + BEGIN_FTR_SECTION 60 + extrdi. r10, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */ 61 + bne tabort_syscall 62 + END_FTR_SECTION_IFSET(CPU_FTR_TM) 63 + #endif 64 + SCV_INTERRUPT_TO_KERNEL 65 + mr r10,r1 66 + ld r1,PACAKSAVE(r13) 67 + std r10,0(r1) 68 + std r11,_NIP(r1) 69 + std r12,_MSR(r1) 70 + std r0,GPR0(r1) 71 + std r10,GPR1(r1) 72 + std r2,GPR2(r1) 73 + ld r2,PACATOC(r13) 74 + mfcr r12 75 + li r11,0 76 + /* Can we avoid saving r3-r8 in common case? */ 77 + std r3,GPR3(r1) 78 + std r4,GPR4(r1) 79 + std r5,GPR5(r1) 80 + std r6,GPR6(r1) 81 + std r7,GPR7(r1) 82 + std r8,GPR8(r1) 83 + /* Zero r9-r12, this should only be required when restoring all GPRs */ 84 + std r11,GPR9(r1) 85 + std r11,GPR10(r1) 86 + std r11,GPR11(r1) 87 + std r11,GPR12(r1) 88 + std r9,GPR13(r1) 89 + SAVE_NVGPRS(r1) 90 + std r11,_XER(r1) 91 + std r11,_LINK(r1) 92 + std r11,_CTR(r1) 93 + 94 + li r11,\trapnr 95 + std r11,_TRAP(r1) 96 + std r12,_CCR(r1) 97 + addi r10,r1,STACK_FRAME_OVERHEAD 98 + ld r11,exception_marker@toc(r2) 99 + std r11,-16(r10) /* "regshere" marker */ 100 + 101 + BEGIN_FTR_SECTION 102 + HMT_MEDIUM 103 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 104 + 105 + /* 106 + * scv enters with MSR[EE]=1 and is immediately considered soft-masked. 107 + * The entry vector already sets PACAIRQSOFTMASK to IRQS_ALL_DISABLED, 108 + * and interrupts may be masked and pending already. 109 + * system_call_exception() will call trace_hardirqs_off() which means 110 + * interrupts could already have been blocked before trace_hardirqs_off, 111 + * but this is the best we can do. 112 + */ 113 + 114 + /* Calling convention has r9 = orig r0, r10 = regs */ 115 + mr r9,r0 116 + bl system_call_exception 117 + 118 + .Lsyscall_vectored_\name\()_exit: 119 + addi r4,r1,STACK_FRAME_OVERHEAD 120 + li r5,1 /* scv */ 121 + bl syscall_exit_prepare 122 + std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */ 123 + .Lsyscall_vectored_\name\()_rst_start: 124 + lbz r11,PACAIRQHAPPENED(r13) 125 + andi. r11,r11,(~PACA_IRQ_HARD_DIS)@l 126 + bne- syscall_vectored_\name\()_restart 127 + li r11,IRQS_ENABLED 128 + stb r11,PACAIRQSOFTMASK(r13) 129 + li r11,0 130 + stb r11,PACAIRQHAPPENED(r13) # clear out possible HARD_DIS 131 + 132 + ld r2,_CCR(r1) 133 + ld r4,_NIP(r1) 134 + ld r5,_MSR(r1) 135 + 136 + BEGIN_FTR_SECTION 137 + stdcx. r0,0,r1 /* to clear the reservation */ 138 + END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 139 + 140 + BEGIN_FTR_SECTION 141 + HMT_MEDIUM_LOW 142 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 143 + 144 + cmpdi r3,0 145 + bne .Lsyscall_vectored_\name\()_restore_regs 146 + 147 + /* rfscv returns with LR->NIA and CTR->MSR */ 148 + mtlr r4 149 + mtctr r5 150 + 151 + /* Could zero these as per ABI, but we may consider a stricter ABI 152 + * which preserves these if libc implementations can benefit, so 153 + * restore them for now until further measurement is done. */ 154 + ld r0,GPR0(r1) 155 + ld r4,GPR4(r1) 156 + ld r5,GPR5(r1) 157 + ld r6,GPR6(r1) 158 + ld r7,GPR7(r1) 159 + ld r8,GPR8(r1) 160 + /* Zero volatile regs that may contain sensitive kernel data */ 161 + li r9,0 162 + li r10,0 163 + li r11,0 164 + li r12,0 165 + mtspr SPRN_XER,r0 166 + 167 + /* 168 + * We don't need to restore AMR on the way back to userspace for KUAP. 169 + * The value of AMR only matters while we're in the kernel. 170 + */ 171 + mtcr r2 172 + ld r2,GPR2(r1) 173 + ld r3,GPR3(r1) 174 + ld r13,GPR13(r1) 175 + ld r1,GPR1(r1) 176 + RFSCV_TO_USER 177 + b . /* prevent speculative execution */ 178 + 179 + .Lsyscall_vectored_\name\()_restore_regs: 180 + mtspr SPRN_SRR0,r4 181 + mtspr SPRN_SRR1,r5 182 + 183 + ld r3,_CTR(r1) 184 + ld r4,_LINK(r1) 185 + ld r5,_XER(r1) 186 + 187 + REST_NVGPRS(r1) 188 + ld r0,GPR0(r1) 189 + mtcr r2 190 + mtctr r3 191 + mtlr r4 192 + mtspr SPRN_XER,r5 193 + REST_10GPRS(2, r1) 194 + REST_2GPRS(12, r1) 195 + ld r1,GPR1(r1) 196 + RFI_TO_USER 197 + .Lsyscall_vectored_\name\()_rst_end: 198 + 199 + syscall_vectored_\name\()_restart: 200 + _ASM_NOKPROBE_SYMBOL(syscall_vectored_\name\()_restart) 201 + GET_PACA(r13) 202 + ld r1,PACA_EXIT_SAVE_R1(r13) 203 + ld r2,PACATOC(r13) 204 + ld r3,RESULT(r1) 205 + addi r4,r1,STACK_FRAME_OVERHEAD 206 + li r11,IRQS_ALL_DISABLED 207 + stb r11,PACAIRQSOFTMASK(r13) 208 + bl syscall_exit_restart 209 + std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */ 210 + b .Lsyscall_vectored_\name\()_rst_start 211 + 1: 212 + 213 + SOFT_MASK_TABLE(.Lsyscall_vectored_\name\()_rst_start, 1b) 214 + RESTART_TABLE(.Lsyscall_vectored_\name\()_rst_start, .Lsyscall_vectored_\name\()_rst_end, syscall_vectored_\name\()_restart) 215 + 216 + .endm 217 + 218 + system_call_vectored common 0x3000 219 + 220 + /* 221 + * We instantiate another entry copy for the SIGILL variant, with TRAP=0x7ff0 222 + * which is tested by system_call_exception when r0 is -1 (as set by vector 223 + * entry code). 224 + */ 225 + system_call_vectored sigill 0x7ff0 226 + 227 + 228 + /* 229 + * Entered via kernel return set up by kernel/sstep.c, must match entry regs 230 + */ 231 + .globl system_call_vectored_emulate 232 + system_call_vectored_emulate: 233 + _ASM_NOKPROBE_SYMBOL(system_call_vectored_emulate) 234 + li r10,IRQS_ALL_DISABLED 235 + stb r10,PACAIRQSOFTMASK(r13) 236 + b system_call_vectored_common 237 + #endif /* CONFIG_PPC_BOOK3S */ 238 + 239 + .balign IFETCH_ALIGN_BYTES 240 + .globl system_call_common_real 241 + system_call_common_real: 242 + _ASM_NOKPROBE_SYMBOL(system_call_common_real) 243 + ld r10,PACAKMSR(r13) /* get MSR value for kernel */ 244 + mtmsrd r10 245 + 246 + .balign IFETCH_ALIGN_BYTES 247 + .globl system_call_common 248 + system_call_common: 249 + _ASM_NOKPROBE_SYMBOL(system_call_common) 250 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 251 + BEGIN_FTR_SECTION 252 + extrdi. r10, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */ 253 + bne tabort_syscall 254 + END_FTR_SECTION_IFSET(CPU_FTR_TM) 255 + #endif 256 + mr r10,r1 257 + ld r1,PACAKSAVE(r13) 258 + std r10,0(r1) 259 + std r11,_NIP(r1) 260 + std r12,_MSR(r1) 261 + std r0,GPR0(r1) 262 + std r10,GPR1(r1) 263 + std r2,GPR2(r1) 264 + #ifdef CONFIG_PPC_FSL_BOOK3E 265 + START_BTB_FLUSH_SECTION 266 + BTB_FLUSH(r10) 267 + END_BTB_FLUSH_SECTION 268 + #endif 269 + ld r2,PACATOC(r13) 270 + mfcr r12 271 + li r11,0 272 + /* Can we avoid saving r3-r8 in common case? */ 273 + std r3,GPR3(r1) 274 + std r4,GPR4(r1) 275 + std r5,GPR5(r1) 276 + std r6,GPR6(r1) 277 + std r7,GPR7(r1) 278 + std r8,GPR8(r1) 279 + /* Zero r9-r12, this should only be required when restoring all GPRs */ 280 + std r11,GPR9(r1) 281 + std r11,GPR10(r1) 282 + std r11,GPR11(r1) 283 + std r11,GPR12(r1) 284 + std r9,GPR13(r1) 285 + SAVE_NVGPRS(r1) 286 + std r11,_XER(r1) 287 + std r11,_CTR(r1) 288 + mflr r10 289 + 290 + /* 291 + * This clears CR0.SO (bit 28), which is the error indication on 292 + * return from this system call. 293 + */ 294 + rldimi r12,r11,28,(63-28) 295 + li r11,0xc00 296 + std r10,_LINK(r1) 297 + std r11,_TRAP(r1) 298 + std r12,_CCR(r1) 299 + addi r10,r1,STACK_FRAME_OVERHEAD 300 + ld r11,exception_marker@toc(r2) 301 + std r11,-16(r10) /* "regshere" marker */ 302 + 303 + #ifdef CONFIG_PPC_BOOK3S 304 + li r11,1 305 + stb r11,PACASRR_VALID(r13) 306 + #endif 307 + 308 + /* 309 + * We always enter kernel from userspace with irq soft-mask enabled and 310 + * nothing pending. system_call_exception() will call 311 + * trace_hardirqs_off(). 312 + */ 313 + li r11,IRQS_ALL_DISABLED 314 + li r12,-1 /* Set MSR_EE and MSR_RI */ 315 + stb r11,PACAIRQSOFTMASK(r13) 316 + mtmsrd r12,1 317 + 318 + /* Calling convention has r9 = orig r0, r10 = regs */ 319 + mr r9,r0 320 + bl system_call_exception 321 + 322 + .Lsyscall_exit: 323 + addi r4,r1,STACK_FRAME_OVERHEAD 324 + li r5,0 /* !scv */ 325 + bl syscall_exit_prepare 326 + std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */ 327 + #ifdef CONFIG_PPC_BOOK3S 328 + .Lsyscall_rst_start: 329 + lbz r11,PACAIRQHAPPENED(r13) 330 + andi. r11,r11,(~PACA_IRQ_HARD_DIS)@l 331 + bne- syscall_restart 332 + #endif 333 + li r11,IRQS_ENABLED 334 + stb r11,PACAIRQSOFTMASK(r13) 335 + li r11,0 336 + stb r11,PACAIRQHAPPENED(r13) # clear out possible HARD_DIS 337 + 338 + ld r2,_CCR(r1) 339 + ld r6,_LINK(r1) 340 + mtlr r6 341 + 342 + #ifdef CONFIG_PPC_BOOK3S 343 + lbz r4,PACASRR_VALID(r13) 344 + cmpdi r4,0 345 + bne 1f 346 + li r4,0 347 + stb r4,PACASRR_VALID(r13) 348 + #endif 349 + ld r4,_NIP(r1) 350 + ld r5,_MSR(r1) 351 + mtspr SPRN_SRR0,r4 352 + mtspr SPRN_SRR1,r5 353 + 1: 354 + DEBUG_SRR_VALID srr 355 + 356 + BEGIN_FTR_SECTION 357 + stdcx. r0,0,r1 /* to clear the reservation */ 358 + END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 359 + 360 + cmpdi r3,0 361 + bne .Lsyscall_restore_regs 362 + /* Zero volatile regs that may contain sensitive kernel data */ 363 + li r0,0 364 + li r4,0 365 + li r5,0 366 + li r6,0 367 + li r7,0 368 + li r8,0 369 + li r9,0 370 + li r10,0 371 + li r11,0 372 + li r12,0 373 + mtctr r0 374 + mtspr SPRN_XER,r0 375 + .Lsyscall_restore_regs_cont: 376 + 377 + BEGIN_FTR_SECTION 378 + HMT_MEDIUM_LOW 379 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 380 + 381 + /* 382 + * We don't need to restore AMR on the way back to userspace for KUAP. 383 + * The value of AMR only matters while we're in the kernel. 384 + */ 385 + mtcr r2 386 + ld r2,GPR2(r1) 387 + ld r3,GPR3(r1) 388 + ld r13,GPR13(r1) 389 + ld r1,GPR1(r1) 390 + RFI_TO_USER 391 + b . /* prevent speculative execution */ 392 + 393 + .Lsyscall_restore_regs: 394 + ld r3,_CTR(r1) 395 + ld r4,_XER(r1) 396 + REST_NVGPRS(r1) 397 + mtctr r3 398 + mtspr SPRN_XER,r4 399 + ld r0,GPR0(r1) 400 + REST_8GPRS(4, r1) 401 + ld r12,GPR12(r1) 402 + b .Lsyscall_restore_regs_cont 403 + .Lsyscall_rst_end: 404 + 405 + #ifdef CONFIG_PPC_BOOK3S 406 + syscall_restart: 407 + _ASM_NOKPROBE_SYMBOL(syscall_restart) 408 + GET_PACA(r13) 409 + ld r1,PACA_EXIT_SAVE_R1(r13) 410 + ld r2,PACATOC(r13) 411 + ld r3,RESULT(r1) 412 + addi r4,r1,STACK_FRAME_OVERHEAD 413 + li r11,IRQS_ALL_DISABLED 414 + stb r11,PACAIRQSOFTMASK(r13) 415 + bl syscall_exit_restart 416 + std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */ 417 + b .Lsyscall_rst_start 418 + 1: 419 + 420 + SOFT_MASK_TABLE(.Lsyscall_rst_start, 1b) 421 + RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) 422 + #endif 423 + 424 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 425 + tabort_syscall: 426 + _ASM_NOKPROBE_SYMBOL(tabort_syscall) 427 + /* Firstly we need to enable TM in the kernel */ 428 + mfmsr r10 429 + li r9, 1 430 + rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG 431 + mtmsrd r10, 0 432 + 433 + /* tabort, this dooms the transaction, nothing else */ 434 + li r9, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT) 435 + TABORT(R9) 436 + 437 + /* 438 + * Return directly to userspace. We have corrupted user register state, 439 + * but userspace will never see that register state. Execution will 440 + * resume after the tbegin of the aborted transaction with the 441 + * checkpointed register state. 442 + */ 443 + li r9, MSR_RI 444 + andc r10, r10, r9 445 + mtmsrd r10, 1 446 + mtspr SPRN_SRR0, r11 447 + mtspr SPRN_SRR1, r12 448 + RFI_TO_USER 449 + b . /* prevent speculative execution */ 450 + #endif 451 + 452 + /* 453 + * If MSR EE/RI was never enabled, IRQs not reconciled, NVGPRs not 454 + * touched, no exit work created, then this can be used. 455 + */ 456 + .balign IFETCH_ALIGN_BYTES 457 + .globl fast_interrupt_return_srr 458 + fast_interrupt_return_srr: 459 + _ASM_NOKPROBE_SYMBOL(fast_interrupt_return_srr) 460 + kuap_check_amr r3, r4 461 + ld r5,_MSR(r1) 462 + andi. r0,r5,MSR_PR 463 + #ifdef CONFIG_PPC_BOOK3S 464 + beq 1f 465 + kuap_user_restore r3, r4 466 + b .Lfast_user_interrupt_return_srr 467 + 1: kuap_kernel_restore r3, r4 468 + andi. r0,r5,MSR_RI 469 + li r3,0 /* 0 return value, no EMULATE_STACK_STORE */ 470 + bne+ .Lfast_kernel_interrupt_return_srr 471 + addi r3,r1,STACK_FRAME_OVERHEAD 472 + bl unrecoverable_exception 473 + b . /* should not get here */ 474 + #else 475 + bne .Lfast_user_interrupt_return_srr 476 + b .Lfast_kernel_interrupt_return_srr 477 + #endif 478 + 479 + .macro interrupt_return_macro srr 480 + .balign IFETCH_ALIGN_BYTES 481 + .globl interrupt_return_\srr 482 + interrupt_return_\srr\(): 483 + _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()) 484 + ld r4,_MSR(r1) 485 + andi. r0,r4,MSR_PR 486 + beq interrupt_return_\srr\()_kernel 487 + interrupt_return_\srr\()_user: /* make backtraces match the _kernel variant */ 488 + _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_user) 489 + addi r3,r1,STACK_FRAME_OVERHEAD 490 + bl interrupt_exit_user_prepare 491 + cmpdi r3,0 492 + bne- .Lrestore_nvgprs_\srr 493 + .Lrestore_nvgprs_\srr\()_cont: 494 + std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */ 495 + #ifdef CONFIG_PPC_BOOK3S 496 + .Linterrupt_return_\srr\()_user_rst_start: 497 + lbz r11,PACAIRQHAPPENED(r13) 498 + andi. r11,r11,(~PACA_IRQ_HARD_DIS)@l 499 + bne- interrupt_return_\srr\()_user_restart 500 + #endif 501 + li r11,IRQS_ENABLED 502 + stb r11,PACAIRQSOFTMASK(r13) 503 + li r11,0 504 + stb r11,PACAIRQHAPPENED(r13) # clear out possible HARD_DIS 505 + 506 + .Lfast_user_interrupt_return_\srr\(): 507 + #ifdef CONFIG_PPC_BOOK3S 508 + .ifc \srr,srr 509 + lbz r4,PACASRR_VALID(r13) 510 + .else 511 + lbz r4,PACAHSRR_VALID(r13) 512 + .endif 513 + cmpdi r4,0 514 + li r4,0 515 + bne 1f 516 + #endif 517 + ld r11,_NIP(r1) 518 + ld r12,_MSR(r1) 519 + .ifc \srr,srr 520 + mtspr SPRN_SRR0,r11 521 + mtspr SPRN_SRR1,r12 522 + 1: 523 + #ifdef CONFIG_PPC_BOOK3S 524 + stb r4,PACASRR_VALID(r13) 525 + #endif 526 + .else 527 + mtspr SPRN_HSRR0,r11 528 + mtspr SPRN_HSRR1,r12 529 + 1: 530 + #ifdef CONFIG_PPC_BOOK3S 531 + stb r4,PACAHSRR_VALID(r13) 532 + #endif 533 + .endif 534 + DEBUG_SRR_VALID \srr 535 + 536 + #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG 537 + lbz r4,PACAIRQSOFTMASK(r13) 538 + tdnei r4,IRQS_ENABLED 539 + #endif 540 + 541 + BEGIN_FTR_SECTION 542 + ld r10,_PPR(r1) 543 + mtspr SPRN_PPR,r10 544 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 545 + 546 + BEGIN_FTR_SECTION 547 + stdcx. r0,0,r1 /* to clear the reservation */ 548 + FTR_SECTION_ELSE 549 + ldarx r0,0,r1 550 + ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 551 + 552 + ld r3,_CCR(r1) 553 + ld r4,_LINK(r1) 554 + ld r5,_CTR(r1) 555 + ld r6,_XER(r1) 556 + li r0,0 557 + 558 + REST_4GPRS(7, r1) 559 + REST_2GPRS(11, r1) 560 + REST_GPR(13, r1) 561 + 562 + mtcr r3 563 + mtlr r4 564 + mtctr r5 565 + mtspr SPRN_XER,r6 566 + 567 + REST_4GPRS(2, r1) 568 + REST_GPR(6, r1) 569 + REST_GPR(0, r1) 570 + REST_GPR(1, r1) 571 + .ifc \srr,srr 572 + RFI_TO_USER 573 + .else 574 + HRFI_TO_USER 575 + .endif 576 + b . /* prevent speculative execution */ 577 + .Linterrupt_return_\srr\()_user_rst_end: 578 + 579 + .Lrestore_nvgprs_\srr\(): 580 + REST_NVGPRS(r1) 581 + b .Lrestore_nvgprs_\srr\()_cont 582 + 583 + #ifdef CONFIG_PPC_BOOK3S 584 + interrupt_return_\srr\()_user_restart: 585 + _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_user_restart) 586 + GET_PACA(r13) 587 + ld r1,PACA_EXIT_SAVE_R1(r13) 588 + ld r2,PACATOC(r13) 589 + addi r3,r1,STACK_FRAME_OVERHEAD 590 + li r11,IRQS_ALL_DISABLED 591 + stb r11,PACAIRQSOFTMASK(r13) 592 + bl interrupt_exit_user_restart 593 + std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */ 594 + b .Linterrupt_return_\srr\()_user_rst_start 595 + 1: 596 + 597 + SOFT_MASK_TABLE(.Linterrupt_return_\srr\()_user_rst_start, 1b) 598 + RESTART_TABLE(.Linterrupt_return_\srr\()_user_rst_start, .Linterrupt_return_\srr\()_user_rst_end, interrupt_return_\srr\()_user_restart) 599 + #endif 600 + 601 + .balign IFETCH_ALIGN_BYTES 602 + interrupt_return_\srr\()_kernel: 603 + _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_kernel) 604 + addi r3,r1,STACK_FRAME_OVERHEAD 605 + bl interrupt_exit_kernel_prepare 606 + 607 + std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */ 608 + .Linterrupt_return_\srr\()_kernel_rst_start: 609 + ld r11,SOFTE(r1) 610 + cmpwi r11,IRQS_ENABLED 611 + stb r11,PACAIRQSOFTMASK(r13) 612 + bne 1f 613 + #ifdef CONFIG_PPC_BOOK3S 614 + lbz r11,PACAIRQHAPPENED(r13) 615 + andi. r11,r11,(~PACA_IRQ_HARD_DIS)@l 616 + bne- interrupt_return_\srr\()_kernel_restart 617 + #endif 618 + li r11,0 619 + stb r11,PACAIRQHAPPENED(r13) # clear out possible HARD_DIS 620 + 1: 621 + 622 + .Lfast_kernel_interrupt_return_\srr\(): 623 + cmpdi cr1,r3,0 624 + #ifdef CONFIG_PPC_BOOK3S 625 + .ifc \srr,srr 626 + lbz r4,PACASRR_VALID(r13) 627 + .else 628 + lbz r4,PACAHSRR_VALID(r13) 629 + .endif 630 + cmpdi r4,0 631 + li r4,0 632 + bne 1f 633 + #endif 634 + ld r11,_NIP(r1) 635 + ld r12,_MSR(r1) 636 + .ifc \srr,srr 637 + mtspr SPRN_SRR0,r11 638 + mtspr SPRN_SRR1,r12 639 + 1: 640 + #ifdef CONFIG_PPC_BOOK3S 641 + stb r4,PACASRR_VALID(r13) 642 + #endif 643 + .else 644 + mtspr SPRN_HSRR0,r11 645 + mtspr SPRN_HSRR1,r12 646 + 1: 647 + #ifdef CONFIG_PPC_BOOK3S 648 + stb r4,PACAHSRR_VALID(r13) 649 + #endif 650 + .endif 651 + DEBUG_SRR_VALID \srr 652 + 653 + BEGIN_FTR_SECTION 654 + stdcx. r0,0,r1 /* to clear the reservation */ 655 + FTR_SECTION_ELSE 656 + ldarx r0,0,r1 657 + ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 658 + 659 + ld r3,_LINK(r1) 660 + ld r4,_CTR(r1) 661 + ld r5,_XER(r1) 662 + ld r6,_CCR(r1) 663 + li r0,0 664 + 665 + REST_4GPRS(7, r1) 666 + REST_2GPRS(11, r1) 667 + 668 + mtlr r3 669 + mtctr r4 670 + mtspr SPRN_XER,r5 671 + 672 + /* 673 + * Leaving a stale exception_marker on the stack can confuse 674 + * the reliable stack unwinder later on. Clear it. 675 + */ 676 + std r0,STACK_FRAME_OVERHEAD-16(r1) 677 + 678 + REST_4GPRS(2, r1) 679 + 680 + bne- cr1,1f /* emulate stack store */ 681 + mtcr r6 682 + REST_GPR(6, r1) 683 + REST_GPR(0, r1) 684 + REST_GPR(1, r1) 685 + .ifc \srr,srr 686 + RFI_TO_KERNEL 687 + .else 688 + HRFI_TO_KERNEL 689 + .endif 690 + b . /* prevent speculative execution */ 691 + 692 + 1: /* 693 + * Emulate stack store with update. New r1 value was already calculated 694 + * and updated in our interrupt regs by emulate_loadstore, but we can't 695 + * store the previous value of r1 to the stack before re-loading our 696 + * registers from it, otherwise they could be clobbered. Use 697 + * PACA_EXGEN as temporary storage to hold the store data, as 698 + * interrupts are disabled here so it won't be clobbered. 699 + */ 700 + mtcr r6 701 + std r9,PACA_EXGEN+0(r13) 702 + addi r9,r1,INT_FRAME_SIZE /* get original r1 */ 703 + REST_GPR(6, r1) 704 + REST_GPR(0, r1) 705 + REST_GPR(1, r1) 706 + std r9,0(r1) /* perform store component of stdu */ 707 + ld r9,PACA_EXGEN+0(r13) 708 + 709 + .ifc \srr,srr 710 + RFI_TO_KERNEL 711 + .else 712 + HRFI_TO_KERNEL 713 + .endif 714 + b . /* prevent speculative execution */ 715 + .Linterrupt_return_\srr\()_kernel_rst_end: 716 + 717 + #ifdef CONFIG_PPC_BOOK3S 718 + interrupt_return_\srr\()_kernel_restart: 719 + _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_kernel_restart) 720 + GET_PACA(r13) 721 + ld r1,PACA_EXIT_SAVE_R1(r13) 722 + ld r2,PACATOC(r13) 723 + addi r3,r1,STACK_FRAME_OVERHEAD 724 + li r11,IRQS_ALL_DISABLED 725 + stb r11,PACAIRQSOFTMASK(r13) 726 + bl interrupt_exit_kernel_restart 727 + std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */ 728 + b .Linterrupt_return_\srr\()_kernel_rst_start 729 + 1: 730 + 731 + SOFT_MASK_TABLE(.Linterrupt_return_\srr\()_kernel_rst_start, 1b) 732 + RESTART_TABLE(.Linterrupt_return_\srr\()_kernel_rst_start, .Linterrupt_return_\srr\()_kernel_rst_end, interrupt_return_\srr\()_kernel_restart) 733 + #endif 734 + 735 + .endm 736 + 737 + interrupt_return_macro srr 738 + #ifdef CONFIG_PPC_BOOK3S 739 + interrupt_return_macro hsrr 740 + 741 + .globl __end_soft_masked 742 + __end_soft_masked: 743 + DEFINE_FIXED_SYMBOL(__end_soft_masked) 744 + #endif /* CONFIG_PPC_BOOK3S */ 745 + 746 + #ifdef CONFIG_PPC_BOOK3S 747 + _GLOBAL(ret_from_fork_scv) 748 + bl schedule_tail 749 + REST_NVGPRS(r1) 750 + li r3,0 /* fork() return value */ 751 + b .Lsyscall_vectored_common_exit 752 + #endif 753 + 754 + _GLOBAL(ret_from_fork) 755 + bl schedule_tail 756 + REST_NVGPRS(r1) 757 + li r3,0 /* fork() return value */ 758 + b .Lsyscall_exit 759 + 760 + _GLOBAL(ret_from_kernel_thread) 761 + bl schedule_tail 762 + REST_NVGPRS(r1) 763 + mtctr r14 764 + mr r3,r15 765 + #ifdef PPC64_ELF_ABI_v2 766 + mr r12,r14 767 + #endif 768 + bctrl 769 + li r3,0 770 + b .Lsyscall_exit
+96
arch/powerpc/kernel/irq.c
··· 121 121 122 122 ppc_save_regs(&regs); 123 123 regs.softe = IRQS_ENABLED; 124 + regs.msr |= MSR_EE; 124 125 125 126 again: 126 127 if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) ··· 218 217 #define replay_soft_interrupts_irqrestore() replay_soft_interrupts() 219 218 #endif 220 219 220 + #ifdef CONFIG_CC_HAS_ASM_GOTO 221 + notrace void arch_local_irq_restore(unsigned long mask) 222 + { 223 + unsigned char irq_happened; 224 + 225 + /* Write the new soft-enabled value if it is a disable */ 226 + if (mask) { 227 + irq_soft_mask_set(mask); 228 + return; 229 + } 230 + 231 + /* 232 + * After the stb, interrupts are unmasked and there are no interrupts 233 + * pending replay. The restart sequence makes this atomic with 234 + * respect to soft-masked interrupts. If this was just a simple code 235 + * sequence, a soft-masked interrupt could become pending right after 236 + * the comparison and before the stb. 237 + * 238 + * This allows interrupts to be unmasked without hard disabling, and 239 + * also without new hard interrupts coming in ahead of pending ones. 240 + */ 241 + asm_volatile_goto( 242 + "1: \n" 243 + " lbz 9,%0(13) \n" 244 + " cmpwi 9,0 \n" 245 + " bne %l[happened] \n" 246 + " stb 9,%1(13) \n" 247 + "2: \n" 248 + RESTART_TABLE(1b, 2b, 1b) 249 + : : "i" (offsetof(struct paca_struct, irq_happened)), 250 + "i" (offsetof(struct paca_struct, irq_soft_mask)) 251 + : "cr0", "r9" 252 + : happened); 253 + 254 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 255 + WARN_ON_ONCE(!(mfmsr() & MSR_EE)); 256 + 257 + return; 258 + 259 + happened: 260 + irq_happened = get_irq_happened(); 261 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 262 + WARN_ON_ONCE(!irq_happened); 263 + 264 + if (irq_happened == PACA_IRQ_HARD_DIS) { 265 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 266 + WARN_ON_ONCE(mfmsr() & MSR_EE); 267 + irq_soft_mask_set(IRQS_ENABLED); 268 + local_paca->irq_happened = 0; 269 + __hard_irq_enable(); 270 + return; 271 + } 272 + 273 + /* Have interrupts to replay, need to hard disable first */ 274 + if (!(irq_happened & PACA_IRQ_HARD_DIS)) { 275 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) { 276 + if (!(mfmsr() & MSR_EE)) { 277 + /* 278 + * An interrupt could have come in and cleared 279 + * MSR[EE] and set IRQ_HARD_DIS, so check 280 + * IRQ_HARD_DIS again and warn if it is still 281 + * clear. 282 + */ 283 + irq_happened = get_irq_happened(); 284 + WARN_ON_ONCE(!(irq_happened & PACA_IRQ_HARD_DIS)); 285 + } 286 + } 287 + __hard_irq_disable(); 288 + local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 289 + } else { 290 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) { 291 + if (WARN_ON_ONCE(mfmsr() & MSR_EE)) 292 + __hard_irq_disable(); 293 + } 294 + } 295 + 296 + /* 297 + * Disable preempt here, so that the below preempt_enable will 298 + * perform resched if required (a replayed interrupt may set 299 + * need_resched). 300 + */ 301 + preempt_disable(); 302 + irq_soft_mask_set(IRQS_ALL_DISABLED); 303 + trace_hardirqs_off(); 304 + 305 + replay_soft_interrupts_irqrestore(); 306 + local_paca->irq_happened = 0; 307 + 308 + trace_hardirqs_on(); 309 + irq_soft_mask_set(IRQS_ENABLED); 310 + __hard_irq_enable(); 311 + preempt_enable(); 312 + } 313 + #else 221 314 notrace void arch_local_irq_restore(unsigned long mask) 222 315 { 223 316 unsigned char irq_happened; ··· 383 288 __hard_irq_enable(); 384 289 preempt_enable(); 385 290 } 291 + #endif 386 292 EXPORT_SYMBOL(arch_local_irq_restore); 387 293 388 294 /*
+2 -2
arch/powerpc/kernel/jump_label.c
··· 11 11 void arch_jump_label_transform(struct jump_entry *entry, 12 12 enum jump_label_type type) 13 13 { 14 - struct ppc_inst *addr = (struct ppc_inst *)jump_entry_code(entry); 14 + u32 *addr = (u32 *)jump_entry_code(entry); 15 15 16 16 if (type == JUMP_LABEL_JMP) 17 17 patch_branch(addr, jump_entry_target(entry), 0); 18 18 else 19 - patch_instruction(addr, ppc_inst(PPC_INST_NOP)); 19 + patch_instruction(addr, ppc_inst(PPC_RAW_NOP())); 20 20 }
+9 -10
arch/powerpc/kernel/kgdb.c
··· 147 147 return 0; 148 148 149 149 if (*(u32 *)regs->nip == BREAK_INSTR) 150 - regs->nip += BREAK_INSTR_SIZE; 150 + regs_add_return_ip(regs, BREAK_INSTR_SIZE); 151 151 152 152 return 1; 153 153 } ··· 372 372 373 373 void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc) 374 374 { 375 - regs->nip = pc; 375 + regs_set_return_ip(regs, pc); 376 376 } 377 377 378 378 /* ··· 394 394 case 'c': 395 395 /* handle the optional parameter */ 396 396 if (kgdb_hex2long(&ptr, &addr)) 397 - linux_regs->nip = addr; 397 + regs_set_return_ip(linux_regs, addr); 398 398 399 399 atomic_set(&kgdb_cpu_doing_single_step, -1); 400 400 /* set the trace bit if we're stepping */ ··· 402 402 #ifdef CONFIG_PPC_ADV_DEBUG_REGS 403 403 mtspr(SPRN_DBCR0, 404 404 mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM); 405 - linux_regs->msr |= MSR_DE; 405 + regs_set_return_msr(linux_regs, linux_regs->msr | MSR_DE); 406 406 #else 407 - linux_regs->msr |= MSR_SE; 407 + regs_set_return_msr(linux_regs, linux_regs->msr | MSR_SE); 408 408 #endif 409 409 atomic_set(&kgdb_cpu_doing_single_step, 410 410 raw_smp_processor_id()); ··· 417 417 418 418 int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) 419 419 { 420 + u32 instr, *addr = (u32 *)bpt->bpt_addr; 420 421 int err; 421 - unsigned int instr; 422 - struct ppc_inst *addr = (struct ppc_inst *)bpt->bpt_addr; 423 422 424 - err = get_kernel_nofault(instr, (unsigned *) addr); 423 + err = get_kernel_nofault(instr, addr); 425 424 if (err) 426 425 return err; 427 426 ··· 428 429 if (err) 429 430 return -EFAULT; 430 431 431 - *(unsigned int *)bpt->saved_instr = instr; 432 + *(u32 *)bpt->saved_instr = instr; 432 433 433 434 return 0; 434 435 } ··· 437 438 { 438 439 int err; 439 440 unsigned int instr = *(unsigned int *)bpt->saved_instr; 440 - struct ppc_inst *addr = (struct ppc_inst *)bpt->bpt_addr; 441 + u32 *addr = (u32 *)bpt->bpt_addr; 441 442 442 443 err = patch_instruction(addr, ppc_inst(instr)); 443 444 if (err)
+2 -2
arch/powerpc/kernel/kprobes-ftrace.c
··· 39 39 * On powerpc, NIP is *before* this instruction for the 40 40 * pre handler 41 41 */ 42 - regs->nip -= MCOUNT_INSN_SIZE; 42 + regs_add_return_ip(regs, -MCOUNT_INSN_SIZE); 43 43 44 44 __this_cpu_write(current_kprobe, p); 45 45 kcb->kprobe_status = KPROBE_HIT_ACTIVE; ··· 48 48 * Emulate singlestep (and also recover regs->nip) 49 49 * as if there is a nop 50 50 */ 51 - regs->nip += MCOUNT_INSN_SIZE; 51 + regs_add_return_ip(regs, MCOUNT_INSN_SIZE); 52 52 if (unlikely(p->post_handler)) { 53 53 kcb->kprobe_status = KPROBE_HIT_SSDONE; 54 54 p->post_handler(p, regs, 0);
+40 -21
arch/powerpc/kernel/kprobes.c
··· 19 19 #include <linux/extable.h> 20 20 #include <linux/kdebug.h> 21 21 #include <linux/slab.h> 22 + #include <linux/moduleloader.h> 22 23 #include <asm/code-patching.h> 23 24 #include <asm/cacheflush.h> 24 25 #include <asm/sstep.h> 25 26 #include <asm/sections.h> 26 27 #include <asm/inst.h> 28 + #include <asm/set_memory.h> 27 29 #include <linux/uaccess.h> 28 30 29 31 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL; ··· 105 103 return addr; 106 104 } 107 105 106 + void *alloc_insn_page(void) 107 + { 108 + void *page; 109 + 110 + page = module_alloc(PAGE_SIZE); 111 + if (!page) 112 + return NULL; 113 + 114 + if (strict_module_rwx_enabled()) { 115 + set_memory_ro((unsigned long)page, 1); 116 + set_memory_x((unsigned long)page, 1); 117 + } 118 + return page; 119 + } 120 + 108 121 int arch_prepare_kprobe(struct kprobe *p) 109 122 { 110 123 int ret = 0; 111 124 struct kprobe *prev; 112 - struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->addr); 125 + struct ppc_inst insn = ppc_inst_read(p->addr); 113 126 114 127 if ((unsigned long)p->addr & 0x03) { 115 128 printk("Attempt to register kprobe at an unaligned address\n"); 116 129 ret = -EINVAL; 117 - } else if (IS_MTMSRD(insn) || IS_RFID(insn) || IS_RFI(insn)) { 118 - printk("Cannot register a kprobe on rfi/rfid or mtmsr[d]\n"); 130 + } else if (IS_MTMSRD(insn) || IS_RFID(insn)) { 131 + printk("Cannot register a kprobe on mtmsr[d]/rfi[d]\n"); 119 132 ret = -EINVAL; 120 133 } else if ((unsigned long)p->addr & ~PAGE_MASK && 121 - ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)(p->addr - 1)))) { 134 + ppc_inst_prefixed(ppc_inst_read(p->addr - 1))) { 122 135 printk("Cannot register a kprobe on the second word of prefixed instruction\n"); 123 136 ret = -EINVAL; 124 137 } 125 138 preempt_disable(); 126 139 prev = get_kprobe(p->addr - 1); 127 140 preempt_enable_no_resched(); 128 - if (prev && 129 - ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)prev->ainsn.insn))) { 141 + if (prev && ppc_inst_prefixed(ppc_inst_read(prev->ainsn.insn))) { 130 142 printk("Cannot register a kprobe on the second word of prefixed instruction\n"); 131 143 ret = -EINVAL; 132 144 } ··· 154 138 } 155 139 156 140 if (!ret) { 157 - patch_instruction((struct ppc_inst *)p->ainsn.insn, insn); 141 + patch_instruction(p->ainsn.insn, insn); 158 142 p->opcode = ppc_inst_val(insn); 159 143 } 160 144 ··· 165 149 166 150 void arch_arm_kprobe(struct kprobe *p) 167 151 { 168 - patch_instruction((struct ppc_inst *)p->addr, ppc_inst(BREAKPOINT_INSTRUCTION)); 152 + WARN_ON_ONCE(patch_instruction(p->addr, ppc_inst(BREAKPOINT_INSTRUCTION))); 169 153 } 170 154 NOKPROBE_SYMBOL(arch_arm_kprobe); 171 155 172 156 void arch_disarm_kprobe(struct kprobe *p) 173 157 { 174 - patch_instruction((struct ppc_inst *)p->addr, ppc_inst(p->opcode)); 158 + WARN_ON_ONCE(patch_instruction(p->addr, ppc_inst(p->opcode))); 175 159 } 176 160 NOKPROBE_SYMBOL(arch_disarm_kprobe); 177 161 ··· 194 178 * variant as values in regs could play a part in 195 179 * if the trap is taken or not 196 180 */ 197 - regs->nip = (unsigned long)p->ainsn.insn; 181 + regs_set_return_ip(regs, (unsigned long)p->ainsn.insn); 198 182 } 199 183 200 184 static nokprobe_inline void save_previous_kprobe(struct kprobe_ctlblk *kcb) ··· 244 228 static int try_to_emulate(struct kprobe *p, struct pt_regs *regs) 245 229 { 246 230 int ret; 247 - struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->ainsn.insn); 231 + struct ppc_inst insn = ppc_inst_read(p->ainsn.insn); 248 232 249 233 /* regs->nip is also adjusted if emulate_step returns 1 */ 250 234 ret = emulate_step(regs, insn); ··· 335 319 kprobe_opcode_t insn = *p->ainsn.insn; 336 320 if (kcb->kprobe_status == KPROBE_HIT_SS && is_trap(insn)) { 337 321 /* Turn off 'trace' bits */ 338 - regs->msr &= ~MSR_SINGLESTEP; 339 - regs->msr |= kcb->kprobe_saved_msr; 322 + regs_set_return_msr(regs, 323 + (regs->msr & ~MSR_SINGLESTEP) | 324 + kcb->kprobe_saved_msr); 340 325 goto no_kprobe; 341 326 } 342 327 ··· 432 415 * we end up emulating it in kprobe_handler(), which increments the nip 433 416 * again. 434 417 */ 435 - regs->nip = orig_ret_address - 4; 418 + regs_set_return_ip(regs, orig_ret_address - 4); 436 419 regs->link = orig_ret_address; 437 420 438 421 return 0; ··· 456 439 if (!cur || user_mode(regs)) 457 440 return 0; 458 441 459 - len = ppc_inst_len(ppc_inst_read((struct ppc_inst *)cur->ainsn.insn)); 442 + len = ppc_inst_len(ppc_inst_read(cur->ainsn.insn)); 460 443 /* make sure we got here for instruction we have a kprobe on */ 461 444 if (((unsigned long)cur->ainsn.insn + len) != regs->nip) 462 445 return 0; ··· 467 450 } 468 451 469 452 /* Adjust nip to after the single-stepped instruction */ 470 - regs->nip = (unsigned long)cur->addr + len; 471 - regs->msr |= kcb->kprobe_saved_msr; 453 + regs_set_return_ip(regs, (unsigned long)cur->addr + len); 454 + regs_set_return_msr(regs, regs->msr | kcb->kprobe_saved_msr); 472 455 473 456 /*Restore back the original saved kprobes variables and continue. */ 474 457 if (kcb->kprobe_status == KPROBE_REENTER) { ··· 507 490 * and allow the page fault handler to continue as a 508 491 * normal page fault. 509 492 */ 510 - regs->nip = (unsigned long)cur->addr; 511 - regs->msr &= ~MSR_SINGLESTEP; /* Turn off 'trace' bits */ 512 - regs->msr |= kcb->kprobe_saved_msr; 493 + regs_set_return_ip(regs, (unsigned long)cur->addr); 494 + /* Turn off 'trace' bits */ 495 + regs_set_return_msr(regs, 496 + (regs->msr & ~MSR_SINGLESTEP) | 497 + kcb->kprobe_saved_msr); 513 498 if (kcb->kprobe_status == KPROBE_REENTER) 514 499 restore_previous_kprobe(kcb); 515 500 else ··· 525 506 * zero, try to fix up. 526 507 */ 527 508 if ((entry = search_exception_tables(regs->nip)) != NULL) { 528 - regs->nip = extable_fixup(entry); 509 + regs_set_return_ip(regs, extable_fixup(entry)); 529 510 return 1; 530 511 } 531 512
+1 -1
arch/powerpc/kernel/mce.c
··· 274 274 entry = search_kernel_exception_table(regs->nip); 275 275 if (entry) { 276 276 mce_err->ignore_event = true; 277 - regs->nip = extable_fixup(entry); 277 + regs_set_return_ip(regs, extable_fixup(entry)); 278 278 } 279 279 } 280 280
+41 -9
arch/powerpc/kernel/mce_power.c
··· 463 463 pfn = addr_to_pfn(regs, regs->nip); 464 464 if (pfn != ULONG_MAX) { 465 465 instr_addr = (pfn << PAGE_SHIFT) + (regs->nip & ~PAGE_MASK); 466 - instr = ppc_inst_read((struct ppc_inst *)instr_addr); 466 + instr = ppc_inst_read((u32 *)instr_addr); 467 467 if (!analyse_instr(&op, &tmp, instr)) { 468 468 pfn = addr_to_pfn(regs, op.ea); 469 469 *addr = op.ea; ··· 481 481 return -1; 482 482 } 483 483 484 - static int mce_handle_ierror(struct pt_regs *regs, 484 + static int mce_handle_ierror(struct pt_regs *regs, unsigned long srr1, 485 485 const struct mce_ierror_table table[], 486 486 struct mce_error_info *mce_err, uint64_t *addr, 487 487 uint64_t *phys_addr) 488 488 { 489 - uint64_t srr1 = regs->msr; 490 489 int handled = 0; 491 490 int i; 492 491 ··· 694 695 } 695 696 696 697 static long mce_handle_error(struct pt_regs *regs, 698 + unsigned long srr1, 697 699 const struct mce_derror_table dtable[], 698 700 const struct mce_ierror_table itable[]) 699 701 { 700 702 struct mce_error_info mce_err = { 0 }; 701 703 uint64_t addr, phys_addr = ULONG_MAX; 702 - uint64_t srr1 = regs->msr; 703 704 long handled; 704 705 705 706 if (SRR1_MC_LOADSTORE(srr1)) 706 707 handled = mce_handle_derror(regs, dtable, &mce_err, &addr, 707 708 &phys_addr); 708 709 else 709 - handled = mce_handle_ierror(regs, itable, &mce_err, &addr, 710 + handled = mce_handle_ierror(regs, srr1, itable, &mce_err, &addr, 710 711 &phys_addr); 711 712 712 713 if (!handled && mce_err.error_type == MCE_ERROR_TYPE_UE) ··· 722 723 /* P7 DD1 leaves top bits of DSISR undefined */ 723 724 regs->dsisr &= 0x0000ffff; 724 725 725 - return mce_handle_error(regs, mce_p7_derror_table, mce_p7_ierror_table); 726 + return mce_handle_error(regs, regs->msr, 727 + mce_p7_derror_table, mce_p7_ierror_table); 726 728 } 727 729 728 730 long __machine_check_early_realmode_p8(struct pt_regs *regs) 729 731 { 730 - return mce_handle_error(regs, mce_p8_derror_table, mce_p8_ierror_table); 732 + return mce_handle_error(regs, regs->msr, 733 + mce_p8_derror_table, mce_p8_ierror_table); 731 734 } 732 735 733 736 long __machine_check_early_realmode_p9(struct pt_regs *regs) 734 737 { 738 + unsigned long srr1 = regs->msr; 739 + 735 740 /* 736 741 * On POWER9 DD2.1 and below, it's possible to get a machine check 737 742 * caused by a paste instruction where only DSISR bit 25 is set. This ··· 749 746 if (SRR1_MC_LOADSTORE(regs->msr) && regs->dsisr == 0x02000000) 750 747 return 1; 751 748 752 - return mce_handle_error(regs, mce_p9_derror_table, mce_p9_ierror_table); 749 + /* 750 + * Async machine check due to bad real address from store or foreign 751 + * link time out comes with the load/store bit (PPC bit 42) set in 752 + * SRR1, but the cause comes in SRR1 not DSISR. Clear bit 42 so we're 753 + * directed to the ierror table so it will find the cause (which 754 + * describes it correctly as a store error). 755 + */ 756 + if (SRR1_MC_LOADSTORE(srr1) && 757 + ((srr1 & 0x081c0000) == 0x08140000 || 758 + (srr1 & 0x081c0000) == 0x08180000)) { 759 + srr1 &= ~PPC_BIT(42); 760 + } 761 + 762 + return mce_handle_error(regs, srr1, 763 + mce_p9_derror_table, mce_p9_ierror_table); 753 764 } 754 765 755 766 long __machine_check_early_realmode_p10(struct pt_regs *regs) 756 767 { 757 - return mce_handle_error(regs, mce_p10_derror_table, mce_p10_ierror_table); 768 + unsigned long srr1 = regs->msr; 769 + 770 + /* 771 + * Async machine check due to bad real address from store comes with 772 + * the load/store bit (PPC bit 42) set in SRR1, but the cause comes in 773 + * SRR1 not DSISR. Clear bit 42 so we're directed to the ierror table 774 + * so it will find the cause (which describes it correctly as a store 775 + * error). 776 + */ 777 + if (SRR1_MC_LOADSTORE(srr1) && 778 + (srr1 & 0x081c0000) == 0x08140000) { 779 + srr1 &= ~PPC_BIT(42); 780 + } 781 + 782 + return mce_handle_error(regs, srr1, 783 + mce_p10_derror_table, mce_p10_ierror_table); 758 784 }
-6
arch/powerpc/kernel/misc_32.S
··· 388 388 bl start_secondary 389 389 b . 390 390 #endif /* CONFIG_SMP */ 391 - 392 - /* 393 - * This routine is just here to keep GCC happy - sigh... 394 - */ 395 - _GLOBAL(__main) 396 - blr
+3 -1
arch/powerpc/kernel/module.c
··· 92 92 static __always_inline void * 93 93 __module_alloc(unsigned long size, unsigned long start, unsigned long end) 94 94 { 95 + pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC; 96 + 95 97 /* 96 98 * Don't do huge page allocations for modules yet until more testing 97 99 * is done. STRICT_MODULE_RWX may require extra work to support this 98 100 * too. 99 101 */ 100 - return __vmalloc_node_range(size, 1, start, end, GFP_KERNEL, PAGE_KERNEL_EXEC, 102 + return __vmalloc_node_range(size, 1, start, end, GFP_KERNEL, prot, 101 103 VM_FLUSH_RESET_PERMS | VM_NO_HUGE_VMAP, 102 104 NUMA_NO_NODE, __builtin_return_address(0)); 103 105 }
+6 -13
arch/powerpc/kernel/module_32.c
··· 145 145 146 146 static inline int entry_matches(struct ppc_plt_entry *entry, Elf32_Addr val) 147 147 { 148 - if (entry->jump[0] != (PPC_INST_ADDIS | __PPC_RT(R12) | PPC_HA(val))) 148 + if (entry->jump[0] != PPC_RAW_LIS(_R12, PPC_HA(val))) 149 149 return 0; 150 - if (entry->jump[1] != (PPC_INST_ADDI | __PPC_RT(R12) | __PPC_RA(R12) | 151 - PPC_LO(val))) 150 + if (entry->jump[1] != PPC_RAW_ADDI(_R12, _R12, PPC_LO(val))) 152 151 return 0; 153 152 return 1; 154 153 } ··· 174 175 entry++; 175 176 } 176 177 177 - /* 178 - * lis r12, sym@ha 179 - * addi r12, r12, sym@l 180 - * mtctr r12 181 - * bctr 182 - */ 183 - entry->jump[0] = PPC_INST_ADDIS | __PPC_RT(R12) | PPC_HA(val); 184 - entry->jump[1] = PPC_INST_ADDI | __PPC_RT(R12) | __PPC_RA(R12) | PPC_LO(val); 185 - entry->jump[2] = PPC_INST_MTCTR | __PPC_RS(R12); 186 - entry->jump[3] = PPC_INST_BCTR; 178 + entry->jump[0] = PPC_RAW_LIS(_R12, PPC_HA(val)); 179 + entry->jump[1] = PPC_RAW_ADDI(_R12, _R12, PPC_LO(val)); 180 + entry->jump[2] = PPC_RAW_MTCTR(_R12); 181 + entry->jump[3] = PPC_RAW_BCTR(); 187 182 188 183 pr_debug("Initialized plt for 0x%x at %p\n", val, entry); 189 184 return (uint32_t)entry;
+17 -38
arch/powerpc/kernel/module_64.c
··· 122 122 * the stub, but it's significantly shorter to put these values at the 123 123 * end of the stub code, and patch the stub address (32-bits relative 124 124 * to the TOC ptr, r2) into the stub. 125 - * 126 - * addis r11,r2, <high> 127 - * addi r11,r11, <low> 128 - * std r2,R2_STACK_OFFSET(r1) 129 - * ld r12,32(r11) 130 - * ld r2,40(r11) 131 - * mtctr r12 132 - * bctr 133 125 */ 134 126 static u32 ppc64_stub_insns[] = { 135 - PPC_INST_ADDIS | __PPC_RT(R11) | __PPC_RA(R2), 136 - PPC_INST_ADDI | __PPC_RT(R11) | __PPC_RA(R11), 127 + PPC_RAW_ADDIS(_R11, _R2, 0), 128 + PPC_RAW_ADDI(_R11, _R11, 0), 137 129 /* Save current r2 value in magic place on the stack. */ 138 - PPC_INST_STD | __PPC_RS(R2) | __PPC_RA(R1) | R2_STACK_OFFSET, 139 - PPC_INST_LD | __PPC_RT(R12) | __PPC_RA(R11) | 32, 130 + PPC_RAW_STD(_R2, _R1, R2_STACK_OFFSET), 131 + PPC_RAW_LD(_R12, _R11, 32), 140 132 #ifdef PPC64_ELF_ABI_v1 141 133 /* Set up new r2 from function descriptor */ 142 - PPC_INST_LD | __PPC_RT(R2) | __PPC_RA(R11) | 40, 134 + PPC_RAW_LD(_R2, _R11, 40), 143 135 #endif 144 - PPC_INST_MTCTR | __PPC_RS(R12), 145 - PPC_INST_BCTR, 136 + PPC_RAW_MTCTR(_R12), 137 + PPC_RAW_BCTR(), 146 138 }; 147 139 148 140 /* Count how many different 24-bit relocations (different symbol, ··· 328 336 329 337 #ifdef CONFIG_MPROFILE_KERNEL 330 338 331 - #define PACATOC offsetof(struct paca_struct, kernel_toc) 332 - 333 - /* 334 - * ld r12,PACATOC(r13) 335 - * addis r12,r12,<high> 336 - * addi r12,r12,<low> 337 - * mtctr r12 338 - * bctr 339 - */ 340 339 static u32 stub_insns[] = { 341 - PPC_INST_LD | __PPC_RT(R12) | __PPC_RA(R13) | PACATOC, 342 - PPC_INST_ADDIS | __PPC_RT(R12) | __PPC_RA(R12), 343 - PPC_INST_ADDI | __PPC_RT(R12) | __PPC_RA(R12), 344 - PPC_INST_MTCTR | __PPC_RS(R12), 345 - PPC_INST_BCTR, 340 + PPC_RAW_LD(_R12, _R13, offsetof(struct paca_struct, kernel_toc)), 341 + PPC_RAW_ADDIS(_R12, _R12, 0), 342 + PPC_RAW_ADDI(_R12, _R12, 0), 343 + PPC_RAW_MTCTR(_R12), 344 + PPC_RAW_BCTR(), 346 345 }; 347 346 348 347 /* ··· 490 507 if (!instr_is_relative_link_branch(ppc_inst(*prev_insn))) 491 508 return 1; 492 509 493 - if (*instruction != PPC_INST_NOP) { 510 + if (*instruction != PPC_RAW_NOP()) { 494 511 pr_err("%s: Expected nop after call, got %08x at %pS\n", 495 512 me->name, *instruction, instruction); 496 513 return 0; ··· 679 696 * ld r2, ...(r12) 680 697 * add r2, r2, r12 681 698 */ 682 - if ((((uint32_t *)location)[0] & ~0xfffc) != 683 - (PPC_INST_LD | __PPC_RT(R2) | __PPC_RA(R12))) 699 + if ((((uint32_t *)location)[0] & ~0xfffc) != PPC_RAW_LD(_R2, _R12, 0)) 684 700 break; 685 - if (((uint32_t *)location)[1] != 686 - (PPC_INST_ADD | __PPC_RT(R2) | __PPC_RA(R2) | __PPC_RB(R12))) 701 + if (((uint32_t *)location)[1] != PPC_RAW_ADD(_R2, _R2, _R12)) 687 702 break; 688 703 /* 689 704 * If found, replace it with: 690 705 * addis r2, r12, (.TOC.-func)@ha 691 706 * addi r2, r2, (.TOC.-func)@l 692 707 */ 693 - ((uint32_t *)location)[0] = PPC_INST_ADDIS | __PPC_RT(R2) | 694 - __PPC_RA(R12) | PPC_HA(value); 695 - ((uint32_t *)location)[1] = PPC_INST_ADDI | __PPC_RT(R2) | 696 - __PPC_RA(R2) | PPC_LO(value); 708 + ((uint32_t *)location)[0] = PPC_RAW_ADDIS(_R2, _R12, PPC_HA(value)); 709 + ((uint32_t *)location)[1] = PPC_RAW_ADDI(_R2, _R2, PPC_LO(value)); 697 710 break; 698 711 699 712 case R_PPC64_REL16_HA:
+50 -105
arch/powerpc/kernel/optprobes.c
··· 18 18 #include <asm/ppc-opcode.h> 19 19 #include <asm/inst.h> 20 20 21 - #define TMPL_CALL_HDLR_IDX \ 22 - (optprobe_template_call_handler - optprobe_template_entry) 23 - #define TMPL_EMULATE_IDX \ 24 - (optprobe_template_call_emulate - optprobe_template_entry) 25 - #define TMPL_RET_IDX \ 26 - (optprobe_template_ret - optprobe_template_entry) 27 - #define TMPL_OP_IDX \ 28 - (optprobe_template_op_address - optprobe_template_entry) 29 - #define TMPL_INSN_IDX \ 30 - (optprobe_template_insn - optprobe_template_entry) 31 - #define TMPL_END_IDX \ 32 - (optprobe_template_end - optprobe_template_entry) 33 - 34 - DEFINE_INSN_CACHE_OPS(ppc_optinsn); 21 + #define TMPL_CALL_HDLR_IDX (optprobe_template_call_handler - optprobe_template_entry) 22 + #define TMPL_EMULATE_IDX (optprobe_template_call_emulate - optprobe_template_entry) 23 + #define TMPL_RET_IDX (optprobe_template_ret - optprobe_template_entry) 24 + #define TMPL_OP_IDX (optprobe_template_op_address - optprobe_template_entry) 25 + #define TMPL_INSN_IDX (optprobe_template_insn - optprobe_template_entry) 26 + #define TMPL_END_IDX (optprobe_template_end - optprobe_template_entry) 35 27 36 28 static bool insn_page_in_use; 37 29 38 - static void *__ppc_alloc_insn_page(void) 30 + void *alloc_optinsn_page(void) 39 31 { 40 32 if (insn_page_in_use) 41 33 return NULL; ··· 35 43 return &optinsn_slot; 36 44 } 37 45 38 - static void __ppc_free_insn_page(void *page __maybe_unused) 46 + void free_optinsn_page(void *page) 39 47 { 40 48 insn_page_in_use = false; 41 49 } 42 - 43 - struct kprobe_insn_cache kprobe_ppc_optinsn_slots = { 44 - .mutex = __MUTEX_INITIALIZER(kprobe_ppc_optinsn_slots.mutex), 45 - .pages = LIST_HEAD_INIT(kprobe_ppc_optinsn_slots.pages), 46 - /* insn_size initialized later */ 47 - .alloc = __ppc_alloc_insn_page, 48 - .free = __ppc_free_insn_page, 49 - .nr_garbage = 0, 50 - }; 51 50 52 51 /* 53 52 * Check if we can optimize this probe. Returns NIP post-emulation if this can ··· 49 66 struct pt_regs regs; 50 67 struct instruction_op op; 51 68 unsigned long nip = 0; 69 + unsigned long addr = (unsigned long)p->addr; 52 70 53 71 /* 54 72 * kprobe placed for kretprobe during boot time ··· 57 73 * So further checks can be skipped. 58 74 */ 59 75 if (p->addr == (kprobe_opcode_t *)&kretprobe_trampoline) 60 - return (unsigned long)p->addr + sizeof(kprobe_opcode_t); 76 + return addr + sizeof(kprobe_opcode_t); 61 77 62 78 /* 63 79 * We only support optimizing kernel addresses, but not ··· 65 81 * 66 82 * FIXME: Optimize kprobes placed in module addresses. 67 83 */ 68 - if (!is_kernel_addr((unsigned long)p->addr)) 84 + if (!is_kernel_addr(addr)) 69 85 return 0; 70 86 71 87 memset(&regs, 0, sizeof(struct pt_regs)); 72 - regs.nip = (unsigned long)p->addr; 88 + regs.nip = addr; 73 89 regs.trap = 0x0; 74 90 regs.msr = MSR_KERNEL; 75 91 ··· 84 100 * Ensure that the instruction is not a conditional branch, 85 101 * and that can be emulated. 86 102 */ 87 - if (!is_conditional_branch(ppc_inst_read((struct ppc_inst *)p->ainsn.insn)) && 88 - analyse_instr(&op, &regs, 89 - ppc_inst_read((struct ppc_inst *)p->ainsn.insn)) == 1) { 103 + if (!is_conditional_branch(ppc_inst_read(p->ainsn.insn)) && 104 + analyse_instr(&op, &regs, ppc_inst_read(p->ainsn.insn)) == 1) { 90 105 emulate_update_regs(&regs, &op); 91 106 nip = regs.nip; 92 107 } ··· 106 123 kprobes_inc_nmissed_count(&op->kp); 107 124 } else { 108 125 __this_cpu_write(current_kprobe, &op->kp); 109 - regs->nip = (unsigned long)op->kp.addr; 126 + regs_set_return_ip(regs, (unsigned long)op->kp.addr); 110 127 get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE; 111 128 opt_pre_handler(&op->kp, regs); 112 129 __this_cpu_write(current_kprobe, NULL); ··· 119 136 void arch_remove_optimized_kprobe(struct optimized_kprobe *op) 120 137 { 121 138 if (op->optinsn.insn) { 122 - free_ppc_optinsn_slot(op->optinsn.insn, 1); 139 + free_optinsn_slot(op->optinsn.insn, 1); 123 140 op->optinsn.insn = NULL; 124 141 } 125 142 } 126 143 127 144 static void patch_imm32_load_insns(unsigned long val, int reg, kprobe_opcode_t *addr) 128 145 { 129 - patch_instruction((struct ppc_inst *)addr, 130 - ppc_inst(PPC_RAW_LIS(reg, IMM_H(val)))); 131 - addr++; 132 - 133 - patch_instruction((struct ppc_inst *)addr, 134 - ppc_inst(PPC_RAW_ORI(reg, reg, IMM_L(val)))); 146 + patch_instruction(addr++, ppc_inst(PPC_RAW_LIS(reg, PPC_HI(val)))); 147 + patch_instruction(addr, ppc_inst(PPC_RAW_ORI(reg, reg, PPC_LO(val)))); 135 148 } 136 149 137 150 /* ··· 136 157 */ 137 158 static void patch_imm64_load_insns(unsigned long long val, int reg, kprobe_opcode_t *addr) 138 159 { 139 - /* lis reg,(op)@highest */ 140 - patch_instruction((struct ppc_inst *)addr, 141 - ppc_inst(PPC_INST_ADDIS | ___PPC_RT(reg) | 142 - ((val >> 48) & 0xffff))); 143 - addr++; 144 - 145 - /* ori reg,reg,(op)@higher */ 146 - patch_instruction((struct ppc_inst *)addr, 147 - ppc_inst(PPC_INST_ORI | ___PPC_RA(reg) | 148 - ___PPC_RS(reg) | ((val >> 32) & 0xffff))); 149 - addr++; 150 - 151 - /* rldicr reg,reg,32,31 */ 152 - patch_instruction((struct ppc_inst *)addr, 153 - ppc_inst(PPC_INST_RLDICR | ___PPC_RA(reg) | 154 - ___PPC_RS(reg) | __PPC_SH64(32) | __PPC_ME64(31))); 155 - addr++; 156 - 157 - /* oris reg,reg,(op)@h */ 158 - patch_instruction((struct ppc_inst *)addr, 159 - ppc_inst(PPC_INST_ORIS | ___PPC_RA(reg) | 160 - ___PPC_RS(reg) | ((val >> 16) & 0xffff))); 161 - addr++; 162 - 163 - /* ori reg,reg,(op)@l */ 164 - patch_instruction((struct ppc_inst *)addr, 165 - ppc_inst(PPC_INST_ORI | ___PPC_RA(reg) | 166 - ___PPC_RS(reg) | (val & 0xffff))); 160 + patch_instruction(addr++, ppc_inst(PPC_RAW_LIS(reg, PPC_HIGHEST(val)))); 161 + patch_instruction(addr++, ppc_inst(PPC_RAW_ORI(reg, reg, PPC_HIGHER(val)))); 162 + patch_instruction(addr++, ppc_inst(PPC_RAW_SLDI(reg, reg, 32))); 163 + patch_instruction(addr++, ppc_inst(PPC_RAW_ORIS(reg, reg, PPC_HI(val)))); 164 + patch_instruction(addr, ppc_inst(PPC_RAW_ORI(reg, reg, PPC_LO(val)))); 167 165 } 168 166 169 167 static void patch_imm_load_insns(unsigned long val, int reg, kprobe_opcode_t *addr) ··· 154 198 int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *p) 155 199 { 156 200 struct ppc_inst branch_op_callback, branch_emulate_step, temp; 157 - kprobe_opcode_t *op_callback_addr, *emulate_step_addr, *buff; 201 + unsigned long op_callback_addr, emulate_step_addr; 202 + kprobe_opcode_t *buff; 158 203 long b_offset; 159 204 unsigned long nip, size; 160 205 int rc, i; 161 - 162 - kprobe_ppc_optinsn_slots.insn_size = MAX_OPTINSN_SIZE; 163 206 164 207 nip = can_optimize(p); 165 208 if (!nip) 166 209 return -EILSEQ; 167 210 168 211 /* Allocate instruction slot for detour buffer */ 169 - buff = get_ppc_optinsn_slot(); 212 + buff = get_optinsn_slot(); 170 213 if (!buff) 171 214 return -ENOMEM; 172 215 ··· 183 228 goto error; 184 229 185 230 /* Check if the return address is also within 32MB range */ 186 - b_offset = (unsigned long)(buff + TMPL_RET_IDX) - 187 - (unsigned long)nip; 231 + b_offset = (unsigned long)(buff + TMPL_RET_IDX) - nip; 188 232 if (!is_offset_in_branch_range(b_offset)) 189 233 goto error; 190 234 ··· 192 238 size = (TMPL_END_IDX * sizeof(kprobe_opcode_t)) / sizeof(int); 193 239 pr_devel("Copying template to %p, size %lu\n", buff, size); 194 240 for (i = 0; i < size; i++) { 195 - rc = patch_instruction((struct ppc_inst *)(buff + i), 196 - ppc_inst(*(optprobe_template_entry + i))); 241 + rc = patch_instruction(buff + i, ppc_inst(*(optprobe_template_entry + i))); 197 242 if (rc < 0) 198 243 goto error; 199 244 } ··· 206 253 /* 207 254 * 2. branch to optimized_callback() and emulate_step() 208 255 */ 209 - op_callback_addr = (kprobe_opcode_t *)ppc_kallsyms_lookup_name("optimized_callback"); 210 - emulate_step_addr = (kprobe_opcode_t *)ppc_kallsyms_lookup_name("emulate_step"); 256 + op_callback_addr = ppc_kallsyms_lookup_name("optimized_callback"); 257 + emulate_step_addr = ppc_kallsyms_lookup_name("emulate_step"); 211 258 if (!op_callback_addr || !emulate_step_addr) { 212 259 WARN(1, "Unable to lookup optimized_callback()/emulate_step()\n"); 213 260 goto error; 214 261 } 215 262 216 - rc = create_branch(&branch_op_callback, 217 - (struct ppc_inst *)(buff + TMPL_CALL_HDLR_IDX), 218 - (unsigned long)op_callback_addr, 219 - BRANCH_SET_LINK); 263 + rc = create_branch(&branch_op_callback, buff + TMPL_CALL_HDLR_IDX, 264 + op_callback_addr, BRANCH_SET_LINK); 220 265 221 - rc |= create_branch(&branch_emulate_step, 222 - (struct ppc_inst *)(buff + TMPL_EMULATE_IDX), 223 - (unsigned long)emulate_step_addr, 224 - BRANCH_SET_LINK); 266 + rc |= create_branch(&branch_emulate_step, buff + TMPL_EMULATE_IDX, 267 + emulate_step_addr, BRANCH_SET_LINK); 225 268 226 269 if (rc) 227 270 goto error; 228 271 229 - patch_instruction((struct ppc_inst *)(buff + TMPL_CALL_HDLR_IDX), 230 - branch_op_callback); 231 - patch_instruction((struct ppc_inst *)(buff + TMPL_EMULATE_IDX), 232 - branch_emulate_step); 272 + patch_instruction(buff + TMPL_CALL_HDLR_IDX, branch_op_callback); 273 + patch_instruction(buff + TMPL_EMULATE_IDX, branch_emulate_step); 233 274 234 275 /* 235 276 * 3. load instruction to be emulated into relevant register, and 236 277 */ 237 - temp = ppc_inst_read((struct ppc_inst *)p->ainsn.insn); 238 - patch_imm_load_insns(ppc_inst_as_ulong(temp), 4, buff + TMPL_INSN_IDX); 278 + if (IS_ENABLED(CONFIG_PPC64)) { 279 + temp = ppc_inst_read(p->ainsn.insn); 280 + patch_imm_load_insns(ppc_inst_as_ulong(temp), 4, buff + TMPL_INSN_IDX); 281 + } else { 282 + patch_imm_load_insns((unsigned long)p->ainsn.insn, 4, buff + TMPL_INSN_IDX); 283 + } 239 284 240 285 /* 241 286 * 4. branch back from trampoline 242 287 */ 243 - patch_branch((struct ppc_inst *)(buff + TMPL_RET_IDX), (unsigned long)nip, 0); 288 + patch_branch(buff + TMPL_RET_IDX, nip, 0); 244 289 245 - flush_icache_range((unsigned long)buff, 246 - (unsigned long)(&buff[TMPL_END_IDX])); 290 + flush_icache_range((unsigned long)buff, (unsigned long)(&buff[TMPL_END_IDX])); 247 291 248 292 op->optinsn.insn = buff; 249 293 250 294 return 0; 251 295 252 296 error: 253 - free_ppc_optinsn_slot(buff, 0); 297 + free_optinsn_slot(buff, 0); 254 298 return -ERANGE; 255 299 256 300 } ··· 278 328 * Backup instructions which will be replaced 279 329 * by jump address 280 330 */ 281 - memcpy(op->optinsn.copied_insn, op->kp.addr, 282 - RELATIVEJUMP_SIZE); 283 - create_branch(&instr, 284 - (struct ppc_inst *)op->kp.addr, 285 - (unsigned long)op->optinsn.insn, 0); 286 - patch_instruction((struct ppc_inst *)op->kp.addr, instr); 331 + memcpy(op->optinsn.copied_insn, op->kp.addr, RELATIVEJUMP_SIZE); 332 + create_branch(&instr, op->kp.addr, (unsigned long)op->optinsn.insn, 0); 333 + patch_instruction(op->kp.addr, instr); 287 334 list_del_init(&op->list); 288 335 } 289 336 } ··· 290 343 arch_arm_kprobe(&op->kp); 291 344 } 292 345 293 - void arch_unoptimize_kprobes(struct list_head *oplist, 294 - struct list_head *done_list) 346 + void arch_unoptimize_kprobes(struct list_head *oplist, struct list_head *done_list) 295 347 { 296 348 struct optimized_kprobe *op; 297 349 struct optimized_kprobe *tmp; ··· 301 355 } 302 356 } 303 357 304 - int arch_within_optimized_kprobe(struct optimized_kprobe *op, 305 - unsigned long addr) 358 + int arch_within_optimized_kprobe(struct optimized_kprobe *op, unsigned long addr) 306 359 { 307 360 return ((unsigned long)op->kp.addr <= addr && 308 361 (unsigned long)op->kp.addr + RELATIVEJUMP_SIZE > addr);
-2
arch/powerpc/kernel/paca.c
··· 346 346 #ifdef CONFIG_PPC_BOOK3S 347 347 mm_context_t *context = &mm->context; 348 348 349 - get_paca()->mm_ctx_id = context->id; 350 349 #ifdef CONFIG_PPC_MM_SLICES 351 350 VM_BUG_ON(!mm_ctx_slb_addr_limit(context)); 352 - get_paca()->mm_ctx_slb_addr_limit = mm_ctx_slb_addr_limit(context); 353 351 memcpy(&get_paca()->mm_ctx_low_slices_psize, mm_ctx_low_slices(context), 354 352 LOW_SLICE_ARRAY_SZ); 355 353 memcpy(&get_paca()->mm_ctx_high_slices_psize, mm_ctx_high_slices(context),
+70 -37
arch/powerpc/kernel/process.c
··· 96 96 if (tsk == current && tsk->thread.regs && 97 97 MSR_TM_ACTIVE(tsk->thread.regs->msr) && 98 98 !test_thread_flag(TIF_RESTORE_TM)) { 99 - tsk->thread.ckpt_regs.msr = tsk->thread.regs->msr; 99 + regs_set_return_msr(&tsk->thread.ckpt_regs, 100 + tsk->thread.regs->msr); 100 101 set_thread_flag(TIF_RESTORE_TM); 101 102 } 102 103 } ··· 162 161 msr &= ~(MSR_FP|MSR_FE0|MSR_FE1); 163 162 if (cpu_has_feature(CPU_FTR_VSX)) 164 163 msr &= ~MSR_VSX; 165 - tsk->thread.regs->msr = msr; 164 + regs_set_return_msr(tsk->thread.regs, msr); 166 165 } 167 166 168 167 void giveup_fpu(struct task_struct *tsk) ··· 245 244 msr &= ~MSR_VEC; 246 245 if (cpu_has_feature(CPU_FTR_VSX)) 247 246 msr &= ~MSR_VSX; 248 - tsk->thread.regs->msr = msr; 247 + regs_set_return_msr(tsk->thread.regs, msr); 249 248 } 250 249 251 250 void giveup_altivec(struct task_struct *tsk) ··· 560 559 561 560 msr_check_and_clear(new_msr); 562 561 563 - regs->msr |= new_msr | fpexc_mode; 562 + regs_set_return_msr(regs, regs->msr | new_msr | fpexc_mode); 564 563 } 565 564 } 566 565 #endif /* CONFIG_PPC_BOOK3S_64 */ ··· 1115 1114 #endif 1116 1115 restore_math(regs); 1117 1116 1118 - regs->msr |= msr_diff; 1117 + regs_set_return_msr(regs, regs->msr | msr_diff); 1119 1118 } 1120 1119 1121 1120 #else /* !CONFIG_PPC_TRANSACTIONAL_MEM */ ··· 1129 1128 #ifdef CONFIG_ALTIVEC 1130 1129 if (cpu_has_feature(CPU_FTR_ALTIVEC)) 1131 1130 t->vrsave = mfspr(SPRN_VRSAVE); 1131 + #endif 1132 + #ifdef CONFIG_SPE 1133 + if (cpu_has_feature(CPU_FTR_SPE)) 1134 + t->spefscr = mfspr(SPRN_SPEFSCR); 1132 1135 #endif 1133 1136 #ifdef CONFIG_PPC_BOOK3S_64 1134 1137 if (cpu_has_feature(CPU_FTR_DSCR)) ··· 1163 1158 if (cpu_has_feature(CPU_FTR_ALTIVEC) && 1164 1159 old_thread->vrsave != new_thread->vrsave) 1165 1160 mtspr(SPRN_VRSAVE, new_thread->vrsave); 1161 + #endif 1162 + #ifdef CONFIG_SPE 1163 + if (cpu_has_feature(CPU_FTR_SPE) && 1164 + old_thread->spefscr != new_thread->spefscr) 1165 + mtspr(SPRN_SPEFSCR, new_thread->spefscr); 1166 1166 #endif 1167 1167 #ifdef CONFIG_PPC_BOOK3S_64 1168 1168 if (cpu_has_feature(CPU_FTR_DSCR)) { ··· 1223 1213 __flush_tlb_pending(batch); 1224 1214 batch->active = 0; 1225 1215 } 1216 + 1217 + /* 1218 + * On POWER9 the copy-paste buffer can only paste into 1219 + * foreign real addresses, so unprivileged processes can not 1220 + * see the data or use it in any way unless they have 1221 + * foreign real mappings. If the new process has the foreign 1222 + * real address mappings, we must issue a cp_abort to clear 1223 + * any state and prevent snooping, corruption or a covert 1224 + * channel. ISA v3.1 supports paste into local memory. 1225 + */ 1226 + if (new->mm && (cpu_has_feature(CPU_FTR_ARCH_31) || 1227 + atomic_read(&new->mm->context.vas_windows))) 1228 + asm volatile(PPC_CP_ABORT); 1226 1229 #endif /* CONFIG_PPC_BOOK3S_64 */ 1227 1230 1228 1231 #ifdef CONFIG_PPC_ADV_DEBUG_REGS ··· 1271 1248 } 1272 1249 1273 1250 /* 1274 - * Call restore_sprs() before calling _switch(). If we move it after 1275 - * _switch() then we miss out on calling it for new tasks. The reason 1276 - * for this is we manually create a stack frame for new tasks that 1277 - * directly returns through ret_from_fork() or 1251 + * Call restore_sprs() and set_return_regs_changed() before calling 1252 + * _switch(). If we move it after _switch() then we miss out on calling 1253 + * it for new tasks. The reason for this is we manually create a stack 1254 + * frame for new tasks that directly returns through ret_from_fork() or 1278 1255 * ret_from_kernel_thread(). See copy_thread() for details. 1279 1256 */ 1280 1257 restore_sprs(old_thread, new_thread); 1258 + 1259 + set_return_regs_changed(); /* _switch changes stack (and regs) */ 1281 1260 1282 1261 #ifdef CONFIG_PPC32 1283 1262 kuap_assert_locked(); 1284 1263 #endif 1285 1264 last = _switch(old_thread, new_thread); 1286 1265 1266 + /* 1267 + * Nothing after _switch will be run for newly created tasks, 1268 + * because they switch directly to ret_from_fork/ret_from_kernel_thread 1269 + * etc. Code added here should have a comment explaining why that is 1270 + * okay. 1271 + */ 1272 + 1287 1273 #ifdef CONFIG_PPC_BOOK3S_64 1274 + /* 1275 + * This applies to a process that was context switched while inside 1276 + * arch_enter_lazy_mmu_mode(), to re-activate the batch that was 1277 + * deactivated above, before _switch(). This will never be the case 1278 + * for new tasks. 1279 + */ 1288 1280 if (current_thread_info()->local_flags & _TLF_LAZY_MMU) { 1289 1281 current_thread_info()->local_flags &= ~_TLF_LAZY_MMU; 1290 1282 batch = this_cpu_ptr(&ppc64_tlb_batch); 1291 1283 batch->active = 1; 1292 1284 } 1293 1285 1294 - if (current->thread.regs) { 1286 + /* 1287 + * Math facilities are masked out of the child MSR in copy_thread. 1288 + * A new task does not need to restore_math because it will 1289 + * demand fault them. 1290 + */ 1291 + if (current->thread.regs) 1295 1292 restore_math(current->thread.regs); 1296 - 1297 - /* 1298 - * On POWER9 the copy-paste buffer can only paste into 1299 - * foreign real addresses, so unprivileged processes can not 1300 - * see the data or use it in any way unless they have 1301 - * foreign real mappings. If the new process has the foreign 1302 - * real address mappings, we must issue a cp_abort to clear 1303 - * any state and prevent snooping, corruption or a covert 1304 - * channel. ISA v3.1 supports paste into local memory. 1305 - */ 1306 - if (current->mm && 1307 - (cpu_has_feature(CPU_FTR_ARCH_31) || 1308 - atomic_read(&current->mm->context.vas_windows))) 1309 - asm volatile(PPC_CP_ABORT); 1310 - } 1311 1293 #endif /* CONFIG_PPC_BOOK3S_64 */ 1312 1294 1313 1295 return last; ··· 1764 1736 #ifdef CONFIG_ALTIVEC 1765 1737 p->thread.vr_save_area = NULL; 1766 1738 #endif 1739 + #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP) 1740 + p->thread.kuap = KUAP_NONE; 1741 + #endif 1767 1742 1768 1743 setup_ksp_vsid(p, sp); 1769 1744 ··· 1869 1838 } 1870 1839 regs->gpr[2] = toc; 1871 1840 } 1872 - regs->nip = entry; 1873 - regs->msr = MSR_USER64; 1841 + regs_set_return_ip(regs, entry); 1842 + regs_set_return_msr(regs, MSR_USER64); 1874 1843 } else { 1875 - regs->nip = start; 1876 1844 regs->gpr[2] = 0; 1877 - regs->msr = MSR_USER32; 1845 + regs_set_return_ip(regs, start); 1846 + regs_set_return_msr(regs, MSR_USER32); 1878 1847 } 1848 + 1879 1849 #endif 1880 1850 #ifdef CONFIG_VSX 1881 1851 current->thread.used_vsr = 0; ··· 1907 1875 current->thread.tm_tfiar = 0; 1908 1876 current->thread.load_tm = 0; 1909 1877 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 1910 - 1911 1878 } 1912 1879 EXPORT_SYMBOL(start_thread); 1913 1880 ··· 1954 1923 if (val > PR_FP_EXC_PRECISE) 1955 1924 return -EINVAL; 1956 1925 tsk->thread.fpexc_mode = __pack_fe01(val); 1957 - if (regs != NULL && (regs->msr & MSR_FP) != 0) 1958 - regs->msr = (regs->msr & ~(MSR_FE0|MSR_FE1)) 1959 - | tsk->thread.fpexc_mode; 1926 + if (regs != NULL && (regs->msr & MSR_FP) != 0) { 1927 + regs_set_return_msr(regs, (regs->msr & ~(MSR_FE0|MSR_FE1)) 1928 + | tsk->thread.fpexc_mode); 1929 + } 1960 1930 return 0; 1961 1931 } 1962 1932 ··· 2003 1971 return -EINVAL; 2004 1972 2005 1973 if (val == PR_ENDIAN_BIG) 2006 - regs->msr &= ~MSR_LE; 1974 + regs_set_return_msr(regs, regs->msr & ~MSR_LE); 2007 1975 else if (val == PR_ENDIAN_LITTLE || val == PR_ENDIAN_PPC_LITTLE) 2008 - regs->msr |= MSR_LE; 1976 + regs_set_return_msr(regs, regs->msr | MSR_LE); 2009 1977 else 2010 1978 return -EINVAL; 2011 1979 ··· 2153 2121 2154 2122 static int kstack_depth_to_print = CONFIG_PRINT_STACK_DEPTH; 2155 2123 2156 - void show_stack(struct task_struct *tsk, unsigned long *stack, 2157 - const char *loglvl) 2124 + void __no_sanitize_address show_stack(struct task_struct *tsk, 2125 + unsigned long *stack, 2126 + const char *loglvl) 2158 2127 { 2159 2128 unsigned long sp, ip, lr, newsp; 2160 2129 int count = 0;
+1 -1
arch/powerpc/kernel/prom.c
··· 758 758 first_memblock_size = min_t(u64, first_memblock_size, memory_limit); 759 759 setup_initial_memory_limit(memstart_addr, first_memblock_size); 760 760 /* Reserve MEMBLOCK regions used by kernel, initrd, dt, etc... */ 761 - memblock_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START); 761 + memblock_reserve(PHYSICAL_START, __pa(_end) - PHYSICAL_START); 762 762 /* If relocatable, reserve first 32k for interrupt vectors etc. */ 763 763 if (PHYSICAL_START > MEMORY_START) 764 764 memblock_reserve(MEMORY_START, 0x8000);
+50 -71
arch/powerpc/kernel/prom_init.c
··· 27 27 #include <linux/initrd.h> 28 28 #include <linux/bitops.h> 29 29 #include <linux/pgtable.h> 30 + #include <linux/printk.h> 30 31 #include <asm/prom.h> 31 32 #include <asm/rtas.h> 32 33 #include <asm/page.h> 33 34 #include <asm/processor.h> 35 + #include <asm/interrupt.h> 34 36 #include <asm/irq.h> 35 37 #include <asm/io.h> 36 38 #include <asm/smp.h> ··· 244 242 return 0; 245 243 } 246 244 247 - static char __init *prom_strcpy(char *dest, const char *src) 245 + static ssize_t __init prom_strscpy_pad(char *dest, const char *src, size_t n) 248 246 { 249 - char *tmp = dest; 247 + ssize_t rc; 248 + size_t i; 250 249 251 - while ((*dest++ = *src++) != '\0') 252 - /* nothing */; 253 - return tmp; 250 + if (n == 0 || n > INT_MAX) 251 + return -E2BIG; 252 + 253 + // Copy up to n bytes 254 + for (i = 0; i < n && src[i] != '\0'; i++) 255 + dest[i] = src[i]; 256 + 257 + rc = i; 258 + 259 + // If we copied all n then we have run out of space for the nul 260 + if (rc == n) { 261 + // Rewind by one character to ensure nul termination 262 + i--; 263 + rc = -E2BIG; 264 + } 265 + 266 + for (; i < n; i++) 267 + dest[i] = '\0'; 268 + 269 + return rc; 254 270 } 255 271 256 272 static int __init prom_strncmp(const char *cs, const char *ct, size_t count) ··· 721 701 } 722 702 723 703 /* We can't use the standard versions because of relocation headaches. */ 724 - #define isxdigit(c) (('0' <= (c) && (c) <= '9') \ 725 - || ('a' <= (c) && (c) <= 'f') \ 726 - || ('A' <= (c) && (c) <= 'F')) 704 + #define prom_isxdigit(c) \ 705 + (('0' <= (c) && (c) <= '9') || ('a' <= (c) && (c) <= 'f') || ('A' <= (c) && (c) <= 'F')) 727 706 728 - #define isdigit(c) ('0' <= (c) && (c) <= '9') 729 - #define islower(c) ('a' <= (c) && (c) <= 'z') 730 - #define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c)) 707 + #define prom_isdigit(c) ('0' <= (c) && (c) <= '9') 708 + #define prom_islower(c) ('a' <= (c) && (c) <= 'z') 709 + #define prom_toupper(c) (prom_islower(c) ? ((c) - 'a' + 'A') : (c)) 731 710 732 711 static unsigned long prom_strtoul(const char *cp, const char **endp) 733 712 { ··· 735 716 if (*cp == '0') { 736 717 base = 8; 737 718 cp++; 738 - if (toupper(*cp) == 'X') { 719 + if (prom_toupper(*cp) == 'X') { 739 720 cp++; 740 721 base = 16; 741 722 } 742 723 } 743 724 744 - while (isxdigit(*cp) && 745 - (value = isdigit(*cp) ? *cp - '0' : toupper(*cp) - 'A' + 10) < base) { 725 + while (prom_isxdigit(*cp) && 726 + (value = prom_isdigit(*cp) ? *cp - '0' : prom_toupper(*cp) - 'A' + 10) < base) { 746 727 result = result * base + value; 747 728 cp++; 748 729 } ··· 946 927 u8 os_name; 947 928 } __packed; 948 929 930 + struct option_vector7 { 931 + u8 os_id[256]; 932 + } __packed; 933 + 949 934 struct ibm_arch_vec { 950 935 struct { u32 mask, val; } pvrs[14]; 951 936 ··· 972 949 973 950 u8 vec6_len; 974 951 struct option_vector6 vec6; 952 + 953 + u8 vec7_len; 954 + struct option_vector7 vec7; 975 955 } __packed; 976 956 977 957 static const struct ibm_arch_vec ibm_architecture_vec_template __initconst = { ··· 1121 1095 .secondary_pteg = 0, 1122 1096 .os_name = OV6_LINUX, 1123 1097 }, 1098 + 1099 + /* option vector 7: OS Identification */ 1100 + .vec7_len = VECTOR_LENGTH(sizeof(struct option_vector7)), 1124 1101 }; 1125 1102 1126 1103 static struct ibm_arch_vec __prombss ibm_architecture_vec ____cacheline_aligned; ··· 1351 1322 */ 1352 1323 memcpy(&ibm_architecture_vec, &ibm_architecture_vec_template, 1353 1324 sizeof(ibm_architecture_vec)); 1325 + 1326 + prom_strscpy_pad(ibm_architecture_vec.vec7.os_id, linux_banner, 256); 1354 1327 1355 1328 if (prop_len > 1) { 1356 1329 int i; ··· 1793 1762 asm volatile("sc 1\n" : "=r" (arg1) : 1794 1763 "r" (arg1), 1795 1764 "r" (arg2) :); 1765 + srr_regs_clobbered(); 1766 + 1796 1767 return arg1; 1797 1768 } 1798 1769 ··· 2735 2702 2736 2703 /* Add "phandle" in there, we'll need it */ 2737 2704 namep = make_room(&mem_start, &mem_end, 16, 1); 2738 - prom_strcpy(namep, "phandle"); 2705 + prom_strscpy_pad(namep, "phandle", sizeof("phandle")); 2739 2706 mem_start = (unsigned long)namep + prom_strlen(namep) + 1; 2740 2707 2741 2708 /* Build string array */ ··· 3243 3210 #endif /* CONFIG_BLK_DEV_INITRD */ 3244 3211 } 3245 3212 3246 - #ifdef CONFIG_PPC64 3247 - #ifdef CONFIG_RELOCATABLE 3248 - static void reloc_toc(void) 3249 - { 3250 - } 3251 - 3252 - static void unreloc_toc(void) 3253 - { 3254 - } 3255 - #else 3256 - static void __reloc_toc(unsigned long offset, unsigned long nr_entries) 3257 - { 3258 - unsigned long i; 3259 - unsigned long *toc_entry; 3260 - 3261 - /* Get the start of the TOC by using r2 directly. */ 3262 - asm volatile("addi %0,2,-0x8000" : "=b" (toc_entry)); 3263 - 3264 - for (i = 0; i < nr_entries; i++) { 3265 - *toc_entry = *toc_entry + offset; 3266 - toc_entry++; 3267 - } 3268 - } 3269 - 3270 - static void reloc_toc(void) 3271 - { 3272 - unsigned long offset = reloc_offset(); 3273 - unsigned long nr_entries = 3274 - (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long); 3275 - 3276 - __reloc_toc(offset, nr_entries); 3277 - 3278 - mb(); 3279 - } 3280 - 3281 - static void unreloc_toc(void) 3282 - { 3283 - unsigned long offset = reloc_offset(); 3284 - unsigned long nr_entries = 3285 - (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long); 3286 - 3287 - mb(); 3288 - 3289 - __reloc_toc(-offset, nr_entries); 3290 - } 3291 - #endif 3292 - #endif 3293 - 3294 3213 #ifdef CONFIG_PPC_SVM 3295 3214 /* 3296 3215 * Perform the Enter Secure Mode ultracall. ··· 3276 3291 * relocated it so the check will fail. Restore the original image by 3277 3292 * relocating it back to the kernel virtual base address. 3278 3293 */ 3279 - if (IS_ENABLED(CONFIG_RELOCATABLE)) 3280 - relocate(KERNELBASE); 3294 + relocate(KERNELBASE); 3281 3295 3282 3296 ret = enter_secure_mode(kbase, fdt); 3283 3297 3284 3298 /* Relocate the kernel again. */ 3285 - if (IS_ENABLED(CONFIG_RELOCATABLE)) 3286 - relocate(kbase); 3299 + relocate(kbase); 3287 3300 3288 3301 if (ret != U_SUCCESS) { 3289 3302 prom_printf("Returned %d from switching to secure mode.\n", ret); ··· 3309 3326 #ifdef CONFIG_PPC32 3310 3327 unsigned long offset = reloc_offset(); 3311 3328 reloc_got2(offset); 3312 - #else 3313 - reloc_toc(); 3314 3329 #endif 3315 3330 3316 3331 /* ··· 3485 3504 3486 3505 #ifdef CONFIG_PPC32 3487 3506 reloc_got2(-offset); 3488 - #else 3489 - unreloc_toc(); 3490 3507 #endif 3491 3508 3492 3509 /* Move to secure memory if we're supposed to be secure guests. */
+11 -9
arch/powerpc/kernel/ptrace/ptrace-adv.c
··· 12 12 if (regs != NULL) { 13 13 task->thread.debug.dbcr0 &= ~DBCR0_BT; 14 14 task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; 15 - regs->msr |= MSR_DE; 15 + regs_set_return_msr(regs, regs->msr | MSR_DE); 16 16 } 17 17 set_tsk_thread_flag(task, TIF_SINGLESTEP); 18 18 } ··· 24 24 if (regs != NULL) { 25 25 task->thread.debug.dbcr0 &= ~DBCR0_IC; 26 26 task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT; 27 - regs->msr |= MSR_DE; 27 + regs_set_return_msr(regs, regs->msr | MSR_DE); 28 28 } 29 29 set_tsk_thread_flag(task, TIF_SINGLESTEP); 30 30 } ··· 50 50 * All debug events were off..... 51 51 */ 52 52 task->thread.debug.dbcr0 &= ~DBCR0_IDM; 53 - regs->msr &= ~MSR_DE; 53 + regs_set_return_msr(regs, regs->msr & ~MSR_DE); 54 54 } 55 55 } 56 56 clear_tsk_thread_flag(task, TIF_SINGLESTEP); ··· 82 82 83 83 int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned long data) 84 84 { 85 + struct pt_regs *regs = task->thread.regs; 85 86 #ifdef CONFIG_HAVE_HW_BREAKPOINT 86 87 int ret; 87 88 struct thread_struct *thread = &task->thread; ··· 113 112 dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W); 114 113 if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, 115 114 task->thread.debug.dbcr1)) { 116 - task->thread.regs->msr &= ~MSR_DE; 115 + regs_set_return_msr(regs, regs->msr & ~MSR_DE); 117 116 task->thread.debug.dbcr0 &= ~DBCR0_IDM; 118 117 } 119 118 return 0; ··· 133 132 dbcr_dac(task) |= DBCR_DAC1R; 134 133 if (data & 0x2UL) 135 134 dbcr_dac(task) |= DBCR_DAC1W; 136 - task->thread.regs->msr |= MSR_DE; 135 + regs_set_return_msr(regs, regs->msr | MSR_DE); 137 136 return 0; 138 137 } 139 138 ··· 221 220 } 222 221 out: 223 222 child->thread.debug.dbcr0 |= DBCR0_IDM; 224 - child->thread.regs->msr |= MSR_DE; 223 + regs_set_return_msr(child->thread.regs, child->thread.regs->msr | MSR_DE); 225 224 226 225 return slot; 227 226 } ··· 337 336 return -ENOSPC; 338 337 } 339 338 child->thread.debug.dbcr0 |= DBCR0_IDM; 340 - child->thread.regs->msr |= MSR_DE; 339 + regs_set_return_msr(child->thread.regs, child->thread.regs->msr | MSR_DE); 341 340 342 341 return slot + 4; 343 342 } ··· 431 430 child->thread.debug.dbcr2 |= DBCR2_DAC12MX; 432 431 else /* PPC_BREAKPOINT_MODE_MASK */ 433 432 child->thread.debug.dbcr2 |= DBCR2_DAC12MM; 434 - child->thread.regs->msr |= MSR_DE; 433 + regs_set_return_msr(child->thread.regs, child->thread.regs->msr | MSR_DE); 435 434 436 435 return 5; 437 436 } ··· 486 485 if (!DBCR_ACTIVE_EVENTS(child->thread.debug.dbcr0, 487 486 child->thread.debug.dbcr1)) { 488 487 child->thread.debug.dbcr0 &= ~DBCR0_IDM; 489 - child->thread.regs->msr &= ~MSR_DE; 488 + regs_set_return_msr(child->thread.regs, 489 + child->thread.regs->msr & ~MSR_DE); 490 490 } 491 491 } 492 492 return rc;
+5 -9
arch/powerpc/kernel/ptrace/ptrace-noadv.c
··· 11 11 { 12 12 struct pt_regs *regs = task->thread.regs; 13 13 14 - if (regs != NULL) { 15 - regs->msr &= ~MSR_BE; 16 - regs->msr |= MSR_SE; 17 - } 14 + if (regs != NULL) 15 + regs_set_return_msr(regs, (regs->msr & ~MSR_BE) | MSR_SE); 18 16 set_tsk_thread_flag(task, TIF_SINGLESTEP); 19 17 } 20 18 ··· 20 22 { 21 23 struct pt_regs *regs = task->thread.regs; 22 24 23 - if (regs != NULL) { 24 - regs->msr &= ~MSR_SE; 25 - regs->msr |= MSR_BE; 26 - } 25 + if (regs != NULL) 26 + regs_set_return_msr(regs, (regs->msr & ~MSR_SE) | MSR_BE); 27 27 set_tsk_thread_flag(task, TIF_SINGLESTEP); 28 28 } 29 29 ··· 30 34 struct pt_regs *regs = task->thread.regs; 31 35 32 36 if (regs != NULL) 33 - regs->msr &= ~(MSR_SE | MSR_BE); 37 + regs_set_return_msr(regs, regs->msr & ~(MSR_SE | MSR_BE)); 34 38 35 39 clear_tsk_thread_flag(task, TIF_SINGLESTEP); 36 40 }
+3 -2
arch/powerpc/kernel/ptrace/ptrace-view.c
··· 113 113 114 114 static __always_inline int set_user_msr(struct task_struct *task, unsigned long msr) 115 115 { 116 - task->thread.regs->msr &= ~MSR_DEBUGCHANGE; 117 - task->thread.regs->msr |= msr & MSR_DEBUGCHANGE; 116 + unsigned long newmsr = (task->thread.regs->msr & ~MSR_DEBUGCHANGE) | 117 + (msr & MSR_DEBUGCHANGE); 118 + regs_set_return_msr(task->thread.regs, newmsr); 118 119 return 0; 119 120 } 120 121
+1 -1
arch/powerpc/kernel/rtas-rtc.c
··· 12 12 13 13 14 14 #define MAX_RTC_WAIT 5000 /* 5 sec */ 15 - #define RTAS_CLOCK_BUSY (-2) 15 + 16 16 time64_t __init rtas_get_boot_time(void) 17 17 { 18 18 int ret[8];
+11 -3
arch/powerpc/kernel/rtas.c
··· 25 25 #include <linux/reboot.h> 26 26 #include <linux/syscalls.h> 27 27 28 + #include <asm/interrupt.h> 28 29 #include <asm/prom.h> 29 30 #include <asm/rtas.h> 30 31 #include <asm/hvcall.h> ··· 46 45 47 46 /* This is here deliberately so it's only used in this file */ 48 47 void enter_rtas(unsigned long); 48 + 49 + static inline void do_enter_rtas(unsigned long args) 50 + { 51 + enter_rtas(args); 52 + 53 + srr_regs_clobbered(); /* rtas uses SRRs, invalidate */ 54 + } 49 55 50 56 struct rtas_t rtas = { 51 57 .lock = __ARCH_SPIN_LOCK_UNLOCKED ··· 392 384 save_args = rtas.args; 393 385 rtas.args = err_args; 394 386 395 - enter_rtas(__pa(&rtas.args)); 387 + do_enter_rtas(__pa(&rtas.args)); 396 388 397 389 err_args = rtas.args; 398 390 rtas.args = save_args; ··· 438 430 for (i = 0; i < nret; ++i) 439 431 args->rets[i] = 0; 440 432 441 - enter_rtas(__pa(args)); 433 + do_enter_rtas(__pa(args)); 442 434 } 443 435 444 436 void rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret, ...) ··· 1146 1138 flags = lock_rtas(); 1147 1139 1148 1140 rtas.args = args; 1149 - enter_rtas(__pa(&rtas.args)); 1141 + do_enter_rtas(__pa(&rtas.args)); 1150 1142 args = rtas.args; 1151 1143 1152 1144 /* A -1 return code indicates that the last command couldn't
+9 -12
arch/powerpc/kernel/security.c
··· 300 300 void setup_stf_barrier(void) 301 301 { 302 302 enum stf_barrier_type type; 303 - bool enable, hv; 304 - 305 - hv = cpu_has_feature(CPU_FTR_HVMODE); 303 + bool enable; 306 304 307 305 /* Default to fallback in case fw-features are not available */ 308 306 if (cpu_has_feature(CPU_FTR_ARCH_300)) ··· 313 315 type = STF_BARRIER_NONE; 314 316 315 317 enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && 316 - (security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR) || 317 - (security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) && hv)); 318 + security_ftr_enabled(SEC_FTR_STF_BARRIER); 318 319 319 320 if (type == STF_BARRIER_FALLBACK) { 320 321 pr_info("stf-barrier: fallback barrier available\n"); ··· 436 439 site2 = &patch__call_kvm_flush_link_stack_p9; 437 440 // This controls the branch from guest_exit_cont to kvm_flush_link_stack 438 441 if (link_stack_flush_type == BRANCH_CACHE_FLUSH_NONE) { 439 - patch_instruction_site(site, ppc_inst(PPC_INST_NOP)); 440 - patch_instruction_site(site2, ppc_inst(PPC_INST_NOP)); 442 + patch_instruction_site(site, ppc_inst(PPC_RAW_NOP())); 443 + patch_instruction_site(site2, ppc_inst(PPC_RAW_NOP())); 441 444 } else { 442 445 // Could use HW flush, but that could also flush count cache 443 446 patch_branch_site(site, (u64)&kvm_flush_link_stack, BRANCH_SET_LINK); ··· 447 450 448 451 // Patch out the bcctr first, then nop the rest 449 452 site = &patch__call_flush_branch_caches3; 450 - patch_instruction_site(site, ppc_inst(PPC_INST_NOP)); 453 + patch_instruction_site(site, ppc_inst(PPC_RAW_NOP())); 451 454 site = &patch__call_flush_branch_caches2; 452 - patch_instruction_site(site, ppc_inst(PPC_INST_NOP)); 455 + patch_instruction_site(site, ppc_inst(PPC_RAW_NOP())); 453 456 site = &patch__call_flush_branch_caches1; 454 - patch_instruction_site(site, ppc_inst(PPC_INST_NOP)); 457 + patch_instruction_site(site, ppc_inst(PPC_RAW_NOP())); 455 458 456 459 // This controls the branch from _switch to flush_branch_caches 457 460 if (count_cache_flush_type == BRANCH_CACHE_FLUSH_NONE && ··· 474 477 // If we just need to flush the link stack, early return 475 478 if (count_cache_flush_type == BRANCH_CACHE_FLUSH_NONE) { 476 479 patch_instruction_site(&patch__flush_link_stack_return, 477 - ppc_inst(PPC_INST_BLR)); 480 + ppc_inst(PPC_RAW_BLR())); 478 481 479 482 // If we have flush instruction, early return 480 483 } else if (count_cache_flush_type == BRANCH_CACHE_FLUSH_HW) { 481 484 patch_instruction_site(&patch__flush_count_cache_return, 482 - ppc_inst(PPC_INST_BLR)); 485 + ppc_inst(PPC_RAW_BLR())); 483 486 } 484 487 } 485 488 }
+1 -3
arch/powerpc/kernel/setup-common.c
··· 92 92 int dcache_bsize; 93 93 int icache_bsize; 94 94 95 - unsigned long klimit = (unsigned long) _end; 96 - 97 95 /* 98 96 * This still seems to be needed... -- paulus 99 97 */ ··· 929 931 init_mm.start_code = (unsigned long)_stext; 930 932 init_mm.end_code = (unsigned long) _etext; 931 933 init_mm.end_data = (unsigned long) _edata; 932 - init_mm.brk = klimit; 934 + init_mm.brk = (unsigned long)_end; 933 935 934 936 mm_iommu_init(&init_mm); 935 937 irqstack_early_init();
+2 -2
arch/powerpc/kernel/setup_32.c
··· 74 74 */ 75 75 notrace void __init machine_init(u64 dt_ptr) 76 76 { 77 - struct ppc_inst *addr = (struct ppc_inst *)patch_site_addr(&patch__memset_nocache); 77 + u32 *addr = (u32 *)patch_site_addr(&patch__memset_nocache); 78 78 struct ppc_inst insn; 79 79 80 80 /* Configure static keys first, now that we're relocated. */ ··· 85 85 /* Enable early debugging if any specified (see udbg.h) */ 86 86 udbg_early_init(); 87 87 88 - patch_instruction_site(&patch__memcpy_nocache, ppc_inst(PPC_INST_NOP)); 88 + patch_instruction_site(&patch__memcpy_nocache, ppc_inst(PPC_RAW_NOP())); 89 89 90 90 create_cond_branch(&insn, addr, branch_target(addr), 0x820000); 91 91 patch_instruction(addr, insn); /* replace b by bne cr0 */
+9 -4
arch/powerpc/kernel/setup_64.c
··· 33 33 #include <linux/pgtable.h> 34 34 35 35 #include <asm/debugfs.h> 36 + #include <asm/kvm_guest.h> 36 37 #include <asm/io.h> 37 38 #include <asm/kdump.h> 38 39 #include <asm/prom.h> ··· 940 939 * disable it by default. Book3S has a soft-nmi hardlockup detector based 941 940 * on the decrementer interrupt, so it does not suffer from this problem. 942 941 * 943 - * It is likely to get false positives in VM guests, so disable it there 944 - * by default too. 942 + * It is likely to get false positives in KVM guests, so disable it there 943 + * by default too. PowerVM will not stop or arbitrarily oversubscribe 944 + * CPUs, but give a minimum regular allotment even with SPLPAR, so enable 945 + * the detector for non-KVM guests, assume PowerVM. 945 946 */ 946 947 static int __init disable_hardlockup_detector(void) 947 948 { 948 949 #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF 949 950 hardlockup_detector_disable(); 950 951 #else 951 - if (firmware_has_feature(FW_FEATURE_LPAR)) 952 - hardlockup_detector_disable(); 952 + if (firmware_has_feature(FW_FEATURE_LPAR)) { 953 + if (is_kvm_guest()) 954 + hardlockup_detector_disable(); 955 + } 953 956 #endif 954 957 955 958 return 0;
+6 -6
arch/powerpc/kernel/signal.c
··· 214 214 regs->gpr[0] = __NR_restart_syscall; 215 215 else 216 216 regs->gpr[3] = regs->orig_gpr3; 217 - regs->nip -= 4; 217 + regs_add_return_ip(regs, -4); 218 218 regs->result = 0; 219 219 } else { 220 220 if (trap_is_scv(regs)) { ··· 322 322 * For signals taken in non-TM or suspended mode, we use the 323 323 * normal/non-checkpointed stack pointer. 324 324 */ 325 - 326 - unsigned long ret = tsk->thread.regs->gpr[1]; 325 + struct pt_regs *regs = tsk->thread.regs; 326 + unsigned long ret = regs->gpr[1]; 327 327 328 328 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 329 329 BUG_ON(tsk != current); 330 330 331 - if (MSR_TM_ACTIVE(tsk->thread.regs->msr)) { 331 + if (MSR_TM_ACTIVE(regs->msr)) { 332 332 preempt_disable(); 333 333 tm_reclaim_current(TM_CAUSE_SIGNAL); 334 - if (MSR_TM_TRANSACTIONAL(tsk->thread.regs->msr)) 334 + if (MSR_TM_TRANSACTIONAL(regs->msr)) 335 335 ret = tsk->thread.ckpt_regs.gpr[1]; 336 336 337 337 /* ··· 341 341 * (tm_recheckpoint_new_task() would recheckpoint). Besides, we 342 342 * enter the signal handler in non-transactional state. 343 343 */ 344 - tsk->thread.regs->msr &= ~MSR_TS_MASK; 344 + regs_set_return_msr(regs, regs->msr & ~MSR_TS_MASK); 345 345 preempt_enable(); 346 346 } 347 347 #endif
+24 -82
arch/powerpc/kernel/signal_32.c
··· 354 354 { 355 355 WARN_ON(tm_suspend_disabled); 356 356 357 - #ifdef CONFIG_ALTIVEC 358 357 if (cpu_has_feature(CPU_FTR_ALTIVEC)) 359 358 current->thread.ckvrsave = mfspr(SPRN_VRSAVE); 360 - #endif 361 - #ifdef CONFIG_SPE 362 - if (current->thread.used_spe) 363 - flush_spe_to_thread(current); 364 - #endif 365 359 } 366 360 367 361 static int save_tm_user_regs_unsafe(struct pt_regs *regs, struct mcontext __user *frame, ··· 373 379 */ 374 380 unsafe_put_user((msr >> 32), &tm_frame->mc_gregs[PT_MSR], failed); 375 381 376 - #ifdef CONFIG_ALTIVEC 377 382 /* save altivec registers */ 378 383 if (current->thread.used_vr) { 379 384 unsafe_copy_to_user(&frame->mc_vregs, &current->thread.ckvr_state, ··· 405 412 else 406 413 unsafe_put_user(current->thread.ckvrsave, 407 414 (u32 __user *)&tm_frame->mc_vregs[32], failed); 408 - #endif /* CONFIG_ALTIVEC */ 409 415 410 416 unsafe_copy_ckfpr_to_user(&frame->mc_fregs, current, failed); 411 417 if (msr & MSR_FP) ··· 412 420 else 413 421 unsafe_copy_ckfpr_to_user(&tm_frame->mc_fregs, current, failed); 414 422 415 - #ifdef CONFIG_VSX 416 423 /* 417 424 * Copy VSR 0-31 upper half from thread_struct to local 418 425 * buffer, then write that to userspace. Also set MSR_VSX in ··· 427 436 428 437 msr |= MSR_VSX; 429 438 } 430 - #endif /* CONFIG_VSX */ 431 - #ifdef CONFIG_SPE 432 - /* SPE regs are not checkpointed with TM, so this section is 433 - * simply the same as in __unsafe_save_user_regs(). 434 - */ 435 - if (current->thread.used_spe) { 436 - unsafe_copy_to_user(&frame->mc_vregs, current->thread.evr, 437 - ELF_NEVRREG * sizeof(u32), failed); 438 - /* set MSR_SPE in the saved MSR value to indicate that 439 - * frame->mc_vregs contains valid data */ 440 - msr |= MSR_SPE; 441 - } 442 - 443 - /* We always copy to/from spefscr */ 444 - unsafe_put_user(current->thread.spefscr, 445 - (u32 __user *)&frame->mc_vregs + ELF_NEVRREG, failed); 446 - #endif /* CONFIG_SPE */ 447 439 448 440 unsafe_put_user(msr, &frame->mc_gregs[PT_MSR], failed); 449 441 ··· 479 505 480 506 /* if doing signal return, restore the previous little-endian mode */ 481 507 if (sig) 482 - regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE); 508 + regs_set_return_msr(regs, (regs->msr & ~MSR_LE) | (msr & MSR_LE)); 483 509 484 510 #ifdef CONFIG_ALTIVEC 485 511 /* 486 512 * Force the process to reload the altivec registers from 487 513 * current->thread when it next does altivec instructions 488 514 */ 489 - regs->msr &= ~MSR_VEC; 515 + regs_set_return_msr(regs, regs->msr & ~MSR_VEC); 490 516 if (msr & MSR_VEC) { 491 517 /* restore altivec registers from the stack */ 492 518 unsafe_copy_from_user(&current->thread.vr_state, &sr->mc_vregs, ··· 508 534 * Force the process to reload the VSX registers from 509 535 * current->thread when it next does VSX instruction. 510 536 */ 511 - regs->msr &= ~MSR_VSX; 537 + regs_set_return_msr(regs, regs->msr & ~MSR_VSX); 512 538 if (msr & MSR_VSX) { 513 539 /* 514 540 * Restore altivec registers from the stack to a local ··· 524 550 * force the process to reload the FP registers from 525 551 * current->thread when it next does FP instructions 526 552 */ 527 - regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1); 553 + regs_set_return_msr(regs, regs->msr & ~(MSR_FP | MSR_FE0 | MSR_FE1)); 528 554 529 555 #ifdef CONFIG_SPE 530 556 /* force the process to reload the spe registers from 531 557 current->thread when it next does spe instructions */ 532 - regs->msr &= ~MSR_SPE; 558 + regs_set_return_msr(regs, regs->msr & ~MSR_SPE); 533 559 if (msr & MSR_SPE) { 534 560 /* restore spe registers from the stack */ 535 561 unsafe_copy_from_user(current->thread.evr, &sr->mc_vregs, ··· 561 587 struct mcontext __user *tm_sr) 562 588 { 563 589 unsigned long msr, msr_hi; 564 - #ifdef CONFIG_VSX 565 590 int i; 566 - #endif 567 591 568 592 if (tm_suspend_disabled) 569 593 return 1; ··· 580 608 unsafe_get_user(msr, &sr->mc_gregs[PT_MSR], failed); 581 609 582 610 /* Restore the previous little-endian mode */ 583 - regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE); 611 + regs_set_return_msr(regs, (regs->msr & ~MSR_LE) | (msr & MSR_LE)); 584 612 585 - #ifdef CONFIG_ALTIVEC 586 - regs->msr &= ~MSR_VEC; 613 + regs_set_return_msr(regs, regs->msr & ~MSR_VEC); 587 614 if (msr & MSR_VEC) { 588 615 /* restore altivec registers from the stack */ 589 616 unsafe_copy_from_user(&current->thread.ckvr_state, &sr->mc_vregs, ··· 600 629 (u32 __user *)&sr->mc_vregs[32], failed); 601 630 if (cpu_has_feature(CPU_FTR_ALTIVEC)) 602 631 mtspr(SPRN_VRSAVE, current->thread.ckvrsave); 603 - #endif /* CONFIG_ALTIVEC */ 604 632 605 - regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1); 633 + regs_set_return_msr(regs, regs->msr & ~(MSR_FP | MSR_FE0 | MSR_FE1)); 606 634 607 635 unsafe_copy_fpr_from_user(current, &sr->mc_fregs, failed); 608 636 609 - #ifdef CONFIG_VSX 610 - regs->msr &= ~MSR_VSX; 637 + regs_set_return_msr(regs, regs->msr & ~MSR_VSX); 611 638 if (msr & MSR_VSX) { 612 639 /* 613 640 * Restore altivec registers from the stack to a local ··· 618 649 current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = 0; 619 650 current->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET] = 0; 620 651 } 621 - #endif /* CONFIG_VSX */ 622 - 623 - #ifdef CONFIG_SPE 624 - /* SPE regs are not checkpointed with TM, so this section is 625 - * simply the same as in restore_user_regs(). 626 - */ 627 - regs->msr &= ~MSR_SPE; 628 - if (msr & MSR_SPE) { 629 - unsafe_copy_from_user(current->thread.evr, &sr->mc_vregs, 630 - ELF_NEVRREG * sizeof(u32), failed); 631 - current->thread.used_spe = true; 632 - } else if (current->thread.used_spe) 633 - memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32)); 634 - 635 - /* Always get SPEFSCR back */ 636 - unsafe_get_user(current->thread.spefscr, 637 - (u32 __user *)&sr->mc_vregs + ELF_NEVRREG, failed); 638 - #endif /* CONFIG_SPE */ 639 652 640 653 user_read_access_end(); 641 654 ··· 626 675 627 676 unsafe_restore_general_regs(regs, tm_sr, failed); 628 677 629 - #ifdef CONFIG_ALTIVEC 630 678 /* restore altivec registers from the stack */ 631 679 if (msr & MSR_VEC) 632 680 unsafe_copy_from_user(&current->thread.vr_state, &tm_sr->mc_vregs, ··· 634 684 /* Always get VRSAVE back */ 635 685 unsafe_get_user(current->thread.vrsave, 636 686 (u32 __user *)&tm_sr->mc_vregs[32], failed); 637 - #endif /* CONFIG_ALTIVEC */ 638 687 639 688 unsafe_copy_ckfpr_from_user(current, &tm_sr->mc_fregs, failed); 640 689 641 - #ifdef CONFIG_VSX 642 690 if (msr & MSR_VSX) { 643 691 /* 644 692 * Restore altivec registers from the stack to a local ··· 645 697 unsafe_copy_vsx_from_user(current, &tm_sr->mc_vsregs, failed); 646 698 current->thread.used_vsr = true; 647 699 } 648 - #endif /* CONFIG_VSX */ 649 700 650 701 /* Get the top half of the MSR from the user context */ 651 702 unsafe_get_user(msr_hi, &tm_sr->mc_gregs[PT_MSR], failed); ··· 672 725 * 673 726 * Pull in the MSR TM bits from the user context 674 727 */ 675 - regs->msr = (regs->msr & ~MSR_TS_MASK) | (msr_hi & MSR_TS_MASK); 728 + regs_set_return_msr(regs, (regs->msr & ~MSR_TS_MASK) | (msr_hi & MSR_TS_MASK)); 676 729 /* Now, recheckpoint. This loads up all of the checkpointed (older) 677 730 * registers, including FP and V[S]Rs. After recheckpointing, the 678 731 * transactional versions should be loaded. ··· 687 740 msr_check_and_set(msr & (MSR_FP | MSR_VEC)); 688 741 if (msr & MSR_FP) { 689 742 load_fp_state(&current->thread.fp_state); 690 - regs->msr |= (MSR_FP | current->thread.fpexc_mode); 743 + regs_set_return_msr(regs, regs->msr | (MSR_FP | current->thread.fpexc_mode)); 691 744 } 692 - #ifdef CONFIG_ALTIVEC 693 745 if (msr & MSR_VEC) { 694 746 load_vr_state(&current->thread.vr_state); 695 - regs->msr |= MSR_VEC; 747 + regs_set_return_msr(regs, regs->msr | MSR_VEC); 696 748 } 697 - #endif 698 749 699 750 preempt_enable(); 700 751 ··· 773 828 tramp = VDSO32_SYMBOL(tsk->mm->context.vdso, sigtramp_rt32); 774 829 } else { 775 830 tramp = (unsigned long)mctx->mc_pad; 776 - /* Set up the sigreturn trampoline: li r0,sigret; sc */ 777 - unsafe_put_user(PPC_INST_ADDI + __NR_rt_sigreturn, &mctx->mc_pad[0], 778 - failed); 779 - unsafe_put_user(PPC_INST_SC, &mctx->mc_pad[1], failed); 831 + unsafe_put_user(PPC_RAW_LI(_R0, __NR_rt_sigreturn), &mctx->mc_pad[0], failed); 832 + unsafe_put_user(PPC_RAW_SC(), &mctx->mc_pad[1], failed); 780 833 asm("dcbst %y0; sync; icbi %y0; sync" :: "Z" (mctx->mc_pad[0])); 781 834 } 782 835 unsafe_put_sigset_t(&frame->uc.uc_sigmask, oldset, failed); ··· 801 858 regs->gpr[4] = (unsigned long)&frame->info; 802 859 regs->gpr[5] = (unsigned long)&frame->uc; 803 860 regs->gpr[6] = (unsigned long)frame; 804 - regs->nip = (unsigned long) ksig->ka.sa.sa_handler; 861 + regs_set_return_ip(regs, (unsigned long) ksig->ka.sa.sa_handler); 805 862 /* enter the signal handler in native-endian mode */ 806 - regs->msr &= ~MSR_LE; 807 - regs->msr |= (MSR_KERNEL & MSR_LE); 863 + regs_set_return_msr(regs, (regs->msr & ~MSR_LE) | (MSR_KERNEL & MSR_LE)); 864 + 808 865 return 0; 809 866 810 867 failed: ··· 869 926 tramp = VDSO32_SYMBOL(tsk->mm->context.vdso, sigtramp32); 870 927 } else { 871 928 tramp = (unsigned long)mctx->mc_pad; 872 - /* Set up the sigreturn trampoline: li r0,sigret; sc */ 873 - unsafe_put_user(PPC_INST_ADDI + __NR_sigreturn, &mctx->mc_pad[0], failed); 874 - unsafe_put_user(PPC_INST_SC, &mctx->mc_pad[1], failed); 929 + unsafe_put_user(PPC_RAW_LI(_R0, __NR_sigreturn), &mctx->mc_pad[0], failed); 930 + unsafe_put_user(PPC_RAW_SC(), &mctx->mc_pad[1], failed); 875 931 asm("dcbst %y0; sync; icbi %y0; sync" :: "Z" (mctx->mc_pad[0])); 876 932 } 877 933 user_access_end(); ··· 889 947 regs->gpr[1] = newsp; 890 948 regs->gpr[3] = ksig->sig; 891 949 regs->gpr[4] = (unsigned long) sc; 892 - regs->nip = (unsigned long)ksig->ka.sa.sa_handler; 950 + regs_set_return_ip(regs, (unsigned long) ksig->ka.sa.sa_handler); 893 951 /* enter the signal handler in native-endian mode */ 894 - regs->msr &= ~MSR_LE; 895 - regs->msr |= (MSR_KERNEL & MSR_LE); 952 + regs_set_return_msr(regs, (regs->msr & ~MSR_LE) | (MSR_KERNEL & MSR_LE)); 953 + 896 954 return 0; 897 955 898 956 failed: ··· 1142 1200 * set, and recheckpoint was not called. This avoid 1143 1201 * hitting a TM Bad thing at RFID 1144 1202 */ 1145 - regs->msr &= ~MSR_TS_MASK; 1203 + regs_set_return_msr(regs, regs->msr & ~MSR_TS_MASK); 1146 1204 } 1147 1205 /* Fall through, for non-TM restore */ 1148 1206 #endif ··· 1231 1289 affect the contents of these registers. After this point, 1232 1290 failure is a problem, anyway, and it's very unlikely unless 1233 1291 the user is really doing something wrong. */ 1234 - regs->msr = new_msr; 1292 + regs_set_return_msr(regs, new_msr); 1235 1293 #ifdef CONFIG_PPC_ADV_DEBUG_REGS 1236 1294 current->thread.debug.dbcr0 = new_dbcr0; 1237 1295 #endif
+24 -25
arch/powerpc/kernel/signal_64.c
··· 354 354 /* get MSR separately, transfer the LE bit if doing signal return */ 355 355 unsafe_get_user(msr, &sc->gp_regs[PT_MSR], efault_out); 356 356 if (sig) 357 - regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE); 357 + regs_set_return_msr(regs, (regs->msr & ~MSR_LE) | (msr & MSR_LE)); 358 358 unsafe_get_user(regs->orig_gpr3, &sc->gp_regs[PT_ORIG_R3], efault_out); 359 359 unsafe_get_user(regs->ctr, &sc->gp_regs[PT_CTR], efault_out); 360 360 unsafe_get_user(regs->link, &sc->gp_regs[PT_LNK], efault_out); ··· 376 376 * This has to be done before copying stuff into tsk->thread.fpr/vr 377 377 * for the reasons explained in the previous comment. 378 378 */ 379 - regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC | MSR_VSX); 379 + regs_set_return_msr(regs, regs->msr & ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC | MSR_VSX)); 380 380 381 381 #ifdef CONFIG_ALTIVEC 382 382 unsafe_get_user(v_regs, &sc->v_regs, efault_out); ··· 468 468 return -EINVAL; 469 469 470 470 /* pull in MSR LE from user context */ 471 - regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE); 471 + regs_set_return_msr(regs, (regs->msr & ~MSR_LE) | (msr & MSR_LE)); 472 472 473 473 /* The following non-GPR non-FPR non-VR state is also checkpointed: */ 474 474 err |= __get_user(regs->ctr, &tm_sc->gp_regs[PT_CTR]); ··· 495 495 * This has to be done before copying stuff into tsk->thread.fpr/vr 496 496 * for the reasons explained in the previous comment. 497 497 */ 498 - regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC | MSR_VSX); 498 + regs_set_return_msr(regs, regs->msr & ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC | MSR_VSX)); 499 499 500 500 #ifdef CONFIG_ALTIVEC 501 501 err |= __get_user(v_regs, &sc->v_regs); ··· 565 565 preempt_disable(); 566 566 567 567 /* pull in MSR TS bits from user context */ 568 - regs->msr |= msr & MSR_TS_MASK; 568 + regs_set_return_msr(regs, regs->msr | (msr & MSR_TS_MASK)); 569 569 570 570 /* 571 571 * Ensure that TM is enabled in regs->msr before we leave the signal ··· 583 583 * to be de-scheduled with MSR[TS] set but without calling 584 584 * tm_recheckpoint(). This can cause a bug. 585 585 */ 586 - regs->msr |= MSR_TM; 586 + regs_set_return_msr(regs, regs->msr | MSR_TM); 587 587 588 588 /* This loads the checkpointed FP/VEC state, if used */ 589 589 tm_recheckpoint(&tsk->thread); ··· 591 591 msr_check_and_set(msr & (MSR_FP | MSR_VEC)); 592 592 if (msr & MSR_FP) { 593 593 load_fp_state(&tsk->thread.fp_state); 594 - regs->msr |= (MSR_FP | tsk->thread.fpexc_mode); 594 + regs_set_return_msr(regs, regs->msr | (MSR_FP | tsk->thread.fpexc_mode)); 595 595 } 596 596 if (msr & MSR_VEC) { 597 597 load_vr_state(&tsk->thread.vr_state); 598 - regs->msr |= MSR_VEC; 598 + regs_set_return_msr(regs, regs->msr | MSR_VEC); 599 599 } 600 600 601 601 preempt_enable(); ··· 618 618 int i; 619 619 long err = 0; 620 620 621 - /* bctrl # call the handler */ 622 - err |= __put_user(PPC_INST_BCTRL, &tramp[0]); 623 - /* addi r1, r1, __SIGNAL_FRAMESIZE # Pop the dummy stackframe */ 624 - err |= __put_user(PPC_INST_ADDI | __PPC_RT(R1) | __PPC_RA(R1) | 625 - (__SIGNAL_FRAMESIZE & 0xffff), &tramp[1]); 626 - /* li r0, __NR_[rt_]sigreturn| */ 627 - err |= __put_user(PPC_INST_ADDI | (syscall & 0xffff), &tramp[2]); 628 - /* sc */ 629 - err |= __put_user(PPC_INST_SC, &tramp[3]); 621 + /* Call the handler and pop the dummy stackframe*/ 622 + err |= __put_user(PPC_RAW_BCTRL(), &tramp[0]); 623 + err |= __put_user(PPC_RAW_ADDI(_R1, _R1, __SIGNAL_FRAMESIZE), &tramp[1]); 624 + 625 + err |= __put_user(PPC_RAW_LI(_R0, syscall), &tramp[2]); 626 + err |= __put_user(PPC_RAW_SC(), &tramp[3]); 630 627 631 628 /* Minimal traceback info */ 632 629 for (i=TRAMP_TRACEBACK; i < TRAMP_SIZE ;i++) ··· 717 720 718 721 /* This returns like rt_sigreturn */ 719 722 set_thread_flag(TIF_RESTOREALL); 723 + 720 724 return 0; 721 725 722 726 efault_out: ··· 784 786 * the MSR[TS] that came from user context later, at 785 787 * restore_tm_sigcontexts. 786 788 */ 787 - regs->msr &= ~MSR_TS_MASK; 789 + regs_set_return_msr(regs, regs->msr & ~MSR_TS_MASK); 788 790 789 791 if (__get_user(msr, &uc->uc_mcontext.gp_regs[PT_MSR])) 790 792 goto badframe; ··· 816 818 * MSR[TS] set, but without CPU in the proper state, 817 819 * causing a TM bad thing. 818 820 */ 819 - current->thread.regs->msr &= ~MSR_TS_MASK; 821 + regs_set_return_msr(current->thread.regs, 822 + current->thread.regs->msr & ~MSR_TS_MASK); 820 823 if (!user_read_access_begin(&uc->uc_mcontext, sizeof(uc->uc_mcontext))) 821 824 goto badframe; 822 825 ··· 831 832 goto badframe; 832 833 833 834 set_thread_flag(TIF_RESTOREALL); 835 + 834 836 return 0; 835 837 836 838 badframe_block: ··· 911 911 912 912 /* Set up to return from userspace. */ 913 913 if (tsk->mm->context.vdso) { 914 - regs->nip = VDSO64_SYMBOL(tsk->mm->context.vdso, sigtramp_rt64); 914 + regs_set_return_ip(regs, VDSO64_SYMBOL(tsk->mm->context.vdso, sigtramp_rt64)); 915 915 } else { 916 916 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]); 917 917 if (err) 918 918 goto badframe; 919 - regs->nip = (unsigned long) &frame->tramp[0]; 919 + regs_set_return_ip(regs, (unsigned long) &frame->tramp[0]); 920 920 } 921 921 922 922 /* Allocate a dummy caller frame for the signal handler. */ ··· 941 941 } 942 942 943 943 /* enter the signal handler in native-endian mode */ 944 - regs->msr &= ~MSR_LE; 945 - regs->msr |= (MSR_KERNEL & MSR_LE); 944 + regs_set_return_msr(regs, (regs->msr & ~MSR_LE) | (MSR_KERNEL & MSR_LE)); 946 945 regs->gpr[1] = newsp; 947 946 regs->gpr[3] = ksig->sig; 948 947 regs->result = 0; 949 948 if (ksig->ka.sa.sa_flags & SA_SIGINFO) { 950 - err |= get_user(regs->gpr[4], (unsigned long __user *)&frame->pinfo); 951 - err |= get_user(regs->gpr[5], (unsigned long __user *)&frame->puc); 949 + regs->gpr[4] = (unsigned long)&frame->info; 950 + regs->gpr[5] = (unsigned long)&frame->uc; 952 951 regs->gpr[6] = (unsigned long) frame; 953 952 } else { 954 953 regs->gpr[4] = (unsigned long)&frame->uc.uc_mcontext;
+15
arch/powerpc/kernel/smp.c
··· 619 619 /* 620 620 * IRQs are already hard disabled by the smp_handle_nmi_ipi. 621 621 */ 622 + set_cpu_online(smp_processor_id(), false); 623 + 622 624 spin_begin(); 623 625 while (1) 624 626 spin_cpu_relax(); ··· 636 634 static void stop_this_cpu(void *dummy) 637 635 { 638 636 hard_irq_disable(); 637 + 638 + /* 639 + * Offlining CPUs in stop_this_cpu can result in scheduler warnings, 640 + * (see commit de6e5d38417e), but printk_safe_flush_on_panic() wants 641 + * to know other CPUs are offline before it breaks locks to flush 642 + * printk buffers, in case we panic()ed while holding the lock. 643 + */ 644 + set_cpu_online(smp_processor_id(), false); 645 + 639 646 spin_begin(); 640 647 while (1) 641 648 spin_cpu_relax(); ··· 1551 1540 void start_secondary(void *unused) 1552 1541 { 1553 1542 unsigned int cpu = raw_smp_processor_id(); 1543 + 1544 + /* PPC64 calls setup_kup() in early_setup_secondary() */ 1545 + if (IS_ENABLED(CONFIG_PPC32)) 1546 + setup_kup(); 1554 1547 1555 1548 mmgrab(&init_mm); 1556 1549 current->active_mm = &init_mm;
+24 -10
arch/powerpc/kernel/stacktrace.c
··· 23 23 24 24 #include <asm/paca.h> 25 25 26 - void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, 27 - struct task_struct *task, struct pt_regs *regs) 26 + void __no_sanitize_address arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, 27 + struct task_struct *task, struct pt_regs *regs) 28 28 { 29 29 unsigned long sp; 30 30 ··· 61 61 * 62 62 * If the task is not 'current', the caller *must* ensure the task is inactive. 63 63 */ 64 - int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry, 65 - void *cookie, struct task_struct *task) 64 + int __no_sanitize_address arch_stack_walk_reliable(stack_trace_consume_fn consume_entry, 65 + void *cookie, struct task_struct *task) 66 66 { 67 67 unsigned long sp; 68 68 unsigned long newsp; ··· 172 172 173 173 static void raise_backtrace_ipi(cpumask_t *mask) 174 174 { 175 + struct paca_struct *p; 175 176 unsigned int cpu; 177 + u64 delay_us; 176 178 177 179 for_each_cpu(cpu, mask) { 178 - if (cpu == smp_processor_id()) 180 + if (cpu == smp_processor_id()) { 179 181 handle_backtrace_ipi(NULL); 180 - else 181 - smp_send_safe_nmi_ipi(cpu, handle_backtrace_ipi, 5 * USEC_PER_SEC); 182 - } 182 + continue; 183 + } 183 184 184 - for_each_cpu(cpu, mask) { 185 - struct paca_struct *p = paca_ptrs[cpu]; 185 + delay_us = 5 * USEC_PER_SEC; 186 + 187 + if (smp_send_safe_nmi_ipi(cpu, handle_backtrace_ipi, delay_us)) { 188 + // Now wait up to 5s for the other CPU to do its backtrace 189 + while (cpumask_test_cpu(cpu, mask) && delay_us) { 190 + udelay(1); 191 + delay_us--; 192 + } 193 + 194 + // Other CPU cleared itself from the mask 195 + if (delay_us) 196 + continue; 197 + } 198 + 199 + p = paca_ptrs[cpu]; 186 200 187 201 cpumask_clear_cpu(cpu, mask); 188 202
+2 -1
arch/powerpc/kernel/syscalls.c
··· 114 114 { 115 115 struct thread_info *ti; 116 116 117 - current->thread.regs->msr ^= MSR_LE; 117 + regs_set_return_msr(current->thread.regs, 118 + current->thread.regs->msr ^ MSR_LE); 118 119 119 120 /* 120 121 * Set TIF_RESTOREALL so that r3 isn't clobbered on return to
+6 -6
arch/powerpc/kernel/sysfs.c
··· 843 843 #ifdef HAS_PPC_PMC_IBM 844 844 case PPC_PMC_IBM: 845 845 attrs = ibm_common_attrs; 846 - nattrs = sizeof(ibm_common_attrs) / sizeof(struct device_attribute); 846 + nattrs = ARRAY_SIZE(ibm_common_attrs); 847 847 pmc_attrs = classic_pmc_attrs; 848 848 break; 849 849 #endif /* HAS_PPC_PMC_IBM */ 850 850 #ifdef HAS_PPC_PMC_G4 851 851 case PPC_PMC_G4: 852 852 attrs = g4_common_attrs; 853 - nattrs = sizeof(g4_common_attrs) / sizeof(struct device_attribute); 853 + nattrs = ARRAY_SIZE(g4_common_attrs); 854 854 pmc_attrs = classic_pmc_attrs; 855 855 break; 856 856 #endif /* HAS_PPC_PMC_G4 */ ··· 858 858 case PPC_PMC_PA6T: 859 859 /* PA Semi starts counting at PMC0 */ 860 860 attrs = pa6t_attrs; 861 - nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute); 861 + nattrs = ARRAY_SIZE(pa6t_attrs); 862 862 pmc_attrs = NULL; 863 863 break; 864 864 #endif ··· 940 940 #ifdef HAS_PPC_PMC_IBM 941 941 case PPC_PMC_IBM: 942 942 attrs = ibm_common_attrs; 943 - nattrs = sizeof(ibm_common_attrs) / sizeof(struct device_attribute); 943 + nattrs = ARRAY_SIZE(ibm_common_attrs); 944 944 pmc_attrs = classic_pmc_attrs; 945 945 break; 946 946 #endif /* HAS_PPC_PMC_IBM */ 947 947 #ifdef HAS_PPC_PMC_G4 948 948 case PPC_PMC_G4: 949 949 attrs = g4_common_attrs; 950 - nattrs = sizeof(g4_common_attrs) / sizeof(struct device_attribute); 950 + nattrs = ARRAY_SIZE(g4_common_attrs); 951 951 pmc_attrs = classic_pmc_attrs; 952 952 break; 953 953 #endif /* HAS_PPC_PMC_G4 */ ··· 955 955 case PPC_PMC_PA6T: 956 956 /* PA Semi starts counting at PMC0 */ 957 957 attrs = pa6t_attrs; 958 - nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute); 958 + nattrs = ARRAY_SIZE(pa6t_attrs); 959 959 pmc_attrs = NULL; 960 960 break; 961 961 #endif
+1 -1
arch/powerpc/kernel/tau_6xx.c
··· 201 201 tau_int_enable = IS_ENABLED(CONFIG_TAU_INT) && 202 202 !strcmp(cur_cpu_spec->platform, "ppc750"); 203 203 204 - tau_workq = alloc_workqueue("tau", WQ_UNBOUND, 1, 0); 204 + tau_workq = alloc_workqueue("tau", WQ_UNBOUND, 1); 205 205 if (!tau_workq) 206 206 return -ENOMEM; 207 207
-11
arch/powerpc/kernel/time.c
··· 231 231 void notrace accumulate_stolen_time(void) 232 232 { 233 233 u64 sst, ust; 234 - unsigned long save_irq_soft_mask = irq_soft_mask_return(); 235 234 struct cpu_accounting_data *acct = &local_paca->accounting; 236 - 237 - /* We are called early in the exception entry, before 238 - * soft/hard_enabled are sync'ed to the expected state 239 - * for the exception. We are hard disabled but the PACA 240 - * needs to reflect that so various debug stuff doesn't 241 - * complain 242 - */ 243 - irq_soft_mask_set(IRQS_DISABLED); 244 235 245 236 sst = scan_dispatch_log(acct->starttime_user); 246 237 ust = scan_dispatch_log(acct->starttime); 247 238 acct->stime -= sst; 248 239 acct->utime -= ust; 249 240 acct->steal_time += ust + sst; 250 - 251 - irq_soft_mask_set(save_irq_soft_mask); 252 241 } 253 242 254 243 static inline u64 calculate_stolen_time(u64 stop_tb)
+25 -26
arch/powerpc/kernel/trace/ftrace.c
··· 49 49 addr = ppc_function_entry((void *)addr); 50 50 51 51 /* if (link) set op to 'bl' else 'b' */ 52 - create_branch(&op, (struct ppc_inst *)ip, addr, link ? 1 : 0); 52 + create_branch(&op, (u32 *)ip, addr, link ? 1 : 0); 53 53 54 54 return op; 55 55 } ··· 79 79 } 80 80 81 81 /* replace the text with the new text */ 82 - if (patch_instruction((struct ppc_inst *)ip, new)) 82 + if (patch_instruction((u32 *)ip, new)) 83 83 return -EPERM; 84 84 85 85 return 0; ··· 94 94 addr = ppc_function_entry((void *)addr); 95 95 96 96 /* use the create_branch to verify that this offset can be branched */ 97 - return create_branch(&op, (struct ppc_inst *)ip, addr, 0) == 0; 97 + return create_branch(&op, (u32 *)ip, addr, 0) == 0; 98 98 } 99 99 100 100 static int is_bl_op(struct ppc_inst op) ··· 162 162 163 163 #ifdef CONFIG_MPROFILE_KERNEL 164 164 /* When using -mkernel_profile there is no load to jump over */ 165 - pop = ppc_inst(PPC_INST_NOP); 165 + pop = ppc_inst(PPC_RAW_NOP()); 166 166 167 167 if (copy_inst_from_kernel_nofault(&op, (void *)(ip - 4))) { 168 168 pr_err("Fetching instruction at %lx failed.\n", ip - 4); ··· 170 170 } 171 171 172 172 /* We expect either a mflr r0, or a std r0, LRSAVE(r1) */ 173 - if (!ppc_inst_equal(op, ppc_inst(PPC_INST_MFLR)) && 173 + if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_MFLR(_R0))) && 174 174 !ppc_inst_equal(op, ppc_inst(PPC_INST_STD_LR))) { 175 175 pr_err("Unexpected instruction %s around bl _mcount\n", 176 176 ppc_inst_as_str(op)); ··· 203 203 } 204 204 205 205 if (!ppc_inst_equal(op, ppc_inst(PPC_INST_LD_TOC))) { 206 - pr_err("Expected %08x found %s\n", PPC_INST_LD_TOC, ppc_inst_as_str(op)); 206 + pr_err("Expected %08lx found %s\n", PPC_INST_LD_TOC, ppc_inst_as_str(op)); 207 207 return -EINVAL; 208 208 } 209 209 #endif /* CONFIG_MPROFILE_KERNEL */ 210 210 211 - if (patch_instruction((struct ppc_inst *)ip, pop)) { 211 + if (patch_instruction((u32 *)ip, pop)) { 212 212 pr_err("Patching NOP failed.\n"); 213 213 return -EPERM; 214 214 } ··· 278 278 return -EINVAL; 279 279 } 280 280 281 - op = ppc_inst(PPC_INST_NOP); 281 + op = ppc_inst(PPC_RAW_NOP()); 282 282 283 - if (patch_instruction((struct ppc_inst *)ip, op)) 283 + if (patch_instruction((u32 *)ip, op)) 284 284 return -EPERM; 285 285 286 286 return 0; ··· 380 380 return -1; 381 381 } 382 382 383 - if (patch_branch((struct ppc_inst *)tramp, ptr, 0)) { 383 + if (patch_branch((u32 *)tramp, ptr, 0)) { 384 384 pr_debug("REL24 out of range!\n"); 385 385 return -1; 386 386 } ··· 424 424 } 425 425 } 426 426 427 - if (patch_instruction((struct ppc_inst *)ip, ppc_inst(PPC_INST_NOP))) { 427 + if (patch_instruction((u32 *)ip, ppc_inst(PPC_RAW_NOP()))) { 428 428 pr_err("Patching NOP failed.\n"); 429 429 return -EPERM; 430 430 } ··· 446 446 if (test_24bit_addr(ip, addr)) { 447 447 /* within range */ 448 448 old = ftrace_call_replace(ip, addr, 1); 449 - new = ppc_inst(PPC_INST_NOP); 449 + new = ppc_inst(PPC_RAW_NOP()); 450 450 return ftrace_modify_code(ip, old, new); 451 451 } else if (core_kernel_text(ip)) 452 452 return __ftrace_make_nop_kernel(rec, addr); ··· 510 510 expected_nop_sequence(void *ip, struct ppc_inst op0, struct ppc_inst op1) 511 511 { 512 512 /* look for patched "NOP" on ppc64 with -mprofile-kernel */ 513 - if (!ppc_inst_equal(op0, ppc_inst(PPC_INST_NOP))) 513 + if (!ppc_inst_equal(op0, ppc_inst(PPC_RAW_NOP()))) 514 514 return 0; 515 515 return 1; 516 516 } ··· 589 589 { 590 590 int err; 591 591 struct ppc_inst op; 592 - unsigned long ip = rec->ip; 592 + u32 *ip = (u32 *)rec->ip; 593 593 594 594 /* read where this goes */ 595 - if (copy_inst_from_kernel_nofault(&op, (void *)ip)) 595 + if (copy_inst_from_kernel_nofault(&op, ip)) 596 596 return -EFAULT; 597 597 598 598 /* It should be pointing to a nop */ 599 - if (!ppc_inst_equal(op, ppc_inst(PPC_INST_NOP))) { 599 + if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_NOP()))) { 600 600 pr_err("Expected NOP but have %s\n", ppc_inst_as_str(op)); 601 601 return -EINVAL; 602 602 } ··· 608 608 } 609 609 610 610 /* create the branch to the trampoline */ 611 - err = create_branch(&op, (struct ppc_inst *)ip, 612 - rec->arch.mod->arch.tramp, BRANCH_SET_LINK); 611 + err = create_branch(&op, ip, rec->arch.mod->arch.tramp, BRANCH_SET_LINK); 613 612 if (err) { 614 613 pr_err("REL24 out of range!\n"); 615 614 return -EINVAL; ··· 616 617 617 618 pr_devel("write to %lx\n", rec->ip); 618 619 619 - if (patch_instruction((struct ppc_inst *)ip, op)) 620 + if (patch_instruction(ip, op)) 620 621 return -EPERM; 621 622 622 623 return 0; ··· 652 653 return -EFAULT; 653 654 } 654 655 655 - if (!ppc_inst_equal(op, ppc_inst(PPC_INST_NOP))) { 656 + if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_NOP()))) { 656 657 pr_err("Unexpected call sequence at %p: %s\n", ip, ppc_inst_as_str(op)); 657 658 return -EINVAL; 658 659 } ··· 683 684 */ 684 685 if (test_24bit_addr(ip, addr)) { 685 686 /* within range */ 686 - old = ppc_inst(PPC_INST_NOP); 687 + old = ppc_inst(PPC_RAW_NOP()); 687 688 new = ftrace_call_replace(ip, addr, 1); 688 689 return ftrace_modify_code(ip, old, new); 689 690 } else if (core_kernel_text(ip)) ··· 761 762 /* The new target may be within range */ 762 763 if (test_24bit_addr(ip, addr)) { 763 764 /* within range */ 764 - if (patch_branch((struct ppc_inst *)ip, addr, BRANCH_SET_LINK)) { 765 + if (patch_branch((u32 *)ip, addr, BRANCH_SET_LINK)) { 765 766 pr_err("REL24 out of range!\n"); 766 767 return -EINVAL; 767 768 } ··· 789 790 } 790 791 791 792 /* Ensure branch is within 24 bits */ 792 - if (create_branch(&op, (struct ppc_inst *)ip, tramp, BRANCH_SET_LINK)) { 793 + if (create_branch(&op, (u32 *)ip, tramp, BRANCH_SET_LINK)) { 793 794 pr_err("Branch out of range\n"); 794 795 return -EINVAL; 795 796 } 796 797 797 - if (patch_branch((struct ppc_inst *)ip, tramp, BRANCH_SET_LINK)) { 798 + if (patch_branch((u32 *)ip, tramp, BRANCH_SET_LINK)) { 798 799 pr_err("REL24 out of range!\n"); 799 800 return -EINVAL; 800 801 } ··· 850 851 struct ppc_inst old, new; 851 852 int ret; 852 853 853 - old = ppc_inst_read((struct ppc_inst *)&ftrace_call); 854 + old = ppc_inst_read((u32 *)&ftrace_call); 854 855 new = ftrace_call_replace(ip, (unsigned long)func, 1); 855 856 ret = ftrace_modify_code(ip, old, new); 856 857 ··· 858 859 /* Also update the regs callback function */ 859 860 if (!ret) { 860 861 ip = (unsigned long)(&ftrace_regs_call); 861 - old = ppc_inst_read((struct ppc_inst *)&ftrace_regs_call); 862 + old = ppc_inst_read((u32 *)&ftrace_regs_call); 862 863 new = ftrace_call_replace(ip, (unsigned long)func, 1); 863 864 ret = ftrace_modify_code(ip, old, new); 864 865 }
+25 -24
arch/powerpc/kernel/traps.c
··· 67 67 #include <asm/kprobes.h> 68 68 #include <asm/stacktrace.h> 69 69 #include <asm/nmi.h> 70 + #include <asm/disassemble.h> 70 71 71 72 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC_CORE) 72 73 int (*__debugger)(struct pt_regs *regs) __read_mostly; ··· 428 427 return; 429 428 430 429 nonrecoverable: 431 - regs->msr &= ~MSR_RI; 430 + regs_set_return_msr(regs, regs->msr & ~MSR_RI); 432 431 #endif 433 432 } 434 433 DEFINE_INTERRUPT_HANDLER_NMI(system_reset_exception) ··· 538 537 * For the debug message, we look at the preceding 539 538 * load or store. 540 539 */ 541 - if (*nip == PPC_INST_NOP) 540 + if (*nip == PPC_RAW_NOP()) 542 541 nip -= 2; 543 - else if (*nip == PPC_INST_ISYNC) 542 + else if (*nip == PPC_RAW_ISYNC()) 544 543 --nip; 545 - if (*nip == PPC_INST_SYNC || (*nip >> 26) == OP_TRAP) { 544 + if (*nip == PPC_RAW_SYNC() || get_op(*nip) == OP_TRAP) { 546 545 unsigned int rb; 547 546 548 547 --nip; ··· 550 549 printk(KERN_DEBUG "%s bad port %lx at %p\n", 551 550 (*nip & 0x100)? "OUT to": "IN from", 552 551 regs->gpr[rb] - _IO_BASE, nip); 553 - regs->msr |= MSR_RI; 554 - regs->nip = extable_fixup(entry); 552 + regs_set_return_msr(regs, regs->msr | MSR_RI); 553 + regs_set_return_ip(regs, extable_fixup(entry)); 555 554 return 1; 556 555 } 557 556 } ··· 587 586 #define REASON_BOUNDARY SRR1_BOUNDARY 588 587 589 588 #define single_stepping(regs) ((regs)->msr & MSR_SE) 590 - #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE) 591 - #define clear_br_trace(regs) ((regs)->msr &= ~MSR_BE) 589 + #define clear_single_step(regs) (regs_set_return_msr((regs), (regs)->msr & ~MSR_SE)) 590 + #define clear_br_trace(regs) (regs_set_return_msr((regs), (regs)->msr & ~MSR_BE)) 592 591 #endif 593 592 594 593 #define inst_length(reason) (((reason) & REASON_PREFIXED) ? 8 : 4) ··· 1032 1031 #endif /* !__LITTLE_ENDIAN__ */ 1033 1032 1034 1033 /* Go to next instruction */ 1035 - regs->nip += 4; 1034 + regs_add_return_ip(regs, 4); 1036 1035 } 1037 1036 #endif /* CONFIG_VSX */ 1038 1037 ··· 1477 1476 1478 1477 if (!(regs->msr & MSR_PR) && /* not user-mode */ 1479 1478 report_bug(bugaddr, regs) == BUG_TRAP_TYPE_WARN) { 1480 - regs->nip += 4; 1479 + regs_add_return_ip(regs, 4); 1481 1480 return; 1482 1481 } 1483 1482 _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); ··· 1539 1538 if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { 1540 1539 switch (emulate_instruction(regs)) { 1541 1540 case 0: 1542 - regs->nip += 4; 1541 + regs_add_return_ip(regs, 4); 1543 1542 emulate_single_step(regs); 1544 1543 return; 1545 1544 case -EFAULT: ··· 1567 1566 */ 1568 1567 DEFINE_INTERRUPT_HANDLER(emulation_assist_interrupt) 1569 1568 { 1570 - regs->msr |= REASON_ILLEGAL; 1569 + regs_set_return_msr(regs, regs->msr | REASON_ILLEGAL); 1571 1570 do_program_check(regs); 1572 1571 } 1573 1572 ··· 1594 1593 1595 1594 if (fixed == 1) { 1596 1595 /* skip over emulated instruction */ 1597 - regs->nip += inst_length(reason); 1596 + regs_add_return_ip(regs, inst_length(reason)); 1598 1597 emulate_single_step(regs); 1599 1598 return; 1600 1599 } ··· 1660 1659 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1661 1660 if (user_mode(regs)) { 1662 1661 current->thread.load_tm++; 1663 - regs->msr |= MSR_TM; 1662 + regs_set_return_msr(regs, regs->msr | MSR_TM); 1664 1663 tm_enable(); 1665 1664 tm_restore_sprs(&current->thread); 1666 1665 return; ··· 1752 1751 pr_err("DSCR based mfspr emulation failed\n"); 1753 1752 return; 1754 1753 } 1755 - regs->nip += 4; 1754 + regs_add_return_ip(regs, 4); 1756 1755 emulate_single_step(regs); 1757 1756 } 1758 1757 return; ··· 1949 1948 */ 1950 1949 if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, 1951 1950 current->thread.debug.dbcr1)) 1952 - regs->msr |= MSR_DE; 1951 + regs_set_return_msr(regs, regs->msr | MSR_DE); 1953 1952 else 1954 1953 /* Make sure the IDM flag is off */ 1955 1954 current->thread.debug.dbcr0 &= ~DBCR0_IDM; ··· 1970 1969 * instead of stopping here when hitting a BT 1971 1970 */ 1972 1971 if (debug_status & DBSR_BT) { 1973 - regs->msr &= ~MSR_DE; 1972 + regs_set_return_msr(regs, regs->msr & ~MSR_DE); 1974 1973 1975 1974 /* Disable BT */ 1976 1975 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT); ··· 1981 1980 if (user_mode(regs)) { 1982 1981 current->thread.debug.dbcr0 &= ~DBCR0_BT; 1983 1982 current->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; 1984 - regs->msr |= MSR_DE; 1983 + regs_set_return_msr(regs, regs->msr | MSR_DE); 1985 1984 return; 1986 1985 } 1987 1986 ··· 1995 1994 if (debugger_sstep(regs)) 1996 1995 return; 1997 1996 } else if (debug_status & DBSR_IC) { /* Instruction complete */ 1998 - regs->msr &= ~MSR_DE; 1997 + regs_set_return_msr(regs, regs->msr & ~MSR_DE); 1999 1998 2000 1999 /* Disable instruction completion */ 2001 2000 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC); ··· 2017 2016 current->thread.debug.dbcr0 &= ~DBCR0_IC; 2018 2017 if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, 2019 2018 current->thread.debug.dbcr1)) 2020 - regs->msr |= MSR_DE; 2019 + regs_set_return_msr(regs, regs->msr | MSR_DE); 2021 2020 else 2022 2021 /* Make sure the IDM bit is off */ 2023 2022 current->thread.debug.dbcr0 &= ~DBCR0_IDM; ··· 2045 2044 PPC_WARN_EMULATED(altivec, regs); 2046 2045 err = emulate_altivec(regs); 2047 2046 if (err == 0) { 2048 - regs->nip += 4; /* skip emulated instruction */ 2047 + regs_add_return_ip(regs, 4); /* skip emulated instruction */ 2049 2048 emulate_single_step(regs); 2050 2049 return; 2051 2050 } ··· 2110 2109 2111 2110 err = do_spe_mathemu(regs); 2112 2111 if (err == 0) { 2113 - regs->nip += 4; /* skip emulated instruction */ 2112 + regs_add_return_ip(regs, 4); /* skip emulated instruction */ 2114 2113 emulate_single_step(regs); 2115 2114 return; 2116 2115 } ··· 2141 2140 giveup_spe(current); 2142 2141 preempt_enable(); 2143 2142 2144 - regs->nip -= 4; 2143 + regs_add_return_ip(regs, -4); 2145 2144 err = speround_handler(regs); 2146 2145 if (err == 0) { 2147 - regs->nip += 4; /* skip emulated instruction */ 2146 + regs_add_return_ip(regs, 4); /* skip emulated instruction */ 2148 2147 emulate_single_step(regs); 2149 2148 return; 2150 2149 }
+39
arch/powerpc/kernel/udbg_16550.c
··· 296 296 } 297 297 298 298 #endif /* CONFIG_PPC_EARLY_DEBUG_40x */ 299 + 300 + #ifdef CONFIG_PPC_EARLY_DEBUG_MICROWATT 301 + 302 + #define UDBG_UART_MW_ADDR ((void __iomem *)0xc0002000) 303 + 304 + static u8 udbg_uart_in_isa300_rm(unsigned int reg) 305 + { 306 + uint64_t msr = mfmsr(); 307 + uint8_t c; 308 + 309 + mtmsr(msr & ~(MSR_EE|MSR_DR)); 310 + isync(); 311 + eieio(); 312 + c = __raw_rm_readb(UDBG_UART_MW_ADDR + (reg << 2)); 313 + mtmsr(msr); 314 + isync(); 315 + return c; 316 + } 317 + 318 + static void udbg_uart_out_isa300_rm(unsigned int reg, u8 val) 319 + { 320 + uint64_t msr = mfmsr(); 321 + 322 + mtmsr(msr & ~(MSR_EE|MSR_DR)); 323 + isync(); 324 + eieio(); 325 + __raw_rm_writeb(val, UDBG_UART_MW_ADDR + (reg << 2)); 326 + mtmsr(msr); 327 + isync(); 328 + } 329 + 330 + void __init udbg_init_debug_microwatt(void) 331 + { 332 + udbg_uart_in = udbg_uart_in_isa300_rm; 333 + udbg_uart_out = udbg_uart_out_isa300_rm; 334 + udbg_use_uart(); 335 + } 336 + 337 + #endif /* CONFIG_PPC_EARLY_DEBUG_MICROWATT */
+4 -4
arch/powerpc/kernel/uprobes.c
··· 42 42 return -EINVAL; 43 43 44 44 if (cpu_has_feature(CPU_FTR_ARCH_31) && 45 - ppc_inst_prefixed(auprobe->insn) && 45 + ppc_inst_prefixed(ppc_inst_read(auprobe->insn)) && 46 46 (addr & 0x3f) == 60) { 47 47 pr_info_ratelimited("Cannot register a uprobe on 64 byte unaligned prefixed instruction\n"); 48 48 return -EINVAL; ··· 62 62 63 63 autask->saved_trap_nr = current->thread.trap_nr; 64 64 current->thread.trap_nr = UPROBE_TRAP_NR; 65 - regs->nip = current->utask->xol_vaddr; 65 + regs_set_return_ip(regs, current->utask->xol_vaddr); 66 66 67 67 user_enable_single_step(current); 68 68 return 0; ··· 119 119 * support doesn't exist and have to fix-up the next instruction 120 120 * to be executed. 121 121 */ 122 - regs->nip = (unsigned long)ppc_inst_next((void *)utask->vaddr, &auprobe->insn); 122 + regs_set_return_ip(regs, (unsigned long)ppc_inst_next((void *)utask->vaddr, auprobe->insn)); 123 123 124 124 user_disable_single_step(current); 125 125 return 0; ··· 182 182 * emulate_step() returns 1 if the insn was successfully emulated. 183 183 * For all other cases, we need to single-step in hardware. 184 184 */ 185 - ret = emulate_step(regs, ppc_inst_read(&auprobe->insn)); 185 + ret = emulate_step(regs, ppc_inst_read(auprobe->insn)); 186 186 if (ret > 0) 187 187 return true; 188 188
+7 -1
arch/powerpc/kernel/vector.S
··· 73 73 addi r5,r4,THREAD /* Get THREAD */ 74 74 oris r12,r12,MSR_VEC@h 75 75 std r12,_MSR(r1) 76 + #ifdef CONFIG_PPC_BOOK3S_64 77 + li r4,0 78 + stb r4,PACASRR_VALID(r13) 79 + #endif 76 80 #endif 77 81 li r4,1 78 82 stb r4,THREAD_LOAD_VEC(r5) ··· 135 131 /* enable use of VSX after return */ 136 132 oris r12,r12,MSR_VSX@h 137 133 std r12,_MSR(r1) 138 - b fast_interrupt_return 134 + li r4,0 135 + stb r4,PACASRR_VALID(r13) 136 + b fast_interrupt_return_srr 139 137 140 138 #endif /* CONFIG_VSX */ 141 139
+19
arch/powerpc/kernel/vmlinux.lds.S
··· 9 9 #define EMITS_PT_NOTE 10 10 #define RO_EXCEPTION_TABLE_ALIGN 0 11 11 12 + #define SOFT_MASK_TABLE(align) \ 13 + . = ALIGN(align); \ 14 + __soft_mask_table : AT(ADDR(__soft_mask_table) - LOAD_OFFSET) { \ 15 + __start___soft_mask_table = .; \ 16 + KEEP(*(__soft_mask_table)) \ 17 + __stop___soft_mask_table = .; \ 18 + } 19 + 20 + #define RESTART_TABLE(align) \ 21 + . = ALIGN(align); \ 22 + __restart_table : AT(ADDR(__restart_table) - LOAD_OFFSET) { \ 23 + __start___restart_table = .; \ 24 + KEEP(*(__restart_table)) \ 25 + __stop___restart_table = .; \ 26 + } 27 + 12 28 #include <asm/page.h> 13 29 #include <asm-generic/vmlinux.lds.h> 14 30 #include <asm/cache.h> ··· 140 124 RO_DATA(PAGE_SIZE) 141 125 142 126 #ifdef CONFIG_PPC64 127 + SOFT_MASK_TABLE(8) 128 + RESTART_TABLE(8) 129 + 143 130 . = ALIGN(8); 144 131 __stf_entry_barrier_fixup : AT(ADDR(__stf_entry_barrier_fixup) - LOAD_OFFSET) { 145 132 __start___stf_entry_barrier_fixup = .;
+1
arch/powerpc/kernel/watchdog.c
··· 24 24 #include <linux/kdebug.h> 25 25 #include <linux/sched/debug.h> 26 26 #include <linux/delay.h> 27 + #include <linux/processor.h> 27 28 #include <linux/smp.h> 28 29 29 30 #include <asm/interrupt.h>
+2 -2
arch/powerpc/kexec/crash.c
··· 105 105 static void crash_kexec_prepare_cpus(int cpu) 106 106 { 107 107 unsigned int msecs; 108 - unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */ 109 - int tries = 0; 108 + volatile unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */ 109 + volatile int tries = 0; 110 110 int (*old_handler)(struct pt_regs *regs); 111 111 112 112 printk(KERN_EMERG "Sending IPI to other CPUs\n");
-3
arch/powerpc/kvm/book3s_32_mmu_host.c
··· 353 353 preempt_enable(); 354 354 } 355 355 356 - /* From mm/mmu_context_hash32.c */ 357 - #define CTX_TO_VSID(c, id) ((((c) * (897 * 16)) + (id * 0x111)) & 0xffffff) 358 - 359 356 int kvmppc_mmu_init_pr(struct kvm_vcpu *vcpu) 360 357 { 361 358 struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
+3
arch/powerpc/kvm/book3s_hv.c
··· 4626 4626 4627 4627 vcpu->arch.state = KVMPPC_VCPU_NOTREADY; 4628 4628 atomic_dec(&kvm->arch.vcpus_running); 4629 + 4630 + srr_regs_clobbered(); 4631 + 4629 4632 return r; 4630 4633 } 4631 4634
+2
arch/powerpc/kvm/book3s_pr.c
··· 25 25 #include <asm/cputable.h> 26 26 #include <asm/cacheflush.h> 27 27 #include <linux/uaccess.h> 28 + #include <asm/interrupt.h> 28 29 #include <asm/io.h> 29 30 #include <asm/kvm_ppc.h> 30 31 #include <asm/kvm_book3s.h> ··· 1849 1848 /* Make sure we save the guest TAR/EBB/DSCR state */ 1850 1849 kvmppc_giveup_fac(vcpu, FSCR_TAR_LG); 1851 1850 1851 + srr_regs_clobbered(); 1852 1852 out: 1853 1853 vcpu->mode = OUTSIDE_GUEST_MODE; 1854 1854 return ret;
+1 -1
arch/powerpc/lib/Makefile
··· 39 39 endif 40 40 41 41 obj-$(CONFIG_PPC_BOOK3S_64) += copyuser_power7.o copypage_power7.o \ 42 - memcpy_power7.o 42 + memcpy_power7.o restart_table.o 43 43 44 44 obj64-y += copypage_64.o copyuser_64.o mem_64.o hweight_64.o \ 45 45 memcpy_64.o copy_mc_64.o
+90 -88
arch/powerpc/lib/code-patching.c
··· 18 18 #include <asm/setup.h> 19 19 #include <asm/inst.h> 20 20 21 - static int __patch_instruction(struct ppc_inst *exec_addr, struct ppc_inst instr, 22 - struct ppc_inst *patch_addr) 21 + static int __patch_instruction(u32 *exec_addr, struct ppc_inst instr, u32 *patch_addr) 23 22 { 24 23 if (!ppc_inst_prefixed(instr)) { 25 24 u32 val = ppc_inst_val(instr); ··· 39 40 return -EFAULT; 40 41 } 41 42 42 - int raw_patch_instruction(struct ppc_inst *addr, struct ppc_inst instr) 43 + int raw_patch_instruction(u32 *addr, struct ppc_inst instr) 43 44 { 44 45 return __patch_instruction(addr, instr, addr); 45 46 } ··· 69 70 } 70 71 71 72 /* 72 - * Run as a late init call. This allows all the boot time patching to be done 73 - * simply by patching the code, and then we're called here prior to 74 - * mark_rodata_ro(), which happens after all init calls are run. Although 75 - * BUG_ON() is rude, in this case it should only happen if ENOMEM, and we judge 76 - * it as being preferable to a kernel that will crash later when someone tries 77 - * to use patch_instruction(). 73 + * Although BUG_ON() is rude, in this case it should only happen if ENOMEM, and 74 + * we judge it as being preferable to a kernel that will crash later when 75 + * someone tries to use patch_instruction(). 78 76 */ 79 - static int __init setup_text_poke_area(void) 77 + void __init poking_init(void) 80 78 { 81 79 BUG_ON(!cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, 82 80 "powerpc/text_poke:online", text_area_cpu_up, 83 81 text_area_cpu_down)); 84 - 85 - return 0; 86 82 } 87 - late_initcall(setup_text_poke_area); 88 83 89 84 /* 90 85 * This can be called for kernel text or a module. ··· 141 148 return 0; 142 149 } 143 150 144 - static int do_patch_instruction(struct ppc_inst *addr, struct ppc_inst instr) 151 + static int do_patch_instruction(u32 *addr, struct ppc_inst instr) 145 152 { 146 153 int err; 147 - struct ppc_inst *patch_addr = NULL; 154 + u32 *patch_addr = NULL; 148 155 unsigned long flags; 149 156 unsigned long text_poke_addr; 150 157 unsigned long kaddr = (unsigned long)addr; ··· 165 172 goto out; 166 173 } 167 174 168 - patch_addr = (struct ppc_inst *)(text_poke_addr + (kaddr & ~PAGE_MASK)); 175 + patch_addr = (u32 *)(text_poke_addr + (kaddr & ~PAGE_MASK)); 169 176 170 177 __patch_instruction(addr, instr, patch_addr); 171 178 ··· 180 187 } 181 188 #else /* !CONFIG_STRICT_KERNEL_RWX */ 182 189 183 - static int do_patch_instruction(struct ppc_inst *addr, struct ppc_inst instr) 190 + static int do_patch_instruction(u32 *addr, struct ppc_inst instr) 184 191 { 185 192 return raw_patch_instruction(addr, instr); 186 193 } 187 194 188 195 #endif /* CONFIG_STRICT_KERNEL_RWX */ 189 196 190 - int patch_instruction(struct ppc_inst *addr, struct ppc_inst instr) 197 + int patch_instruction(u32 *addr, struct ppc_inst instr) 191 198 { 192 199 /* Make sure we aren't patching a freed init section */ 193 200 if (init_mem_is_free && init_section_contains(addr, 4)) { ··· 198 205 } 199 206 NOKPROBE_SYMBOL(patch_instruction); 200 207 201 - int patch_branch(struct ppc_inst *addr, unsigned long target, int flags) 208 + int patch_branch(u32 *addr, unsigned long target, int flags) 202 209 { 203 210 struct ppc_inst instr; 204 211 ··· 250 257 } 251 258 NOKPROBE_SYMBOL(is_conditional_branch); 252 259 253 - int create_branch(struct ppc_inst *instr, 254 - const struct ppc_inst *addr, 260 + int create_branch(struct ppc_inst *instr, const u32 *addr, 255 261 unsigned long target, int flags) 256 262 { 257 263 long offset; ··· 270 278 return 0; 271 279 } 272 280 273 - int create_cond_branch(struct ppc_inst *instr, const struct ppc_inst *addr, 281 + int create_cond_branch(struct ppc_inst *instr, const u32 *addr, 274 282 unsigned long target, int flags) 275 283 { 276 284 long offset; ··· 317 325 return instr_is_relative_branch(instr) && (ppc_inst_val(instr) & BRANCH_SET_LINK); 318 326 } 319 327 320 - static unsigned long branch_iform_target(const struct ppc_inst *instr) 328 + static unsigned long branch_iform_target(const u32 *instr) 321 329 { 322 330 signed long imm; 323 331 324 - imm = ppc_inst_val(*instr) & 0x3FFFFFC; 332 + imm = ppc_inst_val(ppc_inst_read(instr)) & 0x3FFFFFC; 325 333 326 334 /* If the top bit of the immediate value is set this is negative */ 327 335 if (imm & 0x2000000) 328 336 imm -= 0x4000000; 329 337 330 - if ((ppc_inst_val(*instr) & BRANCH_ABSOLUTE) == 0) 338 + if ((ppc_inst_val(ppc_inst_read(instr)) & BRANCH_ABSOLUTE) == 0) 331 339 imm += (unsigned long)instr; 332 340 333 341 return (unsigned long)imm; 334 342 } 335 343 336 - static unsigned long branch_bform_target(const struct ppc_inst *instr) 344 + static unsigned long branch_bform_target(const u32 *instr) 337 345 { 338 346 signed long imm; 339 347 340 - imm = ppc_inst_val(*instr) & 0xFFFC; 348 + imm = ppc_inst_val(ppc_inst_read(instr)) & 0xFFFC; 341 349 342 350 /* If the top bit of the immediate value is set this is negative */ 343 351 if (imm & 0x8000) 344 352 imm -= 0x10000; 345 353 346 - if ((ppc_inst_val(*instr) & BRANCH_ABSOLUTE) == 0) 354 + if ((ppc_inst_val(ppc_inst_read(instr)) & BRANCH_ABSOLUTE) == 0) 347 355 imm += (unsigned long)instr; 348 356 349 357 return (unsigned long)imm; 350 358 } 351 359 352 - unsigned long branch_target(const struct ppc_inst *instr) 360 + unsigned long branch_target(const u32 *instr) 353 361 { 354 362 if (instr_is_branch_iform(ppc_inst_read(instr))) 355 363 return branch_iform_target(instr); ··· 359 367 return 0; 360 368 } 361 369 362 - int instr_is_branch_to_addr(const struct ppc_inst *instr, unsigned long addr) 363 - { 364 - if (instr_is_branch_iform(ppc_inst_read(instr)) || 365 - instr_is_branch_bform(ppc_inst_read(instr))) 366 - return branch_target(instr) == addr; 367 - 368 - return 0; 369 - } 370 - 371 - int translate_branch(struct ppc_inst *instr, const struct ppc_inst *dest, 372 - const struct ppc_inst *src) 370 + int translate_branch(struct ppc_inst *instr, const u32 *dest, const u32 *src) 373 371 { 374 372 unsigned long target; 375 373 target = branch_target(src); ··· 386 404 * instruction of the exception, not the first one 387 405 */ 388 406 389 - patch_branch((struct ppc_inst *)(ibase + (exc / 4) + 1), addr, 0); 407 + patch_branch(ibase + (exc / 4) + 1, addr, 0); 390 408 } 391 409 #endif 392 410 393 411 #ifdef CONFIG_CODE_PATCHING_SELFTEST 412 + 413 + static int instr_is_branch_to_addr(const u32 *instr, unsigned long addr) 414 + { 415 + if (instr_is_branch_iform(ppc_inst_read(instr)) || 416 + instr_is_branch_bform(ppc_inst_read(instr))) 417 + return branch_target(instr) == addr; 418 + 419 + return 0; 420 + } 394 421 395 422 static void __init test_trampoline(void) 396 423 { ··· 413 422 { 414 423 int err; 415 424 struct ppc_inst instr; 416 - unsigned long addr; 417 - 418 - addr = (unsigned long)&instr; 425 + u32 tmp[2]; 426 + u32 *iptr = tmp; 427 + unsigned long addr = (unsigned long)tmp; 419 428 420 429 /* The simplest case, branch to self, no flags */ 421 430 check(instr_is_branch_iform(ppc_inst(0x48000000))); ··· 436 445 check(!instr_is_branch_iform(ppc_inst(0x7bfffffd))); 437 446 438 447 /* Absolute branch to 0x100 */ 439 - instr = ppc_inst(0x48000103); 440 - check(instr_is_branch_to_addr(&instr, 0x100)); 448 + patch_instruction(iptr, ppc_inst(0x48000103)); 449 + check(instr_is_branch_to_addr(iptr, 0x100)); 441 450 /* Absolute branch to 0x420fc */ 442 - instr = ppc_inst(0x480420ff); 443 - check(instr_is_branch_to_addr(&instr, 0x420fc)); 451 + patch_instruction(iptr, ppc_inst(0x480420ff)); 452 + check(instr_is_branch_to_addr(iptr, 0x420fc)); 444 453 /* Maximum positive relative branch, + 20MB - 4B */ 445 - instr = ppc_inst(0x49fffffc); 446 - check(instr_is_branch_to_addr(&instr, addr + 0x1FFFFFC)); 454 + patch_instruction(iptr, ppc_inst(0x49fffffc)); 455 + check(instr_is_branch_to_addr(iptr, addr + 0x1FFFFFC)); 447 456 /* Smallest negative relative branch, - 4B */ 448 - instr = ppc_inst(0x4bfffffc); 449 - check(instr_is_branch_to_addr(&instr, addr - 4)); 457 + patch_instruction(iptr, ppc_inst(0x4bfffffc)); 458 + check(instr_is_branch_to_addr(iptr, addr - 4)); 450 459 /* Largest negative relative branch, - 32 MB */ 451 - instr = ppc_inst(0x4a000000); 452 - check(instr_is_branch_to_addr(&instr, addr - 0x2000000)); 460 + patch_instruction(iptr, ppc_inst(0x4a000000)); 461 + check(instr_is_branch_to_addr(iptr, addr - 0x2000000)); 453 462 454 463 /* Branch to self, with link */ 455 - err = create_branch(&instr, &instr, addr, BRANCH_SET_LINK); 456 - check(instr_is_branch_to_addr(&instr, addr)); 464 + err = create_branch(&instr, iptr, addr, BRANCH_SET_LINK); 465 + patch_instruction(iptr, instr); 466 + check(instr_is_branch_to_addr(iptr, addr)); 457 467 458 468 /* Branch to self - 0x100, with link */ 459 - err = create_branch(&instr, &instr, addr - 0x100, BRANCH_SET_LINK); 460 - check(instr_is_branch_to_addr(&instr, addr - 0x100)); 469 + err = create_branch(&instr, iptr, addr - 0x100, BRANCH_SET_LINK); 470 + patch_instruction(iptr, instr); 471 + check(instr_is_branch_to_addr(iptr, addr - 0x100)); 461 472 462 473 /* Branch to self + 0x100, no link */ 463 - err = create_branch(&instr, &instr, addr + 0x100, 0); 464 - check(instr_is_branch_to_addr(&instr, addr + 0x100)); 474 + err = create_branch(&instr, iptr, addr + 0x100, 0); 475 + patch_instruction(iptr, instr); 476 + check(instr_is_branch_to_addr(iptr, addr + 0x100)); 465 477 466 478 /* Maximum relative negative offset, - 32 MB */ 467 - err = create_branch(&instr, &instr, addr - 0x2000000, BRANCH_SET_LINK); 468 - check(instr_is_branch_to_addr(&instr, addr - 0x2000000)); 479 + err = create_branch(&instr, iptr, addr - 0x2000000, BRANCH_SET_LINK); 480 + patch_instruction(iptr, instr); 481 + check(instr_is_branch_to_addr(iptr, addr - 0x2000000)); 469 482 470 483 /* Out of range relative negative offset, - 32 MB + 4*/ 471 - err = create_branch(&instr, &instr, addr - 0x2000004, BRANCH_SET_LINK); 484 + err = create_branch(&instr, iptr, addr - 0x2000004, BRANCH_SET_LINK); 472 485 check(err); 473 486 474 487 /* Out of range relative positive offset, + 32 MB */ 475 - err = create_branch(&instr, &instr, addr + 0x2000000, BRANCH_SET_LINK); 488 + err = create_branch(&instr, iptr, addr + 0x2000000, BRANCH_SET_LINK); 476 489 check(err); 477 490 478 491 /* Unaligned target */ 479 - err = create_branch(&instr, &instr, addr + 3, BRANCH_SET_LINK); 492 + err = create_branch(&instr, iptr, addr + 3, BRANCH_SET_LINK); 480 493 check(err); 481 494 482 495 /* Check flags are masked correctly */ 483 - err = create_branch(&instr, &instr, addr, 0xFFFFFFFC); 484 - check(instr_is_branch_to_addr(&instr, addr)); 496 + err = create_branch(&instr, iptr, addr, 0xFFFFFFFC); 497 + patch_instruction(iptr, instr); 498 + check(instr_is_branch_to_addr(iptr, addr)); 485 499 check(ppc_inst_equal(instr, ppc_inst(0x48000000))); 486 500 } 487 501 488 502 static void __init test_create_function_call(void) 489 503 { 490 - struct ppc_inst *iptr; 504 + u32 *iptr; 491 505 unsigned long dest; 492 506 struct ppc_inst instr; 493 507 494 508 /* Check we can create a function call */ 495 - iptr = (struct ppc_inst *)ppc_function_entry(test_trampoline); 509 + iptr = (u32 *)ppc_function_entry(test_trampoline); 496 510 dest = ppc_function_entry(test_create_function_call); 497 511 create_branch(&instr, iptr, dest, BRANCH_SET_LINK); 498 512 patch_instruction(iptr, instr); ··· 508 512 { 509 513 int err; 510 514 unsigned long addr; 511 - struct ppc_inst *iptr, instr; 515 + struct ppc_inst instr; 516 + u32 tmp[2]; 517 + u32 *iptr = tmp; 512 518 unsigned int flags; 513 519 514 - iptr = &instr; 515 520 addr = (unsigned long)iptr; 516 521 517 522 /* The simplest case, branch to self, no flags */ ··· 525 528 check(!instr_is_branch_bform(ppc_inst(0x7bffffff))); 526 529 527 530 /* Absolute conditional branch to 0x100 */ 528 - instr = ppc_inst(0x43ff0103); 529 - check(instr_is_branch_to_addr(&instr, 0x100)); 531 + patch_instruction(iptr, ppc_inst(0x43ff0103)); 532 + check(instr_is_branch_to_addr(iptr, 0x100)); 530 533 /* Absolute conditional branch to 0x20fc */ 531 - instr = ppc_inst(0x43ff20ff); 532 - check(instr_is_branch_to_addr(&instr, 0x20fc)); 534 + patch_instruction(iptr, ppc_inst(0x43ff20ff)); 535 + check(instr_is_branch_to_addr(iptr, 0x20fc)); 533 536 /* Maximum positive relative conditional branch, + 32 KB - 4B */ 534 - instr = ppc_inst(0x43ff7ffc); 535 - check(instr_is_branch_to_addr(&instr, addr + 0x7FFC)); 537 + patch_instruction(iptr, ppc_inst(0x43ff7ffc)); 538 + check(instr_is_branch_to_addr(iptr, addr + 0x7FFC)); 536 539 /* Smallest negative relative conditional branch, - 4B */ 537 - instr = ppc_inst(0x43fffffc); 538 - check(instr_is_branch_to_addr(&instr, addr - 4)); 540 + patch_instruction(iptr, ppc_inst(0x43fffffc)); 541 + check(instr_is_branch_to_addr(iptr, addr - 4)); 539 542 /* Largest negative relative conditional branch, - 32 KB */ 540 - instr = ppc_inst(0x43ff8000); 541 - check(instr_is_branch_to_addr(&instr, addr - 0x8000)); 543 + patch_instruction(iptr, ppc_inst(0x43ff8000)); 544 + check(instr_is_branch_to_addr(iptr, addr - 0x8000)); 542 545 543 546 /* All condition code bits set & link */ 544 547 flags = 0x3ff000 | BRANCH_SET_LINK; 545 548 546 549 /* Branch to self */ 547 550 err = create_cond_branch(&instr, iptr, addr, flags); 548 - check(instr_is_branch_to_addr(&instr, addr)); 551 + patch_instruction(iptr, instr); 552 + check(instr_is_branch_to_addr(iptr, addr)); 549 553 550 554 /* Branch to self - 0x100 */ 551 555 err = create_cond_branch(&instr, iptr, addr - 0x100, flags); 552 - check(instr_is_branch_to_addr(&instr, addr - 0x100)); 556 + patch_instruction(iptr, instr); 557 + check(instr_is_branch_to_addr(iptr, addr - 0x100)); 553 558 554 559 /* Branch to self + 0x100 */ 555 560 err = create_cond_branch(&instr, iptr, addr + 0x100, flags); 556 - check(instr_is_branch_to_addr(&instr, addr + 0x100)); 561 + patch_instruction(iptr, instr); 562 + check(instr_is_branch_to_addr(iptr, addr + 0x100)); 557 563 558 564 /* Maximum relative negative offset, - 32 KB */ 559 565 err = create_cond_branch(&instr, iptr, addr - 0x8000, flags); 560 - check(instr_is_branch_to_addr(&instr, addr - 0x8000)); 566 + patch_instruction(iptr, instr); 567 + check(instr_is_branch_to_addr(iptr, addr - 0x8000)); 561 568 562 569 /* Out of range relative negative offset, - 32 KB + 4*/ 563 570 err = create_cond_branch(&instr, iptr, addr - 0x8004, flags); ··· 577 576 578 577 /* Check flags are masked correctly */ 579 578 err = create_cond_branch(&instr, iptr, addr, 0xFFFFFFFC); 580 - check(instr_is_branch_to_addr(&instr, addr)); 579 + patch_instruction(iptr, instr); 580 + check(instr_is_branch_to_addr(iptr, addr)); 581 581 check(ppc_inst_equal(instr, ppc_inst(0x43FF0000))); 582 582 } 583 583 ··· 717 715 extern unsigned int code_patching_test1_expected[]; 718 716 extern unsigned int end_code_patching_test1[]; 719 717 720 - __patch_instruction((struct ppc_inst *)code_patching_test1, 718 + __patch_instruction(code_patching_test1, 721 719 ppc_inst_prefix(OP_PREFIX << 26, 0x00000000), 722 - (struct ppc_inst *)code_patching_test1); 720 + code_patching_test1); 723 721 724 722 check(!memcmp(code_patching_test1, 725 723 code_patching_test1_expected,
+1 -1
arch/powerpc/lib/error-inject.c
··· 11 11 * function in the kernel/module, captured on a kprobe. We don't need 12 12 * to worry about 32-bit userspace on a 64-bit kernel. 13 13 */ 14 - regs->nip = regs->link; 14 + regs_set_return_ip(regs, regs->link); 15 15 } 16 16 NOKPROBE_SYMBOL(override_function_with_return);
+154 -112
arch/powerpc/lib/feature-fixups.c
··· 17 17 #include <linux/stop_machine.h> 18 18 #include <asm/cputable.h> 19 19 #include <asm/code-patching.h> 20 + #include <asm/interrupt.h> 20 21 #include <asm/page.h> 21 22 #include <asm/sections.h> 22 23 #include <asm/setup.h> ··· 34 33 long alt_end_off; 35 34 }; 36 35 37 - static struct ppc_inst *calc_addr(struct fixup_entry *fcur, long offset) 36 + static u32 *calc_addr(struct fixup_entry *fcur, long offset) 38 37 { 39 38 /* 40 39 * We store the offset to the code as a negative offset from 41 40 * the start of the alt_entry, to support the VDSO. This 42 41 * routine converts that back into an actual address. 43 42 */ 44 - return (struct ppc_inst *)((unsigned long)fcur + offset); 43 + return (u32 *)((unsigned long)fcur + offset); 45 44 } 46 45 47 - static int patch_alt_instruction(struct ppc_inst *src, struct ppc_inst *dest, 48 - struct ppc_inst *alt_start, struct ppc_inst *alt_end) 46 + static int patch_alt_instruction(u32 *src, u32 *dest, u32 *alt_start, u32 *alt_end) 49 47 { 50 48 int err; 51 49 struct ppc_inst instr; 52 50 53 51 instr = ppc_inst_read(src); 54 52 55 - if (instr_is_relative_branch(*src)) { 56 - struct ppc_inst *target = (struct ppc_inst *)branch_target(src); 53 + if (instr_is_relative_branch(ppc_inst_read(src))) { 54 + u32 *target = (u32 *)branch_target(src); 57 55 58 56 /* Branch within the section doesn't need translating */ 59 57 if (target < alt_start || target > alt_end) { ··· 69 69 70 70 static int patch_feature_section(unsigned long value, struct fixup_entry *fcur) 71 71 { 72 - struct ppc_inst *start, *end, *alt_start, *alt_end, *src, *dest, nop; 72 + u32 *start, *end, *alt_start, *alt_end, *src, *dest; 73 73 74 74 start = calc_addr(fcur, fcur->start_off); 75 75 end = calc_addr(fcur, fcur->end_off); ··· 91 91 return 1; 92 92 } 93 93 94 - nop = ppc_inst(PPC_INST_NOP); 95 - for (; dest < end; dest = ppc_inst_next(dest, &nop)) 96 - raw_patch_instruction(dest, nop); 94 + for (; dest < end; dest++) 95 + raw_patch_instruction(dest, ppc_inst(PPC_RAW_NOP())); 97 96 98 97 return 0; 99 98 } ··· 127 128 start = PTRRELOC(&__start___stf_entry_barrier_fixup); 128 129 end = PTRRELOC(&__stop___stf_entry_barrier_fixup); 129 130 130 - instrs[0] = 0x60000000; /* nop */ 131 - instrs[1] = 0x60000000; /* nop */ 132 - instrs[2] = 0x60000000; /* nop */ 131 + instrs[0] = PPC_RAW_NOP(); 132 + instrs[1] = PPC_RAW_NOP(); 133 + instrs[2] = PPC_RAW_NOP(); 133 134 134 135 i = 0; 135 136 if (types & STF_BARRIER_FALLBACK) { 136 - instrs[i++] = 0x7d4802a6; /* mflr r10 */ 137 - instrs[i++] = 0x60000000; /* branch patched below */ 138 - instrs[i++] = 0x7d4803a6; /* mtlr r10 */ 137 + instrs[i++] = PPC_RAW_MFLR(_R10); 138 + instrs[i++] = PPC_RAW_NOP(); /* branch patched below */ 139 + instrs[i++] = PPC_RAW_MTLR(_R10); 139 140 } else if (types & STF_BARRIER_EIEIO) { 140 - instrs[i++] = 0x7e0006ac; /* eieio + bit 6 hint */ 141 + instrs[i++] = PPC_RAW_EIEIO() | 0x02000000; /* eieio + bit 6 hint */ 141 142 } else if (types & STF_BARRIER_SYNC_ORI) { 142 - instrs[i++] = 0x7c0004ac; /* hwsync */ 143 - instrs[i++] = 0xe94d0000; /* ld r10,0(r13) */ 144 - instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */ 143 + instrs[i++] = PPC_RAW_SYNC(); 144 + instrs[i++] = PPC_RAW_LD(_R10, _R13, 0); 145 + instrs[i++] = PPC_RAW_ORI(_R31, _R31, 0); /* speculation barrier */ 145 146 } 146 147 147 148 for (i = 0; start < end; start++, i++) { ··· 151 152 152 153 // See comment in do_entry_flush_fixups() RE order of patching 153 154 if (types & STF_BARRIER_FALLBACK) { 154 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 155 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 156 - patch_branch((struct ppc_inst *)(dest + 1), 155 + patch_instruction(dest, ppc_inst(instrs[0])); 156 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 157 + patch_branch(dest + 1, 157 158 (unsigned long)&stf_barrier_fallback, BRANCH_SET_LINK); 158 159 } else { 159 - patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1])); 160 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 161 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 160 + patch_instruction(dest + 1, ppc_inst(instrs[1])); 161 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 162 + patch_instruction(dest, ppc_inst(instrs[0])); 162 163 } 163 164 } 164 165 ··· 179 180 start = PTRRELOC(&__start___stf_exit_barrier_fixup); 180 181 end = PTRRELOC(&__stop___stf_exit_barrier_fixup); 181 182 182 - instrs[0] = 0x60000000; /* nop */ 183 - instrs[1] = 0x60000000; /* nop */ 184 - instrs[2] = 0x60000000; /* nop */ 185 - instrs[3] = 0x60000000; /* nop */ 186 - instrs[4] = 0x60000000; /* nop */ 187 - instrs[5] = 0x60000000; /* nop */ 183 + instrs[0] = PPC_RAW_NOP(); 184 + instrs[1] = PPC_RAW_NOP(); 185 + instrs[2] = PPC_RAW_NOP(); 186 + instrs[3] = PPC_RAW_NOP(); 187 + instrs[4] = PPC_RAW_NOP(); 188 + instrs[5] = PPC_RAW_NOP(); 188 189 189 190 i = 0; 190 191 if (types & STF_BARRIER_FALLBACK || types & STF_BARRIER_SYNC_ORI) { 191 192 if (cpu_has_feature(CPU_FTR_HVMODE)) { 192 - instrs[i++] = 0x7db14ba6; /* mtspr 0x131, r13 (HSPRG1) */ 193 - instrs[i++] = 0x7db04aa6; /* mfspr r13, 0x130 (HSPRG0) */ 193 + instrs[i++] = PPC_RAW_MTSPR(SPRN_HSPRG1, _R13); 194 + instrs[i++] = PPC_RAW_MFSPR(_R13, SPRN_HSPRG0); 194 195 } else { 195 - instrs[i++] = 0x7db243a6; /* mtsprg 2,r13 */ 196 - instrs[i++] = 0x7db142a6; /* mfsprg r13,1 */ 196 + instrs[i++] = PPC_RAW_MTSPR(SPRN_SPRG2, _R13); 197 + instrs[i++] = PPC_RAW_MFSPR(_R13, SPRN_SPRG1); 197 198 } 198 - instrs[i++] = 0x7c0004ac; /* hwsync */ 199 - instrs[i++] = 0xe9ad0000; /* ld r13,0(r13) */ 200 - instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */ 201 - if (cpu_has_feature(CPU_FTR_HVMODE)) { 202 - instrs[i++] = 0x7db14aa6; /* mfspr r13, 0x131 (HSPRG1) */ 203 - } else { 204 - instrs[i++] = 0x7db242a6; /* mfsprg r13,2 */ 205 - } 199 + instrs[i++] = PPC_RAW_SYNC(); 200 + instrs[i++] = PPC_RAW_LD(_R13, _R13, 0); 201 + instrs[i++] = PPC_RAW_ORI(_R31, _R31, 0); /* speculation barrier */ 202 + if (cpu_has_feature(CPU_FTR_HVMODE)) 203 + instrs[i++] = PPC_RAW_MFSPR(_R13, SPRN_HSPRG1); 204 + else 205 + instrs[i++] = PPC_RAW_MFSPR(_R13, SPRN_SPRG2); 206 206 } else if (types & STF_BARRIER_EIEIO) { 207 - instrs[i++] = 0x7e0006ac; /* eieio + bit 6 hint */ 207 + instrs[i++] = PPC_RAW_EIEIO() | 0x02000000; /* eieio + bit 6 hint */ 208 208 } 209 209 210 210 for (i = 0; start < end; start++, i++) { ··· 211 213 212 214 pr_devel("patching dest %lx\n", (unsigned long)dest); 213 215 214 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 215 - patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1])); 216 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 217 - patch_instruction((struct ppc_inst *)(dest + 3), ppc_inst(instrs[3])); 218 - patch_instruction((struct ppc_inst *)(dest + 4), ppc_inst(instrs[4])); 219 - patch_instruction((struct ppc_inst *)(dest + 5), ppc_inst(instrs[5])); 216 + patch_instruction(dest, ppc_inst(instrs[0])); 217 + patch_instruction(dest + 1, ppc_inst(instrs[1])); 218 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 219 + patch_instruction(dest + 3, ppc_inst(instrs[3])); 220 + patch_instruction(dest + 4, ppc_inst(instrs[4])); 221 + patch_instruction(dest + 5, ppc_inst(instrs[5])); 220 222 } 221 223 printk(KERN_DEBUG "stf-barrier: patched %d exit locations (%s barrier)\n", i, 222 224 (types == STF_BARRIER_NONE) ? "no" : ··· 225 227 (types == (STF_BARRIER_SYNC_ORI)) ? "hwsync" 226 228 : "unknown"); 227 229 } 230 + 231 + static bool stf_exit_reentrant = false; 232 + static bool rfi_exit_reentrant = false; 228 233 229 234 static int __do_stf_barrier_fixups(void *data) 230 235 { ··· 243 242 { 244 243 /* 245 244 * The call to the fallback entry flush, and the fallback/sync-ori exit 246 - * flush can not be safely patched in/out while other CPUs are executing 247 - * them. So call __do_stf_barrier_fixups() on one CPU while all other CPUs 248 - * spin in the stop machine core with interrupts hard disabled. 245 + * flush can not be safely patched in/out while other CPUs are 246 + * executing them. So call __do_stf_barrier_fixups() on one CPU while 247 + * all other CPUs spin in the stop machine core with interrupts hard 248 + * disabled. 249 + * 250 + * The branch to mark interrupt exits non-reentrant is enabled first, 251 + * then stop_machine runs which will ensure all CPUs are out of the 252 + * low level interrupt exit code before patching. After the patching, 253 + * if allowed, then flip the branch to allow fast exits. 249 254 */ 255 + static_branch_enable(&interrupt_exit_not_reentrant); 256 + 250 257 stop_machine(__do_stf_barrier_fixups, &types, NULL); 258 + 259 + if ((types & STF_BARRIER_FALLBACK) || (types & STF_BARRIER_SYNC_ORI)) 260 + stf_exit_reentrant = false; 261 + else 262 + stf_exit_reentrant = true; 263 + 264 + if (stf_exit_reentrant && rfi_exit_reentrant) 265 + static_branch_disable(&interrupt_exit_not_reentrant); 251 266 } 252 267 253 268 void do_uaccess_flush_fixups(enum l1d_flush_type types) ··· 275 258 start = PTRRELOC(&__start___uaccess_flush_fixup); 276 259 end = PTRRELOC(&__stop___uaccess_flush_fixup); 277 260 278 - instrs[0] = 0x60000000; /* nop */ 279 - instrs[1] = 0x60000000; /* nop */ 280 - instrs[2] = 0x60000000; /* nop */ 281 - instrs[3] = 0x4e800020; /* blr */ 261 + instrs[0] = PPC_RAW_NOP(); 262 + instrs[1] = PPC_RAW_NOP(); 263 + instrs[2] = PPC_RAW_NOP(); 264 + instrs[3] = PPC_RAW_BLR(); 282 265 283 266 i = 0; 284 267 if (types == L1D_FLUSH_FALLBACK) { 285 - instrs[3] = 0x60000000; /* nop */ 268 + instrs[3] = PPC_RAW_NOP(); 286 269 /* fallthrough to fallback flush */ 287 270 } 288 271 289 272 if (types & L1D_FLUSH_ORI) { 290 - instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */ 291 - instrs[i++] = 0x63de0000; /* ori 30,30,0 L1d flush*/ 273 + instrs[i++] = PPC_RAW_ORI(_R31, _R31, 0); /* speculation barrier */ 274 + instrs[i++] = PPC_RAW_ORI(_R30, _R30, 0); /* L1d flush */ 292 275 } 293 276 294 277 if (types & L1D_FLUSH_MTTRIG) 295 - instrs[i++] = 0x7c12dba6; /* mtspr TRIG2,r0 (SPR #882) */ 278 + instrs[i++] = PPC_RAW_MTSPR(SPRN_TRIG2, _R0); 296 279 297 280 for (i = 0; start < end; start++, i++) { 298 281 dest = (void *)start + *start; 299 282 300 283 pr_devel("patching dest %lx\n", (unsigned long)dest); 301 284 302 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 285 + patch_instruction(dest, ppc_inst(instrs[0])); 303 286 304 - patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1])); 305 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 306 - patch_instruction((struct ppc_inst *)(dest + 3), ppc_inst(instrs[3])); 287 + patch_instruction(dest + 1, ppc_inst(instrs[1])); 288 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 289 + patch_instruction(dest + 3, ppc_inst(instrs[3])); 307 290 } 308 291 309 292 printk(KERN_DEBUG "uaccess-flush: patched %d locations (%s flush)\n", i, ··· 323 306 long *start, *end; 324 307 int i; 325 308 326 - instrs[0] = 0x60000000; /* nop */ 327 - instrs[1] = 0x60000000; /* nop */ 328 - instrs[2] = 0x60000000; /* nop */ 309 + instrs[0] = PPC_RAW_NOP(); 310 + instrs[1] = PPC_RAW_NOP(); 311 + instrs[2] = PPC_RAW_NOP(); 329 312 330 313 i = 0; 331 314 if (types == L1D_FLUSH_FALLBACK) { 332 - instrs[i++] = 0x7d4802a6; /* mflr r10 */ 333 - instrs[i++] = 0x60000000; /* branch patched below */ 334 - instrs[i++] = 0x7d4803a6; /* mtlr r10 */ 315 + instrs[i++] = PPC_RAW_MFLR(_R10); 316 + instrs[i++] = PPC_RAW_NOP(); /* branch patched below */ 317 + instrs[i++] = PPC_RAW_MTLR(_R10); 335 318 } 336 319 337 320 if (types & L1D_FLUSH_ORI) { 338 - instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */ 339 - instrs[i++] = 0x63de0000; /* ori 30,30,0 L1d flush*/ 321 + instrs[i++] = PPC_RAW_ORI(_R31, _R31, 0); /* speculation barrier */ 322 + instrs[i++] = PPC_RAW_ORI(_R30, _R30, 0); /* L1d flush */ 340 323 } 341 324 342 325 if (types & L1D_FLUSH_MTTRIG) 343 - instrs[i++] = 0x7c12dba6; /* mtspr TRIG2,r0 (SPR #882) */ 326 + instrs[i++] = PPC_RAW_MTSPR(SPRN_TRIG2, _R0); 344 327 345 328 /* 346 329 * If we're patching in or out the fallback flush we need to be careful about the ··· 375 358 pr_devel("patching dest %lx\n", (unsigned long)dest); 376 359 377 360 if (types == L1D_FLUSH_FALLBACK) { 378 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 379 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 380 - patch_branch((struct ppc_inst *)(dest + 1), 361 + patch_instruction(dest, ppc_inst(instrs[0])); 362 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 363 + patch_branch(dest + 1, 381 364 (unsigned long)&entry_flush_fallback, BRANCH_SET_LINK); 382 365 } else { 383 - patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1])); 384 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 385 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 366 + patch_instruction(dest + 1, ppc_inst(instrs[1])); 367 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 368 + patch_instruction(dest, ppc_inst(instrs[0])); 386 369 } 387 370 } 388 371 ··· 394 377 pr_devel("patching dest %lx\n", (unsigned long)dest); 395 378 396 379 if (types == L1D_FLUSH_FALLBACK) { 397 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 398 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 399 - patch_branch((struct ppc_inst *)(dest + 1), 380 + patch_instruction(dest, ppc_inst(instrs[0])); 381 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 382 + patch_branch(dest + 1, 400 383 (unsigned long)&scv_entry_flush_fallback, BRANCH_SET_LINK); 401 384 } else { 402 - patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1])); 403 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 404 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 385 + patch_instruction(dest + 1, ppc_inst(instrs[1])); 386 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 387 + patch_instruction(dest, ppc_inst(instrs[0])); 405 388 } 406 389 } 407 390 ··· 429 412 stop_machine(__do_entry_flush_fixups, &types, NULL); 430 413 } 431 414 432 - void do_rfi_flush_fixups(enum l1d_flush_type types) 415 + static int __do_rfi_flush_fixups(void *data) 433 416 { 417 + enum l1d_flush_type types = *(enum l1d_flush_type *)data; 434 418 unsigned int instrs[3], *dest; 435 419 long *start, *end; 436 420 int i; ··· 439 421 start = PTRRELOC(&__start___rfi_flush_fixup); 440 422 end = PTRRELOC(&__stop___rfi_flush_fixup); 441 423 442 - instrs[0] = 0x60000000; /* nop */ 443 - instrs[1] = 0x60000000; /* nop */ 444 - instrs[2] = 0x60000000; /* nop */ 424 + instrs[0] = PPC_RAW_NOP(); 425 + instrs[1] = PPC_RAW_NOP(); 426 + instrs[2] = PPC_RAW_NOP(); 445 427 446 428 if (types & L1D_FLUSH_FALLBACK) 447 429 /* b .+16 to fallback flush */ 448 - instrs[0] = 0x48000010; 430 + instrs[0] = PPC_INST_BRANCH | 16; 449 431 450 432 i = 0; 451 433 if (types & L1D_FLUSH_ORI) { 452 - instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */ 453 - instrs[i++] = 0x63de0000; /* ori 30,30,0 L1d flush*/ 434 + instrs[i++] = PPC_RAW_ORI(_R31, _R31, 0); /* speculation barrier */ 435 + instrs[i++] = PPC_RAW_ORI(_R30, _R30, 0); /* L1d flush */ 454 436 } 455 437 456 438 if (types & L1D_FLUSH_MTTRIG) 457 - instrs[i++] = 0x7c12dba6; /* mtspr TRIG2,r0 (SPR #882) */ 439 + instrs[i++] = PPC_RAW_MTSPR(SPRN_TRIG2, _R0); 458 440 459 441 for (i = 0; start < end; start++, i++) { 460 442 dest = (void *)start + *start; 461 443 462 444 pr_devel("patching dest %lx\n", (unsigned long)dest); 463 445 464 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0])); 465 - patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1])); 466 - patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2])); 446 + patch_instruction(dest, ppc_inst(instrs[0])); 447 + patch_instruction(dest + 1, ppc_inst(instrs[1])); 448 + patch_instruction(dest + 2, ppc_inst(instrs[2])); 467 449 } 468 450 469 451 printk(KERN_DEBUG "rfi-flush: patched %d locations (%s flush)\n", i, ··· 474 456 : "ori type" : 475 457 (types & L1D_FLUSH_MTTRIG) ? "mttrig type" 476 458 : "unknown"); 459 + 460 + return 0; 461 + } 462 + 463 + void do_rfi_flush_fixups(enum l1d_flush_type types) 464 + { 465 + /* 466 + * stop_machine gets all CPUs out of the interrupt exit handler same 467 + * as do_stf_barrier_fixups. do_rfi_flush_fixups patching can run 468 + * without stop_machine, so this could be achieved with a broadcast 469 + * IPI instead, but this matches the stf sequence. 470 + */ 471 + static_branch_enable(&interrupt_exit_not_reentrant); 472 + 473 + stop_machine(__do_rfi_flush_fixups, &types, NULL); 474 + 475 + if (types & L1D_FLUSH_FALLBACK) 476 + rfi_exit_reentrant = false; 477 + else 478 + rfi_exit_reentrant = true; 479 + 480 + if (stf_exit_reentrant && rfi_exit_reentrant) 481 + static_branch_disable(&interrupt_exit_not_reentrant); 477 482 } 478 483 479 484 void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_end) ··· 508 467 start = fixup_start; 509 468 end = fixup_end; 510 469 511 - instr = 0x60000000; /* nop */ 470 + instr = PPC_RAW_NOP(); 512 471 513 472 if (enable) { 514 473 pr_info("barrier-nospec: using ORI speculation barrier\n"); 515 - instr = 0x63ff0000; /* ori 31,31,0 speculation barrier */ 474 + instr = PPC_RAW_ORI(_R31, _R31, 0); /* speculation barrier */ 516 475 } 517 476 518 477 for (i = 0; start < end; start++, i++) { 519 478 dest = (void *)start + *start; 520 479 521 480 pr_devel("patching dest %lx\n", (unsigned long)dest); 522 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instr)); 481 + patch_instruction(dest, ppc_inst(instr)); 523 482 } 524 483 525 484 printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i); ··· 549 508 start = fixup_start; 550 509 end = fixup_end; 551 510 552 - instr[0] = PPC_INST_NOP; 553 - instr[1] = PPC_INST_NOP; 511 + instr[0] = PPC_RAW_NOP(); 512 + instr[1] = PPC_RAW_NOP(); 554 513 555 514 if (enable) { 556 515 pr_info("barrier-nospec: using isync; sync as speculation barrier\n"); 557 - instr[0] = PPC_INST_ISYNC; 558 - instr[1] = PPC_INST_SYNC; 516 + instr[0] = PPC_RAW_ISYNC(); 517 + instr[1] = PPC_RAW_SYNC(); 559 518 } 560 519 561 520 for (i = 0; start < end; start++, i++) { 562 521 dest = (void *)start + *start; 563 522 564 523 pr_devel("patching dest %lx\n", (unsigned long)dest); 565 - patch_instruction((struct ppc_inst *)dest, ppc_inst(instr[0])); 566 - patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instr[1])); 524 + patch_instruction(dest, ppc_inst(instr[0])); 525 + patch_instruction(dest + 1, ppc_inst(instr[1])); 567 526 } 568 527 569 528 printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i); ··· 577 536 end = (void *)curr + *(curr + 1); 578 537 for (; start < end; start++) { 579 538 pr_devel("patching dest %lx\n", (unsigned long)start); 580 - patch_instruction((struct ppc_inst *)start, ppc_inst(PPC_INST_NOP)); 539 + patch_instruction(start, ppc_inst(PPC_RAW_NOP())); 581 540 } 582 541 } 583 542 ··· 596 555 void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end) 597 556 { 598 557 long *start, *end; 599 - struct ppc_inst *dest; 558 + u32 *dest; 600 559 601 560 if (!(value & CPU_FTR_LWSYNC)) 602 561 return ; ··· 613 572 static void do_final_fixups(void) 614 573 { 615 574 #if defined(CONFIG_PPC64) && defined(CONFIG_RELOCATABLE) 616 - struct ppc_inst inst, *src, *dest, *end; 575 + struct ppc_inst inst; 576 + u32 *src, *dest, *end; 617 577 618 578 if (PHYSICAL_START == 0) 619 579 return; 620 580 621 - src = (struct ppc_inst *)(KERNELBASE + PHYSICAL_START); 622 - dest = (struct ppc_inst *)KERNELBASE; 581 + src = (u32 *)(KERNELBASE + PHYSICAL_START); 582 + dest = (u32 *)KERNELBASE; 623 583 end = (void *)src + (__end_interrupts - _stext); 624 584 625 585 while (src < end) {
+56
arch/powerpc/lib/restart_table.c
··· 1 + #include <asm/interrupt.h> 2 + #include <asm/kprobes.h> 3 + 4 + struct soft_mask_table_entry { 5 + unsigned long start; 6 + unsigned long end; 7 + }; 8 + 9 + struct restart_table_entry { 10 + unsigned long start; 11 + unsigned long end; 12 + unsigned long fixup; 13 + }; 14 + 15 + extern struct soft_mask_table_entry __start___soft_mask_table[]; 16 + extern struct soft_mask_table_entry __stop___soft_mask_table[]; 17 + 18 + extern struct restart_table_entry __start___restart_table[]; 19 + extern struct restart_table_entry __stop___restart_table[]; 20 + 21 + /* Given an address, look for it in the soft mask table */ 22 + bool search_kernel_soft_mask_table(unsigned long addr) 23 + { 24 + struct soft_mask_table_entry *smte = __start___soft_mask_table; 25 + 26 + while (smte < __stop___soft_mask_table) { 27 + unsigned long start = smte->start; 28 + unsigned long end = smte->end; 29 + 30 + if (addr >= start && addr < end) 31 + return true; 32 + 33 + smte++; 34 + } 35 + return false; 36 + } 37 + NOKPROBE_SYMBOL(search_kernel_soft_mask_table); 38 + 39 + /* Given an address, look for it in the kernel exception table */ 40 + unsigned long search_kernel_restart_table(unsigned long addr) 41 + { 42 + struct restart_table_entry *rte = __start___restart_table; 43 + 44 + while (rte < __stop___restart_table) { 45 + unsigned long start = rte->start; 46 + unsigned long end = rte->end; 47 + unsigned long fixup = rte->fixup; 48 + 49 + if (addr >= start && addr < end) 50 + return fixup; 51 + 52 + rte++; 53 + } 54 + return 0; 55 + } 56 + NOKPROBE_SYMBOL(search_kernel_restart_table);
+31 -8
arch/powerpc/lib/sstep.c
··· 1700 1700 op->val = regs->ccr & imm; 1701 1701 goto compute_done; 1702 1702 1703 + case 128: /* setb */ 1704 + if (!cpu_has_feature(CPU_FTR_ARCH_300)) 1705 + goto unknown_opcode; 1706 + /* 1707 + * 'ra' encodes the CR field number (bfa) in the top 3 bits. 1708 + * Since each CR field is 4 bits, 1709 + * we can simply mask off the bottom two bits (bfa * 4) 1710 + * to yield the first bit in the CR field. 1711 + */ 1712 + ra = ra & ~0x3; 1713 + /* 'val' stores bits of the CR field (bfa) */ 1714 + val = regs->ccr >> (CR0_SHIFT - ra); 1715 + /* checks if the LT bit of CR field (bfa) is set */ 1716 + if (val & 8) 1717 + op->val = -1; 1718 + /* checks if the GT bit of CR field (bfa) is set */ 1719 + else if (val & 4) 1720 + op->val = 1; 1721 + else 1722 + op->val = 0; 1723 + goto compute_done; 1724 + 1703 1725 case 144: /* mtcrf */ 1704 1726 op->type = COMPUTE + SETCC; 1705 1727 imm = 0xf0000000UL; ··· 3225 3203 default: 3226 3204 WARN_ON_ONCE(1); 3227 3205 } 3228 - regs->nip = next_pc; 3206 + regs_set_return_ip(regs, next_pc); 3229 3207 } 3230 3208 NOKPROBE_SYMBOL(emulate_update_regs); 3231 3209 ··· 3563 3541 /* can't step mtmsr[d] that would clear MSR_RI */ 3564 3542 return -1; 3565 3543 /* here op.val is the mask of bits to change */ 3566 - regs->msr = (regs->msr & ~op.val) | (val & op.val); 3544 + regs_set_return_msr(regs, (regs->msr & ~op.val) | (val & op.val)); 3567 3545 goto instr_done; 3568 3546 3569 3547 #ifdef CONFIG_PPC64 ··· 3576 3554 if (IS_ENABLED(CONFIG_PPC_FAST_ENDIAN_SWITCH) && 3577 3555 cpu_has_feature(CPU_FTR_REAL_LE) && 3578 3556 regs->gpr[0] == 0x1ebe) { 3579 - regs->msr ^= MSR_LE; 3557 + regs_set_return_msr(regs, regs->msr ^ MSR_LE); 3580 3558 goto instr_done; 3581 3559 } 3582 3560 regs->gpr[9] = regs->gpr[13]; ··· 3584 3562 regs->gpr[11] = regs->nip + 4; 3585 3563 regs->gpr[12] = regs->msr & MSR_MASK; 3586 3564 regs->gpr[13] = (unsigned long) get_paca(); 3587 - regs->nip = (unsigned long) &system_call_common; 3588 - regs->msr = MSR_KERNEL; 3565 + regs_set_return_ip(regs, (unsigned long) &system_call_common); 3566 + regs_set_return_msr(regs, MSR_KERNEL); 3589 3567 return 1; 3590 3568 3591 3569 #ifdef CONFIG_PPC_BOOK3S_64 ··· 3595 3573 regs->gpr[11] = regs->nip + 4; 3596 3574 regs->gpr[12] = regs->msr & MSR_MASK; 3597 3575 regs->gpr[13] = (unsigned long) get_paca(); 3598 - regs->nip = (unsigned long) &system_call_vectored_emulate; 3599 - regs->msr = MSR_KERNEL; 3576 + regs_set_return_ip(regs, (unsigned long) &system_call_vectored_emulate); 3577 + regs_set_return_msr(regs, MSR_KERNEL); 3600 3578 return 1; 3601 3579 #endif 3602 3580 ··· 3607 3585 return 0; 3608 3586 3609 3587 instr_done: 3610 - regs->nip = truncate_if_32bit(regs->msr, regs->nip + GETLENGTH(op.type)); 3588 + regs_set_return_ip(regs, 3589 + truncate_if_32bit(regs->msr, regs->nip + GETLENGTH(op.type))); 3611 3590 return 1; 3612 3591 } 3613 3592 NOKPROBE_SYMBOL(emulate_step);
+33 -5
arch/powerpc/lib/test_emulate_step.c
··· 53 53 ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) | IMM_H(i), \ 54 54 PPC_RAW_ADDI(t, a, i)) 55 55 56 + #define TEST_SETB(t, bfa) ppc_inst(PPC_INST_SETB | ___PPC_RT(t) | ___PPC_RA((bfa & 0x7) << 2)) 57 + 56 58 57 59 static void __init init_pt_regs(struct pt_regs *regs) 58 60 { ··· 826 824 * XTp = 32xTX + 2xTp 827 825 * let RA=3 R=0 D=d0||d1=0 R=0 Tp=1 TX=1 828 826 */ 829 - instr = ppc_inst_prefix(PPC_RAW_PLXVP(34, 0, 3, 0) >> 32, 830 - PPC_RAW_PLXVP(34, 0, 3, 0) & 0xffffffff); 827 + instr = ppc_inst_prefix(PPC_RAW_PLXVP_P(34, 0, 3, 0), PPC_RAW_PLXVP_S(34, 0, 3, 0)); 831 828 832 829 stepped = emulate_step(&regs, instr); 833 830 if (stepped == 1 && cpu_has_feature(CPU_FTR_VSX)) { ··· 854 853 * XSp = 32xSX + 2xSp 855 854 * let RA=3 D=d0||d1=0 R=0 Sp=1 SX=1 856 855 */ 857 - instr = ppc_inst_prefix(PPC_RAW_PSTXVP(34, 0, 3, 0) >> 32, 858 - PPC_RAW_PSTXVP(34, 0, 3, 0) & 0xffffffff); 856 + instr = ppc_inst_prefix(PPC_RAW_PSTXVP_P(34, 0, 3, 0), PPC_RAW_PSTXVP_S(34, 0, 3, 0)); 859 857 860 858 stepped = emulate_step(&regs, instr); 861 859 ··· 922 922 .subtests = { 923 923 { 924 924 .descr = "R0 = LONG_MAX", 925 - .instr = ppc_inst(PPC_INST_NOP), 925 + .instr = ppc_inst(PPC_RAW_NOP()), 926 926 .regs = { 927 927 .gpr[0] = LONG_MAX, 928 + } 929 + } 930 + } 931 + }, 932 + { 933 + .mnemonic = "setb", 934 + .cpu_feature = CPU_FTR_ARCH_300, 935 + .subtests = { 936 + { 937 + .descr = "BFA = 1, CR = GT", 938 + .instr = TEST_SETB(20, 1), 939 + .regs = { 940 + .ccr = 0x4000000, 941 + } 942 + }, 943 + { 944 + .descr = "BFA = 4, CR = LT", 945 + .instr = TEST_SETB(20, 4), 946 + .regs = { 947 + .ccr = 0x8000, 948 + } 949 + }, 950 + { 951 + .descr = "BFA = 5, CR = EQ", 952 + .instr = TEST_SETB(20, 5), 953 + .regs = { 954 + .ccr = 0x200, 928 955 } 929 956 } 930 957 } ··· 1609 1582 if (!regs || !ppc_inst_val(instr)) 1610 1583 return -EINVAL; 1611 1584 1585 + /* This is not a return frame regs */ 1612 1586 regs->nip = patch_site_addr(&patch__exec_instr); 1613 1587 1614 1588 analysed = analyse_instr(&op, regs, instr);
+1 -1
arch/powerpc/math-emu/math.c
··· 453 453 break; 454 454 } 455 455 456 - regs->nip += 4; 456 + regs_add_return_ip(regs, 4); 457 457 return 0; 458 458 459 459 illegal:
+1 -1
arch/powerpc/math-emu/math_efp.c
··· 710 710 illegal: 711 711 if (have_e500_cpu_a005_erratum) { 712 712 /* according to e500 cpu a005 erratum, reissue efp inst */ 713 - regs->nip -= 4; 713 + regs_add_return_ip(regs, -4); 714 714 pr_debug("re-issue efp inst: %08lx\n", speinsn); 715 715 return 0; 716 716 }
+1 -1
arch/powerpc/mm/Makefile
··· 5 5 6 6 ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) 7 7 8 - obj-y := fault.o mem.o pgtable.o mmap.o maccess.o \ 8 + obj-y := fault.o mem.o pgtable.o mmap.o maccess.o pageattr.o \ 9 9 init_$(BITS).o pgtable_$(BITS).o \ 10 10 pgtable-frag.o ioremap.o ioremap_$(BITS).o \ 11 11 init-common.o mmu_context.o drmem.o \
+1
arch/powerpc/mm/book3s32/Makefile
··· 10 10 obj-$(CONFIG_PPC_BOOK3S_603) += nohash_low.o 11 11 obj-$(CONFIG_PPC_BOOK3S_604) += hash_low.o tlb.o 12 12 obj-$(CONFIG_PPC_KUEP) += kuep.o 13 + obj-$(CONFIG_PPC_KUAP) += kuap.o
+4 -2
arch/powerpc/mm/book3s32/hash_low.S
··· 27 27 #include <asm/code-patching-asm.h> 28 28 29 29 #ifdef CONFIG_PTE_64BIT 30 + #define PTE_T_SIZE 8 30 31 #define PTE_FLAGS_OFFSET 4 /* offset of PTE flags, in bytes */ 31 32 #else 33 + #define PTE_T_SIZE 4 32 34 #define PTE_FLAGS_OFFSET 0 33 35 #endif 34 36 ··· 490 488 bne 2f 491 489 ble cr1,19f 492 490 addi r4,r4,0x1000 493 - addi r5,r5,PTE_SIZE 491 + addi r5,r5,PTE_T_SIZE 494 492 addi r6,r6,-1 495 493 b 1b 496 494 ··· 575 573 576 574 8: ble cr1,9f /* if all ptes checked */ 577 575 81: addi r6,r6,-1 578 - addi r5,r5,PTE_SIZE 576 + addi r5,r5,PTE_T_SIZE 579 577 addi r4,r4,0x1000 580 578 lwz r0,0(r5) /* check next pte */ 581 579 cmpwi cr1,r6,1
+33
arch/powerpc/mm/book3s32/kuap.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <asm/kup.h> 4 + #include <asm/smp.h> 5 + 6 + struct static_key_false disable_kuap_key; 7 + EXPORT_SYMBOL(disable_kuap_key); 8 + 9 + void kuap_lock_all_ool(void) 10 + { 11 + kuap_lock_all(); 12 + } 13 + EXPORT_SYMBOL(kuap_lock_all_ool); 14 + 15 + void kuap_unlock_all_ool(void) 16 + { 17 + kuap_unlock_all(); 18 + } 19 + EXPORT_SYMBOL(kuap_unlock_all_ool); 20 + 21 + void setup_kuap(bool disabled) 22 + { 23 + if (!disabled) 24 + kuap_lock_all_ool(); 25 + 26 + if (smp_processor_id() != boot_cpuid) 27 + return; 28 + 29 + if (disabled) 30 + static_branch_enable(&disable_kuap_key); 31 + else 32 + pr_info("Activating Kernel Userspace Access Protection\n"); 33 + }
+11 -31
arch/powerpc/mm/book3s32/kuep.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 2 3 3 #include <asm/kup.h> 4 - #include <asm/reg.h> 5 - #include <asm/task_size_32.h> 6 - #include <asm/mmu.h> 4 + #include <asm/smp.h> 7 5 8 - #define KUEP_UPDATE_TWO_USER_SEGMENTS(n) do { \ 9 - if (TASK_SIZE > ((n) << 28)) \ 10 - mtsr(val1, (n) << 28); \ 11 - if (TASK_SIZE > (((n) + 1) << 28)) \ 12 - mtsr(val2, ((n) + 1) << 28); \ 13 - val1 = (val1 + 0x222) & 0xf0ffffff; \ 14 - val2 = (val2 + 0x222) & 0xf0ffffff; \ 15 - } while (0) 6 + struct static_key_false disable_kuep_key; 16 7 17 - static __always_inline void kuep_update(u32 val) 8 + void setup_kuep(bool disabled) 18 9 { 19 - int val1 = val; 20 - int val2 = (val + 0x111) & 0xf0ffffff; 10 + if (!disabled) 11 + kuep_lock(); 21 12 22 - KUEP_UPDATE_TWO_USER_SEGMENTS(0); 23 - KUEP_UPDATE_TWO_USER_SEGMENTS(2); 24 - KUEP_UPDATE_TWO_USER_SEGMENTS(4); 25 - KUEP_UPDATE_TWO_USER_SEGMENTS(6); 26 - KUEP_UPDATE_TWO_USER_SEGMENTS(8); 27 - KUEP_UPDATE_TWO_USER_SEGMENTS(10); 28 - KUEP_UPDATE_TWO_USER_SEGMENTS(12); 29 - KUEP_UPDATE_TWO_USER_SEGMENTS(14); 30 - } 13 + if (smp_processor_id() != boot_cpuid) 14 + return; 31 15 32 - void kuep_lock(void) 33 - { 34 - kuep_update(mfsr(0) | SR_NX); 35 - } 36 - 37 - void kuep_unlock(void) 38 - { 39 - kuep_update(mfsr(0) & ~SR_NX); 16 + if (disabled) 17 + static_branch_enable(&disable_kuep_key); 18 + else 19 + pr_info("Activating Kernel Userspace Execution Prevention\n"); 40 20 }
-20
arch/powerpc/mm/book3s32/mmu.c
··· 445 445 pr_info("Hash_mask = 0x%lx\n", Hash_mask); 446 446 } 447 447 448 - #ifdef CONFIG_PPC_KUEP 449 - void __init setup_kuep(bool disabled) 450 - { 451 - pr_info("Activating Kernel Userspace Execution Prevention\n"); 452 - 453 - if (disabled) 454 - pr_warn("KUEP cannot be disabled yet on 6xx when compiled in\n"); 455 - } 456 - #endif 457 - 458 - #ifdef CONFIG_PPC_KUAP 459 - void __init setup_kuap(bool disabled) 460 - { 461 - pr_info("Activating Kernel Userspace Access Protection\n"); 462 - 463 - if (disabled) 464 - pr_warn("KUAP cannot be disabled yet on 6xx when compiled in\n"); 465 - } 466 - #endif 467 - 468 448 void __init early_init_mmu(void) 469 449 { 470 450 }
+35 -13
arch/powerpc/mm/book3s32/mmu_context.c
··· 24 24 #include <asm/mmu_context.h> 25 25 26 26 /* 27 + * Room for two PTE pointers, usually the kernel and current user pointers 28 + * to their respective root page table. 29 + */ 30 + void *abatron_pteptrs[2]; 31 + 32 + /* 27 33 * On 32-bit PowerPC 6xx/7xx/7xxx CPUs, we use a set of 16 VSIDs 28 34 * (virtual segment identifiers) for each context. Although the 29 35 * hardware supports 24-bit VSIDs, and thus >1 million contexts, ··· 44 38 #define NO_CONTEXT ((unsigned long) -1) 45 39 #define LAST_CONTEXT 32767 46 40 #define FIRST_CONTEXT 1 47 - 48 - /* 49 - * This function defines the mapping from contexts to VSIDs (virtual 50 - * segment IDs). We use a skew on both the context and the high 4 bits 51 - * of the 32-bit virtual address (the "effective segment ID") in order 52 - * to spread out the entries in the MMU hash table. Note, if this 53 - * function is changed then arch/ppc/mm/hashtable.S will have to be 54 - * changed to correspond. 55 - * 56 - * 57 - * CTX_TO_VSID(ctx, va) (((ctx) * (897 * 16) + ((va) >> 28) * 0x111) \ 58 - * & 0xffffff) 59 - */ 60 41 61 42 static unsigned long next_mmu_context; 62 43 static unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1]; ··· 104 111 context_map[0] = (1 << FIRST_CONTEXT) - 1; 105 112 next_mmu_context = FIRST_CONTEXT; 106 113 } 114 + 115 + void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk) 116 + { 117 + long id = next->context.id; 118 + unsigned long val; 119 + 120 + if (id < 0) 121 + panic("mm_struct %p has no context ID", next); 122 + 123 + isync(); 124 + 125 + val = CTX_TO_VSID(id, 0); 126 + if (!kuep_is_disabled()) 127 + val |= SR_NX; 128 + if (!kuap_is_disabled()) 129 + val |= SR_KS; 130 + 131 + update_user_segments(val); 132 + 133 + if (IS_ENABLED(CONFIG_BDI_SWITCH)) 134 + abatron_pteptrs[1] = next->pgd; 135 + 136 + if (!mmu_has_feature(MMU_FTR_HPTE_TABLE)) 137 + mtspr(SPRN_SDR1, rol32(__pa(next->pgd), 4) & 0xffff01ff); 138 + 139 + mb(); /* sync */ 140 + isync(); 141 + } 142 + EXPORT_SYMBOL(switch_mmu_context);
+11 -13
arch/powerpc/mm/book3s64/hash_utils.c
··· 1522 1522 } 1523 1523 EXPORT_SYMBOL_GPL(hash_page); 1524 1524 1525 - DECLARE_INTERRUPT_HANDLER_RET(__do_hash_fault); 1526 - DEFINE_INTERRUPT_HANDLER_RET(__do_hash_fault) 1525 + DECLARE_INTERRUPT_HANDLER(__do_hash_fault); 1526 + DEFINE_INTERRUPT_HANDLER(__do_hash_fault) 1527 1527 { 1528 1528 unsigned long ea = regs->dar; 1529 1529 unsigned long dsisr = regs->dsisr; ··· 1532 1532 struct mm_struct *mm; 1533 1533 unsigned int region_id; 1534 1534 long err; 1535 + 1536 + if (unlikely(dsisr & (DSISR_BAD_FAULT_64S | DSISR_KEYFAULT))) { 1537 + hash__do_page_fault(regs); 1538 + return; 1539 + } 1535 1540 1536 1541 region_id = get_region_id(ea); 1537 1542 if ((region_id == VMALLOC_REGION_ID) || (region_id == IO_REGION_ID)) ··· 1576 1571 bad_page_fault(regs, SIGBUS); 1577 1572 } 1578 1573 err = 0; 1579 - } 1580 1574 1581 - return err; 1575 + } else if (err) { 1576 + hash__do_page_fault(regs); 1577 + } 1582 1578 } 1583 1579 1584 1580 /* ··· 1588 1582 */ 1589 1583 DEFINE_INTERRUPT_HANDLER_RAW(do_hash_fault) 1590 1584 { 1591 - unsigned long dsisr = regs->dsisr; 1592 - 1593 - if (unlikely(dsisr & (DSISR_BAD_FAULT_64S | DSISR_KEYFAULT))) { 1594 - hash__do_page_fault(regs); 1595 - return 0; 1596 - } 1597 - 1598 1585 /* 1599 1586 * If we are in an "NMI" (e.g., an interrupt when soft-disabled), then 1600 1587 * don't call hash_page, just fail the fault. This is required to ··· 1606 1607 return 0; 1607 1608 } 1608 1609 1609 - if (__do_hash_fault(regs)) 1610 - hash__do_page_fault(regs); 1610 + __do_hash_fault(regs); 1611 1611 1612 1612 return 0; 1613 1613 }
+17 -9
arch/powerpc/mm/book3s64/radix_tlb.c
··· 354 354 /* 355 355 * We use 128 set in radix mode and 256 set in hpt mode. 356 356 */ 357 - static __always_inline void _tlbiel_pid(unsigned long pid, unsigned long ric) 357 + static inline void _tlbiel_pid(unsigned long pid, unsigned long ric) 358 358 { 359 359 int set; 360 360 361 361 asm volatile("ptesync": : :"memory"); 362 362 363 - /* 364 - * Flush the first set of the TLB, and if we're doing a RIC_FLUSH_ALL, 365 - * also flush the entire Page Walk Cache. 366 - */ 367 - __tlbiel_pid(pid, 0, ric); 363 + switch (ric) { 364 + case RIC_FLUSH_PWC: 368 365 369 - /* For PWC, only one flush is needed */ 370 - if (ric == RIC_FLUSH_PWC) { 366 + /* For PWC, only one flush is needed */ 367 + __tlbiel_pid(pid, 0, RIC_FLUSH_PWC); 371 368 ppc_after_tlbiel_barrier(); 372 369 return; 370 + case RIC_FLUSH_TLB: 371 + __tlbiel_pid(pid, 0, RIC_FLUSH_TLB); 372 + break; 373 + case RIC_FLUSH_ALL: 374 + default: 375 + /* 376 + * Flush the first set of the TLB, and if 377 + * we're doing a RIC_FLUSH_ALL, also flush 378 + * the entire Page Walk Cache. 379 + */ 380 + __tlbiel_pid(pid, 0, RIC_FLUSH_ALL); 373 381 } 374 382 375 383 if (!cpu_has_feature(CPU_FTR_ARCH_31)) { ··· 1298 1290 } 1299 1291 } 1300 1292 1301 - static __always_inline void __radix__flush_tlb_range_psize(struct mm_struct *mm, 1293 + static void __radix__flush_tlb_range_psize(struct mm_struct *mm, 1302 1294 unsigned long start, unsigned long end, 1303 1295 int psize, bool also_pwc) 1304 1296 {
+2 -2
arch/powerpc/mm/ioremap_32.c
··· 70 70 */ 71 71 pr_warn("ioremap() called early from %pS. Use early_ioremap() instead\n", caller); 72 72 73 - err = early_ioremap_range(ioremap_bot - size, p, size, prot); 73 + err = early_ioremap_range(ioremap_bot - size - PAGE_SIZE, p, size, prot); 74 74 if (err) 75 75 return NULL; 76 - ioremap_bot -= size; 76 + ioremap_bot -= size + PAGE_SIZE; 77 77 78 78 return (void __iomem *)ioremap_bot + offset; 79 79 }
+1 -1
arch/powerpc/mm/ioremap_64.c
··· 38 38 return NULL; 39 39 40 40 ret = (void __iomem *)ioremap_bot + offset; 41 - ioremap_bot += size; 41 + ioremap_bot += size + PAGE_SIZE; 42 42 43 43 return ret; 44 44 }
+2 -2
arch/powerpc/mm/maccess.c
··· 12 12 return is_kernel_addr((unsigned long)unsafe_src); 13 13 } 14 14 15 - int copy_inst_from_kernel_nofault(struct ppc_inst *inst, struct ppc_inst *src) 15 + int copy_inst_from_kernel_nofault(struct ppc_inst *inst, u32 *src) 16 16 { 17 17 unsigned int val, suffix; 18 18 int err; ··· 21 21 if (err) 22 22 return err; 23 23 if (IS_ENABLED(CONFIG_PPC64) && get_op(val) == OP_PREFIX) { 24 - err = copy_from_kernel_nofault(&suffix, (void *)src + 4, 4); 24 + err = copy_from_kernel_nofault(&suffix, src + 1, sizeof(suffix)); 25 25 *inst = ppc_inst_prefix(val, suffix); 26 26 } else { 27 27 *inst = ppc_inst(val);
+7
arch/powerpc/mm/mem.c
··· 28 28 unsigned long long memory_limit; 29 29 bool init_mem_is_free; 30 30 31 + unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss; 32 + EXPORT_SYMBOL(empty_zero_page); 33 + 31 34 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 32 35 unsigned long size, pgprot_t vma_prot) 33 36 { ··· 302 299 ioremap_bot, IOREMAP_TOP); 303 300 pr_info(" * 0x%08lx..0x%08lx : vmalloc & ioremap\n", 304 301 VMALLOC_START, VMALLOC_END); 302 + #ifdef MODULES_VADDR 303 + pr_info(" * 0x%08lx..0x%08lx : modules\n", 304 + MODULES_VADDR, MODULES_END); 305 + #endif 305 306 #endif /* CONFIG_PPC32 */ 306 307 } 307 308
+17
arch/powerpc/mm/nohash/44x.c
··· 25 25 #include <asm/page.h> 26 26 #include <asm/cacheflush.h> 27 27 #include <asm/code-patching.h> 28 + #include <asm/smp.h> 28 29 29 30 #include <mm/mmu_decl.h> 30 31 ··· 240 239 } 241 240 } 242 241 #endif /* CONFIG_SMP */ 242 + 243 + #ifdef CONFIG_PPC_KUEP 244 + void setup_kuep(bool disabled) 245 + { 246 + if (smp_processor_id() != boot_cpuid) 247 + return; 248 + 249 + if (disabled) 250 + patch_instruction_site(&patch__tlb_44x_kuep, ppc_inst(PPC_RAW_NOP())); 251 + else 252 + pr_info("Activating Kernel Userspace Execution Prevention\n"); 253 + 254 + if (IS_ENABLED(CONFIG_PPC_47x) && disabled) 255 + patch_instruction_site(&patch__tlb_47x_kuep, ppc_inst(PPC_RAW_NOP())); 256 + } 257 + #endif
+8 -34
arch/powerpc/mm/nohash/8xx.c
··· 212 212 memblock_set_current_limit(min_t(u64, first_memblock_size, SZ_32M)); 213 213 } 214 214 215 - /* 216 - * Set up to use a given MMU context. 217 - * id is context number, pgd is PGD pointer. 218 - * 219 - * We place the physical address of the new task page directory loaded 220 - * into the MMU base register, and set the ASID compare register with 221 - * the new "context." 222 - */ 223 - void set_context(unsigned long id, pgd_t *pgd) 224 - { 225 - s16 offset = (s16)(__pa(swapper_pg_dir)); 226 - 227 - /* Context switch the PTE pointer for the Abatron BDI2000. 228 - * The PGDIR is passed as second argument. 229 - */ 230 - if (IS_ENABLED(CONFIG_BDI_SWITCH)) 231 - abatron_pteptrs[1] = pgd; 232 - 233 - /* Register M_TWB will contain base address of level 1 table minus the 234 - * lower part of the kernel PGDIR base address, so that all accesses to 235 - * level 1 table are done relative to lower part of kernel PGDIR base 236 - * address. 237 - */ 238 - mtspr(SPRN_M_TWB, __pa(pgd) - offset); 239 - 240 - /* Update context */ 241 - mtspr(SPRN_M_CASID, id - 1); 242 - /* sync */ 243 - mb(); 244 - } 245 - 246 215 #ifdef CONFIG_PPC_KUEP 247 216 void __init setup_kuep(bool disabled) 248 217 { ··· 225 256 #endif 226 257 227 258 #ifdef CONFIG_PPC_KUAP 259 + struct static_key_false disable_kuap_key; 260 + EXPORT_SYMBOL(disable_kuap_key); 261 + 228 262 void __init setup_kuap(bool disabled) 229 263 { 230 - pr_info("Activating Kernel Userspace Access Protection\n"); 264 + if (disabled) { 265 + static_branch_enable(&disable_kuap_key); 266 + return; 267 + } 231 268 232 - if (disabled) 233 - pr_warn("KUAP cannot be disabled yet on 8xx when compiled in\n"); 269 + pr_info("Activating Kernel Userspace Access Protection\n"); 234 270 235 271 mtspr(SPRN_MD_AP, MD_APG_KUAP); 236 272 }
+54 -117
arch/powerpc/mm/nohash/mmu_context.c
··· 21 21 * also clear mm->cpu_vm_mask bits when processes are migrated 22 22 */ 23 23 24 - //#define DEBUG_MAP_CONSISTENCY 25 - //#define DEBUG_CLAMP_LAST_CONTEXT 31 26 - //#define DEBUG_HARDER 27 - 28 - /* We don't use DEBUG because it tends to be compiled in always nowadays 29 - * and this would generate way too much output 30 - */ 31 - #ifdef DEBUG_HARDER 32 - #define pr_hard(args...) printk(KERN_DEBUG args) 33 - #define pr_hardcont(args...) printk(KERN_CONT args) 34 - #else 35 - #define pr_hard(args...) do { } while(0) 36 - #define pr_hardcont(args...) do { } while(0) 37 - #endif 38 - 39 24 #include <linux/kernel.h> 40 25 #include <linux/mm.h> 41 26 #include <linux/init.h> ··· 32 47 33 48 #include <asm/mmu_context.h> 34 49 #include <asm/tlbflush.h> 50 + #include <asm/smp.h> 35 51 36 52 #include <mm/mmu_decl.h> 53 + 54 + /* 55 + * Room for two PTE table pointers, usually the kernel and current user 56 + * pointer to their respective root page table (pgdir). 57 + */ 58 + void *abatron_pteptrs[2]; 37 59 38 60 /* 39 61 * The MPC8xx has only 16 contexts. We rotate through them on each task switch. ··· 60 68 * -- BenH 61 69 */ 62 70 #define FIRST_CONTEXT 1 63 - #ifdef DEBUG_CLAMP_LAST_CONTEXT 64 - #define LAST_CONTEXT DEBUG_CLAMP_LAST_CONTEXT 65 - #elif defined(CONFIG_PPC_8xx) 71 + #if defined(CONFIG_PPC_8xx) 66 72 #define LAST_CONTEXT 16 67 73 #elif defined(CONFIG_PPC_47x) 68 74 #define LAST_CONTEXT 65535 ··· 70 80 71 81 static unsigned int next_context, nr_free_contexts; 72 82 static unsigned long *context_map; 73 - #ifdef CONFIG_SMP 74 83 static unsigned long *stale_map[NR_CPUS]; 75 - #endif 76 84 static struct mm_struct **context_mm; 77 85 static DEFINE_RAW_SPINLOCK(context_lock); 78 86 ··· 93 105 * the stale map as we can just flush the local CPU 94 106 * -- benh 95 107 */ 96 - #ifdef CONFIG_SMP 97 108 static unsigned int steal_context_smp(unsigned int id) 98 109 { 99 110 struct mm_struct *mm; ··· 114 127 id = FIRST_CONTEXT; 115 128 continue; 116 129 } 117 - pr_hardcont(" | steal %d from 0x%p", id, mm); 118 130 119 131 /* Mark this mm has having no context anymore */ 120 132 mm->context.id = MMU_NO_CONTEXT; ··· 144 158 /* This will cause the caller to try again */ 145 159 return MMU_NO_CONTEXT; 146 160 } 147 - #endif /* CONFIG_SMP */ 148 161 149 162 static unsigned int steal_all_contexts(void) 150 163 { 151 164 struct mm_struct *mm; 152 - #ifdef CONFIG_SMP 153 165 int cpu = smp_processor_id(); 154 - #endif 155 166 unsigned int id; 156 167 157 168 for (id = FIRST_CONTEXT; id <= LAST_CONTEXT; id++) { 158 169 /* Pick up the victim mm */ 159 170 mm = context_mm[id]; 160 171 161 - pr_hardcont(" | steal %d from 0x%p", id, mm); 162 - 163 172 /* Mark this mm as having no context anymore */ 164 173 mm->context.id = MMU_NO_CONTEXT; 165 174 if (id != FIRST_CONTEXT) { 166 175 context_mm[id] = NULL; 167 176 __clear_bit(id, context_map); 168 - #ifdef DEBUG_MAP_CONSISTENCY 169 - mm->context.active = 0; 170 - #endif 171 177 } 172 - #ifdef CONFIG_SMP 173 - __clear_bit(id, stale_map[cpu]); 174 - #endif 178 + if (IS_ENABLED(CONFIG_SMP)) 179 + __clear_bit(id, stale_map[cpu]); 175 180 } 176 181 177 182 /* Flush the TLB for all contexts (not to be used on SMP) */ ··· 181 204 static unsigned int steal_context_up(unsigned int id) 182 205 { 183 206 struct mm_struct *mm; 184 - #ifdef CONFIG_SMP 185 207 int cpu = smp_processor_id(); 186 - #endif 187 208 188 209 /* Pick up the victim mm */ 189 210 mm = context_mm[id]; 190 - 191 - pr_hardcont(" | steal %d from 0x%p", id, mm); 192 211 193 212 /* Flush the TLB for that context */ 194 213 local_flush_tlb_mm(mm); ··· 193 220 mm->context.id = MMU_NO_CONTEXT; 194 221 195 222 /* XXX This clear should ultimately be part of local_flush_tlb_mm */ 196 - #ifdef CONFIG_SMP 197 - __clear_bit(id, stale_map[cpu]); 198 - #endif 223 + if (IS_ENABLED(CONFIG_SMP)) 224 + __clear_bit(id, stale_map[cpu]); 199 225 200 226 return id; 201 227 } 202 228 203 - #ifdef DEBUG_MAP_CONSISTENCY 204 - static void context_check_map(void) 229 + static void set_context(unsigned long id, pgd_t *pgd) 205 230 { 206 - unsigned int id, nrf, nact; 231 + if (IS_ENABLED(CONFIG_PPC_8xx)) { 232 + s16 offset = (s16)(__pa(swapper_pg_dir)); 207 233 208 - nrf = nact = 0; 209 - for (id = FIRST_CONTEXT; id <= LAST_CONTEXT; id++) { 210 - int used = test_bit(id, context_map); 211 - if (!used) 212 - nrf++; 213 - if (used != (context_mm[id] != NULL)) 214 - pr_err("MMU: Context %d is %s and MM is %p !\n", 215 - id, used ? "used" : "free", context_mm[id]); 216 - if (context_mm[id] != NULL) 217 - nact += context_mm[id]->context.active; 234 + /* 235 + * Register M_TWB will contain base address of level 1 table minus the 236 + * lower part of the kernel PGDIR base address, so that all accesses to 237 + * level 1 table are done relative to lower part of kernel PGDIR base 238 + * address. 239 + */ 240 + mtspr(SPRN_M_TWB, __pa(pgd) - offset); 241 + 242 + /* Update context */ 243 + mtspr(SPRN_M_CASID, id - 1); 244 + 245 + /* sync */ 246 + mb(); 247 + } else { 248 + if (IS_ENABLED(CONFIG_40x)) 249 + mb(); /* sync */ 250 + 251 + mtspr(SPRN_PID, id); 252 + isync(); 218 253 } 219 - if (nrf != nr_free_contexts) { 220 - pr_err("MMU: Free context count out of sync ! (%d vs %d)\n", 221 - nr_free_contexts, nrf); 222 - nr_free_contexts = nrf; 223 - } 224 - if (nact > num_online_cpus()) 225 - pr_err("MMU: More active contexts than CPUs ! (%d vs %d)\n", 226 - nact, num_online_cpus()); 227 - if (FIRST_CONTEXT > 0 && !test_bit(0, context_map)) 228 - pr_err("MMU: Context 0 has been freed !!!\n"); 229 254 } 230 - #else 231 - static void context_check_map(void) { } 232 - #endif 233 255 234 256 void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next, 235 257 struct task_struct *tsk) 236 258 { 237 259 unsigned int id; 238 - #ifdef CONFIG_SMP 239 260 unsigned int i, cpu = smp_processor_id(); 240 - #endif 241 261 unsigned long *map; 242 262 243 263 /* No lockless fast path .. yet */ 244 264 raw_spin_lock(&context_lock); 245 265 246 - pr_hard("[%d] activating context for mm @%p, active=%d, id=%d", 247 - cpu, next, next->context.active, next->context.id); 248 - 249 - #ifdef CONFIG_SMP 250 - /* Mark us active and the previous one not anymore */ 251 - next->context.active++; 252 - if (prev) { 253 - pr_hardcont(" (old=0x%p a=%d)", prev, prev->context.active); 254 - WARN_ON(prev->context.active < 1); 255 - prev->context.active--; 266 + if (IS_ENABLED(CONFIG_SMP)) { 267 + /* Mark us active and the previous one not anymore */ 268 + next->context.active++; 269 + if (prev) { 270 + WARN_ON(prev->context.active < 1); 271 + prev->context.active--; 272 + } 256 273 } 257 274 258 275 again: 259 - #endif /* CONFIG_SMP */ 260 276 261 277 /* If we already have a valid assigned context, skip all that */ 262 278 id = next->context.id; 263 - if (likely(id != MMU_NO_CONTEXT)) { 264 - #ifdef DEBUG_MAP_CONSISTENCY 265 - if (context_mm[id] != next) 266 - pr_err("MMU: mm 0x%p has id %d but context_mm[%d] says 0x%p\n", 267 - next, id, id, context_mm[id]); 268 - #endif 279 + if (likely(id != MMU_NO_CONTEXT)) 269 280 goto ctxt_ok; 270 - } 271 281 272 282 /* We really don't have a context, let's try to acquire one */ 273 283 id = next_context; ··· 260 304 261 305 /* No more free contexts, let's try to steal one */ 262 306 if (nr_free_contexts == 0) { 263 - #ifdef CONFIG_SMP 264 307 if (num_online_cpus() > 1) { 265 308 id = steal_context_smp(id); 266 309 if (id == MMU_NO_CONTEXT) 267 310 goto again; 268 311 goto stolen; 269 312 } 270 - #endif /* CONFIG_SMP */ 271 313 if (IS_ENABLED(CONFIG_PPC_8xx)) 272 314 id = steal_all_contexts(); 273 315 else ··· 284 330 next_context = id + 1; 285 331 context_mm[id] = next; 286 332 next->context.id = id; 287 - pr_hardcont(" | new id=%d,nrf=%d", id, nr_free_contexts); 288 333 289 - context_check_map(); 290 334 ctxt_ok: 291 335 292 336 /* If that context got marked stale on this CPU, then flush the 293 337 * local TLB for it and unmark it before we use it 294 338 */ 295 - #ifdef CONFIG_SMP 296 - if (test_bit(id, stale_map[cpu])) { 297 - pr_hardcont(" | stale flush %d [%d..%d]", 298 - id, cpu_first_thread_sibling(cpu), 299 - cpu_last_thread_sibling(cpu)); 300 - 339 + if (IS_ENABLED(CONFIG_SMP) && test_bit(id, stale_map[cpu])) { 301 340 local_flush_tlb_mm(next); 302 341 303 342 /* XXX This clear should ultimately be part of local_flush_tlb_mm */ ··· 300 353 __clear_bit(id, stale_map[i]); 301 354 } 302 355 } 303 - #endif 304 356 305 357 /* Flick the MMU and release lock */ 306 - pr_hardcont(" -> %d\n", id); 358 + if (IS_ENABLED(CONFIG_BDI_SWITCH)) 359 + abatron_pteptrs[1] = next->pgd; 307 360 set_context(id, next->pgd); 308 361 raw_spin_unlock(&context_lock); 309 362 } ··· 313 366 */ 314 367 int init_new_context(struct task_struct *t, struct mm_struct *mm) 315 368 { 316 - pr_hard("initing context for mm @%p\n", mm); 317 - 318 369 /* 319 370 * We have MMU_NO_CONTEXT set to be ~0. Hence check 320 371 * explicitly against context.id == 0. This ensures that we properly ··· 346 401 if (id != MMU_NO_CONTEXT) { 347 402 __clear_bit(id, context_map); 348 403 mm->context.id = MMU_NO_CONTEXT; 349 - #ifdef DEBUG_MAP_CONSISTENCY 350 - mm->context.active = 0; 351 - #endif 352 404 context_mm[id] = NULL; 353 405 nr_free_contexts++; 354 406 } 355 407 raw_spin_unlock_irqrestore(&context_lock, flags); 356 408 } 357 409 358 - #ifdef CONFIG_SMP 359 410 static int mmu_ctx_cpu_prepare(unsigned int cpu) 360 411 { 361 412 /* We don't touch CPU 0 map, it's allocated at aboot and kept ··· 360 419 if (cpu == boot_cpuid) 361 420 return 0; 362 421 363 - pr_devel("MMU: Allocating stale context map for CPU %d\n", cpu); 364 422 stale_map[cpu] = kzalloc(CTX_MAP_SIZE, GFP_KERNEL); 365 423 return 0; 366 424 } ··· 370 430 if (cpu == boot_cpuid) 371 431 return 0; 372 432 373 - pr_devel("MMU: Freeing stale context map for CPU %d\n", cpu); 374 433 kfree(stale_map[cpu]); 375 434 stale_map[cpu] = NULL; 376 435 ··· 378 439 #endif 379 440 return 0; 380 441 } 381 - 382 - #endif /* CONFIG_SMP */ 383 442 384 443 /* 385 444 * Initialize the context management stuff. ··· 402 465 if (!context_mm) 403 466 panic("%s: Failed to allocate %zu bytes\n", __func__, 404 467 sizeof(void *) * (LAST_CONTEXT + 1)); 405 - #ifdef CONFIG_SMP 406 - stale_map[boot_cpuid] = memblock_alloc(CTX_MAP_SIZE, SMP_CACHE_BYTES); 407 - if (!stale_map[boot_cpuid]) 408 - panic("%s: Failed to allocate %zu bytes\n", __func__, 409 - CTX_MAP_SIZE); 468 + if (IS_ENABLED(CONFIG_SMP)) { 469 + stale_map[boot_cpuid] = memblock_alloc(CTX_MAP_SIZE, SMP_CACHE_BYTES); 470 + if (!stale_map[boot_cpuid]) 471 + panic("%s: Failed to allocate %zu bytes\n", __func__, 472 + CTX_MAP_SIZE); 410 473 411 - cpuhp_setup_state_nocalls(CPUHP_POWERPC_MMU_CTX_PREPARE, 412 - "powerpc/mmu/ctx:prepare", 413 - mmu_ctx_cpu_prepare, mmu_ctx_cpu_dead); 414 - #endif 474 + cpuhp_setup_state_nocalls(CPUHP_POWERPC_MMU_CTX_PREPARE, 475 + "powerpc/mmu/ctx:prepare", 476 + mmu_ctx_cpu_prepare, mmu_ctx_cpu_dead); 477 + } 415 478 416 479 printk(KERN_INFO 417 480 "MMU: Allocated %zu bytes of context maps for %d contexts\n",
-13
arch/powerpc/mm/nohash/tlb_low.S
··· 360 360 sync 361 361 wrtee r10 362 362 blr 363 - 364 - _GLOBAL(set_context) 365 - #ifdef CONFIG_BDI_SWITCH 366 - /* Context switch the PTE pointer for the Abatron BDI2000. 367 - * The PGDIR is the second parameter. 368 - */ 369 - lis r5, abatron_pteptrs@h 370 - ori r5, r5, abatron_pteptrs@l 371 - stw r4, 0x4(r5) 372 - #endif 373 - mtspr SPRN_PID,r3 374 - isync /* Force context change */ 375 - blr 376 363 #else 377 364 #error Unsupported processor type ! 378 365 #endif
+134
arch/powerpc/mm/pageattr.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + /* 4 + * MMU-generic set_memory implementation for powerpc 5 + * 6 + * Copyright 2019-2021, IBM Corporation. 7 + */ 8 + 9 + #include <linux/mm.h> 10 + #include <linux/vmalloc.h> 11 + #include <linux/set_memory.h> 12 + 13 + #include <asm/mmu.h> 14 + #include <asm/page.h> 15 + #include <asm/pgtable.h> 16 + 17 + 18 + /* 19 + * Updates the attributes of a page in three steps: 20 + * 21 + * 1. invalidate the page table entry 22 + * 2. flush the TLB 23 + * 3. install the new entry with the updated attributes 24 + * 25 + * Invalidating the pte means there are situations where this will not work 26 + * when in theory it should. 27 + * For example: 28 + * - removing write from page whilst it is being executed 29 + * - setting a page read-only whilst it is being read by another CPU 30 + * 31 + */ 32 + static int change_page_attr(pte_t *ptep, unsigned long addr, void *data) 33 + { 34 + long action = (long)data; 35 + pte_t pte; 36 + 37 + spin_lock(&init_mm.page_table_lock); 38 + 39 + /* invalidate the PTE so it's safe to modify */ 40 + pte = ptep_get_and_clear(&init_mm, addr, ptep); 41 + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); 42 + 43 + /* modify the PTE bits as desired, then apply */ 44 + switch (action) { 45 + case SET_MEMORY_RO: 46 + pte = pte_wrprotect(pte); 47 + break; 48 + case SET_MEMORY_RW: 49 + pte = pte_mkwrite(pte_mkdirty(pte)); 50 + break; 51 + case SET_MEMORY_NX: 52 + pte = pte_exprotect(pte); 53 + break; 54 + case SET_MEMORY_X: 55 + pte = pte_mkexec(pte); 56 + break; 57 + default: 58 + WARN_ON_ONCE(1); 59 + break; 60 + } 61 + 62 + set_pte_at(&init_mm, addr, ptep, pte); 63 + 64 + /* See ptesync comment in radix__set_pte_at() */ 65 + if (radix_enabled()) 66 + asm volatile("ptesync": : :"memory"); 67 + spin_unlock(&init_mm.page_table_lock); 68 + 69 + return 0; 70 + } 71 + 72 + int change_memory_attr(unsigned long addr, int numpages, long action) 73 + { 74 + unsigned long start = ALIGN_DOWN(addr, PAGE_SIZE); 75 + unsigned long size = numpages * PAGE_SIZE; 76 + 77 + if (!numpages) 78 + return 0; 79 + 80 + if (WARN_ON_ONCE(is_vmalloc_or_module_addr((void *)addr) && 81 + is_vm_area_hugepages((void *)addr))) 82 + return -EINVAL; 83 + 84 + #ifdef CONFIG_PPC_BOOK3S_64 85 + /* 86 + * On hash, the linear mapping is not in the Linux page table so 87 + * apply_to_existing_page_range() will have no effect. If in the future 88 + * the set_memory_* functions are used on the linear map this will need 89 + * to be updated. 90 + */ 91 + if (!radix_enabled()) { 92 + int region = get_region_id(addr); 93 + 94 + if (WARN_ON_ONCE(region != VMALLOC_REGION_ID && region != IO_REGION_ID)) 95 + return -EINVAL; 96 + } 97 + #endif 98 + 99 + return apply_to_existing_page_range(&init_mm, start, size, 100 + change_page_attr, (void *)action); 101 + } 102 + 103 + /* 104 + * Set the attributes of a page: 105 + * 106 + * This function is used by PPC32 at the end of init to set final kernel memory 107 + * protection. It includes changing the maping of the page it is executing from 108 + * and data pages it is using. 109 + */ 110 + static int set_page_attr(pte_t *ptep, unsigned long addr, void *data) 111 + { 112 + pgprot_t prot = __pgprot((unsigned long)data); 113 + 114 + spin_lock(&init_mm.page_table_lock); 115 + 116 + set_pte_at(&init_mm, addr, ptep, pte_modify(*ptep, prot)); 117 + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); 118 + 119 + spin_unlock(&init_mm.page_table_lock); 120 + 121 + return 0; 122 + } 123 + 124 + int set_memory_attr(unsigned long addr, int numpages, pgprot_t prot) 125 + { 126 + unsigned long start = ALIGN_DOWN(addr, PAGE_SIZE); 127 + unsigned long sz = numpages * PAGE_SIZE; 128 + 129 + if (numpages <= 0) 130 + return 0; 131 + 132 + return apply_to_existing_page_range(&init_mm, start, sz, set_page_attr, 133 + (void *)pgprot_val(prot)); 134 + }
+8
arch/powerpc/mm/pgtable.c
··· 28 28 #include <asm/hugetlb.h> 29 29 #include <asm/pte-walk.h> 30 30 31 + #ifdef CONFIG_PPC64 32 + #define PGD_ALIGN (sizeof(pgd_t) * MAX_PTRS_PER_PGD) 33 + #else 34 + #define PGD_ALIGN PAGE_SIZE 35 + #endif 36 + 37 + pgd_t swapper_pg_dir[MAX_PTRS_PER_PGD] __section(".bss..page_aligned") __aligned(PGD_ALIGN); 38 + 31 39 static inline int is_exec_fault(void) 32 40 { 33 41 return current->thread.regs && TRAP(current->thread.regs) == 0x400;
+10 -50
arch/powerpc/mm/pgtable_32.c
··· 23 23 #include <linux/highmem.h> 24 24 #include <linux/memblock.h> 25 25 #include <linux/slab.h> 26 + #include <linux/set_memory.h> 26 27 27 28 #include <asm/pgalloc.h> 28 29 #include <asm/fixmap.h> ··· 133 132 } 134 133 } 135 134 136 - static int __change_page_attr_noflush(struct page *page, pgprot_t prot) 137 - { 138 - pte_t *kpte; 139 - unsigned long address; 140 - 141 - BUG_ON(PageHighMem(page)); 142 - address = (unsigned long)page_address(page); 143 - 144 - if (v_block_mapped(address)) 145 - return 0; 146 - kpte = virt_to_kpte(address); 147 - if (!kpte) 148 - return -EINVAL; 149 - __set_pte_at(&init_mm, address, kpte, mk_pte(page, prot), 0); 150 - 151 - return 0; 152 - } 153 - 154 - /* 155 - * Change the page attributes of an page in the linear mapping. 156 - * 157 - * THIS DOES NOTHING WITH BAT MAPPINGS, DEBUG USE ONLY 158 - */ 159 - static int change_page_attr(struct page *page, int numpages, pgprot_t prot) 160 - { 161 - int i, err = 0; 162 - unsigned long flags; 163 - struct page *start = page; 164 - 165 - local_irq_save(flags); 166 - for (i = 0; i < numpages; i++, page++) { 167 - err = __change_page_attr_noflush(page, prot); 168 - if (err) 169 - break; 170 - } 171 - wmb(); 172 - local_irq_restore(flags); 173 - flush_tlb_kernel_range((unsigned long)page_address(start), 174 - (unsigned long)page_address(page)); 175 - return err; 176 - } 177 - 178 135 void mark_initmem_nx(void) 179 136 { 180 - struct page *page = virt_to_page(_sinittext); 181 137 unsigned long numpages = PFN_UP((unsigned long)_einittext) - 182 138 PFN_DOWN((unsigned long)_sinittext); 183 139 184 140 if (v_block_mapped((unsigned long)_sinittext)) 185 141 mmu_mark_initmem_nx(); 186 142 else 187 - change_page_attr(page, numpages, PAGE_KERNEL); 143 + set_memory_attr((unsigned long)_sinittext, numpages, PAGE_KERNEL); 188 144 } 189 145 190 146 #ifdef CONFIG_STRICT_KERNEL_RWX 191 147 void mark_rodata_ro(void) 192 148 { 193 - struct page *page; 194 149 unsigned long numpages; 195 150 196 151 if (v_block_mapped((unsigned long)_stext + 1)) { ··· 155 198 return; 156 199 } 157 200 158 - page = virt_to_page(_stext); 159 201 numpages = PFN_UP((unsigned long)_etext) - 160 202 PFN_DOWN((unsigned long)_stext); 161 203 162 - change_page_attr(page, numpages, PAGE_KERNEL_ROX); 204 + set_memory_attr((unsigned long)_stext, numpages, PAGE_KERNEL_ROX); 163 205 /* 164 206 * mark .rodata as read only. Use __init_begin rather than __end_rodata 165 207 * to cover NOTES and EXCEPTION_TABLE. 166 208 */ 167 - page = virt_to_page(__start_rodata); 168 209 numpages = PFN_UP((unsigned long)__init_begin) - 169 210 PFN_DOWN((unsigned long)__start_rodata); 170 211 171 - change_page_attr(page, numpages, PAGE_KERNEL_RO); 212 + set_memory_attr((unsigned long)__start_rodata, numpages, PAGE_KERNEL_RO); 172 213 173 214 // mark_initmem_nx() should have already run by now 174 215 ptdump_check_wx(); ··· 176 221 #ifdef CONFIG_DEBUG_PAGEALLOC 177 222 void __kernel_map_pages(struct page *page, int numpages, int enable) 178 223 { 224 + unsigned long addr = (unsigned long)page_address(page); 225 + 179 226 if (PageHighMem(page)) 180 227 return; 181 228 182 - change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0)); 229 + if (enable) 230 + set_memory_attr(addr, numpages, PAGE_KERNEL); 231 + else 232 + set_memory_attr(addr, numpages, __pgprot(0)); 183 233 } 184 234 #endif /* CONFIG_DEBUG_PAGEALLOC */
+3 -19
arch/powerpc/mm/ptdump/ptdump.c
··· 58 58 const struct addr_marker *marker; 59 59 unsigned long start_address; 60 60 unsigned long start_pa; 61 - unsigned long last_pa; 62 - unsigned long page_size; 63 61 unsigned int level; 64 62 u64 current_flags; 65 63 bool check_wx; ··· 161 163 162 164 static void dump_addr(struct pg_state *st, unsigned long addr) 163 165 { 164 - unsigned long delta; 165 - 166 166 #ifdef CONFIG_PPC64 167 167 #define REG "0x%016lx" 168 168 #else ··· 168 172 #endif 169 173 170 174 pt_dump_seq_printf(st->seq, REG "-" REG " ", st->start_address, addr - 1); 171 - if (st->start_pa == st->last_pa && st->start_address + st->page_size != addr) { 172 - pt_dump_seq_printf(st->seq, "[" REG "]", st->start_pa); 173 - delta = st->page_size >> 10; 174 - } else { 175 - pt_dump_seq_printf(st->seq, " " REG " ", st->start_pa); 176 - delta = (addr - st->start_address) >> 10; 177 - } 178 - pt_dump_size(st->seq, delta); 175 + pt_dump_seq_printf(st->seq, " " REG " ", st->start_pa); 176 + pt_dump_size(st->seq, (addr - st->start_address) >> 10); 179 177 } 180 178 181 179 static void note_prot_wx(struct pg_state *st, unsigned long addr) ··· 198 208 st->current_flags = flag; 199 209 st->start_address = addr; 200 210 st->start_pa = pa; 201 - st->page_size = page_size; 202 211 203 212 while (addr >= st->marker[1].start_address) { 204 213 st->marker++; ··· 209 220 unsigned int level, u64 val, unsigned long page_size) 210 221 { 211 222 u64 flag = val & pg_level[level].mask; 212 - u64 pa = val & PTE_RPN_MASK; 213 223 214 224 /* At first no level is set */ 215 225 if (!st->level) { ··· 220 232 * - we change levels in the tree. 221 233 * - the address is in a different section of memory and is thus 222 234 * used for a different purpose, regardless of the flags. 223 - * - the pa of this page is not adjacent to the last inspected page 224 235 */ 225 236 } else if (flag != st->current_flags || level != st->level || 226 - addr >= st->marker[1].start_address || 227 - (pa != st->last_pa + st->page_size && 228 - (pa != st->start_pa || st->start_pa != st->last_pa))) { 237 + addr >= st->marker[1].start_address) { 229 238 230 239 /* Check the PTE flags */ 231 240 if (st->current_flags) { ··· 244 259 */ 245 260 note_page_update_state(st, addr, level, val, page_size); 246 261 } 247 - st->last_pa = pa; 248 262 } 249 263 250 264 static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start)
+1 -12
arch/powerpc/net/bpf_jit_comp.c
··· 237 237 fp->jited_len = alloclen; 238 238 239 239 bpf_flush_icache(bpf_hdr, (u8 *)bpf_hdr + (bpf_hdr->pages * PAGE_SIZE)); 240 + bpf_jit_binary_lock_ro(bpf_hdr); 240 241 if (!fp->is_func || extra_pass) { 241 242 bpf_prog_fill_jited_linfo(fp, addrs); 242 243 out_addrs: ··· 257 256 bpf_jit_prog_release_other(fp, fp == org_fp ? tmp_fp : org_fp); 258 257 259 258 return fp; 260 - } 261 - 262 - /* Overriding bpf_jit_free() as we don't set images read-only. */ 263 - void bpf_jit_free(struct bpf_prog *fp) 264 - { 265 - unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK; 266 - struct bpf_binary_header *bpf_hdr = (void *)addr; 267 - 268 - if (fp->jited) 269 - bpf_jit_binary_free(bpf_hdr); 270 - 271 - bpf_prog_unlock_free(fp); 272 259 }
+110 -110
arch/powerpc/net/bpf_jit_comp32.c
··· 108 108 int i; 109 109 110 110 /* First arg comes in as a 32 bits pointer. */ 111 - EMIT(PPC_RAW_MR(bpf_to_ppc(ctx, BPF_REG_1), __REG_R3)); 111 + EMIT(PPC_RAW_MR(bpf_to_ppc(ctx, BPF_REG_1), _R3)); 112 112 EMIT(PPC_RAW_LI(bpf_to_ppc(ctx, BPF_REG_1) - 1, 0)); 113 - EMIT(PPC_RAW_STWU(__REG_R1, __REG_R1, -BPF_PPC_STACKFRAME(ctx))); 113 + EMIT(PPC_RAW_STWU(_R1, _R1, -BPF_PPC_STACKFRAME(ctx))); 114 114 115 115 /* 116 116 * Initialize tail_call_cnt in stack frame if we do tail calls. 117 117 * Otherwise, put in NOPs so that it can be skipped when we are 118 118 * invoked through a tail call. 119 119 */ 120 - if (ctx->seen & SEEN_TAILCALL) { 121 - EMIT(PPC_RAW_STW(bpf_to_ppc(ctx, BPF_REG_1) - 1, __REG_R1, bpf_jit_stack_offsetof(ctx, BPF_PPC_TC))); 122 - } else { 120 + if (ctx->seen & SEEN_TAILCALL) 121 + EMIT(PPC_RAW_STW(bpf_to_ppc(ctx, BPF_REG_1) - 1, _R1, 122 + bpf_jit_stack_offsetof(ctx, BPF_PPC_TC))); 123 + else 123 124 EMIT(PPC_RAW_NOP()); 124 - } 125 125 126 126 #define BPF_TAILCALL_PROLOGUE_SIZE 16 127 127 ··· 130 130 * save/restore LR unless we call other functions 131 131 */ 132 132 if (ctx->seen & SEEN_FUNC) 133 - EMIT(PPC_RAW_MFLR(__REG_R0)); 133 + EMIT(PPC_RAW_MFLR(_R0)); 134 134 135 135 /* 136 136 * Back up non-volatile regs -- registers r18-r31 137 137 */ 138 138 for (i = BPF_PPC_NVR_MIN; i <= 31; i++) 139 139 if (bpf_is_seen_register(ctx, i)) 140 - EMIT(PPC_RAW_STW(i, __REG_R1, bpf_jit_stack_offsetof(ctx, i))); 140 + EMIT(PPC_RAW_STW(i, _R1, bpf_jit_stack_offsetof(ctx, i))); 141 141 142 142 /* If needed retrieve arguments 9 and 10, ie 5th 64 bits arg.*/ 143 143 if (bpf_is_seen_register(ctx, bpf_to_ppc(ctx, BPF_REG_5))) { 144 - EMIT(PPC_RAW_LWZ(bpf_to_ppc(ctx, BPF_REG_5) - 1, __REG_R1, BPF_PPC_STACKFRAME(ctx)) + 8); 145 - EMIT(PPC_RAW_LWZ(bpf_to_ppc(ctx, BPF_REG_5), __REG_R1, BPF_PPC_STACKFRAME(ctx)) + 12); 144 + EMIT(PPC_RAW_LWZ(bpf_to_ppc(ctx, BPF_REG_5) - 1, _R1, BPF_PPC_STACKFRAME(ctx)) + 8); 145 + EMIT(PPC_RAW_LWZ(bpf_to_ppc(ctx, BPF_REG_5), _R1, BPF_PPC_STACKFRAME(ctx)) + 12); 146 146 } 147 147 148 148 /* Setup frame pointer to point to the bpf stack area */ 149 149 if (bpf_is_seen_register(ctx, bpf_to_ppc(ctx, BPF_REG_FP))) { 150 150 EMIT(PPC_RAW_LI(bpf_to_ppc(ctx, BPF_REG_FP) - 1, 0)); 151 - EMIT(PPC_RAW_ADDI(bpf_to_ppc(ctx, BPF_REG_FP), __REG_R1, 151 + EMIT(PPC_RAW_ADDI(bpf_to_ppc(ctx, BPF_REG_FP), _R1, 152 152 STACK_FRAME_MIN_SIZE + ctx->stack_size)); 153 153 } 154 154 155 155 if (ctx->seen & SEEN_FUNC) 156 - EMIT(PPC_RAW_STW(__REG_R0, __REG_R1, BPF_PPC_STACKFRAME(ctx) + PPC_LR_STKOFF)); 156 + EMIT(PPC_RAW_STW(_R0, _R1, BPF_PPC_STACKFRAME(ctx) + PPC_LR_STKOFF)); 157 157 } 158 158 159 159 static void bpf_jit_emit_common_epilogue(u32 *image, struct codegen_context *ctx) ··· 163 163 /* Restore NVRs */ 164 164 for (i = BPF_PPC_NVR_MIN; i <= 31; i++) 165 165 if (bpf_is_seen_register(ctx, i)) 166 - EMIT(PPC_RAW_LWZ(i, __REG_R1, bpf_jit_stack_offsetof(ctx, i))); 166 + EMIT(PPC_RAW_LWZ(i, _R1, bpf_jit_stack_offsetof(ctx, i))); 167 167 } 168 168 169 169 void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx) 170 170 { 171 - EMIT(PPC_RAW_MR(__REG_R3, bpf_to_ppc(ctx, BPF_REG_0))); 171 + EMIT(PPC_RAW_MR(_R3, bpf_to_ppc(ctx, BPF_REG_0))); 172 172 173 173 bpf_jit_emit_common_epilogue(image, ctx); 174 174 175 175 /* Tear down our stack frame */ 176 176 177 177 if (ctx->seen & SEEN_FUNC) 178 - EMIT(PPC_RAW_LWZ(__REG_R0, __REG_R1, BPF_PPC_STACKFRAME(ctx) + PPC_LR_STKOFF)); 178 + EMIT(PPC_RAW_LWZ(_R0, _R1, BPF_PPC_STACKFRAME(ctx) + PPC_LR_STKOFF)); 179 179 180 - EMIT(PPC_RAW_ADDI(__REG_R1, __REG_R1, BPF_PPC_STACKFRAME(ctx))); 180 + EMIT(PPC_RAW_ADDI(_R1, _R1, BPF_PPC_STACKFRAME(ctx))); 181 181 182 182 if (ctx->seen & SEEN_FUNC) 183 - EMIT(PPC_RAW_MTLR(__REG_R0)); 183 + EMIT(PPC_RAW_MTLR(_R0)); 184 184 185 185 EMIT(PPC_RAW_BLR()); 186 186 } ··· 193 193 PPC_BL_ABS(func); 194 194 } else { 195 195 /* Load function address into r0 */ 196 - EMIT(PPC_RAW_LIS(__REG_R0, IMM_H(func))); 197 - EMIT(PPC_RAW_ORI(__REG_R0, __REG_R0, IMM_L(func))); 198 - EMIT(PPC_RAW_MTLR(__REG_R0)); 199 - EMIT(PPC_RAW_BLRL()); 196 + EMIT(PPC_RAW_LIS(_R0, IMM_H(func))); 197 + EMIT(PPC_RAW_ORI(_R0, _R0, IMM_L(func))); 198 + EMIT(PPC_RAW_MTCTR(_R0)); 199 + EMIT(PPC_RAW_BCTRL()); 200 200 } 201 201 } 202 202 ··· 215 215 * if (index >= array->map.max_entries) 216 216 * goto out; 217 217 */ 218 - EMIT(PPC_RAW_LWZ(__REG_R0, b2p_bpf_array, offsetof(struct bpf_array, map.max_entries))); 219 - EMIT(PPC_RAW_CMPLW(b2p_index, __REG_R0)); 220 - EMIT(PPC_RAW_LWZ(__REG_R0, __REG_R1, bpf_jit_stack_offsetof(ctx, BPF_PPC_TC))); 218 + EMIT(PPC_RAW_LWZ(_R0, b2p_bpf_array, offsetof(struct bpf_array, map.max_entries))); 219 + EMIT(PPC_RAW_CMPLW(b2p_index, _R0)); 220 + EMIT(PPC_RAW_LWZ(_R0, _R1, bpf_jit_stack_offsetof(ctx, BPF_PPC_TC))); 221 221 PPC_BCC(COND_GE, out); 222 222 223 223 /* 224 224 * if (tail_call_cnt > MAX_TAIL_CALL_CNT) 225 225 * goto out; 226 226 */ 227 - EMIT(PPC_RAW_CMPLWI(__REG_R0, MAX_TAIL_CALL_CNT)); 227 + EMIT(PPC_RAW_CMPLWI(_R0, MAX_TAIL_CALL_CNT)); 228 228 /* tail_call_cnt++; */ 229 - EMIT(PPC_RAW_ADDIC(__REG_R0, __REG_R0, 1)); 229 + EMIT(PPC_RAW_ADDIC(_R0, _R0, 1)); 230 230 PPC_BCC(COND_GT, out); 231 231 232 232 /* prog = array->ptrs[index]; */ 233 - EMIT(PPC_RAW_RLWINM(__REG_R3, b2p_index, 2, 0, 29)); 234 - EMIT(PPC_RAW_ADD(__REG_R3, __REG_R3, b2p_bpf_array)); 235 - EMIT(PPC_RAW_LWZ(__REG_R3, __REG_R3, offsetof(struct bpf_array, ptrs))); 236 - EMIT(PPC_RAW_STW(__REG_R0, __REG_R1, bpf_jit_stack_offsetof(ctx, BPF_PPC_TC))); 233 + EMIT(PPC_RAW_RLWINM(_R3, b2p_index, 2, 0, 29)); 234 + EMIT(PPC_RAW_ADD(_R3, _R3, b2p_bpf_array)); 235 + EMIT(PPC_RAW_LWZ(_R3, _R3, offsetof(struct bpf_array, ptrs))); 236 + EMIT(PPC_RAW_STW(_R0, _R1, bpf_jit_stack_offsetof(ctx, BPF_PPC_TC))); 237 237 238 238 /* 239 239 * if (prog == NULL) 240 240 * goto out; 241 241 */ 242 - EMIT(PPC_RAW_CMPLWI(__REG_R3, 0)); 242 + EMIT(PPC_RAW_CMPLWI(_R3, 0)); 243 243 PPC_BCC(COND_EQ, out); 244 244 245 245 /* goto *(prog->bpf_func + prologue_size); */ 246 - EMIT(PPC_RAW_LWZ(__REG_R3, __REG_R3, offsetof(struct bpf_prog, bpf_func))); 246 + EMIT(PPC_RAW_LWZ(_R3, _R3, offsetof(struct bpf_prog, bpf_func))); 247 247 248 248 if (ctx->seen & SEEN_FUNC) 249 - EMIT(PPC_RAW_LWZ(__REG_R0, __REG_R1, BPF_PPC_STACKFRAME(ctx) + PPC_LR_STKOFF)); 249 + EMIT(PPC_RAW_LWZ(_R0, _R1, BPF_PPC_STACKFRAME(ctx) + PPC_LR_STKOFF)); 250 250 251 - EMIT(PPC_RAW_ADDIC(__REG_R3, __REG_R3, BPF_TAILCALL_PROLOGUE_SIZE)); 251 + EMIT(PPC_RAW_ADDIC(_R3, _R3, BPF_TAILCALL_PROLOGUE_SIZE)); 252 252 253 253 if (ctx->seen & SEEN_FUNC) 254 - EMIT(PPC_RAW_MTLR(__REG_R0)); 254 + EMIT(PPC_RAW_MTLR(_R0)); 255 255 256 - EMIT(PPC_RAW_MTCTR(__REG_R3)); 256 + EMIT(PPC_RAW_MTCTR(_R3)); 257 257 258 - EMIT(PPC_RAW_MR(__REG_R3, bpf_to_ppc(ctx, BPF_REG_1))); 258 + EMIT(PPC_RAW_MR(_R3, bpf_to_ppc(ctx, BPF_REG_1))); 259 259 260 260 /* tear restore NVRs, ... */ 261 261 bpf_jit_emit_common_epilogue(image, ctx); ··· 352 352 if (imm >= -32768 && imm < 32768) { 353 353 EMIT(PPC_RAW_ADDIC(dst_reg, dst_reg, imm)); 354 354 } else { 355 - PPC_LI32(__REG_R0, imm); 356 - EMIT(PPC_RAW_ADDC(dst_reg, dst_reg, __REG_R0)); 355 + PPC_LI32(_R0, imm); 356 + EMIT(PPC_RAW_ADDC(dst_reg, dst_reg, _R0)); 357 357 } 358 358 if (imm >= 0) 359 359 EMIT(PPC_RAW_ADDZE(dst_reg_h, dst_reg_h)); ··· 362 362 break; 363 363 case BPF_ALU64 | BPF_MUL | BPF_X: /* dst *= src */ 364 364 bpf_set_seen_register(ctx, tmp_reg); 365 - EMIT(PPC_RAW_MULW(__REG_R0, dst_reg, src_reg_h)); 365 + EMIT(PPC_RAW_MULW(_R0, dst_reg, src_reg_h)); 366 366 EMIT(PPC_RAW_MULW(dst_reg_h, dst_reg_h, src_reg)); 367 367 EMIT(PPC_RAW_MULHWU(tmp_reg, dst_reg, src_reg)); 368 368 EMIT(PPC_RAW_MULW(dst_reg, dst_reg, src_reg)); 369 - EMIT(PPC_RAW_ADD(dst_reg_h, dst_reg_h, __REG_R0)); 369 + EMIT(PPC_RAW_ADD(dst_reg_h, dst_reg_h, _R0)); 370 370 EMIT(PPC_RAW_ADD(dst_reg_h, dst_reg_h, tmp_reg)); 371 371 break; 372 372 case BPF_ALU | BPF_MUL | BPF_X: /* (u32) dst *= (u32) src */ ··· 376 376 if (imm >= -32768 && imm < 32768) { 377 377 EMIT(PPC_RAW_MULI(dst_reg, dst_reg, imm)); 378 378 } else { 379 - PPC_LI32(__REG_R0, imm); 380 - EMIT(PPC_RAW_MULW(dst_reg, dst_reg, __REG_R0)); 379 + PPC_LI32(_R0, imm); 380 + EMIT(PPC_RAW_MULW(dst_reg, dst_reg, _R0)); 381 381 } 382 382 break; 383 383 case BPF_ALU64 | BPF_MUL | BPF_K: /* dst *= imm */ ··· 398 398 EMIT(PPC_RAW_MULW(dst_reg_h, dst_reg_h, tmp_reg)); 399 399 if (imm < 0) 400 400 EMIT(PPC_RAW_SUB(dst_reg_h, dst_reg_h, dst_reg)); 401 - EMIT(PPC_RAW_MULHWU(__REG_R0, dst_reg, tmp_reg)); 401 + EMIT(PPC_RAW_MULHWU(_R0, dst_reg, tmp_reg)); 402 402 EMIT(PPC_RAW_MULW(dst_reg, dst_reg, tmp_reg)); 403 - EMIT(PPC_RAW_ADD(dst_reg_h, dst_reg_h, __REG_R0)); 403 + EMIT(PPC_RAW_ADD(dst_reg_h, dst_reg_h, _R0)); 404 404 break; 405 405 case BPF_ALU | BPF_DIV | BPF_X: /* (u32) dst /= (u32) src */ 406 406 EMIT(PPC_RAW_DIVWU(dst_reg, dst_reg, src_reg)); 407 407 break; 408 408 case BPF_ALU | BPF_MOD | BPF_X: /* (u32) dst %= (u32) src */ 409 - EMIT(PPC_RAW_DIVWU(__REG_R0, dst_reg, src_reg)); 410 - EMIT(PPC_RAW_MULW(__REG_R0, src_reg, __REG_R0)); 411 - EMIT(PPC_RAW_SUB(dst_reg, dst_reg, __REG_R0)); 409 + EMIT(PPC_RAW_DIVWU(_R0, dst_reg, src_reg)); 410 + EMIT(PPC_RAW_MULW(_R0, src_reg, _R0)); 411 + EMIT(PPC_RAW_SUB(dst_reg, dst_reg, _R0)); 412 412 break; 413 413 case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */ 414 414 return -EOPNOTSUPP; ··· 420 420 if (imm == 1) 421 421 break; 422 422 423 - PPC_LI32(__REG_R0, imm); 424 - EMIT(PPC_RAW_DIVWU(dst_reg, dst_reg, __REG_R0)); 423 + PPC_LI32(_R0, imm); 424 + EMIT(PPC_RAW_DIVWU(dst_reg, dst_reg, _R0)); 425 425 break; 426 426 case BPF_ALU | BPF_MOD | BPF_K: /* (u32) dst %= (u32) imm */ 427 427 if (!imm) ··· 430 430 if (!is_power_of_2((u32)imm)) { 431 431 bpf_set_seen_register(ctx, tmp_reg); 432 432 PPC_LI32(tmp_reg, imm); 433 - EMIT(PPC_RAW_DIVWU(__REG_R0, dst_reg, tmp_reg)); 434 - EMIT(PPC_RAW_MULW(__REG_R0, tmp_reg, __REG_R0)); 435 - EMIT(PPC_RAW_SUB(dst_reg, dst_reg, __REG_R0)); 433 + EMIT(PPC_RAW_DIVWU(_R0, dst_reg, tmp_reg)); 434 + EMIT(PPC_RAW_MULW(_R0, tmp_reg, _R0)); 435 + EMIT(PPC_RAW_SUB(dst_reg, dst_reg, _R0)); 436 436 break; 437 437 } 438 438 if (imm == 1) ··· 503 503 EMIT(PPC_RAW_RLWINM(dst_reg, dst_reg, 0, 504 504 32 - fls(imm), 32 - ffs(imm))); 505 505 } else { 506 - PPC_LI32(__REG_R0, imm); 507 - EMIT(PPC_RAW_AND(dst_reg, dst_reg, __REG_R0)); 506 + PPC_LI32(_R0, imm); 507 + EMIT(PPC_RAW_AND(dst_reg, dst_reg, _R0)); 508 508 } 509 509 break; 510 510 case BPF_ALU64 | BPF_OR | BPF_X: /* dst = dst | src */ ··· 555 555 break; 556 556 case BPF_ALU64 | BPF_LSH | BPF_X: /* dst <<= src; */ 557 557 bpf_set_seen_register(ctx, tmp_reg); 558 - EMIT(PPC_RAW_SUBFIC(__REG_R0, src_reg, 32)); 558 + EMIT(PPC_RAW_SUBFIC(_R0, src_reg, 32)); 559 559 EMIT(PPC_RAW_SLW(dst_reg_h, dst_reg_h, src_reg)); 560 560 EMIT(PPC_RAW_ADDI(tmp_reg, src_reg, 32)); 561 - EMIT(PPC_RAW_SRW(__REG_R0, dst_reg, __REG_R0)); 561 + EMIT(PPC_RAW_SRW(_R0, dst_reg, _R0)); 562 562 EMIT(PPC_RAW_SLW(tmp_reg, dst_reg, tmp_reg)); 563 - EMIT(PPC_RAW_OR(dst_reg_h, dst_reg_h, __REG_R0)); 563 + EMIT(PPC_RAW_OR(dst_reg_h, dst_reg_h, _R0)); 564 564 EMIT(PPC_RAW_SLW(dst_reg, dst_reg, src_reg)); 565 565 EMIT(PPC_RAW_OR(dst_reg_h, dst_reg_h, tmp_reg)); 566 566 break; ··· 591 591 break; 592 592 case BPF_ALU64 | BPF_RSH | BPF_X: /* dst >>= src */ 593 593 bpf_set_seen_register(ctx, tmp_reg); 594 - EMIT(PPC_RAW_SUBFIC(__REG_R0, src_reg, 32)); 594 + EMIT(PPC_RAW_SUBFIC(_R0, src_reg, 32)); 595 595 EMIT(PPC_RAW_SRW(dst_reg, dst_reg, src_reg)); 596 596 EMIT(PPC_RAW_ADDI(tmp_reg, src_reg, 32)); 597 - EMIT(PPC_RAW_SLW(__REG_R0, dst_reg_h, __REG_R0)); 597 + EMIT(PPC_RAW_SLW(_R0, dst_reg_h, _R0)); 598 598 EMIT(PPC_RAW_SRW(tmp_reg, dst_reg_h, tmp_reg)); 599 - EMIT(PPC_RAW_OR(dst_reg, dst_reg, __REG_R0)); 599 + EMIT(PPC_RAW_OR(dst_reg, dst_reg, _R0)); 600 600 EMIT(PPC_RAW_SRW(dst_reg_h, dst_reg_h, src_reg)); 601 601 EMIT(PPC_RAW_OR(dst_reg, dst_reg, tmp_reg)); 602 602 break; ··· 627 627 break; 628 628 case BPF_ALU64 | BPF_ARSH | BPF_X: /* (s64) dst >>= src */ 629 629 bpf_set_seen_register(ctx, tmp_reg); 630 - EMIT(PPC_RAW_SUBFIC(__REG_R0, src_reg, 32)); 630 + EMIT(PPC_RAW_SUBFIC(_R0, src_reg, 32)); 631 631 EMIT(PPC_RAW_SRW(dst_reg, dst_reg, src_reg)); 632 - EMIT(PPC_RAW_SLW(__REG_R0, dst_reg_h, __REG_R0)); 632 + EMIT(PPC_RAW_SLW(_R0, dst_reg_h, _R0)); 633 633 EMIT(PPC_RAW_ADDI(tmp_reg, src_reg, 32)); 634 - EMIT(PPC_RAW_OR(dst_reg, dst_reg, __REG_R0)); 635 - EMIT(PPC_RAW_RLWINM(__REG_R0, tmp_reg, 0, 26, 26)); 634 + EMIT(PPC_RAW_OR(dst_reg, dst_reg, _R0)); 635 + EMIT(PPC_RAW_RLWINM(_R0, tmp_reg, 0, 26, 26)); 636 636 EMIT(PPC_RAW_SRAW(tmp_reg, dst_reg_h, tmp_reg)); 637 637 EMIT(PPC_RAW_SRAW(dst_reg_h, dst_reg_h, src_reg)); 638 - EMIT(PPC_RAW_SLW(tmp_reg, tmp_reg, __REG_R0)); 638 + EMIT(PPC_RAW_SLW(tmp_reg, tmp_reg, _R0)); 639 639 EMIT(PPC_RAW_OR(dst_reg, dst_reg, tmp_reg)); 640 640 break; 641 641 case BPF_ALU | BPF_ARSH | BPF_K: /* (s32) dst >>= imm */ ··· 702 702 * 2 bytes are already in their final position 703 703 * -- byte 2 and 4 (of bytes 1, 2, 3 and 4) 704 704 */ 705 - EMIT(PPC_RAW_RLWINM(__REG_R0, dst_reg, 8, 0, 31)); 705 + EMIT(PPC_RAW_RLWINM(_R0, dst_reg, 8, 0, 31)); 706 706 /* Rotate 24 bits and insert byte 1 */ 707 - EMIT(PPC_RAW_RLWIMI(__REG_R0, dst_reg, 24, 0, 7)); 707 + EMIT(PPC_RAW_RLWIMI(_R0, dst_reg, 24, 0, 7)); 708 708 /* Rotate 24 bits and insert byte 3 */ 709 - EMIT(PPC_RAW_RLWIMI(__REG_R0, dst_reg, 24, 16, 23)); 710 - EMIT(PPC_RAW_MR(dst_reg, __REG_R0)); 709 + EMIT(PPC_RAW_RLWIMI(_R0, dst_reg, 24, 16, 23)); 710 + EMIT(PPC_RAW_MR(dst_reg, _R0)); 711 711 break; 712 712 case 64: 713 713 bpf_set_seen_register(ctx, tmp_reg); 714 714 EMIT(PPC_RAW_RLWINM(tmp_reg, dst_reg, 8, 0, 31)); 715 - EMIT(PPC_RAW_RLWINM(__REG_R0, dst_reg_h, 8, 0, 31)); 715 + EMIT(PPC_RAW_RLWINM(_R0, dst_reg_h, 8, 0, 31)); 716 716 /* Rotate 24 bits and insert byte 1 */ 717 717 EMIT(PPC_RAW_RLWIMI(tmp_reg, dst_reg, 24, 0, 7)); 718 - EMIT(PPC_RAW_RLWIMI(__REG_R0, dst_reg_h, 24, 0, 7)); 718 + EMIT(PPC_RAW_RLWIMI(_R0, dst_reg_h, 24, 0, 7)); 719 719 /* Rotate 24 bits and insert byte 3 */ 720 720 EMIT(PPC_RAW_RLWIMI(tmp_reg, dst_reg, 24, 16, 23)); 721 - EMIT(PPC_RAW_RLWIMI(__REG_R0, dst_reg_h, 24, 16, 23)); 722 - EMIT(PPC_RAW_MR(dst_reg, __REG_R0)); 721 + EMIT(PPC_RAW_RLWIMI(_R0, dst_reg_h, 24, 16, 23)); 722 + EMIT(PPC_RAW_MR(dst_reg, _R0)); 723 723 EMIT(PPC_RAW_MR(dst_reg_h, tmp_reg)); 724 724 break; 725 725 } ··· 744 744 EMIT(PPC_RAW_STB(src_reg, dst_reg, off)); 745 745 break; 746 746 case BPF_ST | BPF_MEM | BPF_B: /* *(u8 *)(dst + off) = imm */ 747 - PPC_LI32(__REG_R0, imm); 748 - EMIT(PPC_RAW_STB(__REG_R0, dst_reg, off)); 747 + PPC_LI32(_R0, imm); 748 + EMIT(PPC_RAW_STB(_R0, dst_reg, off)); 749 749 break; 750 750 case BPF_STX | BPF_MEM | BPF_H: /* (u16 *)(dst + off) = src */ 751 751 EMIT(PPC_RAW_STH(src_reg, dst_reg, off)); 752 752 break; 753 753 case BPF_ST | BPF_MEM | BPF_H: /* (u16 *)(dst + off) = imm */ 754 - PPC_LI32(__REG_R0, imm); 755 - EMIT(PPC_RAW_STH(__REG_R0, dst_reg, off)); 754 + PPC_LI32(_R0, imm); 755 + EMIT(PPC_RAW_STH(_R0, dst_reg, off)); 756 756 break; 757 757 case BPF_STX | BPF_MEM | BPF_W: /* *(u32 *)(dst + off) = src */ 758 758 EMIT(PPC_RAW_STW(src_reg, dst_reg, off)); 759 759 break; 760 760 case BPF_ST | BPF_MEM | BPF_W: /* *(u32 *)(dst + off) = imm */ 761 - PPC_LI32(__REG_R0, imm); 762 - EMIT(PPC_RAW_STW(__REG_R0, dst_reg, off)); 761 + PPC_LI32(_R0, imm); 762 + EMIT(PPC_RAW_STW(_R0, dst_reg, off)); 763 763 break; 764 764 case BPF_STX | BPF_MEM | BPF_DW: /* (u64 *)(dst + off) = src */ 765 765 EMIT(PPC_RAW_STW(src_reg_h, dst_reg, off)); 766 766 EMIT(PPC_RAW_STW(src_reg, dst_reg, off + 4)); 767 767 break; 768 768 case BPF_ST | BPF_MEM | BPF_DW: /* *(u64 *)(dst + off) = imm */ 769 - PPC_LI32(__REG_R0, imm); 770 - EMIT(PPC_RAW_STW(__REG_R0, dst_reg, off + 4)); 771 - PPC_EX32(__REG_R0, imm); 772 - EMIT(PPC_RAW_STW(__REG_R0, dst_reg, off)); 769 + PPC_LI32(_R0, imm); 770 + EMIT(PPC_RAW_STW(_R0, dst_reg, off + 4)); 771 + PPC_EX32(_R0, imm); 772 + EMIT(PPC_RAW_STW(_R0, dst_reg, off)); 773 773 break; 774 774 775 775 /* ··· 780 780 /* Get offset into TMP_REG */ 781 781 EMIT(PPC_RAW_LI(tmp_reg, off)); 782 782 /* load value from memory into r0 */ 783 - EMIT(PPC_RAW_LWARX(__REG_R0, tmp_reg, dst_reg, 0)); 783 + EMIT(PPC_RAW_LWARX(_R0, tmp_reg, dst_reg, 0)); 784 784 /* add value from src_reg into this */ 785 - EMIT(PPC_RAW_ADD(__REG_R0, __REG_R0, src_reg)); 785 + EMIT(PPC_RAW_ADD(_R0, _R0, src_reg)); 786 786 /* store result back */ 787 - EMIT(PPC_RAW_STWCX(__REG_R0, tmp_reg, dst_reg)); 787 + EMIT(PPC_RAW_STWCX(_R0, tmp_reg, dst_reg)); 788 788 /* we're done if this succeeded */ 789 789 PPC_BCC_SHORT(COND_NE, (ctx->idx - 3) * 4); 790 790 break; ··· 852 852 return ret; 853 853 854 854 if (bpf_is_seen_register(ctx, bpf_to_ppc(ctx, BPF_REG_5))) { 855 - EMIT(PPC_RAW_STW(bpf_to_ppc(ctx, BPF_REG_5) - 1, __REG_R1, 8)); 856 - EMIT(PPC_RAW_STW(bpf_to_ppc(ctx, BPF_REG_5), __REG_R1, 12)); 855 + EMIT(PPC_RAW_STW(bpf_to_ppc(ctx, BPF_REG_5) - 1, _R1, 8)); 856 + EMIT(PPC_RAW_STW(bpf_to_ppc(ctx, BPF_REG_5), _R1, 12)); 857 857 } 858 858 859 859 bpf_jit_emit_func_call_rel(image, ctx, func_addr); 860 860 861 - EMIT(PPC_RAW_MR(bpf_to_ppc(ctx, BPF_REG_0) - 1, __REG_R3)); 862 - EMIT(PPC_RAW_MR(bpf_to_ppc(ctx, BPF_REG_0), __REG_R4)); 861 + EMIT(PPC_RAW_MR(bpf_to_ppc(ctx, BPF_REG_0) - 1, _R3)); 862 + EMIT(PPC_RAW_MR(bpf_to_ppc(ctx, BPF_REG_0), _R4)); 863 863 break; 864 864 865 865 /* ··· 967 967 EMIT(PPC_RAW_CMPW(dst_reg, src_reg)); 968 968 break; 969 969 case BPF_JMP | BPF_JSET | BPF_X: 970 - EMIT(PPC_RAW_AND_DOT(__REG_R0, dst_reg_h, src_reg_h)); 970 + EMIT(PPC_RAW_AND_DOT(_R0, dst_reg_h, src_reg_h)); 971 971 PPC_BCC_SHORT(COND_NE, (ctx->idx + 2) * 4); 972 - EMIT(PPC_RAW_AND_DOT(__REG_R0, dst_reg, src_reg)); 972 + EMIT(PPC_RAW_AND_DOT(_R0, dst_reg, src_reg)); 973 973 break; 974 974 case BPF_JMP32 | BPF_JSET | BPF_X: { 975 - EMIT(PPC_RAW_AND_DOT(__REG_R0, dst_reg, src_reg)); 975 + EMIT(PPC_RAW_AND_DOT(_R0, dst_reg, src_reg)); 976 976 break; 977 977 case BPF_JMP | BPF_JNE | BPF_K: 978 978 case BPF_JMP | BPF_JEQ | BPF_K: ··· 990 990 EMIT(PPC_RAW_CMPLWI(dst_reg, imm)); 991 991 } else { 992 992 /* sign-extending load ... but unsigned comparison */ 993 - PPC_EX32(__REG_R0, imm); 994 - EMIT(PPC_RAW_CMPLW(dst_reg_h, __REG_R0)); 995 - PPC_LI32(__REG_R0, imm); 993 + PPC_EX32(_R0, imm); 994 + EMIT(PPC_RAW_CMPLW(dst_reg_h, _R0)); 995 + PPC_LI32(_R0, imm); 996 996 PPC_BCC_SHORT(COND_NE, (ctx->idx + 2) * 4); 997 - EMIT(PPC_RAW_CMPLW(dst_reg, __REG_R0)); 997 + EMIT(PPC_RAW_CMPLW(dst_reg, _R0)); 998 998 } 999 999 break; 1000 1000 case BPF_JMP32 | BPF_JNE | BPF_K: ··· 1006 1006 if (imm >= 0 && imm < 65536) { 1007 1007 EMIT(PPC_RAW_CMPLWI(dst_reg, imm)); 1008 1008 } else { 1009 - PPC_LI32(__REG_R0, imm); 1010 - EMIT(PPC_RAW_CMPLW(dst_reg, __REG_R0)); 1009 + PPC_LI32(_R0, imm); 1010 + EMIT(PPC_RAW_CMPLW(dst_reg, _R0)); 1011 1011 } 1012 1012 break; 1013 1013 } ··· 1022 1022 } else { 1023 1023 /* sign-extending load */ 1024 1024 EMIT(PPC_RAW_CMPWI(dst_reg_h, imm < 0 ? -1 : 0)); 1025 - PPC_LI32(__REG_R0, imm); 1025 + PPC_LI32(_R0, imm); 1026 1026 PPC_BCC_SHORT(COND_NE, (ctx->idx + 2) * 4); 1027 - EMIT(PPC_RAW_CMPLW(dst_reg, __REG_R0)); 1027 + EMIT(PPC_RAW_CMPLW(dst_reg, _R0)); 1028 1028 } 1029 1029 break; 1030 1030 case BPF_JMP32 | BPF_JSGT | BPF_K: ··· 1039 1039 EMIT(PPC_RAW_CMPWI(dst_reg, imm)); 1040 1040 } else { 1041 1041 /* sign-extending load */ 1042 - PPC_LI32(__REG_R0, imm); 1043 - EMIT(PPC_RAW_CMPW(dst_reg, __REG_R0)); 1042 + PPC_LI32(_R0, imm); 1043 + EMIT(PPC_RAW_CMPW(dst_reg, _R0)); 1044 1044 } 1045 1045 break; 1046 1046 case BPF_JMP | BPF_JSET | BPF_K: 1047 1047 /* andi does not sign-extend the immediate */ 1048 1048 if (imm >= 0 && imm < 32768) { 1049 1049 /* PPC_ANDI is _only/always_ dot-form */ 1050 - EMIT(PPC_RAW_ANDI(__REG_R0, dst_reg, imm)); 1050 + EMIT(PPC_RAW_ANDI(_R0, dst_reg, imm)); 1051 1051 } else { 1052 - PPC_LI32(__REG_R0, imm); 1052 + PPC_LI32(_R0, imm); 1053 1053 if (imm < 0) { 1054 1054 EMIT(PPC_RAW_CMPWI(dst_reg_h, 0)); 1055 1055 PPC_BCC_SHORT(COND_NE, (ctx->idx + 2) * 4); 1056 1056 } 1057 - EMIT(PPC_RAW_AND_DOT(__REG_R0, dst_reg, __REG_R0)); 1057 + EMIT(PPC_RAW_AND_DOT(_R0, dst_reg, _R0)); 1058 1058 } 1059 1059 break; 1060 1060 case BPF_JMP32 | BPF_JSET | BPF_K: 1061 1061 /* andi does not sign-extend the immediate */ 1062 1062 if (imm >= -32768 && imm < 32768) { 1063 1063 /* PPC_ANDI is _only/always_ dot-form */ 1064 - EMIT(PPC_RAW_ANDI(__REG_R0, dst_reg, imm)); 1064 + EMIT(PPC_RAW_ANDI(_R0, dst_reg, imm)); 1065 1065 } else { 1066 - PPC_LI32(__REG_R0, imm); 1067 - EMIT(PPC_RAW_AND_DOT(__REG_R0, dst_reg, __REG_R0)); 1066 + PPC_LI32(_R0, imm); 1067 + EMIT(PPC_RAW_AND_DOT(_R0, dst_reg, _R0)); 1068 1068 } 1069 1069 break; 1070 1070 }
+7 -7
arch/powerpc/net/bpf_jit_comp64.c
··· 94 94 * save/restore LR unless we call other functions 95 95 */ 96 96 if (ctx->seen & SEEN_FUNC) { 97 - EMIT(PPC_INST_MFLR | __PPC_RT(R0)); 97 + EMIT(PPC_RAW_MFLR(_R0)); 98 98 PPC_BPF_STL(0, 1, PPC_LR_STKOFF); 99 99 } 100 100 ··· 153 153 PPC_LI64(b2p[TMP_REG_2], func); 154 154 /* Load actual entry point from function descriptor */ 155 155 PPC_BPF_LL(b2p[TMP_REG_1], b2p[TMP_REG_2], 0); 156 - /* ... and move it to LR */ 157 - EMIT(PPC_RAW_MTLR(b2p[TMP_REG_1])); 156 + /* ... and move it to CTR */ 157 + EMIT(PPC_RAW_MTCTR(b2p[TMP_REG_1])); 158 158 /* 159 159 * Load TOC from function descriptor at offset 8. 160 160 * We can clobber r2 since we get called through a ··· 165 165 #else 166 166 /* We can clobber r12 */ 167 167 PPC_FUNC_ADDR(12, func); 168 - EMIT(PPC_RAW_MTLR(12)); 168 + EMIT(PPC_RAW_MTCTR(12)); 169 169 #endif 170 - EMIT(PPC_RAW_BLRL()); 170 + EMIT(PPC_RAW_BCTRL()); 171 171 } 172 172 173 173 void bpf_jit_emit_func_call_rel(u32 *image, struct codegen_context *ctx, u64 func) ··· 202 202 PPC_BPF_LL(12, 12, 0); 203 203 #endif 204 204 205 - EMIT(PPC_RAW_MTLR(12)); 206 - EMIT(PPC_RAW_BLRL()); 205 + EMIT(PPC_RAW_MTCTR(12)); 206 + EMIT(PPC_RAW_BCTRL()); 207 207 } 208 208 209 209 static void bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 out)
+2 -4
arch/powerpc/perf/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - obj-$(CONFIG_PERF_EVENTS) += callchain.o callchain_$(BITS).o perf_regs.o 4 - ifdef CONFIG_COMPAT 5 - obj-$(CONFIG_PERF_EVENTS) += callchain_32.o 6 - endif 3 + obj-y += callchain.o callchain_$(BITS).o perf_regs.o 4 + obj-$(CONFIG_COMPAT) += callchain_32.o 7 5 8 6 obj-$(CONFIG_PPC_PERF_CTRS) += core-book3s.o bhrb.o 9 7 obj64-$(CONFIG_PPC_PERF_CTRS) += ppc970-pmu.o power5-pmu.o \
+1 -1
arch/powerpc/perf/callchain.c
··· 40 40 return 0; 41 41 } 42 42 43 - void 43 + void __no_sanitize_address 44 44 perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs) 45 45 { 46 46 unsigned long sp, next_sp;
+2 -2
arch/powerpc/perf/core-book3s.c
··· 460 460 sizeof(instr))) 461 461 return 0; 462 462 463 - return branch_target((struct ppc_inst *)&instr); 463 + return branch_target(&instr); 464 464 } 465 465 466 466 /* Userspace: need copy instruction here then translate it */ ··· 468 468 sizeof(instr))) 469 469 return 0; 470 470 471 - target = branch_target((struct ppc_inst *)&instr); 471 + target = branch_target(&instr); 472 472 if ((!target) || (instr & BRANCH_ABSOLUTE)) 473 473 return target; 474 474
+134 -36
arch/powerpc/perf/generic-compat-pmu.c
··· 14 14 * 15 15 * 28 24 20 16 12 8 4 0 16 16 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | 17 - * [ pmc ] [unit ] [ ] m [ pmcxsel ] 18 - * | | 19 - * | *- mark 20 - * | 21 - * | 22 - * *- combine 23 - * 24 - * Below uses IBM bit numbering. 25 - * 26 - * MMCR1[x:y] = unit (PMCxUNIT) 27 - * MMCR1[24] = pmc1combine[0] 28 - * MMCR1[25] = pmc1combine[1] 29 - * MMCR1[26] = pmc2combine[0] 30 - * MMCR1[27] = pmc2combine[1] 31 - * MMCR1[28] = pmc3combine[0] 32 - * MMCR1[29] = pmc3combine[1] 33 - * MMCR1[30] = pmc4combine[0] 34 - * MMCR1[31] = pmc4combine[1] 35 - * 17 + * [ pmc ] [ pmcxsel ] 36 18 */ 37 19 38 20 /* 39 - * Some power9 event codes. 21 + * Event codes defined in ISA v3.0B 40 22 */ 41 23 #define EVENT(_name, _code) _name = _code, 42 24 43 25 enum { 44 - EVENT(PM_CYC, 0x0001e) 45 - EVENT(PM_INST_CMPL, 0x00002) 26 + /* Cycles, alternate code */ 27 + EVENT(PM_CYC_ALT, 0x100f0) 28 + /* One or more instructions completed in a cycle */ 29 + EVENT(PM_CYC_INST_CMPL, 0x100f2) 30 + /* Floating-point instruction completed */ 31 + EVENT(PM_FLOP_CMPL, 0x100f4) 32 + /* Instruction ERAT/L1-TLB miss */ 33 + EVENT(PM_L1_ITLB_MISS, 0x100f6) 34 + /* All instructions completed and none available */ 35 + EVENT(PM_NO_INST_AVAIL, 0x100f8) 36 + /* A load-type instruction completed (ISA v3.0+) */ 37 + EVENT(PM_LD_CMPL, 0x100fc) 38 + /* Instruction completed, alternate code (ISA v3.0+) */ 39 + EVENT(PM_INST_CMPL_ALT, 0x100fe) 40 + /* A store-type instruction completed */ 41 + EVENT(PM_ST_CMPL, 0x200f0) 42 + /* Instruction Dispatched */ 43 + EVENT(PM_INST_DISP, 0x200f2) 44 + /* Run_cycles */ 45 + EVENT(PM_RUN_CYC, 0x200f4) 46 + /* Data ERAT/L1-TLB miss/reload */ 47 + EVENT(PM_L1_DTLB_RELOAD, 0x200f6) 48 + /* Taken branch completed */ 49 + EVENT(PM_BR_TAKEN_CMPL, 0x200fa) 50 + /* Demand iCache Miss */ 51 + EVENT(PM_L1_ICACHE_MISS, 0x200fc) 52 + /* L1 Dcache reload from memory */ 53 + EVENT(PM_L1_RELOAD_FROM_MEM, 0x200fe) 54 + /* L1 Dcache store miss */ 55 + EVENT(PM_ST_MISS_L1, 0x300f0) 56 + /* Alternate code for PM_INST_DISP */ 57 + EVENT(PM_INST_DISP_ALT, 0x300f2) 58 + /* Branch direction or target mispredicted */ 59 + EVENT(PM_BR_MISPREDICT, 0x300f6) 60 + /* Data TLB miss/reload */ 61 + EVENT(PM_DTLB_MISS, 0x300fc) 62 + /* Demand LD - L3 Miss (not L2 hit and not L3 hit) */ 63 + EVENT(PM_DATA_FROM_L3MISS, 0x300fe) 64 + /* L1 Dcache load miss */ 65 + EVENT(PM_LD_MISS_L1, 0x400f0) 66 + /* Cycle when instruction(s) dispatched */ 67 + EVENT(PM_CYC_INST_DISP, 0x400f2) 68 + /* Branch or branch target mispredicted */ 69 + EVENT(PM_BR_MPRED_CMPL, 0x400f6) 70 + /* Instructions completed with run latch set */ 71 + EVENT(PM_RUN_INST_CMPL, 0x400fa) 72 + /* Instruction TLB miss/reload */ 73 + EVENT(PM_ITLB_MISS, 0x400fc) 74 + /* Load data not cached */ 75 + EVENT(PM_LD_NOT_CACHED, 0x400fe) 76 + /* Instructions */ 77 + EVENT(PM_INST_CMPL, 0x500fa) 78 + /* Cycles */ 79 + EVENT(PM_CYC, 0x600f4) 46 80 }; 47 81 48 82 #undef EVENT 49 83 84 + /* Table of alternatives, sorted in increasing order of column 0 */ 85 + /* Note that in each row, column 0 must be the smallest */ 86 + static const unsigned int generic_event_alternatives[][MAX_ALT] = { 87 + { PM_CYC_ALT, PM_CYC }, 88 + { PM_INST_CMPL_ALT, PM_INST_CMPL }, 89 + { PM_INST_DISP, PM_INST_DISP_ALT }, 90 + }; 91 + 92 + static int generic_get_alternatives(u64 event, unsigned int flags, u64 alt[]) 93 + { 94 + int num_alt = 0; 95 + 96 + num_alt = isa207_get_alternatives(event, alt, 97 + ARRAY_SIZE(generic_event_alternatives), flags, 98 + generic_event_alternatives); 99 + 100 + return num_alt; 101 + } 102 + 50 103 GENERIC_EVENT_ATTR(cpu-cycles, PM_CYC); 51 104 GENERIC_EVENT_ATTR(instructions, PM_INST_CMPL); 105 + GENERIC_EVENT_ATTR(stalled-cycles-frontend, PM_NO_INST_AVAIL); 106 + GENERIC_EVENT_ATTR(branch-misses, PM_BR_MPRED_CMPL); 107 + GENERIC_EVENT_ATTR(cache-misses, PM_LD_MISS_L1); 108 + 109 + CACHE_EVENT_ATTR(L1-dcache-load-misses, PM_LD_MISS_L1); 110 + CACHE_EVENT_ATTR(L1-dcache-store-misses, PM_ST_MISS_L1); 111 + CACHE_EVENT_ATTR(L1-icache-load-misses, PM_L1_ICACHE_MISS); 112 + CACHE_EVENT_ATTR(LLC-load-misses, PM_DATA_FROM_L3MISS); 113 + CACHE_EVENT_ATTR(branch-load-misses, PM_BR_MPRED_CMPL); 114 + CACHE_EVENT_ATTR(dTLB-load-misses, PM_DTLB_MISS); 115 + CACHE_EVENT_ATTR(iTLB-load-misses, PM_ITLB_MISS); 52 116 53 117 static struct attribute *generic_compat_events_attr[] = { 54 118 GENERIC_EVENT_PTR(PM_CYC), 55 119 GENERIC_EVENT_PTR(PM_INST_CMPL), 120 + GENERIC_EVENT_PTR(PM_NO_INST_AVAIL), 121 + GENERIC_EVENT_PTR(PM_BR_MPRED_CMPL), 122 + GENERIC_EVENT_PTR(PM_LD_MISS_L1), 123 + CACHE_EVENT_PTR(PM_LD_MISS_L1), 124 + CACHE_EVENT_PTR(PM_ST_MISS_L1), 125 + CACHE_EVENT_PTR(PM_L1_ICACHE_MISS), 126 + CACHE_EVENT_PTR(PM_DATA_FROM_L3MISS), 127 + CACHE_EVENT_PTR(PM_BR_MPRED_CMPL), 128 + CACHE_EVENT_PTR(PM_DTLB_MISS), 129 + CACHE_EVENT_PTR(PM_ITLB_MISS), 56 130 NULL 57 131 }; 58 132 ··· 137 63 138 64 PMU_FORMAT_ATTR(event, "config:0-19"); 139 65 PMU_FORMAT_ATTR(pmcxsel, "config:0-7"); 140 - PMU_FORMAT_ATTR(mark, "config:8"); 141 - PMU_FORMAT_ATTR(combine, "config:10-11"); 142 - PMU_FORMAT_ATTR(unit, "config:12-15"); 143 66 PMU_FORMAT_ATTR(pmc, "config:16-19"); 144 67 145 68 static struct attribute *generic_compat_pmu_format_attr[] = { 146 69 &format_attr_event.attr, 147 70 &format_attr_pmcxsel.attr, 148 - &format_attr_mark.attr, 149 - &format_attr_combine.attr, 150 - &format_attr_unit.attr, 151 71 &format_attr_pmc.attr, 152 72 NULL, 153 73 }; ··· 160 92 static int compat_generic_events[] = { 161 93 [PERF_COUNT_HW_CPU_CYCLES] = PM_CYC, 162 94 [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL, 95 + [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = PM_NO_INST_AVAIL, 96 + [PERF_COUNT_HW_BRANCH_MISSES] = PM_BR_MPRED_CMPL, 97 + [PERF_COUNT_HW_CACHE_MISSES] = PM_LD_MISS_L1, 163 98 }; 164 99 165 100 #define C(x) PERF_COUNT_HW_CACHE_##x ··· 176 105 [ C(L1D) ] = { 177 106 [ C(OP_READ) ] = { 178 107 [ C(RESULT_ACCESS) ] = 0, 179 - [ C(RESULT_MISS) ] = 0, 108 + [ C(RESULT_MISS) ] = PM_LD_MISS_L1, 180 109 }, 181 110 [ C(OP_WRITE) ] = { 182 111 [ C(RESULT_ACCESS) ] = 0, 183 - [ C(RESULT_MISS) ] = 0, 112 + [ C(RESULT_MISS) ] = PM_ST_MISS_L1, 184 113 }, 185 114 [ C(OP_PREFETCH) ] = { 186 115 [ C(RESULT_ACCESS) ] = 0, ··· 190 119 [ C(L1I) ] = { 191 120 [ C(OP_READ) ] = { 192 121 [ C(RESULT_ACCESS) ] = 0, 193 - [ C(RESULT_MISS) ] = 0, 122 + [ C(RESULT_MISS) ] = PM_L1_ICACHE_MISS, 194 123 }, 195 124 [ C(OP_WRITE) ] = { 196 125 [ C(RESULT_ACCESS) ] = 0, ··· 204 133 [ C(LL) ] = { 205 134 [ C(OP_READ) ] = { 206 135 [ C(RESULT_ACCESS) ] = 0, 207 - [ C(RESULT_MISS) ] = 0, 136 + [ C(RESULT_MISS) ] = PM_DATA_FROM_L3MISS, 208 137 }, 209 138 [ C(OP_WRITE) ] = { 210 139 [ C(RESULT_ACCESS) ] = 0, ··· 218 147 [ C(DTLB) ] = { 219 148 [ C(OP_READ) ] = { 220 149 [ C(RESULT_ACCESS) ] = 0, 221 - [ C(RESULT_MISS) ] = 0, 150 + [ C(RESULT_MISS) ] = PM_DTLB_MISS, 222 151 }, 223 152 [ C(OP_WRITE) ] = { 224 153 [ C(RESULT_ACCESS) ] = -1, ··· 232 161 [ C(ITLB) ] = { 233 162 [ C(OP_READ) ] = { 234 163 [ C(RESULT_ACCESS) ] = 0, 235 - [ C(RESULT_MISS) ] = 0, 164 + [ C(RESULT_MISS) ] = PM_ITLB_MISS, 236 165 }, 237 166 [ C(OP_WRITE) ] = { 238 167 [ C(RESULT_ACCESS) ] = -1, ··· 246 175 [ C(BPU) ] = { 247 176 [ C(OP_READ) ] = { 248 177 [ C(RESULT_ACCESS) ] = 0, 249 - [ C(RESULT_MISS) ] = 0, 178 + [ C(RESULT_MISS) ] = PM_BR_MPRED_CMPL, 250 179 }, 251 180 [ C(OP_WRITE) ] = { 252 181 [ C(RESULT_ACCESS) ] = -1, ··· 275 204 276 205 #undef C 277 206 207 + /* 208 + * We set MMCR0[CC5-6RUN] so we can use counters 5 and 6 for 209 + * PM_INST_CMPL and PM_CYC. 210 + */ 211 + static int generic_compute_mmcr(u64 event[], int n_ev, 212 + unsigned int hwc[], struct mmcr_regs *mmcr, 213 + struct perf_event *pevents[], u32 flags) 214 + { 215 + int ret; 216 + 217 + ret = isa207_compute_mmcr(event, n_ev, hwc, mmcr, pevents, flags); 218 + if (!ret) 219 + mmcr->mmcr0 |= MMCR0_C56RUN; 220 + return ret; 221 + } 222 + 278 223 static struct power_pmu generic_compat_pmu = { 279 224 .name = "GENERIC_COMPAT", 280 225 .n_counter = MAX_PMU_COUNTERS, 281 226 .add_fields = ISA207_ADD_FIELDS, 282 227 .test_adder = ISA207_TEST_ADDER, 283 - .compute_mmcr = isa207_compute_mmcr, 228 + .compute_mmcr = generic_compute_mmcr, 284 229 .get_constraint = isa207_get_constraint, 230 + .get_alternatives = generic_get_alternatives, 285 231 .disable_pmc = isa207_disable_pmc, 286 232 .flags = PPMU_HAS_SIER | PPMU_ARCH_207S, 287 233 .n_generic = ARRAY_SIZE(compat_generic_events), ··· 310 222 int init_generic_compat_pmu(void) 311 223 { 312 224 int rc = 0; 225 + 226 + /* 227 + * From ISA v2.07 on, PMU features are architected; 228 + * we require >= v3.0 because (a) that has PM_LD_CMPL and 229 + * PM_INST_CMPL_ALT, which v2.07 doesn't have, and 230 + * (b) we don't expect any non-IBM Power ISA 231 + * implementations that conform to v2.07 but not v3.0. 232 + */ 233 + if (!cpu_has_feature(CPU_FTR_ARCH_300)) 234 + return -ENODEV; 313 235 314 236 rc = register_power_pmu(&generic_compat_pmu); 315 237 if (rc)
+1
arch/powerpc/platforms/52xx/mpc52xx_gpt.c
··· 582 582 if (ret) 583 583 break; 584 584 /* fall through and return the timeout */ 585 + fallthrough; 585 586 586 587 case WDIOC_GETTIMEOUT: 587 588 /* we need to round here as to avoid e.g. the following
+2 -2
arch/powerpc/platforms/86xx/mpc86xx_smp.c
··· 73 73 74 74 /* Setup fake reset vector to call __secondary_start_mpc86xx. */ 75 75 target = (unsigned long) __secondary_start_mpc86xx; 76 - patch_branch((struct ppc_inst *)vector, target, BRANCH_SET_LINK); 76 + patch_branch(vector, target, BRANCH_SET_LINK); 77 77 78 78 /* Kick that CPU */ 79 79 smp_86xx_release_core(nr); ··· 83 83 mdelay(1); 84 84 85 85 /* Restore the exception vector */ 86 - patch_instruction((struct ppc_inst *)vector, ppc_inst(save_vector)); 86 + patch_instruction(vector, ppc_inst(save_vector)); 87 87 88 88 local_irq_restore(flags); 89 89
+3
arch/powerpc/platforms/Kconfig
··· 20 20 source "arch/powerpc/platforms/44x/Kconfig" 21 21 source "arch/powerpc/platforms/40x/Kconfig" 22 22 source "arch/powerpc/platforms/amigaone/Kconfig" 23 + source "arch/powerpc/platforms/book3s/Kconfig" 24 + source "arch/powerpc/platforms/microwatt/Kconfig" 23 25 24 26 config KVM_GUEST 25 27 bool "KVM Guest support" ··· 51 49 config PPC_OF_BOOT_TRAMPOLINE 52 50 bool "Support booting from Open Firmware or yaboot" 53 51 depends on PPC_BOOK3S_32 || PPC64 52 + select RELOCATABLE if PPC64 54 53 default y 55 54 help 56 55 Support from booting from Open Firmware or yaboot using an
+6 -9
arch/powerpc/platforms/Kconfig.cputype
··· 61 61 select 4xx_SOC 62 62 select HAVE_PCI 63 63 select PHYS_64BIT 64 + select PPC_HAVE_KUEP 64 65 65 66 endchoice 66 67 ··· 391 390 config PPC_KUEP 392 391 bool "Kernel Userspace Execution Prevention" 393 392 depends on PPC_HAVE_KUEP 394 - default y if !PPC_BOOK3S_32 393 + default y 395 394 help 396 395 Enable support for Kernel Userspace Execution Prevention (KUEP) 397 396 ··· 403 402 config PPC_KUAP 404 403 bool "Kernel Userspace Access Protection" 405 404 depends on PPC_HAVE_KUAP 406 - default y if !PPC_BOOK3S_32 405 + default y 407 406 help 408 407 Enable support for Kernel Userspace Access Protection (KUAP) 409 408 ··· 425 424 config PPC_MMU_NOHASH 426 425 def_bool y 427 426 depends on !PPC_BOOK3S 428 - 429 - config PPC_MMU_NOHASH_32 430 - def_bool y 431 - depends on PPC_MMU_NOHASH && PPC32 432 427 433 428 config PPC_BOOK3E_MMU 434 429 def_bool y ··· 474 477 If you don't know what to do here, say N. 475 478 476 479 config NR_CPUS 477 - int "Maximum number of CPUs (2-8192)" 478 - range 2 8192 479 - depends on SMP 480 + int "Maximum number of CPUs (2-8192)" if SMP 481 + range 2 8192 if SMP 482 + default "1" if !SMP 480 483 default "32" if PPC64 481 484 default "4" 482 485
+2
arch/powerpc/platforms/Makefile
··· 22 22 obj-$(CONFIG_PPC_PS3) += ps3/ 23 23 obj-$(CONFIG_EMBEDDED6xx) += embedded6xx/ 24 24 obj-$(CONFIG_AMIGAONE) += amigaone/ 25 + obj-$(CONFIG_PPC_BOOK3S) += book3s/ 26 + obj-$(CONFIG_PPC_MICROWATT) += microwatt/
+15
arch/powerpc/platforms/book3s/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + config PPC_VAS 3 + bool "IBM Virtual Accelerator Switchboard (VAS)" 4 + depends on (PPC_POWERNV || PPC_PSERIES) && PPC_64K_PAGES 5 + default y 6 + help 7 + This enables support for IBM Virtual Accelerator Switchboard (VAS). 8 + 9 + VAS devices are found in POWER9-based and later systems, they 10 + provide access to accelerator coprocessors such as NX-GZIP and 11 + NX-842. This config allows the kernel to use NX-842 accelerators, 12 + and user-mode APIs for the NX-GZIP accelerator on POWER9 PowerNV 13 + and POWER10 PowerVM platforms. 14 + 15 + If unsure, say "N".
+2
arch/powerpc/platforms/book3s/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + obj-$(CONFIG_PPC_VAS) += vas-api.o
+493
arch/powerpc/platforms/book3s/vas-api.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * VAS user space API for its accelerators (Only NX-GZIP is supported now) 4 + * Copyright (C) 2019 Haren Myneni, IBM Corp 5 + */ 6 + 7 + #include <linux/kernel.h> 8 + #include <linux/device.h> 9 + #include <linux/cdev.h> 10 + #include <linux/fs.h> 11 + #include <linux/slab.h> 12 + #include <linux/uaccess.h> 13 + #include <linux/kthread.h> 14 + #include <linux/sched/signal.h> 15 + #include <linux/mmu_context.h> 16 + #include <linux/io.h> 17 + #include <asm/vas.h> 18 + #include <uapi/asm/vas-api.h> 19 + 20 + /* 21 + * The driver creates the device node that can be used as follows: 22 + * For NX-GZIP 23 + * 24 + * fd = open("/dev/crypto/nx-gzip", O_RDWR); 25 + * rc = ioctl(fd, VAS_TX_WIN_OPEN, &attr); 26 + * paste_addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, fd, 0ULL). 27 + * vas_copy(&crb, 0, 1); 28 + * vas_paste(paste_addr, 0, 1); 29 + * close(fd) or exit process to close window. 30 + * 31 + * where "vas_copy" and "vas_paste" are defined in copy-paste.h. 32 + * copy/paste returns to the user space directly. So refer NX hardware 33 + * documententation for exact copy/paste usage and completion / error 34 + * conditions. 35 + */ 36 + 37 + /* 38 + * Wrapper object for the nx-gzip device - there is just one instance of 39 + * this node for the whole system. 40 + */ 41 + static struct coproc_dev { 42 + struct cdev cdev; 43 + struct device *device; 44 + char *name; 45 + dev_t devt; 46 + struct class *class; 47 + enum vas_cop_type cop_type; 48 + const struct vas_user_win_ops *vops; 49 + } coproc_device; 50 + 51 + struct coproc_instance { 52 + struct coproc_dev *coproc; 53 + struct vas_window *txwin; 54 + }; 55 + 56 + static char *coproc_devnode(struct device *dev, umode_t *mode) 57 + { 58 + return kasprintf(GFP_KERNEL, "crypto/%s", dev_name(dev)); 59 + } 60 + 61 + /* 62 + * Take reference to pid and mm 63 + */ 64 + int get_vas_user_win_ref(struct vas_user_win_ref *task_ref) 65 + { 66 + /* 67 + * Window opened by a child thread may not be closed when 68 + * it exits. So take reference to its pid and release it 69 + * when the window is free by parent thread. 70 + * Acquire a reference to the task's pid to make sure 71 + * pid will not be re-used - needed only for multithread 72 + * applications. 73 + */ 74 + task_ref->pid = get_task_pid(current, PIDTYPE_PID); 75 + /* 76 + * Acquire a reference to the task's mm. 77 + */ 78 + task_ref->mm = get_task_mm(current); 79 + if (!task_ref->mm) { 80 + put_pid(task_ref->pid); 81 + pr_err("VAS: pid(%d): mm_struct is not found\n", 82 + current->pid); 83 + return -EPERM; 84 + } 85 + 86 + mmgrab(task_ref->mm); 87 + mmput(task_ref->mm); 88 + /* 89 + * Process closes window during exit. In the case of 90 + * multithread application, the child thread can open 91 + * window and can exit without closing it. So takes tgid 92 + * reference until window closed to make sure tgid is not 93 + * reused. 94 + */ 95 + task_ref->tgid = find_get_pid(task_tgid_vnr(current)); 96 + 97 + return 0; 98 + } 99 + 100 + /* 101 + * Successful return must release the task reference with 102 + * put_task_struct 103 + */ 104 + static bool ref_get_pid_and_task(struct vas_user_win_ref *task_ref, 105 + struct task_struct **tskp, struct pid **pidp) 106 + { 107 + struct task_struct *tsk; 108 + struct pid *pid; 109 + 110 + pid = task_ref->pid; 111 + tsk = get_pid_task(pid, PIDTYPE_PID); 112 + if (!tsk) { 113 + pid = task_ref->tgid; 114 + tsk = get_pid_task(pid, PIDTYPE_PID); 115 + /* 116 + * Parent thread (tgid) will be closing window when it 117 + * exits. So should not get here. 118 + */ 119 + if (WARN_ON_ONCE(!tsk)) 120 + return false; 121 + } 122 + 123 + /* Return if the task is exiting. */ 124 + if (tsk->flags & PF_EXITING) { 125 + put_task_struct(tsk); 126 + return false; 127 + } 128 + 129 + *tskp = tsk; 130 + *pidp = pid; 131 + 132 + return true; 133 + } 134 + 135 + /* 136 + * Update the CSB to indicate a translation error. 137 + * 138 + * User space will be polling on CSB after the request is issued. 139 + * If NX can handle the request without any issues, it updates CSB. 140 + * Whereas if NX encounters page fault, the kernel will handle the 141 + * fault and update CSB with translation error. 142 + * 143 + * If we are unable to update the CSB means copy_to_user failed due to 144 + * invalid csb_addr, send a signal to the process. 145 + */ 146 + void vas_update_csb(struct coprocessor_request_block *crb, 147 + struct vas_user_win_ref *task_ref) 148 + { 149 + struct coprocessor_status_block csb; 150 + struct kernel_siginfo info; 151 + struct task_struct *tsk; 152 + void __user *csb_addr; 153 + struct pid *pid; 154 + int rc; 155 + 156 + /* 157 + * NX user space windows can not be opened for task->mm=NULL 158 + * and faults will not be generated for kernel requests. 159 + */ 160 + if (WARN_ON_ONCE(!task_ref->mm)) 161 + return; 162 + 163 + csb_addr = (void __user *)be64_to_cpu(crb->csb_addr); 164 + 165 + memset(&csb, 0, sizeof(csb)); 166 + csb.cc = CSB_CC_FAULT_ADDRESS; 167 + csb.ce = CSB_CE_TERMINATION; 168 + csb.cs = 0; 169 + csb.count = 0; 170 + 171 + /* 172 + * NX operates and returns in BE format as defined CRB struct. 173 + * So saves fault_storage_addr in BE as NX pastes in FIFO and 174 + * expects user space to convert to CPU format. 175 + */ 176 + csb.address = crb->stamp.nx.fault_storage_addr; 177 + csb.flags = 0; 178 + 179 + /* 180 + * Process closes send window after all pending NX requests are 181 + * completed. In multi-thread applications, a child thread can 182 + * open a window and can exit without closing it. May be some 183 + * requests are pending or this window can be used by other 184 + * threads later. We should handle faults if NX encounters 185 + * pages faults on these requests. Update CSB with translation 186 + * error and fault address. If csb_addr passed by user space is 187 + * invalid, send SEGV signal to pid saved in window. If the 188 + * child thread is not running, send the signal to tgid. 189 + * Parent thread (tgid) will close this window upon its exit. 190 + * 191 + * pid and mm references are taken when window is opened by 192 + * process (pid). So tgid is used only when child thread opens 193 + * a window and exits without closing it. 194 + */ 195 + 196 + if (!ref_get_pid_and_task(task_ref, &tsk, &pid)) 197 + return; 198 + 199 + kthread_use_mm(task_ref->mm); 200 + rc = copy_to_user(csb_addr, &csb, sizeof(csb)); 201 + /* 202 + * User space polls on csb.flags (first byte). So add barrier 203 + * then copy first byte with csb flags update. 204 + */ 205 + if (!rc) { 206 + csb.flags = CSB_V; 207 + /* Make sure update to csb.flags is visible now */ 208 + smp_mb(); 209 + rc = copy_to_user(csb_addr, &csb, sizeof(u8)); 210 + } 211 + kthread_unuse_mm(task_ref->mm); 212 + put_task_struct(tsk); 213 + 214 + /* Success */ 215 + if (!rc) 216 + return; 217 + 218 + 219 + pr_debug("Invalid CSB address 0x%p signalling pid(%d)\n", 220 + csb_addr, pid_vnr(pid)); 221 + 222 + clear_siginfo(&info); 223 + info.si_signo = SIGSEGV; 224 + info.si_errno = EFAULT; 225 + info.si_code = SEGV_MAPERR; 226 + info.si_addr = csb_addr; 227 + /* 228 + * process will be polling on csb.flags after request is sent to 229 + * NX. So generally CSB update should not fail except when an 230 + * application passes invalid csb_addr. So an error message will 231 + * be displayed and leave it to user space whether to ignore or 232 + * handle this signal. 233 + */ 234 + rcu_read_lock(); 235 + rc = kill_pid_info(SIGSEGV, &info, pid); 236 + rcu_read_unlock(); 237 + 238 + pr_devel("%s(): pid %d kill_proc_info() rc %d\n", __func__, 239 + pid_vnr(pid), rc); 240 + } 241 + 242 + void vas_dump_crb(struct coprocessor_request_block *crb) 243 + { 244 + struct data_descriptor_entry *dde; 245 + struct nx_fault_stamp *nx; 246 + 247 + dde = &crb->source; 248 + pr_devel("SrcDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n", 249 + be64_to_cpu(dde->address), be32_to_cpu(dde->length), 250 + dde->count, dde->index, dde->flags); 251 + 252 + dde = &crb->target; 253 + pr_devel("TgtDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n", 254 + be64_to_cpu(dde->address), be32_to_cpu(dde->length), 255 + dde->count, dde->index, dde->flags); 256 + 257 + nx = &crb->stamp.nx; 258 + pr_devel("NX Stamp: PSWID 0x%x, FSA 0x%llx, flags 0x%x, FS 0x%x\n", 259 + be32_to_cpu(nx->pswid), 260 + be64_to_cpu(crb->stamp.nx.fault_storage_addr), 261 + nx->flags, nx->fault_status); 262 + } 263 + 264 + static int coproc_open(struct inode *inode, struct file *fp) 265 + { 266 + struct coproc_instance *cp_inst; 267 + 268 + cp_inst = kzalloc(sizeof(*cp_inst), GFP_KERNEL); 269 + if (!cp_inst) 270 + return -ENOMEM; 271 + 272 + cp_inst->coproc = container_of(inode->i_cdev, struct coproc_dev, 273 + cdev); 274 + fp->private_data = cp_inst; 275 + 276 + return 0; 277 + } 278 + 279 + static int coproc_ioc_tx_win_open(struct file *fp, unsigned long arg) 280 + { 281 + void __user *uptr = (void __user *)arg; 282 + struct vas_tx_win_open_attr uattr; 283 + struct coproc_instance *cp_inst; 284 + struct vas_window *txwin; 285 + int rc; 286 + 287 + cp_inst = fp->private_data; 288 + 289 + /* 290 + * One window for file descriptor 291 + */ 292 + if (cp_inst->txwin) 293 + return -EEXIST; 294 + 295 + rc = copy_from_user(&uattr, uptr, sizeof(uattr)); 296 + if (rc) { 297 + pr_err("%s(): copy_from_user() returns %d\n", __func__, rc); 298 + return -EFAULT; 299 + } 300 + 301 + if (uattr.version != 1) { 302 + pr_err("Invalid window open API version\n"); 303 + return -EINVAL; 304 + } 305 + 306 + if (!cp_inst->coproc->vops && !cp_inst->coproc->vops->open_win) { 307 + pr_err("VAS API is not registered\n"); 308 + return -EACCES; 309 + } 310 + 311 + txwin = cp_inst->coproc->vops->open_win(uattr.vas_id, uattr.flags, 312 + cp_inst->coproc->cop_type); 313 + if (IS_ERR(txwin)) { 314 + pr_err("%s() VAS window open failed, %ld\n", __func__, 315 + PTR_ERR(txwin)); 316 + return PTR_ERR(txwin); 317 + } 318 + 319 + cp_inst->txwin = txwin; 320 + 321 + return 0; 322 + } 323 + 324 + static int coproc_release(struct inode *inode, struct file *fp) 325 + { 326 + struct coproc_instance *cp_inst = fp->private_data; 327 + int rc; 328 + 329 + if (cp_inst->txwin) { 330 + if (cp_inst->coproc->vops && 331 + cp_inst->coproc->vops->close_win) { 332 + rc = cp_inst->coproc->vops->close_win(cp_inst->txwin); 333 + if (rc) 334 + return rc; 335 + } 336 + cp_inst->txwin = NULL; 337 + } 338 + 339 + kfree(cp_inst); 340 + fp->private_data = NULL; 341 + 342 + /* 343 + * We don't know here if user has other receive windows 344 + * open, so we can't really call clear_thread_tidr(). 345 + * So, once the process calls set_thread_tidr(), the 346 + * TIDR value sticks around until process exits, resulting 347 + * in an extra copy in restore_sprs(). 348 + */ 349 + 350 + return 0; 351 + } 352 + 353 + static int coproc_mmap(struct file *fp, struct vm_area_struct *vma) 354 + { 355 + struct coproc_instance *cp_inst = fp->private_data; 356 + struct vas_window *txwin; 357 + unsigned long pfn; 358 + u64 paste_addr; 359 + pgprot_t prot; 360 + int rc; 361 + 362 + txwin = cp_inst->txwin; 363 + 364 + if ((vma->vm_end - vma->vm_start) > PAGE_SIZE) { 365 + pr_debug("%s(): size 0x%zx, PAGE_SIZE 0x%zx\n", __func__, 366 + (vma->vm_end - vma->vm_start), PAGE_SIZE); 367 + return -EINVAL; 368 + } 369 + 370 + /* Ensure instance has an open send window */ 371 + if (!txwin) { 372 + pr_err("%s(): No send window open?\n", __func__); 373 + return -EINVAL; 374 + } 375 + 376 + if (!cp_inst->coproc->vops && !cp_inst->coproc->vops->paste_addr) { 377 + pr_err("%s(): VAS API is not registered\n", __func__); 378 + return -EACCES; 379 + } 380 + 381 + paste_addr = cp_inst->coproc->vops->paste_addr(txwin); 382 + if (!paste_addr) { 383 + pr_err("%s(): Window paste address failed\n", __func__); 384 + return -EINVAL; 385 + } 386 + 387 + pfn = paste_addr >> PAGE_SHIFT; 388 + 389 + /* flags, page_prot from cxl_mmap(), except we want cachable */ 390 + vma->vm_flags |= VM_IO | VM_PFNMAP; 391 + vma->vm_page_prot = pgprot_cached(vma->vm_page_prot); 392 + 393 + prot = __pgprot(pgprot_val(vma->vm_page_prot) | _PAGE_DIRTY); 394 + 395 + rc = remap_pfn_range(vma, vma->vm_start, pfn + vma->vm_pgoff, 396 + vma->vm_end - vma->vm_start, prot); 397 + 398 + pr_devel("%s(): paste addr %llx at %lx, rc %d\n", __func__, 399 + paste_addr, vma->vm_start, rc); 400 + 401 + return rc; 402 + } 403 + 404 + static long coproc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) 405 + { 406 + switch (cmd) { 407 + case VAS_TX_WIN_OPEN: 408 + return coproc_ioc_tx_win_open(fp, arg); 409 + default: 410 + return -EINVAL; 411 + } 412 + } 413 + 414 + static struct file_operations coproc_fops = { 415 + .open = coproc_open, 416 + .release = coproc_release, 417 + .mmap = coproc_mmap, 418 + .unlocked_ioctl = coproc_ioctl, 419 + }; 420 + 421 + /* 422 + * Supporting only nx-gzip coprocessor type now, but this API code 423 + * extended to other coprocessor types later. 424 + */ 425 + int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, 426 + const char *name, 427 + const struct vas_user_win_ops *vops) 428 + { 429 + int rc = -EINVAL; 430 + dev_t devno; 431 + 432 + rc = alloc_chrdev_region(&coproc_device.devt, 1, 1, name); 433 + if (rc) { 434 + pr_err("Unable to allocate coproc major number: %i\n", rc); 435 + return rc; 436 + } 437 + 438 + pr_devel("%s device allocated, dev [%i,%i]\n", name, 439 + MAJOR(coproc_device.devt), MINOR(coproc_device.devt)); 440 + 441 + coproc_device.class = class_create(mod, name); 442 + if (IS_ERR(coproc_device.class)) { 443 + rc = PTR_ERR(coproc_device.class); 444 + pr_err("Unable to create %s class %d\n", name, rc); 445 + goto err_class; 446 + } 447 + coproc_device.class->devnode = coproc_devnode; 448 + coproc_device.cop_type = cop_type; 449 + coproc_device.vops = vops; 450 + 451 + coproc_fops.owner = mod; 452 + cdev_init(&coproc_device.cdev, &coproc_fops); 453 + 454 + devno = MKDEV(MAJOR(coproc_device.devt), 0); 455 + rc = cdev_add(&coproc_device.cdev, devno, 1); 456 + if (rc) { 457 + pr_err("cdev_add() failed %d\n", rc); 458 + goto err_cdev; 459 + } 460 + 461 + coproc_device.device = device_create(coproc_device.class, NULL, 462 + devno, NULL, name, MINOR(devno)); 463 + if (IS_ERR(coproc_device.device)) { 464 + rc = PTR_ERR(coproc_device.device); 465 + pr_err("Unable to create coproc-%d %d\n", MINOR(devno), rc); 466 + goto err; 467 + } 468 + 469 + pr_devel("%s: Added dev [%d,%d]\n", __func__, MAJOR(devno), 470 + MINOR(devno)); 471 + 472 + return 0; 473 + 474 + err: 475 + cdev_del(&coproc_device.cdev); 476 + err_cdev: 477 + class_destroy(coproc_device.class); 478 + err_class: 479 + unregister_chrdev_region(coproc_device.devt, 1); 480 + return rc; 481 + } 482 + 483 + void vas_unregister_coproc_api(void) 484 + { 485 + dev_t devno; 486 + 487 + cdev_del(&coproc_device.cdev); 488 + devno = MKDEV(MAJOR(coproc_device.devt), 0); 489 + device_destroy(coproc_device.class, devno); 490 + 491 + class_destroy(coproc_device.class); 492 + unregister_chrdev_region(coproc_device.devt, 1); 493 + }
+1 -2
arch/powerpc/platforms/cell/spider-pci.c
··· 25 25 static void spiderpci_io_flush(struct iowa_bus *bus) 26 26 { 27 27 struct spiderpci_iowa_private *priv; 28 - u32 val; 29 28 30 29 priv = bus->private; 31 - val = in_be32(priv->regs + SPIDER_PCI_DUMMY_READ); 30 + in_be32(priv->regs + SPIDER_PCI_DUMMY_READ); 32 31 iosync(); 33 32 } 34 33
+2 -4
arch/powerpc/platforms/cell/spufs/switch.c
··· 1657 1657 static inline void check_ppu_mb_stat(struct spu_state *csa, struct spu *spu) 1658 1658 { 1659 1659 struct spu_problem __iomem *prob = spu->problem; 1660 - u32 dummy = 0; 1661 1660 1662 1661 /* Restore, Step 66: 1663 1662 * If CSA.MB_Stat[P]=0 (mailbox empty) then 1664 1663 * read from the PPU_MB register. 1665 1664 */ 1666 1665 if ((csa->prob.mb_stat_R & 0xFF) == 0) { 1667 - dummy = in_be32(&prob->pu_mb_R); 1666 + in_be32(&prob->pu_mb_R); 1668 1667 eieio(); 1669 1668 } 1670 1669 } ··· 1671 1672 static inline void check_ppuint_mb_stat(struct spu_state *csa, struct spu *spu) 1672 1673 { 1673 1674 struct spu_priv2 __iomem *priv2 = spu->priv2; 1674 - u64 dummy = 0UL; 1675 1675 1676 1676 /* Restore, Step 66: 1677 1677 * If CSA.MB_Stat[I]=0 (mailbox empty) then 1678 1678 * read from the PPUINT_MB register. 1679 1679 */ 1680 1680 if ((csa->prob.mb_stat_R & 0xFF0000) == 0) { 1681 - dummy = in_be64(&priv2->puint_mb_R); 1681 + in_be64(&priv2->puint_mb_R); 1682 1682 eieio(); 1683 1683 spu_int_stat_clear(spu, 2, CLASS2_ENABLE_MAILBOX_INTR); 1684 1684 eieio();
+2 -2
arch/powerpc/platforms/embedded6xx/holly.c
··· 251 251 /* Are we prepared to handle this fault */ 252 252 if ((entry = search_exception_tables(regs->nip)) != NULL) { 253 253 tsi108_clear_pci_cfg_error(); 254 - regs->msr |= MSR_RI; 255 - regs->nip = extable_fixup(entry); 254 + regs_set_return_msr(regs, regs->msr | MSR_RI); 255 + regs_set_return_ip(regs, extable_fixup(entry)); 256 256 return 1; 257 257 } 258 258 return 0;
+2 -2
arch/powerpc/platforms/embedded6xx/mpc7448_hpc2.c
··· 173 173 /* Are we prepared to handle this fault */ 174 174 if ((entry = search_exception_tables(regs->nip)) != NULL) { 175 175 tsi108_clear_pci_cfg_error(); 176 - regs->msr |= MSR_RI; 177 - regs->nip = extable_fixup(entry); 176 + regs_set_return_msr(regs, regs->msr | MSR_RI); 177 + regs_set_return_ip(regs, extable_fixup(entry)); 178 178 return 1; 179 179 } 180 180 return 0;
+13
arch/powerpc/platforms/microwatt/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + config PPC_MICROWATT 3 + depends on PPC_BOOK3S_64 && !SMP 4 + bool "Microwatt SoC platform" 5 + select PPC_XICS 6 + select PPC_ICS_NATIVE 7 + select PPC_ICP_NATIVE 8 + select PPC_NATIVE 9 + select PPC_UDBG_16550 10 + select ARCH_RANDOM 11 + help 12 + This option enables support for FPGA-based Microwatt implementations. 13 +
+1
arch/powerpc/platforms/microwatt/Makefile
··· 1 + obj-y += setup.o rng.o
+48
arch/powerpc/platforms/microwatt/rng.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Derived from arch/powerpc/platforms/powernv/rng.c, which is: 4 + * Copyright 2013, Michael Ellerman, IBM Corporation. 5 + */ 6 + 7 + #define pr_fmt(fmt) "microwatt-rng: " fmt 8 + 9 + #include <linux/kernel.h> 10 + #include <linux/smp.h> 11 + #include <asm/archrandom.h> 12 + #include <asm/cputable.h> 13 + #include <asm/machdep.h> 14 + 15 + #define DARN_ERR 0xFFFFFFFFFFFFFFFFul 16 + 17 + int microwatt_get_random_darn(unsigned long *v) 18 + { 19 + unsigned long val; 20 + 21 + /* Using DARN with L=1 - 64-bit conditioned random number */ 22 + asm volatile(PPC_DARN(%0, 1) : "=r"(val)); 23 + 24 + if (val == DARN_ERR) 25 + return 0; 26 + 27 + *v = val; 28 + 29 + return 1; 30 + } 31 + 32 + static __init int rng_init(void) 33 + { 34 + unsigned long val; 35 + int i; 36 + 37 + for (i = 0; i < 10; i++) { 38 + if (microwatt_get_random_darn(&val)) { 39 + ppc_md.get_random_seed = microwatt_get_random_darn; 40 + return 0; 41 + } 42 + } 43 + 44 + pr_warn("Unable to use DARN for get_random_seed()\n"); 45 + 46 + return -EIO; 47 + } 48 + machine_subsys_initcall(, rng_init);
+41
arch/powerpc/platforms/microwatt/setup.c
··· 1 + /* 2 + * Microwatt FPGA-based SoC platform setup code. 3 + * 4 + * Copyright 2020 Paul Mackerras (paulus@ozlabs.org), IBM Corp. 5 + */ 6 + 7 + #include <linux/types.h> 8 + #include <linux/kernel.h> 9 + #include <linux/stddef.h> 10 + #include <linux/init.h> 11 + #include <linux/of.h> 12 + #include <linux/of_platform.h> 13 + 14 + #include <asm/machdep.h> 15 + #include <asm/time.h> 16 + #include <asm/xics.h> 17 + #include <asm/udbg.h> 18 + 19 + static void __init microwatt_init_IRQ(void) 20 + { 21 + xics_init(); 22 + } 23 + 24 + static int __init microwatt_probe(void) 25 + { 26 + return of_machine_is_compatible("microwatt-soc"); 27 + } 28 + 29 + static int __init microwatt_populate(void) 30 + { 31 + return of_platform_default_populate(NULL, NULL, NULL); 32 + } 33 + machine_arch_initcall(microwatt, microwatt_populate); 34 + 35 + define_machine(microwatt) { 36 + .name = "microwatt", 37 + .probe = microwatt_probe, 38 + .init_IRQ = microwatt_init_IRQ, 39 + .progress = udbg_progress, 40 + .calibrate_decr = generic_calibrate_decr, 41 + };
+2 -2
arch/powerpc/platforms/pasemi/idle.c
··· 37 37 */ 38 38 39 39 if (regs->msr & SRR1_WAKEMASK) 40 - regs->nip = regs->link; 40 + regs_set_return_ip(regs, regs->link); 41 41 42 42 switch (regs->msr & SRR1_WAKEMASK) { 43 43 case SRR1_WAKEDEC: ··· 58 58 restore_astate(hard_smp_processor_id()); 59 59 60 60 /* everything handled */ 61 - regs->msr |= MSR_RI; 61 + regs_set_return_msr(regs, regs->msr | MSR_RI); 62 62 return 1; 63 63 } 64 64
+1 -1
arch/powerpc/platforms/powermac/bootx_init.c
··· 433 433 bootx_printf("\nframe buffer at : 0x%x", bi->dispDeviceBase); 434 434 bootx_printf(" (phys), 0x%x", bi->logicalDisplayBase); 435 435 bootx_printf(" (log)"); 436 - bootx_printf("\nklimit : 0x%x",(unsigned long)klimit); 436 + bootx_printf("\nklimit : 0x%x",(unsigned long)_end); 437 437 bootx_printf("\nboot_info at : 0x%x", bi); 438 438 __asm__ __volatile__ ("mfmsr %0" : "=r" (flags)); 439 439 bootx_printf("\nMSR : 0x%x", flags);
+2 -2
arch/powerpc/platforms/powermac/smp.c
··· 810 810 * b __secondary_start_pmac_0 + nr*8 811 811 */ 812 812 target = (unsigned long) __secondary_start_pmac_0 + nr * 8; 813 - patch_branch((struct ppc_inst *)vector, target, BRANCH_SET_LINK); 813 + patch_branch(vector, target, BRANCH_SET_LINK); 814 814 815 815 /* Put some life in our friend */ 816 816 pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0); ··· 823 823 mdelay(1); 824 824 825 825 /* Restore our exception vector */ 826 - patch_instruction((struct ppc_inst *)vector, ppc_inst(save_vector)); 826 + patch_instruction(vector, ppc_inst(save_vector)); 827 827 828 828 local_irq_restore(flags); 829 829 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
-14
arch/powerpc/platforms/powernv/Kconfig
··· 33 33 Enabling this option allows for runtime allocation of memory (RAM) 34 34 for hardware tracing. 35 35 36 - config PPC_VAS 37 - bool "IBM Virtual Accelerator Switchboard (VAS)" 38 - depends on PPC_POWERNV && PPC_64K_PAGES 39 - default y 40 - help 41 - This enables support for IBM Virtual Accelerator Switchboard (VAS). 42 - 43 - VAS allows accelerators in co-processors like NX-GZIP and NX-842 44 - to be accessible to kernel subsystems and user processes. 45 - 46 - VAS adapters are found in POWER9 based systems. 47 - 48 - If unsure, say N. 49 - 50 36 config SCOM_DEBUGFS 51 37 bool "Expose SCOM controllers via debugfs" 52 38 depends on DEBUG_FS
+1 -1
arch/powerpc/platforms/powernv/Makefile
··· 18 18 obj-$(CONFIG_OPAL_PRD) += opal-prd.o 19 19 obj-$(CONFIG_PERF_EVENTS) += opal-imc.o 20 20 obj-$(CONFIG_PPC_MEMTRACE) += memtrace.o 21 - obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o vas-fault.o vas-api.o 21 + obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o vas-fault.o 22 22 obj-$(CONFIG_OCXL_BASE) += ocxl.o 23 23 obj-$(CONFIG_SCOM_DEBUGFS) += opal-xscom.o 24 24 obj-$(CONFIG_PPC_SECURE_BOOT) += opal-secvar.o
+4
arch/powerpc/platforms/powernv/opal-call.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/percpu.h> 3 3 #include <linux/jump_label.h> 4 + #include <asm/interrupt.h> 4 5 #include <asm/opal-api.h> 5 6 #include <asm/trace.h> 6 7 #include <asm/asm-prototypes.h> ··· 100 99 unsigned long msr = mfmsr(); 101 100 bool mmu = (msr & (MSR_IR|MSR_DR)); 102 101 int64_t ret; 102 + 103 + /* OPAL call / firmware may use SRR and/or HSRR */ 104 + srr_regs_clobbered(); 103 105 104 106 msr &= ~MSR_EE; 105 107
+1 -1
arch/powerpc/platforms/powernv/opal.c
··· 773 773 * Setup regs->nip to rfi into fixup address. 774 774 */ 775 775 if (recover_addr) 776 - regs->nip = recover_addr; 776 + regs_set_return_ip(regs, recover_addr); 777 777 778 778 out: 779 779 return !!recover_addr;
+1 -1
arch/powerpc/platforms/powernv/pci.c
··· 711 711 return PCIBIOS_SUCCESSFUL; 712 712 } 713 713 714 - #if CONFIG_EEH 714 + #ifdef CONFIG_EEH 715 715 static bool pnv_pci_cfg_check(struct pci_dn *pdn) 716 716 { 717 717 struct eeh_dev *edev = NULL;
+10
arch/powerpc/platforms/powernv/subcore.c
··· 169 169 } 170 170 } 171 171 172 + static inline void update_power8_hid0(unsigned long hid0) 173 + { 174 + /* 175 + * The HID0 update on Power8 should at the very least be 176 + * preceded by a SYNC instruction followed by an ISYNC 177 + * instruction 178 + */ 179 + asm volatile("sync; mtspr %0,%1; isync":: "i"(SPRN_HID0), "r"(hid0)); 180 + } 181 + 172 182 static void unsplit_core(void) 173 183 { 174 184 u64 hid0, mask;
-278
arch/powerpc/platforms/powernv/vas-api.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * VAS user space API for its accelerators (Only NX-GZIP is supported now) 4 - * Copyright (C) 2019 Haren Myneni, IBM Corp 5 - */ 6 - 7 - #include <linux/kernel.h> 8 - #include <linux/device.h> 9 - #include <linux/cdev.h> 10 - #include <linux/fs.h> 11 - #include <linux/slab.h> 12 - #include <linux/uaccess.h> 13 - #include <asm/vas.h> 14 - #include <uapi/asm/vas-api.h> 15 - #include "vas.h" 16 - 17 - /* 18 - * The driver creates the device node that can be used as follows: 19 - * For NX-GZIP 20 - * 21 - * fd = open("/dev/crypto/nx-gzip", O_RDWR); 22 - * rc = ioctl(fd, VAS_TX_WIN_OPEN, &attr); 23 - * paste_addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, fd, 0ULL). 24 - * vas_copy(&crb, 0, 1); 25 - * vas_paste(paste_addr, 0, 1); 26 - * close(fd) or exit process to close window. 27 - * 28 - * where "vas_copy" and "vas_paste" are defined in copy-paste.h. 29 - * copy/paste returns to the user space directly. So refer NX hardware 30 - * documententation for exact copy/paste usage and completion / error 31 - * conditions. 32 - */ 33 - 34 - /* 35 - * Wrapper object for the nx-gzip device - there is just one instance of 36 - * this node for the whole system. 37 - */ 38 - static struct coproc_dev { 39 - struct cdev cdev; 40 - struct device *device; 41 - char *name; 42 - dev_t devt; 43 - struct class *class; 44 - enum vas_cop_type cop_type; 45 - } coproc_device; 46 - 47 - struct coproc_instance { 48 - struct coproc_dev *coproc; 49 - struct vas_window *txwin; 50 - }; 51 - 52 - static char *coproc_devnode(struct device *dev, umode_t *mode) 53 - { 54 - return kasprintf(GFP_KERNEL, "crypto/%s", dev_name(dev)); 55 - } 56 - 57 - static int coproc_open(struct inode *inode, struct file *fp) 58 - { 59 - struct coproc_instance *cp_inst; 60 - 61 - cp_inst = kzalloc(sizeof(*cp_inst), GFP_KERNEL); 62 - if (!cp_inst) 63 - return -ENOMEM; 64 - 65 - cp_inst->coproc = container_of(inode->i_cdev, struct coproc_dev, 66 - cdev); 67 - fp->private_data = cp_inst; 68 - 69 - return 0; 70 - } 71 - 72 - static int coproc_ioc_tx_win_open(struct file *fp, unsigned long arg) 73 - { 74 - void __user *uptr = (void __user *)arg; 75 - struct vas_tx_win_attr txattr = {}; 76 - struct vas_tx_win_open_attr uattr; 77 - struct coproc_instance *cp_inst; 78 - struct vas_window *txwin; 79 - int rc, vasid; 80 - 81 - cp_inst = fp->private_data; 82 - 83 - /* 84 - * One window for file descriptor 85 - */ 86 - if (cp_inst->txwin) 87 - return -EEXIST; 88 - 89 - rc = copy_from_user(&uattr, uptr, sizeof(uattr)); 90 - if (rc) { 91 - pr_err("%s(): copy_from_user() returns %d\n", __func__, rc); 92 - return -EFAULT; 93 - } 94 - 95 - if (uattr.version != 1) { 96 - pr_err("Invalid version\n"); 97 - return -EINVAL; 98 - } 99 - 100 - vasid = uattr.vas_id; 101 - 102 - vas_init_tx_win_attr(&txattr, cp_inst->coproc->cop_type); 103 - 104 - txattr.lpid = mfspr(SPRN_LPID); 105 - txattr.pidr = mfspr(SPRN_PID); 106 - txattr.user_win = true; 107 - txattr.rsvd_txbuf_count = false; 108 - txattr.pswid = false; 109 - 110 - pr_devel("Pid %d: Opening txwin, PIDR %ld\n", txattr.pidr, 111 - mfspr(SPRN_PID)); 112 - 113 - txwin = vas_tx_win_open(vasid, cp_inst->coproc->cop_type, &txattr); 114 - if (IS_ERR(txwin)) { 115 - pr_err("%s() vas_tx_win_open() failed, %ld\n", __func__, 116 - PTR_ERR(txwin)); 117 - return PTR_ERR(txwin); 118 - } 119 - 120 - cp_inst->txwin = txwin; 121 - 122 - return 0; 123 - } 124 - 125 - static int coproc_release(struct inode *inode, struct file *fp) 126 - { 127 - struct coproc_instance *cp_inst = fp->private_data; 128 - 129 - if (cp_inst->txwin) { 130 - vas_win_close(cp_inst->txwin); 131 - cp_inst->txwin = NULL; 132 - } 133 - 134 - kfree(cp_inst); 135 - fp->private_data = NULL; 136 - 137 - /* 138 - * We don't know here if user has other receive windows 139 - * open, so we can't really call clear_thread_tidr(). 140 - * So, once the process calls set_thread_tidr(), the 141 - * TIDR value sticks around until process exits, resulting 142 - * in an extra copy in restore_sprs(). 143 - */ 144 - 145 - return 0; 146 - } 147 - 148 - static int coproc_mmap(struct file *fp, struct vm_area_struct *vma) 149 - { 150 - struct coproc_instance *cp_inst = fp->private_data; 151 - struct vas_window *txwin; 152 - unsigned long pfn; 153 - u64 paste_addr; 154 - pgprot_t prot; 155 - int rc; 156 - 157 - txwin = cp_inst->txwin; 158 - 159 - if ((vma->vm_end - vma->vm_start) > PAGE_SIZE) { 160 - pr_debug("%s(): size 0x%zx, PAGE_SIZE 0x%zx\n", __func__, 161 - (vma->vm_end - vma->vm_start), PAGE_SIZE); 162 - return -EINVAL; 163 - } 164 - 165 - /* Ensure instance has an open send window */ 166 - if (!txwin) { 167 - pr_err("%s(): No send window open?\n", __func__); 168 - return -EINVAL; 169 - } 170 - 171 - vas_win_paste_addr(txwin, &paste_addr, NULL); 172 - pfn = paste_addr >> PAGE_SHIFT; 173 - 174 - /* flags, page_prot from cxl_mmap(), except we want cachable */ 175 - vma->vm_flags |= VM_IO | VM_PFNMAP; 176 - vma->vm_page_prot = pgprot_cached(vma->vm_page_prot); 177 - 178 - prot = __pgprot(pgprot_val(vma->vm_page_prot) | _PAGE_DIRTY); 179 - 180 - rc = remap_pfn_range(vma, vma->vm_start, pfn + vma->vm_pgoff, 181 - vma->vm_end - vma->vm_start, prot); 182 - 183 - pr_devel("%s(): paste addr %llx at %lx, rc %d\n", __func__, 184 - paste_addr, vma->vm_start, rc); 185 - 186 - return rc; 187 - } 188 - 189 - static long coproc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) 190 - { 191 - switch (cmd) { 192 - case VAS_TX_WIN_OPEN: 193 - return coproc_ioc_tx_win_open(fp, arg); 194 - default: 195 - return -EINVAL; 196 - } 197 - } 198 - 199 - static struct file_operations coproc_fops = { 200 - .open = coproc_open, 201 - .release = coproc_release, 202 - .mmap = coproc_mmap, 203 - .unlocked_ioctl = coproc_ioctl, 204 - }; 205 - 206 - /* 207 - * Supporting only nx-gzip coprocessor type now, but this API code 208 - * extended to other coprocessor types later. 209 - */ 210 - int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, 211 - const char *name) 212 - { 213 - int rc = -EINVAL; 214 - dev_t devno; 215 - 216 - rc = alloc_chrdev_region(&coproc_device.devt, 1, 1, name); 217 - if (rc) { 218 - pr_err("Unable to allocate coproc major number: %i\n", rc); 219 - return rc; 220 - } 221 - 222 - pr_devel("%s device allocated, dev [%i,%i]\n", name, 223 - MAJOR(coproc_device.devt), MINOR(coproc_device.devt)); 224 - 225 - coproc_device.class = class_create(mod, name); 226 - if (IS_ERR(coproc_device.class)) { 227 - rc = PTR_ERR(coproc_device.class); 228 - pr_err("Unable to create %s class %d\n", name, rc); 229 - goto err_class; 230 - } 231 - coproc_device.class->devnode = coproc_devnode; 232 - coproc_device.cop_type = cop_type; 233 - 234 - coproc_fops.owner = mod; 235 - cdev_init(&coproc_device.cdev, &coproc_fops); 236 - 237 - devno = MKDEV(MAJOR(coproc_device.devt), 0); 238 - rc = cdev_add(&coproc_device.cdev, devno, 1); 239 - if (rc) { 240 - pr_err("cdev_add() failed %d\n", rc); 241 - goto err_cdev; 242 - } 243 - 244 - coproc_device.device = device_create(coproc_device.class, NULL, 245 - devno, NULL, name, MINOR(devno)); 246 - if (IS_ERR(coproc_device.device)) { 247 - rc = PTR_ERR(coproc_device.device); 248 - pr_err("Unable to create coproc-%d %d\n", MINOR(devno), rc); 249 - goto err; 250 - } 251 - 252 - pr_devel("%s: Added dev [%d,%d]\n", __func__, MAJOR(devno), 253 - MINOR(devno)); 254 - 255 - return 0; 256 - 257 - err: 258 - cdev_del(&coproc_device.cdev); 259 - err_cdev: 260 - class_destroy(coproc_device.class); 261 - err_class: 262 - unregister_chrdev_region(coproc_device.devt, 1); 263 - return rc; 264 - } 265 - EXPORT_SYMBOL_GPL(vas_register_coproc_api); 266 - 267 - void vas_unregister_coproc_api(void) 268 - { 269 - dev_t devno; 270 - 271 - cdev_del(&coproc_device.cdev); 272 - devno = MKDEV(MAJOR(coproc_device.devt), 0); 273 - device_destroy(coproc_device.class, devno); 274 - 275 - class_destroy(coproc_device.class); 276 - unregister_chrdev_region(coproc_device.devt, 1); 277 - } 278 - EXPORT_SYMBOL_GPL(vas_unregister_coproc_api);
+15 -12
arch/powerpc/platforms/powernv/vas-debug.c
··· 9 9 #include <linux/slab.h> 10 10 #include <linux/debugfs.h> 11 11 #include <linux/seq_file.h> 12 + #include <asm/vas.h> 12 13 #include "vas.h" 13 14 14 15 static struct dentry *vas_debugfs; ··· 29 28 30 29 static int info_show(struct seq_file *s, void *private) 31 30 { 32 - struct vas_window *window = s->private; 31 + struct pnv_vas_window *window = s->private; 33 32 34 33 mutex_lock(&vas_mutex); 35 34 ··· 37 36 if (!window->hvwc_map) 38 37 goto unlock; 39 38 40 - seq_printf(s, "Type: %s, %s\n", cop_to_str(window->cop), 39 + seq_printf(s, "Type: %s, %s\n", cop_to_str(window->vas_win.cop), 41 40 window->tx_win ? "Send" : "Receive"); 42 - seq_printf(s, "Pid : %d\n", vas_window_pid(window)); 41 + seq_printf(s, "Pid : %d\n", vas_window_pid(&window->vas_win)); 43 42 44 43 unlock: 45 44 mutex_unlock(&vas_mutex); ··· 48 47 49 48 DEFINE_SHOW_ATTRIBUTE(info); 50 49 51 - static inline void print_reg(struct seq_file *s, struct vas_window *win, 50 + static inline void print_reg(struct seq_file *s, struct pnv_vas_window *win, 52 51 char *name, u32 reg) 53 52 { 54 53 seq_printf(s, "0x%016llx %s\n", read_hvwc_reg(win, name, reg), name); ··· 56 55 57 56 static int hvwc_show(struct seq_file *s, void *private) 58 57 { 59 - struct vas_window *window = s->private; 58 + struct pnv_vas_window *window = s->private; 60 59 61 60 mutex_lock(&vas_mutex); 62 61 ··· 104 103 105 104 DEFINE_SHOW_ATTRIBUTE(hvwc); 106 105 107 - void vas_window_free_dbgdir(struct vas_window *window) 106 + void vas_window_free_dbgdir(struct pnv_vas_window *pnv_win) 108 107 { 108 + struct vas_window *window = &pnv_win->vas_win; 109 + 109 110 if (window->dbgdir) { 110 111 debugfs_remove_recursive(window->dbgdir); 111 112 kfree(window->dbgname); ··· 116 113 } 117 114 } 118 115 119 - void vas_window_init_dbgdir(struct vas_window *window) 116 + void vas_window_init_dbgdir(struct pnv_vas_window *window) 120 117 { 121 118 struct dentry *d; 122 119 123 120 if (!window->vinst->dbgdir) 124 121 return; 125 122 126 - window->dbgname = kzalloc(16, GFP_KERNEL); 127 - if (!window->dbgname) 123 + window->vas_win.dbgname = kzalloc(16, GFP_KERNEL); 124 + if (!window->vas_win.dbgname) 128 125 return; 129 126 130 - snprintf(window->dbgname, 16, "w%d", window->winid); 127 + snprintf(window->vas_win.dbgname, 16, "w%d", window->vas_win.winid); 131 128 132 - d = debugfs_create_dir(window->dbgname, window->vinst->dbgdir); 133 - window->dbgdir = d; 129 + d = debugfs_create_dir(window->vas_win.dbgname, window->vinst->dbgdir); 130 + window->vas_win.dbgdir = d; 134 131 135 132 debugfs_create_file("info", 0444, d, window, &info_fops); 136 133 debugfs_create_file("hvwc", 0444, d, window, &hvwc_fops);
+18 -155
arch/powerpc/platforms/powernv/vas-fault.c
··· 26 26 */ 27 27 #define VAS_FAULT_WIN_FIFO_SIZE (4 << 20) 28 28 29 - static void dump_crb(struct coprocessor_request_block *crb) 30 - { 31 - struct data_descriptor_entry *dde; 32 - struct nx_fault_stamp *nx; 33 - 34 - dde = &crb->source; 35 - pr_devel("SrcDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n", 36 - be64_to_cpu(dde->address), be32_to_cpu(dde->length), 37 - dde->count, dde->index, dde->flags); 38 - 39 - dde = &crb->target; 40 - pr_devel("TgtDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n", 41 - be64_to_cpu(dde->address), be32_to_cpu(dde->length), 42 - dde->count, dde->index, dde->flags); 43 - 44 - nx = &crb->stamp.nx; 45 - pr_devel("NX Stamp: PSWID 0x%x, FSA 0x%llx, flags 0x%x, FS 0x%x\n", 46 - be32_to_cpu(nx->pswid), 47 - be64_to_cpu(crb->stamp.nx.fault_storage_addr), 48 - nx->flags, nx->fault_status); 49 - } 50 - 51 - /* 52 - * Update the CSB to indicate a translation error. 53 - * 54 - * User space will be polling on CSB after the request is issued. 55 - * If NX can handle the request without any issues, it updates CSB. 56 - * Whereas if NX encounters page fault, the kernel will handle the 57 - * fault and update CSB with translation error. 58 - * 59 - * If we are unable to update the CSB means copy_to_user failed due to 60 - * invalid csb_addr, send a signal to the process. 61 - */ 62 - static void update_csb(struct vas_window *window, 63 - struct coprocessor_request_block *crb) 64 - { 65 - struct coprocessor_status_block csb; 66 - struct kernel_siginfo info; 67 - struct task_struct *tsk; 68 - void __user *csb_addr; 69 - struct pid *pid; 70 - int rc; 71 - 72 - /* 73 - * NX user space windows can not be opened for task->mm=NULL 74 - * and faults will not be generated for kernel requests. 75 - */ 76 - if (WARN_ON_ONCE(!window->mm || !window->user_win)) 77 - return; 78 - 79 - csb_addr = (void __user *)be64_to_cpu(crb->csb_addr); 80 - 81 - memset(&csb, 0, sizeof(csb)); 82 - csb.cc = CSB_CC_FAULT_ADDRESS; 83 - csb.ce = CSB_CE_TERMINATION; 84 - csb.cs = 0; 85 - csb.count = 0; 86 - 87 - /* 88 - * NX operates and returns in BE format as defined CRB struct. 89 - * So saves fault_storage_addr in BE as NX pastes in FIFO and 90 - * expects user space to convert to CPU format. 91 - */ 92 - csb.address = crb->stamp.nx.fault_storage_addr; 93 - csb.flags = 0; 94 - 95 - pid = window->pid; 96 - tsk = get_pid_task(pid, PIDTYPE_PID); 97 - /* 98 - * Process closes send window after all pending NX requests are 99 - * completed. In multi-thread applications, a child thread can 100 - * open a window and can exit without closing it. May be some 101 - * requests are pending or this window can be used by other 102 - * threads later. We should handle faults if NX encounters 103 - * pages faults on these requests. Update CSB with translation 104 - * error and fault address. If csb_addr passed by user space is 105 - * invalid, send SEGV signal to pid saved in window. If the 106 - * child thread is not running, send the signal to tgid. 107 - * Parent thread (tgid) will close this window upon its exit. 108 - * 109 - * pid and mm references are taken when window is opened by 110 - * process (pid). So tgid is used only when child thread opens 111 - * a window and exits without closing it. 112 - */ 113 - if (!tsk) { 114 - pid = window->tgid; 115 - tsk = get_pid_task(pid, PIDTYPE_PID); 116 - /* 117 - * Parent thread (tgid) will be closing window when it 118 - * exits. So should not get here. 119 - */ 120 - if (WARN_ON_ONCE(!tsk)) 121 - return; 122 - } 123 - 124 - /* Return if the task is exiting. */ 125 - if (tsk->flags & PF_EXITING) { 126 - put_task_struct(tsk); 127 - return; 128 - } 129 - 130 - kthread_use_mm(window->mm); 131 - rc = copy_to_user(csb_addr, &csb, sizeof(csb)); 132 - /* 133 - * User space polls on csb.flags (first byte). So add barrier 134 - * then copy first byte with csb flags update. 135 - */ 136 - if (!rc) { 137 - csb.flags = CSB_V; 138 - /* Make sure update to csb.flags is visible now */ 139 - smp_mb(); 140 - rc = copy_to_user(csb_addr, &csb, sizeof(u8)); 141 - } 142 - kthread_unuse_mm(window->mm); 143 - put_task_struct(tsk); 144 - 145 - /* Success */ 146 - if (!rc) 147 - return; 148 - 149 - pr_debug("Invalid CSB address 0x%p signalling pid(%d)\n", 150 - csb_addr, pid_vnr(pid)); 151 - 152 - clear_siginfo(&info); 153 - info.si_signo = SIGSEGV; 154 - info.si_errno = EFAULT; 155 - info.si_code = SEGV_MAPERR; 156 - info.si_addr = csb_addr; 157 - 158 - /* 159 - * process will be polling on csb.flags after request is sent to 160 - * NX. So generally CSB update should not fail except when an 161 - * application passes invalid csb_addr. So an error message will 162 - * be displayed and leave it to user space whether to ignore or 163 - * handle this signal. 164 - */ 165 - rcu_read_lock(); 166 - rc = kill_pid_info(SIGSEGV, &info, pid); 167 - rcu_read_unlock(); 168 - 169 - pr_devel("%s(): pid %d kill_proc_info() rc %d\n", __func__, 170 - pid_vnr(pid), rc); 171 - } 172 - 173 29 static void dump_fifo(struct vas_instance *vinst, void *entry) 174 30 { 175 31 unsigned long *end = vinst->fault_fifo + vinst->fault_fifo_size; ··· 68 212 struct vas_instance *vinst = data; 69 213 struct coprocessor_request_block *crb, *entry; 70 214 struct coprocessor_request_block buf; 71 - struct vas_window *window; 215 + struct pnv_vas_window *window; 72 216 unsigned long flags; 73 217 void *fifo; 74 218 ··· 128 272 vinst->vas_id, vinst->fault_fifo, fifo, 129 273 vinst->fault_crbs); 130 274 131 - dump_crb(crb); 275 + vas_dump_crb(crb); 132 276 window = vas_pswid_to_window(vinst, 133 277 be32_to_cpu(crb->stamp.nx.pswid)); 134 278 ··· 149 293 150 294 WARN_ON_ONCE(1); 151 295 } else { 152 - update_csb(window, crb); 296 + /* 297 + * NX sees faults only with user space windows. 298 + */ 299 + if (window->user_win) 300 + vas_update_csb(crb, &window->vas_win.task_ref); 301 + else 302 + WARN_ON_ONCE(!window->user_win); 303 + 153 304 /* 154 305 * Return credit for send window after processing 155 306 * fault CRB. ··· 199 336 int vas_setup_fault_window(struct vas_instance *vinst) 200 337 { 201 338 struct vas_rx_win_attr attr; 339 + struct vas_window *win; 202 340 203 341 vinst->fault_fifo_size = VAS_FAULT_WIN_FIFO_SIZE; 204 342 vinst->fault_fifo = kzalloc(vinst->fault_fifo_size, GFP_KERNEL); ··· 228 364 attr.lnotify_pid = mfspr(SPRN_PID); 229 365 attr.lnotify_tid = mfspr(SPRN_PID); 230 366 231 - vinst->fault_win = vas_rx_win_open(vinst->vas_id, VAS_COP_TYPE_FAULT, 232 - &attr); 233 - 234 - if (IS_ERR(vinst->fault_win)) { 235 - pr_err("VAS: Error %ld opening FaultWin\n", 236 - PTR_ERR(vinst->fault_win)); 367 + win = vas_rx_win_open(vinst->vas_id, VAS_COP_TYPE_FAULT, &attr); 368 + if (IS_ERR(win)) { 369 + pr_err("VAS: Error %ld opening FaultWin\n", PTR_ERR(win)); 237 370 kfree(vinst->fault_fifo); 238 - return PTR_ERR(vinst->fault_win); 371 + return PTR_ERR(win); 239 372 } 240 373 374 + vinst->fault_win = container_of(win, struct pnv_vas_window, vas_win); 375 + 241 376 pr_devel("VAS: Created FaultWin %d, LPID/PID/TID [%d/%d/%d]\n", 242 - vinst->fault_win->winid, attr.lnotify_lpid, 377 + vinst->fault_win->vas_win.winid, attr.lnotify_lpid, 243 378 attr.lnotify_pid, attr.lnotify_tid); 244 379 245 380 return 0;
+2 -2
arch/powerpc/platforms/powernv/vas-trace.h
··· 80 80 TRACE_EVENT( vas_paste_crb, 81 81 82 82 TP_PROTO(struct task_struct *tsk, 83 - struct vas_window *win), 83 + struct pnv_vas_window *win), 84 84 85 85 TP_ARGS(tsk, win), 86 86 ··· 96 96 TP_fast_assign( 97 97 __entry->pid = tsk->pid; 98 98 __entry->vasid = win->vinst->vas_id; 99 - __entry->winid = win->winid; 99 + __entry->winid = win->vas_win.winid; 100 100 __entry->paste_kaddr = (unsigned long)win->paste_kaddr 101 101 ), 102 102
+146 -118
arch/powerpc/platforms/powernv/vas-window.c
··· 16 16 #include <linux/mmu_context.h> 17 17 #include <asm/switch_to.h> 18 18 #include <asm/ppc-opcode.h> 19 + #include <asm/vas.h> 19 20 #include "vas.h" 20 21 #include "copy-paste.h" 21 22 ··· 27 26 * Compute the paste address region for the window @window using the 28 27 * ->paste_base_addr and ->paste_win_id_shift we got from device tree. 29 28 */ 30 - void vas_win_paste_addr(struct vas_window *window, u64 *addr, int *len) 29 + void vas_win_paste_addr(struct pnv_vas_window *window, u64 *addr, int *len) 31 30 { 32 31 int winid; 33 32 u64 base, shift; 34 33 35 34 base = window->vinst->paste_base_addr; 36 35 shift = window->vinst->paste_win_id_shift; 37 - winid = window->winid; 36 + winid = window->vas_win.winid; 38 37 39 38 *addr = base + (winid << shift); 40 39 if (len) ··· 43 42 pr_debug("Txwin #%d: Paste addr 0x%llx\n", winid, *addr); 44 43 } 45 44 46 - static inline void get_hvwc_mmio_bar(struct vas_window *window, 45 + static inline void get_hvwc_mmio_bar(struct pnv_vas_window *window, 47 46 u64 *start, int *len) 48 47 { 49 48 u64 pbaddr; 50 49 51 50 pbaddr = window->vinst->hvwc_bar_start; 52 - *start = pbaddr + window->winid * VAS_HVWC_SIZE; 51 + *start = pbaddr + window->vas_win.winid * VAS_HVWC_SIZE; 53 52 *len = VAS_HVWC_SIZE; 54 53 } 55 54 56 - static inline void get_uwc_mmio_bar(struct vas_window *window, 55 + static inline void get_uwc_mmio_bar(struct pnv_vas_window *window, 57 56 u64 *start, int *len) 58 57 { 59 58 u64 pbaddr; 60 59 61 60 pbaddr = window->vinst->uwc_bar_start; 62 - *start = pbaddr + window->winid * VAS_UWC_SIZE; 61 + *start = pbaddr + window->vas_win.winid * VAS_UWC_SIZE; 63 62 *len = VAS_UWC_SIZE; 64 63 } 65 64 ··· 68 67 * space. Unlike MMIO regions (map_mmio_region() below), paste region must 69 68 * be mapped cache-able and is only applicable to send windows. 70 69 */ 71 - static void *map_paste_region(struct vas_window *txwin) 70 + static void *map_paste_region(struct pnv_vas_window *txwin) 72 71 { 73 72 int len; 74 73 void *map; ··· 76 75 u64 start; 77 76 78 77 name = kasprintf(GFP_KERNEL, "window-v%d-w%d", txwin->vinst->vas_id, 79 - txwin->winid); 78 + txwin->vas_win.winid); 80 79 if (!name) 81 80 goto free_name; 82 81 ··· 133 132 /* 134 133 * Unmap the paste address region for a window. 135 134 */ 136 - static void unmap_paste_region(struct vas_window *window) 135 + static void unmap_paste_region(struct pnv_vas_window *window) 137 136 { 138 137 int len; 139 138 u64 busaddr_start; ··· 154 153 * path, just minimize the time we hold the mutex for now. We can add 155 154 * a per-instance mutex later if necessary. 156 155 */ 157 - static void unmap_winctx_mmio_bars(struct vas_window *window) 156 + static void unmap_winctx_mmio_bars(struct pnv_vas_window *window) 158 157 { 159 158 int len; 160 159 void *uwc_map; ··· 187 186 * OS/User Window Context (UWC) MMIO Base Address Region for the given window. 188 187 * Map these bus addresses and save the mapped kernel addresses in @window. 189 188 */ 190 - static int map_winctx_mmio_bars(struct vas_window *window) 189 + static int map_winctx_mmio_bars(struct pnv_vas_window *window) 191 190 { 192 191 int len; 193 192 u64 start; ··· 215 214 * registers are not sequential. And, we can only write to offsets 216 215 * with valid registers. 217 216 */ 218 - static void reset_window_regs(struct vas_window *window) 217 + static void reset_window_regs(struct pnv_vas_window *window) 219 218 { 220 219 write_hvwc_reg(window, VREG(LPID), 0ULL); 221 220 write_hvwc_reg(window, VREG(PID), 0ULL); ··· 271 270 * want to add fields to vas_winctx and move the initialization to 272 271 * init_vas_winctx_regs(). 273 272 */ 274 - static void init_xlate_regs(struct vas_window *window, bool user_win) 273 + static void init_xlate_regs(struct pnv_vas_window *window, bool user_win) 275 274 { 276 275 u64 lpcr, val; 277 276 ··· 336 335 * 337 336 * TODO: Reserved (aka dedicated) send buffers are not supported yet. 338 337 */ 339 - static void init_rsvd_tx_buf_count(struct vas_window *txwin, 338 + static void init_rsvd_tx_buf_count(struct pnv_vas_window *txwin, 340 339 struct vas_winctx *winctx) 341 340 { 342 341 write_hvwc_reg(txwin, VREG(TX_RSVD_BUF_COUNT), 0ULL); ··· 358 357 * as a one-time task? That could work for NX but what about other 359 358 * receivers? Let the receivers tell us the rx-fifo buffers for now. 360 359 */ 361 - static void init_winctx_regs(struct vas_window *window, 360 + static void init_winctx_regs(struct pnv_vas_window *window, 362 361 struct vas_winctx *winctx) 363 362 { 364 363 u64 val; ··· 520 519 return winid; 521 520 } 522 521 523 - static void vas_window_free(struct vas_window *window) 522 + static void vas_window_free(struct pnv_vas_window *window) 524 523 { 525 - int winid = window->winid; 526 524 struct vas_instance *vinst = window->vinst; 525 + int winid = window->vas_win.winid; 527 526 528 527 unmap_winctx_mmio_bars(window); 529 528 ··· 534 533 vas_release_window_id(&vinst->ida, winid); 535 534 } 536 535 537 - static struct vas_window *vas_window_alloc(struct vas_instance *vinst) 536 + static struct pnv_vas_window *vas_window_alloc(struct vas_instance *vinst) 538 537 { 539 538 int winid; 540 - struct vas_window *window; 539 + struct pnv_vas_window *window; 541 540 542 541 winid = vas_assign_window_id(&vinst->ida); 543 542 if (winid < 0) ··· 548 547 goto out_free; 549 548 550 549 window->vinst = vinst; 551 - window->winid = winid; 550 + window->vas_win.winid = winid; 552 551 553 552 if (map_winctx_mmio_bars(window)) 554 553 goto out_free; ··· 563 562 return ERR_PTR(-ENOMEM); 564 563 } 565 564 566 - static void put_rx_win(struct vas_window *rxwin) 565 + static void put_rx_win(struct pnv_vas_window *rxwin) 567 566 { 568 567 /* Better not be a send window! */ 569 568 WARN_ON_ONCE(rxwin->tx_win); ··· 579 578 * 580 579 * NOTE: We access ->windows[] table and assume that vinst->mutex is held. 581 580 */ 582 - static struct vas_window *get_user_rxwin(struct vas_instance *vinst, u32 pswid) 581 + static struct pnv_vas_window *get_user_rxwin(struct vas_instance *vinst, 582 + u32 pswid) 583 583 { 584 584 int vasid, winid; 585 - struct vas_window *rxwin; 585 + struct pnv_vas_window *rxwin; 586 586 587 587 decode_pswid(pswid, &vasid, &winid); 588 588 ··· 592 590 593 591 rxwin = vinst->windows[winid]; 594 592 595 - if (!rxwin || rxwin->tx_win || rxwin->cop != VAS_COP_TYPE_FTW) 593 + if (!rxwin || rxwin->tx_win || rxwin->vas_win.cop != VAS_COP_TYPE_FTW) 596 594 return ERR_PTR(-EINVAL); 597 595 598 596 return rxwin; ··· 604 602 * 605 603 * See also function header of set_vinst_win(). 606 604 */ 607 - static struct vas_window *get_vinst_rxwin(struct vas_instance *vinst, 605 + static struct pnv_vas_window *get_vinst_rxwin(struct vas_instance *vinst, 608 606 enum vas_cop_type cop, u32 pswid) 609 607 { 610 - struct vas_window *rxwin; 608 + struct pnv_vas_window *rxwin; 611 609 612 610 mutex_lock(&vinst->mutex); 613 611 ··· 640 638 * window, we also save the window in the ->rxwin[] table. 641 639 */ 642 640 static void set_vinst_win(struct vas_instance *vinst, 643 - struct vas_window *window) 641 + struct pnv_vas_window *window) 644 642 { 645 - int id = window->winid; 643 + int id = window->vas_win.winid; 646 644 647 645 mutex_lock(&vinst->mutex); 648 646 ··· 651 649 * unless its a user (FTW) window. 652 650 */ 653 651 if (!window->user_win && !window->tx_win) { 654 - WARN_ON_ONCE(vinst->rxwin[window->cop]); 655 - vinst->rxwin[window->cop] = window; 652 + WARN_ON_ONCE(vinst->rxwin[window->vas_win.cop]); 653 + vinst->rxwin[window->vas_win.cop] = window; 656 654 } 657 655 658 656 WARN_ON_ONCE(vinst->windows[id] != NULL); ··· 665 663 * Clear this window from the table(s) of windows for this VAS instance. 666 664 * See also function header of set_vinst_win(). 667 665 */ 668 - static void clear_vinst_win(struct vas_window *window) 666 + static void clear_vinst_win(struct pnv_vas_window *window) 669 667 { 670 - int id = window->winid; 668 + int id = window->vas_win.winid; 671 669 struct vas_instance *vinst = window->vinst; 672 670 673 671 mutex_lock(&vinst->mutex); 674 672 675 673 if (!window->user_win && !window->tx_win) { 676 - WARN_ON_ONCE(!vinst->rxwin[window->cop]); 677 - vinst->rxwin[window->cop] = NULL; 674 + WARN_ON_ONCE(!vinst->rxwin[window->vas_win.cop]); 675 + vinst->rxwin[window->vas_win.cop] = NULL; 678 676 } 679 677 680 678 WARN_ON_ONCE(vinst->windows[id] != window); ··· 683 681 mutex_unlock(&vinst->mutex); 684 682 } 685 683 686 - static void init_winctx_for_rxwin(struct vas_window *rxwin, 684 + static void init_winctx_for_rxwin(struct pnv_vas_window *rxwin, 687 685 struct vas_rx_win_attr *rxattr, 688 686 struct vas_winctx *winctx) 689 687 { ··· 704 702 705 703 winctx->rx_fifo = rxattr->rx_fifo; 706 704 winctx->rx_fifo_size = rxattr->rx_fifo_size; 707 - winctx->wcreds_max = rxwin->wcreds_max; 705 + winctx->wcreds_max = rxwin->vas_win.wcreds_max; 708 706 winctx->pin_win = rxattr->pin_win; 709 707 710 708 winctx->nx_win = rxattr->nx_win; ··· 853 851 struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop, 854 852 struct vas_rx_win_attr *rxattr) 855 853 { 856 - struct vas_window *rxwin; 854 + struct pnv_vas_window *rxwin; 857 855 struct vas_winctx winctx; 858 856 struct vas_instance *vinst; 859 857 ··· 872 870 rxwin = vas_window_alloc(vinst); 873 871 if (IS_ERR(rxwin)) { 874 872 pr_devel("Unable to allocate memory for Rx window\n"); 875 - return rxwin; 873 + return (struct vas_window *)rxwin; 876 874 } 877 875 878 876 rxwin->tx_win = false; 879 877 rxwin->nx_win = rxattr->nx_win; 880 878 rxwin->user_win = rxattr->user_win; 881 - rxwin->cop = cop; 882 - rxwin->wcreds_max = rxattr->wcreds_max; 879 + rxwin->vas_win.cop = cop; 880 + rxwin->vas_win.wcreds_max = rxattr->wcreds_max; 883 881 884 882 init_winctx_for_rxwin(rxwin, rxattr, &winctx); 885 883 init_winctx_regs(rxwin, &winctx); 886 884 887 885 set_vinst_win(vinst, rxwin); 888 886 889 - return rxwin; 887 + return &rxwin->vas_win; 890 888 } 891 889 EXPORT_SYMBOL_GPL(vas_rx_win_open); 892 890 ··· 907 905 } 908 906 EXPORT_SYMBOL_GPL(vas_init_tx_win_attr); 909 907 910 - static void init_winctx_for_txwin(struct vas_window *txwin, 908 + static void init_winctx_for_txwin(struct pnv_vas_window *txwin, 911 909 struct vas_tx_win_attr *txattr, 912 910 struct vas_winctx *winctx) 913 911 { ··· 928 926 */ 929 927 memset(winctx, 0, sizeof(struct vas_winctx)); 930 928 931 - winctx->wcreds_max = txwin->wcreds_max; 929 + winctx->wcreds_max = txwin->vas_win.wcreds_max; 932 930 933 931 winctx->user_win = txattr->user_win; 934 932 winctx->nx_win = txwin->rxwin->nx_win; ··· 948 946 949 947 winctx->lpid = txattr->lpid; 950 948 winctx->pidr = txattr->pidr; 951 - winctx->rx_win_id = txwin->rxwin->winid; 949 + winctx->rx_win_id = txwin->rxwin->vas_win.winid; 952 950 /* 953 951 * IRQ and fault window setup is successful. Set fault window 954 952 * for the send window so that ready to handle faults. 955 953 */ 956 954 if (txwin->vinst->virq) 957 - winctx->fault_win_id = txwin->vinst->fault_win->winid; 955 + winctx->fault_win_id = txwin->vinst->fault_win->vas_win.winid; 958 956 959 957 winctx->dma_type = VAS_DMA_TYPE_INJECT; 960 958 winctx->tc_mode = txattr->tc_mode; ··· 964 962 winctx->irq_port = txwin->vinst->irq_port; 965 963 966 964 winctx->pswid = txattr->pswid ? txattr->pswid : 967 - encode_pswid(txwin->vinst->vas_id, txwin->winid); 965 + encode_pswid(txwin->vinst->vas_id, 966 + txwin->vas_win.winid); 968 967 } 969 968 970 969 static bool tx_win_args_valid(enum vas_cop_type cop, ··· 996 993 struct vas_tx_win_attr *attr) 997 994 { 998 995 int rc; 999 - struct vas_window *txwin; 1000 - struct vas_window *rxwin; 996 + struct pnv_vas_window *txwin; 997 + struct pnv_vas_window *rxwin; 1001 998 struct vas_winctx winctx; 1002 999 struct vas_instance *vinst; 1003 1000 ··· 1023 1020 rxwin = get_vinst_rxwin(vinst, cop, attr->pswid); 1024 1021 if (IS_ERR(rxwin)) { 1025 1022 pr_devel("No RxWin for vasid %d, cop %d\n", vasid, cop); 1026 - return rxwin; 1023 + return (struct vas_window *)rxwin; 1027 1024 } 1028 1025 1029 1026 txwin = vas_window_alloc(vinst); ··· 1032 1029 goto put_rxwin; 1033 1030 } 1034 1031 1035 - txwin->cop = cop; 1032 + txwin->vas_win.cop = cop; 1036 1033 txwin->tx_win = 1; 1037 1034 txwin->rxwin = rxwin; 1038 1035 txwin->nx_win = txwin->rxwin->nx_win; 1039 1036 txwin->user_win = attr->user_win; 1040 - txwin->wcreds_max = attr->wcreds_max ?: VAS_WCREDS_DEFAULT; 1037 + txwin->vas_win.wcreds_max = attr->wcreds_max ?: VAS_WCREDS_DEFAULT; 1041 1038 1042 1039 init_winctx_for_txwin(txwin, attr, &winctx); 1043 1040 ··· 1067 1064 rc = -ENODEV; 1068 1065 goto free_window; 1069 1066 } 1070 - 1071 - /* 1072 - * Window opened by a child thread may not be closed when 1073 - * it exits. So take reference to its pid and release it 1074 - * when the window is free by parent thread. 1075 - * Acquire a reference to the task's pid to make sure 1076 - * pid will not be re-used - needed only for multithread 1077 - * applications. 1078 - */ 1079 - txwin->pid = get_task_pid(current, PIDTYPE_PID); 1080 - /* 1081 - * Acquire a reference to the task's mm. 1082 - */ 1083 - txwin->mm = get_task_mm(current); 1084 - 1085 - if (!txwin->mm) { 1086 - put_pid(txwin->pid); 1087 - pr_err("VAS: pid(%d): mm_struct is not found\n", 1088 - current->pid); 1089 - rc = -EPERM; 1067 + rc = get_vas_user_win_ref(&txwin->vas_win.task_ref); 1068 + if (rc) 1090 1069 goto free_window; 1091 - } 1092 1070 1093 - mmgrab(txwin->mm); 1094 - mmput(txwin->mm); 1095 - mm_context_add_vas_window(txwin->mm); 1096 - /* 1097 - * Process closes window during exit. In the case of 1098 - * multithread application, the child thread can open 1099 - * window and can exit without closing it. Expects parent 1100 - * thread to use and close the window. So do not need 1101 - * to take pid reference for parent thread. 1102 - */ 1103 - txwin->tgid = find_get_pid(task_tgid_vnr(current)); 1104 - /* 1105 - * Even a process that has no foreign real address mapping can 1106 - * use an unpaired COPY instruction (to no real effect). Issue 1107 - * CP_ABORT to clear any pending COPY and prevent a covert 1108 - * channel. 1109 - * 1110 - * __switch_to() will issue CP_ABORT on future context switches 1111 - * if process / thread has any open VAS window (Use 1112 - * current->mm->context.vas_windows). 1113 - */ 1114 - asm volatile(PPC_CP_ABORT); 1071 + vas_user_win_add_mm_context(&txwin->vas_win.task_ref); 1115 1072 } 1116 1073 1117 1074 set_vinst_win(vinst, txwin); 1118 1075 1119 - return txwin; 1076 + return &txwin->vas_win; 1120 1077 1121 1078 free_window: 1122 1079 vas_window_free(txwin); ··· 1095 1132 EXPORT_SYMBOL_GPL(vas_copy_crb); 1096 1133 1097 1134 #define RMA_LSMP_REPORT_ENABLE PPC_BIT(53) 1098 - int vas_paste_crb(struct vas_window *txwin, int offset, bool re) 1135 + int vas_paste_crb(struct vas_window *vwin, int offset, bool re) 1099 1136 { 1137 + struct pnv_vas_window *txwin; 1100 1138 int rc; 1101 1139 void *addr; 1102 1140 uint64_t val; 1103 1141 1142 + txwin = container_of(vwin, struct pnv_vas_window, vas_win); 1104 1143 trace_vas_paste_crb(current, txwin); 1105 1144 1106 1145 /* ··· 1132 1167 else 1133 1168 rc = -EINVAL; 1134 1169 1135 - pr_debug("Txwin #%d: Msg count %llu\n", txwin->winid, 1170 + pr_debug("Txwin #%d: Msg count %llu\n", txwin->vas_win.winid, 1136 1171 read_hvwc_reg(txwin, VREG(LRFIFO_PUSH))); 1137 1172 1138 1173 return rc; ··· 1152 1187 * user space. (NX-842 driver waits for CSB and Fast thread-wakeup 1153 1188 * doesn't use credit checking). 1154 1189 */ 1155 - static void poll_window_credits(struct vas_window *window) 1190 + static void poll_window_credits(struct pnv_vas_window *window) 1156 1191 { 1157 1192 u64 val; 1158 1193 int creds, mode; ··· 1182 1217 * and issue CRB Kill to stop all pending requests. Need only 1183 1218 * if there is a bug in NX or fault handling in kernel. 1184 1219 */ 1185 - if (creds < window->wcreds_max) { 1220 + if (creds < window->vas_win.wcreds_max) { 1186 1221 val = 0; 1187 1222 set_current_state(TASK_UNINTERRUPTIBLE); 1188 1223 schedule_timeout(msecs_to_jiffies(10)); ··· 1193 1228 */ 1194 1229 if (!(count % 1000)) 1195 1230 pr_warn_ratelimited("VAS: pid %d stuck. Waiting for credits returned for Window(%d). creds %d, Retries %d\n", 1196 - vas_window_pid(window), window->winid, 1231 + vas_window_pid(&window->vas_win), 1232 + window->vas_win.winid, 1197 1233 creds, count); 1198 1234 1199 1235 goto retry; ··· 1206 1240 * short time to queue a CRB, so window should not be busy for too long. 1207 1241 * Trying 5ms intervals. 1208 1242 */ 1209 - static void poll_window_busy_state(struct vas_window *window) 1243 + static void poll_window_busy_state(struct pnv_vas_window *window) 1210 1244 { 1211 1245 int busy; 1212 1246 u64 val; ··· 1226 1260 */ 1227 1261 if (!(count % 1000)) 1228 1262 pr_warn_ratelimited("VAS: pid %d stuck. Window (ID=%d) is in busy state. Retries %d\n", 1229 - vas_window_pid(window), window->winid, count); 1263 + vas_window_pid(&window->vas_win), 1264 + window->vas_win.winid, count); 1230 1265 1231 1266 goto retry; 1232 1267 } ··· 1249 1282 * casting out becomes necessary we should consider offloading the 1250 1283 * job to a worker thread, so the window close can proceed quickly. 1251 1284 */ 1252 - static void poll_window_castout(struct vas_window *window) 1285 + static void poll_window_castout(struct pnv_vas_window *window) 1253 1286 { 1254 1287 /* stub for now */ 1255 1288 } ··· 1258 1291 * Unpin and close a window so no new requests are accepted and the 1259 1292 * hardware can evict this window from cache if necessary. 1260 1293 */ 1261 - static void unpin_close_window(struct vas_window *window) 1294 + static void unpin_close_window(struct pnv_vas_window *window) 1262 1295 { 1263 1296 u64 val; 1264 1297 ··· 1280 1313 * 1281 1314 * Besides the hardware, kernel has some bookkeeping of course. 1282 1315 */ 1283 - int vas_win_close(struct vas_window *window) 1316 + int vas_win_close(struct vas_window *vwin) 1284 1317 { 1285 - if (!window) 1318 + struct pnv_vas_window *window; 1319 + 1320 + if (!vwin) 1286 1321 return 0; 1322 + 1323 + window = container_of(vwin, struct pnv_vas_window, vas_win); 1287 1324 1288 1325 if (!window->tx_win && atomic_read(&window->num_txwins) != 0) { 1289 1326 pr_devel("Attempting to close an active Rx window!\n"); ··· 1310 1339 /* if send window, drop reference to matching receive window */ 1311 1340 if (window->tx_win) { 1312 1341 if (window->user_win) { 1313 - /* Drop references to pid and mm */ 1314 - put_pid(window->pid); 1315 - if (window->mm) { 1316 - mm_context_remove_vas_window(window->mm); 1317 - mmdrop(window->mm); 1318 - } 1342 + put_vas_user_win_ref(&vwin->task_ref); 1343 + mm_context_remove_vas_window(vwin->task_ref.mm); 1319 1344 } 1320 1345 put_rx_win(window->rxwin); 1321 1346 } ··· 1344 1377 * - The kernel with return credit on fault window after reading entry 1345 1378 * from fault FIFO. 1346 1379 */ 1347 - void vas_return_credit(struct vas_window *window, bool tx) 1380 + void vas_return_credit(struct pnv_vas_window *window, bool tx) 1348 1381 { 1349 1382 uint64_t val; 1350 1383 ··· 1358 1391 } 1359 1392 } 1360 1393 1361 - struct vas_window *vas_pswid_to_window(struct vas_instance *vinst, 1394 + struct pnv_vas_window *vas_pswid_to_window(struct vas_instance *vinst, 1362 1395 uint32_t pswid) 1363 1396 { 1364 - struct vas_window *window; 1397 + struct pnv_vas_window *window; 1365 1398 int winid; 1366 1399 1367 1400 if (!pswid) { ··· 1398 1431 * by NX). 1399 1432 */ 1400 1433 if (!window->tx_win || !window->user_win || !window->nx_win || 1401 - window->cop == VAS_COP_TYPE_FAULT || 1402 - window->cop == VAS_COP_TYPE_FTW) { 1434 + window->vas_win.cop == VAS_COP_TYPE_FAULT || 1435 + window->vas_win.cop == VAS_COP_TYPE_FTW) { 1403 1436 pr_err("PSWID decode: id %d, tx %d, user %d, nx %d, cop %d\n", 1404 1437 winid, window->tx_win, window->user_win, 1405 - window->nx_win, window->cop); 1438 + window->nx_win, window->vas_win.cop); 1406 1439 WARN_ON(1); 1407 1440 } 1408 1441 1409 1442 return window; 1410 1443 } 1444 + 1445 + static struct vas_window *vas_user_win_open(int vas_id, u64 flags, 1446 + enum vas_cop_type cop_type) 1447 + { 1448 + struct vas_tx_win_attr txattr = {}; 1449 + 1450 + vas_init_tx_win_attr(&txattr, cop_type); 1451 + 1452 + txattr.lpid = mfspr(SPRN_LPID); 1453 + txattr.pidr = mfspr(SPRN_PID); 1454 + txattr.user_win = true; 1455 + txattr.rsvd_txbuf_count = false; 1456 + txattr.pswid = false; 1457 + 1458 + pr_devel("Pid %d: Opening txwin, PIDR %ld\n", txattr.pidr, 1459 + mfspr(SPRN_PID)); 1460 + 1461 + return vas_tx_win_open(vas_id, cop_type, &txattr); 1462 + } 1463 + 1464 + static u64 vas_user_win_paste_addr(struct vas_window *txwin) 1465 + { 1466 + struct pnv_vas_window *win; 1467 + u64 paste_addr; 1468 + 1469 + win = container_of(txwin, struct pnv_vas_window, vas_win); 1470 + vas_win_paste_addr(win, &paste_addr, NULL); 1471 + 1472 + return paste_addr; 1473 + } 1474 + 1475 + static int vas_user_win_close(struct vas_window *txwin) 1476 + { 1477 + vas_win_close(txwin); 1478 + 1479 + return 0; 1480 + } 1481 + 1482 + static const struct vas_user_win_ops vops = { 1483 + .open_win = vas_user_win_open, 1484 + .paste_addr = vas_user_win_paste_addr, 1485 + .close_win = vas_user_win_close, 1486 + }; 1487 + 1488 + /* 1489 + * Supporting only nx-gzip coprocessor type now, but this API code 1490 + * extended to other coprocessor types later. 1491 + */ 1492 + int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, 1493 + const char *name) 1494 + { 1495 + 1496 + return vas_register_coproc_api(mod, cop_type, name, &vops); 1497 + } 1498 + EXPORT_SYMBOL_GPL(vas_register_api_powernv); 1499 + 1500 + void vas_unregister_api_powernv(void) 1501 + { 1502 + vas_unregister_coproc_api(); 1503 + } 1504 + EXPORT_SYMBOL_GPL(vas_unregister_api_powernv);
+21 -29
arch/powerpc/platforms/powernv/vas.h
··· 334 334 int fifo_in_progress; /* To wake up thread or return IRQ_HANDLED */ 335 335 spinlock_t fault_lock; /* Protects fifo_in_progress update */ 336 336 void *fault_fifo; 337 - struct vas_window *fault_win; /* Fault window */ 337 + struct pnv_vas_window *fault_win; /* Fault window */ 338 338 339 339 struct mutex mutex; 340 - struct vas_window *rxwin[VAS_COP_TYPE_MAX]; 341 - struct vas_window *windows[VAS_WINDOWS_PER_CHIP]; 340 + struct pnv_vas_window *rxwin[VAS_COP_TYPE_MAX]; 341 + struct pnv_vas_window *windows[VAS_WINDOWS_PER_CHIP]; 342 342 343 343 char *name; 344 344 char *dbgname; ··· 346 346 }; 347 347 348 348 /* 349 - * In-kernel state a VAS window. One per window. 349 + * In-kernel state a VAS window on PowerNV. One per window. 350 350 */ 351 - struct vas_window { 351 + struct pnv_vas_window { 352 + struct vas_window vas_win; 352 353 /* Fields common to send and receive windows */ 353 354 struct vas_instance *vinst; 354 - int winid; 355 355 bool tx_win; /* True if send window */ 356 356 bool nx_win; /* True if NX window */ 357 357 bool user_win; /* True if user space window */ 358 358 void *hvwc_map; /* HV window context */ 359 359 void *uwc_map; /* OS/User window context */ 360 - struct pid *pid; /* Linux process id of owner */ 361 - struct pid *tgid; /* Thread group ID of owner */ 362 - struct mm_struct *mm; /* Linux process mm_struct */ 363 - int wcreds_max; /* Window credits */ 364 - 365 - char *dbgname; 366 - struct dentry *dbgdir; 367 360 368 361 /* Fields applicable only to send windows */ 369 362 void *paste_kaddr; 370 363 char *paste_addr_name; 371 - struct vas_window *rxwin; 364 + struct pnv_vas_window *rxwin; 372 365 373 - /* Feilds applicable only to receive windows */ 374 - enum vas_cop_type cop; 366 + /* Fields applicable only to receive windows */ 375 367 atomic_t num_txwins; 376 368 }; 377 369 ··· 422 430 extern struct vas_instance *find_vas_instance(int vasid); 423 431 extern void vas_init_dbgdir(void); 424 432 extern void vas_instance_init_dbgdir(struct vas_instance *vinst); 425 - extern void vas_window_init_dbgdir(struct vas_window *win); 426 - extern void vas_window_free_dbgdir(struct vas_window *win); 433 + extern void vas_window_init_dbgdir(struct pnv_vas_window *win); 434 + extern void vas_window_free_dbgdir(struct pnv_vas_window *win); 427 435 extern int vas_setup_fault_window(struct vas_instance *vinst); 428 436 extern irqreturn_t vas_fault_thread_fn(int irq, void *data); 429 437 extern irqreturn_t vas_fault_handler(int irq, void *dev_id); 430 - extern void vas_return_credit(struct vas_window *window, bool tx); 431 - extern struct vas_window *vas_pswid_to_window(struct vas_instance *vinst, 438 + extern void vas_return_credit(struct pnv_vas_window *window, bool tx); 439 + extern struct pnv_vas_window *vas_pswid_to_window(struct vas_instance *vinst, 432 440 uint32_t pswid); 433 - extern void vas_win_paste_addr(struct vas_window *window, u64 *addr, 434 - int *len); 441 + extern void vas_win_paste_addr(struct pnv_vas_window *window, u64 *addr, 442 + int *len); 435 443 436 444 static inline int vas_window_pid(struct vas_window *window) 437 445 { 438 - return pid_vnr(window->pid); 446 + return pid_vnr(window->task_ref.pid); 439 447 } 440 448 441 - static inline void vas_log_write(struct vas_window *win, char *name, 449 + static inline void vas_log_write(struct pnv_vas_window *win, char *name, 442 450 void *regptr, u64 val) 443 451 { 444 452 if (val) 445 453 pr_debug("%swin #%d: %s reg %p, val 0x%016llx\n", 446 - win->tx_win ? "Tx" : "Rx", win->winid, name, 447 - regptr, val); 454 + win->tx_win ? "Tx" : "Rx", win->vas_win.winid, 455 + name, regptr, val); 448 456 } 449 457 450 - static inline void write_uwc_reg(struct vas_window *win, char *name, 458 + static inline void write_uwc_reg(struct pnv_vas_window *win, char *name, 451 459 s32 reg, u64 val) 452 460 { 453 461 void *regptr; ··· 458 466 out_be64(regptr, val); 459 467 } 460 468 461 - static inline void write_hvwc_reg(struct vas_window *win, char *name, 469 + static inline void write_hvwc_reg(struct pnv_vas_window *win, char *name, 462 470 s32 reg, u64 val) 463 471 { 464 472 void *regptr; ··· 469 477 out_be64(regptr, val); 470 478 } 471 479 472 - static inline u64 read_hvwc_reg(struct vas_window *win, 480 + static inline u64 read_hvwc_reg(struct pnv_vas_window *win, 473 481 char *name __maybe_unused, s32 reg) 474 482 { 475 483 return in_be64(win->hvwc_map+reg);
+9
arch/powerpc/platforms/ps3/Kconfig
··· 86 86 This support is required for PS3 system control. In 87 87 general, all users will say Y or M. 88 88 89 + config PS3_VERBOSE_RESULT 90 + bool "PS3 Verbose LV1 hypercall results" if PS3_ADVANCED 91 + depends on PPC_PS3 92 + help 93 + Enables more verbose log mesages for LV1 hypercall results. 94 + 95 + If in doubt, say N here and reduce the size of the kernel by a 96 + small amount. 97 + 89 98 config PS3_REPOSITORY_WRITE 90 99 bool "PS3 Repository write support" if PS3_ADVANCED 91 100 depends on PPC_PS3
+12
arch/powerpc/platforms/ps3/mm.c
··· 6 6 * Copyright 2006 Sony Corp. 7 7 */ 8 8 9 + #include <linux/dma-mapping.h> 9 10 #include <linux/kernel.h> 10 11 #include <linux/export.h> 11 12 #include <linux/memblock.h> ··· 1119 1118 enum ps3_dma_region_type region_type, void *addr, unsigned long len) 1120 1119 { 1121 1120 unsigned long lpar_addr; 1121 + int result; 1122 1122 1123 1123 lpar_addr = addr ? ps3_mm_phys_to_lpar(__pa(addr)) : 0; 1124 1124 ··· 1130 1128 if (r->offset >= map.rm.size) 1131 1129 r->offset -= map.r1.offset; 1132 1130 r->len = len ? len : ALIGN(map.total, 1 << r->page_size); 1131 + 1132 + dev->core.dma_mask = &r->dma_mask; 1133 + 1134 + result = dma_set_mask_and_coherent(&dev->core, DMA_BIT_MASK(32)); 1135 + 1136 + if (result < 0) { 1137 + dev_err(&dev->core, "%s:%d: dma_set_mask_and_coherent failed: %d\n", 1138 + __func__, __LINE__, result); 1139 + return result; 1140 + } 1133 1141 1134 1142 switch (dev->dev_type) { 1135 1143 case PS3_DEVICE_TYPE_SB:
+40 -3
arch/powerpc/platforms/ps3/setup.c
··· 36 36 EXPORT_SYMBOL_GPL(ps3_gpu_mutex); 37 37 38 38 static union ps3_firmware_version ps3_firmware_version; 39 + static char ps3_firmware_version_str[16]; 39 40 40 41 void ps3_get_firmware_version(union ps3_firmware_version *v) 41 42 { ··· 183 182 return lv1_set_dabr(dabr, dabrx) ? -1 : 0; 184 183 } 185 184 185 + static ssize_t ps3_fw_version_show(struct kobject *kobj, 186 + struct kobj_attribute *attr, char *buf) 187 + { 188 + return sprintf(buf, "%s", ps3_firmware_version_str); 189 + } 190 + 191 + static int __init ps3_setup_sysfs(void) 192 + { 193 + static struct kobj_attribute attr = __ATTR(fw-version, S_IRUGO, 194 + ps3_fw_version_show, NULL); 195 + static struct kobject *kobj; 196 + int result; 197 + 198 + kobj = kobject_create_and_add("ps3", firmware_kobj); 199 + 200 + if (!kobj) { 201 + pr_warn("%s:%d: kobject_create_and_add failed.\n", __func__, 202 + __LINE__); 203 + return -ENOMEM; 204 + } 205 + 206 + result = sysfs_create_file(kobj, &attr.attr); 207 + 208 + if (result) { 209 + pr_warn("%s:%d: sysfs_create_file failed.\n", __func__, 210 + __LINE__); 211 + kobject_put(kobj); 212 + return -ENOMEM; 213 + } 214 + 215 + return 0; 216 + } 217 + core_initcall(ps3_setup_sysfs); 218 + 186 219 static void __init ps3_setup_arch(void) 187 220 { 188 221 u64 tmp; ··· 225 190 226 191 lv1_get_version_info(&ps3_firmware_version.raw, &tmp); 227 192 228 - printk(KERN_INFO "PS3 firmware version %u.%u.%u\n", 229 - ps3_firmware_version.major, ps3_firmware_version.minor, 230 - ps3_firmware_version.rev); 193 + snprintf(ps3_firmware_version_str, sizeof(ps3_firmware_version_str), 194 + "%u.%u.%u", ps3_firmware_version.major, 195 + ps3_firmware_version.minor, ps3_firmware_version.rev); 196 + 197 + printk(KERN_INFO "PS3 firmware version %s\n", ps3_firmware_version_str); 231 198 232 199 ps3_spu_set_platform(); 233 200
+5 -4
arch/powerpc/platforms/ps3/system-bus.c
··· 64 64 result = lv1_open_device(dev->bus_id, dev->dev_id, 0); 65 65 66 66 if (result) { 67 - pr_debug("%s:%d: lv1_open_device failed: %s\n", __func__, 68 - __LINE__, ps3_result(result)); 69 - result = -EPERM; 67 + pr_warn("%s:%d: lv1_open_device dev=%u.%u(%s) failed: %s\n", 68 + __func__, __LINE__, dev->match_id, dev->match_sub_id, 69 + dev_name(&dev->core), ps3_result(result)); 70 + result = -EPERM; 70 71 } 71 72 72 73 done: ··· 121 120 result = lv1_gpu_open(0); 122 121 123 122 if (result) { 124 - pr_debug("%s:%d: lv1_gpu_open failed: %s\n", __func__, 123 + pr_warn("%s:%d: lv1_gpu_open failed: %s\n", __func__, 125 124 __LINE__, ps3_result(result)); 126 125 result = -EPERM; 127 126 }
+1
arch/powerpc/platforms/pseries/Makefile
··· 30 30 obj-$(CONFIG_FA_DUMP) += rtas-fadump.o 31 31 32 32 obj-$(CONFIG_SUSPEND) += suspend.o 33 + obj-$(CONFIG_PPC_VAS) += vas.o
+3 -6
arch/powerpc/platforms/pseries/dlpar.c
··· 289 289 { 290 290 int dr_status, rc; 291 291 292 - rc = rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status, 293 - DR_ENTITY_SENSE, drc_index); 292 + rc = rtas_get_sensor(DR_ENTITY_SENSE, drc_index, &dr_status); 294 293 if (rc || dr_status != DR_ENTITY_UNUSABLE) 295 294 return -1; 296 295 ··· 310 311 { 311 312 int dr_status, rc; 312 313 313 - rc = rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status, 314 - DR_ENTITY_SENSE, drc_index); 314 + rc = rtas_get_sensor(DR_ENTITY_SENSE, drc_index, &dr_status); 315 315 if (rc || dr_status != DR_ENTITY_PRESENT) 316 316 return -1; 317 317 ··· 331 333 { 332 334 int dr_status, rc; 333 335 334 - rc = rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status, 335 - DR_ENTITY_SENSE, drc_index); 336 + rc = rtas_get_sensor(DR_ENTITY_SENSE, drc_index, &dr_status); 336 337 if (rc || dr_status != DR_ENTITY_PRESENT) 337 338 return -1; 338 339
+61 -31
arch/powerpc/platforms/pseries/hotplug-memory.c
··· 348 348 349 349 static bool lmb_is_removable(struct drmem_lmb *lmb) 350 350 { 351 - if (!(lmb->flags & DRCONF_MEM_ASSIGNED)) 351 + if ((lmb->flags & DRCONF_MEM_RESERVED) || 352 + !(lmb->flags & DRCONF_MEM_ASSIGNED)) 352 353 return false; 353 354 354 355 #ifdef CONFIG_FA_DUMP ··· 402 401 static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) 403 402 { 404 403 struct drmem_lmb *lmb; 405 - int lmbs_removed = 0; 404 + int lmbs_reserved = 0; 406 405 int lmbs_available = 0; 407 406 int rc; 408 407 ··· 436 435 */ 437 436 drmem_mark_lmb_reserved(lmb); 438 437 439 - lmbs_removed++; 440 - if (lmbs_removed == lmbs_to_remove) 438 + lmbs_reserved++; 439 + if (lmbs_reserved == lmbs_to_remove) 441 440 break; 442 441 } 443 442 444 - if (lmbs_removed != lmbs_to_remove) { 443 + if (lmbs_reserved != lmbs_to_remove) { 445 444 pr_err("Memory hot-remove failed, adding LMB's back\n"); 446 445 447 446 for_each_drmem_lmb(lmb) { ··· 454 453 lmb->drc_index); 455 454 456 455 drmem_remove_lmb_reservation(lmb); 456 + 457 + lmbs_reserved--; 458 + if (lmbs_reserved == 0) 459 + break; 457 460 } 458 461 459 462 rc = -EINVAL; ··· 471 466 lmb->base_addr); 472 467 473 468 drmem_remove_lmb_reservation(lmb); 469 + 470 + lmbs_reserved--; 471 + if (lmbs_reserved == 0) 472 + break; 474 473 } 475 474 rc = 0; 476 475 } ··· 517 508 static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index) 518 509 { 519 510 struct drmem_lmb *lmb, *start_lmb, *end_lmb; 520 - int lmbs_available = 0; 521 511 int rc; 522 512 523 513 pr_info("Attempting to hot-remove %u LMB(s) at %x\n", ··· 529 521 if (rc) 530 522 return -EINVAL; 531 523 532 - /* Validate that there are enough LMBs to satisfy the request */ 524 + /* 525 + * Validate that all LMBs in range are not reserved. Note that it 526 + * is ok if they are !ASSIGNED since our goal here is to remove the 527 + * LMB range, regardless of whether some LMBs were already removed 528 + * by any other reason. 529 + * 530 + * This is a contrast to what is done in remove_by_count() where we 531 + * check for both RESERVED and !ASSIGNED (via lmb_is_removable()), 532 + * because we want to remove a fixed amount of LMBs in that function. 533 + */ 533 534 for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { 534 - if (lmb->flags & DRCONF_MEM_RESERVED) 535 - break; 536 - 537 - lmbs_available++; 535 + if (lmb->flags & DRCONF_MEM_RESERVED) { 536 + pr_err("Memory at %llx (drc index %x) is reserved\n", 537 + lmb->base_addr, lmb->drc_index); 538 + return -EINVAL; 539 + } 538 540 } 539 541 540 - if (lmbs_available < lmbs_to_remove) 541 - return -EINVAL; 542 - 543 542 for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { 543 + /* 544 + * dlpar_remove_lmb() will error out if the LMB is already 545 + * !ASSIGNED, but this case is a no-op for us. 546 + */ 544 547 if (!(lmb->flags & DRCONF_MEM_ASSIGNED)) 545 548 continue; 546 549 ··· 569 550 for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { 570 551 if (!drmem_lmb_reserved(lmb)) 571 552 continue; 553 + 554 + /* 555 + * Setting the isolation state of an UNISOLATED/CONFIGURED 556 + * device to UNISOLATE is a no-op, but the hypervisor can 557 + * use it as a hint that the LMB removal failed. 558 + */ 559 + dlpar_unisolate_drc(lmb->drc_index); 572 560 573 561 rc = dlpar_add_lmb(lmb); 574 562 if (rc) ··· 610 584 static inline int pseries_remove_mem_node(struct device_node *np) 611 585 { 612 586 return 0; 613 - } 614 - static inline int dlpar_memory_remove(struct pseries_hp_errorlog *hp_elog) 615 - { 616 - return -EOPNOTSUPP; 617 587 } 618 588 static int dlpar_remove_lmb(struct drmem_lmb *lmb) 619 589 { ··· 673 651 { 674 652 struct drmem_lmb *lmb; 675 653 int lmbs_available = 0; 676 - int lmbs_added = 0; 654 + int lmbs_reserved = 0; 677 655 int rc; 678 656 679 657 pr_info("Attempting to hot-add %d LMB(s)\n", lmbs_to_add); ··· 683 661 684 662 /* Validate that there are enough LMBs to satisfy the request */ 685 663 for_each_drmem_lmb(lmb) { 664 + if (lmb->flags & DRCONF_MEM_RESERVED) 665 + continue; 666 + 686 667 if (!(lmb->flags & DRCONF_MEM_ASSIGNED)) 687 668 lmbs_available++; 688 669 ··· 714 689 * requested LMBs cannot be added. 715 690 */ 716 691 drmem_mark_lmb_reserved(lmb); 717 - 718 - lmbs_added++; 719 - if (lmbs_added == lmbs_to_add) 692 + lmbs_reserved++; 693 + if (lmbs_reserved == lmbs_to_add) 720 694 break; 721 695 } 722 696 723 - if (lmbs_added != lmbs_to_add) { 697 + if (lmbs_reserved != lmbs_to_add) { 724 698 pr_err("Memory hot-add failed, removing any added LMBs\n"); 725 699 726 700 for_each_drmem_lmb(lmb) { ··· 734 710 dlpar_release_drc(lmb->drc_index); 735 711 736 712 drmem_remove_lmb_reservation(lmb); 713 + lmbs_reserved--; 714 + 715 + if (lmbs_reserved == 0) 716 + break; 737 717 } 738 718 rc = -EINVAL; 739 719 } else { ··· 748 720 pr_debug("Memory at %llx (drc index %x) was hot-added\n", 749 721 lmb->base_addr, lmb->drc_index); 750 722 drmem_remove_lmb_reservation(lmb); 723 + lmbs_reserved--; 724 + 725 + if (lmbs_reserved == 0) 726 + break; 751 727 } 752 728 rc = 0; 753 729 } ··· 796 764 static int dlpar_memory_add_by_ic(u32 lmbs_to_add, u32 drc_index) 797 765 { 798 766 struct drmem_lmb *lmb, *start_lmb, *end_lmb; 799 - int lmbs_available = 0; 800 767 int rc; 801 768 802 769 pr_info("Attempting to hot-add %u LMB(s) at index %x\n", ··· 810 779 811 780 /* Validate that the LMBs in this range are not reserved */ 812 781 for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { 813 - if (lmb->flags & DRCONF_MEM_RESERVED) 814 - break; 815 - 816 - lmbs_available++; 782 + /* Fail immediately if the whole range can't be hot-added */ 783 + if (lmb->flags & DRCONF_MEM_RESERVED) { 784 + pr_err("Memory at %llx (drc index %x) is reserved\n", 785 + lmb->base_addr, lmb->drc_index); 786 + return -EINVAL; 787 + } 817 788 } 818 - 819 - if (lmbs_available < lmbs_to_add) 820 - return -EINVAL; 821 789 822 790 for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { 823 791 if (lmb->flags & DRCONF_MEM_ASSIGNED)
+29
arch/powerpc/platforms/pseries/hvCall.S
··· 108 108 mfcr r0 109 109 stw r0,8(r1) 110 110 HVSC /* invoke the hypervisor */ 111 + 112 + li r4,0 113 + stb r4,PACASRR_VALID(r13) 114 + 111 115 lwz r0,8(r1) 112 116 mtcrf 0xff,r0 113 117 blr /* return r3 = status */ ··· 124 120 HCALL_BRANCH(plpar_hcall_norets_trace) 125 121 HVSC /* invoke the hypervisor */ 126 122 123 + li r4,0 124 + stb r4,PACASRR_VALID(r13) 125 + 127 126 lwz r0,8(r1) 128 127 mtcrf 0xff,r0 129 128 blr /* return r3 = status */ ··· 136 129 HCALL_INST_PRECALL(R4) 137 130 HVSC 138 131 HCALL_INST_POSTCALL_NORETS 132 + 133 + li r4,0 134 + stb r4,PACASRR_VALID(r13) 135 + 139 136 lwz r0,8(r1) 140 137 mtcrf 0xff,r0 141 138 blr ··· 170 159 std r6, 16(r12) 171 160 std r7, 24(r12) 172 161 162 + li r4,0 163 + stb r4,PACASRR_VALID(r13) 164 + 173 165 lwz r0,8(r1) 174 166 mtcrf 0xff,r0 175 167 ··· 201 187 std r7,24(r12) 202 188 203 189 HCALL_INST_POSTCALL(r12) 190 + 191 + li r4,0 192 + stb r4,PACASRR_VALID(r13) 204 193 205 194 lwz r0,8(r1) 206 195 mtcrf 0xff,r0 ··· 239 222 std r5, 8(r12) 240 223 std r6, 16(r12) 241 224 std r7, 24(r12) 225 + 226 + li r4,0 227 + stb r4,PACASRR_VALID(r13) 242 228 243 229 lwz r0,8(r1) 244 230 mtcrf 0xff,r0 ··· 282 262 std r11,56(r12) 283 263 std r0, 64(r12) 284 264 265 + li r4,0 266 + stb r4,PACASRR_VALID(r13) 267 + 285 268 lwz r0,8(r1) 286 269 mtcrf 0xff,r0 287 270 ··· 322 299 std r0,64(r12) 323 300 324 301 HCALL_INST_POSTCALL(r12) 302 + 303 + li r4,0 304 + stb r4,PACASRR_VALID(r13) 325 305 326 306 lwz r0,8(r1) 327 307 mtcrf 0xff,r0 ··· 364 338 std r10,48(r12) 365 339 std r11,56(r12) 366 340 std r0, 64(r12) 341 + 342 + li r4,0 343 + stb r4,PACASRR_VALID(r13) 367 344 368 345 lwz r0,8(r1) 369 346 mtcrf 0xff,r0
+80 -21
arch/powerpc/platforms/pseries/papr_scm.c
··· 18 18 #include <asm/plpar_wrappers.h> 19 19 #include <asm/papr_pdsm.h> 20 20 #include <asm/mce.h> 21 + #include <asm/unaligned.h> 21 22 22 23 #define BIND_ANY_ADDR (~0ul) 23 24 ··· 114 113 115 114 /* Health information for the dimm */ 116 115 u64 health_bitmap; 116 + 117 + /* Holds the last known dirty shutdown counter value */ 118 + u64 dirty_shutdown_counter; 117 119 118 120 /* length of the stat buffer as expected by phyp */ 119 121 size_t stat_buffer_len; ··· 264 260 * Query the Dimm performance stats from PHYP and copy them (if returned) to 265 261 * provided struct papr_scm_perf_stats instance 'stats' that can hold atleast 266 262 * (num_stats + header) bytes. 267 - * - If buff_stats == NULL the return value is the size in byes of the buffer 263 + * - If buff_stats == NULL the return value is the size in bytes of the buffer 268 264 * needed to hold all supported performance-statistics. 269 265 * - If buff_stats != NULL and num_stats == 0 then we copy all known 270 266 * performance-statistics to 'buff_stat' and expect to be large enough to ··· 314 310 dev_err(&p->pdev->dev, 315 311 "Unknown performance stats, Err:0x%016lX\n", ret[0]); 316 312 return -ENOENT; 313 + } else if (rc == H_AUTHORITY) { 314 + dev_info(&p->pdev->dev, 315 + "Permission denied while accessing performance stats"); 316 + return -EPERM; 317 + } else if (rc == H_UNSUPPORTED) { 318 + dev_dbg(&p->pdev->dev, "Performance stats unsupported\n"); 319 + return -EOPNOTSUPP; 317 320 } else if (rc != H_SUCCESS) { 318 321 dev_err(&p->pdev->dev, 319 322 "Failed to query performance stats, Err:%lld\n", rc); ··· 607 596 return rc; 608 597 } 609 598 599 + /* Add the dirty-shutdown-counter value to the pdsm */ 600 + static int papr_pdsm_dsc(struct papr_scm_priv *p, 601 + union nd_pdsm_payload *payload) 602 + { 603 + payload->health.extension_flags |= PDSM_DIMM_DSC_VALID; 604 + payload->health.dimm_dsc = p->dirty_shutdown_counter; 605 + 606 + return sizeof(struct nd_papr_pdsm_health); 607 + } 608 + 610 609 /* Fetch the DIMM health info and populate it in provided package. */ 611 610 static int papr_pdsm_health(struct papr_scm_priv *p, 612 611 union nd_pdsm_payload *payload) ··· 660 639 661 640 /* Populate the fuel gauge meter in the payload */ 662 641 papr_pdsm_fuel_gauge(p, payload); 642 + /* Populate the dirty-shutdown-counter field */ 643 + papr_pdsm_dsc(p, payload); 663 644 664 645 rc = sizeof(struct nd_papr_pdsm_health); 665 646 ··· 923 900 } 924 901 DEVICE_ATTR_RO(flags); 925 902 903 + static ssize_t dirty_shutdown_show(struct device *dev, 904 + struct device_attribute *attr, char *buf) 905 + { 906 + struct nvdimm *dimm = to_nvdimm(dev); 907 + struct papr_scm_priv *p = nvdimm_provider_data(dimm); 908 + 909 + return sysfs_emit(buf, "%llu\n", p->dirty_shutdown_counter); 910 + } 911 + DEVICE_ATTR_RO(dirty_shutdown); 912 + 913 + static umode_t papr_nd_attribute_visible(struct kobject *kobj, 914 + struct attribute *attr, int n) 915 + { 916 + struct device *dev = kobj_to_dev(kobj); 917 + struct nvdimm *nvdimm = to_nvdimm(dev); 918 + struct papr_scm_priv *p = nvdimm_provider_data(nvdimm); 919 + 920 + /* For if perf-stats not available remove perf_stats sysfs */ 921 + if (attr == &dev_attr_perf_stats.attr && p->stat_buffer_len == 0) 922 + return 0; 923 + 924 + return attr->mode; 925 + } 926 + 926 927 /* papr_scm specific dimm attributes */ 927 928 static struct attribute *papr_nd_attributes[] = { 928 929 &dev_attr_flags.attr, 929 930 &dev_attr_perf_stats.attr, 931 + &dev_attr_dirty_shutdown.attr, 930 932 NULL, 931 933 }; 932 934 933 935 static struct attribute_group papr_nd_attribute_group = { 934 936 .name = "papr", 937 + .is_visible = papr_nd_attribute_visible, 935 938 .attrs = papr_nd_attributes, 936 939 }; 937 940 ··· 973 924 struct nd_region_desc ndr_desc; 974 925 unsigned long dimm_flags; 975 926 int target_nid, online_nid; 976 - ssize_t stat_size; 977 927 978 928 p->bus_desc.ndctl = papr_scm_ndctl; 979 929 p->bus_desc.module = THIS_MODULE; ··· 1057 1009 list_add_tail(&p->region_list, &papr_nd_regions); 1058 1010 mutex_unlock(&papr_ndr_lock); 1059 1011 1060 - /* Try retriving the stat buffer and see if its supported */ 1061 - stat_size = drc_pmem_query_stats(p, NULL, 0); 1062 - if (stat_size > 0) { 1063 - p->stat_buffer_len = stat_size; 1064 - dev_dbg(&p->pdev->dev, "Max perf-stat size %lu-bytes\n", 1065 - p->stat_buffer_len); 1066 - } else { 1067 - dev_info(&p->pdev->dev, "Dimm performance stats unavailable\n"); 1068 - } 1069 - 1070 1012 return 0; 1071 1013 1072 1014 err: nvdimm_bus_unregister(p->bus); ··· 1132 1094 u32 drc_index, metadata_size; 1133 1095 u64 blocks, block_size; 1134 1096 struct papr_scm_priv *p; 1097 + u8 uuid_raw[UUID_SIZE]; 1135 1098 const char *uuid_str; 1136 - u64 uuid[2]; 1099 + ssize_t stat_size; 1100 + uuid_t uuid; 1137 1101 int rc; 1138 1102 1139 1103 /* check we have all the required DT properties */ ··· 1177 1137 p->is_volatile = !of_property_read_bool(dn, "ibm,cache-flush-required"); 1178 1138 p->hcall_flush_required = of_property_read_bool(dn, "ibm,hcall-flush-required"); 1179 1139 1140 + if (of_property_read_u64(dn, "ibm,persistence-failed-count", 1141 + &p->dirty_shutdown_counter)) 1142 + p->dirty_shutdown_counter = 0; 1143 + 1180 1144 /* We just need to ensure that set cookies are unique across */ 1181 - uuid_parse(uuid_str, (uuid_t *) uuid); 1145 + uuid_parse(uuid_str, &uuid); 1146 + 1182 1147 /* 1183 - * cookie1 and cookie2 are not really little endian 1184 - * we store a little endian representation of the 1185 - * uuid str so that we can compare this with the label 1186 - * area cookie irrespective of the endian config with which 1187 - * the kernel is built. 1148 + * The cookie1 and cookie2 are not really little endian. 1149 + * We store a raw buffer representation of the 1150 + * uuid string so that we can compare this with the label 1151 + * area cookie irrespective of the endian configuration 1152 + * with which the kernel is built. 1153 + * 1154 + * Historically we stored the cookie in the below format. 1155 + * for a uuid string 72511b67-0b3b-42fd-8d1d-5be3cae8bcaa 1156 + * cookie1 was 0xfd423b0b671b5172 1157 + * cookie2 was 0xaabce8cae35b1d8d 1188 1158 */ 1189 - p->nd_set.cookie1 = cpu_to_le64(uuid[0]); 1190 - p->nd_set.cookie2 = cpu_to_le64(uuid[1]); 1159 + export_uuid(uuid_raw, &uuid); 1160 + p->nd_set.cookie1 = get_unaligned_le64(&uuid_raw[0]); 1161 + p->nd_set.cookie2 = get_unaligned_le64(&uuid_raw[8]); 1191 1162 1192 1163 /* might be zero */ 1193 1164 p->metadata_size = metadata_size; ··· 1222 1171 p->res.end = p->bound_addr + p->blocks * p->block_size - 1; 1223 1172 p->res.name = pdev->name; 1224 1173 p->res.flags = IORESOURCE_MEM; 1174 + 1175 + /* Try retrieving the stat buffer and see if its supported */ 1176 + stat_size = drc_pmem_query_stats(p, NULL, 0); 1177 + if (stat_size > 0) { 1178 + p->stat_buffer_len = stat_size; 1179 + dev_dbg(&p->pdev->dev, "Max perf-stat size %lu-bytes\n", 1180 + p->stat_buffer_len); 1181 + } 1225 1182 1226 1183 rc = papr_scm_nvdimm_init(p); 1227 1184 if (rc)
+2 -4
arch/powerpc/platforms/pseries/ras.c
··· 487 487 if ((be64_to_cpu(regs->msr) & 488 488 (MSR_LE|MSR_RI|MSR_DR|MSR_IR|MSR_ME|MSR_PR| 489 489 MSR_ILE|MSR_HV|MSR_SF)) == (MSR_DR|MSR_SF)) { 490 - regs->nip = be64_to_cpu((__be64)regs->nip); 491 - regs->msr = 0; 490 + regs_set_return_ip(regs, be64_to_cpu((__be64)regs->nip)); 491 + regs_set_return_msr(regs, 0); 492 492 } 493 493 #endif 494 494 ··· 593 593 mce_err.severity = MCE_SEV_SEVERE; 594 594 else if (severity == RTAS_SEVERITY_ERROR) 595 595 mce_err.severity = MCE_SEV_SEVERE; 596 - else if (severity == RTAS_SEVERITY_FATAL) 597 - mce_err.severity = MCE_SEV_FATAL; 598 596 else 599 597 mce_err.severity = MCE_SEV_FATAL; 600 598
+9
arch/powerpc/platforms/pseries/setup.c
··· 549 549 if (!(result->behaviour & H_CPU_BEHAV_L1D_FLUSH_PR)) 550 550 security_ftr_clear(SEC_FTR_L1D_FLUSH_PR); 551 551 552 + if (result->behaviour & H_CPU_BEHAV_NO_L1D_FLUSH_ENTRY) 553 + security_ftr_clear(SEC_FTR_L1D_FLUSH_ENTRY); 554 + 555 + if (result->behaviour & H_CPU_BEHAV_NO_L1D_FLUSH_UACCESS) 556 + security_ftr_clear(SEC_FTR_L1D_FLUSH_UACCESS); 557 + 558 + if (result->behaviour & H_CPU_BEHAV_NO_STF_BARRIER) 559 + security_ftr_clear(SEC_FTR_STF_BARRIER); 560 + 552 561 if (!(result->behaviour & H_CPU_BEHAV_BNDS_CHK_SPEC_BAR)) 553 562 security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR); 554 563 }
+3 -1
arch/powerpc/platforms/pseries/smp.c
··· 211 211 if (!cpu_has_feature(CPU_FTR_SMT)) 212 212 return; 213 213 214 - if (check_kvm_guest()) { 214 + check_kvm_guest(); 215 + 216 + if (is_kvm_guest()) { 215 217 /* 216 218 * KVM emulates doorbells by disabling FSCR[MSGP] so msgsndp 217 219 * faults to the hypervisor which then reads the instruction
+595
arch/powerpc/platforms/pseries/vas.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Copyright 2020-21 IBM Corp. 4 + */ 5 + 6 + #define pr_fmt(fmt) "vas: " fmt 7 + 8 + #include <linux/module.h> 9 + #include <linux/kernel.h> 10 + #include <linux/export.h> 11 + #include <linux/types.h> 12 + #include <linux/delay.h> 13 + #include <linux/slab.h> 14 + #include <linux/interrupt.h> 15 + #include <linux/irqdomain.h> 16 + #include <asm/machdep.h> 17 + #include <asm/hvcall.h> 18 + #include <asm/plpar_wrappers.h> 19 + #include <asm/vas.h> 20 + #include "vas.h" 21 + 22 + #define VAS_INVALID_WIN_ADDRESS 0xFFFFFFFFFFFFFFFFul 23 + #define VAS_DEFAULT_DOMAIN_ID 0xFFFFFFFFFFFFFFFFul 24 + /* The hypervisor allows one credit per window right now */ 25 + #define DEF_WIN_CREDS 1 26 + 27 + static struct vas_all_caps caps_all; 28 + static bool copypaste_feat; 29 + 30 + static struct vas_caps vascaps[VAS_MAX_FEAT_TYPE]; 31 + static DEFINE_MUTEX(vas_pseries_mutex); 32 + 33 + static long hcall_return_busy_check(long rc) 34 + { 35 + /* Check if we are stalled for some time */ 36 + if (H_IS_LONG_BUSY(rc)) { 37 + msleep(get_longbusy_msecs(rc)); 38 + rc = H_BUSY; 39 + } else if (rc == H_BUSY) { 40 + cond_resched(); 41 + } 42 + 43 + return rc; 44 + } 45 + 46 + /* 47 + * Allocate VAS window hcall 48 + */ 49 + static int h_allocate_vas_window(struct pseries_vas_window *win, u64 *domain, 50 + u8 wintype, u16 credits) 51 + { 52 + long retbuf[PLPAR_HCALL9_BUFSIZE] = {0}; 53 + long rc; 54 + 55 + do { 56 + rc = plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, wintype, 57 + credits, domain[0], domain[1], domain[2], 58 + domain[3], domain[4], domain[5]); 59 + 60 + rc = hcall_return_busy_check(rc); 61 + } while (rc == H_BUSY); 62 + 63 + if (rc == H_SUCCESS) { 64 + if (win->win_addr == VAS_INVALID_WIN_ADDRESS) { 65 + pr_err("H_ALLOCATE_VAS_WINDOW: COPY/PASTE is not supported\n"); 66 + return -ENOTSUPP; 67 + } 68 + win->vas_win.winid = retbuf[0]; 69 + win->win_addr = retbuf[1]; 70 + win->complete_irq = retbuf[2]; 71 + win->fault_irq = retbuf[3]; 72 + return 0; 73 + } 74 + 75 + pr_err("H_ALLOCATE_VAS_WINDOW error: %ld, wintype: %u, credits: %u\n", 76 + rc, wintype, credits); 77 + 78 + return -EIO; 79 + } 80 + 81 + /* 82 + * Deallocate VAS window hcall. 83 + */ 84 + static int h_deallocate_vas_window(u64 winid) 85 + { 86 + long rc; 87 + 88 + do { 89 + rc = plpar_hcall_norets(H_DEALLOCATE_VAS_WINDOW, winid); 90 + 91 + rc = hcall_return_busy_check(rc); 92 + } while (rc == H_BUSY); 93 + 94 + if (rc == H_SUCCESS) 95 + return 0; 96 + 97 + pr_err("H_DEALLOCATE_VAS_WINDOW error: %ld, winid: %llu\n", 98 + rc, winid); 99 + return -EIO; 100 + } 101 + 102 + /* 103 + * Modify VAS window. 104 + * After the window is opened with allocate window hcall, configure it 105 + * with flags and LPAR PID before using. 106 + */ 107 + static int h_modify_vas_window(struct pseries_vas_window *win) 108 + { 109 + long rc; 110 + u32 lpid = mfspr(SPRN_PID); 111 + 112 + /* 113 + * AMR value is not supported in Linux VAS implementation. 114 + * The hypervisor ignores it if 0 is passed. 115 + */ 116 + do { 117 + rc = plpar_hcall_norets(H_MODIFY_VAS_WINDOW, 118 + win->vas_win.winid, lpid, 0, 119 + VAS_MOD_WIN_FLAGS, 0); 120 + 121 + rc = hcall_return_busy_check(rc); 122 + } while (rc == H_BUSY); 123 + 124 + if (rc == H_SUCCESS) 125 + return 0; 126 + 127 + pr_err("H_MODIFY_VAS_WINDOW error: %ld, winid %u lpid %u\n", 128 + rc, win->vas_win.winid, lpid); 129 + return -EIO; 130 + } 131 + 132 + /* 133 + * This hcall is used to determine the capabilities from the hypervisor. 134 + * @hcall: H_QUERY_VAS_CAPABILITIES or H_QUERY_NX_CAPABILITIES 135 + * @query_type: If 0 is passed, the hypervisor returns the overall 136 + * capabilities which provides all feature(s) that are 137 + * available. Then query the hypervisor to get the 138 + * corresponding capabilities for the specific feature. 139 + * Example: H_QUERY_VAS_CAPABILITIES provides VAS GZIP QoS 140 + * and VAS GZIP Default capabilities. 141 + * H_QUERY_NX_CAPABILITIES provides NX GZIP 142 + * capabilities. 143 + * @result: Return buffer to save capabilities. 144 + */ 145 + int h_query_vas_capabilities(const u64 hcall, u8 query_type, u64 result) 146 + { 147 + long rc; 148 + 149 + rc = plpar_hcall_norets(hcall, query_type, result); 150 + 151 + if (rc == H_SUCCESS) 152 + return 0; 153 + 154 + pr_err("HCALL(%llx) error %ld, query_type %u, result buffer 0x%llx\n", 155 + hcall, rc, query_type, result); 156 + return -EIO; 157 + } 158 + EXPORT_SYMBOL_GPL(h_query_vas_capabilities); 159 + 160 + /* 161 + * hcall to get fault CRB from the hypervisor. 162 + */ 163 + static int h_get_nx_fault(u32 winid, u64 buffer) 164 + { 165 + long rc; 166 + 167 + rc = plpar_hcall_norets(H_GET_NX_FAULT, winid, buffer); 168 + 169 + if (rc == H_SUCCESS) 170 + return 0; 171 + 172 + pr_err("H_GET_NX_FAULT error: %ld, winid %u, buffer 0x%llx\n", 173 + rc, winid, buffer); 174 + return -EIO; 175 + 176 + } 177 + 178 + /* 179 + * Handle the fault interrupt. 180 + * When the fault interrupt is received for each window, query the 181 + * hypervisor to get the fault CRB on the specific fault. Then 182 + * process the CRB by updating CSB or send signal if the user space 183 + * CSB is invalid. 184 + * Note: The hypervisor forwards an interrupt for each fault request. 185 + * So one fault CRB to process for each H_GET_NX_FAULT hcall. 186 + */ 187 + irqreturn_t pseries_vas_fault_thread_fn(int irq, void *data) 188 + { 189 + struct pseries_vas_window *txwin = data; 190 + struct coprocessor_request_block crb; 191 + struct vas_user_win_ref *tsk_ref; 192 + int rc; 193 + 194 + rc = h_get_nx_fault(txwin->vas_win.winid, (u64)virt_to_phys(&crb)); 195 + if (!rc) { 196 + tsk_ref = &txwin->vas_win.task_ref; 197 + vas_dump_crb(&crb); 198 + vas_update_csb(&crb, tsk_ref); 199 + } 200 + 201 + return IRQ_HANDLED; 202 + } 203 + 204 + /* 205 + * Allocate window and setup IRQ mapping. 206 + */ 207 + static int allocate_setup_window(struct pseries_vas_window *txwin, 208 + u64 *domain, u8 wintype) 209 + { 210 + int rc; 211 + 212 + rc = h_allocate_vas_window(txwin, domain, wintype, DEF_WIN_CREDS); 213 + if (rc) 214 + return rc; 215 + /* 216 + * On PowerVM, the hypervisor setup and forwards the fault 217 + * interrupt per window. So the IRQ setup and fault handling 218 + * will be done for each open window separately. 219 + */ 220 + txwin->fault_virq = irq_create_mapping(NULL, txwin->fault_irq); 221 + if (!txwin->fault_virq) { 222 + pr_err("Failed irq mapping %d\n", txwin->fault_irq); 223 + rc = -EINVAL; 224 + goto out_win; 225 + } 226 + 227 + txwin->name = kasprintf(GFP_KERNEL, "vas-win-%d", 228 + txwin->vas_win.winid); 229 + if (!txwin->name) { 230 + rc = -ENOMEM; 231 + goto out_irq; 232 + } 233 + 234 + rc = request_threaded_irq(txwin->fault_virq, NULL, 235 + pseries_vas_fault_thread_fn, IRQF_ONESHOT, 236 + txwin->name, txwin); 237 + if (rc) { 238 + pr_err("VAS-Window[%d]: Request IRQ(%u) failed with %d\n", 239 + txwin->vas_win.winid, txwin->fault_virq, rc); 240 + goto out_free; 241 + } 242 + 243 + txwin->vas_win.wcreds_max = DEF_WIN_CREDS; 244 + 245 + return 0; 246 + out_free: 247 + kfree(txwin->name); 248 + out_irq: 249 + irq_dispose_mapping(txwin->fault_virq); 250 + out_win: 251 + h_deallocate_vas_window(txwin->vas_win.winid); 252 + return rc; 253 + } 254 + 255 + static inline void free_irq_setup(struct pseries_vas_window *txwin) 256 + { 257 + free_irq(txwin->fault_virq, txwin); 258 + kfree(txwin->name); 259 + irq_dispose_mapping(txwin->fault_virq); 260 + } 261 + 262 + static struct vas_window *vas_allocate_window(int vas_id, u64 flags, 263 + enum vas_cop_type cop_type) 264 + { 265 + long domain[PLPAR_HCALL9_BUFSIZE] = {VAS_DEFAULT_DOMAIN_ID}; 266 + struct vas_cop_feat_caps *cop_feat_caps; 267 + struct vas_caps *caps; 268 + struct pseries_vas_window *txwin; 269 + int rc; 270 + 271 + txwin = kzalloc(sizeof(*txwin), GFP_KERNEL); 272 + if (!txwin) 273 + return ERR_PTR(-ENOMEM); 274 + 275 + /* 276 + * A VAS window can have many credits which means that many 277 + * requests can be issued simultaneously. But the hypervisor 278 + * restricts one credit per window. 279 + * The hypervisor introduces 2 different types of credits: 280 + * Default credit type (Uses normal priority FIFO): 281 + * A limited number of credits are assigned to partitions 282 + * based on processor entitlement. But these credits may be 283 + * over-committed on a system depends on whether the CPUs 284 + * are in shared or dedicated modes - that is, more requests 285 + * may be issued across the system than NX can service at 286 + * once which can result in paste command failure (RMA_busy). 287 + * Then the process has to resend requests or fall-back to 288 + * SW compression. 289 + * Quality of Service (QoS) credit type (Uses high priority FIFO): 290 + * To avoid NX HW contention, the system admins can assign 291 + * QoS credits for each LPAR so that this partition is 292 + * guaranteed access to NX resources. These credits are 293 + * assigned to partitions via the HMC. 294 + * Refer PAPR for more information. 295 + * 296 + * Allocate window with QoS credits if user requested. Otherwise 297 + * default credits are used. 298 + */ 299 + if (flags & VAS_TX_WIN_FLAG_QOS_CREDIT) 300 + caps = &vascaps[VAS_GZIP_QOS_FEAT_TYPE]; 301 + else 302 + caps = &vascaps[VAS_GZIP_DEF_FEAT_TYPE]; 303 + 304 + cop_feat_caps = &caps->caps; 305 + 306 + if (atomic_inc_return(&cop_feat_caps->used_lpar_creds) > 307 + atomic_read(&cop_feat_caps->target_lpar_creds)) { 308 + pr_err("Credits are not available to allocate window\n"); 309 + rc = -EINVAL; 310 + goto out; 311 + } 312 + 313 + if (vas_id == -1) { 314 + /* 315 + * The user space is requesting to allocate a window on 316 + * a VAS instance where the process is executing. 317 + * On PowerVM, domain values are passed to the hypervisor 318 + * to select VAS instance. Useful if the process is 319 + * affinity to NUMA node. 320 + * The hypervisor selects VAS instance if 321 + * VAS_DEFAULT_DOMAIN_ID (-1) is passed for domain values. 322 + * The h_allocate_vas_window hcall is defined to take a 323 + * domain values as specified by h_home_node_associativity, 324 + * So no unpacking needs to be done. 325 + */ 326 + rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, domain, 327 + VPHN_FLAG_VCPU, smp_processor_id()); 328 + if (rc != H_SUCCESS) { 329 + pr_err("H_HOME_NODE_ASSOCIATIVITY error: %d\n", rc); 330 + goto out; 331 + } 332 + } 333 + 334 + /* 335 + * Allocate / Deallocate window hcalls and setup / free IRQs 336 + * have to be protected with mutex. 337 + * Open VAS window: Allocate window hcall and setup IRQ 338 + * Close VAS window: Deallocate window hcall and free IRQ 339 + * The hypervisor waits until all NX requests are 340 + * completed before closing the window. So expects OS 341 + * to handle NX faults, means IRQ can be freed only 342 + * after the deallocate window hcall is returned. 343 + * So once the window is closed with deallocate hcall before 344 + * the IRQ is freed, it can be assigned to new allocate 345 + * hcall with the same fault IRQ by the hypervisor. It can 346 + * result in setup IRQ fail for the new window since the 347 + * same fault IRQ is not freed by the OS before. 348 + */ 349 + mutex_lock(&vas_pseries_mutex); 350 + rc = allocate_setup_window(txwin, (u64 *)&domain[0], 351 + cop_feat_caps->win_type); 352 + mutex_unlock(&vas_pseries_mutex); 353 + if (rc) 354 + goto out; 355 + 356 + /* 357 + * Modify window and it is ready to use. 358 + */ 359 + rc = h_modify_vas_window(txwin); 360 + if (!rc) 361 + rc = get_vas_user_win_ref(&txwin->vas_win.task_ref); 362 + if (rc) 363 + goto out_free; 364 + 365 + vas_user_win_add_mm_context(&txwin->vas_win.task_ref); 366 + txwin->win_type = cop_feat_caps->win_type; 367 + mutex_lock(&vas_pseries_mutex); 368 + list_add(&txwin->win_list, &caps->list); 369 + mutex_unlock(&vas_pseries_mutex); 370 + 371 + return &txwin->vas_win; 372 + 373 + out_free: 374 + /* 375 + * Window is not operational. Free IRQ before closing 376 + * window so that do not have to hold mutex. 377 + */ 378 + free_irq_setup(txwin); 379 + h_deallocate_vas_window(txwin->vas_win.winid); 380 + out: 381 + atomic_dec(&cop_feat_caps->used_lpar_creds); 382 + kfree(txwin); 383 + return ERR_PTR(rc); 384 + } 385 + 386 + static u64 vas_paste_address(struct vas_window *vwin) 387 + { 388 + struct pseries_vas_window *win; 389 + 390 + win = container_of(vwin, struct pseries_vas_window, vas_win); 391 + return win->win_addr; 392 + } 393 + 394 + static int deallocate_free_window(struct pseries_vas_window *win) 395 + { 396 + int rc = 0; 397 + 398 + /* 399 + * The hypervisor waits for all requests including faults 400 + * are processed before closing the window - Means all 401 + * credits have to be returned. In the case of fault 402 + * request, a credit is returned after OS issues 403 + * H_GET_NX_FAULT hcall. 404 + * So free IRQ after executing H_DEALLOCATE_VAS_WINDOW 405 + * hcall. 406 + */ 407 + rc = h_deallocate_vas_window(win->vas_win.winid); 408 + if (!rc) 409 + free_irq_setup(win); 410 + 411 + return rc; 412 + } 413 + 414 + static int vas_deallocate_window(struct vas_window *vwin) 415 + { 416 + struct pseries_vas_window *win; 417 + struct vas_cop_feat_caps *caps; 418 + int rc = 0; 419 + 420 + if (!vwin) 421 + return -EINVAL; 422 + 423 + win = container_of(vwin, struct pseries_vas_window, vas_win); 424 + 425 + /* Should not happen */ 426 + if (win->win_type >= VAS_MAX_FEAT_TYPE) { 427 + pr_err("Window (%u): Invalid window type %u\n", 428 + vwin->winid, win->win_type); 429 + return -EINVAL; 430 + } 431 + 432 + caps = &vascaps[win->win_type].caps; 433 + mutex_lock(&vas_pseries_mutex); 434 + rc = deallocate_free_window(win); 435 + if (rc) { 436 + mutex_unlock(&vas_pseries_mutex); 437 + return rc; 438 + } 439 + 440 + list_del(&win->win_list); 441 + atomic_dec(&caps->used_lpar_creds); 442 + mutex_unlock(&vas_pseries_mutex); 443 + 444 + put_vas_user_win_ref(&vwin->task_ref); 445 + mm_context_remove_vas_window(vwin->task_ref.mm); 446 + 447 + kfree(win); 448 + return 0; 449 + } 450 + 451 + static const struct vas_user_win_ops vops_pseries = { 452 + .open_win = vas_allocate_window, /* Open and configure window */ 453 + .paste_addr = vas_paste_address, /* To do copy/paste */ 454 + .close_win = vas_deallocate_window, /* Close window */ 455 + }; 456 + 457 + /* 458 + * Supporting only nx-gzip coprocessor type now, but this API code 459 + * extended to other coprocessor types later. 460 + */ 461 + int vas_register_api_pseries(struct module *mod, enum vas_cop_type cop_type, 462 + const char *name) 463 + { 464 + int rc; 465 + 466 + if (!copypaste_feat) 467 + return -ENOTSUPP; 468 + 469 + rc = vas_register_coproc_api(mod, cop_type, name, &vops_pseries); 470 + 471 + return rc; 472 + } 473 + EXPORT_SYMBOL_GPL(vas_register_api_pseries); 474 + 475 + void vas_unregister_api_pseries(void) 476 + { 477 + vas_unregister_coproc_api(); 478 + } 479 + EXPORT_SYMBOL_GPL(vas_unregister_api_pseries); 480 + 481 + /* 482 + * Get the specific capabilities based on the feature type. 483 + * Right now supports GZIP default and GZIP QoS capabilities. 484 + */ 485 + static int get_vas_capabilities(u8 feat, enum vas_cop_feat_type type, 486 + struct hv_vas_cop_feat_caps *hv_caps) 487 + { 488 + struct vas_cop_feat_caps *caps; 489 + struct vas_caps *vcaps; 490 + int rc = 0; 491 + 492 + vcaps = &vascaps[type]; 493 + memset(vcaps, 0, sizeof(*vcaps)); 494 + INIT_LIST_HEAD(&vcaps->list); 495 + 496 + caps = &vcaps->caps; 497 + 498 + rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, feat, 499 + (u64)virt_to_phys(hv_caps)); 500 + if (rc) 501 + return rc; 502 + 503 + caps->user_mode = hv_caps->user_mode; 504 + if (!(caps->user_mode & VAS_COPY_PASTE_USER_MODE)) { 505 + pr_err("User space COPY/PASTE is not supported\n"); 506 + return -ENOTSUPP; 507 + } 508 + 509 + caps->descriptor = be64_to_cpu(hv_caps->descriptor); 510 + caps->win_type = hv_caps->win_type; 511 + if (caps->win_type >= VAS_MAX_FEAT_TYPE) { 512 + pr_err("Unsupported window type %u\n", caps->win_type); 513 + return -EINVAL; 514 + } 515 + caps->max_lpar_creds = be16_to_cpu(hv_caps->max_lpar_creds); 516 + caps->max_win_creds = be16_to_cpu(hv_caps->max_win_creds); 517 + atomic_set(&caps->target_lpar_creds, 518 + be16_to_cpu(hv_caps->target_lpar_creds)); 519 + if (feat == VAS_GZIP_DEF_FEAT) { 520 + caps->def_lpar_creds = be16_to_cpu(hv_caps->def_lpar_creds); 521 + 522 + if (caps->max_win_creds < DEF_WIN_CREDS) { 523 + pr_err("Window creds(%u) > max allowed window creds(%u)\n", 524 + DEF_WIN_CREDS, caps->max_win_creds); 525 + return -EINVAL; 526 + } 527 + } 528 + 529 + copypaste_feat = true; 530 + 531 + return 0; 532 + } 533 + 534 + static int __init pseries_vas_init(void) 535 + { 536 + struct hv_vas_cop_feat_caps *hv_cop_caps; 537 + struct hv_vas_all_caps *hv_caps; 538 + int rc; 539 + 540 + /* 541 + * Linux supports user space COPY/PASTE only with Radix 542 + */ 543 + if (!radix_enabled()) { 544 + pr_err("API is supported only with radix page tables\n"); 545 + return -ENOTSUPP; 546 + } 547 + 548 + hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL); 549 + if (!hv_caps) 550 + return -ENOMEM; 551 + /* 552 + * Get VAS overall capabilities by passing 0 to feature type. 553 + */ 554 + rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, 0, 555 + (u64)virt_to_phys(hv_caps)); 556 + if (rc) 557 + goto out; 558 + 559 + caps_all.descriptor = be64_to_cpu(hv_caps->descriptor); 560 + caps_all.feat_type = be64_to_cpu(hv_caps->feat_type); 561 + 562 + hv_cop_caps = kmalloc(sizeof(*hv_cop_caps), GFP_KERNEL); 563 + if (!hv_cop_caps) { 564 + rc = -ENOMEM; 565 + goto out; 566 + } 567 + /* 568 + * QOS capabilities available 569 + */ 570 + if (caps_all.feat_type & VAS_GZIP_QOS_FEAT_BIT) { 571 + rc = get_vas_capabilities(VAS_GZIP_QOS_FEAT, 572 + VAS_GZIP_QOS_FEAT_TYPE, hv_cop_caps); 573 + 574 + if (rc) 575 + goto out_cop; 576 + } 577 + /* 578 + * Default capabilities available 579 + */ 580 + if (caps_all.feat_type & VAS_GZIP_DEF_FEAT_BIT) { 581 + rc = get_vas_capabilities(VAS_GZIP_DEF_FEAT, 582 + VAS_GZIP_DEF_FEAT_TYPE, hv_cop_caps); 583 + if (rc) 584 + goto out_cop; 585 + } 586 + 587 + pr_info("GZIP feature is available\n"); 588 + 589 + out_cop: 590 + kfree(hv_cop_caps); 591 + out: 592 + kfree(hv_caps); 593 + return rc; 594 + } 595 + machine_device_initcall(pseries, pseries_vas_init);
+125
arch/powerpc/platforms/pseries/vas.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* 3 + * Copyright 2020-21 IBM Corp. 4 + */ 5 + 6 + #ifndef _VAS_H 7 + #define _VAS_H 8 + #include <asm/vas.h> 9 + #include <linux/mutex.h> 10 + #include <linux/stringify.h> 11 + 12 + /* 13 + * VAS window modify flags 14 + */ 15 + #define VAS_MOD_WIN_CLOSE PPC_BIT(0) 16 + #define VAS_MOD_WIN_JOBS_KILL PPC_BIT(1) 17 + #define VAS_MOD_WIN_DR PPC_BIT(3) 18 + #define VAS_MOD_WIN_PR PPC_BIT(4) 19 + #define VAS_MOD_WIN_SF PPC_BIT(5) 20 + #define VAS_MOD_WIN_TA PPC_BIT(6) 21 + #define VAS_MOD_WIN_FLAGS (VAS_MOD_WIN_JOBS_KILL | VAS_MOD_WIN_DR | \ 22 + VAS_MOD_WIN_PR | VAS_MOD_WIN_SF) 23 + 24 + #define VAS_WIN_ACTIVE 0x0 25 + #define VAS_WIN_CLOSED 0x1 26 + #define VAS_WIN_INACTIVE 0x2 /* Inactive due to HW failure */ 27 + /* Process of being modified, deallocated, or quiesced */ 28 + #define VAS_WIN_MOD_IN_PROCESS 0x3 29 + 30 + #define VAS_COPY_PASTE_USER_MODE 0x00000001 31 + #define VAS_COP_OP_USER_MODE 0x00000010 32 + 33 + /* 34 + * Co-processor feature - GZIP QoS windows or GZIP default windows 35 + */ 36 + enum vas_cop_feat_type { 37 + VAS_GZIP_QOS_FEAT_TYPE, 38 + VAS_GZIP_DEF_FEAT_TYPE, 39 + VAS_MAX_FEAT_TYPE, 40 + }; 41 + 42 + /* 43 + * Use to get feature specific capabilities from the 44 + * hypervisor. 45 + */ 46 + struct hv_vas_cop_feat_caps { 47 + __be64 descriptor; 48 + u8 win_type; /* Default or QoS type */ 49 + u8 user_mode; 50 + __be16 max_lpar_creds; 51 + __be16 max_win_creds; 52 + union { 53 + __be16 reserved; 54 + __be16 def_lpar_creds; /* Used for default capabilities */ 55 + }; 56 + __be16 target_lpar_creds; 57 + } __packed __aligned(0x1000); 58 + 59 + /* 60 + * Feature specific (QoS or default) capabilities. 61 + */ 62 + struct vas_cop_feat_caps { 63 + u64 descriptor; 64 + u8 win_type; /* Default or QoS type */ 65 + u8 user_mode; /* User mode copy/paste or COP HCALL */ 66 + u16 max_lpar_creds; /* Max credits available in LPAR */ 67 + /* Max credits can be assigned per window */ 68 + u16 max_win_creds; 69 + union { 70 + u16 reserved; /* Used for QoS credit type */ 71 + u16 def_lpar_creds; /* Used for default credit type */ 72 + }; 73 + /* Total LPAR available credits. Can be different from max LPAR */ 74 + /* credits due to DLPAR operation */ 75 + atomic_t target_lpar_creds; 76 + atomic_t used_lpar_creds; /* Used credits so far */ 77 + u16 avail_lpar_creds; /* Remaining available credits */ 78 + }; 79 + 80 + /* 81 + * Feature (QoS or Default) specific to store capabilities and 82 + * the list of open windows. 83 + */ 84 + struct vas_caps { 85 + struct vas_cop_feat_caps caps; 86 + struct list_head list; /* List of open windows */ 87 + }; 88 + 89 + /* 90 + * To get window information from the hypervisor. 91 + */ 92 + struct hv_vas_win_lpar { 93 + __be16 version; 94 + u8 win_type; 95 + u8 status; 96 + __be16 credits; /* No of credits assigned to this window */ 97 + __be16 reserved; 98 + __be32 pid; /* LPAR Process ID */ 99 + __be32 tid; /* LPAR Thread ID */ 100 + __be64 win_addr; /* Paste address */ 101 + __be32 interrupt; /* Interrupt when NX request completes */ 102 + __be32 fault; /* Interrupt when NX sees fault */ 103 + /* Associativity Domain Identifiers as returned in */ 104 + /* H_HOME_NODE_ASSOCIATIVITY */ 105 + __be64 domain[6]; 106 + __be64 win_util; /* Number of bytes processed */ 107 + } __packed __aligned(0x1000); 108 + 109 + struct pseries_vas_window { 110 + struct vas_window vas_win; 111 + u64 win_addr; /* Physical paste address */ 112 + u8 win_type; /* QoS or Default window */ 113 + u32 complete_irq; /* Completion interrupt */ 114 + u32 fault_irq; /* Fault interrupt */ 115 + u64 domain[6]; /* Associativity domain Ids */ 116 + /* this window is allocated */ 117 + u64 util; 118 + 119 + /* List of windows opened which is used for LPM */ 120 + struct list_head win_list; 121 + u64 flags; 122 + char *name; 123 + int fault_virq; 124 + }; 125 + #endif /* _VAS_H */
+1 -1
arch/powerpc/sysdev/fsl_pci.c
··· 1072 1072 ret = get_kernel_nofault(inst, (void *)regs->nip); 1073 1073 1074 1074 if (!ret && mcheck_handle_load(regs, inst)) { 1075 - regs->nip += 4; 1075 + regs_add_return_ip(regs, 4); 1076 1076 return 1; 1077 1077 } 1078 1078 }
+2 -2
arch/powerpc/sysdev/fsl_rio.c
··· 108 108 __func__); 109 109 out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR), 110 110 0); 111 - regs->msr |= MSR_RI; 112 - regs->nip = extable_fixup(entry); 111 + regs_set_return_msr(regs, regs->msr | MSR_RI); 112 + regs_set_return_ip(regs, extable_fixup(entry)); 113 113 return 1; 114 114 } 115 115 }
+3
arch/powerpc/sysdev/xics/Kconfig
··· 12 12 13 13 config PPC_ICS_RTAS 14 14 def_bool n 15 + 16 + config PPC_ICS_NATIVE 17 + def_bool n
+1
arch/powerpc/sysdev/xics/Makefile
··· 4 4 obj-$(CONFIG_PPC_ICP_NATIVE) += icp-native.o 5 5 obj-$(CONFIG_PPC_ICP_HV) += icp-hv.o 6 6 obj-$(CONFIG_PPC_ICS_RTAS) += ics-rtas.o 7 + obj-$(CONFIG_PPC_ICS_NATIVE) += ics-native.o 7 8 obj-$(CONFIG_PPC_POWERNV) += ics-opal.o icp-opal.o
+257
arch/powerpc/sysdev/xics/ics-native.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * ICS backend for OPAL managed interrupts. 4 + * 5 + * Copyright 2011 IBM Corp. 6 + */ 7 + 8 + //#define DEBUG 9 + 10 + #include <linux/types.h> 11 + #include <linux/kernel.h> 12 + #include <linux/irq.h> 13 + #include <linux/smp.h> 14 + #include <linux/interrupt.h> 15 + #include <linux/init.h> 16 + #include <linux/cpu.h> 17 + #include <linux/of.h> 18 + #include <linux/spinlock.h> 19 + #include <linux/msi.h> 20 + #include <linux/list.h> 21 + 22 + #include <asm/prom.h> 23 + #include <asm/smp.h> 24 + #include <asm/machdep.h> 25 + #include <asm/irq.h> 26 + #include <asm/errno.h> 27 + #include <asm/xics.h> 28 + #include <asm/opal.h> 29 + #include <asm/firmware.h> 30 + 31 + struct ics_native { 32 + struct ics ics; 33 + struct device_node *node; 34 + void __iomem *base; 35 + u32 ibase; 36 + u32 icount; 37 + }; 38 + #define to_ics_native(_ics) container_of(_ics, struct ics_native, ics) 39 + 40 + static void __iomem *ics_native_xive(struct ics_native *in, unsigned int vec) 41 + { 42 + return in->base + 0x800 + ((vec - in->ibase) << 2); 43 + } 44 + 45 + static void ics_native_unmask_irq(struct irq_data *d) 46 + { 47 + unsigned int vec = (unsigned int)irqd_to_hwirq(d); 48 + struct ics *ics = irq_data_get_irq_chip_data(d); 49 + struct ics_native *in = to_ics_native(ics); 50 + unsigned int server; 51 + 52 + pr_devel("ics-native: unmask virq %d [hw 0x%x]\n", d->irq, vec); 53 + 54 + if (vec < in->ibase || vec >= (in->ibase + in->icount)) 55 + return; 56 + 57 + server = xics_get_irq_server(d->irq, irq_data_get_affinity_mask(d), 0); 58 + out_be32(ics_native_xive(in, vec), (server << 8) | DEFAULT_PRIORITY); 59 + } 60 + 61 + static unsigned int ics_native_startup(struct irq_data *d) 62 + { 63 + #ifdef CONFIG_PCI_MSI 64 + /* 65 + * The generic MSI code returns with the interrupt disabled on the 66 + * card, using the MSI mask bits. Firmware doesn't appear to unmask 67 + * at that level, so we do it here by hand. 68 + */ 69 + if (irq_data_get_msi_desc(d)) 70 + pci_msi_unmask_irq(d); 71 + #endif 72 + 73 + /* unmask it */ 74 + ics_native_unmask_irq(d); 75 + return 0; 76 + } 77 + 78 + static void ics_native_do_mask(struct ics_native *in, unsigned int vec) 79 + { 80 + out_be32(ics_native_xive(in, vec), 0xff); 81 + } 82 + 83 + static void ics_native_mask_irq(struct irq_data *d) 84 + { 85 + unsigned int vec = (unsigned int)irqd_to_hwirq(d); 86 + struct ics *ics = irq_data_get_irq_chip_data(d); 87 + struct ics_native *in = to_ics_native(ics); 88 + 89 + pr_devel("ics-native: mask virq %d [hw 0x%x]\n", d->irq, vec); 90 + 91 + if (vec < in->ibase || vec >= (in->ibase + in->icount)) 92 + return; 93 + ics_native_do_mask(in, vec); 94 + } 95 + 96 + static int ics_native_set_affinity(struct irq_data *d, 97 + const struct cpumask *cpumask, 98 + bool force) 99 + { 100 + unsigned int vec = (unsigned int)irqd_to_hwirq(d); 101 + struct ics *ics = irq_data_get_irq_chip_data(d); 102 + struct ics_native *in = to_ics_native(ics); 103 + int server; 104 + u32 xive; 105 + 106 + if (vec < in->ibase || vec >= (in->ibase + in->icount)) 107 + return -EINVAL; 108 + 109 + server = xics_get_irq_server(d->irq, cpumask, 1); 110 + if (server == -1) { 111 + pr_warn("%s: No online cpus in the mask %*pb for irq %d\n", 112 + __func__, cpumask_pr_args(cpumask), d->irq); 113 + return -1; 114 + } 115 + 116 + xive = in_be32(ics_native_xive(in, vec)); 117 + xive = (xive & 0xff) | (server << 8); 118 + out_be32(ics_native_xive(in, vec), xive); 119 + 120 + return IRQ_SET_MASK_OK; 121 + } 122 + 123 + static struct irq_chip ics_native_irq_chip = { 124 + .name = "ICS", 125 + .irq_startup = ics_native_startup, 126 + .irq_mask = ics_native_mask_irq, 127 + .irq_unmask = ics_native_unmask_irq, 128 + .irq_eoi = NULL, /* Patched at init time */ 129 + .irq_set_affinity = ics_native_set_affinity, 130 + .irq_set_type = xics_set_irq_type, 131 + .irq_retrigger = xics_retrigger, 132 + }; 133 + 134 + static int ics_native_map(struct ics *ics, unsigned int virq) 135 + { 136 + unsigned int vec = (unsigned int)virq_to_hw(virq); 137 + struct ics_native *in = to_ics_native(ics); 138 + 139 + pr_devel("%s: vec=0x%x\n", __func__, vec); 140 + 141 + if (vec < in->ibase || vec >= (in->ibase + in->icount)) 142 + return -EINVAL; 143 + 144 + irq_set_chip_and_handler(virq, &ics_native_irq_chip, handle_fasteoi_irq); 145 + irq_set_chip_data(virq, ics); 146 + 147 + return 0; 148 + } 149 + 150 + static void ics_native_mask_unknown(struct ics *ics, unsigned long vec) 151 + { 152 + struct ics_native *in = to_ics_native(ics); 153 + 154 + if (vec < in->ibase || vec >= (in->ibase + in->icount)) 155 + return; 156 + 157 + ics_native_do_mask(in, vec); 158 + } 159 + 160 + static long ics_native_get_server(struct ics *ics, unsigned long vec) 161 + { 162 + struct ics_native *in = to_ics_native(ics); 163 + u32 xive; 164 + 165 + if (vec < in->ibase || vec >= (in->ibase + in->icount)) 166 + return -EINVAL; 167 + 168 + xive = in_be32(ics_native_xive(in, vec)); 169 + return (xive >> 8) & 0xfff; 170 + } 171 + 172 + static int ics_native_host_match(struct ics *ics, struct device_node *node) 173 + { 174 + struct ics_native *in = to_ics_native(ics); 175 + 176 + return in->node == node; 177 + } 178 + 179 + static struct ics ics_native_template = { 180 + .map = ics_native_map, 181 + .mask_unknown = ics_native_mask_unknown, 182 + .get_server = ics_native_get_server, 183 + .host_match = ics_native_host_match, 184 + }; 185 + 186 + static int __init ics_native_add_one(struct device_node *np) 187 + { 188 + struct ics_native *ics; 189 + u32 ranges[2]; 190 + int rc, count; 191 + 192 + ics = kzalloc(sizeof(struct ics_native), GFP_KERNEL); 193 + if (!ics) 194 + return -ENOMEM; 195 + ics->node = of_node_get(np); 196 + memcpy(&ics->ics, &ics_native_template, sizeof(struct ics)); 197 + 198 + ics->base = of_iomap(np, 0); 199 + if (!ics->base) { 200 + pr_err("Failed to map %pOFP\n", np); 201 + rc = -ENOMEM; 202 + goto fail; 203 + } 204 + 205 + count = of_property_count_u32_elems(np, "interrupt-ranges"); 206 + if (count < 2 || count & 1) { 207 + pr_err("Failed to read interrupt-ranges of %pOFP\n", np); 208 + rc = -EINVAL; 209 + goto fail; 210 + } 211 + if (count > 2) { 212 + pr_warn("ICS %pOFP has %d ranges, only one supported\n", 213 + np, count >> 1); 214 + } 215 + rc = of_property_read_u32_array(np, "interrupt-ranges", 216 + ranges, 2); 217 + if (rc) { 218 + pr_err("Failed to read interrupt-ranges of %pOFP\n", np); 219 + goto fail; 220 + } 221 + ics->ibase = ranges[0]; 222 + ics->icount = ranges[1]; 223 + 224 + pr_info("ICS native initialized for sources %d..%d\n", 225 + ics->ibase, ics->ibase + ics->icount - 1); 226 + 227 + /* Register ourselves */ 228 + xics_register_ics(&ics->ics); 229 + 230 + return 0; 231 + fail: 232 + of_node_put(ics->node); 233 + kfree(ics); 234 + return rc; 235 + } 236 + 237 + int __init ics_native_init(void) 238 + { 239 + struct device_node *ics; 240 + bool found_one = false; 241 + 242 + /* We need to patch our irq chip's EOI to point to the 243 + * right ICP 244 + */ 245 + ics_native_irq_chip.irq_eoi = icp_ops->eoi; 246 + 247 + /* Find native ICS in the device-tree */ 248 + for_each_compatible_node(ics, NULL, "openpower,xics-sources") { 249 + if (ics_native_add_one(ics) == 0) 250 + found_one = true; 251 + } 252 + 253 + if (found_one) 254 + pr_info("ICS native backend registered\n"); 255 + 256 + return found_one ? 0 : -ENODEV; 257 + }
+2
arch/powerpc/sysdev/xics/xics-common.c
··· 477 477 if (rc < 0) 478 478 rc = ics_opal_init(); 479 479 if (rc < 0) 480 + rc = ics_native_init(); 481 + if (rc < 0) 480 482 pr_warn("XICS: Cannot find a Source Controller !\n"); 481 483 482 484 /* Initialize common bits */
+152 -48
arch/powerpc/xmon/xmon.c
··· 70 70 static unsigned long xmon_taken = 1; 71 71 static int xmon_owner; 72 72 static int xmon_gate; 73 + static int xmon_batch; 74 + static unsigned long xmon_batch_start_cpu; 75 + static cpumask_t xmon_batch_cpus = CPU_MASK_NONE; 73 76 #else 74 77 #define xmon_owner 0 75 78 #endif /* CONFIG_SMP */ ··· 103 100 /* Breakpoint stuff */ 104 101 struct bpt { 105 102 unsigned long address; 106 - struct ppc_inst *instr; 103 + u32 *instr; 107 104 atomic_t ref_count; 108 105 int enabled; 109 106 unsigned long pad; ··· 135 132 static void prdump(unsigned long, long); 136 133 static int ppc_inst_dump(unsigned long, long, int); 137 134 static void dump_log_buf(void); 135 + 136 + #ifdef CONFIG_SMP 137 + static int xmon_switch_cpu(unsigned long); 138 + static int xmon_batch_next_cpu(void); 139 + static int batch_cmds(struct pt_regs *); 140 + #endif 138 141 139 142 #ifdef CONFIG_PPC_POWERNV 140 143 static void dump_opal_msglog(void); ··· 225 216 #ifdef CONFIG_SMP 226 217 "\ 227 218 c print cpus stopped in xmon\n\ 228 - c# try to switch to cpu number h (in hex)\n" 219 + c# try to switch to cpu number h (in hex)\n\ 220 + c# $ run command '$' (one of 'r','S' or 't') on all cpus in xmon\n" 229 221 #endif 230 222 "\ 231 223 C checksum\n\ ··· 499 489 touch_nmi_watchdog(); 500 490 } 501 491 502 - static int xmon_core(struct pt_regs *regs, int fromipi) 492 + static int xmon_core(struct pt_regs *regs, volatile int fromipi) 503 493 { 504 - int cmd = 0; 505 - struct bpt *bp; 494 + volatile int cmd = 0; 495 + struct bpt *volatile bp; 506 496 long recurse_jmp[JMP_BUF_LEN]; 507 497 bool locked_down; 508 498 unsigned long offset; ··· 524 514 525 515 bp = in_breakpoint_table(regs->nip, &offset); 526 516 if (bp != NULL) { 527 - regs->nip = bp->address + offset; 517 + regs_set_return_ip(regs, bp->address + offset); 528 518 atomic_dec(&bp->ref_count); 529 519 } 530 520 ··· 654 644 spin_cpu_relax(); 655 645 touch_nmi_watchdog(); 656 646 } else { 657 - if (!locked_down) 647 + cmd = 1; 648 + #ifdef CONFIG_SMP 649 + if (xmon_batch) 650 + cmd = batch_cmds(regs); 651 + #endif 652 + if (!locked_down && cmd) 658 653 cmd = cmds(regs); 659 654 if (locked_down || cmd != 0) { 660 655 /* exiting xmon */ ··· 717 702 if (regs->msr & MSR_DE) { 718 703 bp = at_breakpoint(regs->nip); 719 704 if (bp != NULL) { 720 - regs->nip = (unsigned long) &bp->instr[0]; 705 + regs_set_return_ip(regs, (unsigned long) &bp->instr[0]); 721 706 atomic_inc(&bp->ref_count); 722 707 } 723 708 } ··· 727 712 if (bp != NULL) { 728 713 int stepped = emulate_step(regs, ppc_inst_read(bp->instr)); 729 714 if (stepped == 0) { 730 - regs->nip = (unsigned long) &bp->instr[0]; 715 + regs_set_return_ip(regs, (unsigned long) &bp->instr[0]); 731 716 atomic_inc(&bp->ref_count); 732 717 } else if (stepped < 0) { 733 718 printf("Couldn't single-step %s instruction\n", ··· 781 766 /* Are we at the trap at bp->instr[1] for some bp? */ 782 767 bp = in_breakpoint_table(regs->nip, &offset); 783 768 if (bp != NULL && (offset == 4 || offset == 8)) { 784 - regs->nip = bp->address + offset; 769 + regs_set_return_ip(regs, bp->address + offset); 785 770 atomic_dec(&bp->ref_count); 786 771 return 1; 787 772 } ··· 851 836 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT)) { 852 837 bp = in_breakpoint_table(regs->nip, &offset); 853 838 if (bp != NULL) { 854 - regs->nip = bp->address + offset; 839 + regs_set_return_ip(regs, bp->address + offset); 855 840 atomic_dec(&bp->ref_count); 856 841 } 857 842 } ··· 872 857 static struct bpt *at_breakpoint(unsigned long pc) 873 858 { 874 859 int i; 875 - struct bpt *bp; 860 + struct bpt *volatile bp; 876 861 877 862 bp = bpts; 878 863 for (i = 0; i < NBPTS; ++i, ++bp) ··· 961 946 } 962 947 963 948 patch_instruction(bp->instr, instr); 964 - patch_instruction(ppc_inst_next(bp->instr, &instr), 949 + patch_instruction(ppc_inst_next(bp->instr, bp->instr), 965 950 ppc_inst(bpinstr)); 966 951 if (bp->enabled & BP_CIABR) 967 952 continue; 968 - if (patch_instruction((struct ppc_inst *)bp->address, 953 + if (patch_instruction((u32 *)bp->address, 969 954 ppc_inst(bpinstr)) != 0) { 970 955 printf("Couldn't write instruction at %lx, " 971 956 "disabling breakpoint there\n", bp->address); ··· 1007 992 if (mread_instr(bp->address, &instr) 1008 993 && ppc_inst_equal(instr, ppc_inst(bpinstr)) 1009 994 && patch_instruction( 1010 - (struct ppc_inst *)bp->address, ppc_inst_read(bp->instr)) != 0) 995 + (u32 *)bp->address, ppc_inst_read(bp->instr)) != 0) 1011 996 printf("Couldn't remove breakpoint at %lx\n", 1012 997 bp->address); 1013 998 } ··· 1203 1188 #ifdef CONFIG_BOOKE 1204 1189 static int do_step(struct pt_regs *regs) 1205 1190 { 1206 - regs->msr |= MSR_DE; 1191 + regs_set_return_msr(regs, regs->msr | MSR_DE); 1207 1192 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM); 1208 1193 return 1; 1209 1194 } ··· 1236 1221 } 1237 1222 } 1238 1223 } 1239 - regs->msr |= MSR_SE; 1224 + regs_set_return_msr(regs, regs->msr | MSR_SE); 1240 1225 return 1; 1241 1226 } 1242 1227 #endif ··· 1258 1243 } 1259 1244 } 1260 1245 1246 + #ifdef CONFIG_SMP 1247 + static int xmon_switch_cpu(unsigned long cpu) 1248 + { 1249 + int timeout; 1250 + 1251 + xmon_taken = 0; 1252 + mb(); 1253 + xmon_owner = cpu; 1254 + timeout = 10000000; 1255 + while (!xmon_taken) { 1256 + if (--timeout == 0) { 1257 + if (test_and_set_bit(0, &xmon_taken)) 1258 + break; 1259 + /* take control back */ 1260 + mb(); 1261 + xmon_owner = smp_processor_id(); 1262 + printf("cpu 0x%lx didn't take control\n", cpu); 1263 + return 0; 1264 + } 1265 + barrier(); 1266 + } 1267 + return 1; 1268 + } 1269 + 1270 + static int xmon_batch_next_cpu(void) 1271 + { 1272 + unsigned long cpu; 1273 + 1274 + while (!cpumask_empty(&xmon_batch_cpus)) { 1275 + cpu = cpumask_next_wrap(smp_processor_id(), &xmon_batch_cpus, 1276 + xmon_batch_start_cpu, true); 1277 + if (cpu == nr_cpumask_bits) 1278 + break; 1279 + if (xmon_batch_start_cpu == -1) 1280 + xmon_batch_start_cpu = cpu; 1281 + if (xmon_switch_cpu(cpu)) 1282 + return 0; 1283 + cpumask_clear_cpu(cpu, &xmon_batch_cpus); 1284 + } 1285 + 1286 + xmon_batch = 0; 1287 + printf("%x:mon> \n", smp_processor_id()); 1288 + return 1; 1289 + } 1290 + 1291 + static int batch_cmds(struct pt_regs *excp) 1292 + { 1293 + int cmd; 1294 + 1295 + /* simulate command entry */ 1296 + cmd = xmon_batch; 1297 + termch = '\n'; 1298 + 1299 + last_cmd = NULL; 1300 + xmon_regs = excp; 1301 + 1302 + printf("%x:", smp_processor_id()); 1303 + printf("mon> "); 1304 + printf("%c\n", (char)cmd); 1305 + 1306 + switch (cmd) { 1307 + case 'r': 1308 + prregs(excp); /* print regs */ 1309 + break; 1310 + case 'S': 1311 + super_regs(); 1312 + break; 1313 + case 't': 1314 + backtrace(excp); 1315 + break; 1316 + } 1317 + 1318 + cpumask_clear_cpu(smp_processor_id(), &xmon_batch_cpus); 1319 + 1320 + return xmon_batch_next_cpu(); 1321 + } 1322 + 1261 1323 static int cpu_cmd(void) 1262 1324 { 1263 - #ifdef CONFIG_SMP 1264 1325 unsigned long cpu, first_cpu, last_cpu; 1265 - int timeout; 1326 + 1327 + cpu = skipbl(); 1328 + if (cpu == '#') { 1329 + xmon_batch = skipbl(); 1330 + if (xmon_batch) { 1331 + switch (xmon_batch) { 1332 + case 'r': 1333 + case 'S': 1334 + case 't': 1335 + cpumask_copy(&xmon_batch_cpus, &cpus_in_xmon); 1336 + if (cpumask_weight(&xmon_batch_cpus) <= 1) { 1337 + printf("There are no other cpus in xmon\n"); 1338 + break; 1339 + } 1340 + xmon_batch_start_cpu = -1; 1341 + if (!xmon_batch_next_cpu()) 1342 + return 1; 1343 + break; 1344 + default: 1345 + printf("c# only supports 'r', 'S' and 't' commands\n"); 1346 + } 1347 + xmon_batch = 0; 1348 + return 0; 1349 + } 1350 + } 1351 + termch = cpu; 1266 1352 1267 1353 if (!scanhex(&cpu)) { 1268 1354 /* print cpus waiting or in xmon */ ··· 1395 1279 #endif 1396 1280 return 0; 1397 1281 } 1398 - xmon_taken = 0; 1399 - mb(); 1400 - xmon_owner = cpu; 1401 - timeout = 10000000; 1402 - while (!xmon_taken) { 1403 - if (--timeout == 0) { 1404 - if (test_and_set_bit(0, &xmon_taken)) 1405 - break; 1406 - /* take control back */ 1407 - mb(); 1408 - xmon_owner = smp_processor_id(); 1409 - printf("cpu 0x%lx didn't take control\n", cpu); 1410 - return 0; 1411 - } 1412 - barrier(); 1413 - } 1414 - return 1; 1415 - #else 1416 - return 0; 1417 - #endif /* CONFIG_SMP */ 1282 + 1283 + return xmon_switch_cpu(cpu); 1418 1284 } 1285 + #else 1286 + static int cpu_cmd(void) 1287 + { 1288 + return 0; 1289 + } 1290 + #endif /* CONFIG_SMP */ 1419 1291 1420 1292 static unsigned short fcstab[256] = { 1421 1293 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, ··· 2318 2214 if (setjmp(bus_error_jmp) == 0) { 2319 2215 catch_memory_errors = 1; 2320 2216 sync(); 2321 - *instr = ppc_inst_read((struct ppc_inst *)adrs); 2217 + *instr = ppc_inst_read((u32 *)adrs); 2322 2218 sync(); 2323 2219 /* wait a little while to see if we get a machine check */ 2324 2220 __delay(200); ··· 3079 2975 dump_log_buf(void) 3080 2976 { 3081 2977 struct kmsg_dump_iter iter; 3082 - unsigned char buf[128]; 2978 + static unsigned char buf[1024]; 3083 2979 size_t len; 3084 2980 3085 2981 if (setjmp(bus_error_jmp) != 0) { ··· 3109 3005 { 3110 3006 unsigned char buf[128]; 3111 3007 ssize_t res; 3112 - loff_t pos = 0; 3008 + volatile loff_t pos = 0; 3113 3009 3114 3010 if (!firmware_has_feature(FW_FEATURE_OPAL)) { 3115 3011 printf("Machine is not running OPAL firmware.\n"); ··· 3264 3160 printf("%.8lx\n", a - mskip); 3265 3161 } 3266 3162 3267 - static void show_task(struct task_struct *tsk) 3163 + static void show_task(struct task_struct *volatile tsk) 3268 3164 { 3269 3165 unsigned int p_state = READ_ONCE(tsk->__state); 3270 3166 char state; ··· 3309 3205 static void show_pte(unsigned long addr) 3310 3206 { 3311 3207 unsigned long tskv = 0; 3312 - struct task_struct *tsk = NULL; 3208 + struct task_struct *volatile tsk = NULL; 3313 3209 struct mm_struct *mm; 3314 3210 pgd_t *pgdp; 3315 3211 p4d_t *p4dp; ··· 3404 3300 static void show_tasks(void) 3405 3301 { 3406 3302 unsigned long tskv; 3407 - struct task_struct *tsk = NULL; 3303 + struct task_struct *volatile tsk = NULL; 3408 3304 3409 3305 printf(" task_struct ->thread.ksp ->thread.regs PID PPID S P CMD\n"); 3410 3306 ··· 3727 3623 const char *after) 3728 3624 { 3729 3625 char *modname; 3730 - const char *name = NULL; 3626 + const char *volatile name = NULL; 3731 3627 unsigned long offset, size; 3732 3628 3733 3629 printf(REG, address); ··· 4159 4055 static void stop_spus(void) 4160 4056 { 4161 4057 struct spu *spu; 4162 - int i; 4058 + volatile int i; 4163 4059 u64 tmp; 4164 4060 4165 4061 for (i = 0; i < XMON_NUM_SPUS; i++) { ··· 4200 4096 static void restart_spus(void) 4201 4097 { 4202 4098 struct spu *spu; 4203 - int i; 4099 + volatile int i; 4204 4100 4205 4101 for (i = 0; i < XMON_NUM_SPUS; i++) { 4206 4102 if (!spu_info[i].spu)
+1
drivers/crypto/nx/Kconfig
··· 29 29 config CRYPTO_DEV_NX_COMPRESS_PSERIES 30 30 tristate "Compression acceleration support on pSeries platform" 31 31 depends on PPC_PSERIES && IBMVIO 32 + depends on PPC_VAS 32 33 default y 33 34 help 34 35 Support for PowerPC Nest (NX) compression acceleration. This
+1 -1
drivers/crypto/nx/Makefile
··· 14 14 obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_PSERIES) += nx-compress-pseries.o nx-compress.o 15 15 obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_POWERNV) += nx-compress-powernv.o nx-compress.o 16 16 nx-compress-objs := nx-842.o 17 - nx-compress-pseries-objs := nx-842-pseries.o 17 + nx-compress-pseries-objs := nx-common-pseries.o 18 18 nx-compress-powernv-objs := nx-common-powernv.o
+138
drivers/crypto/nx/nx-842-pseries.c drivers/crypto/nx/nx-common-pseries.c
··· 9 9 */ 10 10 11 11 #include <asm/vio.h> 12 + #include <asm/hvcall.h> 13 + #include <asm/vas.h> 12 14 13 15 #include "nx-842.h" 14 16 #include "nx_csbcpb.h" /* struct nx_csbcpb */ ··· 20 18 MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors"); 21 19 MODULE_ALIAS_CRYPTO("842"); 22 20 MODULE_ALIAS_CRYPTO("842-nx"); 21 + 22 + /* 23 + * Coprocessor type specific capabilities from the hypervisor. 24 + */ 25 + struct hv_nx_cop_caps { 26 + __be64 descriptor; 27 + __be64 req_max_processed_len; /* Max bytes in one GZIP request */ 28 + __be64 min_compress_len; /* Min compression size in bytes */ 29 + __be64 min_decompress_len; /* Min decompression size in bytes */ 30 + } __packed __aligned(0x1000); 31 + 32 + /* 33 + * Coprocessor type specific capabilities. 34 + */ 35 + struct nx_cop_caps { 36 + u64 descriptor; 37 + u64 req_max_processed_len; /* Max bytes in one GZIP request */ 38 + u64 min_compress_len; /* Min compression in bytes */ 39 + u64 min_decompress_len; /* Min decompression in bytes */ 40 + }; 41 + 42 + static u64 caps_feat; 43 + static struct nx_cop_caps nx_cop_caps; 23 44 24 45 static struct nx842_constraints nx842_pseries_constraints = { 25 46 .alignment = DDE_BUFFER_ALIGN, ··· 967 942 .attrs = nx842_sysfs_entries, 968 943 }; 969 944 945 + #define nxcop_caps_read(_name) \ 946 + static ssize_t nxcop_##_name##_show(struct device *dev, \ 947 + struct device_attribute *attr, char *buf) \ 948 + { \ 949 + return sprintf(buf, "%lld\n", nx_cop_caps._name); \ 950 + } 951 + 952 + #define NXCT_ATTR_RO(_name) \ 953 + nxcop_caps_read(_name); \ 954 + static struct device_attribute dev_attr_##_name = __ATTR(_name, \ 955 + 0444, \ 956 + nxcop_##_name##_show, \ 957 + NULL); 958 + 959 + NXCT_ATTR_RO(req_max_processed_len); 960 + NXCT_ATTR_RO(min_compress_len); 961 + NXCT_ATTR_RO(min_decompress_len); 962 + 963 + static struct attribute *nxcop_caps_sysfs_entries[] = { 964 + &dev_attr_req_max_processed_len.attr, 965 + &dev_attr_min_compress_len.attr, 966 + &dev_attr_min_decompress_len.attr, 967 + NULL, 968 + }; 969 + 970 + static struct attribute_group nxcop_caps_attr_group = { 971 + .name = "nx_gzip_caps", 972 + .attrs = nxcop_caps_sysfs_entries, 973 + }; 974 + 970 975 static struct nx842_driver nx842_pseries_driver = { 971 976 .name = KBUILD_MODNAME, 972 977 .owner = THIS_MODULE, ··· 1086 1031 goto error; 1087 1032 } 1088 1033 1034 + if (caps_feat) { 1035 + if (sysfs_create_group(&viodev->dev.kobj, 1036 + &nxcop_caps_attr_group)) { 1037 + dev_err(&viodev->dev, 1038 + "Could not create sysfs NX capability entries\n"); 1039 + ret = -1; 1040 + goto error; 1041 + } 1042 + } 1043 + 1089 1044 return 0; 1090 1045 1091 1046 error_unlock: ··· 1115 1050 pr_info("Removing IBM Power 842 compression device\n"); 1116 1051 sysfs_remove_group(&viodev->dev.kobj, &nx842_attribute_group); 1117 1052 1053 + if (caps_feat) 1054 + sysfs_remove_group(&viodev->dev.kobj, &nxcop_caps_attr_group); 1055 + 1118 1056 crypto_unregister_alg(&nx842_pseries_alg); 1119 1057 1120 1058 spin_lock_irqsave(&devdata_mutex, flags); ··· 1131 1063 if (old_devdata) 1132 1064 kfree(old_devdata->counters); 1133 1065 kfree(old_devdata); 1066 + } 1067 + 1068 + /* 1069 + * Get NX capabilities from the hypervisor. 1070 + * Only NXGZIP capabilities are provided by the hypersvisor right 1071 + * now and these values are available to user space with sysfs. 1072 + */ 1073 + static void __init nxcop_get_capabilities(void) 1074 + { 1075 + struct hv_vas_all_caps *hv_caps; 1076 + struct hv_nx_cop_caps *hv_nxc; 1077 + int rc; 1078 + 1079 + hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL); 1080 + if (!hv_caps) 1081 + return; 1082 + /* 1083 + * Get NX overall capabilities with feature type=0 1084 + */ 1085 + rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, 0, 1086 + (u64)virt_to_phys(hv_caps)); 1087 + if (rc) 1088 + goto out; 1089 + 1090 + caps_feat = be64_to_cpu(hv_caps->feat_type); 1091 + /* 1092 + * NX-GZIP feature available 1093 + */ 1094 + if (caps_feat & VAS_NX_GZIP_FEAT_BIT) { 1095 + hv_nxc = kmalloc(sizeof(*hv_nxc), GFP_KERNEL); 1096 + if (!hv_nxc) 1097 + goto out; 1098 + /* 1099 + * Get capabilities for NX-GZIP feature 1100 + */ 1101 + rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, 1102 + VAS_NX_GZIP_FEAT, 1103 + (u64)virt_to_phys(hv_nxc)); 1104 + } else { 1105 + pr_err("NX-GZIP feature is not available\n"); 1106 + rc = -EINVAL; 1107 + } 1108 + 1109 + if (!rc) { 1110 + nx_cop_caps.descriptor = be64_to_cpu(hv_nxc->descriptor); 1111 + nx_cop_caps.req_max_processed_len = 1112 + be64_to_cpu(hv_nxc->req_max_processed_len); 1113 + nx_cop_caps.min_compress_len = 1114 + be64_to_cpu(hv_nxc->min_compress_len); 1115 + nx_cop_caps.min_decompress_len = 1116 + be64_to_cpu(hv_nxc->min_decompress_len); 1117 + } else { 1118 + caps_feat = 0; 1119 + } 1120 + 1121 + kfree(hv_nxc); 1122 + out: 1123 + kfree(hv_caps); 1134 1124 } 1135 1125 1136 1126 static const struct vio_device_id nx842_vio_driver_ids[] = { ··· 1219 1093 return -ENOMEM; 1220 1094 1221 1095 RCU_INIT_POINTER(devdata, new_devdata); 1096 + /* 1097 + * Get NX capabilities from the hypervisor. 1098 + */ 1099 + nxcop_get_capabilities(); 1222 1100 1223 1101 ret = vio_register_driver(&nx842_vio_driver); 1224 1102 if (ret) { ··· 1231 1101 kfree(new_devdata); 1232 1102 return ret; 1233 1103 } 1104 + 1105 + ret = vas_register_api_pseries(THIS_MODULE, VAS_COP_TYPE_GZIP, 1106 + "nx-gzip"); 1107 + 1108 + if (ret) 1109 + pr_err("NX-GZIP is not supported. Returned=%d\n", ret); 1234 1110 1235 1111 return 0; 1236 1112 } ··· 1247 1111 { 1248 1112 struct nx842_devdata *old_devdata; 1249 1113 unsigned long flags; 1114 + 1115 + vas_unregister_api_pseries(); 1250 1116 1251 1117 crypto_unregister_alg(&nx842_pseries_alg); 1252 1118
+3 -3
drivers/crypto/nx/nx-common-powernv.c
··· 1092 1092 * normal FIFO priority is assigned for userspace. 1093 1093 * 842 compression is supported only in kernel. 1094 1094 */ 1095 - ret = vas_register_coproc_api(THIS_MODULE, VAS_COP_TYPE_GZIP, 1096 - "nx-gzip"); 1095 + ret = vas_register_api_powernv(THIS_MODULE, VAS_COP_TYPE_GZIP, 1096 + "nx-gzip"); 1097 1097 1098 1098 /* 1099 1099 * GZIP is not supported in kernel right now. ··· 1129 1129 * use. So delete this API use for GZIP engine. 1130 1130 */ 1131 1131 if (!nx842_ct) 1132 - vas_unregister_coproc_api(); 1132 + vas_unregister_api_powernv(); 1133 1133 1134 1134 crypto_unregister_alg(&nx842_powernv_alg); 1135 1135
+1 -1
drivers/ps3/ps3-vuart.c
··· 358 358 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written); 359 359 360 360 if (result) { 361 - dev_dbg(&dev->core, "%s:%d: lv1_write_virtual_uart failed: " 361 + dev_warn(&dev->core, "%s:%d: lv1_write_virtual_uart failed: " 362 362 "%s\n", __func__, __LINE__, ps3_result(result)); 363 363 return result; 364 364 }
+11 -11
drivers/ps3/ps3av.c
··· 217 217 /* send pkt */ 218 218 res = ps3av_vuart_write(ps3av->dev, send_buf, write_len); 219 219 if (res < 0) { 220 - dev_dbg(&ps3av->dev->core, 221 - "%s: ps3av_vuart_write() failed (result=%d)\n", 222 - __func__, res); 220 + dev_warn(&ps3av->dev->core, 221 + "%s:%d: ps3av_vuart_write() failed: %s\n", __func__, 222 + __LINE__, ps3_result(res)); 223 223 return res; 224 224 } 225 225 ··· 230 230 res = ps3av_vuart_read(ps3av->dev, recv_buf, PS3AV_HDR_SIZE, 231 231 timeout); 232 232 if (res != PS3AV_HDR_SIZE) { 233 - dev_dbg(&ps3av->dev->core, 234 - "%s: ps3av_vuart_read() failed (result=%d)\n", 235 - __func__, res); 233 + dev_warn(&ps3av->dev->core, 234 + "%s:%d: ps3av_vuart_read() failed: %s\n", __func__, 235 + __LINE__, ps3_result(res)); 236 236 return res; 237 237 } 238 238 ··· 240 240 res = ps3av_vuart_read(ps3av->dev, &recv_buf->cid, 241 241 recv_buf->size, timeout); 242 242 if (res < 0) { 243 - dev_dbg(&ps3av->dev->core, 244 - "%s: ps3av_vuart_read() failed (result=%d)\n", 245 - __func__, res); 243 + dev_warn(&ps3av->dev->core, 244 + "%s:%d: ps3av_vuart_read() failed: %s\n", __func__, 245 + __LINE__, ps3_result(res)); 246 246 return res; 247 247 } 248 248 res += PS3AV_HDR_SIZE; /* total len */ ··· 251 251 } while (event); 252 252 253 253 if ((cmd | PS3AV_REPLY_BIT) != recv_buf->cid) { 254 - dev_dbg(&ps3av->dev->core, "%s: reply err (result=%x)\n", 255 - __func__, recv_buf->cid); 254 + dev_warn(&ps3av->dev->core, "%s:%d: reply err: %x\n", __func__, 255 + __LINE__, recv_buf->cid); 256 256 return -EINVAL; 257 257 } 258 258
+1 -1
drivers/tty/hvc/hvc_vio.c
··· 249 249 count = hvterm_hvsi_put_chars(0, &c, 1); 250 250 break; 251 251 } 252 - } while(count == 0); 252 + } while (count == 0 || count == -EAGAIN); 253 253 } 254 254 255 255 static int udbg_hvc_getc_poll(void)
+3
include/linux/kprobes.h
··· 400 400 401 401 void *alloc_insn_page(void); 402 402 403 + void *alloc_optinsn_page(void); 404 + void free_optinsn_page(void *page); 405 + 403 406 int kprobe_get_kallsym(unsigned int symnum, unsigned long *value, char *type, 404 407 char *sym); 405 408
+12 -2
kernel/kprobes.c
··· 321 321 } 322 322 323 323 #ifdef CONFIG_OPTPROBES 324 + void __weak *alloc_optinsn_page(void) 325 + { 326 + return alloc_insn_page(); 327 + } 328 + 329 + void __weak free_optinsn_page(void *page) 330 + { 331 + free_insn_page(page); 332 + } 333 + 324 334 /* For optimized_kprobe buffer */ 325 335 struct kprobe_insn_cache kprobe_optinsn_slots = { 326 336 .mutex = __MUTEX_INITIALIZER(kprobe_optinsn_slots.mutex), 327 - .alloc = alloc_insn_page, 328 - .free = free_insn_page, 337 + .alloc = alloc_optinsn_page, 338 + .free = free_optinsn_page, 329 339 .sym = KPROBE_OPTINSN_PAGE_SYM, 330 340 .pages = LIST_HEAD_INIT(kprobe_optinsn_slots.pages), 331 341 /* .insn_size is initialized later */
+2 -1
tools/testing/selftests/powerpc/benchmarks/null_syscall.c
··· 14 14 #include <time.h> 15 15 #include <sys/types.h> 16 16 #include <sys/time.h> 17 + #include <sys/syscall.h> 17 18 #include <signal.h> 18 19 19 20 static volatile int soak_done; ··· 122 121 unsigned long i; 123 122 124 123 for (i = 0; i < nr; i++) 125 - getppid(); 124 + syscall(__NR_gettid); 126 125 } 127 126 128 127 #define TIME(A, STR) \
+2 -2
tools/testing/selftests/powerpc/nx-gzip/Makefile
··· 1 - CFLAGS = -O3 -m64 -I./include 1 + CFLAGS = -O3 -m64 -I./include -I../include 2 2 3 3 TEST_GEN_FILES := gzfht_test gunz_test 4 4 TEST_PROGS := nx-gzip-test.sh 5 5 6 6 include ../../lib.mk 7 7 8 - $(TEST_GEN_FILES): gzip_vas.c 8 + $(TEST_GEN_FILES): gzip_vas.c ../utils.c
+15 -2
tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c
··· 60 60 #include <assert.h> 61 61 #include <errno.h> 62 62 #include <signal.h> 63 + #include "utils.h" 63 64 #include "nxu.h" 64 65 #include "nx.h" 65 66 ··· 70 69 #define NX_MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) 71 70 #define FNAME_MAX 1024 72 71 #define FEXT ".nx.gz" 72 + 73 + #define SYSFS_MAX_REQ_BUF_PATH "devices/vio/ibm,compression-v1/nx_gzip_caps/req_max_processed_len" 73 74 74 75 /* 75 76 * LZ counts returned in the user supplied nx_gzip_crb_cpb_t structure. ··· 247 244 struct nx_gzip_crb_cpb_t *cmdp; 248 245 uint32_t pagelen = 65536; 249 246 int fault_tries = NX_MAX_FAULTS; 247 + char buf[32]; 250 248 251 249 cmdp = (void *)(uintptr_t) 252 250 aligned_alloc(sizeof(struct nx_gzip_crb_cpb_t), ··· 267 263 assert(NULL != (outbuf = (char *)malloc(outlen))); 268 264 nxu_touch_pages(outbuf, outlen, pagelen, 1); 269 265 270 - /* Compress piecemeal in smallish chunks */ 271 - chunk = 1<<22; 266 + /* 267 + * On PowerVM, the hypervisor defines the maximum request buffer 268 + * size is defined and this value is available via sysfs. 269 + */ 270 + if (!read_sysfs_file(SYSFS_MAX_REQ_BUF_PATH, buf, sizeof(buf))) { 271 + chunk = atoi(buf); 272 + } else { 273 + /* sysfs entry is not available on PowerNV */ 274 + /* Compress piecemeal in smallish chunks */ 275 + chunk = 1<<22; 276 + } 272 277 273 278 /* Write the gzip header to the stream */ 274 279 num_hdr_bytes = gzip_header_blank(outbuf);
+1 -1
tools/testing/selftests/powerpc/pmu/ebb/Makefile
··· 24 24 fork_cleanup_test ebb_on_child_test \ 25 25 ebb_on_willing_child_test back_to_back_ebbs_test \ 26 26 lost_exception_test no_handler_test \ 27 - cycles_with_mmcr2_test 27 + cycles_with_mmcr2_test regs_access_pmccext_test 28 28 29 29 top_srcdir = ../../../../../.. 30 30 include ../../../lib.mk
-2
tools/testing/selftests/powerpc/pmu/ebb/ebb.h
··· 55 55 bool ebb_is_supported(void); 56 56 void ebb_freeze_pmcs(void); 57 57 void ebb_unfreeze_pmcs(void); 58 - void event_ebb_init(struct event *e); 59 - void event_leader_ebb_init(struct event *e); 60 58 int count_pmc(int pmc, uint32_t sample_period); 61 59 void dump_ebb_state(void); 62 60 void dump_summary_ebb_state(void);
-2
tools/testing/selftests/powerpc/pmu/ebb/no_handler_test.c
··· 50 50 51 51 event_close(&event); 52 52 53 - dump_ebb_state(); 54 - 55 53 /* The real test is that we never took an EBB at 0x0 */ 56 54 57 55 return 0;
+63
tools/testing/selftests/powerpc/pmu/ebb/regs_access_pmccext_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright 2021, Athira Rajeev, IBM Corp. 4 + */ 5 + 6 + #include <stdio.h> 7 + #include <stdlib.h> 8 + #include <setjmp.h> 9 + #include <signal.h> 10 + 11 + #include "ebb.h" 12 + 13 + 14 + /* 15 + * Test that closing the EBB event clears MMCR0_PMCC and 16 + * sets MMCR0_PMCCEXT preventing further read access to the 17 + * group B PMU registers. 18 + */ 19 + 20 + static int regs_access_pmccext(void) 21 + { 22 + struct event event; 23 + 24 + SKIP_IF(!ebb_is_supported()); 25 + 26 + event_init_named(&event, 0x1001e, "cycles"); 27 + event_leader_ebb_init(&event); 28 + 29 + FAIL_IF(event_open(&event)); 30 + 31 + ebb_enable_pmc_counting(1); 32 + setup_ebb_handler(standard_ebb_callee); 33 + ebb_global_enable(); 34 + FAIL_IF(ebb_event_enable(&event)); 35 + 36 + mtspr(SPRN_PMC1, pmc_sample_period(sample_period)); 37 + 38 + while (ebb_state.stats.ebb_count < 1) 39 + FAIL_IF(core_busy_loop()); 40 + 41 + ebb_global_disable(); 42 + event_close(&event); 43 + 44 + FAIL_IF(ebb_state.stats.ebb_count == 0); 45 + 46 + /* 47 + * For ISA v3.1, verify the test takes a SIGILL when reading 48 + * PMU regs after the event is closed. With the control bit 49 + * in MMCR0 (PMCCEXT) restricting access to group B PMU regs, 50 + * sigill is expected. 51 + */ 52 + if (have_hwcap2(PPC_FEATURE2_ARCH_3_1)) 53 + FAIL_IF(catch_sigill(dump_ebb_state)); 54 + else 55 + dump_ebb_state(); 56 + 57 + return 0; 58 + } 59 + 60 + int main(void) 61 + { 62 + return test_harness(regs_access_pmccext, "regs_access_pmccext"); 63 + }
+2
tools/testing/selftests/powerpc/security/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0+ 2 2 3 3 TEST_GEN_PROGS := rfi_flush entry_flush uaccess_flush spectre_v2 4 + TEST_PROGS := mitigation-patching.sh 5 + 4 6 top_srcdir = ../../../../.. 5 7 6 8 CFLAGS += -I../../../../../usr/include
+75
tools/testing/selftests/powerpc/security/mitigation-patching.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + set -euo pipefail 4 + 5 + TIMEOUT=10 6 + 7 + function do_one 8 + { 9 + local mitigation="$1" 10 + local orig 11 + local start 12 + local now 13 + 14 + orig=$(cat "$mitigation") 15 + 16 + start=$EPOCHSECONDS 17 + now=$start 18 + 19 + while [[ $((now-start)) -lt "$TIMEOUT" ]] 20 + do 21 + echo 0 > "$mitigation" 22 + echo 1 > "$mitigation" 23 + 24 + now=$EPOCHSECONDS 25 + done 26 + 27 + echo "$orig" > "$mitigation" 28 + } 29 + 30 + rc=0 31 + cd /sys/kernel/debug/powerpc || rc=1 32 + if [[ "$rc" -ne 0 ]]; then 33 + echo "Error: couldn't cd to /sys/kernel/debug/powerpc" >&2 34 + exit 1 35 + fi 36 + 37 + tainted=$(cat /proc/sys/kernel/tainted) 38 + if [[ "$tainted" -ne 0 ]]; then 39 + echo "Error: kernel already tainted!" >&2 40 + exit 1 41 + fi 42 + 43 + mitigations="barrier_nospec stf_barrier count_cache_flush rfi_flush entry_flush uaccess_flush" 44 + 45 + for m in $mitigations 46 + do 47 + do_one "$m" & 48 + done 49 + 50 + echo "Spawned threads enabling/disabling mitigations ..." 51 + 52 + if stress-ng > /dev/null 2>&1; then 53 + stress="stress-ng" 54 + elif stress > /dev/null 2>&1; then 55 + stress="stress" 56 + else 57 + stress="" 58 + fi 59 + 60 + if [[ -n "$stress" ]]; then 61 + "$stress" -m "$(nproc)" -t "$TIMEOUT" & 62 + echo "Spawned VM stressors ..." 63 + fi 64 + 65 + echo "Waiting for timeout ..." 66 + wait 67 + 68 + tainted=$(cat /proc/sys/kernel/tainted) 69 + if [[ "$tainted" -ne 0 ]]; then 70 + echo "Error: kernel became tainted!" >&2 71 + exit 1 72 + fi 73 + 74 + echo "OK" 75 + exit 0
-1
tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
··· 17 17 #include <pthread.h> 18 18 #include <sys/mman.h> 19 19 #include <unistd.h> 20 - #include <pthread.h> 21 20 22 21 #include "tm.h" 23 22 #include "utils.h"