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

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

Pull powerpc updates from Michael Ellerman:
"Slightly late as I had to rebase mid-week to insert a bug fix:

- A large series from Nick for 64-bit to further rework our exception
vectors, and rewrite portions of the syscall entry/exit and
interrupt return in C. The result is much easier to follow code
that is also faster in general.

- Cleanup of our ptrace code to split various parts out that had
become badly intertwined with #ifdefs over the years.

- Changes to our NUMA setup under the PowerVM hypervisor which should
hopefully avoid non-sensical topologies which can lead to warnings
from the workqueue code and other problems.

- MAINTAINERS updates to remove some of our old orphan entries and
update the status of others.

- Quite a few other small changes and fixes all over the map.

Thanks to: Abdul Haleem, afzal mohammed, Alexey Kardashevskiy, Andrew
Donnellan, Aneesh Kumar K.V, Balamuruhan S, Cédric Le Goater, Chen
Zhou, Christophe JAILLET, Christophe Leroy, Christoph Hellwig, Clement
Courbet, Daniel Axtens, David Gibson, Douglas Miller, Fabiano Rosas,
Fangrui Song, Ganesh Goudar, Gautham R. Shenoy, Greg Kroah-Hartman,
Greg Kurz, Gustavo Luiz Duarte, Hari Bathini, Ilie Halip, Jan Kara,
Joe Lawrence, Joe Perches, Kajol Jain, Larry Finger, Laurentiu Tudor,
Leonardo Bras, Libor Pechacek, Madhavan Srinivasan, Mahesh Salgaonkar,
Masahiro Yamada, Masami Hiramatsu, Mauricio Faria de Oliveira, Michael
Neuling, Michal Suchanek, Mike Rapoport, Nageswara R Sastry, Nathan
Chancellor, Nathan Lynch, Naveen N. Rao, Nicholas Piggin, Nick
Desaulniers, Oliver O'Halloran, Po-Hsu Lin, Pratik Rajesh Sampat,
Rasmus Villemoes, Ravi Bangoria, Roman Bolshakov, Sam Bobroff,
Sandipan Das, Santosh S, Sedat Dilek, Segher Boessenkool, Shilpasri G
Bhat, Sourabh Jain, Srikar Dronamraju, Stephen Rothwell, Tyrel
Datwyler, Vaibhav Jain, YueHaibing"

* tag 'powerpc-5.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (158 commits)
powerpc: Make setjmp/longjmp signature standard
powerpc/cputable: Remove unnecessary copy of cpu_spec->oprofile_type
powerpc: Suppress .eh_frame generation
powerpc: Drop -fno-dwarf2-cfi-asm
powerpc/32: drop unused ISA_DMA_THRESHOLD
powerpc/powernv: Add documentation for the opal sensor_groups sysfs interfaces
selftests/powerpc: Fix try-run when source tree is not writable
powerpc/vmlinux.lds: Explicitly retain .gnu.hash
powerpc/ptrace: move ptrace_triggered() into hw_breakpoint.c
powerpc/ptrace: create ppc_gethwdinfo()
powerpc/ptrace: create ptrace_get_debugreg()
powerpc/ptrace: split out ADV_DEBUG_REGS related functions.
powerpc/ptrace: move register viewing functions out of ptrace.c
powerpc/ptrace: split out TRANSACTIONAL_MEM related functions.
powerpc/ptrace: split out SPE related functions.
powerpc/ptrace: split out ALTIVEC related functions.
powerpc/ptrace: split out VSX related functions.
powerpc/ptrace: drop PARAMETER_SAVE_AREA_OFFSET
powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64
powerpc/ptrace: remove unused header includes
...

+8015 -6180
+9
Documentation/ABI/obsolete/sysfs-kernel-fadump_enabled
··· 1 + This ABI is renamed and moved to a new location /sys/kernel/fadump/enabled. 2 + 3 + What: /sys/kernel/fadump_enabled 4 + Date: Feb 2012 5 + Contact: linuxppc-dev@lists.ozlabs.org 6 + Description: read only 7 + Primarily used to identify whether the FADump is enabled in 8 + the kernel or not. 9 + User: Kdump service
+10
Documentation/ABI/obsolete/sysfs-kernel-fadump_registered
··· 1 + This ABI is renamed and moved to a new location /sys/kernel/fadump/registered.¬ 2 + 3 + What: /sys/kernel/fadump_registered 4 + Date: Feb 2012 5 + Contact: linuxppc-dev@lists.ozlabs.org 6 + Description: read/write 7 + Helps to control the dump collect feature from userspace. 8 + Setting 1 to this file enables the system to collect the 9 + dump and 0 to disable it. 10 + User: Kdump service
+10
Documentation/ABI/obsolete/sysfs-kernel-fadump_release_mem
··· 1 + This ABI is renamed and moved to a new location /sys/kernel/fadump/release_mem.¬ 2 + 3 + What: /sys/kernel/fadump_release_mem 4 + Date: Feb 2012 5 + Contact: linuxppc-dev@lists.ozlabs.org 6 + Description: write only 7 + This is a special sysfs file and only available when 8 + the system is booted to capture the vmcore using FADump. 9 + It is used to release the memory reserved by FADump to 10 + save the crash dump.
+9
Documentation/ABI/removed/sysfs-kernel-fadump_release_opalcore
··· 1 + This ABI is moved to /sys/firmware/opal/mpipl/release_core. 2 + 3 + What: /sys/kernel/fadump_release_opalcore 4 + Date: Sep 2019 5 + Contact: linuxppc-dev@lists.ozlabs.org 6 + Description: write only 7 + The sysfs file is available when the system is booted to 8 + collect the dump on OPAL based machine. It used to release 9 + the memory used to collect the opalcore.
+21
Documentation/ABI/testing/sysfs-firmware-opal-sensor-groups
··· 1 + What: /sys/firmware/opal/sensor_groups 2 + Date: August 2017 3 + Contact: Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org> 4 + Description: Sensor groups directory for POWER9 powernv servers 5 + 6 + Each folder in this directory contains a sensor group 7 + which are classified based on type of the sensor 8 + like power, temperature, frequency, current, etc. They 9 + can also indicate the group of sensors belonging to 10 + different owners like CSM, Profiler, Job-Scheduler 11 + 12 + What: /sys/firmware/opal/sensor_groups/<sensor_group_name>/clear 13 + Date: August 2017 14 + Contact: Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org> 15 + Description: Sysfs file to clear the min-max of all the sensors 16 + belonging to the group. 17 + 18 + Writing 1 to this file will clear the minimum and 19 + maximum values of all the sensors in the group. 20 + In POWER9, the min-max of a sensor is the historical minimum 21 + and maximum value of the sensor cached by OCC.
+40
Documentation/ABI/testing/sysfs-kernel-fadump
··· 1 + What: /sys/kernel/fadump/* 2 + Date: Dec 2019 3 + Contact: linuxppc-dev@lists.ozlabs.org 4 + Description: 5 + The /sys/kernel/fadump/* is a collection of FADump sysfs 6 + file provide information about the configuration status 7 + of Firmware Assisted Dump (FADump). 8 + 9 + What: /sys/kernel/fadump/enabled 10 + Date: Dec 2019 11 + Contact: linuxppc-dev@lists.ozlabs.org 12 + Description: read only 13 + Primarily used to identify whether the FADump is enabled in 14 + the kernel or not. 15 + User: Kdump service 16 + 17 + What: /sys/kernel/fadump/registered 18 + Date: Dec 2019 19 + Contact: linuxppc-dev@lists.ozlabs.org 20 + Description: read/write 21 + Helps to control the dump collect feature from userspace. 22 + Setting 1 to this file enables the system to collect the 23 + dump and 0 to disable it. 24 + User: Kdump service 25 + 26 + What: /sys/kernel/fadump/release_mem 27 + Date: Dec 2019 28 + Contact: linuxppc-dev@lists.ozlabs.org 29 + Description: write only 30 + This is a special sysfs file and only available when 31 + the system is booted to capture the vmcore using FADump. 32 + It is used to release the memory reserved by FADump to 33 + save the crash dump. 34 + 35 + What: /sys/kernel/fadump/mem_reserved 36 + Date: Dec 2019 37 + Contact: linuxppc-dev@lists.ozlabs.org 38 + Description: read only 39 + Provide information about the amount of memory reserved by 40 + FADump to save the crash dump in bytes.
+26 -6
Documentation/powerpc/firmware-assisted-dump.rst
··· 112 112 113 113 -- On OPAL based machines (PowerNV), if the kernel is build with 114 114 CONFIG_OPAL_CORE=y, OPAL memory at the time of crash is also 115 - exported as /sys/firmware/opal/core file. This procfs file is 115 + exported as /sys/firmware/opal/mpipl/core file. This procfs file is 116 116 helpful in debugging OPAL crashes with GDB. The kernel memory 117 117 used for exporting this procfs file can be released by echo'ing 118 - '1' to /sys/kernel/fadump_release_opalcore node. 118 + '1' to /sys/firmware/opal/mpipl/release_core node. 119 119 120 120 e.g. 121 - # echo 1 > /sys/kernel/fadump_release_opalcore 121 + # echo 1 > /sys/firmware/opal/mpipl/release_core 122 122 123 123 Implementation details: 124 124 ----------------------- ··· 268 268 be handled and vmcore will not be captured. This interface can be 269 269 easily integrated with kdump service start/stop. 270 270 271 + /sys/kernel/fadump/mem_reserved 272 + 273 + This is used to display the memory reserved by FADump for saving the 274 + crash dump. 275 + 271 276 /sys/kernel/fadump_release_mem 272 277 This file is available only when FADump is active during 273 278 second kernel. This is used to release the reserved memory ··· 288 283 enhanced to use this interface to release the memory reserved for 289 284 dump and continue without 2nd reboot. 290 285 291 - /sys/kernel/fadump_release_opalcore 286 + Note: /sys/kernel/fadump_release_opalcore sysfs has moved to 287 + /sys/firmware/opal/mpipl/release_core 288 + 289 + /sys/firmware/opal/mpipl/release_core 292 290 293 291 This file is available only on OPAL based machines when FADump is 294 292 active during capture kernel. This is used to release the memory 295 - used by the kernel to export /sys/firmware/opal/core file. To 293 + used by the kernel to export /sys/firmware/opal/mpipl/core file. To 296 294 release this memory, echo '1' to it: 297 295 298 - echo 1 > /sys/kernel/fadump_release_opalcore 296 + echo 1 > /sys/firmware/opal/mpipl/release_core 297 + 298 + Note: The following FADump sysfs files are deprecated. 299 + 300 + +----------------------------------+--------------------------------+ 301 + | Deprecated | Alternative | 302 + +----------------------------------+--------------------------------+ 303 + | /sys/kernel/fadump_enabled | /sys/kernel/fadump/enabled | 304 + +----------------------------------+--------------------------------+ 305 + | /sys/kernel/fadump_registered | /sys/kernel/fadump/registered | 306 + +----------------------------------+--------------------------------+ 307 + | /sys/kernel/fadump_release_mem | /sys/kernel/fadump/release_mem | 308 + +----------------------------------+--------------------------------+ 299 309 300 310 Here is the list of files under powerpc debugfs: 301 311 (Assuming debugfs is mounted on /sys/kernel/debug directory.)
+10 -39
MAINTAINERS
··· 9692 9692 9693 9693 LINUX FOR POWER MACINTOSH 9694 9694 M: Benjamin Herrenschmidt <benh@kernel.crashing.org> 9695 - W: http://www.penguinppc.org/ 9696 9695 L: linuxppc-dev@lists.ozlabs.org 9697 - S: Maintained 9696 + S: Odd Fixes 9698 9697 F: arch/powerpc/platforms/powermac/ 9699 9698 F: drivers/macintosh/ 9700 9699 9701 9700 LINUX FOR POWERPC (32-BIT AND 64-BIT) 9702 - M: Benjamin Herrenschmidt <benh@kernel.crashing.org> 9703 - M: Paul Mackerras <paulus@samba.org> 9704 9701 M: Michael Ellerman <mpe@ellerman.id.au> 9705 - W: https://github.com/linuxppc/linux/wiki 9702 + R: Benjamin Herrenschmidt <benh@kernel.crashing.org> 9703 + R: Paul Mackerras <paulus@samba.org> 9704 + W: https://github.com/linuxppc/wiki/wiki 9706 9705 L: linuxppc-dev@lists.ozlabs.org 9707 9706 Q: http://patchwork.ozlabs.org/project/linuxppc-dev/list/ 9708 9707 T: git git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git ··· 9718 9719 F: drivers/i2c/busses/i2c-opal.c 9719 9720 F: drivers/net/ethernet/ibm/ibmveth.* 9720 9721 F: drivers/net/ethernet/ibm/ibmvnic.* 9722 + F: drivers/*/*/*pasemi* 9723 + F: drivers/*/*pasemi* 9721 9724 F: drivers/pci/hotplug/pnv_php.c 9722 9725 F: drivers/pci/hotplug/rpa* 9723 9726 F: drivers/rtc/rtc-opal.c ··· 9736 9735 LINUX FOR POWERPC EMBEDDED MPC5XXX 9737 9736 M: Anatolij Gustschin <agust@denx.de> 9738 9737 L: linuxppc-dev@lists.ozlabs.org 9739 - T: git git://git.denx.de/linux-denx-agust.git 9740 - S: Maintained 9738 + S: Odd Fixes 9741 9739 F: arch/powerpc/platforms/512x/ 9742 9740 F: arch/powerpc/platforms/52xx/ 9743 9741 9744 9742 LINUX FOR POWERPC EMBEDDED PPC4XX 9745 - M: Alistair Popple <alistair@popple.id.au> 9746 - M: Matt Porter <mporter@kernel.crashing.org> 9747 - W: http://www.penguinppc.org/ 9748 9743 L: linuxppc-dev@lists.ozlabs.org 9749 - S: Maintained 9744 + S: Orphan 9750 9745 F: arch/powerpc/platforms/40x/ 9751 9746 F: arch/powerpc/platforms/44x/ 9752 9747 9753 9748 LINUX FOR POWERPC EMBEDDED PPC83XX AND PPC85XX 9754 9749 M: Scott Wood <oss@buserror.net> 9755 - M: Kumar Gala <galak@kernel.crashing.org> 9756 - W: http://www.penguinppc.org/ 9757 9750 L: linuxppc-dev@lists.ozlabs.org 9758 9751 T: git git://git.kernel.org/pub/scm/linux/kernel/git/scottwood/linux.git 9759 - S: Maintained 9752 + S: Odd fixes 9760 9753 F: arch/powerpc/platforms/83xx/ 9761 9754 F: arch/powerpc/platforms/85xx/ 9762 9755 F: Documentation/devicetree/bindings/powerpc/fsl/ 9763 9756 9764 9757 LINUX FOR POWERPC EMBEDDED PPC8XX 9765 - M: Vitaly Bordug <vitb@kernel.crashing.org> 9766 - W: http://www.penguinppc.org/ 9758 + M: Christophe Leroy <christophe.leroy@c-s.fr> 9767 9759 L: linuxppc-dev@lists.ozlabs.org 9768 9760 S: Maintained 9769 9761 F: arch/powerpc/platforms/8xx/ 9770 - 9771 - LINUX FOR POWERPC EMBEDDED XILINX VIRTEX 9772 - L: linuxppc-dev@lists.ozlabs.org 9773 - S: Orphan 9774 - F: arch/powerpc/*/*virtex* 9775 - F: arch/powerpc/*/*/*virtex* 9776 - 9777 - LINUX FOR POWERPC PA SEMI PWRFICIENT 9778 - L: linuxppc-dev@lists.ozlabs.org 9779 - S: Orphan 9780 - F: arch/powerpc/platforms/pasemi/ 9781 - F: drivers/*/*pasemi* 9782 - F: drivers/*/*/*pasemi* 9783 9762 9784 9763 LINUX KERNEL DUMP TEST MODULE (LKDTM) 9785 9764 M: Kees Cook <keescook@chromium.org> ··· 12647 12666 W: http://wireless.kernel.org/en/users/Drivers/p54 12648 12667 S: Maintained 12649 12668 F: drivers/net/wireless/intersil/p54/ 12650 - 12651 - PA SEMI ETHERNET DRIVER 12652 - L: netdev@vger.kernel.org 12653 - S: Orphan 12654 - F: drivers/net/ethernet/pasemi/* 12655 - 12656 - PA SEMI SMBUS DRIVER 12657 - L: linux-i2c@vger.kernel.org 12658 - S: Orphan 12659 - F: drivers/i2c/busses/i2c-pasemi.c 12660 12669 12661 12670 PACKING 12662 12671 M: Vladimir Oltean <olteanv@gmail.com>
+8 -4
arch/powerpc/Makefile
··· 239 239 KBUILD_CFLAGS += $(call cc-option,-mno-spe) 240 240 KBUILD_CFLAGS += $(call cc-option,-mspe=no) 241 241 242 - # FIXME: the module load should be taught about the additional relocs 243 - # generated by this. 244 - # revert to pre-gcc-4.4 behaviour of .eh_frame 245 - KBUILD_CFLAGS += $(call cc-option,-fno-dwarf2-cfi-asm) 242 + # Don't emit .eh_frame since we have no use for it 243 + KBUILD_CFLAGS += -fno-asynchronous-unwind-tables 246 244 247 245 # Never use string load/store instructions as they are 248 246 # often slow when they are implemented at all ··· 296 298 $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@) 297 299 298 300 301 + PHONY += bootwrapper_install 299 302 bootwrapper_install: 300 303 $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@) 301 304 ··· 402 403 @echo ' (minus the .dts extension).' 403 404 endef 404 405 406 + PHONY += install 405 407 install: 406 408 $(Q)$(MAKE) $(build)=$(boot) install 407 409 410 + PHONY += vdso_install 408 411 vdso_install: 409 412 ifdef CONFIG_PPC64 410 413 $(Q)$(MAKE) $(build)=arch/$(ARCH)/kernel/vdso64 $@ ··· 426 425 ifdef CONFIG_STACKPROTECTOR 427 426 prepare: stack_protector_prepare 428 427 428 + PHONY += stack_protector_prepare 429 429 stack_protector_prepare: prepare0 430 430 ifdef CONFIG_PPC64 431 431 $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h)) ··· 438 436 ifdef CONFIG_SMP 439 437 prepare: task_cpu_prepare 440 438 439 + PHONY += task_cpu_prepare 441 440 task_cpu_prepare: prepare0 442 441 $(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TASK_CPU") print $$3;}' include/generated/asm-offsets.h)) 443 442 endif 444 443 444 + PHONY += checkbin 445 445 # Check toolchain versions: 446 446 # - gcc-4.6 is the minimum kernel-wide version so nothing required. 447 447 checkbin:
+2
arch/powerpc/boot/Makefile
··· 445 445 zInstall: $(CONFIGURE) $(addprefix $(obj)/, $(image-y)) 446 446 sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" $^ 447 447 448 + PHONY += install zInstall 449 + 448 450 # anything not in $(targets) 449 451 clean-files += $(image-) $(initrd-) cuImage.* dtbImage.* treeImage.* \ 450 452 zImage zImage.initrd zImage.chrp zImage.coff zImage.holly \
-3
arch/powerpc/boot/crt0.S
··· 44 44 p_pstack: .long _platform_stack_top 45 45 #endif 46 46 47 - .globl _zimage_start 48 - /* Clang appears to require the .weak directive to be after the symbol 49 - * is defined. See https://bugs.llvm.org/show_bug.cgi?id=38921 */ 50 47 .weak _zimage_start 51 48 _zimage_start: 52 49 .globl _zimage_start_lib
+4 -11
arch/powerpc/include/asm/asm-prototypes.h
··· 97 97 unsigned long __init early_init(unsigned long dt_ptr); 98 98 void __init machine_init(u64 dt_ptr); 99 99 #endif 100 + long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, unsigned long r0, struct pt_regs *regs); 101 + notrace unsigned long syscall_exit_prepare(unsigned long r3, struct pt_regs *regs); 102 + notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long msr); 103 + notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsigned long msr); 100 104 101 105 long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low, 102 106 u32 len_high, u32 len_low); 103 107 long sys_switch_endian(void); 104 108 notrace unsigned int __check_irq_replay(void); 105 109 void notrace restore_interrupts(void); 106 - 107 - /* ptrace */ 108 - long do_syscall_trace_enter(struct pt_regs *regs); 109 - void do_syscall_trace_leave(struct pt_regs *regs); 110 - 111 - /* process */ 112 - void restore_math(struct pt_regs *regs); 113 - void restore_tm_state(struct pt_regs *regs); 114 110 115 111 /* prom_init (OpenFirmware) */ 116 112 unsigned long __init prom_init(unsigned long r3, unsigned long r4, ··· 117 121 /* setup */ 118 122 void __init early_setup(unsigned long dt_ptr); 119 123 void early_setup_secondary(void); 120 - 121 - /* time */ 122 - void accumulate_stolen_time(void); 123 124 124 125 /* misc runtime */ 125 126 extern u64 __bswapdi2(u64);
+4 -4
arch/powerpc/include/asm/book3s/32/hash.h
··· 17 17 * updating the accessed and modified bits in the page table tree. 18 18 */ 19 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 */ 20 + #define _PAGE_USER 0x001 /* usermode access allowed */ 21 + #define _PAGE_RW 0x002 /* software: user write access allowed */ 22 + #define _PAGE_PRESENT 0x004 /* software: pte contains a translation */ 23 23 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */ 24 24 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */ 25 25 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */ ··· 27 27 #define _PAGE_DIRTY 0x080 /* C: page changed */ 28 28 #define _PAGE_ACCESSED 0x100 /* R: page referenced */ 29 29 #define _PAGE_EXEC 0x200 /* software: exec allowed */ 30 - #define _PAGE_RW 0x400 /* software: user write access allowed */ 30 + #define _PAGE_HASHPTE 0x400 /* hash_page has made an HPTE for this pte */ 31 31 #define _PAGE_SPECIAL 0x800 /* software: Special page */ 32 32 33 33 #ifdef CONFIG_PTE_64BIT
+2 -4
arch/powerpc/include/asm/book3s/32/pgtable.h
··· 366 366 (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) 367 367 #define pte_offset_kernel(dir, addr) \ 368 368 ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(addr)) 369 - #define pte_offset_map(dir, addr) \ 370 - ((pte_t *)(kmap_atomic(pmd_page(*(dir))) + \ 371 - (pmd_page_vaddr(*(dir)) & ~PAGE_MASK)) + pte_index(addr)) 372 - #define pte_unmap(pte) kunmap_atomic(pte) 369 + #define pte_offset_map(dir, addr) pte_offset_kernel((dir), (addr)) 370 + static inline void pte_unmap(pte_t *pte) { } 373 371 374 372 /* 375 373 * Encode and decode a swap entry.
+6
arch/powerpc/include/asm/book3s/64/hash-4k.h
··· 156 156 extern int hash__has_transparent_hugepage(void); 157 157 #endif 158 158 159 + static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd) 160 + { 161 + BUG(); 162 + return pmd; 163 + } 164 + 159 165 #endif /* !__ASSEMBLY__ */ 160 166 161 167 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */
+7 -1
arch/powerpc/include/asm/book3s/64/hash-64k.h
··· 246 246 */ 247 247 static inline int hash__pmd_trans_huge(pmd_t pmd) 248 248 { 249 - return !!((pmd_val(pmd) & (_PAGE_PTE | H_PAGE_THP_HUGE)) == 249 + return !!((pmd_val(pmd) & (_PAGE_PTE | H_PAGE_THP_HUGE | _PAGE_DEVMAP)) == 250 250 (_PAGE_PTE | H_PAGE_THP_HUGE)); 251 251 } 252 252 ··· 272 272 unsigned long addr, pmd_t *pmdp); 273 273 extern int hash__has_transparent_hugepage(void); 274 274 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 275 + 276 + static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd) 277 + { 278 + return __pmd(pmd_val(pmd) | (_PAGE_PTE | H_PAGE_THP_HUGE | _PAGE_DEVMAP)); 279 + } 280 + 275 281 #endif /* __ASSEMBLY__ */ 276 282 277 283 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */
+23 -1
arch/powerpc/include/asm/book3s/64/kup-radix.h
··· 3 3 #define _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H 4 4 5 5 #include <linux/const.h> 6 + #include <asm/reg.h> 6 7 7 8 #define AMR_KUAP_BLOCK_READ UL(0x4000000000000000) 8 9 #define AMR_KUAP_BLOCK_WRITE UL(0x8000000000000000) ··· 57 56 58 57 #ifdef CONFIG_PPC_KUAP 59 58 60 - #include <asm/reg.h> 59 + #include <asm/mmu.h> 60 + #include <asm/ptrace.h> 61 + 62 + static inline void kuap_restore_amr(struct pt_regs *regs) 63 + { 64 + if (mmu_has_feature(MMU_FTR_RADIX_KUAP)) 65 + mtspr(SPRN_AMR, regs->kuap); 66 + } 67 + 68 + static inline void kuap_check_amr(void) 69 + { 70 + if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && mmu_has_feature(MMU_FTR_RADIX_KUAP)) 71 + WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED); 72 + } 61 73 62 74 /* 63 75 * We support individually allowing read or write, but we don't support nesting ··· 140 126 return WARN(mmu_has_feature(MMU_FTR_RADIX_KUAP) && 141 127 (regs->kuap & (is_write ? AMR_KUAP_BLOCK_WRITE : AMR_KUAP_BLOCK_READ)), 142 128 "Bug: %s fault blocked by AMR!", is_write ? "Write" : "Read"); 129 + } 130 + #else /* CONFIG_PPC_KUAP */ 131 + static inline void kuap_restore_amr(struct pt_regs *regs) 132 + { 133 + } 134 + 135 + static inline void kuap_check_amr(void) 136 + { 143 137 } 144 138 #endif /* CONFIG_PPC_KUAP */ 145 139
+3 -1
arch/powerpc/include/asm/book3s/64/pgtable.h
··· 1303 1303 1304 1304 static inline pmd_t pmd_mkdevmap(pmd_t pmd) 1305 1305 { 1306 - return __pmd(pmd_val(pmd) | (_PAGE_PTE | _PAGE_DEVMAP)); 1306 + if (radix_enabled()) 1307 + return radix__pmd_mkdevmap(pmd); 1308 + return hash__pmd_mkdevmap(pmd); 1307 1309 } 1308 1310 1309 1311 static inline int pmd_devmap(pmd_t pmd)
+5
arch/powerpc/include/asm/book3s/64/radix.h
··· 263 263 } 264 264 #endif 265 265 266 + static inline pmd_t radix__pmd_mkdevmap(pmd_t pmd) 267 + { 268 + return __pmd(pmd_val(pmd) | (_PAGE_PTE | _PAGE_DEVMAP)); 269 + } 270 + 266 271 extern int __meminit radix__vmemmap_create_mapping(unsigned long start, 267 272 unsigned long page_size, 268 273 unsigned long phys);
+1 -1
arch/powerpc/include/asm/cache.h
··· 97 97 98 98 #endif 99 99 100 - #define __read_mostly __attribute__((__section__(".data..read_mostly"))) 100 + #define __read_mostly __section(.data..read_mostly) 101 101 102 102 #ifdef CONFIG_PPC_BOOK3S_32 103 103 extern long _get_L2CR(void);
+1 -5
arch/powerpc/include/asm/cacheflush.h
··· 65 65 unsigned long size = stop - (unsigned long)addr + (bytes - 1); 66 66 unsigned long i; 67 67 68 - if (IS_ENABLED(CONFIG_PPC64)) { 68 + if (IS_ENABLED(CONFIG_PPC64)) 69 69 mb(); /* sync */ 70 - isync(); 71 - } 72 70 73 71 for (i = 0; i < size >> shift; i++, addr += bytes) 74 72 dcbf(addr); 75 73 mb(); /* sync */ 76 74 77 - if (IS_ENABLED(CONFIG_PPC64)) 78 - isync(); 79 75 } 80 76 81 77 /*
+33
arch/powerpc/include/asm/cputime.h
··· 43 43 */ 44 44 #ifdef CONFIG_PPC64 45 45 #define get_accounting(tsk) (&get_paca()->accounting) 46 + #define raw_get_accounting(tsk) (&local_paca->accounting) 46 47 static inline void arch_vtime_task_switch(struct task_struct *tsk) { } 48 + 47 49 #else 48 50 #define get_accounting(tsk) (&task_thread_info(tsk)->accounting) 51 + #define raw_get_accounting(tsk) get_accounting(tsk) 49 52 /* 50 53 * Called from the context switch with interrupts disabled, to charge all 51 54 * accumulated times to the current process, and to prepare accounting on ··· 63 60 } 64 61 #endif 65 62 63 + /* 64 + * account_cpu_user_entry/exit runs "unreconciled", so can't trace, 65 + * can't use use get_paca() 66 + */ 67 + static notrace inline void account_cpu_user_entry(void) 68 + { 69 + unsigned long tb = mftb(); 70 + struct cpu_accounting_data *acct = raw_get_accounting(current); 71 + 72 + acct->utime += (tb - acct->starttime_user); 73 + acct->starttime = tb; 74 + } 75 + 76 + static notrace inline void account_cpu_user_exit(void) 77 + { 78 + unsigned long tb = mftb(); 79 + struct cpu_accounting_data *acct = raw_get_accounting(current); 80 + 81 + acct->stime += (tb - acct->starttime); 82 + acct->starttime_user = tb; 83 + } 84 + 85 + 66 86 #endif /* __KERNEL__ */ 87 + #else /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ 88 + static inline void account_cpu_user_entry(void) 89 + { 90 + } 91 + static inline void account_cpu_user_exit(void) 92 + { 93 + } 67 94 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ 68 95 #endif /* __POWERPC_CPUTIME_H */
+1 -2
arch/powerpc/include/asm/dma.h
··· 151 151 #define DMA2_EXT_REG 0x4D6 152 152 153 153 #ifndef __powerpc64__ 154 - /* in arch/ppc/kernel/setup.c -- Cort */ 154 + /* in arch/powerpc/kernel/setup_32.c -- Cort */ 155 155 extern unsigned int DMA_MODE_WRITE; 156 156 extern unsigned int DMA_MODE_READ; 157 - extern unsigned long ISA_DMA_THRESHOLD; 158 157 #else 159 158 #define DMA_MODE_READ 0x44 /* I/O to memory, no autoinit, increment, single mode */ 160 159 #define DMA_MODE_WRITE 0x48 /* memory to I/O, no autoinit, increment, single mode */
+2 -2
arch/powerpc/include/asm/drmem.h
··· 27 27 extern struct drmem_lmb_info *drmem_info; 28 28 29 29 #define for_each_drmem_lmb_in_range(lmb, start, end) \ 30 - for ((lmb) = (start); (lmb) <= (end); (lmb)++) 30 + for ((lmb) = (start); (lmb) < (end); (lmb)++) 31 31 32 32 #define for_each_drmem_lmb(lmb) \ 33 33 for_each_drmem_lmb_in_range((lmb), \ 34 34 &drmem_info->lmbs[0], \ 35 - &drmem_info->lmbs[drmem_info->n_lmbs - 1]) 35 + &drmem_info->lmbs[drmem_info->n_lmbs]) 36 36 37 37 /* 38 38 * The of_drconf_cell_v1 struct defines the layout of the LMB data
+11 -15
arch/powerpc/include/asm/eeh.h
··· 215 215 struct eeh_ops { 216 216 char *name; 217 217 int (*init)(void); 218 - void* (*probe)(struct pci_dn *pdn, void *data); 218 + struct eeh_dev *(*probe)(struct pci_dev *pdev); 219 219 int (*set_option)(struct eeh_pe *pe, int option); 220 220 int (*get_pe_addr)(struct eeh_pe *pe); 221 221 int (*get_state)(struct eeh_pe *pe, int *delay); ··· 301 301 int eeh_check_failure(const volatile void __iomem *token); 302 302 int eeh_dev_check_failure(struct eeh_dev *edev); 303 303 void eeh_addr_cache_init(void); 304 - void eeh_add_device_early(struct pci_dn *); 305 - void eeh_add_device_tree_early(struct pci_dn *); 306 - void eeh_add_device_late(struct pci_dev *); 307 - void eeh_add_device_tree_late(struct pci_bus *); 308 - void eeh_add_sysfs_files(struct pci_bus *); 304 + void eeh_probe_device(struct pci_dev *pdev); 309 305 void eeh_remove_device(struct pci_dev *); 310 306 int eeh_unfreeze_pe(struct eeh_pe *pe); 311 307 int eeh_pe_reset_and_recover(struct eeh_pe *pe); ··· 356 360 357 361 static inline void eeh_addr_cache_init(void) { } 358 362 359 - static inline void eeh_add_device_early(struct pci_dn *pdn) { } 360 - 361 - static inline void eeh_add_device_tree_early(struct pci_dn *pdn) { } 362 - 363 - static inline void eeh_add_device_late(struct pci_dev *dev) { } 364 - 365 - static inline void eeh_add_device_tree_late(struct pci_bus *bus) { } 366 - 367 - static inline void eeh_add_sysfs_files(struct pci_bus *bus) { } 363 + static inline void eeh_probe_device(struct pci_dev *dev) { } 368 364 369 365 static inline void eeh_remove_device(struct pci_dev *dev) { } 370 366 371 367 #define EEH_POSSIBLE_ERROR(val, type) (0) 372 368 #define EEH_IO_ERROR_VALUE(size) (-1UL) 373 369 #endif /* CONFIG_EEH */ 370 + 371 + #if defined(CONFIG_PPC_PSERIES) && defined(CONFIG_EEH) 372 + void pseries_eeh_init_edev(struct pci_dn *pdn); 373 + void pseries_eeh_init_edev_recursive(struct pci_dn *pdn); 374 + #else 375 + static inline void pseries_eeh_add_device_early(struct pci_dn *pdn) { } 376 + static inline void pseries_eeh_add_device_tree_early(struct pci_dn *pdn) { } 377 + #endif 374 378 375 379 #ifdef CONFIG_PPC64 376 380 /*
-4
arch/powerpc/include/asm/exception-64s.h
··· 33 33 #include <asm/feature-fixups.h> 34 34 35 35 /* PACA save area size in u64 units (exgen, exmc, etc) */ 36 - #if defined(CONFIG_RELOCATABLE) 37 36 #define EX_SIZE 10 38 - #else 39 - #define EX_SIZE 9 40 - #endif 41 37 42 38 /* 43 39 * maximum recursive depth of MCE exceptions
+5 -1
arch/powerpc/include/asm/hw_irq.h
··· 52 52 #ifndef __ASSEMBLY__ 53 53 54 54 extern void replay_system_reset(void); 55 - extern void __replay_interrupt(unsigned int vector); 55 + extern void replay_soft_interrupts(void); 56 56 57 57 extern void timer_interrupt(struct pt_regs *); 58 58 extern void timer_broadcast_interrupt(void); ··· 228 228 #ifdef CONFIG_PPC_BOOK3E 229 229 #define __hard_irq_enable() wrtee(MSR_EE) 230 230 #define __hard_irq_disable() wrtee(0) 231 + #define __hard_EE_RI_disable() wrtee(0) 232 + #define __hard_RI_enable() do { } while (0) 231 233 #else 232 234 #define __hard_irq_enable() __mtmsrd(MSR_EE|MSR_RI, 1) 233 235 #define __hard_irq_disable() __mtmsrd(MSR_RI, 1) 236 + #define __hard_EE_RI_disable() __mtmsrd(0, 1) 237 + #define __hard_RI_enable() __mtmsrd(MSR_RI, 1) 234 238 #endif 235 239 236 240 #define hard_irq_disable() do { \
-3
arch/powerpc/include/asm/kvm_host.h
··· 309 309 pgd_t *pgtable; 310 310 u64 process_table; 311 311 struct dentry *debugfs_dir; 312 - struct dentry *htab_dentry; 313 - struct dentry *radix_dentry; 314 312 struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */ 315 313 #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ 316 314 #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE ··· 829 831 struct kvmhv_tb_accumulator cede_time; /* time napping inside guest */ 830 832 831 833 struct dentry *debugfs_dir; 832 - struct dentry *debugfs_timings; 833 834 #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ 834 835 }; 835 836
+2
arch/powerpc/include/asm/mce.h
··· 218 218 extern void machine_check_print_event_info(struct machine_check_event *evt, 219 219 bool user_mode, bool in_guest); 220 220 unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr); 221 + extern void mce_common_process_ue(struct pt_regs *regs, 222 + struct mce_error_info *mce_err); 221 223 #ifdef CONFIG_PPC_BOOK3S_64 222 224 void flush_and_reload_slb(void); 223 225 #endif /* CONFIG_PPC_BOOK3S_64 */
+2 -4
arch/powerpc/include/asm/nohash/32/pgtable.h
··· 372 372 #define pte_offset_kernel(dir, addr) \ 373 373 (pmd_bad(*(dir)) ? NULL : (pte_t *)pmd_page_vaddr(*(dir)) + \ 374 374 pte_index(addr)) 375 - #define pte_offset_map(dir, addr) \ 376 - ((pte_t *)(kmap_atomic(pmd_page(*(dir))) + \ 377 - (pmd_page_vaddr(*(dir)) & ~PAGE_MASK)) + pte_index(addr)) 378 - #define pte_unmap(pte) kunmap_atomic(pte) 375 + #define pte_offset_map(dir, addr) pte_offset_kernel((dir), (addr)) 376 + static inline void pte_unmap(pte_t *pte) { } 379 377 380 378 /* 381 379 * Encode and decode a swap entry.
+1
arch/powerpc/include/asm/opal-api.h
··· 1067 1067 OPAL_REBOOT_PLATFORM_ERROR = 1, 1068 1068 OPAL_REBOOT_FULL_IPL = 2, 1069 1069 OPAL_REBOOT_MPIPL = 3, 1070 + OPAL_REBOOT_FAST = 4, 1070 1071 }; 1071 1072 1072 1073 /* Argument to OPAL_PCI_TCE_KILL */
+1 -1
arch/powerpc/include/asm/perf_event.h
··· 32 32 do { \ 33 33 (regs)->result = 0; \ 34 34 (regs)->nip = __ip; \ 35 - (regs)->gpr[1] = current_stack_pointer(); \ 35 + (regs)->gpr[1] = current_stack_frame(); \ 36 36 asm volatile("mfmsr %0" : "=r" ((regs)->msr)); \ 37 37 } while (0) 38 38
+19
arch/powerpc/include/asm/pgtable.h
··· 41 41 42 42 #ifndef __ASSEMBLY__ 43 43 44 + #ifdef CONFIG_PPC32 45 + static inline pmd_t *pmd_ptr(struct mm_struct *mm, unsigned long va) 46 + { 47 + return pmd_offset(pud_offset(pgd_offset(mm, va), va), va); 48 + } 49 + 50 + static inline pmd_t *pmd_ptr_k(unsigned long va) 51 + { 52 + return pmd_offset(pud_offset(pgd_offset_k(va), va), va); 53 + } 54 + 55 + static inline pte_t *virt_to_kpte(unsigned long vaddr) 56 + { 57 + pmd_t *pmd = pmd_ptr_k(vaddr); 58 + 59 + return pmd_none(*pmd) ? NULL : pte_offset_kernel(pmd, vaddr); 60 + } 61 + #endif 62 + 44 63 #include <asm/tlbflush.h> 45 64 46 65 /* Keep these as a macros to avoid include dependency mess */
+5
arch/powerpc/include/asm/ptrace.h
··· 138 138 #define profile_pc(regs) instruction_pointer(regs) 139 139 #endif 140 140 141 + long do_syscall_trace_enter(struct pt_regs *regs); 142 + void do_syscall_trace_leave(struct pt_regs *regs); 143 + 141 144 #define kernel_stack_pointer(regs) ((regs)->gpr[1]) 142 145 static inline int is_syscall_success(struct pt_regs *regs) 143 146 { ··· 279 276 #endif /* __ASSEMBLY__ */ 280 277 281 278 #ifndef __powerpc64__ 279 + /* We need PT_SOFTE defined at all time to avoid #ifdefs */ 280 + #define PT_SOFTE PT_MQ 282 281 #else /* __powerpc64__ */ 283 282 #define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */ 284 283 #define PT_VR0_32 164 /* each Vector reg occupies 4 slots in 32-bit */
+3 -1
arch/powerpc/include/asm/reg.h
··· 1448 1448 1449 1449 #define proc_trap() asm volatile("trap") 1450 1450 1451 - extern unsigned long current_stack_pointer(void); 1451 + extern unsigned long current_stack_frame(void); 1452 + 1453 + register unsigned long current_stack_pointer asm("r1"); 1452 1454 1453 1455 extern unsigned long scom970_read(unsigned int address); 1454 1456 extern void scom970_write(unsigned int address, unsigned long value);
+4 -2
arch/powerpc/include/asm/setjmp.h
··· 7 7 8 8 #define JMP_BUF_LEN 23 9 9 10 - extern long setjmp(long *) __attribute__((returns_twice)); 11 - extern void longjmp(long *, long) __attribute__((noreturn)); 10 + typedef long jmp_buf[JMP_BUF_LEN]; 11 + 12 + extern int setjmp(jmp_buf env) __attribute__((returns_twice)); 13 + extern void longjmp(jmp_buf env, int val) __attribute__((noreturn)); 12 14 13 15 #endif /* _ASM_POWERPC_SETJMP_H */
+3
arch/powerpc/include/asm/signal.h
··· 6 6 #include <uapi/asm/signal.h> 7 7 #include <uapi/asm/ptrace.h> 8 8 9 + struct pt_regs; 10 + void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags); 11 + 9 12 #endif /* _ASM_POWERPC_SIGNAL_H */
+11
arch/powerpc/include/asm/switch_to.h
··· 5 5 #ifndef _ASM_POWERPC_SWITCH_TO_H 6 6 #define _ASM_POWERPC_SWITCH_TO_H 7 7 8 + #include <linux/sched.h> 8 9 #include <asm/reg.h> 9 10 10 11 struct thread_struct; ··· 22 21 extern void switch_booke_debug_regs(struct debug_reg *new_debug); 23 22 24 23 extern int emulate_altivec(struct pt_regs *); 24 + 25 + #ifdef CONFIG_PPC_BOOK3S_64 26 + void restore_math(struct pt_regs *regs); 27 + #else 28 + static inline void restore_math(struct pt_regs *regs) 29 + { 30 + } 31 + #endif 32 + 33 + void restore_tm_state(struct pt_regs *regs); 25 34 26 35 extern void flush_all_to_thread(struct task_struct *); 27 36 extern void giveup_all(struct task_struct *);
+3 -1
arch/powerpc/include/asm/time.h
··· 24 24 25 25 26 26 extern void generic_calibrate_decr(void); 27 - extern void hdec_interrupt(struct pt_regs *regs); 28 27 29 28 /* Some sane defaults: 125 MHz timebase, 1GHz processor */ 30 29 extern unsigned long ppc_proc_freq; ··· 193 194 194 195 /* Convert timebase ticks to nanoseconds */ 195 196 unsigned long long tb_to_ns(unsigned long long tb_ticks); 197 + 198 + /* SPLPAR */ 199 + void accumulate_stolen_time(void); 196 200 197 201 #endif /* __KERNEL__ */ 198 202 #endif /* __POWERPC_TIME_H */
+6 -4
arch/powerpc/include/asm/topology.h
··· 98 98 extern int prrn_is_enabled(void); 99 99 extern int find_and_online_cpu_nid(int cpu); 100 100 extern int timed_topology_update(int nsecs); 101 - extern void __init shared_proc_topology_init(void); 102 101 #else 103 102 static inline int start_topology_update(void) 104 103 { ··· 120 121 return 0; 121 122 } 122 123 123 - #ifdef CONFIG_SMP 124 - static inline void shared_proc_topology_init(void) {} 125 - #endif 126 124 #endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */ 127 125 128 126 #include <asm-generic/topology.h> ··· 130 134 #ifdef CONFIG_PPC64 131 135 #include <asm/smp.h> 132 136 137 + #ifdef CONFIG_PPC_SPLPAR 138 + int get_physical_package_id(int cpu); 139 + #define topology_physical_package_id(cpu) (get_physical_package_id(cpu)) 140 + #else 133 141 #define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu)) 142 + #endif 143 + 134 144 #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) 135 145 #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) 136 146 #define topology_core_id(cpu) (cpu_to_core_id(cpu))
-24
arch/powerpc/include/asm/vdso.h
··· 13 13 14 14 #define VDSO_VERSION_STRING LINUX_2.6.15 15 15 16 - /* Define if 64 bits VDSO has procedure descriptors */ 17 - #undef VDS64_HAS_DESCRIPTORS 18 - 19 16 #ifndef __ASSEMBLY__ 20 17 21 18 /* Offsets relative to thread->vdso_base */ ··· 25 28 #else /* __ASSEMBLY__ */ 26 29 27 30 #ifdef __VDSO64__ 28 - #ifdef VDS64_HAS_DESCRIPTORS 29 - #define V_FUNCTION_BEGIN(name) \ 30 - .globl name; \ 31 - .section ".opd","a"; \ 32 - .align 3; \ 33 - name: \ 34 - .quad .name,.TOC.@tocbase,0; \ 35 - .previous; \ 36 - .globl .name; \ 37 - .type .name,@function; \ 38 - .name: \ 39 - 40 - #define V_FUNCTION_END(name) \ 41 - .size .name,.-.name; 42 - 43 - #define V_LOCAL_FUNC(name) (.name) 44 - 45 - #else /* VDS64_HAS_DESCRIPTORS */ 46 - 47 31 #define V_FUNCTION_BEGIN(name) \ 48 32 .globl name; \ 49 33 name: \ ··· 33 55 .size name,.-name; 34 56 35 57 #define V_LOCAL_FUNC(name) (name) 36 - 37 - #endif /* VDS64_HAS_DESCRIPTORS */ 38 58 #endif /* __VDSO64__ */ 39 59 40 60 #ifdef __VDSO32__
+5 -6
arch/powerpc/kernel/Makefile
··· 3 3 # Makefile for the linux kernel. 4 4 # 5 5 6 - CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' 7 - 8 6 ifdef CONFIG_PPC64 9 7 CFLAGS_prom_init.o += $(NO_MINIMAL_TOC) 10 8 endif ··· 39 41 CFLAGS_btext.o += -DDISABLE_BRANCH_PROFILING 40 42 endif 41 43 42 - obj-y := cputable.o ptrace.o syscalls.o \ 44 + obj-y := cputable.o syscalls.o \ 43 45 irq.o align.o signal_32.o pmc.o vdso.o \ 44 46 process.o systbl.o idle.o \ 45 47 signal.o sysfs.o cacheinfo.o time.o \ 46 48 prom.o traps.o setup-common.o \ 47 49 udbg.o misc.o io.o misc_$(BITS).o \ 48 50 of_platform.o prom_parse.o 49 - obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \ 50 - signal_64.o ptrace32.o \ 51 - paca.o nvram_64.o firmware.o note.o 51 + obj-y += ptrace/ 52 + obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o signal_64.o \ 53 + paca.o nvram_64.o firmware.o note.o \ 54 + syscall_64.o 52 55 obj-$(CONFIG_VDSO32) += vdso32/ 53 56 obj-$(CONFIG_PPC_WATCHDOG) += watchdog.o 54 57 obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
+1 -1
arch/powerpc/kernel/btext.c
··· 26 26 static void scrollscreen(void); 27 27 #endif 28 28 29 - #define __force_data __attribute__((__section__(".data"))) 29 + #define __force_data __section(.data) 30 30 31 31 static int g_loc_X __force_data; 32 32 static int g_loc_Y __force_data;
-1
arch/powerpc/kernel/cputable.c
··· 2198 2198 */ 2199 2199 if (old.oprofile_cpu_type != NULL) { 2200 2200 t->oprofile_cpu_type = old.oprofile_cpu_type; 2201 - t->oprofile_type = old.oprofile_type; 2202 2201 t->cpu_features |= old.cpu_features & CPU_FTR_PMAO_BUG; 2203 2202 } 2204 2203 }
-1
arch/powerpc/kernel/dt_cpu_ftrs.c
··· 139 139 /* Initialize the base environment -- clear FSCR/HFSCR. */ 140 140 hv_mode = !!(mfmsr() & MSR_HV); 141 141 if (hv_mode) { 142 - /* CPU_FTR_HVMODE is used early in PACA setup */ 143 142 cur_cpu_spec->cpu_features |= CPU_FTR_HVMODE; 144 143 mtspr(SPRN_HFSCR, 0); 145 144 }
+25 -122
arch/powerpc/kernel/eeh.c
··· 1107 1107 core_initcall_sync(eeh_init); 1108 1108 1109 1109 /** 1110 - * eeh_add_device_early - Enable EEH for the indicated device node 1111 - * @pdn: PCI device node for which to set up EEH 1112 - * 1113 - * This routine must be used to perform EEH initialization for PCI 1114 - * devices that were added after system boot (e.g. hotplug, dlpar). 1115 - * This routine must be called before any i/o is performed to the 1116 - * adapter (inluding any config-space i/o). 1117 - * Whether this actually enables EEH or not for this device depends 1118 - * on the CEC architecture, type of the device, on earlier boot 1119 - * command-line arguments & etc. 1120 - */ 1121 - void eeh_add_device_early(struct pci_dn *pdn) 1122 - { 1123 - struct pci_controller *phb = pdn ? pdn->phb : NULL; 1124 - struct eeh_dev *edev = pdn_to_eeh_dev(pdn); 1125 - 1126 - if (!edev) 1127 - return; 1128 - 1129 - if (!eeh_has_flag(EEH_PROBE_MODE_DEVTREE)) 1130 - return; 1131 - 1132 - /* USB Bus children of PCI devices will not have BUID's */ 1133 - if (NULL == phb || 1134 - (eeh_has_flag(EEH_PROBE_MODE_DEVTREE) && 0 == phb->buid)) 1135 - return; 1136 - 1137 - eeh_ops->probe(pdn, NULL); 1138 - } 1139 - 1140 - /** 1141 - * eeh_add_device_tree_early - Enable EEH for the indicated device 1142 - * @pdn: PCI device node 1143 - * 1144 - * This routine must be used to perform EEH initialization for the 1145 - * indicated PCI device that was added after system boot (e.g. 1146 - * hotplug, dlpar). 1147 - */ 1148 - void eeh_add_device_tree_early(struct pci_dn *pdn) 1149 - { 1150 - struct pci_dn *n; 1151 - 1152 - if (!pdn) 1153 - return; 1154 - 1155 - list_for_each_entry(n, &pdn->child_list, list) 1156 - eeh_add_device_tree_early(n); 1157 - eeh_add_device_early(pdn); 1158 - } 1159 - EXPORT_SYMBOL_GPL(eeh_add_device_tree_early); 1160 - 1161 - /** 1162 - * eeh_add_device_late - Perform EEH initialization for the indicated pci device 1110 + * eeh_probe_device() - Perform EEH initialization for the indicated pci device 1163 1111 * @dev: pci device for which to set up EEH 1164 1112 * 1165 1113 * This routine must be used to complete EEH initialization for PCI 1166 1114 * devices that were added after system boot (e.g. hotplug, dlpar). 1167 1115 */ 1168 - void eeh_add_device_late(struct pci_dev *dev) 1116 + void eeh_probe_device(struct pci_dev *dev) 1169 1117 { 1170 - struct pci_dn *pdn; 1171 1118 struct eeh_dev *edev; 1172 1119 1173 - if (!dev) 1174 - return; 1120 + pr_debug("EEH: Adding device %s\n", pci_name(dev)); 1175 1121 1176 - pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn); 1177 - edev = pdn_to_eeh_dev(pdn); 1178 - eeh_edev_dbg(edev, "Adding device\n"); 1179 - if (edev->pdev == dev) { 1180 - eeh_edev_dbg(edev, "Device already referenced!\n"); 1122 + /* 1123 + * pci_dev_to_eeh_dev() can only work if eeh_probe_dev() was 1124 + * already called for this device. 1125 + */ 1126 + if (WARN_ON_ONCE(pci_dev_to_eeh_dev(dev))) { 1127 + pci_dbg(dev, "Already bound to an eeh_dev!\n"); 1128 + return; 1129 + } 1130 + 1131 + edev = eeh_ops->probe(dev); 1132 + if (!edev) { 1133 + pr_debug("EEH: Adding device failed\n"); 1181 1134 return; 1182 1135 } 1183 1136 1184 1137 /* 1185 - * The EEH cache might not be removed correctly because of 1186 - * unbalanced kref to the device during unplug time, which 1187 - * relies on pcibios_release_device(). So we have to remove 1188 - * that here explicitly. 1138 + * FIXME: We rely on pcibios_release_device() to remove the 1139 + * existing EEH state. The release function is only called if 1140 + * the pci_dev's refcount drops to zero so if something is 1141 + * keeping a ref to a device (e.g. a filesystem) we need to 1142 + * remove the old EEH state. 1143 + * 1144 + * FIXME: HEY MA, LOOK AT ME, NO LOCKING! 1189 1145 */ 1190 - if (edev->pdev) { 1146 + if (edev->pdev && edev->pdev != dev) { 1191 1147 eeh_rmv_from_parent_pe(edev); 1192 1148 eeh_addr_cache_rmv_dev(edev->pdev); 1193 1149 eeh_sysfs_remove_device(edev->pdev); ··· 1154 1198 * into error handler afterwards. 1155 1199 */ 1156 1200 edev->mode |= EEH_DEV_NO_HANDLER; 1157 - 1158 - edev->pdev = NULL; 1159 - dev->dev.archdata.edev = NULL; 1160 1201 } 1161 1202 1162 - if (eeh_has_flag(EEH_PROBE_MODE_DEV)) 1163 - eeh_ops->probe(pdn, NULL); 1164 - 1203 + /* bind the pdev and the edev together */ 1165 1204 edev->pdev = dev; 1166 1205 dev->dev.archdata.edev = edev; 1167 - 1168 1206 eeh_addr_cache_insert_dev(dev); 1207 + eeh_sysfs_add_device(dev); 1169 1208 } 1170 - 1171 - /** 1172 - * eeh_add_device_tree_late - Perform EEH initialization for the indicated PCI bus 1173 - * @bus: PCI bus 1174 - * 1175 - * This routine must be used to perform EEH initialization for PCI 1176 - * devices which are attached to the indicated PCI bus. The PCI bus 1177 - * is added after system boot through hotplug or dlpar. 1178 - */ 1179 - void eeh_add_device_tree_late(struct pci_bus *bus) 1180 - { 1181 - struct pci_dev *dev; 1182 - 1183 - if (eeh_has_flag(EEH_FORCE_DISABLED)) 1184 - return; 1185 - list_for_each_entry(dev, &bus->devices, bus_list) { 1186 - eeh_add_device_late(dev); 1187 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { 1188 - struct pci_bus *subbus = dev->subordinate; 1189 - if (subbus) 1190 - eeh_add_device_tree_late(subbus); 1191 - } 1192 - } 1193 - } 1194 - EXPORT_SYMBOL_GPL(eeh_add_device_tree_late); 1195 - 1196 - /** 1197 - * eeh_add_sysfs_files - Add EEH sysfs files for the indicated PCI bus 1198 - * @bus: PCI bus 1199 - * 1200 - * This routine must be used to add EEH sysfs files for PCI 1201 - * devices which are attached to the indicated PCI bus. The PCI bus 1202 - * is added after system boot through hotplug or dlpar. 1203 - */ 1204 - void eeh_add_sysfs_files(struct pci_bus *bus) 1205 - { 1206 - struct pci_dev *dev; 1207 - 1208 - list_for_each_entry(dev, &bus->devices, bus_list) { 1209 - eeh_sysfs_add_device(dev); 1210 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { 1211 - struct pci_bus *subbus = dev->subordinate; 1212 - if (subbus) 1213 - eeh_add_sysfs_files(subbus); 1214 - } 1215 - } 1216 - } 1217 - EXPORT_SYMBOL_GPL(eeh_add_sysfs_files); 1218 1209 1219 1210 /** 1220 1211 * eeh_remove_device - Undo EEH setup for the indicated pci device
+30 -8
arch/powerpc/kernel/entry_32.S
··· 246 246 * r3 can be different from GPR3(r1) at this point, r9 and r11 247 247 * contains the old MSR and handler address respectively, 248 248 * r4 & r5 can contain page fault arguments that need to be passed 249 - * along as well. r12, CCR, CTR, XER etc... are left clobbered as 250 - * they aren't useful past this point (aren't syscall arguments), 251 - * the rest is restored from the exception frame. 249 + * along as well. r0, r6-r8, r12, CCR, CTR, XER etc... are left 250 + * clobbered as they aren't useful past this point. 252 251 */ 253 252 254 253 stwu r1,-32(r1) ··· 261 262 * lockdep 262 263 */ 263 264 1: bl trace_hardirqs_off 264 - 2: lwz r5,24(r1) 265 + lwz r5,24(r1) 265 266 lwz r4,20(r1) 266 267 lwz r3,16(r1) 267 268 lwz r11,12(r1) 268 269 lwz r9,8(r1) 269 270 addi r1,r1,32 270 - lwz r0,GPR0(r1) 271 - lwz r6,GPR6(r1) 272 - lwz r7,GPR7(r1) 273 - lwz r8,GPR8(r1) 274 271 mtctr r11 275 272 mtlr r9 276 273 bctr /* jump to handler */ ··· 569 574 addi r3,r1,STACK_FRAME_OVERHEAD 570 575 bl do_syscall_trace_leave 571 576 b ret_from_except_full 577 + 578 + /* 579 + * System call was called from kernel. We get here with SRR1 in r9. 580 + * Mark the exception as recoverable once we have retrieved SRR0, 581 + * trap a warning and return ENOSYS with CR[SO] set. 582 + */ 583 + .globl ret_from_kernel_syscall 584 + ret_from_kernel_syscall: 585 + mfspr r9, SPRN_SRR0 586 + mfspr r10, SPRN_SRR1 587 + #if !defined(CONFIG_4xx) && !defined(CONFIG_BOOKE) 588 + LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~(MSR_IR|MSR_DR)) 589 + mtmsr r11 590 + #endif 591 + 592 + 0: trap 593 + EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING 594 + 595 + li r3, ENOSYS 596 + crset so 597 + #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS) 598 + mtspr SPRN_NRI, r0 599 + #endif 600 + mtspr SPRN_SRR0, r9 601 + mtspr SPRN_SRR1, r10 602 + SYNC 603 + RFI 572 604 573 605 /* 574 606 * The fork/clone functions need to copy the full register set into
+186 -711
arch/powerpc/kernel/entry_64.S
··· 16 16 17 17 #include <linux/errno.h> 18 18 #include <linux/err.h> 19 + #include <asm/cache.h> 19 20 #include <asm/unistd.h> 20 21 #include <asm/processor.h> 21 22 #include <asm/page.h> ··· 70 69 bne .Ltabort_syscall 71 70 END_FTR_SECTION_IFSET(CPU_FTR_TM) 72 71 #endif 72 + _ASM_NOKPROBE_SYMBOL(system_call_common) 73 73 mr r10,r1 74 74 ld r1,PACAKSAVE(r13) 75 75 std r10,0(r1) ··· 78 76 std r12,_MSR(r1) 79 77 std r0,GPR0(r1) 80 78 std r10,GPR1(r1) 79 + std r2,GPR2(r1) 81 80 #ifdef CONFIG_PPC_FSL_BOOK3E 82 81 START_BTB_FLUSH_SECTION 83 82 BTB_FLUSH(r10) 84 83 END_BTB_FLUSH_SECTION 85 84 #endif 86 - ACCOUNT_CPU_USER_ENTRY(r13, r10, r11) 87 - std r2,GPR2(r1) 85 + ld r2,PACATOC(r13) 86 + mfcr r12 87 + li r11,0 88 + /* Can we avoid saving r3-r8 in common case? */ 88 89 std r3,GPR3(r1) 89 - mfcr r2 90 90 std r4,GPR4(r1) 91 91 std r5,GPR5(r1) 92 92 std r6,GPR6(r1) 93 93 std r7,GPR7(r1) 94 94 std r8,GPR8(r1) 95 - li r11,0 95 + /* Zero r9-r12, this should only be required when restoring all GPRs */ 96 96 std r11,GPR9(r1) 97 97 std r11,GPR10(r1) 98 98 std r11,GPR11(r1) 99 99 std r11,GPR12(r1) 100 + std r9,GPR13(r1) 101 + SAVE_NVGPRS(r1) 100 102 std r11,_XER(r1) 101 103 std r11,_CTR(r1) 102 - std r9,GPR13(r1) 103 104 mflr r10 105 + 104 106 /* 105 107 * This clears CR0.SO (bit 28), which is the error indication on 106 108 * return from this system call. 107 109 */ 108 - rldimi r2,r11,28,(63-28) 109 - li r11,0xc01 110 + rldimi r12,r11,28,(63-28) 111 + li r11,0xc00 110 112 std r10,_LINK(r1) 111 113 std r11,_TRAP(r1) 114 + std r12,_CCR(r1) 112 115 std r3,ORIG_GPR3(r1) 113 - std r2,_CCR(r1) 114 - ld r2,PACATOC(r13) 115 - addi r9,r1,STACK_FRAME_OVERHEAD 116 + addi r10,r1,STACK_FRAME_OVERHEAD 116 117 ld r11,exception_marker@toc(r2) 117 - std r11,-16(r9) /* "regshere" marker */ 118 - 119 - kuap_check_amr r10, r11 120 - 121 - #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR) 122 - BEGIN_FW_FTR_SECTION 123 - /* see if there are any DTL entries to process */ 124 - ld r10,PACALPPACAPTR(r13) /* get ptr to VPA */ 125 - ld r11,PACA_DTL_RIDX(r13) /* get log read index */ 126 - addi r10,r10,LPPACA_DTLIDX 127 - LDX_BE r10,0,r10 /* get log write index */ 128 - cmpd r11,r10 129 - beq+ 33f 130 - bl accumulate_stolen_time 131 - REST_GPR(0,r1) 132 - REST_4GPRS(3,r1) 133 - REST_2GPRS(7,r1) 134 - addi r9,r1,STACK_FRAME_OVERHEAD 135 - 33: 136 - END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR) 137 - #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE && CONFIG_PPC_SPLPAR */ 118 + std r11,-16(r10) /* "regshere" marker */ 138 119 139 120 /* 140 - * A syscall should always be called with interrupts enabled 141 - * so we just unconditionally hard-enable here. When some kind 142 - * of irq tracing is used, we additionally check that condition 143 - * is correct 121 + * RECONCILE_IRQ_STATE without calling trace_hardirqs_off(), which 122 + * would clobber syscall parameters. Also we always enter with IRQs 123 + * enabled and nothing pending. system_call_exception() will call 124 + * trace_hardirqs_off(). 144 125 */ 145 - #if defined(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG) && defined(CONFIG_BUG) 146 - lbz r10,PACAIRQSOFTMASK(r13) 147 - 1: tdnei r10,IRQS_ENABLED 148 - EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING 149 - #endif 126 + li r11,IRQS_ALL_DISABLED 127 + li r12,PACA_IRQ_HARD_DIS 128 + stb r11,PACAIRQSOFTMASK(r13) 129 + stb r12,PACAIRQHAPPENED(r13) 150 130 151 - #ifdef CONFIG_PPC_BOOK3E 152 - wrteei 1 153 - #else 154 - li r11,MSR_RI 155 - ori r11,r11,MSR_EE 156 - mtmsrd r11,1 157 - #endif /* CONFIG_PPC_BOOK3E */ 131 + /* Calling convention has r9 = orig r0, r10 = regs */ 132 + mr r9,r0 133 + bl system_call_exception 158 134 159 - system_call: /* label this so stack traces look sane */ 160 - /* We do need to set SOFTE in the stack frame or the return 161 - * from interrupt will be painful 162 - */ 163 - li r10,IRQS_ENABLED 164 - std r10,SOFTE(r1) 165 - 166 - ld r11, PACA_THREAD_INFO(r13) 167 - ld r10,TI_FLAGS(r11) 168 - andi. r11,r10,_TIF_SYSCALL_DOTRACE 169 - bne .Lsyscall_dotrace /* does not return */ 170 - cmpldi 0,r0,NR_syscalls 171 - bge- .Lsyscall_enosys 172 - 173 - .Lsyscall: 174 - /* 175 - * Need to vector to 32 Bit or default sys_call_table here, 176 - * based on caller's run-mode / personality. 177 - */ 178 - ld r11,SYS_CALL_TABLE@toc(2) 179 - andis. r10,r10,_TIF_32BIT@h 180 - beq 15f 181 - ld r11,COMPAT_SYS_CALL_TABLE@toc(2) 182 - clrldi r3,r3,32 183 - clrldi r4,r4,32 184 - clrldi r5,r5,32 185 - clrldi r6,r6,32 186 - clrldi r7,r7,32 187 - clrldi r8,r8,32 188 - 15: 189 - slwi r0,r0,3 190 - 191 - barrier_nospec_asm 192 - /* 193 - * Prevent the load of the handler below (based on the user-passed 194 - * system call number) being speculatively executed until the test 195 - * against NR_syscalls and branch to .Lsyscall_enosys above has 196 - * committed. 197 - */ 198 - 199 - ldx r12,r11,r0 /* Fetch system call handler [ptr] */ 200 - mtctr r12 201 - bctrl /* Call handler */ 202 - 203 - /* syscall_exit can exit to kernel mode, via ret_from_kernel_thread */ 204 135 .Lsyscall_exit: 205 - std r3,RESULT(r1) 136 + addi r4,r1,STACK_FRAME_OVERHEAD 137 + bl syscall_exit_prepare 206 138 207 - #ifdef CONFIG_DEBUG_RSEQ 208 - /* Check whether the syscall is issued inside a restartable sequence */ 209 - addi r3,r1,STACK_FRAME_OVERHEAD 210 - bl rseq_syscall 211 - ld r3,RESULT(r1) 212 - #endif 139 + ld r2,_CCR(r1) 140 + ld r4,_NIP(r1) 141 + ld r5,_MSR(r1) 142 + ld r6,_LINK(r1) 213 143 214 - ld r12, PACA_THREAD_INFO(r13) 215 - 216 - ld r8,_MSR(r1) 217 - 218 - /* 219 - * This is a few instructions into the actual syscall exit path (which actually 220 - * starts at .Lsyscall_exit) to cater to kprobe blacklisting and to reduce the 221 - * number of visible symbols for profiling purposes. 222 - * 223 - * We can probe from system_call until this point as MSR_RI is set. But once it 224 - * is cleared below, we won't be able to take a trap. 225 - * 226 - * This is blacklisted from kprobes further below with _ASM_NOKPROBE_SYMBOL(). 227 - */ 228 - system_call_exit: 229 - /* 230 - * Disable interrupts so current_thread_info()->flags can't change, 231 - * and so that we don't get interrupted after loading SRR0/1. 232 - * 233 - * Leave MSR_RI enabled for now, because with THREAD_INFO_IN_TASK we 234 - * could fault on the load of the TI_FLAGS below. 235 - */ 236 - #ifdef CONFIG_PPC_BOOK3E 237 - wrteei 0 238 - #else 239 - li r11,MSR_RI 240 - mtmsrd r11,1 241 - #endif /* CONFIG_PPC_BOOK3E */ 242 - 243 - ld r9,TI_FLAGS(r12) 244 - li r11,-MAX_ERRNO 245 - andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) 246 - bne- .Lsyscall_exit_work 247 - 248 - andi. r0,r8,MSR_FP 249 - beq 2f 250 - #ifdef CONFIG_ALTIVEC 251 - andis. r0,r8,MSR_VEC@h 252 - bne 3f 253 - #endif 254 - 2: addi r3,r1,STACK_FRAME_OVERHEAD 255 - bl restore_math 256 - ld r8,_MSR(r1) 257 - ld r3,RESULT(r1) 258 - li r11,-MAX_ERRNO 259 - 260 - 3: cmpld r3,r11 261 - ld r5,_CCR(r1) 262 - bge- .Lsyscall_error 263 - .Lsyscall_error_cont: 264 - ld r7,_NIP(r1) 265 144 BEGIN_FTR_SECTION 266 145 stdcx. r0,0,r1 /* to clear the reservation */ 267 146 END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 268 - andi. r6,r8,MSR_PR 269 - ld r4,_LINK(r1) 270 147 271 - kuap_check_amr r10, r11 148 + mtspr SPRN_SRR0,r4 149 + mtspr SPRN_SRR1,r5 150 + mtlr r6 272 151 273 - #ifdef CONFIG_PPC_BOOK3S 274 - /* 275 - * Clear MSR_RI, MSR_EE is already and remains disabled. We could do 276 - * this later, but testing shows that doing it here causes less slow 277 - * down than doing it closer to the rfid. 278 - */ 152 + cmpdi r3,0 153 + bne .Lsyscall_restore_regs 154 + /* Zero volatile regs that may contain sensitive kernel data */ 155 + li r0,0 156 + li r4,0 157 + li r5,0 158 + li r6,0 159 + li r7,0 160 + li r8,0 161 + li r9,0 162 + li r10,0 279 163 li r11,0 280 - mtmsrd r11,1 281 - #endif 282 - 283 - beq- 1f 284 - ACCOUNT_CPU_USER_EXIT(r13, r11, r12) 164 + li r12,0 165 + mtctr r0 166 + mtspr SPRN_XER,r0 167 + .Lsyscall_restore_regs_cont: 285 168 286 169 BEGIN_FTR_SECTION 287 170 HMT_MEDIUM_LOW 288 171 END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 289 172 290 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 291 - std r8, PACATMSCRATCH(r13) 292 - #endif 293 - 294 173 /* 295 174 * We don't need to restore AMR on the way back to userspace for KUAP. 296 175 * The value of AMR only matters while we're in the kernel. 297 176 */ 298 - ld r13,GPR13(r1) /* only restore r13 if returning to usermode */ 177 + mtcr r2 299 178 ld r2,GPR2(r1) 179 + ld r3,GPR3(r1) 180 + ld r13,GPR13(r1) 300 181 ld r1,GPR1(r1) 301 - mtlr r4 302 - mtcr r5 303 - mtspr SPRN_SRR0,r7 304 - mtspr SPRN_SRR1,r8 305 182 RFI_TO_USER 306 183 b . /* prevent speculative execution */ 307 184 308 - 1: /* exit to kernel */ 309 - kuap_restore_amr r2 310 - 311 - ld r2,GPR2(r1) 312 - ld r1,GPR1(r1) 313 - mtlr r4 314 - mtcr r5 315 - mtspr SPRN_SRR0,r7 316 - mtspr SPRN_SRR1,r8 317 - RFI_TO_KERNEL 318 - b . /* prevent speculative execution */ 319 - 320 - .Lsyscall_error: 321 - oris r5,r5,0x1000 /* Set SO bit in CR */ 322 - neg r3,r3 323 - std r5,_CCR(r1) 324 - b .Lsyscall_error_cont 325 - 326 - /* Traced system call support */ 327 - .Lsyscall_dotrace: 328 - bl save_nvgprs 329 - addi r3,r1,STACK_FRAME_OVERHEAD 330 - bl do_syscall_trace_enter 331 - 332 - /* 333 - * We use the return value of do_syscall_trace_enter() as the syscall 334 - * number. If the syscall was rejected for any reason do_syscall_trace_enter() 335 - * returns an invalid syscall number and the test below against 336 - * NR_syscalls will fail. 337 - */ 338 - mr r0,r3 339 - 340 - /* Restore argument registers just clobbered and/or possibly changed. */ 341 - ld r3,GPR3(r1) 342 - ld r4,GPR4(r1) 343 - ld r5,GPR5(r1) 344 - ld r6,GPR6(r1) 345 - ld r7,GPR7(r1) 346 - ld r8,GPR8(r1) 347 - 348 - /* Repopulate r9 and r10 for the syscall path */ 349 - addi r9,r1,STACK_FRAME_OVERHEAD 350 - ld r10, PACA_THREAD_INFO(r13) 351 - ld r10,TI_FLAGS(r10) 352 - 353 - cmpldi r0,NR_syscalls 354 - blt+ .Lsyscall 355 - 356 - /* Return code is already in r3 thanks to do_syscall_trace_enter() */ 357 - b .Lsyscall_exit 358 - 359 - 360 - .Lsyscall_enosys: 361 - li r3,-ENOSYS 362 - b .Lsyscall_exit 363 - 364 - .Lsyscall_exit_work: 365 - /* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr. 366 - If TIF_NOERROR is set, just save r3 as it is. */ 367 - 368 - andi. r0,r9,_TIF_RESTOREALL 369 - beq+ 0f 185 + .Lsyscall_restore_regs: 186 + ld r3,_CTR(r1) 187 + ld r4,_XER(r1) 370 188 REST_NVGPRS(r1) 371 - b 2f 372 - 0: cmpld r3,r11 /* r11 is -MAX_ERRNO */ 373 - blt+ 1f 374 - andi. r0,r9,_TIF_NOERROR 375 - bne- 1f 376 - ld r5,_CCR(r1) 377 - neg r3,r3 378 - oris r5,r5,0x1000 /* Set SO bit in CR */ 379 - std r5,_CCR(r1) 380 - 1: std r3,GPR3(r1) 381 - 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK) 382 - beq 4f 383 - 384 - /* Clear per-syscall TIF flags if any are set. */ 385 - 386 - li r11,_TIF_PERSYSCALL_MASK 387 - addi r12,r12,TI_FLAGS 388 - 3: ldarx r10,0,r12 389 - andc r10,r10,r11 390 - stdcx. r10,0,r12 391 - bne- 3b 392 - subi r12,r12,TI_FLAGS 393 - 394 - 4: /* Anything else left to do? */ 395 - BEGIN_FTR_SECTION 396 - lis r3,DEFAULT_PPR@highest /* Set default PPR */ 397 - sldi r3,r3,32 /* bits 11-13 are used for ppr */ 398 - std r3,_PPR(r1) 399 - END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 400 - 401 - andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP) 402 - beq ret_from_except_lite 403 - 404 - /* Re-enable interrupts */ 405 - #ifdef CONFIG_PPC_BOOK3E 406 - wrteei 1 407 - #else 408 - li r10,MSR_RI 409 - ori r10,r10,MSR_EE 410 - mtmsrd r10,1 411 - #endif /* CONFIG_PPC_BOOK3E */ 412 - 413 - bl save_nvgprs 414 - addi r3,r1,STACK_FRAME_OVERHEAD 415 - bl do_syscall_trace_leave 416 - b ret_from_except 189 + mtctr r3 190 + mtspr SPRN_XER,r4 191 + ld r0,GPR0(r1) 192 + REST_8GPRS(4, r1) 193 + ld r12,GPR12(r1) 194 + b .Lsyscall_restore_regs_cont 417 195 418 196 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 419 197 .Ltabort_syscall: ··· 221 439 RFI_TO_USER 222 440 b . /* prevent speculative execution */ 223 441 #endif 224 - _ASM_NOKPROBE_SYMBOL(system_call_common); 225 - _ASM_NOKPROBE_SYMBOL(system_call_exit); 226 - 227 - /* Save non-volatile GPRs, if not already saved. */ 228 - _GLOBAL(save_nvgprs) 229 - ld r11,_TRAP(r1) 230 - andi. r0,r11,1 231 - beqlr- 232 - SAVE_NVGPRS(r1) 233 - clrrdi r0,r11,1 234 - std r0,_TRAP(r1) 235 - blr 236 - _ASM_NOKPROBE_SYMBOL(save_nvgprs); 237 - 238 - 239 - /* 240 - * The sigsuspend and rt_sigsuspend system calls can call do_signal 241 - * and thus put the process into the stopped state where we might 242 - * want to examine its user state with ptrace. Therefore we need 243 - * to save all the nonvolatile registers (r14 - r31) before calling 244 - * the C code. Similarly, fork, vfork and clone need the full 245 - * register state on the stack so that it can be copied to the child. 246 - */ 247 - 248 - _GLOBAL(ppc_fork) 249 - bl save_nvgprs 250 - bl sys_fork 251 - b .Lsyscall_exit 252 - 253 - _GLOBAL(ppc_vfork) 254 - bl save_nvgprs 255 - bl sys_vfork 256 - b .Lsyscall_exit 257 - 258 - _GLOBAL(ppc_clone) 259 - bl save_nvgprs 260 - bl sys_clone 261 - b .Lsyscall_exit 262 - 263 - _GLOBAL(ppc_clone3) 264 - bl save_nvgprs 265 - bl sys_clone3 266 - b .Lsyscall_exit 267 - 268 - _GLOBAL(ppc32_swapcontext) 269 - bl save_nvgprs 270 - bl compat_sys_swapcontext 271 - b .Lsyscall_exit 272 - 273 - _GLOBAL(ppc64_swapcontext) 274 - bl save_nvgprs 275 - bl sys_swapcontext 276 - b .Lsyscall_exit 277 - 278 - _GLOBAL(ppc_switch_endian) 279 - bl save_nvgprs 280 - bl sys_switch_endian 281 - b .Lsyscall_exit 282 442 283 443 _GLOBAL(ret_from_fork) 284 444 bl schedule_tail ··· 239 515 blrl 240 516 li r3,0 241 517 b .Lsyscall_exit 518 + 519 + #ifdef CONFIG_PPC_BOOK3E 520 + /* Save non-volatile GPRs, if not already saved. */ 521 + _GLOBAL(save_nvgprs) 522 + ld r11,_TRAP(r1) 523 + andi. r0,r11,1 524 + beqlr- 525 + SAVE_NVGPRS(r1) 526 + clrrdi r0,r11,1 527 + std r0,_TRAP(r1) 528 + blr 529 + _ASM_NOKPROBE_SYMBOL(save_nvgprs); 530 + #endif 242 531 243 532 #ifdef CONFIG_PPC_BOOK3S_64 244 533 ··· 315 578 * state of one is saved on its kernel stack. Then the state 316 579 * of the other is restored from its kernel stack. The memory 317 580 * management hardware is updated to the second process's state. 318 - * Finally, we can return to the second process, via ret_from_except. 581 + * Finally, we can return to the second process, via interrupt_return. 319 582 * On entry, r3 points to the THREAD for the current task, r4 320 583 * points to the THREAD for the new task. 321 584 * ··· 467 730 addi r1,r1,SWITCH_FRAME_SIZE 468 731 blr 469 732 470 - .align 7 471 - _GLOBAL(ret_from_except) 472 - ld r11,_TRAP(r1) 473 - andi. r0,r11,1 474 - bne ret_from_except_lite 475 - REST_NVGPRS(r1) 476 - 477 - _GLOBAL(ret_from_except_lite) 733 + #ifdef CONFIG_PPC_BOOK3S 478 734 /* 479 - * Disable interrupts so that current_thread_info()->flags 480 - * can't change between when we test it and when we return 481 - * from the interrupt. 735 + * If MSR EE/RI was never enabled, IRQs not reconciled, NVGPRs not 736 + * touched, AMR not set, no exit work created, then this can be used. 482 737 */ 483 - #ifdef CONFIG_PPC_BOOK3E 484 - wrteei 0 485 - #else 486 - li r10,MSR_RI 487 - mtmsrd r10,1 /* Update machine state */ 488 - #endif /* CONFIG_PPC_BOOK3E */ 489 - 490 - ld r9, PACA_THREAD_INFO(r13) 491 - ld r3,_MSR(r1) 492 - #ifdef CONFIG_PPC_BOOK3E 493 - ld r10,PACACURRENT(r13) 494 - #endif /* CONFIG_PPC_BOOK3E */ 495 - ld r4,TI_FLAGS(r9) 496 - andi. r3,r3,MSR_PR 497 - beq resume_kernel 498 - #ifdef CONFIG_PPC_BOOK3E 499 - lwz r3,(THREAD+THREAD_DBCR0)(r10) 500 - #endif /* CONFIG_PPC_BOOK3E */ 501 - 502 - /* Check current_thread_info()->flags */ 503 - andi. r0,r4,_TIF_USER_WORK_MASK 504 - bne 1f 505 - #ifdef CONFIG_PPC_BOOK3E 506 - /* 507 - * Check to see if the dbcr0 register is set up to debug. 508 - * Use the internal debug mode bit to do this. 509 - */ 510 - andis. r0,r3,DBCR0_IDM@h 511 - beq restore 512 - mfmsr r0 513 - rlwinm r0,r0,0,~MSR_DE /* Clear MSR.DE */ 514 - mtmsr r0 515 - mtspr SPRN_DBCR0,r3 516 - li r10, -1 517 - mtspr SPRN_DBSR,r10 518 - b restore 519 - #else 738 + .balign IFETCH_ALIGN_BYTES 739 + .globl fast_interrupt_return 740 + fast_interrupt_return: 741 + _ASM_NOKPROBE_SYMBOL(fast_interrupt_return) 742 + ld r4,_MSR(r1) 743 + andi. r0,r4,MSR_PR 744 + bne .Lfast_user_interrupt_return 745 + andi. r0,r4,MSR_RI 746 + li r3,0 /* 0 return value, no EMULATE_STACK_STORE */ 747 + bne+ .Lfast_kernel_interrupt_return 520 748 addi r3,r1,STACK_FRAME_OVERHEAD 521 - bl restore_math 522 - b restore 523 - #endif 524 - 1: andi. r0,r4,_TIF_NEED_RESCHED 525 - beq 2f 526 - bl restore_interrupts 527 - SCHEDULE_USER 528 - b ret_from_except_lite 529 - 2: 530 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 531 - andi. r0,r4,_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM 532 - bne 3f /* only restore TM if nothing else to do */ 749 + bl unrecoverable_exception 750 + b . /* should not get here */ 751 + 752 + .balign IFETCH_ALIGN_BYTES 753 + .globl interrupt_return 754 + interrupt_return: 755 + _ASM_NOKPROBE_SYMBOL(interrupt_return) 756 + ld r4,_MSR(r1) 757 + andi. r0,r4,MSR_PR 758 + beq .Lkernel_interrupt_return 533 759 addi r3,r1,STACK_FRAME_OVERHEAD 534 - bl restore_tm_state 535 - b restore 536 - 3: 537 - #endif 538 - bl save_nvgprs 539 - /* 540 - * Use a non volatile GPR to save and restore our thread_info flags 541 - * across the call to restore_interrupts. 542 - */ 543 - mr r30,r4 544 - bl restore_interrupts 545 - mr r4,r30 546 - addi r3,r1,STACK_FRAME_OVERHEAD 547 - bl do_notify_resume 548 - b ret_from_except 760 + bl interrupt_exit_user_prepare 761 + cmpdi r3,0 762 + bne- .Lrestore_nvgprs 549 763 550 - resume_kernel: 551 - /* check current_thread_info, _TIF_EMULATE_STACK_STORE */ 552 - andis. r8,r4,_TIF_EMULATE_STACK_STORE@h 553 - beq+ 1f 764 + .Lfast_user_interrupt_return: 765 + ld r11,_NIP(r1) 766 + ld r12,_MSR(r1) 767 + BEGIN_FTR_SECTION 768 + ld r10,_PPR(r1) 769 + mtspr SPRN_PPR,r10 770 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 771 + mtspr SPRN_SRR0,r11 772 + mtspr SPRN_SRR1,r12 554 773 555 - addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */ 556 - 557 - ld r3,GPR1(r1) 558 - subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */ 559 - mr r4,r1 /* src: current exception frame */ 560 - mr r1,r3 /* Reroute the trampoline frame to r1 */ 561 - 562 - /* Copy from the original to the trampoline. */ 563 - li r5,INT_FRAME_SIZE/8 /* size: INT_FRAME_SIZE */ 564 - li r6,0 /* start offset: 0 */ 565 - mtctr r5 566 - 2: ldx r0,r6,r4 567 - stdx r0,r6,r3 568 - addi r6,r6,8 569 - bdnz 2b 570 - 571 - /* Do real store operation to complete stdu */ 572 - ld r5,GPR1(r1) 573 - std r8,0(r5) 574 - 575 - /* Clear _TIF_EMULATE_STACK_STORE flag */ 576 - lis r11,_TIF_EMULATE_STACK_STORE@h 577 - addi r5,r9,TI_FLAGS 578 - 0: ldarx r4,0,r5 579 - andc r4,r4,r11 580 - stdcx. r4,0,r5 581 - bne- 0b 582 - 1: 583 - 584 - #ifdef CONFIG_PREEMPTION 585 - /* Check if we need to preempt */ 586 - andi. r0,r4,_TIF_NEED_RESCHED 587 - beq+ restore 588 - /* Check that preempt_count() == 0 and interrupts are enabled */ 589 - lwz r8,TI_PREEMPT(r9) 590 - cmpwi cr0,r8,0 591 - bne restore 592 - ld r0,SOFTE(r1) 593 - andi. r0,r0,IRQS_DISABLED 594 - bne restore 595 - 596 - /* 597 - * Here we are preempting the current task. We want to make 598 - * sure we are soft-disabled first and reconcile irq state. 599 - */ 600 - RECONCILE_IRQ_STATE(r3,r4) 601 - bl preempt_schedule_irq 602 - 603 - /* 604 - * arch_local_irq_restore() from preempt_schedule_irq above may 605 - * enable hard interrupt but we really should disable interrupts 606 - * when we return from the interrupt, and so that we don't get 607 - * interrupted after loading SRR0/1. 608 - */ 609 - #ifdef CONFIG_PPC_BOOK3E 610 - wrteei 0 611 - #else 612 - li r10,MSR_RI 613 - mtmsrd r10,1 /* Update machine state */ 614 - #endif /* CONFIG_PPC_BOOK3E */ 615 - #endif /* CONFIG_PREEMPTION */ 616 - 617 - .globl fast_exc_return_irq 618 - fast_exc_return_irq: 619 - restore: 620 - /* 621 - * This is the main kernel exit path. First we check if we 622 - * are about to re-enable interrupts 623 - */ 624 - ld r5,SOFTE(r1) 625 - lbz r6,PACAIRQSOFTMASK(r13) 626 - andi. r5,r5,IRQS_DISABLED 627 - bne .Lrestore_irq_off 628 - 629 - /* We are enabling, were we already enabled ? Yes, just return */ 630 - andi. r6,r6,IRQS_DISABLED 631 - beq cr0,.Ldo_restore 632 - 633 - /* 634 - * We are about to soft-enable interrupts (we are hard disabled 635 - * at this point). We check if there's anything that needs to 636 - * be replayed first. 637 - */ 638 - lbz r0,PACAIRQHAPPENED(r13) 639 - cmpwi cr0,r0,0 640 - bne- .Lrestore_check_irq_replay 641 - 642 - /* 643 - * Get here when nothing happened while soft-disabled, just 644 - * soft-enable and move-on. We will hard-enable as a side 645 - * effect of rfi 646 - */ 647 - .Lrestore_no_replay: 648 - TRACE_ENABLE_INTS 649 - li r0,IRQS_ENABLED 650 - stb r0,PACAIRQSOFTMASK(r13); 651 - 652 - /* 653 - * Final return path. BookE is handled in a different file 654 - */ 655 - .Ldo_restore: 656 - #ifdef CONFIG_PPC_BOOK3E 657 - b exception_return_book3e 658 - #else 659 - /* 660 - * Clear the reservation. If we know the CPU tracks the address of 661 - * the reservation then we can potentially save some cycles and use 662 - * a larx. On POWER6 and POWER7 this is significantly faster. 663 - */ 664 774 BEGIN_FTR_SECTION 665 775 stdcx. r0,0,r1 /* to clear the reservation */ 666 776 FTR_SECTION_ELSE 667 - ldarx r4,0,r1 777 + ldarx r0,0,r1 668 778 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 669 779 670 - /* 671 - * Some code path such as load_up_fpu or altivec return directly 672 - * here. They run entirely hard disabled and do not alter the 673 - * interrupt state. They also don't use lwarx/stwcx. and thus 674 - * are known not to leave dangling reservations. 675 - */ 676 - .globl fast_exception_return 677 - fast_exception_return: 678 - ld r3,_MSR(r1) 679 - ld r4,_CTR(r1) 680 - ld r0,_LINK(r1) 681 - mtctr r4 682 - mtlr r0 683 - ld r4,_XER(r1) 684 - mtspr SPRN_XER,r4 780 + ld r3,_CCR(r1) 781 + ld r4,_LINK(r1) 782 + ld r5,_CTR(r1) 783 + ld r6,_XER(r1) 784 + li r0,0 685 785 686 - kuap_check_amr r5, r6 687 - 688 - REST_8GPRS(5, r1) 689 - 690 - andi. r0,r3,MSR_RI 691 - beq- .Lunrecov_restore 692 - 693 - /* 694 - * Clear RI before restoring r13. If we are returning to 695 - * userspace and we take an exception after restoring r13, 696 - * we end up corrupting the userspace r13 value. 697 - */ 698 - li r4,0 699 - mtmsrd r4,1 700 - 701 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 702 - /* TM debug */ 703 - std r3, PACATMSCRATCH(r13) /* Stash returned-to MSR */ 704 - #endif 705 - /* 706 - * r13 is our per cpu area, only restore it if we are returning to 707 - * userspace the value stored in the stack frame may belong to 708 - * another CPU. 709 - */ 710 - andi. r0,r3,MSR_PR 711 - beq 1f 712 - BEGIN_FTR_SECTION 713 - /* Restore PPR */ 714 - ld r2,_PPR(r1) 715 - mtspr SPRN_PPR,r2 716 - END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 717 - ACCOUNT_CPU_USER_EXIT(r13, r2, r4) 786 + REST_4GPRS(7, r1) 787 + REST_2GPRS(11, r1) 718 788 REST_GPR(13, r1) 719 789 720 - /* 721 - * We don't need to restore AMR on the way back to userspace for KUAP. 722 - * The value of AMR only matters while we're in the kernel. 723 - */ 724 - mtspr SPRN_SRR1,r3 790 + mtcr r3 791 + mtlr r4 792 + mtctr r5 793 + mtspr SPRN_XER,r6 725 794 726 - ld r2,_CCR(r1) 727 - mtcrf 0xFF,r2 728 - ld r2,_NIP(r1) 729 - mtspr SPRN_SRR0,r2 730 - 731 - ld r0,GPR0(r1) 732 - ld r2,GPR2(r1) 733 - ld r3,GPR3(r1) 734 - ld r4,GPR4(r1) 735 - ld r1,GPR1(r1) 795 + REST_4GPRS(2, r1) 796 + REST_GPR(6, r1) 797 + REST_GPR(0, r1) 798 + REST_GPR(1, r1) 736 799 RFI_TO_USER 737 800 b . /* prevent speculative execution */ 738 801 739 - 1: mtspr SPRN_SRR1,r3 802 + .Lrestore_nvgprs: 803 + REST_NVGPRS(r1) 804 + b .Lfast_user_interrupt_return 740 805 741 - ld r2,_CCR(r1) 742 - mtcrf 0xFF,r2 743 - ld r2,_NIP(r1) 744 - mtspr SPRN_SRR0,r2 806 + .balign IFETCH_ALIGN_BYTES 807 + .Lkernel_interrupt_return: 808 + addi r3,r1,STACK_FRAME_OVERHEAD 809 + bl interrupt_exit_kernel_prepare 810 + 811 + .Lfast_kernel_interrupt_return: 812 + cmpdi cr1,r3,0 813 + ld r11,_NIP(r1) 814 + ld r12,_MSR(r1) 815 + mtspr SPRN_SRR0,r11 816 + mtspr SPRN_SRR1,r12 817 + 818 + BEGIN_FTR_SECTION 819 + stdcx. r0,0,r1 /* to clear the reservation */ 820 + FTR_SECTION_ELSE 821 + ldarx r0,0,r1 822 + ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) 823 + 824 + ld r3,_LINK(r1) 825 + ld r4,_CTR(r1) 826 + ld r5,_XER(r1) 827 + ld r6,_CCR(r1) 828 + li r0,0 829 + 830 + REST_4GPRS(7, r1) 831 + REST_2GPRS(11, r1) 832 + 833 + mtlr r3 834 + mtctr r4 835 + mtspr SPRN_XER,r5 745 836 746 837 /* 747 838 * Leaving a stale exception_marker on the stack can confuse 748 839 * the reliable stack unwinder later on. Clear it. 749 840 */ 750 - li r2,0 751 - std r2,STACK_FRAME_OVERHEAD-16(r1) 841 + std r0,STACK_FRAME_OVERHEAD-16(r1) 752 842 753 - ld r0,GPR0(r1) 754 - ld r2,GPR2(r1) 755 - ld r3,GPR3(r1) 843 + REST_4GPRS(2, r1) 756 844 757 - kuap_restore_amr r4 758 - 759 - ld r4,GPR4(r1) 760 - ld r1,GPR1(r1) 845 + bne- cr1,1f /* emulate stack store */ 846 + mtcr r6 847 + REST_GPR(6, r1) 848 + REST_GPR(0, r1) 849 + REST_GPR(1, r1) 761 850 RFI_TO_KERNEL 762 851 b . /* prevent speculative execution */ 763 852 764 - #endif /* CONFIG_PPC_BOOK3E */ 765 - 766 - /* 767 - * We are returning to a context with interrupts soft disabled. 768 - * 769 - * However, we may also about to hard enable, so we need to 770 - * make sure that in this case, we also clear PACA_IRQ_HARD_DIS 771 - * or that bit can get out of sync and bad things will happen 853 + 1: /* 854 + * Emulate stack store with update. New r1 value was already calculated 855 + * and updated in our interrupt regs by emulate_loadstore, but we can't 856 + * store the previous value of r1 to the stack before re-loading our 857 + * registers from it, otherwise they could be clobbered. Use 858 + * PACA_EXGEN as temporary storage to hold the store data, as 859 + * interrupts are disabled here so it won't be clobbered. 772 860 */ 773 - .Lrestore_irq_off: 774 - ld r3,_MSR(r1) 775 - lbz r7,PACAIRQHAPPENED(r13) 776 - andi. r0,r3,MSR_EE 777 - beq 1f 778 - rlwinm r7,r7,0,~PACA_IRQ_HARD_DIS 779 - stb r7,PACAIRQHAPPENED(r13) 780 - 1: 781 - #if defined(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG) && defined(CONFIG_BUG) 782 - /* The interrupt should not have soft enabled. */ 783 - lbz r7,PACAIRQSOFTMASK(r13) 784 - 1: tdeqi r7,IRQS_ENABLED 785 - EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING 786 - #endif 787 - b .Ldo_restore 861 + mtcr r6 862 + std r9,PACA_EXGEN+0(r13) 863 + addi r9,r1,INT_FRAME_SIZE /* get original r1 */ 864 + REST_GPR(6, r1) 865 + REST_GPR(0, r1) 866 + REST_GPR(1, r1) 867 + std r9,0(r1) /* perform store component of stdu */ 868 + ld r9,PACA_EXGEN+0(r13) 788 869 789 - /* 790 - * Something did happen, check if a re-emit is needed 791 - * (this also clears paca->irq_happened) 792 - */ 793 - .Lrestore_check_irq_replay: 794 - /* XXX: We could implement a fast path here where we check 795 - * for irq_happened being just 0x01, in which case we can 796 - * clear it and return. That means that we would potentially 797 - * miss a decrementer having wrapped all the way around. 798 - * 799 - * Still, this might be useful for things like hash_page 800 - */ 801 - bl __check_irq_replay 802 - cmpwi cr0,r3,0 803 - beq .Lrestore_no_replay 804 - 805 - /* 806 - * We need to re-emit an interrupt. We do so by re-using our 807 - * existing exception frame. We first change the trap value, 808 - * but we need to ensure we preserve the low nibble of it 809 - */ 810 - ld r4,_TRAP(r1) 811 - clrldi r4,r4,60 812 - or r4,r4,r3 813 - std r4,_TRAP(r1) 814 - 815 - /* 816 - * PACA_IRQ_HARD_DIS won't always be set here, so set it now 817 - * to reconcile the IRQ state. Tracing is already accounted for. 818 - */ 819 - lbz r4,PACAIRQHAPPENED(r13) 820 - ori r4,r4,PACA_IRQ_HARD_DIS 821 - stb r4,PACAIRQHAPPENED(r13) 822 - 823 - /* 824 - * Then find the right handler and call it. Interrupts are 825 - * still soft-disabled and we keep them that way. 826 - */ 827 - cmpwi cr0,r3,0x500 828 - bne 1f 829 - addi r3,r1,STACK_FRAME_OVERHEAD; 830 - bl do_IRQ 831 - b ret_from_except 832 - 1: cmpwi cr0,r3,0xf00 833 - bne 1f 834 - addi r3,r1,STACK_FRAME_OVERHEAD; 835 - bl performance_monitor_exception 836 - b ret_from_except 837 - 1: cmpwi cr0,r3,0xe60 838 - bne 1f 839 - addi r3,r1,STACK_FRAME_OVERHEAD; 840 - bl handle_hmi_exception 841 - b ret_from_except 842 - 1: cmpwi cr0,r3,0x900 843 - bne 1f 844 - addi r3,r1,STACK_FRAME_OVERHEAD; 845 - bl timer_interrupt 846 - b ret_from_except 847 - #ifdef CONFIG_PPC_DOORBELL 848 - 1: 849 - #ifdef CONFIG_PPC_BOOK3E 850 - cmpwi cr0,r3,0x280 851 - #else 852 - cmpwi cr0,r3,0xa00 853 - #endif /* CONFIG_PPC_BOOK3E */ 854 - bne 1f 855 - addi r3,r1,STACK_FRAME_OVERHEAD; 856 - bl doorbell_exception 857 - #endif /* CONFIG_PPC_DOORBELL */ 858 - 1: b ret_from_except /* What else to do here ? */ 859 - 860 - .Lunrecov_restore: 861 - addi r3,r1,STACK_FRAME_OVERHEAD 862 - bl unrecoverable_exception 863 - b .Lunrecov_restore 864 - 865 - _ASM_NOKPROBE_SYMBOL(ret_from_except); 866 - _ASM_NOKPROBE_SYMBOL(ret_from_except_lite); 867 - _ASM_NOKPROBE_SYMBOL(resume_kernel); 868 - _ASM_NOKPROBE_SYMBOL(fast_exc_return_irq); 869 - _ASM_NOKPROBE_SYMBOL(restore); 870 - _ASM_NOKPROBE_SYMBOL(fast_exception_return); 871 - 870 + RFI_TO_KERNEL 871 + b . /* prevent speculative execution */ 872 + #endif /* CONFIG_PPC_BOOK3S */ 872 873 873 874 #ifdef CONFIG_PPC_RTAS 874 875 /*
+248 -39
arch/powerpc/kernel/exceptions-64e.S
··· 24 24 #include <asm/kvm_asm.h> 25 25 #include <asm/kvm_booke_hv_asm.h> 26 26 #include <asm/feature-fixups.h> 27 + #include <asm/context_tracking.h> 27 28 28 29 /* XXX This will ultimately add space for a special exception save 29 30 * structure used to save things like SRR0/SRR1, SPRGs, MAS, etc... ··· 1004 1003 masked_interrupt_book3e PACA_IRQ_DBELL 0 1005 1004 1006 1005 /* 1007 - * Called from arch_local_irq_enable when an interrupt needs 1008 - * to be resent. r3 contains either 0x500,0x900,0x260 or 0x280 1009 - * to indicate the kind of interrupt. MSR:EE is already off. 1010 - * We generate a stackframe like if a real interrupt had happened. 1011 - * 1012 - * Note: While MSR:EE is off, we need to make sure that _MSR 1013 - * in the generated frame has EE set to 1 or the exception 1014 - * handler will not properly re-enable them. 1015 - */ 1016 - _GLOBAL(__replay_interrupt) 1017 - /* We are going to jump to the exception common code which 1018 - * will retrieve various register values from the PACA which 1019 - * we don't give a damn about. 1020 - */ 1021 - mflr r10 1022 - mfmsr r11 1023 - mfcr r4 1024 - mtspr SPRN_SPRG_GEN_SCRATCH,r13; 1025 - std r1,PACA_EXGEN+EX_R1(r13); 1026 - stw r4,PACA_EXGEN+EX_CR(r13); 1027 - ori r11,r11,MSR_EE 1028 - subi r1,r1,INT_FRAME_SIZE; 1029 - cmpwi cr0,r3,0x500 1030 - beq exc_0x500_common 1031 - cmpwi cr0,r3,0x900 1032 - beq exc_0x900_common 1033 - cmpwi cr0,r3,0x280 1034 - beq exc_0x280_common 1035 - blr 1036 - 1037 - 1038 - /* 1039 1006 * This is called from 0x300 and 0x400 handlers after the prologs with 1040 1007 * r14 and r15 containing the fault address and error code, with the 1041 1008 * original values stashed away in the PACA ··· 1042 1073 bl alignment_exception 1043 1074 b ret_from_except 1044 1075 1045 - /* 1046 - * We branch here from entry_64.S for the last stage of the exception 1047 - * return code path. MSR:EE is expected to be off at that point 1048 - */ 1049 - _GLOBAL(exception_return_book3e) 1050 - b 1f 1076 + .align 7 1077 + _GLOBAL(ret_from_except) 1078 + ld r11,_TRAP(r1) 1079 + andi. r0,r11,1 1080 + bne ret_from_except_lite 1081 + REST_NVGPRS(r1) 1082 + 1083 + _GLOBAL(ret_from_except_lite) 1084 + /* 1085 + * Disable interrupts so that current_thread_info()->flags 1086 + * can't change between when we test it and when we return 1087 + * from the interrupt. 1088 + */ 1089 + wrteei 0 1090 + 1091 + ld r9, PACA_THREAD_INFO(r13) 1092 + ld r3,_MSR(r1) 1093 + ld r10,PACACURRENT(r13) 1094 + ld r4,TI_FLAGS(r9) 1095 + andi. r3,r3,MSR_PR 1096 + beq resume_kernel 1097 + lwz r3,(THREAD+THREAD_DBCR0)(r10) 1098 + 1099 + /* Check current_thread_info()->flags */ 1100 + andi. r0,r4,_TIF_USER_WORK_MASK 1101 + bne 1f 1102 + /* 1103 + * Check to see if the dbcr0 register is set up to debug. 1104 + * Use the internal debug mode bit to do this. 1105 + */ 1106 + andis. r0,r3,DBCR0_IDM@h 1107 + beq restore 1108 + mfmsr r0 1109 + rlwinm r0,r0,0,~MSR_DE /* Clear MSR.DE */ 1110 + mtmsr r0 1111 + mtspr SPRN_DBCR0,r3 1112 + li r10, -1 1113 + mtspr SPRN_DBSR,r10 1114 + b restore 1115 + 1: andi. r0,r4,_TIF_NEED_RESCHED 1116 + beq 2f 1117 + bl restore_interrupts 1118 + SCHEDULE_USER 1119 + b ret_from_except_lite 1120 + 2: 1121 + bl save_nvgprs 1122 + /* 1123 + * Use a non volatile GPR to save and restore our thread_info flags 1124 + * across the call to restore_interrupts. 1125 + */ 1126 + mr r30,r4 1127 + bl restore_interrupts 1128 + mr r4,r30 1129 + addi r3,r1,STACK_FRAME_OVERHEAD 1130 + bl do_notify_resume 1131 + b ret_from_except 1132 + 1133 + resume_kernel: 1134 + /* check current_thread_info, _TIF_EMULATE_STACK_STORE */ 1135 + andis. r8,r4,_TIF_EMULATE_STACK_STORE@h 1136 + beq+ 1f 1137 + 1138 + addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */ 1139 + 1140 + ld r3,GPR1(r1) 1141 + subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */ 1142 + mr r4,r1 /* src: current exception frame */ 1143 + mr r1,r3 /* Reroute the trampoline frame to r1 */ 1144 + 1145 + /* Copy from the original to the trampoline. */ 1146 + li r5,INT_FRAME_SIZE/8 /* size: INT_FRAME_SIZE */ 1147 + li r6,0 /* start offset: 0 */ 1148 + mtctr r5 1149 + 2: ldx r0,r6,r4 1150 + stdx r0,r6,r3 1151 + addi r6,r6,8 1152 + bdnz 2b 1153 + 1154 + /* Do real store operation to complete stdu */ 1155 + ld r5,GPR1(r1) 1156 + std r8,0(r5) 1157 + 1158 + /* Clear _TIF_EMULATE_STACK_STORE flag */ 1159 + lis r11,_TIF_EMULATE_STACK_STORE@h 1160 + addi r5,r9,TI_FLAGS 1161 + 0: ldarx r4,0,r5 1162 + andc r4,r4,r11 1163 + stdcx. r4,0,r5 1164 + bne- 0b 1165 + 1: 1166 + 1167 + #ifdef CONFIG_PREEMPT 1168 + /* Check if we need to preempt */ 1169 + andi. r0,r4,_TIF_NEED_RESCHED 1170 + beq+ restore 1171 + /* Check that preempt_count() == 0 and interrupts are enabled */ 1172 + lwz r8,TI_PREEMPT(r9) 1173 + cmpwi cr0,r8,0 1174 + bne restore 1175 + ld r0,SOFTE(r1) 1176 + andi. r0,r0,IRQS_DISABLED 1177 + bne restore 1178 + 1179 + /* 1180 + * Here we are preempting the current task. We want to make 1181 + * sure we are soft-disabled first and reconcile irq state. 1182 + */ 1183 + RECONCILE_IRQ_STATE(r3,r4) 1184 + bl preempt_schedule_irq 1185 + 1186 + /* 1187 + * arch_local_irq_restore() from preempt_schedule_irq above may 1188 + * enable hard interrupt but we really should disable interrupts 1189 + * when we return from the interrupt, and so that we don't get 1190 + * interrupted after loading SRR0/1. 1191 + */ 1192 + wrteei 0 1193 + #endif /* CONFIG_PREEMPT */ 1194 + 1195 + restore: 1196 + /* 1197 + * This is the main kernel exit path. First we check if we 1198 + * are about to re-enable interrupts 1199 + */ 1200 + ld r5,SOFTE(r1) 1201 + lbz r6,PACAIRQSOFTMASK(r13) 1202 + andi. r5,r5,IRQS_DISABLED 1203 + bne .Lrestore_irq_off 1204 + 1205 + /* We are enabling, were we already enabled ? Yes, just return */ 1206 + andi. r6,r6,IRQS_DISABLED 1207 + beq cr0,fast_exception_return 1208 + 1209 + /* 1210 + * We are about to soft-enable interrupts (we are hard disabled 1211 + * at this point). We check if there's anything that needs to 1212 + * be replayed first. 1213 + */ 1214 + lbz r0,PACAIRQHAPPENED(r13) 1215 + cmpwi cr0,r0,0 1216 + bne- .Lrestore_check_irq_replay 1217 + 1218 + /* 1219 + * Get here when nothing happened while soft-disabled, just 1220 + * soft-enable and move-on. We will hard-enable as a side 1221 + * effect of rfi 1222 + */ 1223 + .Lrestore_no_replay: 1224 + TRACE_ENABLE_INTS 1225 + li r0,IRQS_ENABLED 1226 + stb r0,PACAIRQSOFTMASK(r13); 1051 1227 1052 1228 /* This is the return from load_up_fpu fast path which could do with 1053 1229 * less GPR restores in fact, but for now we have a single return path 1054 1230 */ 1055 - .globl fast_exception_return 1056 1231 fast_exception_return: 1057 1232 wrteei 0 1058 1233 1: mr r0,r13 ··· 1236 1123 ld r11,PACA_EXGEN+EX_R11(r13) 1237 1124 mfspr r13,SPRN_SPRG_GEN_SCRATCH 1238 1125 rfi 1126 + 1127 + /* 1128 + * We are returning to a context with interrupts soft disabled. 1129 + * 1130 + * However, we may also about to hard enable, so we need to 1131 + * make sure that in this case, we also clear PACA_IRQ_HARD_DIS 1132 + * or that bit can get out of sync and bad things will happen 1133 + */ 1134 + .Lrestore_irq_off: 1135 + ld r3,_MSR(r1) 1136 + lbz r7,PACAIRQHAPPENED(r13) 1137 + andi. r0,r3,MSR_EE 1138 + beq 1f 1139 + rlwinm r7,r7,0,~PACA_IRQ_HARD_DIS 1140 + stb r7,PACAIRQHAPPENED(r13) 1141 + 1: 1142 + #if defined(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG) && defined(CONFIG_BUG) 1143 + /* The interrupt should not have soft enabled. */ 1144 + lbz r7,PACAIRQSOFTMASK(r13) 1145 + 1: tdeqi r7,IRQS_ENABLED 1146 + EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING 1147 + #endif 1148 + b fast_exception_return 1149 + 1150 + /* 1151 + * Something did happen, check if a re-emit is needed 1152 + * (this also clears paca->irq_happened) 1153 + */ 1154 + .Lrestore_check_irq_replay: 1155 + /* XXX: We could implement a fast path here where we check 1156 + * for irq_happened being just 0x01, in which case we can 1157 + * clear it and return. That means that we would potentially 1158 + * miss a decrementer having wrapped all the way around. 1159 + * 1160 + * Still, this might be useful for things like hash_page 1161 + */ 1162 + bl __check_irq_replay 1163 + cmpwi cr0,r3,0 1164 + beq .Lrestore_no_replay 1165 + 1166 + /* 1167 + * We need to re-emit an interrupt. We do so by re-using our 1168 + * existing exception frame. We first change the trap value, 1169 + * but we need to ensure we preserve the low nibble of it 1170 + */ 1171 + ld r4,_TRAP(r1) 1172 + clrldi r4,r4,60 1173 + or r4,r4,r3 1174 + std r4,_TRAP(r1) 1175 + 1176 + /* 1177 + * PACA_IRQ_HARD_DIS won't always be set here, so set it now 1178 + * to reconcile the IRQ state. Tracing is already accounted for. 1179 + */ 1180 + lbz r4,PACAIRQHAPPENED(r13) 1181 + ori r4,r4,PACA_IRQ_HARD_DIS 1182 + stb r4,PACAIRQHAPPENED(r13) 1183 + 1184 + /* 1185 + * Then find the right handler and call it. Interrupts are 1186 + * still soft-disabled and we keep them that way. 1187 + */ 1188 + cmpwi cr0,r3,0x500 1189 + bne 1f 1190 + addi r3,r1,STACK_FRAME_OVERHEAD; 1191 + bl do_IRQ 1192 + b ret_from_except 1193 + 1: cmpwi cr0,r3,0xf00 1194 + bne 1f 1195 + addi r3,r1,STACK_FRAME_OVERHEAD; 1196 + bl performance_monitor_exception 1197 + b ret_from_except 1198 + 1: cmpwi cr0,r3,0xe60 1199 + bne 1f 1200 + addi r3,r1,STACK_FRAME_OVERHEAD; 1201 + bl handle_hmi_exception 1202 + b ret_from_except 1203 + 1: cmpwi cr0,r3,0x900 1204 + bne 1f 1205 + addi r3,r1,STACK_FRAME_OVERHEAD; 1206 + bl timer_interrupt 1207 + b ret_from_except 1208 + #ifdef CONFIG_PPC_DOORBELL 1209 + 1: 1210 + cmpwi cr0,r3,0x280 1211 + bne 1f 1212 + addi r3,r1,STACK_FRAME_OVERHEAD; 1213 + bl doorbell_exception 1214 + #endif /* CONFIG_PPC_DOORBELL */ 1215 + 1: b ret_from_except /* What else to do here ? */ 1216 + 1217 + _ASM_NOKPROBE_SYMBOL(ret_from_except); 1218 + _ASM_NOKPROBE_SYMBOL(ret_from_except_lite); 1219 + _ASM_NOKPROBE_SYMBOL(resume_kernel); 1220 + _ASM_NOKPROBE_SYMBOL(restore); 1221 + _ASM_NOKPROBE_SYMBOL(fast_exception_return); 1239 1222 1240 1223 /* 1241 1224 * Trampolines used when spotting a bad kernel stack pointer in
+1389 -654
arch/powerpc/kernel/exceptions-64s.S
··· 32 32 #define EX_CCR 52 33 33 #define EX_CFAR 56 34 34 #define EX_PPR 64 35 - #if defined(CONFIG_RELOCATABLE) 36 35 #define EX_CTR 72 37 36 .if EX_SIZE != 10 38 37 .error "EX_SIZE is wrong" 39 38 .endif 40 - #else 41 - .if EX_SIZE != 9 42 - .error "EX_SIZE is wrong" 43 - .endif 44 - #endif 45 39 46 40 /* 47 41 * Following are fixed section helper macros. ··· 44 50 * EXC_VIRT_BEGIN/END - virt (AIL), unrelocated exception vectors 45 51 * TRAMP_REAL_BEGIN - real, unrelocated helpers (virt may call these) 46 52 * TRAMP_VIRT_BEGIN - virt, unreloc helpers (in practice, real can use) 47 - * TRAMP_KVM_BEGIN - KVM handlers, these are put into real, unrelocated 48 53 * EXC_COMMON - After switching to virtual, relocated mode. 49 54 */ 50 55 ··· 72 79 73 80 #define TRAMP_VIRT_BEGIN(name) \ 74 81 FIXED_SECTION_ENTRY_BEGIN(virt_trampolines, name) 75 - 76 - #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 77 - #define TRAMP_KVM_BEGIN(name) \ 78 - TRAMP_VIRT_BEGIN(name) 79 - #else 80 - #define TRAMP_KVM_BEGIN(name) 81 - #endif 82 82 83 83 #define EXC_REAL_NONE(start, size) \ 84 84 FIXED_SECTION_ENTRY_BEGIN_LOCATION(real_vectors, exc_real_##start##_##unused, start, size); \ ··· 105 119 ori reg,reg,(ABS_ADDR(label))@l; \ 106 120 addis reg,reg,(ABS_ADDR(label))@h 107 121 108 - /* Exception register prefixes */ 109 - #define EXC_HV_OR_STD 2 /* depends on HVMODE */ 110 - #define EXC_HV 1 111 - #define EXC_STD 0 112 - 113 - #if defined(CONFIG_RELOCATABLE) 114 - /* 115 - * If we support interrupts with relocation on AND we're a relocatable kernel, 116 - * we need to use CTR to get to the 2nd level handler. So, save/restore it 117 - * when required. 118 - */ 119 - #define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13) 120 - #define GET_CTR(reg, area) ld reg,area+EX_CTR(r13) 121 - #define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg 122 - #else 123 - /* ...else CTR is unused and in register. */ 124 - #define SAVE_CTR(reg, area) 125 - #define GET_CTR(reg, area) mfctr reg 126 - #define RESTORE_CTR(reg, area) 127 - #endif 128 - 129 - /* 130 - * PPR save/restore macros used in exceptions-64s.S 131 - * Used for P7 or later processors 132 - */ 133 - #define SAVE_PPR(area, ra) \ 134 - BEGIN_FTR_SECTION_NESTED(940) \ 135 - ld ra,area+EX_PPR(r13); /* Read PPR from paca */ \ 136 - std ra,_PPR(r1); \ 137 - END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940) 138 - 139 - #define RESTORE_PPR_PACA(area, ra) \ 140 - BEGIN_FTR_SECTION_NESTED(941) \ 141 - ld ra,area+EX_PPR(r13); \ 142 - mtspr SPRN_PPR,ra; \ 143 - END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941) 144 - 145 - /* 146 - * Get an SPR into a register if the CPU has the given feature 147 - */ 148 - #define OPT_GET_SPR(ra, spr, ftr) \ 149 - BEGIN_FTR_SECTION_NESTED(943) \ 150 - mfspr ra,spr; \ 151 - END_FTR_SECTION_NESTED(ftr,ftr,943) 152 - 153 - /* 154 - * Set an SPR from a register if the CPU has the given feature 155 - */ 156 - #define OPT_SET_SPR(ra, spr, ftr) \ 157 - BEGIN_FTR_SECTION_NESTED(943) \ 158 - mtspr spr,ra; \ 159 - END_FTR_SECTION_NESTED(ftr,ftr,943) 160 - 161 - /* 162 - * Save a register to the PACA if the CPU has the given feature 163 - */ 164 - #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \ 165 - BEGIN_FTR_SECTION_NESTED(943) \ 166 - std ra,offset(r13); \ 167 - END_FTR_SECTION_NESTED(ftr,ftr,943) 168 - 169 122 /* 170 123 * Branch to label using its 0xC000 address. This results in instruction 171 124 * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned ··· 118 193 mtctr reg; \ 119 194 bctr 120 195 121 - .macro INT_KVM_HANDLER name, vec, hsrr, area, skip 122 - TRAMP_KVM_BEGIN(\name\()_kvm) 123 - KVM_HANDLER \vec, \hsrr, \area, \skip 196 + /* 197 + * Interrupt code generation macros 198 + */ 199 + #define IVEC .L_IVEC_\name\() /* Interrupt vector address */ 200 + #define IHSRR .L_IHSRR_\name\() /* Sets SRR or HSRR registers */ 201 + #define IHSRR_IF_HVMODE .L_IHSRR_IF_HVMODE_\name\() /* HSRR if HV else SRR */ 202 + #define IAREA .L_IAREA_\name\() /* PACA save area */ 203 + #define IVIRT .L_IVIRT_\name\() /* Has virt mode entry point */ 204 + #define IISIDE .L_IISIDE_\name\() /* Uses SRR0/1 not DAR/DSISR */ 205 + #define IDAR .L_IDAR_\name\() /* Uses DAR (or SRR0) */ 206 + #define IDSISR .L_IDSISR_\name\() /* Uses DSISR (or SRR1) */ 207 + #define ISET_RI .L_ISET_RI_\name\() /* Run common code w/ MSR[RI]=1 */ 208 + #define IBRANCH_TO_COMMON .L_IBRANCH_TO_COMMON_\name\() /* ENTRY branch to common */ 209 + #define IREALMODE_COMMON .L_IREALMODE_COMMON_\name\() /* Common runs in realmode */ 210 + #define IMASK .L_IMASK_\name\() /* IRQ soft-mask bit */ 211 + #define IKVM_SKIP .L_IKVM_SKIP_\name\() /* Generate KVM skip handler */ 212 + #define IKVM_REAL .L_IKVM_REAL_\name\() /* Real entry tests KVM */ 213 + #define __IKVM_REAL(name) .L_IKVM_REAL_ ## name 214 + #define IKVM_VIRT .L_IKVM_VIRT_\name\() /* Virt entry tests KVM */ 215 + #define ISTACK .L_ISTACK_\name\() /* Set regular kernel stack */ 216 + #define __ISTACK(name) .L_ISTACK_ ## name 217 + #define IRECONCILE .L_IRECONCILE_\name\() /* Do RECONCILE_IRQ_STATE */ 218 + #define IKUAP .L_IKUAP_\name\() /* Do KUAP lock */ 219 + 220 + #define INT_DEFINE_BEGIN(n) \ 221 + .macro int_define_ ## n name 222 + 223 + #define INT_DEFINE_END(n) \ 224 + .endm ; \ 225 + int_define_ ## n n ; \ 226 + do_define_int n 227 + 228 + .macro do_define_int name 229 + .ifndef IVEC 230 + .error "IVEC not defined" 231 + .endif 232 + .ifndef IHSRR 233 + IHSRR=0 234 + .endif 235 + .ifndef IHSRR_IF_HVMODE 236 + IHSRR_IF_HVMODE=0 237 + .endif 238 + .ifndef IAREA 239 + IAREA=PACA_EXGEN 240 + .endif 241 + .ifndef IVIRT 242 + IVIRT=1 243 + .endif 244 + .ifndef IISIDE 245 + IISIDE=0 246 + .endif 247 + .ifndef IDAR 248 + IDAR=0 249 + .endif 250 + .ifndef IDSISR 251 + IDSISR=0 252 + .endif 253 + .ifndef ISET_RI 254 + ISET_RI=1 255 + .endif 256 + .ifndef IBRANCH_TO_COMMON 257 + IBRANCH_TO_COMMON=1 258 + .endif 259 + .ifndef IREALMODE_COMMON 260 + IREALMODE_COMMON=0 261 + .else 262 + .if ! IBRANCH_TO_COMMON 263 + .error "IREALMODE_COMMON=1 but IBRANCH_TO_COMMON=0" 264 + .endif 265 + .endif 266 + .ifndef IMASK 267 + IMASK=0 268 + .endif 269 + .ifndef IKVM_SKIP 270 + IKVM_SKIP=0 271 + .endif 272 + .ifndef IKVM_REAL 273 + IKVM_REAL=0 274 + .endif 275 + .ifndef IKVM_VIRT 276 + IKVM_VIRT=0 277 + .endif 278 + .ifndef ISTACK 279 + ISTACK=1 280 + .endif 281 + .ifndef IRECONCILE 282 + IRECONCILE=1 283 + .endif 284 + .ifndef IKUAP 285 + IKUAP=1 286 + .endif 124 287 .endm 125 288 126 289 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 127 290 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 128 291 /* 129 - * If hv is possible, interrupts come into to the hv version 130 - * of the kvmppc_interrupt code, which then jumps to the PR handler, 131 - * kvmppc_interrupt_pr, if the guest is a PR guest. 292 + * All interrupts which set HSRR registers, as well as SRESET and MCE and 293 + * syscall when invoked with "sc 1" switch to MSR[HV]=1 (HVMODE) to be taken, 294 + * so they all generally need to test whether they were taken in guest context. 295 + * 296 + * Note: SRESET and MCE may also be sent to the guest by the hypervisor, and be 297 + * taken with MSR[HV]=0. 298 + * 299 + * Interrupts which set SRR registers (with the above exceptions) do not 300 + * elevate to MSR[HV]=1 mode, though most can be taken when running with 301 + * MSR[HV]=1 (e.g., bare metal kernel and userspace). So these interrupts do 302 + * not need to test whether a guest is running because they get delivered to 303 + * the guest directly, including nested HV KVM guests. 304 + * 305 + * The exception is PR KVM, where the guest runs with MSR[PR]=1 and the host 306 + * runs with MSR[HV]=0, so the host takes all interrupts on behalf of the 307 + * guest. PR KVM runs with LPCR[AIL]=0 which causes interrupts to always be 308 + * delivered to the real-mode entry point, therefore such interrupts only test 309 + * KVM in their real mode handlers, and only when PR KVM is possible. 310 + * 311 + * Interrupts that are taken in MSR[HV]=0 and escalate to MSR[HV]=1 are always 312 + * delivered in real-mode when the MMU is in hash mode because the MMU 313 + * registers are not set appropriately to translate host addresses. In nested 314 + * radix mode these can be delivered in virt-mode as the host translations are 315 + * used implicitly (see: effective LPID, effective PID). 316 + */ 317 + 318 + /* 319 + * If an interrupt is taken while a guest is running, it is immediately routed 320 + * to KVM to handle. If both HV and PR KVM arepossible, KVM interrupts go first 321 + * to kvmppc_interrupt_hv, which handles the PR guest case. 132 322 */ 133 323 #define kvmppc_interrupt kvmppc_interrupt_hv 134 324 #else 135 325 #define kvmppc_interrupt kvmppc_interrupt_pr 136 326 #endif 137 327 138 - .macro KVMTEST name, hsrr, n 328 + .macro KVMTEST name 139 329 lbz r10,HSTATE_IN_GUEST(r13) 140 330 cmpwi r10,0 141 331 bne \name\()_kvm 142 332 .endm 143 333 144 - .macro KVM_HANDLER vec, hsrr, area, skip 145 - .if \skip 334 + .macro GEN_KVM name 335 + .balign IFETCH_ALIGN_BYTES 336 + \name\()_kvm: 337 + 338 + .if IKVM_SKIP 146 339 cmpwi r10,KVM_GUEST_MODE_SKIP 147 340 beq 89f 148 341 .else 149 - BEGIN_FTR_SECTION_NESTED(947) 150 - ld r10,\area+EX_CFAR(r13) 342 + BEGIN_FTR_SECTION 343 + ld r10,IAREA+EX_CFAR(r13) 151 344 std r10,HSTATE_CFAR(r13) 152 - END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947) 345 + END_FTR_SECTION_IFSET(CPU_FTR_CFAR) 153 346 .endif 154 347 155 - BEGIN_FTR_SECTION_NESTED(948) 156 - ld r10,\area+EX_PPR(r13) 348 + ld r10,PACA_EXGEN+EX_CTR(r13) 349 + mtctr r10 350 + BEGIN_FTR_SECTION 351 + ld r10,IAREA+EX_PPR(r13) 157 352 std r10,HSTATE_PPR(r13) 158 - END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948) 159 - ld r10,\area+EX_R10(r13) 353 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 354 + ld r11,IAREA+EX_R11(r13) 355 + ld r12,IAREA+EX_R12(r13) 160 356 std r12,HSTATE_SCRATCH0(r13) 161 357 sldi r12,r9,32 358 + ld r9,IAREA+EX_R9(r13) 359 + ld r10,IAREA+EX_R10(r13) 162 360 /* HSRR variants have the 0x2 bit added to their trap number */ 163 - .if \hsrr == EXC_HV_OR_STD 361 + .if IHSRR_IF_HVMODE 164 362 BEGIN_FTR_SECTION 165 - ori r12,r12,(\vec + 0x2) 363 + ori r12,r12,(IVEC + 0x2) 166 364 FTR_SECTION_ELSE 167 - ori r12,r12,(\vec) 365 + ori r12,r12,(IVEC) 168 366 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 169 - .elseif \hsrr 170 - ori r12,r12,(\vec + 0x2) 367 + .elseif IHSRR 368 + ori r12,r12,(IVEC+ 0x2) 171 369 .else 172 - ori r12,r12,(\vec) 370 + ori r12,r12,(IVEC) 173 371 .endif 174 - 175 - #ifdef CONFIG_RELOCATABLE 176 - /* 177 - * KVM requires __LOAD_FAR_HANDLER beause kvmppc_interrupt lives 178 - * outside the head section. CONFIG_RELOCATABLE KVM expects CTR 179 - * to be saved in HSTATE_SCRATCH1. 180 - */ 181 - mfctr r9 182 - std r9,HSTATE_SCRATCH1(r13) 183 - __LOAD_FAR_HANDLER(r9, kvmppc_interrupt) 184 - mtctr r9 185 - ld r9,\area+EX_R9(r13) 186 - bctr 187 - #else 188 - ld r9,\area+EX_R9(r13) 189 372 b kvmppc_interrupt 190 - #endif 191 373 192 - 193 - .if \skip 374 + .if IKVM_SKIP 194 375 89: mtocrf 0x80,r9 195 - ld r9,\area+EX_R9(r13) 196 - ld r10,\area+EX_R10(r13) 197 - .if \hsrr == EXC_HV_OR_STD 376 + ld r10,PACA_EXGEN+EX_CTR(r13) 377 + mtctr r10 378 + ld r9,IAREA+EX_R9(r13) 379 + ld r10,IAREA+EX_R10(r13) 380 + ld r11,IAREA+EX_R11(r13) 381 + ld r12,IAREA+EX_R12(r13) 382 + .if IHSRR_IF_HVMODE 198 383 BEGIN_FTR_SECTION 199 384 b kvmppc_skip_Hinterrupt 200 385 FTR_SECTION_ELSE 201 386 b kvmppc_skip_interrupt 202 387 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 203 - .elseif \hsrr 388 + .elseif IHSRR 204 389 b kvmppc_skip_Hinterrupt 205 390 .else 206 391 b kvmppc_skip_interrupt ··· 319 284 .endm 320 285 321 286 #else 322 - .macro KVMTEST name, hsrr, n 287 + .macro KVMTEST name 323 288 .endm 324 - .macro KVM_HANDLER name, vec, hsrr, area, skip 289 + .macro GEN_KVM name 325 290 .endm 326 291 #endif 327 - 328 - .macro INT_SAVE_SRR_AND_JUMP label, hsrr, set_ri 329 - ld r10,PACAKMSR(r13) /* get MSR value for kernel */ 330 - .if ! \set_ri 331 - xori r10,r10,MSR_RI /* Clear MSR_RI */ 332 - .endif 333 - .if \hsrr == EXC_HV_OR_STD 334 - BEGIN_FTR_SECTION 335 - mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 336 - mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 337 - mtspr SPRN_HSRR1,r10 338 - FTR_SECTION_ELSE 339 - mfspr r11,SPRN_SRR0 /* save SRR0 */ 340 - mfspr r12,SPRN_SRR1 /* and SRR1 */ 341 - mtspr SPRN_SRR1,r10 342 - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 343 - .elseif \hsrr 344 - mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 345 - mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 346 - mtspr SPRN_HSRR1,r10 347 - .else 348 - mfspr r11,SPRN_SRR0 /* save SRR0 */ 349 - mfspr r12,SPRN_SRR1 /* and SRR1 */ 350 - mtspr SPRN_SRR1,r10 351 - .endif 352 - LOAD_HANDLER(r10, \label\()) 353 - .if \hsrr == EXC_HV_OR_STD 354 - BEGIN_FTR_SECTION 355 - mtspr SPRN_HSRR0,r10 356 - HRFI_TO_KERNEL 357 - FTR_SECTION_ELSE 358 - mtspr SPRN_SRR0,r10 359 - RFI_TO_KERNEL 360 - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 361 - .elseif \hsrr 362 - mtspr SPRN_HSRR0,r10 363 - HRFI_TO_KERNEL 364 - .else 365 - mtspr SPRN_SRR0,r10 366 - RFI_TO_KERNEL 367 - .endif 368 - b . /* prevent speculative execution */ 369 - .endm 370 - 371 - /* INT_SAVE_SRR_AND_JUMP works for real or virt, this is faster but virt only */ 372 - .macro INT_VIRT_SAVE_SRR_AND_JUMP label, hsrr 373 - #ifdef CONFIG_RELOCATABLE 374 - .if \hsrr == EXC_HV_OR_STD 375 - BEGIN_FTR_SECTION 376 - mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 377 - FTR_SECTION_ELSE 378 - mfspr r11,SPRN_SRR0 /* save SRR0 */ 379 - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 380 - .elseif \hsrr 381 - mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 382 - .else 383 - mfspr r11,SPRN_SRR0 /* save SRR0 */ 384 - .endif 385 - LOAD_HANDLER(r12, \label\()) 386 - mtctr r12 387 - .if \hsrr == EXC_HV_OR_STD 388 - BEGIN_FTR_SECTION 389 - mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 390 - FTR_SECTION_ELSE 391 - mfspr r12,SPRN_SRR1 /* and HSRR1 */ 392 - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 393 - .elseif \hsrr 394 - mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 395 - .else 396 - mfspr r12,SPRN_SRR1 /* and HSRR1 */ 397 - .endif 398 - li r10,MSR_RI 399 - mtmsrd r10,1 /* Set RI (EE=0) */ 400 - bctr 401 - #else 402 - .if \hsrr == EXC_HV_OR_STD 403 - BEGIN_FTR_SECTION 404 - mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 405 - mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 406 - FTR_SECTION_ELSE 407 - mfspr r11,SPRN_SRR0 /* save SRR0 */ 408 - mfspr r12,SPRN_SRR1 /* and SRR1 */ 409 - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 410 - .elseif \hsrr 411 - mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 412 - mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 413 - .else 414 - mfspr r11,SPRN_SRR0 /* save SRR0 */ 415 - mfspr r12,SPRN_SRR1 /* and SRR1 */ 416 - .endif 417 - li r10,MSR_RI 418 - mtmsrd r10,1 /* Set RI (EE=0) */ 419 - b \label 420 - #endif 421 - .endm 422 292 423 293 /* 424 294 * This is the BOOK3S interrupt entry code macro. ··· 345 405 * - Fall through and continue executing in real, unrelocated mode. 346 406 * This is done if early=2. 347 407 */ 348 - .macro INT_HANDLER name, vec, ool=0, early=0, virt=0, hsrr=0, area=PACA_EXGEN, ri=1, dar=0, dsisr=0, bitmask=0, kvm=0 408 + 409 + .macro GEN_BRANCH_TO_COMMON name, virt 410 + .if IREALMODE_COMMON 411 + LOAD_HANDLER(r10, \name\()_common) 412 + mtctr r10 413 + bctr 414 + .else 415 + .if \virt 416 + #ifndef CONFIG_RELOCATABLE 417 + b \name\()_common_virt 418 + #else 419 + LOAD_HANDLER(r10, \name\()_common_virt) 420 + mtctr r10 421 + bctr 422 + #endif 423 + .else 424 + LOAD_HANDLER(r10, \name\()_common_real) 425 + mtctr r10 426 + bctr 427 + .endif 428 + .endif 429 + .endm 430 + 431 + .macro GEN_INT_ENTRY name, virt, ool=0 349 432 SET_SCRATCH0(r13) /* save r13 */ 350 433 GET_PACA(r13) 351 - std r9,\area\()+EX_R9(r13) /* save r9 */ 352 - OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR) 434 + std r9,IAREA+EX_R9(r13) /* save r9 */ 435 + BEGIN_FTR_SECTION 436 + mfspr r9,SPRN_PPR 437 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 353 438 HMT_MEDIUM 354 - std r10,\area\()+EX_R10(r13) /* save r10 - r12 */ 355 - OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR) 439 + std r10,IAREA+EX_R10(r13) /* save r10 - r12 */ 440 + BEGIN_FTR_SECTION 441 + mfspr r10,SPRN_CFAR 442 + END_FTR_SECTION_IFSET(CPU_FTR_CFAR) 356 443 .if \ool 357 444 .if !\virt 358 445 b tramp_real_\name ··· 392 425 .endif 393 426 .endif 394 427 395 - OPT_SAVE_REG_TO_PACA(\area\()+EX_PPR, r9, CPU_FTR_HAS_PPR) 396 - OPT_SAVE_REG_TO_PACA(\area\()+EX_CFAR, r10, CPU_FTR_CFAR) 428 + BEGIN_FTR_SECTION 429 + std r9,IAREA+EX_PPR(r13) 430 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 431 + BEGIN_FTR_SECTION 432 + std r10,IAREA+EX_CFAR(r13) 433 + END_FTR_SECTION_IFSET(CPU_FTR_CFAR) 397 434 INTERRUPT_TO_KERNEL 398 - SAVE_CTR(r10, \area\()) 435 + mfctr r10 436 + std r10,IAREA+EX_CTR(r13) 399 437 mfcr r9 400 - .if \kvm 401 - KVMTEST \name \hsrr \vec 402 - .endif 403 - .if \bitmask 404 - lbz r10,PACAIRQSOFTMASK(r13) 405 - andi. r10,r10,\bitmask 406 - /* Associate vector numbers with bits in paca->irq_happened */ 407 - .if \vec == 0x500 || \vec == 0xea0 408 - li r10,PACA_IRQ_EE 409 - .elseif \vec == 0x900 410 - li r10,PACA_IRQ_DEC 411 - .elseif \vec == 0xa00 || \vec == 0xe80 412 - li r10,PACA_IRQ_DBELL 413 - .elseif \vec == 0xe60 414 - li r10,PACA_IRQ_HMI 415 - .elseif \vec == 0xf00 416 - li r10,PACA_IRQ_PMI 417 - .else 418 - .abort "Bad maskable vector" 419 - .endif 420 - 421 - .if \hsrr == EXC_HV_OR_STD 422 - BEGIN_FTR_SECTION 423 - bne masked_Hinterrupt 424 - FTR_SECTION_ELSE 425 - bne masked_interrupt 426 - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 427 - .elseif \hsrr 428 - bne masked_Hinterrupt 429 - .else 430 - bne masked_interrupt 431 - .endif 432 - .endif 433 - 434 - std r11,\area\()+EX_R11(r13) 435 - std r12,\area\()+EX_R12(r13) 438 + std r11,IAREA+EX_R11(r13) 439 + std r12,IAREA+EX_R12(r13) 436 440 437 441 /* 438 442 * DAR/DSISR, SCRATCH0 must be read before setting MSR[RI], ··· 411 473 * not recoverable if they are live. 412 474 */ 413 475 GET_SCRATCH0(r10) 414 - std r10,\area\()+EX_R13(r13) 415 - .if \dar 416 - .if \hsrr 476 + std r10,IAREA+EX_R13(r13) 477 + .if IDAR && !IISIDE 478 + .if IHSRR 417 479 mfspr r10,SPRN_HDAR 418 480 .else 419 481 mfspr r10,SPRN_DAR 420 482 .endif 421 - std r10,\area\()+EX_DAR(r13) 483 + std r10,IAREA+EX_DAR(r13) 422 484 .endif 423 - .if \dsisr 424 - .if \hsrr 485 + .if IDSISR && !IISIDE 486 + .if IHSRR 425 487 mfspr r10,SPRN_HDSISR 426 488 .else 427 489 mfspr r10,SPRN_DSISR 428 490 .endif 429 - stw r10,\area\()+EX_DSISR(r13) 491 + stw r10,IAREA+EX_DSISR(r13) 430 492 .endif 431 493 432 - .if \early == 2 433 - /* nothing more */ 434 - .elseif \early 435 - mfctr r10 /* save ctr, even for !RELOCATABLE */ 436 - BRANCH_TO_C000(r11, \name\()_early_common) 437 - .elseif !\virt 438 - INT_SAVE_SRR_AND_JUMP \name\()_common, \hsrr, \ri 494 + .if IHSRR_IF_HVMODE 495 + BEGIN_FTR_SECTION 496 + mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 497 + mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 498 + FTR_SECTION_ELSE 499 + mfspr r11,SPRN_SRR0 /* save SRR0 */ 500 + mfspr r12,SPRN_SRR1 /* and SRR1 */ 501 + ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 502 + .elseif IHSRR 503 + mfspr r11,SPRN_HSRR0 /* save HSRR0 */ 504 + mfspr r12,SPRN_HSRR1 /* and HSRR1 */ 439 505 .else 440 - INT_VIRT_SAVE_SRR_AND_JUMP \name\()_common, \hsrr 506 + mfspr r11,SPRN_SRR0 /* save SRR0 */ 507 + mfspr r12,SPRN_SRR1 /* and SRR1 */ 441 508 .endif 509 + 510 + .if IBRANCH_TO_COMMON 511 + GEN_BRANCH_TO_COMMON \name \virt 512 + .endif 513 + 442 514 .if \ool 443 515 .popsection 444 516 .endif 445 517 .endm 446 518 447 519 /* 448 - * On entry r13 points to the paca, r9-r13 are saved in the paca, 449 - * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 450 - * SRR1, and relocation is on. 520 + * __GEN_COMMON_ENTRY is required to receive the branch from interrupt 521 + * entry, except in the case of the real-mode handlers which require 522 + * __GEN_REALMODE_COMMON_ENTRY. 451 523 * 452 - * If stack=0, then the stack is already set in r1, and r1 is saved in r10. 453 - * PPR save and CPU accounting is not done for the !stack case (XXX why not?) 524 + * This switches to virtual mode and sets MSR[RI]. 454 525 */ 455 - .macro INT_COMMON vec, area, stack, kuap, reconcile, dar, dsisr 456 - .if \stack 526 + .macro __GEN_COMMON_ENTRY name 527 + DEFINE_FIXED_SYMBOL(\name\()_common_real) 528 + \name\()_common_real: 529 + .if IKVM_REAL 530 + KVMTEST \name 531 + .endif 532 + 533 + ld r10,PACAKMSR(r13) /* get MSR value for kernel */ 534 + /* MSR[RI] is clear iff using SRR regs */ 535 + .if IHSRR == EXC_HV_OR_STD 536 + BEGIN_FTR_SECTION 537 + xori r10,r10,MSR_RI 538 + END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE) 539 + .elseif ! IHSRR 540 + xori r10,r10,MSR_RI 541 + .endif 542 + mtmsrd r10 543 + 544 + .if IVIRT 545 + .if IKVM_VIRT 546 + b 1f /* skip the virt test coming from real */ 547 + .endif 548 + 549 + .balign IFETCH_ALIGN_BYTES 550 + DEFINE_FIXED_SYMBOL(\name\()_common_virt) 551 + \name\()_common_virt: 552 + .if IKVM_VIRT 553 + KVMTEST \name 554 + 1: 555 + .endif 556 + .endif /* IVIRT */ 557 + .endm 558 + 559 + /* 560 + * Don't switch to virt mode. Used for early MCE and HMI handlers that 561 + * want to run in real mode. 562 + */ 563 + .macro __GEN_REALMODE_COMMON_ENTRY name 564 + DEFINE_FIXED_SYMBOL(\name\()_common_real) 565 + \name\()_common_real: 566 + .if IKVM_REAL 567 + KVMTEST \name 568 + .endif 569 + .endm 570 + 571 + .macro __GEN_COMMON_BODY name 572 + .if IMASK 573 + lbz r10,PACAIRQSOFTMASK(r13) 574 + andi. r10,r10,IMASK 575 + /* Associate vector numbers with bits in paca->irq_happened */ 576 + .if IVEC == 0x500 || IVEC == 0xea0 577 + li r10,PACA_IRQ_EE 578 + .elseif IVEC == 0x900 579 + li r10,PACA_IRQ_DEC 580 + .elseif IVEC == 0xa00 || IVEC == 0xe80 581 + li r10,PACA_IRQ_DBELL 582 + .elseif IVEC == 0xe60 583 + li r10,PACA_IRQ_HMI 584 + .elseif IVEC == 0xf00 585 + li r10,PACA_IRQ_PMI 586 + .else 587 + .abort "Bad maskable vector" 588 + .endif 589 + 590 + .if IHSRR_IF_HVMODE 591 + BEGIN_FTR_SECTION 592 + bne masked_Hinterrupt 593 + FTR_SECTION_ELSE 594 + bne masked_interrupt 595 + ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 596 + .elseif IHSRR 597 + bne masked_Hinterrupt 598 + .else 599 + bne masked_interrupt 600 + .endif 601 + .endif 602 + 603 + .if ISTACK 457 604 andi. r10,r12,MSR_PR /* See if coming from user */ 458 605 mr r10,r1 /* Save r1 */ 459 606 subi r1,r1,INT_FRAME_SIZE /* alloc frame on kernel stack */ ··· 555 532 std r0,GPR0(r1) /* save r0 in stackframe */ 556 533 std r10,GPR1(r1) /* save r1 in stackframe */ 557 534 558 - .if \stack 559 - .if \kuap 535 + .if ISET_RI 536 + li r10,MSR_RI 537 + mtmsrd r10,1 /* Set MSR_RI */ 538 + .endif 539 + 540 + .if ISTACK 541 + .if IKUAP 560 542 kuap_save_amr_and_lock r9, r10, cr1, cr0 561 543 .endif 562 544 beq 101f /* if from kernel mode */ 563 545 ACCOUNT_CPU_USER_ENTRY(r13, r9, r10) 564 - SAVE_PPR(\area, r9) 546 + BEGIN_FTR_SECTION 547 + ld r9,IAREA+EX_PPR(r13) /* Read PPR from paca */ 548 + std r9,_PPR(r1) 549 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 565 550 101: 566 551 .else 567 - .if \kuap 552 + .if IKUAP 568 553 kuap_save_amr_and_lock r9, r10, cr1 569 554 .endif 570 555 .endif 571 556 572 557 /* Save original regs values from save area to stack frame. */ 573 - ld r9,\area+EX_R9(r13) /* move r9, r10 to stackframe */ 574 - ld r10,\area+EX_R10(r13) 558 + ld r9,IAREA+EX_R9(r13) /* move r9, r10 to stackframe */ 559 + ld r10,IAREA+EX_R10(r13) 575 560 std r9,GPR9(r1) 576 561 std r10,GPR10(r1) 577 - ld r9,\area+EX_R11(r13) /* move r11 - r13 to stackframe */ 578 - ld r10,\area+EX_R12(r13) 579 - ld r11,\area+EX_R13(r13) 562 + ld r9,IAREA+EX_R11(r13) /* move r11 - r13 to stackframe */ 563 + ld r10,IAREA+EX_R12(r13) 564 + ld r11,IAREA+EX_R13(r13) 580 565 std r9,GPR11(r1) 581 566 std r10,GPR12(r1) 582 567 std r11,GPR13(r1) 583 - .if \dar 584 - .if \dar == 2 568 + 569 + SAVE_NVGPRS(r1) 570 + 571 + .if IDAR 572 + .if IISIDE 585 573 ld r10,_NIP(r1) 586 574 .else 587 - ld r10,\area+EX_DAR(r13) 575 + ld r10,IAREA+EX_DAR(r13) 588 576 .endif 589 577 std r10,_DAR(r1) 590 578 .endif 591 - .if \dsisr 592 - .if \dsisr == 2 579 + 580 + .if IDSISR 581 + .if IISIDE 593 582 ld r10,_MSR(r1) 594 583 lis r11,DSISR_SRR1_MATCH_64S@h 595 584 and r10,r10,r11 596 585 .else 597 - lwz r10,\area+EX_DSISR(r13) 586 + lwz r10,IAREA+EX_DSISR(r13) 598 587 .endif 599 588 std r10,_DSISR(r1) 600 589 .endif 601 - BEGIN_FTR_SECTION_NESTED(66) 602 - ld r10,\area+EX_CFAR(r13) 590 + 591 + BEGIN_FTR_SECTION 592 + ld r10,IAREA+EX_CFAR(r13) 603 593 std r10,ORIG_GPR3(r1) 604 - END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66) 605 - GET_CTR(r10, \area) 594 + END_FTR_SECTION_IFSET(CPU_FTR_CFAR) 595 + ld r10,IAREA+EX_CTR(r13) 606 596 std r10,_CTR(r1) 607 597 std r2,GPR2(r1) /* save r2 in stackframe */ 608 598 SAVE_4GPRS(3, r1) /* save r3 - r6 in stackframe */ ··· 627 591 mfspr r11,SPRN_XER /* save XER in stackframe */ 628 592 std r10,SOFTE(r1) 629 593 std r11,_XER(r1) 630 - li r9,(\vec)+1 594 + li r9,IVEC 631 595 std r9,_TRAP(r1) /* set trap number */ 632 596 li r10,0 633 597 ld r11,exception_marker@toc(r2) 634 598 std r10,RESULT(r1) /* clear regs->result */ 635 599 std r11,STACK_FRAME_OVERHEAD-16(r1) /* mark the frame */ 636 600 637 - .if \stack 601 + .if ISTACK 638 602 ACCOUNT_STOLEN_TIME 639 603 .endif 640 604 641 - .if \reconcile 605 + .if IRECONCILE 642 606 RECONCILE_IRQ_STATE(r10, r11) 643 607 .endif 608 + .endm 609 + 610 + /* 611 + * On entry r13 points to the paca, r9-r13 are saved in the paca, 612 + * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 613 + * SRR1, and relocation is on. 614 + * 615 + * If stack=0, then the stack is already set in r1, and r1 is saved in r10. 616 + * PPR save and CPU accounting is not done for the !stack case (XXX why not?) 617 + */ 618 + .macro GEN_COMMON name 619 + __GEN_COMMON_ENTRY \name 620 + __GEN_COMMON_BODY \name 644 621 .endm 645 622 646 623 /* 647 624 * Restore all registers including H/SRR0/1 saved in a stack frame of a 648 625 * standard exception. 649 626 */ 650 - .macro EXCEPTION_RESTORE_REGS hsrr 627 + .macro EXCEPTION_RESTORE_REGS hsrr=0 651 628 /* Move original SRR0 and SRR1 into the respective regs */ 652 629 ld r9,_MSR(r1) 653 - .if \hsrr == EXC_HV_OR_STD 654 - .error "EXC_HV_OR_STD Not implemented for EXCEPTION_RESTORE_REGS" 655 - .endif 656 630 .if \hsrr 657 631 mtspr SPRN_HSRR1,r9 658 632 .else ··· 715 669 #else 716 670 #define FINISH_NAP 717 671 #endif 718 - 719 - #define EXC_COMMON(name, realvec, hdlr) \ 720 - EXC_COMMON_BEGIN(name); \ 721 - INT_COMMON realvec, PACA_EXGEN, 1, 1, 1, 0, 0 ; \ 722 - bl save_nvgprs; \ 723 - addi r3,r1,STACK_FRAME_OVERHEAD; \ 724 - bl hdlr; \ 725 - b ret_from_except 726 - 727 - /* 728 - * Like EXC_COMMON, but for exceptions that can occur in the idle task and 729 - * therefore need the special idle handling (finish nap and runlatch) 730 - */ 731 - #define EXC_COMMON_ASYNC(name, realvec, hdlr) \ 732 - EXC_COMMON_BEGIN(name); \ 733 - INT_COMMON realvec, PACA_EXGEN, 1, 1, 1, 0, 0 ; \ 734 - FINISH_NAP; \ 735 - RUNLATCH_ON; \ 736 - addi r3,r1,STACK_FRAME_OVERHEAD; \ 737 - bl hdlr; \ 738 - b ret_from_except_lite 739 - 740 672 741 673 /* 742 674 * There are a few constraints to be concerned with. ··· 802 778 EXC_VIRT_NONE(0x4000, 0x100) 803 779 804 780 781 + /** 782 + * Interrupt 0x100 - System Reset Interrupt (SRESET aka NMI). 783 + * This is a non-maskable, asynchronous interrupt always taken in real-mode. 784 + * It is caused by: 785 + * - Wake from power-saving state, on powernv. 786 + * - An NMI from another CPU, triggered by firmware or hypercall. 787 + * - As crash/debug signal injected from BMC, firmware or hypervisor. 788 + * 789 + * Handling: 790 + * Power-save wakeup is the only performance critical path, so this is 791 + * determined quickly as possible first. In this case volatile registers 792 + * can be discarded and SPRs like CFAR don't need to be read. 793 + * 794 + * If not a powersave wakeup, then it's run as a regular interrupt, however 795 + * it uses its own stack and PACA save area to preserve the regular kernel 796 + * environment for debugging. 797 + * 798 + * This interrupt is not maskable, so triggering it when MSR[RI] is clear, 799 + * or SCRATCH0 is in use, etc. may cause a crash. It's also not entirely 800 + * correct to switch to virtual mode to run the regular interrupt handler 801 + * because it might be interrupted when the MMU is in a bad state (e.g., SLB 802 + * is clear). 803 + * 804 + * FWNMI: 805 + * PAPR specifies a "fwnmi" facility which sends the sreset to a different 806 + * entry point with a different register set up. Some hypervisors will 807 + * send the sreset to 0x100 in the guest if it is not fwnmi capable. 808 + * 809 + * KVM: 810 + * Unlike most SRR interrupts, this may be taken by the host while executing 811 + * in a guest, so a KVM test is required. KVM will pull the CPU out of guest 812 + * mode and then raise the sreset. 813 + */ 814 + INT_DEFINE_BEGIN(system_reset) 815 + IVEC=0x100 816 + IAREA=PACA_EXNMI 817 + IVIRT=0 /* no virt entry point */ 818 + /* 819 + * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is 820 + * being used, so a nested NMI exception would corrupt it. 821 + */ 822 + ISET_RI=0 823 + ISTACK=0 824 + IRECONCILE=0 825 + IKVM_REAL=1 826 + INT_DEFINE_END(system_reset) 827 + 805 828 EXC_REAL_BEGIN(system_reset, 0x100, 0x100) 806 829 #ifdef CONFIG_PPC_P7_NAP 807 830 /* ··· 886 815 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) 887 816 #endif 888 817 889 - INT_HANDLER system_reset, 0x100, area=PACA_EXNMI, ri=0, kvm=1 818 + GEN_INT_ENTRY system_reset, virt=0 890 819 /* 891 - * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is 892 - * being used, so a nested NMI exception would corrupt it. 893 - * 894 820 * In theory, we should not enable relocation here if it was disabled 895 821 * in SRR1, because the MMU may not be configured to support it (e.g., 896 822 * SLB may have been cleared). In practice, there should only be a few ··· 896 828 */ 897 829 EXC_REAL_END(system_reset, 0x100, 0x100) 898 830 EXC_VIRT_NONE(0x4100, 0x100) 899 - INT_KVM_HANDLER system_reset 0x100, EXC_STD, PACA_EXNMI, 0 900 831 901 832 #ifdef CONFIG_PPC_P7_NAP 902 833 TRAMP_REAL_BEGIN(system_reset_idle_wake) ··· 910 843 * Vectors for the FWNMI option. Share common code. 911 844 */ 912 845 TRAMP_REAL_BEGIN(system_reset_fwnmi) 913 - /* See comment at system_reset exception, don't turn on RI */ 914 - INT_HANDLER system_reset, 0x100, area=PACA_EXNMI, ri=0 846 + /* XXX: fwnmi guest could run a nested/PR guest, so why no test? */ 847 + __IKVM_REAL(system_reset)=0 848 + GEN_INT_ENTRY system_reset, virt=0 915 849 916 850 #endif /* CONFIG_PPC_PSERIES */ 917 851 918 852 EXC_COMMON_BEGIN(system_reset_common) 853 + __GEN_COMMON_ENTRY system_reset 919 854 /* 920 855 * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able 921 856 * to recover, but nested NMI will notice in_nmi and not recover ··· 933 864 mr r10,r1 934 865 ld r1,PACA_NMI_EMERG_SP(r13) 935 866 subi r1,r1,INT_FRAME_SIZE 936 - INT_COMMON 0x100, PACA_EXNMI, 0, 1, 0, 0, 0 937 - bl save_nvgprs 867 + __GEN_COMMON_BODY system_reset 938 868 /* 939 - * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does 869 + * Set IRQS_ALL_DISABLED unconditionally so irqs_disabled() does 940 870 * the right thing. We do not want to reconcile because that goes 941 871 * through irq tracing which we don't want in NMI. 942 872 * 943 - * Save PACAIRQHAPPENED because some code will do a hard disable 944 - * (e.g., xmon). So we want to restore this back to where it was 945 - * when we return. DAR is unused in the stack, so save it there. 873 + * Save PACAIRQHAPPENED to _DAR (otherwise unused), and set HARD_DIS 874 + * as we are running with MSR[EE]=0. 946 875 */ 947 876 li r10,IRQS_ALL_DISABLED 948 877 stb r10,PACAIRQSOFTMASK(r13) 949 878 lbz r10,PACAIRQHAPPENED(r13) 950 879 std r10,_DAR(r1) 880 + ori r10,r10,PACA_IRQ_HARD_DIS 881 + stb r10,PACAIRQHAPPENED(r13) 951 882 952 883 addi r3,r1,STACK_FRAME_OVERHEAD 953 884 bl system_reset_exception ··· 971 902 ld r10,SOFTE(r1) 972 903 stb r10,PACAIRQSOFTMASK(r13) 973 904 974 - EXCEPTION_RESTORE_REGS EXC_STD 905 + EXCEPTION_RESTORE_REGS 975 906 RFI_TO_USER_OR_KERNEL 976 907 908 + GEN_KVM system_reset 977 909 978 - EXC_REAL_BEGIN(machine_check, 0x200, 0x100) 979 - INT_HANDLER machine_check, 0x200, early=1, area=PACA_EXMC, dar=1, dsisr=1 910 + 911 + /** 912 + * Interrupt 0x200 - Machine Check Interrupt (MCE). 913 + * This is a non-maskable interrupt always taken in real-mode. It can be 914 + * synchronous or asynchronous, caused by hardware or software, and it may be 915 + * taken in a power-saving state. 916 + * 917 + * Handling: 918 + * Similarly to system reset, this uses its own stack and PACA save area, 919 + * the difference is re-entrancy is allowed on the machine check stack. 920 + * 921 + * machine_check_early is run in real mode, and carefully decodes the 922 + * machine check and tries to handle it (e.g., flush the SLB if there was an 923 + * error detected there), determines if it was recoverable and logs the 924 + * event. 925 + * 926 + * This early code does not "reconcile" irq soft-mask state like SRESET or 927 + * regular interrupts do, so irqs_disabled() among other things may not work 928 + * properly (irq disable/enable already doesn't work because irq tracing can 929 + * not work in real mode). 930 + * 931 + * Then, depending on the execution context when the interrupt is taken, there 932 + * are 3 main actions: 933 + * - Executing in kernel mode. The event is queued with irq_work, which means 934 + * it is handled when it is next safe to do so (i.e., the kernel has enabled 935 + * interrupts), which could be immediately when the interrupt returns. This 936 + * avoids nasty issues like switching to virtual mode when the MMU is in a 937 + * bad state, or when executing OPAL code. (SRESET is exposed to such issues, 938 + * but it has different priorities). Check to see if the CPU was in power 939 + * save, and return via the wake up code if it was. 940 + * 941 + * - Executing in user mode. machine_check_exception is run like a normal 942 + * interrupt handler, which processes the data generated by the early handler. 943 + * 944 + * - Executing in guest mode. The interrupt is run with its KVM test, and 945 + * branches to KVM to deal with. KVM may queue the event for the host 946 + * to report later. 947 + * 948 + * This interrupt is not maskable, so if it triggers when MSR[RI] is clear, 949 + * or SCRATCH0 is in use, it may cause a crash. 950 + * 951 + * KVM: 952 + * See SRESET. 953 + */ 954 + INT_DEFINE_BEGIN(machine_check_early) 955 + IVEC=0x200 956 + IAREA=PACA_EXMC 957 + IVIRT=0 /* no virt entry point */ 958 + IREALMODE_COMMON=1 980 959 /* 981 960 * MSR_RI is not enabled, because PACA_EXMC is being used, so a 982 961 * nested machine check corrupts it. machine_check_common enables 983 962 * MSR_RI. 984 963 */ 964 + ISET_RI=0 965 + ISTACK=0 966 + IDAR=1 967 + IDSISR=1 968 + IRECONCILE=0 969 + IKUAP=0 /* We don't touch AMR here, we never go to virtual mode */ 970 + INT_DEFINE_END(machine_check_early) 971 + 972 + INT_DEFINE_BEGIN(machine_check) 973 + IVEC=0x200 974 + IAREA=PACA_EXMC 975 + IVIRT=0 /* no virt entry point */ 976 + ISET_RI=0 977 + IDAR=1 978 + IDSISR=1 979 + IKVM_SKIP=1 980 + IKVM_REAL=1 981 + INT_DEFINE_END(machine_check) 982 + 983 + EXC_REAL_BEGIN(machine_check, 0x200, 0x100) 984 + GEN_INT_ENTRY machine_check_early, virt=0 985 985 EXC_REAL_END(machine_check, 0x200, 0x100) 986 986 EXC_VIRT_NONE(0x4200, 0x100) 987 987 988 988 #ifdef CONFIG_PPC_PSERIES 989 989 TRAMP_REAL_BEGIN(machine_check_fwnmi) 990 990 /* See comment at machine_check exception, don't turn on RI */ 991 - INT_HANDLER machine_check, 0x200, early=1, area=PACA_EXMC, dar=1, dsisr=1 991 + GEN_INT_ENTRY machine_check_early, virt=0 992 992 #endif 993 - 994 - INT_KVM_HANDLER machine_check 0x200, EXC_STD, PACA_EXMC, 1 995 993 996 994 #define MACHINE_CHECK_HANDLER_WINDUP \ 997 995 /* Clear MSR_RI before setting SRR0 and SRR1. */\ ··· 1068 932 lhz r12,PACA_IN_MCE(r13); \ 1069 933 subi r12,r12,1; \ 1070 934 sth r12,PACA_IN_MCE(r13); \ 1071 - EXCEPTION_RESTORE_REGS EXC_STD 935 + EXCEPTION_RESTORE_REGS 1072 936 1073 937 EXC_COMMON_BEGIN(machine_check_early_common) 1074 - mtctr r10 /* Restore ctr */ 1075 - mfspr r11,SPRN_SRR0 1076 - mfspr r12,SPRN_SRR1 938 + __GEN_REALMODE_COMMON_ENTRY machine_check_early 1077 939 1078 940 /* 1079 941 * Switch to mc_emergency stack and handle re-entrancy (we limit ··· 1108 974 bgt cr1,unrecoverable_mce /* Check if we hit limit of 4 */ 1109 975 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ 1110 976 1111 - /* We don't touch AMR here, we never go to virtual mode */ 1112 - INT_COMMON 0x200, PACA_EXMC, 0, 0, 0, 1, 1 977 + __GEN_COMMON_BODY machine_check_early 1113 978 1114 979 BEGIN_FTR_SECTION 1115 980 bl enable_machine_check ··· 1116 983 li r10,MSR_RI 1117 984 mtmsrd r10,1 1118 985 1119 - bl save_nvgprs 1120 986 addi r3,r1,STACK_FRAME_OVERHEAD 1121 987 bl machine_check_early 1122 988 std r3,RESULT(r1) /* Save result */ ··· 1195 1063 mtspr SPRN_CFAR,r10 1196 1064 END_FTR_SECTION_IFSET(CPU_FTR_CFAR) 1197 1065 MACHINE_CHECK_HANDLER_WINDUP 1198 - /* See comment at machine_check exception, don't turn on RI */ 1199 - INT_HANDLER machine_check, 0x200, area=PACA_EXMC, ri=0, dar=1, dsisr=1, kvm=1 1066 + GEN_INT_ENTRY machine_check, virt=0 1200 1067 1201 1068 EXC_COMMON_BEGIN(machine_check_common) 1202 1069 /* 1203 1070 * Machine check is different because we use a different 1204 1071 * save area: PACA_EXMC instead of PACA_EXGEN. 1205 1072 */ 1206 - INT_COMMON 0x200, PACA_EXMC, 1, 1, 1, 1, 1 1073 + GEN_COMMON machine_check 1074 + 1207 1075 FINISH_NAP 1208 1076 /* Enable MSR_RI when finished with PACA_EXMC */ 1209 1077 li r10,MSR_RI 1210 1078 mtmsrd r10,1 1211 - bl save_nvgprs 1212 1079 addi r3,r1,STACK_FRAME_OVERHEAD 1213 1080 bl machine_check_exception 1214 - b ret_from_except 1081 + b interrupt_return 1082 + 1083 + GEN_KVM machine_check 1084 + 1215 1085 1216 1086 #ifdef CONFIG_PPC_P7_NAP 1217 1087 /* ··· 1278 1144 b . 1279 1145 1280 1146 1147 + /** 1148 + * Interrupt 0x300 - Data Storage Interrupt (DSI). 1149 + * This is a synchronous interrupt generated due to a data access exception, 1150 + * e.g., a load orstore which does not have a valid page table entry with 1151 + * permissions. DAWR matches also fault here, as do RC updates, and minor misc 1152 + * errors e.g., copy/paste, AMO, certain invalid CI accesses, etc. 1153 + * 1154 + * Handling: 1155 + * - Hash MMU 1156 + * Go to do_hash_page first to see if the HPT can be filled from an entry in 1157 + * the Linux page table. Hash faults can hit in kernel mode in a fairly 1158 + * arbitrary state (e.g., interrupts disabled, locks held) when accessing 1159 + * "non-bolted" regions, e.g., vmalloc space. However these should always be 1160 + * backed by Linux page tables. 1161 + * 1162 + * If none is found, do a Linux page fault. Linux page faults can happen in 1163 + * kernel mode due to user copy operations of course. 1164 + * 1165 + * - Radix MMU 1166 + * The hardware loads from the Linux page table directly, so a fault goes 1167 + * immediately to Linux page fault. 1168 + * 1169 + * Conditions like DAWR match are handled on the way in to Linux page fault. 1170 + */ 1171 + INT_DEFINE_BEGIN(data_access) 1172 + IVEC=0x300 1173 + IDAR=1 1174 + IDSISR=1 1175 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1176 + IKVM_SKIP=1 1177 + IKVM_REAL=1 1178 + #endif 1179 + INT_DEFINE_END(data_access) 1180 + 1281 1181 EXC_REAL_BEGIN(data_access, 0x300, 0x80) 1282 - INT_HANDLER data_access, 0x300, ool=1, dar=1, dsisr=1, kvm=1 1182 + GEN_INT_ENTRY data_access, virt=0 1283 1183 EXC_REAL_END(data_access, 0x300, 0x80) 1284 1184 EXC_VIRT_BEGIN(data_access, 0x4300, 0x80) 1285 - INT_HANDLER data_access, 0x300, virt=1, dar=1, dsisr=1 1185 + GEN_INT_ENTRY data_access, virt=1 1286 1186 EXC_VIRT_END(data_access, 0x4300, 0x80) 1287 - INT_KVM_HANDLER data_access, 0x300, EXC_STD, PACA_EXGEN, 1 1288 1187 EXC_COMMON_BEGIN(data_access_common) 1289 - /* 1290 - * Here r13 points to the paca, r9 contains the saved CR, 1291 - * SRR0 and SRR1 are saved in r11 and r12, 1292 - * r9 - r13 are saved in paca->exgen. 1293 - * EX_DAR and EX_DSISR have saved DAR/DSISR 1294 - */ 1295 - INT_COMMON 0x300, PACA_EXGEN, 1, 1, 1, 1, 1 1188 + GEN_COMMON data_access 1296 1189 ld r4,_DAR(r1) 1297 1190 ld r5,_DSISR(r1) 1298 1191 BEGIN_MMU_FTR_SECTION ··· 1330 1169 b handle_page_fault 1331 1170 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) 1332 1171 1172 + GEN_KVM data_access 1173 + 1174 + 1175 + /** 1176 + * Interrupt 0x380 - Data Segment Interrupt (DSLB). 1177 + * This is a synchronous interrupt in response to an MMU fault missing SLB 1178 + * entry for HPT, or an address outside RPT translation range. 1179 + * 1180 + * Handling: 1181 + * - HPT: 1182 + * This refills the SLB, or reports an access fault similarly to a bad page 1183 + * fault. When coming from user-mode, the SLB handler may access any kernel 1184 + * data, though it may itself take a DSLB. When coming from kernel mode, 1185 + * recursive faults must be avoided so access is restricted to the kernel 1186 + * image text/data, kernel stack, and any data allocated below 1187 + * ppc64_bolted_size (first segment). The kernel handler must avoid stomping 1188 + * on user-handler data structures. 1189 + * 1190 + * A dedicated save area EXSLB is used (XXX: but it actually need not be 1191 + * these days, we could use EXGEN). 1192 + */ 1193 + INT_DEFINE_BEGIN(data_access_slb) 1194 + IVEC=0x380 1195 + IAREA=PACA_EXSLB 1196 + IRECONCILE=0 1197 + IDAR=1 1198 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1199 + IKVM_SKIP=1 1200 + IKVM_REAL=1 1201 + #endif 1202 + INT_DEFINE_END(data_access_slb) 1333 1203 1334 1204 EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80) 1335 - INT_HANDLER data_access_slb, 0x380, ool=1, area=PACA_EXSLB, dar=1, kvm=1 1205 + GEN_INT_ENTRY data_access_slb, virt=0 1336 1206 EXC_REAL_END(data_access_slb, 0x380, 0x80) 1337 1207 EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80) 1338 - INT_HANDLER data_access_slb, 0x380, virt=1, area=PACA_EXSLB, dar=1 1208 + GEN_INT_ENTRY data_access_slb, virt=1 1339 1209 EXC_VIRT_END(data_access_slb, 0x4380, 0x80) 1340 - INT_KVM_HANDLER data_access_slb, 0x380, EXC_STD, PACA_EXSLB, 1 1341 1210 EXC_COMMON_BEGIN(data_access_slb_common) 1342 - INT_COMMON 0x380, PACA_EXSLB, 1, 1, 0, 1, 0 1211 + GEN_COMMON data_access_slb 1343 1212 ld r4,_DAR(r1) 1344 1213 addi r3,r1,STACK_FRAME_OVERHEAD 1345 1214 BEGIN_MMU_FTR_SECTION ··· 1377 1186 bl do_slb_fault 1378 1187 cmpdi r3,0 1379 1188 bne- 1f 1380 - b fast_exception_return 1189 + b fast_interrupt_return 1381 1190 1: /* Error case */ 1382 1191 MMU_FTR_SECTION_ELSE 1383 1192 /* Radix case, access is outside page table range */ 1384 1193 li r3,-EFAULT 1385 1194 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) 1386 1195 std r3,RESULT(r1) 1387 - bl save_nvgprs 1388 1196 RECONCILE_IRQ_STATE(r10, r11) 1389 1197 ld r4,_DAR(r1) 1390 1198 ld r5,RESULT(r1) 1391 1199 addi r3,r1,STACK_FRAME_OVERHEAD 1392 1200 bl do_bad_slb_fault 1393 - b ret_from_except 1201 + b interrupt_return 1394 1202 1203 + GEN_KVM data_access_slb 1204 + 1205 + 1206 + /** 1207 + * Interrupt 0x400 - Instruction Storage Interrupt (ISI). 1208 + * This is a synchronous interrupt in response to an MMU fault due to an 1209 + * instruction fetch. 1210 + * 1211 + * Handling: 1212 + * Similar to DSI, though in response to fetch. The faulting address is found 1213 + * in SRR0 (rather than DAR), and status in SRR1 (rather than DSISR). 1214 + */ 1215 + INT_DEFINE_BEGIN(instruction_access) 1216 + IVEC=0x400 1217 + IISIDE=1 1218 + IDAR=1 1219 + IDSISR=1 1220 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1221 + IKVM_REAL=1 1222 + #endif 1223 + INT_DEFINE_END(instruction_access) 1395 1224 1396 1225 EXC_REAL_BEGIN(instruction_access, 0x400, 0x80) 1397 - INT_HANDLER instruction_access, 0x400, kvm=1 1226 + GEN_INT_ENTRY instruction_access, virt=0 1398 1227 EXC_REAL_END(instruction_access, 0x400, 0x80) 1399 1228 EXC_VIRT_BEGIN(instruction_access, 0x4400, 0x80) 1400 - INT_HANDLER instruction_access, 0x400, virt=1 1229 + GEN_INT_ENTRY instruction_access, virt=1 1401 1230 EXC_VIRT_END(instruction_access, 0x4400, 0x80) 1402 - INT_KVM_HANDLER instruction_access, 0x400, EXC_STD, PACA_EXGEN, 0 1403 1231 EXC_COMMON_BEGIN(instruction_access_common) 1404 - INT_COMMON 0x400, PACA_EXGEN, 1, 1, 1, 2, 2 1232 + GEN_COMMON instruction_access 1405 1233 ld r4,_DAR(r1) 1406 1234 ld r5,_DSISR(r1) 1407 1235 BEGIN_MMU_FTR_SECTION ··· 1431 1221 b handle_page_fault 1432 1222 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) 1433 1223 1224 + GEN_KVM instruction_access 1225 + 1226 + 1227 + /** 1228 + * Interrupt 0x480 - Instruction Segment Interrupt (ISLB). 1229 + * This is a synchronous interrupt in response to an MMU fault due to an 1230 + * instruction fetch. 1231 + * 1232 + * Handling: 1233 + * Similar to DSLB, though in response to fetch. The faulting address is found 1234 + * in SRR0 (rather than DAR). 1235 + */ 1236 + INT_DEFINE_BEGIN(instruction_access_slb) 1237 + IVEC=0x480 1238 + IAREA=PACA_EXSLB 1239 + IRECONCILE=0 1240 + IISIDE=1 1241 + IDAR=1 1242 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1243 + IKVM_REAL=1 1244 + #endif 1245 + INT_DEFINE_END(instruction_access_slb) 1434 1246 1435 1247 EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80) 1436 - INT_HANDLER instruction_access_slb, 0x480, area=PACA_EXSLB, kvm=1 1248 + GEN_INT_ENTRY instruction_access_slb, virt=0 1437 1249 EXC_REAL_END(instruction_access_slb, 0x480, 0x80) 1438 1250 EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80) 1439 - INT_HANDLER instruction_access_slb, 0x480, virt=1, area=PACA_EXSLB 1251 + GEN_INT_ENTRY instruction_access_slb, virt=1 1440 1252 EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80) 1441 - INT_KVM_HANDLER instruction_access_slb, 0x480, EXC_STD, PACA_EXSLB, 0 1442 1253 EXC_COMMON_BEGIN(instruction_access_slb_common) 1443 - INT_COMMON 0x480, PACA_EXSLB, 1, 1, 0, 2, 0 1254 + GEN_COMMON instruction_access_slb 1444 1255 ld r4,_DAR(r1) 1445 1256 addi r3,r1,STACK_FRAME_OVERHEAD 1446 1257 BEGIN_MMU_FTR_SECTION ··· 1469 1238 bl do_slb_fault 1470 1239 cmpdi r3,0 1471 1240 bne- 1f 1472 - b fast_exception_return 1241 + b fast_interrupt_return 1473 1242 1: /* Error case */ 1474 1243 MMU_FTR_SECTION_ELSE 1475 1244 /* Radix case, access is outside page table range */ 1476 1245 li r3,-EFAULT 1477 1246 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) 1478 1247 std r3,RESULT(r1) 1479 - bl save_nvgprs 1480 1248 RECONCILE_IRQ_STATE(r10, r11) 1481 1249 ld r4,_DAR(r1) 1482 1250 ld r5,RESULT(r1) 1483 1251 addi r3,r1,STACK_FRAME_OVERHEAD 1484 1252 bl do_bad_slb_fault 1485 - b ret_from_except 1253 + b interrupt_return 1254 + 1255 + GEN_KVM instruction_access_slb 1256 + 1257 + 1258 + /** 1259 + * Interrupt 0x500 - External Interrupt. 1260 + * This is an asynchronous maskable interrupt in response to an "external 1261 + * exception" from the interrupt controller or hypervisor (e.g., device 1262 + * interrupt). It is maskable in hardware by clearing MSR[EE], and 1263 + * soft-maskable with IRQS_DISABLED mask (i.e., local_irq_disable()). 1264 + * 1265 + * When running in HV mode, Linux sets up the LPCR[LPES] bit such that 1266 + * interrupts are delivered with HSRR registers, guests use SRRs, which 1267 + * reqiures IHSRR_IF_HVMODE. 1268 + * 1269 + * On bare metal POWER9 and later, Linux sets the LPCR[HVICE] bit such that 1270 + * external interrupts are delivered as Hypervisor Virtualization Interrupts 1271 + * rather than External Interrupts. 1272 + * 1273 + * Handling: 1274 + * This calls into Linux IRQ handler. NVGPRs are not saved to reduce overhead, 1275 + * because registers at the time of the interrupt are not so important as it is 1276 + * asynchronous. 1277 + * 1278 + * If soft masked, the masked handler will note the pending interrupt for 1279 + * replay, and clear MSR[EE] in the interrupted context. 1280 + */ 1281 + INT_DEFINE_BEGIN(hardware_interrupt) 1282 + IVEC=0x500 1283 + IHSRR_IF_HVMODE=1 1284 + IMASK=IRQS_DISABLED 1285 + IKVM_REAL=1 1286 + IKVM_VIRT=1 1287 + INT_DEFINE_END(hardware_interrupt) 1486 1288 1487 1289 EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100) 1488 - INT_HANDLER hardware_interrupt, 0x500, hsrr=EXC_HV_OR_STD, bitmask=IRQS_DISABLED, kvm=1 1290 + GEN_INT_ENTRY hardware_interrupt, virt=0 1489 1291 EXC_REAL_END(hardware_interrupt, 0x500, 0x100) 1490 1292 EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100) 1491 - INT_HANDLER hardware_interrupt, 0x500, virt=1, hsrr=EXC_HV_OR_STD, bitmask=IRQS_DISABLED, kvm=1 1293 + GEN_INT_ENTRY hardware_interrupt, virt=1 1492 1294 EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100) 1493 - INT_KVM_HANDLER hardware_interrupt, 0x500, EXC_HV_OR_STD, PACA_EXGEN, 0 1494 - EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ) 1295 + EXC_COMMON_BEGIN(hardware_interrupt_common) 1296 + GEN_COMMON hardware_interrupt 1297 + FINISH_NAP 1298 + RUNLATCH_ON 1299 + addi r3,r1,STACK_FRAME_OVERHEAD 1300 + bl do_IRQ 1301 + b interrupt_return 1495 1302 1303 + GEN_KVM hardware_interrupt 1304 + 1305 + 1306 + /** 1307 + * Interrupt 0x600 - Alignment Interrupt 1308 + * This is a synchronous interrupt in response to data alignment fault. 1309 + */ 1310 + INT_DEFINE_BEGIN(alignment) 1311 + IVEC=0x600 1312 + IDAR=1 1313 + IDSISR=1 1314 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1315 + IKVM_REAL=1 1316 + #endif 1317 + INT_DEFINE_END(alignment) 1496 1318 1497 1319 EXC_REAL_BEGIN(alignment, 0x600, 0x100) 1498 - INT_HANDLER alignment, 0x600, dar=1, dsisr=1, kvm=1 1320 + GEN_INT_ENTRY alignment, virt=0 1499 1321 EXC_REAL_END(alignment, 0x600, 0x100) 1500 1322 EXC_VIRT_BEGIN(alignment, 0x4600, 0x100) 1501 - INT_HANDLER alignment, 0x600, virt=1, dar=1, dsisr=1 1323 + GEN_INT_ENTRY alignment, virt=1 1502 1324 EXC_VIRT_END(alignment, 0x4600, 0x100) 1503 - INT_KVM_HANDLER alignment, 0x600, EXC_STD, PACA_EXGEN, 0 1504 1325 EXC_COMMON_BEGIN(alignment_common) 1505 - INT_COMMON 0x600, PACA_EXGEN, 1, 1, 1, 1, 1 1506 - bl save_nvgprs 1326 + GEN_COMMON alignment 1507 1327 addi r3,r1,STACK_FRAME_OVERHEAD 1508 1328 bl alignment_exception 1509 - b ret_from_except 1329 + REST_NVGPRS(r1) /* instruction emulation may change GPRs */ 1330 + b interrupt_return 1510 1331 1332 + GEN_KVM alignment 1333 + 1334 + 1335 + /** 1336 + * Interrupt 0x700 - Program Interrupt (program check). 1337 + * This is a synchronous interrupt in response to various instruction faults: 1338 + * traps, privilege errors, TM errors, floating point exceptions. 1339 + * 1340 + * Handling: 1341 + * This interrupt may use the "emergency stack" in some cases when being taken 1342 + * from kernel context, which complicates handling. 1343 + */ 1344 + INT_DEFINE_BEGIN(program_check) 1345 + IVEC=0x700 1346 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1347 + IKVM_REAL=1 1348 + #endif 1349 + INT_DEFINE_END(program_check) 1511 1350 1512 1351 EXC_REAL_BEGIN(program_check, 0x700, 0x100) 1513 - INT_HANDLER program_check, 0x700, kvm=1 1352 + GEN_INT_ENTRY program_check, virt=0 1514 1353 EXC_REAL_END(program_check, 0x700, 0x100) 1515 1354 EXC_VIRT_BEGIN(program_check, 0x4700, 0x100) 1516 - INT_HANDLER program_check, 0x700, virt=1 1355 + GEN_INT_ENTRY program_check, virt=1 1517 1356 EXC_VIRT_END(program_check, 0x4700, 0x100) 1518 - INT_KVM_HANDLER program_check, 0x700, EXC_STD, PACA_EXGEN, 0 1519 1357 EXC_COMMON_BEGIN(program_check_common) 1358 + __GEN_COMMON_ENTRY program_check 1359 + 1520 1360 /* 1521 1361 * It's possible to receive a TM Bad Thing type program check with 1522 1362 * userspace register values (in particular r1), but with SRR1 reporting ··· 1612 1310 mr r10,r1 /* Save r1 */ 1613 1311 ld r1,PACAEMERGSP(r13) /* Use emergency stack */ 1614 1312 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ 1615 - INT_COMMON 0x700, PACA_EXGEN, 0, 1, 1, 0, 0 1313 + __ISTACK(program_check)=0 1314 + __GEN_COMMON_BODY program_check 1616 1315 b 3f 1617 1316 2: 1618 - INT_COMMON 0x700, PACA_EXGEN, 1, 1, 1, 0, 0 1317 + __ISTACK(program_check)=1 1318 + __GEN_COMMON_BODY program_check 1619 1319 3: 1620 - bl save_nvgprs 1621 1320 addi r3,r1,STACK_FRAME_OVERHEAD 1622 1321 bl program_check_exception 1623 - b ret_from_except 1322 + REST_NVGPRS(r1) /* instruction emulation may change GPRs */ 1323 + b interrupt_return 1624 1324 1325 + GEN_KVM program_check 1326 + 1327 + 1328 + /* 1329 + * Interrupt 0x800 - Floating-Point Unavailable Interrupt. 1330 + * This is a synchronous interrupt in response to executing an fp instruction 1331 + * with MSR[FP]=0. 1332 + * 1333 + * Handling: 1334 + * This will load FP registers and enable the FP bit if coming from userspace, 1335 + * otherwise report a bad kernel use of FP. 1336 + */ 1337 + INT_DEFINE_BEGIN(fp_unavailable) 1338 + IVEC=0x800 1339 + IRECONCILE=0 1340 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1341 + IKVM_REAL=1 1342 + #endif 1343 + INT_DEFINE_END(fp_unavailable) 1625 1344 1626 1345 EXC_REAL_BEGIN(fp_unavailable, 0x800, 0x100) 1627 - INT_HANDLER fp_unavailable, 0x800, kvm=1 1346 + GEN_INT_ENTRY fp_unavailable, virt=0 1628 1347 EXC_REAL_END(fp_unavailable, 0x800, 0x100) 1629 1348 EXC_VIRT_BEGIN(fp_unavailable, 0x4800, 0x100) 1630 - INT_HANDLER fp_unavailable, 0x800, virt=1 1349 + GEN_INT_ENTRY fp_unavailable, virt=1 1631 1350 EXC_VIRT_END(fp_unavailable, 0x4800, 0x100) 1632 - INT_KVM_HANDLER fp_unavailable, 0x800, EXC_STD, PACA_EXGEN, 0 1633 1351 EXC_COMMON_BEGIN(fp_unavailable_common) 1634 - INT_COMMON 0x800, PACA_EXGEN, 1, 1, 0, 0, 0 1352 + GEN_COMMON fp_unavailable 1635 1353 bne 1f /* if from user, just load it up */ 1636 - bl save_nvgprs 1637 1354 RECONCILE_IRQ_STATE(r10, r11) 1638 1355 addi r3,r1,STACK_FRAME_OVERHEAD 1639 1356 bl kernel_fp_unavailable_exception ··· 1669 1348 END_FTR_SECTION_IFSET(CPU_FTR_TM) 1670 1349 #endif 1671 1350 bl load_up_fpu 1672 - b fast_exception_return 1351 + b fast_interrupt_return 1673 1352 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1674 1353 2: /* User process was in a transaction */ 1675 - bl save_nvgprs 1676 1354 RECONCILE_IRQ_STATE(r10, r11) 1677 1355 addi r3,r1,STACK_FRAME_OVERHEAD 1678 1356 bl fp_unavailable_tm 1679 - b ret_from_except 1357 + b interrupt_return 1680 1358 #endif 1681 1359 1360 + GEN_KVM fp_unavailable 1361 + 1362 + 1363 + /** 1364 + * Interrupt 0x900 - Decrementer Interrupt. 1365 + * This is an asynchronous interrupt in response to a decrementer exception 1366 + * (e.g., DEC has wrapped below zero). It is maskable in hardware by clearing 1367 + * MSR[EE], and soft-maskable with IRQS_DISABLED mask (i.e., 1368 + * local_irq_disable()). 1369 + * 1370 + * Handling: 1371 + * This calls into Linux timer handler. NVGPRs are not saved (see 0x500). 1372 + * 1373 + * If soft masked, the masked handler will note the pending interrupt for 1374 + * replay, and bump the decrementer to a high value, leaving MSR[EE] enabled 1375 + * in the interrupted context. 1376 + * If PPC_WATCHDOG is configured, the soft masked handler will actually set 1377 + * things back up to run soft_nmi_interrupt as a regular interrupt handler 1378 + * on the emergency stack. 1379 + */ 1380 + INT_DEFINE_BEGIN(decrementer) 1381 + IVEC=0x900 1382 + IMASK=IRQS_DISABLED 1383 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1384 + IKVM_REAL=1 1385 + #endif 1386 + INT_DEFINE_END(decrementer) 1682 1387 1683 1388 EXC_REAL_BEGIN(decrementer, 0x900, 0x80) 1684 - INT_HANDLER decrementer, 0x900, ool=1, bitmask=IRQS_DISABLED, kvm=1 1389 + GEN_INT_ENTRY decrementer, virt=0 1685 1390 EXC_REAL_END(decrementer, 0x900, 0x80) 1686 1391 EXC_VIRT_BEGIN(decrementer, 0x4900, 0x80) 1687 - INT_HANDLER decrementer, 0x900, virt=1, bitmask=IRQS_DISABLED 1392 + GEN_INT_ENTRY decrementer, virt=1 1688 1393 EXC_VIRT_END(decrementer, 0x4900, 0x80) 1689 - INT_KVM_HANDLER decrementer, 0x900, EXC_STD, PACA_EXGEN, 0 1690 - EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt) 1394 + EXC_COMMON_BEGIN(decrementer_common) 1395 + GEN_COMMON decrementer 1396 + FINISH_NAP 1397 + RUNLATCH_ON 1398 + addi r3,r1,STACK_FRAME_OVERHEAD 1399 + bl timer_interrupt 1400 + b interrupt_return 1691 1401 1402 + GEN_KVM decrementer 1403 + 1404 + 1405 + /** 1406 + * Interrupt 0x980 - Hypervisor Decrementer Interrupt. 1407 + * This is an asynchronous interrupt, similar to 0x900 but for the HDEC 1408 + * register. 1409 + * 1410 + * Handling: 1411 + * Linux does not use this outside KVM where it's used to keep a host timer 1412 + * while the guest is given control of DEC. It should normally be caught by 1413 + * the KVM test and routed there. 1414 + */ 1415 + INT_DEFINE_BEGIN(hdecrementer) 1416 + IVEC=0x980 1417 + IHSRR=1 1418 + ISTACK=0 1419 + IRECONCILE=0 1420 + IKVM_REAL=1 1421 + IKVM_VIRT=1 1422 + INT_DEFINE_END(hdecrementer) 1692 1423 1693 1424 EXC_REAL_BEGIN(hdecrementer, 0x980, 0x80) 1694 - INT_HANDLER hdecrementer, 0x980, hsrr=EXC_HV, kvm=1 1425 + GEN_INT_ENTRY hdecrementer, virt=0 1695 1426 EXC_REAL_END(hdecrementer, 0x980, 0x80) 1696 1427 EXC_VIRT_BEGIN(hdecrementer, 0x4980, 0x80) 1697 - INT_HANDLER hdecrementer, 0x980, virt=1, hsrr=EXC_HV, kvm=1 1428 + GEN_INT_ENTRY hdecrementer, virt=1 1698 1429 EXC_VIRT_END(hdecrementer, 0x4980, 0x80) 1699 - INT_KVM_HANDLER hdecrementer, 0x980, EXC_HV, PACA_EXGEN, 0 1700 - EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt) 1430 + EXC_COMMON_BEGIN(hdecrementer_common) 1431 + __GEN_COMMON_ENTRY hdecrementer 1432 + /* 1433 + * Hypervisor decrementer interrupts not caught by the KVM test 1434 + * shouldn't occur but are sometimes left pending on exit from a KVM 1435 + * guest. We don't need to do anything to clear them, as they are 1436 + * edge-triggered. 1437 + * 1438 + * Be careful to avoid touching the kernel stack. 1439 + */ 1440 + ld r10,PACA_EXGEN+EX_CTR(r13) 1441 + mtctr r10 1442 + mtcrf 0x80,r9 1443 + ld r9,PACA_EXGEN+EX_R9(r13) 1444 + ld r10,PACA_EXGEN+EX_R10(r13) 1445 + ld r11,PACA_EXGEN+EX_R11(r13) 1446 + ld r12,PACA_EXGEN+EX_R12(r13) 1447 + ld r13,PACA_EXGEN+EX_R13(r13) 1448 + HRFI_TO_KERNEL 1701 1449 1450 + GEN_KVM hdecrementer 1451 + 1452 + 1453 + /** 1454 + * Interrupt 0xa00 - Directed Privileged Doorbell Interrupt. 1455 + * This is an asynchronous interrupt in response to a msgsndp doorbell. 1456 + * It is maskable in hardware by clearing MSR[EE], and soft-maskable with 1457 + * IRQS_DISABLED mask (i.e., local_irq_disable()). 1458 + * 1459 + * Handling: 1460 + * Guests may use this for IPIs between threads in a core if the 1461 + * hypervisor supports it. NVGPRS are not saved (see 0x500). 1462 + * 1463 + * If soft masked, the masked handler will note the pending interrupt for 1464 + * replay, leaving MSR[EE] enabled in the interrupted context because the 1465 + * doorbells are edge triggered. 1466 + */ 1467 + INT_DEFINE_BEGIN(doorbell_super) 1468 + IVEC=0xa00 1469 + IMASK=IRQS_DISABLED 1470 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1471 + IKVM_REAL=1 1472 + #endif 1473 + INT_DEFINE_END(doorbell_super) 1702 1474 1703 1475 EXC_REAL_BEGIN(doorbell_super, 0xa00, 0x100) 1704 - INT_HANDLER doorbell_super, 0xa00, bitmask=IRQS_DISABLED, kvm=1 1476 + GEN_INT_ENTRY doorbell_super, virt=0 1705 1477 EXC_REAL_END(doorbell_super, 0xa00, 0x100) 1706 1478 EXC_VIRT_BEGIN(doorbell_super, 0x4a00, 0x100) 1707 - INT_HANDLER doorbell_super, 0xa00, virt=1, bitmask=IRQS_DISABLED 1479 + GEN_INT_ENTRY doorbell_super, virt=1 1708 1480 EXC_VIRT_END(doorbell_super, 0x4a00, 0x100) 1709 - INT_KVM_HANDLER doorbell_super, 0xa00, EXC_STD, PACA_EXGEN, 0 1481 + EXC_COMMON_BEGIN(doorbell_super_common) 1482 + GEN_COMMON doorbell_super 1483 + FINISH_NAP 1484 + RUNLATCH_ON 1485 + addi r3,r1,STACK_FRAME_OVERHEAD 1710 1486 #ifdef CONFIG_PPC_DOORBELL 1711 - EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception) 1487 + bl doorbell_exception 1712 1488 #else 1713 - EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception) 1489 + bl unknown_exception 1714 1490 #endif 1491 + b interrupt_return 1492 + 1493 + GEN_KVM doorbell_super 1715 1494 1716 1495 1717 1496 EXC_REAL_NONE(0xb00, 0x100) 1718 1497 EXC_VIRT_NONE(0x4b00, 0x100) 1719 1498 1720 - /* 1721 - * system call / hypercall (0xc00, 0x4c00) 1722 - * 1723 - * The system call exception is invoked with "sc 0" and does not alter HV bit. 1724 - * 1725 - * The hypercall is invoked with "sc 1" and sets HV=1. 1499 + /** 1500 + * Interrupt 0xc00 - System Call Interrupt (syscall, hcall). 1501 + * This is a synchronous interrupt invoked with the "sc" instruction. The 1502 + * system call is invoked with "sc 0" and does not alter the HV bit, so it 1503 + * is directed to the currently running OS. The hypercall is invoked with 1504 + * "sc 1" and it sets HV=1, so it elevates to hypervisor. 1726 1505 * 1727 1506 * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to 1728 1507 * 0x4c00 virtual mode. 1508 + * 1509 + * Handling: 1510 + * If the KVM test fires then it was due to a hypercall and is accordingly 1511 + * routed to KVM. Otherwise this executes a normal Linux system call. 1729 1512 * 1730 1513 * Call convention: 1731 1514 * ··· 1842 1417 * without saving, though xer is not a good idea to use, as hardware may 1843 1418 * interpret some bits so it may be costly to change them. 1844 1419 */ 1420 + INT_DEFINE_BEGIN(system_call) 1421 + IVEC=0xc00 1422 + IKVM_REAL=1 1423 + IKVM_VIRT=1 1424 + INT_DEFINE_END(system_call) 1425 + 1845 1426 .macro SYSTEM_CALL virt 1846 1427 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 1847 1428 /* ··· 1862 1431 GET_PACA(r13) 1863 1432 std r10,PACA_EXGEN+EX_R10(r13) 1864 1433 INTERRUPT_TO_KERNEL 1865 - KVMTEST system_call EXC_STD 0xc00 /* uses r10, branch to system_call_kvm */ 1434 + KVMTEST system_call /* uses r10, branch to system_call_kvm */ 1866 1435 mfctr r9 1867 1436 #else 1868 1437 mr r9,r13 ··· 1921 1490 EXC_VIRT_END(system_call, 0x4c00, 0x100) 1922 1491 1923 1492 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 1493 + TRAMP_REAL_BEGIN(system_call_kvm) 1924 1494 /* 1925 1495 * This is a hcall, so register convention is as above, with these 1926 1496 * differences: ··· 1929 1497 * ctr = orig r13 1930 1498 * orig r10 saved in PACA 1931 1499 */ 1932 - TRAMP_KVM_BEGIN(system_call_kvm) 1933 1500 /* 1934 1501 * Save the PPR (on systems that support it) before changing to 1935 1502 * HMT_MEDIUM. That allows the KVM code to save that value into the 1936 1503 * guest state (it is the guest's PPR value). 1937 1504 */ 1938 - OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR) 1505 + BEGIN_FTR_SECTION 1506 + mfspr r10,SPRN_PPR 1507 + std r10,HSTATE_PPR(r13) 1508 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 1939 1509 HMT_MEDIUM 1940 - OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR) 1941 1510 mfctr r10 1942 1511 SET_SCRATCH0(r10) 1943 - std r9,PACA_EXGEN+EX_R9(r13) 1944 - mfcr r9 1945 - KVM_HANDLER 0xc00, EXC_STD, PACA_EXGEN, 0 1512 + mfcr r10 1513 + std r12,HSTATE_SCRATCH0(r13) 1514 + sldi r12,r10,32 1515 + ori r12,r12,0xc00 1516 + #ifdef CONFIG_RELOCATABLE 1517 + /* 1518 + * Requires __LOAD_FAR_HANDLER beause kvmppc_interrupt lives 1519 + * outside the head section. 1520 + */ 1521 + __LOAD_FAR_HANDLER(r10, kvmppc_interrupt) 1522 + mtctr r10 1523 + ld r10,PACA_EXGEN+EX_R10(r13) 1524 + bctr 1525 + #else 1526 + ld r10,PACA_EXGEN+EX_R10(r13) 1527 + b kvmppc_interrupt 1528 + #endif 1946 1529 #endif 1947 1530 1948 1531 1532 + /** 1533 + * Interrupt 0xd00 - Trace Interrupt. 1534 + * This is a synchronous interrupt in response to instruction step or 1535 + * breakpoint faults. 1536 + */ 1537 + INT_DEFINE_BEGIN(single_step) 1538 + IVEC=0xd00 1539 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1540 + IKVM_REAL=1 1541 + #endif 1542 + INT_DEFINE_END(single_step) 1543 + 1949 1544 EXC_REAL_BEGIN(single_step, 0xd00, 0x100) 1950 - INT_HANDLER single_step, 0xd00, kvm=1 1545 + GEN_INT_ENTRY single_step, virt=0 1951 1546 EXC_REAL_END(single_step, 0xd00, 0x100) 1952 1547 EXC_VIRT_BEGIN(single_step, 0x4d00, 0x100) 1953 - INT_HANDLER single_step, 0xd00, virt=1 1548 + GEN_INT_ENTRY single_step, virt=1 1954 1549 EXC_VIRT_END(single_step, 0x4d00, 0x100) 1955 - INT_KVM_HANDLER single_step, 0xd00, EXC_STD, PACA_EXGEN, 0 1956 - EXC_COMMON(single_step_common, 0xd00, single_step_exception) 1550 + EXC_COMMON_BEGIN(single_step_common) 1551 + GEN_COMMON single_step 1552 + addi r3,r1,STACK_FRAME_OVERHEAD 1553 + bl single_step_exception 1554 + b interrupt_return 1957 1555 1556 + GEN_KVM single_step 1557 + 1558 + 1559 + /** 1560 + * Interrupt 0xe00 - Hypervisor Data Storage Interrupt (HDSI). 1561 + * This is a synchronous interrupt in response to an MMU fault caused by a 1562 + * guest data access. 1563 + * 1564 + * Handling: 1565 + * This should always get routed to KVM. In radix MMU mode, this is caused 1566 + * by a guest nested radix access that can't be performed due to the 1567 + * partition scope page table. In hash mode, this can be caused by guests 1568 + * running with translation disabled (virtual real mode) or with VPM enabled. 1569 + * KVM will update the page table structures or disallow the access. 1570 + */ 1571 + INT_DEFINE_BEGIN(h_data_storage) 1572 + IVEC=0xe00 1573 + IHSRR=1 1574 + IDAR=1 1575 + IDSISR=1 1576 + IKVM_SKIP=1 1577 + IKVM_REAL=1 1578 + IKVM_VIRT=1 1579 + INT_DEFINE_END(h_data_storage) 1958 1580 1959 1581 EXC_REAL_BEGIN(h_data_storage, 0xe00, 0x20) 1960 - INT_HANDLER h_data_storage, 0xe00, ool=1, hsrr=EXC_HV, dar=1, dsisr=1, kvm=1 1582 + GEN_INT_ENTRY h_data_storage, virt=0, ool=1 1961 1583 EXC_REAL_END(h_data_storage, 0xe00, 0x20) 1962 1584 EXC_VIRT_BEGIN(h_data_storage, 0x4e00, 0x20) 1963 - INT_HANDLER h_data_storage, 0xe00, ool=1, virt=1, hsrr=EXC_HV, dar=1, dsisr=1, kvm=1 1585 + GEN_INT_ENTRY h_data_storage, virt=1, ool=1 1964 1586 EXC_VIRT_END(h_data_storage, 0x4e00, 0x20) 1965 - INT_KVM_HANDLER h_data_storage, 0xe00, EXC_HV, PACA_EXGEN, 1 1966 1587 EXC_COMMON_BEGIN(h_data_storage_common) 1967 - INT_COMMON 0xe00, PACA_EXGEN, 1, 1, 1, 1, 1 1968 - bl save_nvgprs 1588 + GEN_COMMON h_data_storage 1969 1589 addi r3,r1,STACK_FRAME_OVERHEAD 1970 1590 BEGIN_MMU_FTR_SECTION 1971 1591 ld r4,_DAR(r1) ··· 2026 1542 MMU_FTR_SECTION_ELSE 2027 1543 bl unknown_exception 2028 1544 ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX) 2029 - b ret_from_except 1545 + b interrupt_return 2030 1546 1547 + GEN_KVM h_data_storage 1548 + 1549 + 1550 + /** 1551 + * Interrupt 0xe20 - Hypervisor Instruction Storage Interrupt (HISI). 1552 + * This is a synchronous interrupt in response to an MMU fault caused by a 1553 + * guest instruction fetch, similar to HDSI. 1554 + */ 1555 + INT_DEFINE_BEGIN(h_instr_storage) 1556 + IVEC=0xe20 1557 + IHSRR=1 1558 + IKVM_REAL=1 1559 + IKVM_VIRT=1 1560 + INT_DEFINE_END(h_instr_storage) 2031 1561 2032 1562 EXC_REAL_BEGIN(h_instr_storage, 0xe20, 0x20) 2033 - INT_HANDLER h_instr_storage, 0xe20, ool=1, hsrr=EXC_HV, kvm=1 1563 + GEN_INT_ENTRY h_instr_storage, virt=0, ool=1 2034 1564 EXC_REAL_END(h_instr_storage, 0xe20, 0x20) 2035 1565 EXC_VIRT_BEGIN(h_instr_storage, 0x4e20, 0x20) 2036 - INT_HANDLER h_instr_storage, 0xe20, ool=1, virt=1, hsrr=EXC_HV, kvm=1 1566 + GEN_INT_ENTRY h_instr_storage, virt=1, ool=1 2037 1567 EXC_VIRT_END(h_instr_storage, 0x4e20, 0x20) 2038 - INT_KVM_HANDLER h_instr_storage, 0xe20, EXC_HV, PACA_EXGEN, 0 2039 - EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception) 1568 + EXC_COMMON_BEGIN(h_instr_storage_common) 1569 + GEN_COMMON h_instr_storage 1570 + addi r3,r1,STACK_FRAME_OVERHEAD 1571 + bl unknown_exception 1572 + b interrupt_return 2040 1573 1574 + GEN_KVM h_instr_storage 1575 + 1576 + 1577 + /** 1578 + * Interrupt 0xe40 - Hypervisor Emulation Assistance Interrupt. 1579 + */ 1580 + INT_DEFINE_BEGIN(emulation_assist) 1581 + IVEC=0xe40 1582 + IHSRR=1 1583 + IKVM_REAL=1 1584 + IKVM_VIRT=1 1585 + INT_DEFINE_END(emulation_assist) 2041 1586 2042 1587 EXC_REAL_BEGIN(emulation_assist, 0xe40, 0x20) 2043 - INT_HANDLER emulation_assist, 0xe40, ool=1, hsrr=EXC_HV, kvm=1 1588 + GEN_INT_ENTRY emulation_assist, virt=0, ool=1 2044 1589 EXC_REAL_END(emulation_assist, 0xe40, 0x20) 2045 1590 EXC_VIRT_BEGIN(emulation_assist, 0x4e40, 0x20) 2046 - INT_HANDLER emulation_assist, 0xe40, ool=1, virt=1, hsrr=EXC_HV, kvm=1 1591 + GEN_INT_ENTRY emulation_assist, virt=1, ool=1 2047 1592 EXC_VIRT_END(emulation_assist, 0x4e40, 0x20) 2048 - INT_KVM_HANDLER emulation_assist, 0xe40, EXC_HV, PACA_EXGEN, 0 2049 - EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt) 1593 + EXC_COMMON_BEGIN(emulation_assist_common) 1594 + GEN_COMMON emulation_assist 1595 + addi r3,r1,STACK_FRAME_OVERHEAD 1596 + bl emulation_assist_interrupt 1597 + REST_NVGPRS(r1) /* instruction emulation may change GPRs */ 1598 + b interrupt_return 1599 + 1600 + GEN_KVM emulation_assist 2050 1601 2051 1602 2052 - /* 2053 - * hmi_exception trampoline is a special case. It jumps to hmi_exception_early 2054 - * first, and then eventaully from there to the trampoline to get into virtual 2055 - * mode. 1603 + /** 1604 + * Interrupt 0xe60 - Hypervisor Maintenance Interrupt (HMI). 1605 + * This is an asynchronous interrupt caused by a Hypervisor Maintenance 1606 + * Exception. It is always taken in real mode but uses HSRR registers 1607 + * unlike SRESET and MCE. 1608 + * 1609 + * It is maskable in hardware by clearing MSR[EE], and partially soft-maskable 1610 + * with IRQS_DISABLED mask (i.e., local_irq_disable()). 1611 + * 1612 + * Handling: 1613 + * This is a special case, this is handled similarly to machine checks, with an 1614 + * initial real mode handler that is not soft-masked, which attempts to fix the 1615 + * problem. Then a regular handler which is soft-maskable and reports the 1616 + * problem. 1617 + * 1618 + * The emergency stack is used for the early real mode handler. 1619 + * 1620 + * XXX: unclear why MCE and HMI schemes could not be made common, e.g., 1621 + * either use soft-masking for the MCE, or use irq_work for the HMI. 1622 + * 1623 + * KVM: 1624 + * Unlike MCE, this calls into KVM without calling the real mode handler 1625 + * first. 2056 1626 */ 1627 + INT_DEFINE_BEGIN(hmi_exception_early) 1628 + IVEC=0xe60 1629 + IHSRR=1 1630 + IREALMODE_COMMON=1 1631 + ISTACK=0 1632 + IRECONCILE=0 1633 + IKUAP=0 /* We don't touch AMR here, we never go to virtual mode */ 1634 + IKVM_REAL=1 1635 + INT_DEFINE_END(hmi_exception_early) 1636 + 1637 + INT_DEFINE_BEGIN(hmi_exception) 1638 + IVEC=0xe60 1639 + IHSRR=1 1640 + IMASK=IRQS_DISABLED 1641 + IKVM_REAL=1 1642 + INT_DEFINE_END(hmi_exception) 1643 + 2057 1644 EXC_REAL_BEGIN(hmi_exception, 0xe60, 0x20) 2058 - INT_HANDLER hmi_exception, 0xe60, ool=1, early=1, hsrr=EXC_HV, ri=0, kvm=1 1645 + GEN_INT_ENTRY hmi_exception_early, virt=0, ool=1 2059 1646 EXC_REAL_END(hmi_exception, 0xe60, 0x20) 2060 1647 EXC_VIRT_NONE(0x4e60, 0x20) 2061 - INT_KVM_HANDLER hmi_exception, 0xe60, EXC_HV, PACA_EXGEN, 0 1648 + 2062 1649 EXC_COMMON_BEGIN(hmi_exception_early_common) 2063 - mtctr r10 /* Restore ctr */ 2064 - mfspr r11,SPRN_HSRR0 /* Save HSRR0 */ 2065 - mfspr r12,SPRN_HSRR1 /* Save HSRR1 */ 1650 + __GEN_REALMODE_COMMON_ENTRY hmi_exception_early 1651 + 2066 1652 mr r10,r1 /* Save r1 */ 2067 1653 ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */ 2068 1654 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ 2069 1655 2070 - /* We don't touch AMR here, we never go to virtual mode */ 2071 - INT_COMMON 0xe60, PACA_EXGEN, 0, 0, 0, 0, 0 1656 + __GEN_COMMON_BODY hmi_exception_early 2072 1657 2073 1658 addi r3,r1,STACK_FRAME_OVERHEAD 2074 1659 bl hmi_exception_realmode 2075 1660 cmpdi cr0,r3,0 2076 1661 bne 1f 2077 1662 2078 - EXCEPTION_RESTORE_REGS EXC_HV 1663 + EXCEPTION_RESTORE_REGS hsrr=1 2079 1664 HRFI_TO_USER_OR_KERNEL 2080 1665 2081 1666 1: ··· 2152 1599 * Go to virtual mode and pull the HMI event information from 2153 1600 * firmware. 2154 1601 */ 2155 - EXCEPTION_RESTORE_REGS EXC_HV 2156 - INT_HANDLER hmi_exception, 0xe60, hsrr=EXC_HV, bitmask=IRQS_DISABLED, kvm=1 1602 + EXCEPTION_RESTORE_REGS hsrr=1 1603 + GEN_INT_ENTRY hmi_exception, virt=0 1604 + 1605 + GEN_KVM hmi_exception_early 2157 1606 2158 1607 EXC_COMMON_BEGIN(hmi_exception_common) 2159 - INT_COMMON 0xe60, PACA_EXGEN, 1, 1, 1, 0, 0 1608 + GEN_COMMON hmi_exception 2160 1609 FINISH_NAP 2161 1610 RUNLATCH_ON 2162 - bl save_nvgprs 2163 1611 addi r3,r1,STACK_FRAME_OVERHEAD 2164 1612 bl handle_hmi_exception 2165 - b ret_from_except 1613 + b interrupt_return 2166 1614 1615 + GEN_KVM hmi_exception 1616 + 1617 + 1618 + /** 1619 + * Interrupt 0xe80 - Directed Hypervisor Doorbell Interrupt. 1620 + * This is an asynchronous interrupt in response to a msgsnd doorbell. 1621 + * Similar to the 0xa00 doorbell but for host rather than guest. 1622 + */ 1623 + INT_DEFINE_BEGIN(h_doorbell) 1624 + IVEC=0xe80 1625 + IHSRR=1 1626 + IMASK=IRQS_DISABLED 1627 + IKVM_REAL=1 1628 + IKVM_VIRT=1 1629 + INT_DEFINE_END(h_doorbell) 2167 1630 2168 1631 EXC_REAL_BEGIN(h_doorbell, 0xe80, 0x20) 2169 - INT_HANDLER h_doorbell, 0xe80, ool=1, hsrr=EXC_HV, bitmask=IRQS_DISABLED, kvm=1 1632 + GEN_INT_ENTRY h_doorbell, virt=0, ool=1 2170 1633 EXC_REAL_END(h_doorbell, 0xe80, 0x20) 2171 1634 EXC_VIRT_BEGIN(h_doorbell, 0x4e80, 0x20) 2172 - INT_HANDLER h_doorbell, 0xe80, ool=1, virt=1, hsrr=EXC_HV, bitmask=IRQS_DISABLED, kvm=1 1635 + GEN_INT_ENTRY h_doorbell, virt=1, ool=1 2173 1636 EXC_VIRT_END(h_doorbell, 0x4e80, 0x20) 2174 - INT_KVM_HANDLER h_doorbell, 0xe80, EXC_HV, PACA_EXGEN, 0 1637 + EXC_COMMON_BEGIN(h_doorbell_common) 1638 + GEN_COMMON h_doorbell 1639 + FINISH_NAP 1640 + RUNLATCH_ON 1641 + addi r3,r1,STACK_FRAME_OVERHEAD 2175 1642 #ifdef CONFIG_PPC_DOORBELL 2176 - EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception) 1643 + bl doorbell_exception 2177 1644 #else 2178 - EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception) 1645 + bl unknown_exception 2179 1646 #endif 1647 + b interrupt_return 2180 1648 1649 + GEN_KVM h_doorbell 1650 + 1651 + 1652 + /** 1653 + * Interrupt 0xea0 - Hypervisor Virtualization Interrupt. 1654 + * This is an asynchronous interrupt in response to an "external exception". 1655 + * Similar to 0x500 but for host only. 1656 + */ 1657 + INT_DEFINE_BEGIN(h_virt_irq) 1658 + IVEC=0xea0 1659 + IHSRR=1 1660 + IMASK=IRQS_DISABLED 1661 + IKVM_REAL=1 1662 + IKVM_VIRT=1 1663 + INT_DEFINE_END(h_virt_irq) 2181 1664 2182 1665 EXC_REAL_BEGIN(h_virt_irq, 0xea0, 0x20) 2183 - INT_HANDLER h_virt_irq, 0xea0, ool=1, hsrr=EXC_HV, bitmask=IRQS_DISABLED, kvm=1 1666 + GEN_INT_ENTRY h_virt_irq, virt=0, ool=1 2184 1667 EXC_REAL_END(h_virt_irq, 0xea0, 0x20) 2185 1668 EXC_VIRT_BEGIN(h_virt_irq, 0x4ea0, 0x20) 2186 - INT_HANDLER h_virt_irq, 0xea0, ool=1, virt=1, hsrr=EXC_HV, bitmask=IRQS_DISABLED, kvm=1 1669 + GEN_INT_ENTRY h_virt_irq, virt=1, ool=1 2187 1670 EXC_VIRT_END(h_virt_irq, 0x4ea0, 0x20) 2188 - INT_KVM_HANDLER h_virt_irq, 0xea0, EXC_HV, PACA_EXGEN, 0 2189 - EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ) 1671 + EXC_COMMON_BEGIN(h_virt_irq_common) 1672 + GEN_COMMON h_virt_irq 1673 + FINISH_NAP 1674 + RUNLATCH_ON 1675 + addi r3,r1,STACK_FRAME_OVERHEAD 1676 + bl do_IRQ 1677 + b interrupt_return 1678 + 1679 + GEN_KVM h_virt_irq 2190 1680 2191 1681 2192 1682 EXC_REAL_NONE(0xec0, 0x20) ··· 2238 1642 EXC_VIRT_NONE(0x4ee0, 0x20) 2239 1643 2240 1644 1645 + /* 1646 + * Interrupt 0xf00 - Performance Monitor Interrupt (PMI, PMU). 1647 + * This is an asynchronous interrupt in response to a PMU exception. 1648 + * It is maskable in hardware by clearing MSR[EE], and soft-maskable with 1649 + * IRQS_PMI_DISABLED mask (NOTE: NOT local_irq_disable()). 1650 + * 1651 + * Handling: 1652 + * This calls into the perf subsystem. 1653 + * 1654 + * Like the watchdog soft-nmi, it appears an NMI interrupt to Linux, in that it 1655 + * runs under local_irq_disable. However it may be soft-masked in 1656 + * powerpc-specific code. 1657 + * 1658 + * If soft masked, the masked handler will note the pending interrupt for 1659 + * replay, and clear MSR[EE] in the interrupted context. 1660 + */ 1661 + INT_DEFINE_BEGIN(performance_monitor) 1662 + IVEC=0xf00 1663 + IMASK=IRQS_PMI_DISABLED 1664 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1665 + IKVM_REAL=1 1666 + #endif 1667 + INT_DEFINE_END(performance_monitor) 1668 + 2241 1669 EXC_REAL_BEGIN(performance_monitor, 0xf00, 0x20) 2242 - INT_HANDLER performance_monitor, 0xf00, ool=1, bitmask=IRQS_PMI_DISABLED, kvm=1 1670 + GEN_INT_ENTRY performance_monitor, virt=0, ool=1 2243 1671 EXC_REAL_END(performance_monitor, 0xf00, 0x20) 2244 1672 EXC_VIRT_BEGIN(performance_monitor, 0x4f00, 0x20) 2245 - INT_HANDLER performance_monitor, 0xf00, ool=1, virt=1, bitmask=IRQS_PMI_DISABLED 1673 + GEN_INT_ENTRY performance_monitor, virt=1, ool=1 2246 1674 EXC_VIRT_END(performance_monitor, 0x4f00, 0x20) 2247 - INT_KVM_HANDLER performance_monitor, 0xf00, EXC_STD, PACA_EXGEN, 0 2248 - EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception) 1675 + EXC_COMMON_BEGIN(performance_monitor_common) 1676 + GEN_COMMON performance_monitor 1677 + FINISH_NAP 1678 + RUNLATCH_ON 1679 + addi r3,r1,STACK_FRAME_OVERHEAD 1680 + bl performance_monitor_exception 1681 + b interrupt_return 2249 1682 1683 + GEN_KVM performance_monitor 1684 + 1685 + 1686 + /** 1687 + * Interrupt 0xf20 - Vector Unavailable Interrupt. 1688 + * This is a synchronous interrupt in response to 1689 + * executing a vector (or altivec) instruction with MSR[VEC]=0. 1690 + * Similar to FP unavailable. 1691 + */ 1692 + INT_DEFINE_BEGIN(altivec_unavailable) 1693 + IVEC=0xf20 1694 + IRECONCILE=0 1695 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1696 + IKVM_REAL=1 1697 + #endif 1698 + INT_DEFINE_END(altivec_unavailable) 2250 1699 2251 1700 EXC_REAL_BEGIN(altivec_unavailable, 0xf20, 0x20) 2252 - INT_HANDLER altivec_unavailable, 0xf20, ool=1, kvm=1 1701 + GEN_INT_ENTRY altivec_unavailable, virt=0, ool=1 2253 1702 EXC_REAL_END(altivec_unavailable, 0xf20, 0x20) 2254 1703 EXC_VIRT_BEGIN(altivec_unavailable, 0x4f20, 0x20) 2255 - INT_HANDLER altivec_unavailable, 0xf20, ool=1, virt=1 1704 + GEN_INT_ENTRY altivec_unavailable, virt=1, ool=1 2256 1705 EXC_VIRT_END(altivec_unavailable, 0x4f20, 0x20) 2257 - INT_KVM_HANDLER altivec_unavailable, 0xf20, EXC_STD, PACA_EXGEN, 0 2258 1706 EXC_COMMON_BEGIN(altivec_unavailable_common) 2259 - INT_COMMON 0xf20, PACA_EXGEN, 1, 1, 0, 0, 0 1707 + GEN_COMMON altivec_unavailable 2260 1708 #ifdef CONFIG_ALTIVEC 2261 1709 BEGIN_FTR_SECTION 2262 1710 beq 1f ··· 2314 1674 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69) 2315 1675 #endif 2316 1676 bl load_up_altivec 2317 - b fast_exception_return 1677 + b fast_interrupt_return 2318 1678 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 2319 1679 2: /* User process was in a transaction */ 2320 - bl save_nvgprs 2321 1680 RECONCILE_IRQ_STATE(r10, r11) 2322 1681 addi r3,r1,STACK_FRAME_OVERHEAD 2323 1682 bl altivec_unavailable_tm 2324 - b ret_from_except 1683 + b interrupt_return 2325 1684 #endif 2326 1685 1: 2327 1686 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 2328 1687 #endif 2329 - bl save_nvgprs 2330 1688 RECONCILE_IRQ_STATE(r10, r11) 2331 1689 addi r3,r1,STACK_FRAME_OVERHEAD 2332 1690 bl altivec_unavailable_exception 2333 - b ret_from_except 1691 + b interrupt_return 2334 1692 1693 + GEN_KVM altivec_unavailable 1694 + 1695 + 1696 + /** 1697 + * Interrupt 0xf40 - VSX Unavailable Interrupt. 1698 + * This is a synchronous interrupt in response to 1699 + * executing a VSX instruction with MSR[VSX]=0. 1700 + * Similar to FP unavailable. 1701 + */ 1702 + INT_DEFINE_BEGIN(vsx_unavailable) 1703 + IVEC=0xf40 1704 + IRECONCILE=0 1705 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1706 + IKVM_REAL=1 1707 + #endif 1708 + INT_DEFINE_END(vsx_unavailable) 2335 1709 2336 1710 EXC_REAL_BEGIN(vsx_unavailable, 0xf40, 0x20) 2337 - INT_HANDLER vsx_unavailable, 0xf40, ool=1, kvm=1 1711 + GEN_INT_ENTRY vsx_unavailable, virt=0, ool=1 2338 1712 EXC_REAL_END(vsx_unavailable, 0xf40, 0x20) 2339 1713 EXC_VIRT_BEGIN(vsx_unavailable, 0x4f40, 0x20) 2340 - INT_HANDLER vsx_unavailable, 0xf40, ool=1, virt=1 1714 + GEN_INT_ENTRY vsx_unavailable, virt=1, ool=1 2341 1715 EXC_VIRT_END(vsx_unavailable, 0x4f40, 0x20) 2342 - INT_KVM_HANDLER vsx_unavailable, 0xf40, EXC_STD, PACA_EXGEN, 0 2343 1716 EXC_COMMON_BEGIN(vsx_unavailable_common) 2344 - INT_COMMON 0xf40, PACA_EXGEN, 1, 1, 0, 0, 0 1717 + GEN_COMMON vsx_unavailable 2345 1718 #ifdef CONFIG_VSX 2346 1719 BEGIN_FTR_SECTION 2347 1720 beq 1f ··· 2370 1717 b load_up_vsx 2371 1718 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 2372 1719 2: /* User process was in a transaction */ 2373 - bl save_nvgprs 2374 1720 RECONCILE_IRQ_STATE(r10, r11) 2375 1721 addi r3,r1,STACK_FRAME_OVERHEAD 2376 1722 bl vsx_unavailable_tm 2377 - b ret_from_except 1723 + b interrupt_return 2378 1724 #endif 2379 1725 1: 2380 1726 END_FTR_SECTION_IFSET(CPU_FTR_VSX) 2381 1727 #endif 2382 - bl save_nvgprs 2383 1728 RECONCILE_IRQ_STATE(r10, r11) 2384 1729 addi r3,r1,STACK_FRAME_OVERHEAD 2385 1730 bl vsx_unavailable_exception 2386 - b ret_from_except 1731 + b interrupt_return 2387 1732 1733 + GEN_KVM vsx_unavailable 1734 + 1735 + 1736 + /** 1737 + * Interrupt 0xf60 - Facility Unavailable Interrupt. 1738 + * This is a synchronous interrupt in response to 1739 + * executing an instruction without access to the facility that can be 1740 + * resolved by the OS (e.g., FSCR, MSR). 1741 + * Similar to FP unavailable. 1742 + */ 1743 + INT_DEFINE_BEGIN(facility_unavailable) 1744 + IVEC=0xf60 1745 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1746 + IKVM_REAL=1 1747 + #endif 1748 + INT_DEFINE_END(facility_unavailable) 2388 1749 2389 1750 EXC_REAL_BEGIN(facility_unavailable, 0xf60, 0x20) 2390 - INT_HANDLER facility_unavailable, 0xf60, ool=1, kvm=1 1751 + GEN_INT_ENTRY facility_unavailable, virt=0, ool=1 2391 1752 EXC_REAL_END(facility_unavailable, 0xf60, 0x20) 2392 1753 EXC_VIRT_BEGIN(facility_unavailable, 0x4f60, 0x20) 2393 - INT_HANDLER facility_unavailable, 0xf60, ool=1, virt=1 1754 + GEN_INT_ENTRY facility_unavailable, virt=1, ool=1 2394 1755 EXC_VIRT_END(facility_unavailable, 0x4f60, 0x20) 2395 - INT_KVM_HANDLER facility_unavailable, 0xf60, EXC_STD, PACA_EXGEN, 0 2396 - EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception) 1756 + EXC_COMMON_BEGIN(facility_unavailable_common) 1757 + GEN_COMMON facility_unavailable 1758 + addi r3,r1,STACK_FRAME_OVERHEAD 1759 + bl facility_unavailable_exception 1760 + b interrupt_return 2397 1761 1762 + GEN_KVM facility_unavailable 1763 + 1764 + 1765 + /** 1766 + * Interrupt 0xf60 - Hypervisor Facility Unavailable Interrupt. 1767 + * This is a synchronous interrupt in response to 1768 + * executing an instruction without access to the facility that can only 1769 + * be resolved in HV mode (e.g., HFSCR). 1770 + * Similar to FP unavailable. 1771 + */ 1772 + INT_DEFINE_BEGIN(h_facility_unavailable) 1773 + IVEC=0xf80 1774 + IHSRR=1 1775 + IKVM_REAL=1 1776 + IKVM_VIRT=1 1777 + INT_DEFINE_END(h_facility_unavailable) 2398 1778 2399 1779 EXC_REAL_BEGIN(h_facility_unavailable, 0xf80, 0x20) 2400 - INT_HANDLER h_facility_unavailable, 0xf80, ool=1, hsrr=EXC_HV, kvm=1 1780 + GEN_INT_ENTRY h_facility_unavailable, virt=0, ool=1 2401 1781 EXC_REAL_END(h_facility_unavailable, 0xf80, 0x20) 2402 1782 EXC_VIRT_BEGIN(h_facility_unavailable, 0x4f80, 0x20) 2403 - INT_HANDLER h_facility_unavailable, 0xf80, ool=1, virt=1, hsrr=EXC_HV, kvm=1 1783 + GEN_INT_ENTRY h_facility_unavailable, virt=1, ool=1 2404 1784 EXC_VIRT_END(h_facility_unavailable, 0x4f80, 0x20) 2405 - INT_KVM_HANDLER h_facility_unavailable, 0xf80, EXC_HV, PACA_EXGEN, 0 2406 - EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception) 1785 + EXC_COMMON_BEGIN(h_facility_unavailable_common) 1786 + GEN_COMMON h_facility_unavailable 1787 + addi r3,r1,STACK_FRAME_OVERHEAD 1788 + bl facility_unavailable_exception 1789 + b interrupt_return 1790 + 1791 + GEN_KVM h_facility_unavailable 2407 1792 2408 1793 2409 1794 EXC_REAL_NONE(0xfa0, 0x20) ··· 2457 1766 EXC_VIRT_NONE(0x5100, 0x100) 2458 1767 2459 1768 #ifdef CONFIG_CBE_RAS 1769 + INT_DEFINE_BEGIN(cbe_system_error) 1770 + IVEC=0x1200 1771 + IHSRR=1 1772 + IKVM_SKIP=1 1773 + IKVM_REAL=1 1774 + INT_DEFINE_END(cbe_system_error) 1775 + 2460 1776 EXC_REAL_BEGIN(cbe_system_error, 0x1200, 0x100) 2461 - INT_HANDLER cbe_system_error, 0x1200, ool=1, hsrr=EXC_HV, kvm=1 1777 + GEN_INT_ENTRY cbe_system_error, virt=0 2462 1778 EXC_REAL_END(cbe_system_error, 0x1200, 0x100) 2463 1779 EXC_VIRT_NONE(0x5200, 0x100) 2464 - INT_KVM_HANDLER cbe_system_error, 0x1200, EXC_HV, PACA_EXGEN, 1 2465 - EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception) 1780 + EXC_COMMON_BEGIN(cbe_system_error_common) 1781 + GEN_COMMON cbe_system_error 1782 + addi r3,r1,STACK_FRAME_OVERHEAD 1783 + bl cbe_system_error_exception 1784 + b interrupt_return 1785 + 1786 + GEN_KVM cbe_system_error 1787 + 2466 1788 #else /* CONFIG_CBE_RAS */ 2467 1789 EXC_REAL_NONE(0x1200, 0x100) 2468 1790 EXC_VIRT_NONE(0x5200, 0x100) 2469 1791 #endif 2470 1792 2471 1793 1794 + INT_DEFINE_BEGIN(instruction_breakpoint) 1795 + IVEC=0x1300 1796 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1797 + IKVM_SKIP=1 1798 + IKVM_REAL=1 1799 + #endif 1800 + INT_DEFINE_END(instruction_breakpoint) 1801 + 2472 1802 EXC_REAL_BEGIN(instruction_breakpoint, 0x1300, 0x100) 2473 - INT_HANDLER instruction_breakpoint, 0x1300, kvm=1 1803 + GEN_INT_ENTRY instruction_breakpoint, virt=0 2474 1804 EXC_REAL_END(instruction_breakpoint, 0x1300, 0x100) 2475 1805 EXC_VIRT_BEGIN(instruction_breakpoint, 0x5300, 0x100) 2476 - INT_HANDLER instruction_breakpoint, 0x1300, virt=1 1806 + GEN_INT_ENTRY instruction_breakpoint, virt=1 2477 1807 EXC_VIRT_END(instruction_breakpoint, 0x5300, 0x100) 2478 - INT_KVM_HANDLER instruction_breakpoint, 0x1300, EXC_STD, PACA_EXGEN, 1 2479 - EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception) 1808 + EXC_COMMON_BEGIN(instruction_breakpoint_common) 1809 + GEN_COMMON instruction_breakpoint 1810 + addi r3,r1,STACK_FRAME_OVERHEAD 1811 + bl instruction_breakpoint_exception 1812 + b interrupt_return 1813 + 1814 + GEN_KVM instruction_breakpoint 2480 1815 2481 1816 2482 1817 EXC_REAL_NONE(0x1400, 0x100) 2483 1818 EXC_VIRT_NONE(0x5400, 0x100) 2484 1819 2485 - EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100) 2486 - INT_HANDLER denorm_exception_hv, 0x1500, early=2, hsrr=EXC_HV 1820 + /** 1821 + * Interrupt 0x1500 - Soft Patch Interrupt 1822 + * 1823 + * Handling: 1824 + * This is an implementation specific interrupt which can be used for a 1825 + * range of exceptions. 1826 + * 1827 + * This interrupt handler is unique in that it runs the denormal assist 1828 + * code even for guests (and even in guest context) without going to KVM, 1829 + * for speed. POWER9 does not raise denorm exceptions, so this special case 1830 + * could be phased out in future to reduce special cases. 1831 + */ 1832 + INT_DEFINE_BEGIN(denorm_exception) 1833 + IVEC=0x1500 1834 + IHSRR=1 1835 + IBRANCH_COMMON=0 1836 + IKVM_REAL=1 1837 + INT_DEFINE_END(denorm_exception) 1838 + 1839 + EXC_REAL_BEGIN(denorm_exception, 0x1500, 0x100) 1840 + GEN_INT_ENTRY denorm_exception, virt=0 2487 1841 #ifdef CONFIG_PPC_DENORMALISATION 2488 - mfspr r10,SPRN_HSRR1 2489 - andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */ 1842 + andis. r10,r12,(HSRR1_DENORM)@h /* denorm? */ 2490 1843 bne+ denorm_assist 2491 1844 #endif 2492 - KVMTEST denorm_exception_hv, EXC_HV 0x1500 2493 - INT_SAVE_SRR_AND_JUMP denorm_common, EXC_HV, 1 2494 - EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100) 2495 - 1845 + GEN_BRANCH_TO_COMMON denorm_exception, virt=0 1846 + EXC_REAL_END(denorm_exception, 0x1500, 0x100) 2496 1847 #ifdef CONFIG_PPC_DENORMALISATION 2497 1848 EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100) 2498 - INT_HANDLER denorm_exception, 0x1500, 0, 2, 1, EXC_HV, PACA_EXGEN, 1, 0, 0, 0, 0 2499 - mfspr r10,SPRN_HSRR1 2500 - andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */ 1849 + GEN_INT_ENTRY denorm_exception, virt=1 1850 + andis. r10,r12,(HSRR1_DENORM)@h /* denorm? */ 2501 1851 bne+ denorm_assist 2502 - INT_VIRT_SAVE_SRR_AND_JUMP denorm_common, EXC_HV 1852 + GEN_BRANCH_TO_COMMON denorm_exception, virt=1 2503 1853 EXC_VIRT_END(denorm_exception, 0x5500, 0x100) 2504 1854 #else 2505 1855 EXC_VIRT_NONE(0x5500, 0x100) 2506 1856 #endif 2507 - 2508 - INT_KVM_HANDLER denorm_exception_hv, 0x1500, EXC_HV, PACA_EXGEN, 0 2509 1857 2510 1858 #ifdef CONFIG_PPC_DENORMALISATION 2511 1859 TRAMP_REAL_BEGIN(denorm_assist) ··· 2602 1872 mtspr SPRN_HSRR0,r11 2603 1873 mtcrf 0x80,r9 2604 1874 ld r9,PACA_EXGEN+EX_R9(r13) 2605 - RESTORE_PPR_PACA(PACA_EXGEN, r10) 1875 + BEGIN_FTR_SECTION 1876 + ld r10,PACA_EXGEN+EX_PPR(r13) 1877 + mtspr SPRN_PPR,r10 1878 + END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) 2606 1879 BEGIN_FTR_SECTION 2607 1880 ld r10,PACA_EXGEN+EX_CFAR(r13) 2608 1881 mtspr SPRN_CFAR,r10 ··· 2618 1885 b . 2619 1886 #endif 2620 1887 2621 - EXC_COMMON(denorm_common, 0x1500, unknown_exception) 1888 + EXC_COMMON_BEGIN(denorm_exception_common) 1889 + GEN_COMMON denorm_exception 1890 + addi r3,r1,STACK_FRAME_OVERHEAD 1891 + bl unknown_exception 1892 + b interrupt_return 1893 + 1894 + GEN_KVM denorm_exception 2622 1895 2623 1896 2624 1897 #ifdef CONFIG_CBE_RAS 1898 + INT_DEFINE_BEGIN(cbe_maintenance) 1899 + IVEC=0x1600 1900 + IHSRR=1 1901 + IKVM_SKIP=1 1902 + IKVM_REAL=1 1903 + INT_DEFINE_END(cbe_maintenance) 1904 + 2625 1905 EXC_REAL_BEGIN(cbe_maintenance, 0x1600, 0x100) 2626 - INT_HANDLER cbe_maintenance, 0x1600, ool=1, hsrr=EXC_HV, kvm=1 1906 + GEN_INT_ENTRY cbe_maintenance, virt=0 2627 1907 EXC_REAL_END(cbe_maintenance, 0x1600, 0x100) 2628 1908 EXC_VIRT_NONE(0x5600, 0x100) 2629 - INT_KVM_HANDLER cbe_maintenance, 0x1600, EXC_HV, PACA_EXGEN, 1 2630 - EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception) 1909 + EXC_COMMON_BEGIN(cbe_maintenance_common) 1910 + GEN_COMMON cbe_maintenance 1911 + addi r3,r1,STACK_FRAME_OVERHEAD 1912 + bl cbe_maintenance_exception 1913 + b interrupt_return 1914 + 1915 + GEN_KVM cbe_maintenance 1916 + 2631 1917 #else /* CONFIG_CBE_RAS */ 2632 1918 EXC_REAL_NONE(0x1600, 0x100) 2633 1919 EXC_VIRT_NONE(0x5600, 0x100) 2634 1920 #endif 2635 1921 2636 1922 1923 + INT_DEFINE_BEGIN(altivec_assist) 1924 + IVEC=0x1700 1925 + #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 1926 + IKVM_REAL=1 1927 + #endif 1928 + INT_DEFINE_END(altivec_assist) 1929 + 2637 1930 EXC_REAL_BEGIN(altivec_assist, 0x1700, 0x100) 2638 - INT_HANDLER altivec_assist, 0x1700, kvm=1 1931 + GEN_INT_ENTRY altivec_assist, virt=0 2639 1932 EXC_REAL_END(altivec_assist, 0x1700, 0x100) 2640 1933 EXC_VIRT_BEGIN(altivec_assist, 0x5700, 0x100) 2641 - INT_HANDLER altivec_assist, 0x1700, virt=1 1934 + GEN_INT_ENTRY altivec_assist, virt=1 2642 1935 EXC_VIRT_END(altivec_assist, 0x5700, 0x100) 2643 - INT_KVM_HANDLER altivec_assist, 0x1700, EXC_STD, PACA_EXGEN, 0 1936 + EXC_COMMON_BEGIN(altivec_assist_common) 1937 + GEN_COMMON altivec_assist 1938 + addi r3,r1,STACK_FRAME_OVERHEAD 2644 1939 #ifdef CONFIG_ALTIVEC 2645 - EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception) 1940 + bl altivec_assist_exception 1941 + REST_NVGPRS(r1) /* instruction emulation may change GPRs */ 2646 1942 #else 2647 - EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception) 1943 + bl unknown_exception 2648 1944 #endif 1945 + b interrupt_return 1946 + 1947 + GEN_KVM altivec_assist 2649 1948 2650 1949 2651 1950 #ifdef CONFIG_CBE_RAS 1951 + INT_DEFINE_BEGIN(cbe_thermal) 1952 + IVEC=0x1800 1953 + IHSRR=1 1954 + IKVM_SKIP=1 1955 + IKVM_REAL=1 1956 + INT_DEFINE_END(cbe_thermal) 1957 + 2652 1958 EXC_REAL_BEGIN(cbe_thermal, 0x1800, 0x100) 2653 - INT_HANDLER cbe_thermal, 0x1800, ool=1, hsrr=EXC_HV, kvm=1 1959 + GEN_INT_ENTRY cbe_thermal, virt=0 2654 1960 EXC_REAL_END(cbe_thermal, 0x1800, 0x100) 2655 1961 EXC_VIRT_NONE(0x5800, 0x100) 2656 - INT_KVM_HANDLER cbe_thermal, 0x1800, EXC_HV, PACA_EXGEN, 1 2657 - EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception) 1962 + EXC_COMMON_BEGIN(cbe_thermal_common) 1963 + GEN_COMMON cbe_thermal 1964 + addi r3,r1,STACK_FRAME_OVERHEAD 1965 + bl cbe_thermal_exception 1966 + b interrupt_return 1967 + 1968 + GEN_KVM cbe_thermal 1969 + 2658 1970 #else /* CONFIG_CBE_RAS */ 2659 1971 EXC_REAL_NONE(0x1800, 0x100) 2660 1972 EXC_VIRT_NONE(0x5800, 0x100) ··· 2708 1930 2709 1931 #ifdef CONFIG_PPC_WATCHDOG 2710 1932 2711 - #define MASKED_DEC_HANDLER_LABEL 3f 2712 - 2713 - #define MASKED_DEC_HANDLER(_H) \ 2714 - 3: /* soft-nmi */ \ 2715 - std r12,PACA_EXGEN+EX_R12(r13); \ 2716 - GET_SCRATCH0(r10); \ 2717 - std r10,PACA_EXGEN+EX_R13(r13); \ 2718 - INT_SAVE_SRR_AND_JUMP soft_nmi_common, _H, 1 1933 + INT_DEFINE_BEGIN(soft_nmi) 1934 + IVEC=0x900 1935 + ISTACK=0 1936 + IRECONCILE=0 /* Soft-NMI may fire under local_irq_disable */ 1937 + INT_DEFINE_END(soft_nmi) 2719 1938 2720 1939 /* 2721 1940 * Branch to soft_nmi_interrupt using the emergency stack. The emergency ··· 2724 1949 * and run it entirely with interrupts hard disabled. 2725 1950 */ 2726 1951 EXC_COMMON_BEGIN(soft_nmi_common) 1952 + mfspr r11,SPRN_SRR0 2727 1953 mr r10,r1 2728 1954 ld r1,PACAEMERGSP(r13) 2729 1955 subi r1,r1,INT_FRAME_SIZE 2730 - INT_COMMON 0x900, PACA_EXGEN, 0, 1, 1, 0, 0 2731 - bl save_nvgprs 1956 + __GEN_COMMON_BODY soft_nmi 1957 + 1958 + /* 1959 + * Set IRQS_ALL_DISABLED and save PACAIRQHAPPENED (see 1960 + * system_reset_common) 1961 + */ 1962 + li r10,IRQS_ALL_DISABLED 1963 + stb r10,PACAIRQSOFTMASK(r13) 1964 + lbz r10,PACAIRQHAPPENED(r13) 1965 + std r10,_DAR(r1) 1966 + ori r10,r10,PACA_IRQ_HARD_DIS 1967 + stb r10,PACAIRQHAPPENED(r13) 1968 + 2732 1969 addi r3,r1,STACK_FRAME_OVERHEAD 2733 1970 bl soft_nmi_interrupt 2734 - b ret_from_except 2735 1971 2736 - #else /* CONFIG_PPC_WATCHDOG */ 2737 - #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */ 2738 - #define MASKED_DEC_HANDLER(_H) 1972 + /* Clear MSR_RI before setting SRR0 and SRR1. */ 1973 + li r9,0 1974 + mtmsrd r9,1 1975 + 1976 + /* 1977 + * Restore soft mask settings. 1978 + */ 1979 + ld r10,_DAR(r1) 1980 + stb r10,PACAIRQHAPPENED(r13) 1981 + ld r10,SOFTE(r1) 1982 + stb r10,PACAIRQSOFTMASK(r13) 1983 + 1984 + kuap_restore_amr r10 1985 + EXCEPTION_RESTORE_REGS hsrr=0 1986 + RFI_TO_KERNEL 1987 + 2739 1988 #endif /* CONFIG_PPC_WATCHDOG */ 2740 1989 2741 1990 /* ··· 2772 1973 * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return. 2773 1974 * This is called with r10 containing the value to OR to the paca field. 2774 1975 */ 2775 - .macro MASKED_INTERRUPT hsrr 1976 + .macro MASKED_INTERRUPT hsrr=0 2776 1977 .if \hsrr 2777 1978 masked_Hinterrupt: 2778 1979 .else 2779 1980 masked_interrupt: 2780 1981 .endif 2781 - std r11,PACA_EXGEN+EX_R11(r13) 2782 1982 lbz r11,PACAIRQHAPPENED(r13) 2783 1983 or r11,r11,r10 2784 1984 stb r11,PACAIRQHAPPENED(r13) ··· 2786 1988 lis r10,0x7fff 2787 1989 ori r10,r10,0xffff 2788 1990 mtspr SPRN_DEC,r10 2789 - b MASKED_DEC_HANDLER_LABEL 1991 + #ifdef CONFIG_PPC_WATCHDOG 1992 + b soft_nmi_common 1993 + #else 1994 + b 2f 1995 + #endif 2790 1996 1: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK 2791 1997 beq 2f 1998 + xori r12,r12,MSR_EE /* clear MSR_EE */ 2792 1999 .if \hsrr 2793 - mfspr r10,SPRN_HSRR1 2794 - xori r10,r10,MSR_EE /* clear MSR_EE */ 2795 - mtspr SPRN_HSRR1,r10 2000 + mtspr SPRN_HSRR1,r12 2796 2001 .else 2797 - mfspr r10,SPRN_SRR1 2798 - xori r10,r10,MSR_EE /* clear MSR_EE */ 2799 - mtspr SPRN_SRR1,r10 2002 + mtspr SPRN_SRR1,r12 2800 2003 .endif 2801 2004 ori r11,r11,PACA_IRQ_HARD_DIS 2802 2005 stb r11,PACAIRQHAPPENED(r13) 2803 2006 2: /* done */ 2007 + ld r10,PACA_EXGEN+EX_CTR(r13) 2008 + mtctr r10 2804 2009 mtcrf 0x80,r9 2805 2010 std r1,PACAR1(r13) 2806 2011 ld r9,PACA_EXGEN+EX_R9(r13) 2807 2012 ld r10,PACA_EXGEN+EX_R10(r13) 2808 2013 ld r11,PACA_EXGEN+EX_R11(r13) 2014 + ld r12,PACA_EXGEN+EX_R12(r13) 2809 2015 /* returns to kernel where r13 must be set up, so don't restore it */ 2810 2016 .if \hsrr 2811 2017 HRFI_TO_KERNEL ··· 2817 2015 RFI_TO_KERNEL 2818 2016 .endif 2819 2017 b . 2820 - MASKED_DEC_HANDLER(\hsrr\()) 2821 2018 .endm 2822 2019 2823 2020 TRAMP_REAL_BEGIN(stf_barrier_fallback) ··· 2918 2117 GET_SCRATCH0(r13); 2919 2118 hrfid 2920 2119 2921 - /* 2922 - * Real mode exceptions actually use this too, but alternate 2923 - * instruction code patches (which end up in the common .text area) 2924 - * cannot reach these if they are put there. 2925 - */ 2926 - USE_FIXED_SECTION(virt_trampolines) 2927 - MASKED_INTERRUPT EXC_STD 2928 - MASKED_INTERRUPT EXC_HV 2120 + USE_TEXT_SECTION() 2121 + MASKED_INTERRUPT 2122 + MASKED_INTERRUPT hsrr=1 2929 2123 2930 2124 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 2931 - TRAMP_REAL_BEGIN(kvmppc_skip_interrupt) 2125 + kvmppc_skip_interrupt: 2932 2126 /* 2933 2127 * Here all GPRs are unchanged from when the interrupt happened 2934 2128 * except for r13, which is saved in SPRG_SCRATCH0. ··· 2935 2139 RFI_TO_KERNEL 2936 2140 b . 2937 2141 2938 - TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt) 2142 + kvmppc_skip_Hinterrupt: 2939 2143 /* 2940 2144 * Here all GPRs are unchanged from when the interrupt happened 2941 2145 * except for r13, which is saved in SPRG_SCRATCH0. ··· 2947 2151 HRFI_TO_KERNEL 2948 2152 b . 2949 2153 #endif 2950 - 2951 - /* 2952 - * Ensure that any handlers that get invoked from the exception prologs 2953 - * above are below the first 64KB (0x10000) of the kernel image because 2954 - * the prologs assemble the addresses of these handlers using the 2955 - * LOAD_HANDLER macro, which uses an ori instruction. 2956 - */ 2957 - 2958 - /*** Common interrupt handlers ***/ 2959 - 2960 2154 2961 2155 /* 2962 2156 * Relocation-on interrupts: A subset of the interrupts can be delivered ··· 3061 2275 cmpdi r3,0 /* see if __hash_page succeeded */ 3062 2276 3063 2277 /* Success */ 3064 - beq fast_exc_return_irq /* Return from exception on success */ 2278 + beq interrupt_return /* Return from exception on success */ 3065 2279 3066 2280 /* Error */ 3067 2281 blt- 13f ··· 3078 2292 addi r3,r1,STACK_FRAME_OVERHEAD 3079 2293 bl do_page_fault 3080 2294 cmpdi r3,0 3081 - beq+ ret_from_except_lite 3082 - bl save_nvgprs 2295 + beq+ interrupt_return 3083 2296 mr r5,r3 3084 2297 addi r3,r1,STACK_FRAME_OVERHEAD 3085 2298 ld r4,_DAR(r1) 3086 2299 bl bad_page_fault 3087 - b ret_from_except 2300 + b interrupt_return 3088 2301 3089 2302 /* We have a data breakpoint exception - handle it */ 3090 2303 handle_dabr_fault: 3091 - bl save_nvgprs 3092 2304 ld r4,_DAR(r1) 3093 2305 ld r5,_DSISR(r1) 3094 2306 addi r3,r1,STACK_FRAME_OVERHEAD 3095 2307 bl do_break 3096 2308 /* 3097 2309 * do_break() may have changed the NV GPRS while handling a breakpoint. 3098 - * If so, we need to restore them with their updated values. Don't use 3099 - * ret_from_except_lite here. 2310 + * If so, we need to restore them with their updated values. 3100 2311 */ 3101 - b ret_from_except 2312 + REST_NVGPRS(r1) 2313 + b interrupt_return 3102 2314 3103 2315 3104 2316 #ifdef CONFIG_PPC_BOOK3S_64 3105 2317 /* We have a page fault that hash_page could handle but HV refused 3106 2318 * the PTE insertion 3107 2319 */ 3108 - 13: bl save_nvgprs 3109 - mr r5,r3 2320 + 13: mr r5,r3 3110 2321 addi r3,r1,STACK_FRAME_OVERHEAD 3111 2322 ld r4,_DAR(r1) 3112 2323 bl low_hash_fault 3113 - b ret_from_except 2324 + b interrupt_return 3114 2325 #endif 3115 2326 3116 2327 /* ··· 3117 2334 * were soft-disabled. We want to invoke the exception handler for 3118 2335 * the access, or panic if there isn't a handler. 3119 2336 */ 3120 - 77: bl save_nvgprs 3121 - addi r3,r1,STACK_FRAME_OVERHEAD 2337 + 77: addi r3,r1,STACK_FRAME_OVERHEAD 3122 2338 li r5,SIGSEGV 3123 2339 bl bad_page_fault 3124 - b ret_from_except 2340 + b interrupt_return 3125 2341 3126 2342 /* 3127 2343 * When doorbell is triggered from system reset wakeup, the message is ··· 3134 2352 h_doorbell_common_msgclr: 3135 2353 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36)) 3136 2354 PPC_MSGCLR(3) 3137 - b h_doorbell_common 2355 + b h_doorbell_common_virt 3138 2356 3139 2357 doorbell_super_common_msgclr: 3140 2358 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36)) 3141 2359 PPC_MSGCLRP(3) 3142 - b doorbell_super_common 3143 - 3144 - /* 3145 - * Called from arch_local_irq_enable when an interrupt needs 3146 - * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate 3147 - * which kind of interrupt. MSR:EE is already off. We generate a 3148 - * stackframe like if a real interrupt had happened. 3149 - * 3150 - * Note: While MSR:EE is off, we need to make sure that _MSR 3151 - * in the generated frame has EE set to 1 or the exception 3152 - * handler will not properly re-enable them. 3153 - * 3154 - * Note that we don't specify LR as the NIP (return address) for 3155 - * the interrupt because that would unbalance the return branch 3156 - * predictor. 3157 - */ 3158 - _GLOBAL(__replay_interrupt) 3159 - /* We are going to jump to the exception common code which 3160 - * will retrieve various register values from the PACA which 3161 - * we don't give a damn about, so we don't bother storing them. 3162 - */ 3163 - mfmsr r12 3164 - LOAD_REG_ADDR(r11, replay_interrupt_return) 3165 - mfcr r9 3166 - ori r12,r12,MSR_EE 3167 - cmpwi r3,0x900 3168 - beq decrementer_common 3169 - cmpwi r3,0x500 3170 - BEGIN_FTR_SECTION 3171 - beq h_virt_irq_common 3172 - FTR_SECTION_ELSE 3173 - beq hardware_interrupt_common 3174 - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300) 3175 - cmpwi r3,0xf00 3176 - beq performance_monitor_common 3177 - BEGIN_FTR_SECTION 3178 - cmpwi r3,0xa00 3179 - beq h_doorbell_common_msgclr 3180 - cmpwi r3,0xe60 3181 - beq hmi_exception_common 3182 - FTR_SECTION_ELSE 3183 - cmpwi r3,0xa00 3184 - beq doorbell_super_common_msgclr 3185 - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) 3186 - replay_interrupt_return: 3187 - blr 3188 - 3189 - _ASM_NOKPROBE_SYMBOL(__replay_interrupt) 2360 + b doorbell_super_common_virt
+96 -40
arch/powerpc/kernel/fadump.c
··· 36 36 37 37 static void __init fadump_reserve_crash_area(u64 base); 38 38 39 + struct kobject *fadump_kobj; 40 + 39 41 #ifndef CONFIG_PRESERVE_FA_DUMP 40 42 static DEFINE_MUTEX(fadump_mutex); 41 43 struct fadump_mrange_info crash_mrange_info = { "crash", NULL, 0, 0, 0 }; ··· 1325 1323 fw_dump.ops->fadump_init_mem_struct(&fw_dump); 1326 1324 } 1327 1325 1328 - static ssize_t fadump_release_memory_store(struct kobject *kobj, 1329 - struct kobj_attribute *attr, 1330 - const char *buf, size_t count) 1326 + static ssize_t release_mem_store(struct kobject *kobj, 1327 + struct kobj_attribute *attr, 1328 + const char *buf, size_t count) 1331 1329 { 1332 1330 int input = -1; 1333 1331 ··· 1352 1350 return count; 1353 1351 } 1354 1352 1355 - static ssize_t fadump_enabled_show(struct kobject *kobj, 1356 - struct kobj_attribute *attr, 1357 - char *buf) 1353 + /* Release the reserved memory and disable the FADump */ 1354 + static void unregister_fadump(void) 1355 + { 1356 + fadump_cleanup(); 1357 + fadump_release_memory(fw_dump.reserve_dump_area_start, 1358 + fw_dump.reserve_dump_area_size); 1359 + fw_dump.fadump_enabled = 0; 1360 + kobject_put(fadump_kobj); 1361 + } 1362 + 1363 + static ssize_t enabled_show(struct kobject *kobj, 1364 + struct kobj_attribute *attr, 1365 + char *buf) 1358 1366 { 1359 1367 return sprintf(buf, "%d\n", fw_dump.fadump_enabled); 1360 1368 } 1361 1369 1362 - static ssize_t fadump_register_show(struct kobject *kobj, 1363 - struct kobj_attribute *attr, 1364 - char *buf) 1370 + static ssize_t mem_reserved_show(struct kobject *kobj, 1371 + struct kobj_attribute *attr, 1372 + char *buf) 1373 + { 1374 + return sprintf(buf, "%ld\n", fw_dump.reserve_dump_area_size); 1375 + } 1376 + 1377 + static ssize_t registered_show(struct kobject *kobj, 1378 + struct kobj_attribute *attr, 1379 + char *buf) 1365 1380 { 1366 1381 return sprintf(buf, "%d\n", fw_dump.dump_registered); 1367 1382 } 1368 1383 1369 - static ssize_t fadump_register_store(struct kobject *kobj, 1370 - struct kobj_attribute *attr, 1371 - const char *buf, size_t count) 1384 + static ssize_t registered_store(struct kobject *kobj, 1385 + struct kobj_attribute *attr, 1386 + const char *buf, size_t count) 1372 1387 { 1373 1388 int ret = 0; 1374 1389 int input = -1; ··· 1437 1418 return 0; 1438 1419 } 1439 1420 1440 - static struct kobj_attribute fadump_release_attr = __ATTR(fadump_release_mem, 1441 - 0200, NULL, 1442 - fadump_release_memory_store); 1443 - static struct kobj_attribute fadump_attr = __ATTR(fadump_enabled, 1444 - 0444, fadump_enabled_show, 1445 - NULL); 1446 - static struct kobj_attribute fadump_register_attr = __ATTR(fadump_registered, 1447 - 0644, fadump_register_show, 1448 - fadump_register_store); 1421 + static struct kobj_attribute release_attr = __ATTR_WO(release_mem); 1422 + static struct kobj_attribute enable_attr = __ATTR_RO(enabled); 1423 + static struct kobj_attribute register_attr = __ATTR_RW(registered); 1424 + static struct kobj_attribute mem_reserved_attr = __ATTR_RO(mem_reserved); 1425 + 1426 + static struct attribute *fadump_attrs[] = { 1427 + &enable_attr.attr, 1428 + &register_attr.attr, 1429 + &mem_reserved_attr.attr, 1430 + NULL, 1431 + }; 1432 + 1433 + ATTRIBUTE_GROUPS(fadump); 1449 1434 1450 1435 DEFINE_SHOW_ATTRIBUTE(fadump_region); 1451 1436 1452 1437 static void fadump_init_files(void) 1453 1438 { 1454 - struct dentry *debugfs_file; 1455 1439 int rc = 0; 1456 1440 1457 - rc = sysfs_create_file(kernel_kobj, &fadump_attr.attr); 1458 - if (rc) 1459 - printk(KERN_ERR "fadump: unable to create sysfs file" 1460 - " fadump_enabled (%d)\n", rc); 1441 + fadump_kobj = kobject_create_and_add("fadump", kernel_kobj); 1442 + if (!fadump_kobj) { 1443 + pr_err("failed to create fadump kobject\n"); 1444 + return; 1445 + } 1461 1446 1462 - rc = sysfs_create_file(kernel_kobj, &fadump_register_attr.attr); 1463 - if (rc) 1464 - printk(KERN_ERR "fadump: unable to create sysfs file" 1465 - " fadump_registered (%d)\n", rc); 1466 - 1467 - debugfs_file = debugfs_create_file("fadump_region", 0444, 1468 - powerpc_debugfs_root, NULL, 1469 - &fadump_region_fops); 1470 - if (!debugfs_file) 1471 - printk(KERN_ERR "fadump: unable to create debugfs file" 1472 - " fadump_region\n"); 1447 + debugfs_create_file("fadump_region", 0444, powerpc_debugfs_root, NULL, 1448 + &fadump_region_fops); 1473 1449 1474 1450 if (fw_dump.dump_active) { 1475 - rc = sysfs_create_file(kernel_kobj, &fadump_release_attr.attr); 1451 + rc = sysfs_create_file(fadump_kobj, &release_attr.attr); 1476 1452 if (rc) 1477 - printk(KERN_ERR "fadump: unable to create sysfs file" 1478 - " fadump_release_mem (%d)\n", rc); 1453 + pr_err("unable to create release_mem sysfs file (%d)\n", 1454 + rc); 1455 + } 1456 + 1457 + rc = sysfs_create_groups(fadump_kobj, fadump_groups); 1458 + if (rc) { 1459 + pr_err("sysfs group creation failed (%d), unregistering FADump", 1460 + rc); 1461 + unregister_fadump(); 1462 + return; 1463 + } 1464 + 1465 + /* 1466 + * The FADump sysfs are moved from kernel_kobj to fadump_kobj need to 1467 + * create symlink at old location to maintain backward compatibility. 1468 + * 1469 + * - fadump_enabled -> fadump/enabled 1470 + * - fadump_registered -> fadump/registered 1471 + * - fadump_release_mem -> fadump/release_mem 1472 + */ 1473 + rc = compat_only_sysfs_link_entry_to_kobj(kernel_kobj, fadump_kobj, 1474 + "enabled", "fadump_enabled"); 1475 + if (rc) { 1476 + pr_err("unable to create fadump_enabled symlink (%d)", rc); 1477 + return; 1478 + } 1479 + 1480 + rc = compat_only_sysfs_link_entry_to_kobj(kernel_kobj, fadump_kobj, 1481 + "registered", 1482 + "fadump_registered"); 1483 + if (rc) { 1484 + pr_err("unable to create fadump_registered symlink (%d)", rc); 1485 + sysfs_remove_link(kernel_kobj, "fadump_enabled"); 1486 + return; 1487 + } 1488 + 1489 + if (fw_dump.dump_active) { 1490 + rc = compat_only_sysfs_link_entry_to_kobj(kernel_kobj, 1491 + fadump_kobj, 1492 + "release_mem", 1493 + "fadump_release_mem"); 1494 + if (rc) 1495 + pr_err("unable to create fadump_release_mem symlink (%d)", 1496 + rc); 1479 1497 } 1480 1498 return; 1481 1499 }
+3 -6
arch/powerpc/kernel/head_32.S
··· 348 348 andis. r0, r5, (DSISR_BAD_FAULT_32S | DSISR_DABRMATCH)@h 349 349 #endif 350 350 bne handle_page_fault_tramp_2 /* if not, try to put a PTE */ 351 - rlwinm r3, r5, 32 - 15, 21, 21 /* DSISR_STORE -> _PAGE_RW */ 351 + rlwinm r3, r5, 32 - 24, 30, 30 /* DSISR_STORE -> _PAGE_RW */ 352 352 bl hash_page 353 353 b handle_page_fault_tramp_1 354 354 FTR_SECTION_ELSE ··· 497 497 andc. r1,r1,r0 /* check access & ~permission */ 498 498 bne- InstructionAddressInvalid /* return if access not permitted */ 499 499 /* Convert linux-style PTE to low word of PPC-style PTE */ 500 - rlwimi r0,r0,32-2,31,31 /* _PAGE_USER -> PP lsb */ 501 500 ori r1, r1, 0xe06 /* clear out reserved bits */ 502 501 andc r1, r0, r1 /* PP = user? 1 : 0 */ 503 502 BEGIN_FTR_SECTION ··· 564 565 * we would need to update the pte atomically with lwarx/stwcx. 565 566 */ 566 567 /* Convert linux-style PTE to low word of PPC-style PTE */ 567 - rlwinm r1,r0,32-9,30,30 /* _PAGE_RW -> PP msb */ 568 - rlwimi r0,r0,32-1,30,30 /* _PAGE_USER -> PP msb */ 569 - rlwimi r0,r0,32-1,31,31 /* _PAGE_USER -> PP lsb */ 568 + rlwinm r1,r0,0,30,30 /* _PAGE_RW -> PP msb */ 569 + rlwimi r0,r0,1,30,30 /* _PAGE_USER -> PP msb */ 570 570 ori r1,r1,0xe04 /* clear out reserved bits */ 571 571 andc r1,r0,r1 /* PP = user? rw? 1: 3: 0 */ 572 572 BEGIN_FTR_SECTION ··· 643 645 * we would need to update the pte atomically with lwarx/stwcx. 644 646 */ 645 647 /* Convert linux-style PTE to low word of PPC-style PTE */ 646 - rlwimi r0,r0,32-2,31,31 /* _PAGE_USER -> PP lsb */ 647 648 li r1,0xe06 /* clear out reserved bits & PP msb */ 648 649 andc r1,r0,r1 /* PP = user? 1: 0 */ 649 650 BEGIN_FTR_SECTION
+14 -14
arch/powerpc/kernel/head_32.h
··· 130 130 131 131 .macro SYSCALL_ENTRY trapno 132 132 mfspr r12,SPRN_SPRG_THREAD 133 + mfspr r9, SPRN_SRR1 133 134 #ifdef CONFIG_VMAP_STACK 134 - mfspr r9, SPRN_SRR0 135 - mfspr r11, SPRN_SRR1 136 - stw r9, SRR0(r12) 137 - stw r11, SRR1(r12) 135 + mfspr r11, SPRN_SRR0 136 + mtctr r11 138 137 #endif 139 - mfcr r10 138 + andi. r11, r9, MSR_PR 140 139 lwz r11,TASK_STACK-THREAD(r12) 141 - rlwinm r10,r10,0,4,2 /* Clear SO bit in CR */ 140 + beq- 99f 142 141 addi r11, r11, THREAD_SIZE - INT_FRAME_SIZE 143 142 #ifdef CONFIG_VMAP_STACK 144 - li r9, MSR_KERNEL & ~(MSR_IR | MSR_RI) /* can take DTLB miss */ 145 - mtmsr r9 143 + li r10, MSR_KERNEL & ~(MSR_IR | MSR_RI) /* can take DTLB miss */ 144 + mtmsr r10 146 145 isync 147 146 #endif 148 147 tovirt_vmstack r12, r12 149 148 tophys_novmstack r11, r11 150 - mflr r9 151 - stw r10,_CCR(r11) /* save registers */ 152 - stw r9, _LINK(r11) 149 + mflr r10 150 + stw r10, _LINK(r11) 153 151 #ifdef CONFIG_VMAP_STACK 154 - lwz r10, SRR0(r12) 155 - lwz r9, SRR1(r12) 152 + mfctr r10 156 153 #else 157 154 mfspr r10,SPRN_SRR0 158 - mfspr r9,SPRN_SRR1 159 155 #endif 160 156 stw r1,GPR1(r11) 161 157 stw r1,0(r11) 162 158 tovirt_novmstack r1, r11 /* set new kernel sp */ 163 159 stw r10,_NIP(r11) 160 + mfcr r10 161 + rlwinm r10,r10,0,4,2 /* Clear SO bit in CR */ 162 + stw r10,_CCR(r11) /* save registers */ 164 163 #ifdef CONFIG_40x 165 164 rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ 166 165 #else ··· 227 228 mtspr SPRN_SRR0,r11 228 229 SYNC 229 230 RFI /* jump to handler, enable MMU */ 231 + 99: b ret_from_kernel_syscall 230 232 .endm 231 233 232 234 .macro save_dar_dsisr_on_stack reg1, reg2, sp
+3 -1
arch/powerpc/kernel/head_64.S
··· 537 537 b __after_prom_start 538 538 #endif /* CONFIG_PPC_BOOK3E */ 539 539 540 + __REF 540 541 __boot_from_prom: 541 542 #ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE 542 543 /* Save parameters */ ··· 575 574 /* We never return. We also hit that trap if trying to boot 576 575 * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */ 577 576 trap 577 + .previous 578 578 579 579 __after_prom_start: 580 580 #ifdef CONFIG_RELOCATABLE ··· 979 977 RFI 980 978 b . /* prevent speculative execution */ 981 979 982 - .previous 983 980 /* This is where all platforms converge execution */ 984 981 985 982 start_here_common: ··· 1002 1001 /* Not reached */ 1003 1002 trap 1004 1003 EMIT_BUG_ENTRY 0b, __FILE__, __LINE__, 0 1004 + .previous 1005 1005 1006 1006 /* 1007 1007 * We put a few things here that have to be page-aligned.
+4 -1
arch/powerpc/kernel/head_booke.h
··· 104 104 #ifdef CONFIG_KVM_BOOKE_HV 105 105 ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV) 106 106 #endif 107 + mfspr r9, SPRN_SRR1 107 108 BOOKE_CLEAR_BTB(r11) 109 + andi. r11, r9, MSR_PR 108 110 lwz r11, TASK_STACK - THREAD(r10) 109 111 rlwinm r12,r12,0,4,2 /* Clear SO bit in CR */ 112 + beq- 99f 110 113 ALLOC_STACK_FRAME(r11, THREAD_SIZE - INT_FRAME_SIZE) 111 114 stw r12, _CCR(r11) /* save various registers */ 112 115 mflr r12 113 116 stw r12,_LINK(r11) 114 117 mfspr r12,SPRN_SRR0 115 118 stw r1, GPR1(r11) 116 - mfspr r9,SPRN_SRR1 117 119 stw r1, 0(r11) 118 120 mr r1, r11 119 121 stw r12,_NIP(r11) ··· 178 176 mtspr SPRN_SRR0,r11 179 177 SYNC 180 178 RFI /* jump to handler, enable MMU */ 179 + 99: b ret_from_kernel_syscall 181 180 .endm 182 181 183 182 /* To handle the additional exception priority levels on 40x and Book-E
+16
arch/powerpc/kernel/hw_breakpoint.c
··· 429 429 { 430 430 /* TODO */ 431 431 } 432 + 433 + void ptrace_triggered(struct perf_event *bp, 434 + struct perf_sample_data *data, struct pt_regs *regs) 435 + { 436 + struct perf_event_attr attr; 437 + 438 + /* 439 + * Disable the breakpoint request here since ptrace has defined a 440 + * one-shot behaviour for breakpoint exceptions in PPC64. 441 + * The SIGTRAP signal is generated automatically for us in do_dabr(). 442 + * We don't have to do anything about that here 443 + */ 444 + attr = bp->attr; 445 + attr.disabled = true; 446 + modify_user_hw_breakpoint(bp, &attr); 447 + }
+138 -70
arch/powerpc/kernel/irq.c
··· 70 70 #include <asm/paca.h> 71 71 #include <asm/firmware.h> 72 72 #include <asm/lv1call.h> 73 + #include <asm/dbell.h> 73 74 #endif 74 75 #define CREATE_TRACE_POINTS 75 76 #include <asm/trace.h> ··· 109 108 110 109 return now >= *next_tb; 111 110 } 111 + 112 + #ifdef CONFIG_PPC_BOOK3E 112 113 113 114 /* This is called whenever we are re-enabling interrupts 114 115 * and returns either 0 (nothing to do) or 500/900/280/a00/e80 if ··· 171 168 } 172 169 } 173 170 174 - /* 175 - * Force the delivery of pending soft-disabled interrupts on PS3. 176 - * Any HV call will have this side effect. 177 - */ 178 - if (firmware_has_feature(FW_FEATURE_PS3_LV1)) { 179 - u64 tmp, tmp2; 180 - lv1_get_version_info(&tmp, &tmp2); 181 - } 182 - 183 - /* 184 - * Check if an hypervisor Maintenance interrupt happened. 185 - * This is a higher priority interrupt than the others, so 186 - * replay it first. 187 - */ 188 - if (happened & PACA_IRQ_HMI) { 189 - local_paca->irq_happened &= ~PACA_IRQ_HMI; 190 - return 0xe60; 191 - } 192 - 193 171 if (happened & PACA_IRQ_DEC) { 194 172 local_paca->irq_happened &= ~PACA_IRQ_DEC; 195 173 return 0x900; 196 - } 197 - 198 - if (happened & PACA_IRQ_PMI) { 199 - local_paca->irq_happened &= ~PACA_IRQ_PMI; 200 - return 0xf00; 201 174 } 202 175 203 176 if (happened & PACA_IRQ_EE) { ··· 181 202 return 0x500; 182 203 } 183 204 184 - #ifdef CONFIG_PPC_BOOK3E 185 205 /* 186 206 * Check if an EPR external interrupt happened this bit is typically 187 207 * set if we need to handle another "edge" interrupt from within the ··· 195 217 local_paca->irq_happened &= ~PACA_IRQ_DBELL; 196 218 return 0x280; 197 219 } 198 - #else 199 - if (happened & PACA_IRQ_DBELL) { 200 - local_paca->irq_happened &= ~PACA_IRQ_DBELL; 201 - return 0xa00; 202 - } 203 - #endif /* CONFIG_PPC_BOOK3E */ 204 220 205 221 /* There should be nothing left ! */ 206 222 BUG_ON(local_paca->irq_happened != 0); 207 223 208 224 return 0; 209 225 } 226 + #endif /* CONFIG_PPC_BOOK3E */ 227 + 228 + void replay_soft_interrupts(void) 229 + { 230 + /* 231 + * We use local_paca rather than get_paca() to avoid all 232 + * the debug_smp_processor_id() business in this low level 233 + * function 234 + */ 235 + unsigned char happened = local_paca->irq_happened; 236 + struct pt_regs regs; 237 + 238 + ppc_save_regs(&regs); 239 + regs.softe = IRQS_ALL_DISABLED; 240 + 241 + again: 242 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 243 + WARN_ON_ONCE(mfmsr() & MSR_EE); 244 + 245 + if (happened & PACA_IRQ_HARD_DIS) { 246 + /* 247 + * We may have missed a decrementer interrupt if hard disabled. 248 + * Check the decrementer register in case we had a rollover 249 + * while hard disabled. 250 + */ 251 + if (!(happened & PACA_IRQ_DEC)) { 252 + if (decrementer_check_overflow()) 253 + happened |= PACA_IRQ_DEC; 254 + } 255 + } 256 + 257 + /* 258 + * Force the delivery of pending soft-disabled interrupts on PS3. 259 + * Any HV call will have this side effect. 260 + */ 261 + if (firmware_has_feature(FW_FEATURE_PS3_LV1)) { 262 + u64 tmp, tmp2; 263 + lv1_get_version_info(&tmp, &tmp2); 264 + } 265 + 266 + /* 267 + * Check if an hypervisor Maintenance interrupt happened. 268 + * This is a higher priority interrupt than the others, so 269 + * replay it first. 270 + */ 271 + if (IS_ENABLED(CONFIG_PPC_BOOK3S) && (happened & PACA_IRQ_HMI)) { 272 + local_paca->irq_happened &= ~PACA_IRQ_HMI; 273 + regs.trap = 0xe60; 274 + handle_hmi_exception(&regs); 275 + if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) 276 + hard_irq_disable(); 277 + } 278 + 279 + if (happened & PACA_IRQ_DEC) { 280 + local_paca->irq_happened &= ~PACA_IRQ_DEC; 281 + regs.trap = 0x900; 282 + timer_interrupt(&regs); 283 + if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) 284 + hard_irq_disable(); 285 + } 286 + 287 + if (happened & PACA_IRQ_EE) { 288 + local_paca->irq_happened &= ~PACA_IRQ_EE; 289 + regs.trap = 0x500; 290 + do_IRQ(&regs); 291 + if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) 292 + hard_irq_disable(); 293 + } 294 + 295 + /* 296 + * Check if an EPR external interrupt happened this bit is typically 297 + * set if we need to handle another "edge" interrupt from within the 298 + * MPIC "EPR" handler. 299 + */ 300 + if (IS_ENABLED(CONFIG_PPC_BOOK3E) && (happened & PACA_IRQ_EE_EDGE)) { 301 + local_paca->irq_happened &= ~PACA_IRQ_EE_EDGE; 302 + regs.trap = 0x500; 303 + do_IRQ(&regs); 304 + if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) 305 + hard_irq_disable(); 306 + } 307 + 308 + if (IS_ENABLED(CONFIG_PPC_DOORBELL) && (happened & PACA_IRQ_DBELL)) { 309 + local_paca->irq_happened &= ~PACA_IRQ_DBELL; 310 + if (IS_ENABLED(CONFIG_PPC_BOOK3E)) 311 + regs.trap = 0x280; 312 + else 313 + regs.trap = 0xa00; 314 + doorbell_exception(&regs); 315 + if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) 316 + hard_irq_disable(); 317 + } 318 + 319 + /* Book3E does not support soft-masking PMI interrupts */ 320 + if (IS_ENABLED(CONFIG_PPC_BOOK3S) && (happened & PACA_IRQ_PMI)) { 321 + local_paca->irq_happened &= ~PACA_IRQ_PMI; 322 + regs.trap = 0xf00; 323 + performance_monitor_exception(&regs); 324 + if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) 325 + hard_irq_disable(); 326 + } 327 + 328 + happened = local_paca->irq_happened; 329 + if (happened & ~PACA_IRQ_HARD_DIS) { 330 + /* 331 + * We are responding to the next interrupt, so interrupt-off 332 + * latencies should be reset here. 333 + */ 334 + trace_hardirqs_on(); 335 + trace_hardirqs_off(); 336 + goto again; 337 + } 338 + } 210 339 211 340 notrace void arch_local_irq_restore(unsigned long mask) 212 341 { 213 342 unsigned char irq_happened; 214 - unsigned int replay; 215 343 216 344 /* Write the new soft-enabled value */ 217 345 irq_soft_mask_set(mask); ··· 339 255 */ 340 256 irq_happened = get_irq_happened(); 341 257 if (!irq_happened) { 342 - #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG 343 - WARN_ON_ONCE(!(mfmsr() & MSR_EE)); 344 - #endif 258 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 259 + WARN_ON_ONCE(!(mfmsr() & MSR_EE)); 345 260 return; 346 261 } 347 262 348 - /* 349 - * We need to hard disable to get a trusted value from 350 - * __check_irq_replay(). We also need to soft-disable 351 - * again to avoid warnings in there due to the use of 352 - * per-cpu variables. 353 - */ 263 + /* We need to hard disable to replay. */ 354 264 if (!(irq_happened & PACA_IRQ_HARD_DIS)) { 355 - #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG 356 - WARN_ON_ONCE(!(mfmsr() & MSR_EE)); 357 - #endif 265 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 266 + WARN_ON_ONCE(!(mfmsr() & MSR_EE)); 358 267 __hard_irq_disable(); 359 - #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG 360 268 } else { 361 269 /* 362 270 * We should already be hard disabled here. We had bugs ··· 356 280 * warn if we are wrong. Only do that when IRQ tracing 357 281 * is enabled as mfmsr() can be costly. 358 282 */ 359 - if (WARN_ON_ONCE(mfmsr() & MSR_EE)) 360 - __hard_irq_disable(); 361 - #endif 283 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) { 284 + if (WARN_ON_ONCE(mfmsr() & MSR_EE)) 285 + __hard_irq_disable(); 286 + } 287 + 288 + if (irq_happened == PACA_IRQ_HARD_DIS) { 289 + local_paca->irq_happened = 0; 290 + __hard_irq_enable(); 291 + return; 292 + } 362 293 } 363 294 364 295 irq_soft_mask_set(IRQS_ALL_DISABLED); 365 296 trace_hardirqs_off(); 366 297 367 - /* 368 - * Check if anything needs to be re-emitted. We haven't 369 - * soft-enabled yet to avoid warnings in decrementer_check_overflow 370 - * accessing per-cpu variables 371 - */ 372 - replay = __check_irq_replay(); 298 + replay_soft_interrupts(); 299 + local_paca->irq_happened = 0; 373 300 374 - /* We can soft-enable now */ 375 301 trace_hardirqs_on(); 376 302 irq_soft_mask_set(IRQS_ENABLED); 377 - 378 - /* 379 - * And replay if we have to. This will return with interrupts 380 - * hard-enabled. 381 - */ 382 - if (replay) { 383 - __replay_interrupt(replay); 384 - return; 385 - } 386 - 387 - /* Finally, let's ensure we are hard enabled */ 388 303 __hard_irq_enable(); 389 304 } 390 305 EXPORT_SYMBOL(arch_local_irq_restore); ··· 666 599 667 600 static inline void check_stack_overflow(void) 668 601 { 669 - #ifdef CONFIG_DEBUG_STACKOVERFLOW 670 602 long sp; 671 603 672 - sp = current_stack_pointer() & (THREAD_SIZE-1); 604 + if (!IS_ENABLED(CONFIG_DEBUG_STACKOVERFLOW)) 605 + return; 606 + 607 + sp = current_stack_pointer & (THREAD_SIZE - 1); 673 608 674 609 /* check for stack overflow: is there less than 2KB free? */ 675 610 if (unlikely(sp < 2048)) { 676 611 pr_err("do_IRQ: stack overflow: %ld\n", sp); 677 612 dump_stack(); 678 613 } 679 - #endif 680 614 } 681 615 682 616 void __do_irq(struct pt_regs *regs) ··· 715 647 void *cursp, *irqsp, *sirqsp; 716 648 717 649 /* Switch to the irq stack to handle this */ 718 - cursp = (void *)(current_stack_pointer() & ~(THREAD_SIZE - 1)); 650 + cursp = (void *)(current_stack_pointer & ~(THREAD_SIZE - 1)); 719 651 irqsp = hardirq_ctx[raw_smp_processor_id()]; 720 652 sirqsp = softirq_ctx[raw_smp_processor_id()]; 721 653
+36 -48
arch/powerpc/kernel/kprobes.c
··· 264 264 if (user_mode(regs)) 265 265 return 0; 266 266 267 + if (!(regs->msr & MSR_IR) || !(regs->msr & MSR_DR)) 268 + return 0; 269 + 267 270 /* 268 271 * We don't want to be preempted for the entire 269 272 * duration of kprobe processing 270 273 */ 271 274 preempt_disable(); 272 275 kcb = get_kprobe_ctlblk(); 273 - 274 - /* Check we're not actually recursing */ 275 - if (kprobe_running()) { 276 - p = get_kprobe(addr); 277 - if (p) { 278 - kprobe_opcode_t insn = *p->ainsn.insn; 279 - if (kcb->kprobe_status == KPROBE_HIT_SS && 280 - is_trap(insn)) { 281 - /* Turn off 'trace' bits */ 282 - regs->msr &= ~MSR_SINGLESTEP; 283 - regs->msr |= kcb->kprobe_saved_msr; 284 - goto no_kprobe; 285 - } 286 - /* We have reentered the kprobe_handler(), since 287 - * another probe was hit while within the handler. 288 - * We here save the original kprobes variables and 289 - * just single step on the instruction of the new probe 290 - * without calling any user handlers. 291 - */ 292 - save_previous_kprobe(kcb); 293 - set_current_kprobe(p, regs, kcb); 294 - kprobes_inc_nmissed_count(p); 295 - kcb->kprobe_status = KPROBE_REENTER; 296 - if (p->ainsn.boostable >= 0) { 297 - ret = try_to_emulate(p, regs); 298 - 299 - if (ret > 0) { 300 - restore_previous_kprobe(kcb); 301 - preempt_enable_no_resched(); 302 - return 1; 303 - } 304 - } 305 - prepare_singlestep(p, regs); 306 - return 1; 307 - } else if (*addr != BREAKPOINT_INSTRUCTION) { 308 - /* If trap variant, then it belongs not to us */ 309 - kprobe_opcode_t cur_insn = *addr; 310 - 311 - if (is_trap(cur_insn)) 312 - goto no_kprobe; 313 - /* The breakpoint instruction was removed by 314 - * another cpu right after we hit, no further 315 - * handling of this interrupt is appropriate 316 - */ 317 - ret = 1; 318 - } 319 - goto no_kprobe; 320 - } 321 276 322 277 p = get_kprobe(addr); 323 278 if (!p) { ··· 296 341 } 297 342 /* Not one of ours: let kernel handle it */ 298 343 goto no_kprobe; 344 + } 345 + 346 + /* Check we're not actually recursing */ 347 + if (kprobe_running()) { 348 + kprobe_opcode_t insn = *p->ainsn.insn; 349 + if (kcb->kprobe_status == KPROBE_HIT_SS && is_trap(insn)) { 350 + /* Turn off 'trace' bits */ 351 + regs->msr &= ~MSR_SINGLESTEP; 352 + regs->msr |= kcb->kprobe_saved_msr; 353 + goto no_kprobe; 354 + } 355 + 356 + /* 357 + * We have reentered the kprobe_handler(), since another probe 358 + * was hit while within the handler. We here save the original 359 + * kprobes variables and just single step on the instruction of 360 + * the new probe without calling any user handlers. 361 + */ 362 + save_previous_kprobe(kcb); 363 + set_current_kprobe(p, regs, kcb); 364 + kprobes_inc_nmissed_count(p); 365 + kcb->kprobe_status = KPROBE_REENTER; 366 + if (p->ainsn.boostable >= 0) { 367 + ret = try_to_emulate(p, regs); 368 + 369 + if (ret > 0) { 370 + restore_previous_kprobe(kcb); 371 + preempt_enable_no_resched(); 372 + return 1; 373 + } 374 + } 375 + prepare_singlestep(p, regs); 376 + return 1; 299 377 } 300 378 301 379 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
+14
arch/powerpc/kernel/mce.c
··· 15 15 #include <linux/percpu.h> 16 16 #include <linux/export.h> 17 17 #include <linux/irq_work.h> 18 + #include <linux/extable.h> 18 19 19 20 #include <asm/machdep.h> 20 21 #include <asm/mce.h> ··· 252 251 /* Queue irq work to process this event later. */ 253 252 irq_work_queue(&mce_event_process_work); 254 253 } 254 + 255 + void mce_common_process_ue(struct pt_regs *regs, 256 + struct mce_error_info *mce_err) 257 + { 258 + const struct exception_table_entry *entry; 259 + 260 + entry = search_kernel_exception_table(regs->nip); 261 + if (entry) { 262 + mce_err->ignore_event = true; 263 + regs->nip = extable_fixup(entry); 264 + } 265 + } 266 + 255 267 /* 256 268 * process pending MCE event from the mce event queue. This function will be 257 269 * called during syscall exit.
+2 -6
arch/powerpc/kernel/mce_power.c
··· 579 579 struct mce_error_info *mce_err) 580 580 { 581 581 long handled = 0; 582 - const struct exception_table_entry *entry; 583 582 584 - entry = search_kernel_exception_table(regs->nip); 585 - if (entry) { 586 - mce_err->ignore_event = true; 587 - regs->nip = extable_fixup(entry); 583 + mce_common_process_ue(regs, mce_err); 584 + if (mce_err->ignore_event) 588 585 return 1; 589 - } 590 586 591 587 /* 592 588 * On specific SCOM read via MMIO we may get a machine check
+2 -2
arch/powerpc/kernel/misc.S
··· 110 110 li r3, 1 111 111 blr 112 112 113 - _GLOBAL(current_stack_pointer) 113 + _GLOBAL(current_stack_frame) 114 114 PPC_LL r3,0(r1) 115 115 blr 116 - EXPORT_SYMBOL(current_stack_pointer) 116 + EXPORT_SYMBOL(current_stack_frame)
+1 -11
arch/powerpc/kernel/of_platform.c
··· 62 62 /* Init pci_dn data structures */ 63 63 pci_devs_phb_init_dynamic(phb); 64 64 65 - /* Create EEH devices for the PHB */ 65 + /* Create EEH PEs for the PHB */ 66 66 eeh_dev_phb_init_dynamic(phb); 67 - 68 - /* Register devices with EEH */ 69 - if (dev->dev.of_node->child) 70 - eeh_add_device_tree_early(PCI_DN(dev->dev.of_node)); 71 67 72 68 /* Scan the bus */ 73 69 pcibios_scan_phb(phb); ··· 76 80 */ 77 81 pcibios_claim_one_bus(phb->bus); 78 82 79 - /* Finish EEH setup */ 80 - eeh_add_device_tree_late(phb->bus); 81 - 82 83 /* Add probed PCI devices to the device model */ 83 84 pci_bus_add_devices(phb->bus); 84 - 85 - /* sysfs files should only be added after devices are added */ 86 - eeh_add_sysfs_files(phb->bus); 87 85 88 86 return 0; 89 87 }
+9 -5
arch/powerpc/kernel/paca.c
··· 176 176 struct paca_struct **paca_ptrs __read_mostly; 177 177 EXPORT_SYMBOL(paca_ptrs); 178 178 179 - void __init initialise_paca(struct paca_struct *new_paca, int cpu) 179 + void __init __nostackprotector initialise_paca(struct paca_struct *new_paca, int cpu) 180 180 { 181 181 #ifdef CONFIG_PPC_PSERIES 182 182 new_paca->lppaca_ptr = NULL; ··· 205 205 } 206 206 207 207 /* Put the paca pointer into r13 and SPRG_PACA */ 208 - void setup_paca(struct paca_struct *new_paca) 208 + void __nostackprotector setup_paca(struct paca_struct *new_paca) 209 209 { 210 210 /* Setup r13 */ 211 211 local_paca = new_paca; ··· 214 214 /* On Book3E, initialize the TLB miss exception frames */ 215 215 mtspr(SPRN_SPRG_TLB_EXFRAME, local_paca->extlb); 216 216 #else 217 - /* In HV mode, we setup both HPACA and PACA to avoid problems 217 + /* 218 + * In HV mode, we setup both HPACA and PACA to avoid problems 218 219 * if we do a GET_PACA() before the feature fixups have been 219 - * applied 220 + * applied. 221 + * 222 + * Normally you should test against CPU_FTR_HVMODE, but CPU features 223 + * are not yet set up when we first reach here. 220 224 */ 221 - if (early_cpu_has_feature(CPU_FTR_HVMODE)) 225 + if (mfmsr() & MSR_HV) 222 226 mtspr(SPRN_SPRG_HPACA, local_paca); 223 227 #endif 224 228 mtspr(SPRN_SPRG_PACA, local_paca);
-6
arch/powerpc/kernel/pci-common.c
··· 1399 1399 pci_assign_unassigned_bus_resources(bus); 1400 1400 } 1401 1401 1402 - /* Fixup EEH */ 1403 - eeh_add_device_tree_late(bus); 1404 - 1405 1402 /* Add new devices to global lists. Register in proc, sysfs. */ 1406 1403 pci_bus_add_devices(bus); 1407 - 1408 - /* sysfs files should only be added after devices are added */ 1409 - eeh_add_sysfs_files(bus); 1410 1404 } 1411 1405 EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus); 1412 1406
-2
arch/powerpc/kernel/pci-hotplug.c
··· 112 112 struct pci_controller *phb; 113 113 struct device_node *dn = pci_bus_to_OF_node(bus); 114 114 115 - eeh_add_device_tree_early(PCI_DN(dn)); 116 - 117 115 phb = pci_bus_to_host(bus); 118 116 119 117 mode = PCI_PROBE_NORMAL;
+79 -45
arch/powerpc/kernel/process.c
··· 236 236 } 237 237 } 238 238 EXPORT_SYMBOL(enable_kernel_fp); 239 - 240 - static int restore_fp(struct task_struct *tsk) 241 - { 242 - if (tsk->thread.load_fp) { 243 - load_fp_state(&current->thread.fp_state); 244 - current->thread.load_fp++; 245 - return 1; 246 - } 247 - return 0; 248 - } 249 - #else 250 - static int restore_fp(struct task_struct *tsk) { return 0; } 251 239 #endif /* CONFIG_PPC_FPU */ 252 240 253 241 #ifdef CONFIG_ALTIVEC 254 - #define loadvec(thr) ((thr).load_vec) 255 - 256 242 static void __giveup_altivec(struct task_struct *tsk) 257 243 { 258 244 unsigned long msr; ··· 304 318 } 305 319 } 306 320 EXPORT_SYMBOL_GPL(flush_altivec_to_thread); 307 - 308 - static int restore_altivec(struct task_struct *tsk) 309 - { 310 - if (cpu_has_feature(CPU_FTR_ALTIVEC) && (tsk->thread.load_vec)) { 311 - load_vr_state(&tsk->thread.vr_state); 312 - tsk->thread.used_vr = 1; 313 - tsk->thread.load_vec++; 314 - 315 - return 1; 316 - } 317 - return 0; 318 - } 319 - #else 320 - #define loadvec(thr) 0 321 - static inline int restore_altivec(struct task_struct *tsk) { return 0; } 322 321 #endif /* CONFIG_ALTIVEC */ 323 322 324 323 #ifdef CONFIG_VSX ··· 371 400 } 372 401 } 373 402 EXPORT_SYMBOL_GPL(flush_vsx_to_thread); 374 - 375 - static int restore_vsx(struct task_struct *tsk) 376 - { 377 - if (cpu_has_feature(CPU_FTR_VSX)) { 378 - tsk->thread.used_vsr = 1; 379 - return 1; 380 - } 381 - 382 - return 0; 383 - } 384 - #else 385 - static inline int restore_vsx(struct task_struct *tsk) { return 0; } 386 403 #endif /* CONFIG_VSX */ 387 404 388 405 #ifdef CONFIG_SPE ··· 470 511 } 471 512 EXPORT_SYMBOL(giveup_all); 472 513 514 + #ifdef CONFIG_PPC_BOOK3S_64 515 + #ifdef CONFIG_PPC_FPU 516 + static int restore_fp(struct task_struct *tsk) 517 + { 518 + if (tsk->thread.load_fp) { 519 + load_fp_state(&current->thread.fp_state); 520 + current->thread.load_fp++; 521 + return 1; 522 + } 523 + return 0; 524 + } 525 + #else 526 + static int restore_fp(struct task_struct *tsk) { return 0; } 527 + #endif /* CONFIG_PPC_FPU */ 528 + 529 + #ifdef CONFIG_ALTIVEC 530 + #define loadvec(thr) ((thr).load_vec) 531 + static int restore_altivec(struct task_struct *tsk) 532 + { 533 + if (cpu_has_feature(CPU_FTR_ALTIVEC) && (tsk->thread.load_vec)) { 534 + load_vr_state(&tsk->thread.vr_state); 535 + tsk->thread.used_vr = 1; 536 + tsk->thread.load_vec++; 537 + 538 + return 1; 539 + } 540 + return 0; 541 + } 542 + #else 543 + #define loadvec(thr) 0 544 + static inline int restore_altivec(struct task_struct *tsk) { return 0; } 545 + #endif /* CONFIG_ALTIVEC */ 546 + 547 + #ifdef CONFIG_VSX 548 + static int restore_vsx(struct task_struct *tsk) 549 + { 550 + if (cpu_has_feature(CPU_FTR_VSX)) { 551 + tsk->thread.used_vsr = 1; 552 + return 1; 553 + } 554 + 555 + return 0; 556 + } 557 + #else 558 + static inline int restore_vsx(struct task_struct *tsk) { return 0; } 559 + #endif /* CONFIG_VSX */ 560 + 473 561 /* 474 562 * The exception exit path calls restore_math() with interrupts hard disabled 475 563 * but the soft irq state not "reconciled". ftrace code that calls ··· 557 551 558 552 regs->msr = msr; 559 553 } 554 + #endif 560 555 561 556 static void save_all(struct task_struct *tsk) 562 557 { ··· 1641 1634 p->thread.regs = childregs; 1642 1635 childregs->gpr[3] = 0; /* Result from fork() */ 1643 1636 if (clone_flags & CLONE_SETTLS) { 1644 - #ifdef CONFIG_PPC64 1645 1637 if (!is_32bit_task()) 1646 1638 childregs->gpr[13] = tls; 1647 1639 else 1648 - #endif 1649 1640 childregs->gpr[2] = tls; 1650 1641 } 1651 1642 ··· 1981 1976 return 0; 1982 1977 } 1983 1978 1979 + static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p, 1980 + unsigned long nbytes) 1981 + { 1982 + #ifdef CONFIG_PPC64 1983 + unsigned long stack_page; 1984 + unsigned long cpu = task_cpu(p); 1985 + 1986 + stack_page = (unsigned long)paca_ptrs[cpu]->emergency_sp - THREAD_SIZE; 1987 + if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes) 1988 + return 1; 1989 + 1990 + # ifdef CONFIG_PPC_BOOK3S_64 1991 + stack_page = (unsigned long)paca_ptrs[cpu]->nmi_emergency_sp - THREAD_SIZE; 1992 + if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes) 1993 + return 1; 1994 + 1995 + stack_page = (unsigned long)paca_ptrs[cpu]->mc_emergency_sp - THREAD_SIZE; 1996 + if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes) 1997 + return 1; 1998 + # endif 1999 + #endif 2000 + 2001 + return 0; 2002 + } 2003 + 2004 + 1984 2005 int validate_sp(unsigned long sp, struct task_struct *p, 1985 2006 unsigned long nbytes) 1986 2007 { ··· 2018 1987 if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes) 2019 1988 return 1; 2020 1989 2021 - return valid_irq_stack(sp, p, nbytes); 1990 + if (valid_irq_stack(sp, p, nbytes)) 1991 + return 1; 1992 + 1993 + return valid_emergency_stack(sp, p, nbytes); 2022 1994 } 2023 1995 2024 1996 EXPORT_SYMBOL(validate_sp); ··· 2087 2053 sp = (unsigned long) stack; 2088 2054 if (sp == 0) { 2089 2055 if (tsk == current) 2090 - sp = current_stack_pointer(); 2056 + sp = current_stack_frame(); 2091 2057 else 2092 2058 sp = tsk->thread.ksp; 2093 2059 }
+3 -1
arch/powerpc/kernel/prom_init.c
··· 1773 1773 if (token == 0) 1774 1774 prom_panic("Could not get token for ibm,os-term\n"); 1775 1775 os_term_args.token = cpu_to_be32(token); 1776 + os_term_args.nargs = cpu_to_be32(1); 1777 + os_term_args.nret = cpu_to_be32(1); 1778 + os_term_args.args[0] = cpu_to_be32(__pa(str)); 1776 1779 prom_rtas_hcall((uint64_t)&os_term_args); 1777 1780 } 1778 1781 #endif /* CONFIG_PPC_SVM */ ··· 3477 3474 */ 3478 3475 hdr = dt_header_start; 3479 3476 3480 - /* Don't print anything after quiesce under OPAL, it crashes OFW */ 3481 3477 prom_printf("Booting Linux via __start() @ 0x%lx ...\n", kbase); 3482 3478 prom_debug("->dt_header_start=0x%lx\n", hdr); 3483 3479
-3468
arch/powerpc/kernel/ptrace.c
··· 1 - /* 2 - * PowerPC version 3 - * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 4 - * 5 - * Derived from "arch/m68k/kernel/ptrace.c" 6 - * Copyright (C) 1994 by Hamish Macdonald 7 - * Taken from linux/kernel/ptrace.c and modified for M680x0. 8 - * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds 9 - * 10 - * Modified by Cort Dougan (cort@hq.fsmlabs.com) 11 - * and Paul Mackerras (paulus@samba.org). 12 - * 13 - * This file is subject to the terms and conditions of the GNU General 14 - * Public License. See the file README.legal in the main directory of 15 - * this archive for more details. 16 - */ 17 - 18 - #include <linux/kernel.h> 19 - #include <linux/sched.h> 20 - #include <linux/mm.h> 21 - #include <linux/smp.h> 22 - #include <linux/errno.h> 23 - #include <linux/ptrace.h> 24 - #include <linux/regset.h> 25 - #include <linux/tracehook.h> 26 - #include <linux/elf.h> 27 - #include <linux/user.h> 28 - #include <linux/security.h> 29 - #include <linux/signal.h> 30 - #include <linux/seccomp.h> 31 - #include <linux/audit.h> 32 - #include <trace/syscall.h> 33 - #include <linux/hw_breakpoint.h> 34 - #include <linux/perf_event.h> 35 - #include <linux/context_tracking.h> 36 - #include <linux/nospec.h> 37 - 38 - #include <linux/uaccess.h> 39 - #include <linux/pkeys.h> 40 - #include <asm/page.h> 41 - #include <asm/pgtable.h> 42 - #include <asm/switch_to.h> 43 - #include <asm/tm.h> 44 - #include <asm/asm-prototypes.h> 45 - #include <asm/debug.h> 46 - #include <asm/hw_breakpoint.h> 47 - 48 - #define CREATE_TRACE_POINTS 49 - #include <trace/events/syscalls.h> 50 - 51 - /* 52 - * The parameter save area on the stack is used to store arguments being passed 53 - * to callee function and is located at fixed offset from stack pointer. 54 - */ 55 - #ifdef CONFIG_PPC32 56 - #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */ 57 - #else /* CONFIG_PPC32 */ 58 - #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */ 59 - #endif 60 - 61 - struct pt_regs_offset { 62 - const char *name; 63 - int offset; 64 - }; 65 - 66 - #define STR(s) #s /* convert to string */ 67 - #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)} 68 - #define GPR_OFFSET_NAME(num) \ 69 - {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \ 70 - {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])} 71 - #define REG_OFFSET_END {.name = NULL, .offset = 0} 72 - 73 - #define TVSO(f) (offsetof(struct thread_vr_state, f)) 74 - #define TFSO(f) (offsetof(struct thread_fp_state, f)) 75 - #define TSO(f) (offsetof(struct thread_struct, f)) 76 - 77 - static const struct pt_regs_offset regoffset_table[] = { 78 - GPR_OFFSET_NAME(0), 79 - GPR_OFFSET_NAME(1), 80 - GPR_OFFSET_NAME(2), 81 - GPR_OFFSET_NAME(3), 82 - GPR_OFFSET_NAME(4), 83 - GPR_OFFSET_NAME(5), 84 - GPR_OFFSET_NAME(6), 85 - GPR_OFFSET_NAME(7), 86 - GPR_OFFSET_NAME(8), 87 - GPR_OFFSET_NAME(9), 88 - GPR_OFFSET_NAME(10), 89 - GPR_OFFSET_NAME(11), 90 - GPR_OFFSET_NAME(12), 91 - GPR_OFFSET_NAME(13), 92 - GPR_OFFSET_NAME(14), 93 - GPR_OFFSET_NAME(15), 94 - GPR_OFFSET_NAME(16), 95 - GPR_OFFSET_NAME(17), 96 - GPR_OFFSET_NAME(18), 97 - GPR_OFFSET_NAME(19), 98 - GPR_OFFSET_NAME(20), 99 - GPR_OFFSET_NAME(21), 100 - GPR_OFFSET_NAME(22), 101 - GPR_OFFSET_NAME(23), 102 - GPR_OFFSET_NAME(24), 103 - GPR_OFFSET_NAME(25), 104 - GPR_OFFSET_NAME(26), 105 - GPR_OFFSET_NAME(27), 106 - GPR_OFFSET_NAME(28), 107 - GPR_OFFSET_NAME(29), 108 - GPR_OFFSET_NAME(30), 109 - GPR_OFFSET_NAME(31), 110 - REG_OFFSET_NAME(nip), 111 - REG_OFFSET_NAME(msr), 112 - REG_OFFSET_NAME(ctr), 113 - REG_OFFSET_NAME(link), 114 - REG_OFFSET_NAME(xer), 115 - REG_OFFSET_NAME(ccr), 116 - #ifdef CONFIG_PPC64 117 - REG_OFFSET_NAME(softe), 118 - #else 119 - REG_OFFSET_NAME(mq), 120 - #endif 121 - REG_OFFSET_NAME(trap), 122 - REG_OFFSET_NAME(dar), 123 - REG_OFFSET_NAME(dsisr), 124 - REG_OFFSET_END, 125 - }; 126 - 127 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 128 - static void flush_tmregs_to_thread(struct task_struct *tsk) 129 - { 130 - /* 131 - * If task is not current, it will have been flushed already to 132 - * it's thread_struct during __switch_to(). 133 - * 134 - * A reclaim flushes ALL the state or if not in TM save TM SPRs 135 - * in the appropriate thread structures from live. 136 - */ 137 - 138 - if ((!cpu_has_feature(CPU_FTR_TM)) || (tsk != current)) 139 - return; 140 - 141 - if (MSR_TM_SUSPENDED(mfmsr())) { 142 - tm_reclaim_current(TM_CAUSE_SIGNAL); 143 - } else { 144 - tm_enable(); 145 - tm_save_sprs(&(tsk->thread)); 146 - } 147 - } 148 - #else 149 - static inline void flush_tmregs_to_thread(struct task_struct *tsk) { } 150 - #endif 151 - 152 - /** 153 - * regs_query_register_offset() - query register offset from its name 154 - * @name: the name of a register 155 - * 156 - * regs_query_register_offset() returns the offset of a register in struct 157 - * pt_regs from its name. If the name is invalid, this returns -EINVAL; 158 - */ 159 - int regs_query_register_offset(const char *name) 160 - { 161 - const struct pt_regs_offset *roff; 162 - for (roff = regoffset_table; roff->name != NULL; roff++) 163 - if (!strcmp(roff->name, name)) 164 - return roff->offset; 165 - return -EINVAL; 166 - } 167 - 168 - /** 169 - * regs_query_register_name() - query register name from its offset 170 - * @offset: the offset of a register in struct pt_regs. 171 - * 172 - * regs_query_register_name() returns the name of a register from its 173 - * offset in struct pt_regs. If the @offset is invalid, this returns NULL; 174 - */ 175 - const char *regs_query_register_name(unsigned int offset) 176 - { 177 - const struct pt_regs_offset *roff; 178 - for (roff = regoffset_table; roff->name != NULL; roff++) 179 - if (roff->offset == offset) 180 - return roff->name; 181 - return NULL; 182 - } 183 - 184 - /* 185 - * does not yet catch signals sent when the child dies. 186 - * in exit.c or in signal.c. 187 - */ 188 - 189 - /* 190 - * Set of msr bits that gdb can change on behalf of a process. 191 - */ 192 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 193 - #define MSR_DEBUGCHANGE 0 194 - #else 195 - #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE) 196 - #endif 197 - 198 - /* 199 - * Max register writeable via put_reg 200 - */ 201 - #ifdef CONFIG_PPC32 202 - #define PT_MAX_PUT_REG PT_MQ 203 - #else 204 - #define PT_MAX_PUT_REG PT_CCR 205 - #endif 206 - 207 - static unsigned long get_user_msr(struct task_struct *task) 208 - { 209 - return task->thread.regs->msr | task->thread.fpexc_mode; 210 - } 211 - 212 - static int set_user_msr(struct task_struct *task, unsigned long msr) 213 - { 214 - task->thread.regs->msr &= ~MSR_DEBUGCHANGE; 215 - task->thread.regs->msr |= msr & MSR_DEBUGCHANGE; 216 - return 0; 217 - } 218 - 219 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 220 - static unsigned long get_user_ckpt_msr(struct task_struct *task) 221 - { 222 - return task->thread.ckpt_regs.msr | task->thread.fpexc_mode; 223 - } 224 - 225 - static int set_user_ckpt_msr(struct task_struct *task, unsigned long msr) 226 - { 227 - task->thread.ckpt_regs.msr &= ~MSR_DEBUGCHANGE; 228 - task->thread.ckpt_regs.msr |= msr & MSR_DEBUGCHANGE; 229 - return 0; 230 - } 231 - 232 - static int set_user_ckpt_trap(struct task_struct *task, unsigned long trap) 233 - { 234 - task->thread.ckpt_regs.trap = trap & 0xfff0; 235 - return 0; 236 - } 237 - #endif 238 - 239 - #ifdef CONFIG_PPC64 240 - static int get_user_dscr(struct task_struct *task, unsigned long *data) 241 - { 242 - *data = task->thread.dscr; 243 - return 0; 244 - } 245 - 246 - static int set_user_dscr(struct task_struct *task, unsigned long dscr) 247 - { 248 - task->thread.dscr = dscr; 249 - task->thread.dscr_inherit = 1; 250 - return 0; 251 - } 252 - #else 253 - static int get_user_dscr(struct task_struct *task, unsigned long *data) 254 - { 255 - return -EIO; 256 - } 257 - 258 - static int set_user_dscr(struct task_struct *task, unsigned long dscr) 259 - { 260 - return -EIO; 261 - } 262 - #endif 263 - 264 - /* 265 - * We prevent mucking around with the reserved area of trap 266 - * which are used internally by the kernel. 267 - */ 268 - static int set_user_trap(struct task_struct *task, unsigned long trap) 269 - { 270 - task->thread.regs->trap = trap & 0xfff0; 271 - return 0; 272 - } 273 - 274 - /* 275 - * Get contents of register REGNO in task TASK. 276 - */ 277 - int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data) 278 - { 279 - unsigned int regs_max; 280 - 281 - if ((task->thread.regs == NULL) || !data) 282 - return -EIO; 283 - 284 - if (regno == PT_MSR) { 285 - *data = get_user_msr(task); 286 - return 0; 287 - } 288 - 289 - if (regno == PT_DSCR) 290 - return get_user_dscr(task, data); 291 - 292 - #ifdef CONFIG_PPC64 293 - /* 294 - * softe copies paca->irq_soft_mask variable state. Since irq_soft_mask is 295 - * no more used as a flag, lets force usr to alway see the softe value as 1 296 - * which means interrupts are not soft disabled. 297 - */ 298 - if (regno == PT_SOFTE) { 299 - *data = 1; 300 - return 0; 301 - } 302 - #endif 303 - 304 - regs_max = sizeof(struct user_pt_regs) / sizeof(unsigned long); 305 - if (regno < regs_max) { 306 - regno = array_index_nospec(regno, regs_max); 307 - *data = ((unsigned long *)task->thread.regs)[regno]; 308 - return 0; 309 - } 310 - 311 - return -EIO; 312 - } 313 - 314 - /* 315 - * Write contents of register REGNO in task TASK. 316 - */ 317 - int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data) 318 - { 319 - if (task->thread.regs == NULL) 320 - return -EIO; 321 - 322 - if (regno == PT_MSR) 323 - return set_user_msr(task, data); 324 - if (regno == PT_TRAP) 325 - return set_user_trap(task, data); 326 - if (regno == PT_DSCR) 327 - return set_user_dscr(task, data); 328 - 329 - if (regno <= PT_MAX_PUT_REG) { 330 - regno = array_index_nospec(regno, PT_MAX_PUT_REG + 1); 331 - ((unsigned long *)task->thread.regs)[regno] = data; 332 - return 0; 333 - } 334 - return -EIO; 335 - } 336 - 337 - static int gpr_get(struct task_struct *target, const struct user_regset *regset, 338 - unsigned int pos, unsigned int count, 339 - void *kbuf, void __user *ubuf) 340 - { 341 - int i, ret; 342 - 343 - if (target->thread.regs == NULL) 344 - return -EIO; 345 - 346 - if (!FULL_REGS(target->thread.regs)) { 347 - /* We have a partial register set. Fill 14-31 with bogus values */ 348 - for (i = 14; i < 32; i++) 349 - target->thread.regs->gpr[i] = NV_REG_POISON; 350 - } 351 - 352 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 353 - target->thread.regs, 354 - 0, offsetof(struct pt_regs, msr)); 355 - if (!ret) { 356 - unsigned long msr = get_user_msr(target); 357 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr, 358 - offsetof(struct pt_regs, msr), 359 - offsetof(struct pt_regs, msr) + 360 - sizeof(msr)); 361 - } 362 - 363 - BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 364 - offsetof(struct pt_regs, msr) + sizeof(long)); 365 - 366 - if (!ret) 367 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 368 - &target->thread.regs->orig_gpr3, 369 - offsetof(struct pt_regs, orig_gpr3), 370 - sizeof(struct user_pt_regs)); 371 - if (!ret) 372 - ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, 373 - sizeof(struct user_pt_regs), -1); 374 - 375 - return ret; 376 - } 377 - 378 - static int gpr_set(struct task_struct *target, const struct user_regset *regset, 379 - unsigned int pos, unsigned int count, 380 - const void *kbuf, const void __user *ubuf) 381 - { 382 - unsigned long reg; 383 - int ret; 384 - 385 - if (target->thread.regs == NULL) 386 - return -EIO; 387 - 388 - CHECK_FULL_REGS(target->thread.regs); 389 - 390 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 391 - target->thread.regs, 392 - 0, PT_MSR * sizeof(reg)); 393 - 394 - if (!ret && count > 0) { 395 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg, 396 - PT_MSR * sizeof(reg), 397 - (PT_MSR + 1) * sizeof(reg)); 398 - if (!ret) 399 - ret = set_user_msr(target, reg); 400 - } 401 - 402 - BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 403 - offsetof(struct pt_regs, msr) + sizeof(long)); 404 - 405 - if (!ret) 406 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 407 - &target->thread.regs->orig_gpr3, 408 - PT_ORIG_R3 * sizeof(reg), 409 - (PT_MAX_PUT_REG + 1) * sizeof(reg)); 410 - 411 - if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret) 412 - ret = user_regset_copyin_ignore( 413 - &pos, &count, &kbuf, &ubuf, 414 - (PT_MAX_PUT_REG + 1) * sizeof(reg), 415 - PT_TRAP * sizeof(reg)); 416 - 417 - if (!ret && count > 0) { 418 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg, 419 - PT_TRAP * sizeof(reg), 420 - (PT_TRAP + 1) * sizeof(reg)); 421 - if (!ret) 422 - ret = set_user_trap(target, reg); 423 - } 424 - 425 - if (!ret) 426 - ret = user_regset_copyin_ignore( 427 - &pos, &count, &kbuf, &ubuf, 428 - (PT_TRAP + 1) * sizeof(reg), -1); 429 - 430 - return ret; 431 - } 432 - 433 - /* 434 - * Regardless of transactions, 'fp_state' holds the current running 435 - * value of all FPR registers and 'ckfp_state' holds the last checkpointed 436 - * value of all FPR registers for the current transaction. 437 - * 438 - * Userspace interface buffer layout: 439 - * 440 - * struct data { 441 - * u64 fpr[32]; 442 - * u64 fpscr; 443 - * }; 444 - */ 445 - static int fpr_get(struct task_struct *target, const struct user_regset *regset, 446 - unsigned int pos, unsigned int count, 447 - void *kbuf, void __user *ubuf) 448 - { 449 - #ifdef CONFIG_VSX 450 - u64 buf[33]; 451 - int i; 452 - 453 - flush_fp_to_thread(target); 454 - 455 - /* copy to local buffer then write that out */ 456 - for (i = 0; i < 32 ; i++) 457 - buf[i] = target->thread.TS_FPR(i); 458 - buf[32] = target->thread.fp_state.fpscr; 459 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); 460 - #else 461 - BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) != 462 - offsetof(struct thread_fp_state, fpr[32])); 463 - 464 - flush_fp_to_thread(target); 465 - 466 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 467 - &target->thread.fp_state, 0, -1); 468 - #endif 469 - } 470 - 471 - /* 472 - * Regardless of transactions, 'fp_state' holds the current running 473 - * value of all FPR registers and 'ckfp_state' holds the last checkpointed 474 - * value of all FPR registers for the current transaction. 475 - * 476 - * Userspace interface buffer layout: 477 - * 478 - * struct data { 479 - * u64 fpr[32]; 480 - * u64 fpscr; 481 - * }; 482 - * 483 - */ 484 - static int fpr_set(struct task_struct *target, const struct user_regset *regset, 485 - unsigned int pos, unsigned int count, 486 - const void *kbuf, const void __user *ubuf) 487 - { 488 - #ifdef CONFIG_VSX 489 - u64 buf[33]; 490 - int i; 491 - 492 - flush_fp_to_thread(target); 493 - 494 - for (i = 0; i < 32 ; i++) 495 - buf[i] = target->thread.TS_FPR(i); 496 - buf[32] = target->thread.fp_state.fpscr; 497 - 498 - /* copy to local buffer then write that out */ 499 - i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); 500 - if (i) 501 - return i; 502 - 503 - for (i = 0; i < 32 ; i++) 504 - target->thread.TS_FPR(i) = buf[i]; 505 - target->thread.fp_state.fpscr = buf[32]; 506 - return 0; 507 - #else 508 - BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) != 509 - offsetof(struct thread_fp_state, fpr[32])); 510 - 511 - flush_fp_to_thread(target); 512 - 513 - return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 514 - &target->thread.fp_state, 0, -1); 515 - #endif 516 - } 517 - 518 - #ifdef CONFIG_ALTIVEC 519 - /* 520 - * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go. 521 - * The transfer totals 34 quadword. Quadwords 0-31 contain the 522 - * corresponding vector registers. Quadword 32 contains the vscr as the 523 - * last word (offset 12) within that quadword. Quadword 33 contains the 524 - * vrsave as the first word (offset 0) within the quadword. 525 - * 526 - * This definition of the VMX state is compatible with the current PPC32 527 - * ptrace interface. This allows signal handling and ptrace to use the 528 - * same structures. This also simplifies the implementation of a bi-arch 529 - * (combined (32- and 64-bit) gdb. 530 - */ 531 - 532 - static int vr_active(struct task_struct *target, 533 - const struct user_regset *regset) 534 - { 535 - flush_altivec_to_thread(target); 536 - return target->thread.used_vr ? regset->n : 0; 537 - } 538 - 539 - /* 540 - * Regardless of transactions, 'vr_state' holds the current running 541 - * value of all the VMX registers and 'ckvr_state' holds the last 542 - * checkpointed value of all the VMX registers for the current 543 - * transaction to fall back on in case it aborts. 544 - * 545 - * Userspace interface buffer layout: 546 - * 547 - * struct data { 548 - * vector128 vr[32]; 549 - * vector128 vscr; 550 - * vector128 vrsave; 551 - * }; 552 - */ 553 - static int vr_get(struct task_struct *target, const struct user_regset *regset, 554 - unsigned int pos, unsigned int count, 555 - void *kbuf, void __user *ubuf) 556 - { 557 - int ret; 558 - 559 - flush_altivec_to_thread(target); 560 - 561 - BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) != 562 - offsetof(struct thread_vr_state, vr[32])); 563 - 564 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 565 - &target->thread.vr_state, 0, 566 - 33 * sizeof(vector128)); 567 - if (!ret) { 568 - /* 569 - * Copy out only the low-order word of vrsave. 570 - */ 571 - int start, end; 572 - union { 573 - elf_vrreg_t reg; 574 - u32 word; 575 - } vrsave; 576 - memset(&vrsave, 0, sizeof(vrsave)); 577 - 578 - vrsave.word = target->thread.vrsave; 579 - 580 - start = 33 * sizeof(vector128); 581 - end = start + sizeof(vrsave); 582 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, 583 - start, end); 584 - } 585 - 586 - return ret; 587 - } 588 - 589 - /* 590 - * Regardless of transactions, 'vr_state' holds the current running 591 - * value of all the VMX registers and 'ckvr_state' holds the last 592 - * checkpointed value of all the VMX registers for the current 593 - * transaction to fall back on in case it aborts. 594 - * 595 - * Userspace interface buffer layout: 596 - * 597 - * struct data { 598 - * vector128 vr[32]; 599 - * vector128 vscr; 600 - * vector128 vrsave; 601 - * }; 602 - */ 603 - static int vr_set(struct task_struct *target, const struct user_regset *regset, 604 - unsigned int pos, unsigned int count, 605 - const void *kbuf, const void __user *ubuf) 606 - { 607 - int ret; 608 - 609 - flush_altivec_to_thread(target); 610 - 611 - BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) != 612 - offsetof(struct thread_vr_state, vr[32])); 613 - 614 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 615 - &target->thread.vr_state, 0, 616 - 33 * sizeof(vector128)); 617 - if (!ret && count > 0) { 618 - /* 619 - * We use only the first word of vrsave. 620 - */ 621 - int start, end; 622 - union { 623 - elf_vrreg_t reg; 624 - u32 word; 625 - } vrsave; 626 - memset(&vrsave, 0, sizeof(vrsave)); 627 - 628 - vrsave.word = target->thread.vrsave; 629 - 630 - start = 33 * sizeof(vector128); 631 - end = start + sizeof(vrsave); 632 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, 633 - start, end); 634 - if (!ret) 635 - target->thread.vrsave = vrsave.word; 636 - } 637 - 638 - return ret; 639 - } 640 - #endif /* CONFIG_ALTIVEC */ 641 - 642 - #ifdef CONFIG_VSX 643 - /* 644 - * Currently to set and and get all the vsx state, you need to call 645 - * the fp and VMX calls as well. This only get/sets the lower 32 646 - * 128bit VSX registers. 647 - */ 648 - 649 - static int vsr_active(struct task_struct *target, 650 - const struct user_regset *regset) 651 - { 652 - flush_vsx_to_thread(target); 653 - return target->thread.used_vsr ? regset->n : 0; 654 - } 655 - 656 - /* 657 - * Regardless of transactions, 'fp_state' holds the current running 658 - * value of all FPR registers and 'ckfp_state' holds the last 659 - * checkpointed value of all FPR registers for the current 660 - * transaction. 661 - * 662 - * Userspace interface buffer layout: 663 - * 664 - * struct data { 665 - * u64 vsx[32]; 666 - * }; 667 - */ 668 - static int vsr_get(struct task_struct *target, const struct user_regset *regset, 669 - unsigned int pos, unsigned int count, 670 - void *kbuf, void __user *ubuf) 671 - { 672 - u64 buf[32]; 673 - int ret, i; 674 - 675 - flush_tmregs_to_thread(target); 676 - flush_fp_to_thread(target); 677 - flush_altivec_to_thread(target); 678 - flush_vsx_to_thread(target); 679 - 680 - for (i = 0; i < 32 ; i++) 681 - buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET]; 682 - 683 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 684 - buf, 0, 32 * sizeof(double)); 685 - 686 - return ret; 687 - } 688 - 689 - /* 690 - * Regardless of transactions, 'fp_state' holds the current running 691 - * value of all FPR registers and 'ckfp_state' holds the last 692 - * checkpointed value of all FPR registers for the current 693 - * transaction. 694 - * 695 - * Userspace interface buffer layout: 696 - * 697 - * struct data { 698 - * u64 vsx[32]; 699 - * }; 700 - */ 701 - static int vsr_set(struct task_struct *target, const struct user_regset *regset, 702 - unsigned int pos, unsigned int count, 703 - const void *kbuf, const void __user *ubuf) 704 - { 705 - u64 buf[32]; 706 - int ret,i; 707 - 708 - flush_tmregs_to_thread(target); 709 - flush_fp_to_thread(target); 710 - flush_altivec_to_thread(target); 711 - flush_vsx_to_thread(target); 712 - 713 - for (i = 0; i < 32 ; i++) 714 - buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET]; 715 - 716 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 717 - buf, 0, 32 * sizeof(double)); 718 - if (!ret) 719 - for (i = 0; i < 32 ; i++) 720 - target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i]; 721 - 722 - return ret; 723 - } 724 - #endif /* CONFIG_VSX */ 725 - 726 - #ifdef CONFIG_SPE 727 - 728 - /* 729 - * For get_evrregs/set_evrregs functions 'data' has the following layout: 730 - * 731 - * struct { 732 - * u32 evr[32]; 733 - * u64 acc; 734 - * u32 spefscr; 735 - * } 736 - */ 737 - 738 - static int evr_active(struct task_struct *target, 739 - const struct user_regset *regset) 740 - { 741 - flush_spe_to_thread(target); 742 - return target->thread.used_spe ? regset->n : 0; 743 - } 744 - 745 - static int evr_get(struct task_struct *target, const struct user_regset *regset, 746 - unsigned int pos, unsigned int count, 747 - void *kbuf, void __user *ubuf) 748 - { 749 - int ret; 750 - 751 - flush_spe_to_thread(target); 752 - 753 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 754 - &target->thread.evr, 755 - 0, sizeof(target->thread.evr)); 756 - 757 - BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != 758 - offsetof(struct thread_struct, spefscr)); 759 - 760 - if (!ret) 761 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 762 - &target->thread.acc, 763 - sizeof(target->thread.evr), -1); 764 - 765 - return ret; 766 - } 767 - 768 - static int evr_set(struct task_struct *target, const struct user_regset *regset, 769 - unsigned int pos, unsigned int count, 770 - const void *kbuf, const void __user *ubuf) 771 - { 772 - int ret; 773 - 774 - flush_spe_to_thread(target); 775 - 776 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 777 - &target->thread.evr, 778 - 0, sizeof(target->thread.evr)); 779 - 780 - BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != 781 - offsetof(struct thread_struct, spefscr)); 782 - 783 - if (!ret) 784 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 785 - &target->thread.acc, 786 - sizeof(target->thread.evr), -1); 787 - 788 - return ret; 789 - } 790 - #endif /* CONFIG_SPE */ 791 - 792 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 793 - /** 794 - * tm_cgpr_active - get active number of registers in CGPR 795 - * @target: The target task. 796 - * @regset: The user regset structure. 797 - * 798 - * This function checks for the active number of available 799 - * regisers in transaction checkpointed GPR category. 800 - */ 801 - static int tm_cgpr_active(struct task_struct *target, 802 - const struct user_regset *regset) 803 - { 804 - if (!cpu_has_feature(CPU_FTR_TM)) 805 - return -ENODEV; 806 - 807 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 808 - return 0; 809 - 810 - return regset->n; 811 - } 812 - 813 - /** 814 - * tm_cgpr_get - get CGPR registers 815 - * @target: The target task. 816 - * @regset: The user regset structure. 817 - * @pos: The buffer position. 818 - * @count: Number of bytes to copy. 819 - * @kbuf: Kernel buffer to copy from. 820 - * @ubuf: User buffer to copy into. 821 - * 822 - * This function gets transaction checkpointed GPR registers. 823 - * 824 - * When the transaction is active, 'ckpt_regs' holds all the checkpointed 825 - * GPR register values for the current transaction to fall back on if it 826 - * aborts in between. This function gets those checkpointed GPR registers. 827 - * The userspace interface buffer layout is as follows. 828 - * 829 - * struct data { 830 - * struct pt_regs ckpt_regs; 831 - * }; 832 - */ 833 - static int tm_cgpr_get(struct task_struct *target, 834 - const struct user_regset *regset, 835 - unsigned int pos, unsigned int count, 836 - void *kbuf, void __user *ubuf) 837 - { 838 - int ret; 839 - 840 - if (!cpu_has_feature(CPU_FTR_TM)) 841 - return -ENODEV; 842 - 843 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 844 - return -ENODATA; 845 - 846 - flush_tmregs_to_thread(target); 847 - flush_fp_to_thread(target); 848 - flush_altivec_to_thread(target); 849 - 850 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 851 - &target->thread.ckpt_regs, 852 - 0, offsetof(struct pt_regs, msr)); 853 - if (!ret) { 854 - unsigned long msr = get_user_ckpt_msr(target); 855 - 856 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr, 857 - offsetof(struct pt_regs, msr), 858 - offsetof(struct pt_regs, msr) + 859 - sizeof(msr)); 860 - } 861 - 862 - BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 863 - offsetof(struct pt_regs, msr) + sizeof(long)); 864 - 865 - if (!ret) 866 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 867 - &target->thread.ckpt_regs.orig_gpr3, 868 - offsetof(struct pt_regs, orig_gpr3), 869 - sizeof(struct user_pt_regs)); 870 - if (!ret) 871 - ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, 872 - sizeof(struct user_pt_regs), -1); 873 - 874 - return ret; 875 - } 876 - 877 - /* 878 - * tm_cgpr_set - set the CGPR registers 879 - * @target: The target task. 880 - * @regset: The user regset structure. 881 - * @pos: The buffer position. 882 - * @count: Number of bytes to copy. 883 - * @kbuf: Kernel buffer to copy into. 884 - * @ubuf: User buffer to copy from. 885 - * 886 - * This function sets in transaction checkpointed GPR registers. 887 - * 888 - * When the transaction is active, 'ckpt_regs' holds the checkpointed 889 - * GPR register values for the current transaction to fall back on if it 890 - * aborts in between. This function sets those checkpointed GPR registers. 891 - * The userspace interface buffer layout is as follows. 892 - * 893 - * struct data { 894 - * struct pt_regs ckpt_regs; 895 - * }; 896 - */ 897 - static int tm_cgpr_set(struct task_struct *target, 898 - const struct user_regset *regset, 899 - unsigned int pos, unsigned int count, 900 - const void *kbuf, const void __user *ubuf) 901 - { 902 - unsigned long reg; 903 - int ret; 904 - 905 - if (!cpu_has_feature(CPU_FTR_TM)) 906 - return -ENODEV; 907 - 908 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 909 - return -ENODATA; 910 - 911 - flush_tmregs_to_thread(target); 912 - flush_fp_to_thread(target); 913 - flush_altivec_to_thread(target); 914 - 915 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 916 - &target->thread.ckpt_regs, 917 - 0, PT_MSR * sizeof(reg)); 918 - 919 - if (!ret && count > 0) { 920 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg, 921 - PT_MSR * sizeof(reg), 922 - (PT_MSR + 1) * sizeof(reg)); 923 - if (!ret) 924 - ret = set_user_ckpt_msr(target, reg); 925 - } 926 - 927 - BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 928 - offsetof(struct pt_regs, msr) + sizeof(long)); 929 - 930 - if (!ret) 931 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 932 - &target->thread.ckpt_regs.orig_gpr3, 933 - PT_ORIG_R3 * sizeof(reg), 934 - (PT_MAX_PUT_REG + 1) * sizeof(reg)); 935 - 936 - if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret) 937 - ret = user_regset_copyin_ignore( 938 - &pos, &count, &kbuf, &ubuf, 939 - (PT_MAX_PUT_REG + 1) * sizeof(reg), 940 - PT_TRAP * sizeof(reg)); 941 - 942 - if (!ret && count > 0) { 943 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg, 944 - PT_TRAP * sizeof(reg), 945 - (PT_TRAP + 1) * sizeof(reg)); 946 - if (!ret) 947 - ret = set_user_ckpt_trap(target, reg); 948 - } 949 - 950 - if (!ret) 951 - ret = user_regset_copyin_ignore( 952 - &pos, &count, &kbuf, &ubuf, 953 - (PT_TRAP + 1) * sizeof(reg), -1); 954 - 955 - return ret; 956 - } 957 - 958 - /** 959 - * tm_cfpr_active - get active number of registers in CFPR 960 - * @target: The target task. 961 - * @regset: The user regset structure. 962 - * 963 - * This function checks for the active number of available 964 - * regisers in transaction checkpointed FPR category. 965 - */ 966 - static int tm_cfpr_active(struct task_struct *target, 967 - const struct user_regset *regset) 968 - { 969 - if (!cpu_has_feature(CPU_FTR_TM)) 970 - return -ENODEV; 971 - 972 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 973 - return 0; 974 - 975 - return regset->n; 976 - } 977 - 978 - /** 979 - * tm_cfpr_get - get CFPR registers 980 - * @target: The target task. 981 - * @regset: The user regset structure. 982 - * @pos: The buffer position. 983 - * @count: Number of bytes to copy. 984 - * @kbuf: Kernel buffer to copy from. 985 - * @ubuf: User buffer to copy into. 986 - * 987 - * This function gets in transaction checkpointed FPR registers. 988 - * 989 - * When the transaction is active 'ckfp_state' holds the checkpointed 990 - * values for the current transaction to fall back on if it aborts 991 - * in between. This function gets those checkpointed FPR registers. 992 - * The userspace interface buffer layout is as follows. 993 - * 994 - * struct data { 995 - * u64 fpr[32]; 996 - * u64 fpscr; 997 - *}; 998 - */ 999 - static int tm_cfpr_get(struct task_struct *target, 1000 - const struct user_regset *regset, 1001 - unsigned int pos, unsigned int count, 1002 - void *kbuf, void __user *ubuf) 1003 - { 1004 - u64 buf[33]; 1005 - int i; 1006 - 1007 - if (!cpu_has_feature(CPU_FTR_TM)) 1008 - return -ENODEV; 1009 - 1010 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1011 - return -ENODATA; 1012 - 1013 - flush_tmregs_to_thread(target); 1014 - flush_fp_to_thread(target); 1015 - flush_altivec_to_thread(target); 1016 - 1017 - /* copy to local buffer then write that out */ 1018 - for (i = 0; i < 32 ; i++) 1019 - buf[i] = target->thread.TS_CKFPR(i); 1020 - buf[32] = target->thread.ckfp_state.fpscr; 1021 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); 1022 - } 1023 - 1024 - /** 1025 - * tm_cfpr_set - set CFPR registers 1026 - * @target: The target task. 1027 - * @regset: The user regset structure. 1028 - * @pos: The buffer position. 1029 - * @count: Number of bytes to copy. 1030 - * @kbuf: Kernel buffer to copy into. 1031 - * @ubuf: User buffer to copy from. 1032 - * 1033 - * This function sets in transaction checkpointed FPR registers. 1034 - * 1035 - * When the transaction is active 'ckfp_state' holds the checkpointed 1036 - * FPR register values for the current transaction to fall back on 1037 - * if it aborts in between. This function sets these checkpointed 1038 - * FPR registers. The userspace interface buffer layout is as follows. 1039 - * 1040 - * struct data { 1041 - * u64 fpr[32]; 1042 - * u64 fpscr; 1043 - *}; 1044 - */ 1045 - static int tm_cfpr_set(struct task_struct *target, 1046 - const struct user_regset *regset, 1047 - unsigned int pos, unsigned int count, 1048 - const void *kbuf, const void __user *ubuf) 1049 - { 1050 - u64 buf[33]; 1051 - int i; 1052 - 1053 - if (!cpu_has_feature(CPU_FTR_TM)) 1054 - return -ENODEV; 1055 - 1056 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1057 - return -ENODATA; 1058 - 1059 - flush_tmregs_to_thread(target); 1060 - flush_fp_to_thread(target); 1061 - flush_altivec_to_thread(target); 1062 - 1063 - for (i = 0; i < 32; i++) 1064 - buf[i] = target->thread.TS_CKFPR(i); 1065 - buf[32] = target->thread.ckfp_state.fpscr; 1066 - 1067 - /* copy to local buffer then write that out */ 1068 - i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); 1069 - if (i) 1070 - return i; 1071 - for (i = 0; i < 32 ; i++) 1072 - target->thread.TS_CKFPR(i) = buf[i]; 1073 - target->thread.ckfp_state.fpscr = buf[32]; 1074 - return 0; 1075 - } 1076 - 1077 - /** 1078 - * tm_cvmx_active - get active number of registers in CVMX 1079 - * @target: The target task. 1080 - * @regset: The user regset structure. 1081 - * 1082 - * This function checks for the active number of available 1083 - * regisers in checkpointed VMX category. 1084 - */ 1085 - static int tm_cvmx_active(struct task_struct *target, 1086 - const struct user_regset *regset) 1087 - { 1088 - if (!cpu_has_feature(CPU_FTR_TM)) 1089 - return -ENODEV; 1090 - 1091 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1092 - return 0; 1093 - 1094 - return regset->n; 1095 - } 1096 - 1097 - /** 1098 - * tm_cvmx_get - get CMVX registers 1099 - * @target: The target task. 1100 - * @regset: The user regset structure. 1101 - * @pos: The buffer position. 1102 - * @count: Number of bytes to copy. 1103 - * @kbuf: Kernel buffer to copy from. 1104 - * @ubuf: User buffer to copy into. 1105 - * 1106 - * This function gets in transaction checkpointed VMX registers. 1107 - * 1108 - * When the transaction is active 'ckvr_state' and 'ckvrsave' hold 1109 - * the checkpointed values for the current transaction to fall 1110 - * back on if it aborts in between. The userspace interface buffer 1111 - * layout is as follows. 1112 - * 1113 - * struct data { 1114 - * vector128 vr[32]; 1115 - * vector128 vscr; 1116 - * vector128 vrsave; 1117 - *}; 1118 - */ 1119 - static int tm_cvmx_get(struct task_struct *target, 1120 - const struct user_regset *regset, 1121 - unsigned int pos, unsigned int count, 1122 - void *kbuf, void __user *ubuf) 1123 - { 1124 - int ret; 1125 - 1126 - BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32])); 1127 - 1128 - if (!cpu_has_feature(CPU_FTR_TM)) 1129 - return -ENODEV; 1130 - 1131 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1132 - return -ENODATA; 1133 - 1134 - /* Flush the state */ 1135 - flush_tmregs_to_thread(target); 1136 - flush_fp_to_thread(target); 1137 - flush_altivec_to_thread(target); 1138 - 1139 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1140 - &target->thread.ckvr_state, 0, 1141 - 33 * sizeof(vector128)); 1142 - if (!ret) { 1143 - /* 1144 - * Copy out only the low-order word of vrsave. 1145 - */ 1146 - union { 1147 - elf_vrreg_t reg; 1148 - u32 word; 1149 - } vrsave; 1150 - memset(&vrsave, 0, sizeof(vrsave)); 1151 - vrsave.word = target->thread.ckvrsave; 1152 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, 1153 - 33 * sizeof(vector128), -1); 1154 - } 1155 - 1156 - return ret; 1157 - } 1158 - 1159 - /** 1160 - * tm_cvmx_set - set CMVX registers 1161 - * @target: The target task. 1162 - * @regset: The user regset structure. 1163 - * @pos: The buffer position. 1164 - * @count: Number of bytes to copy. 1165 - * @kbuf: Kernel buffer to copy into. 1166 - * @ubuf: User buffer to copy from. 1167 - * 1168 - * This function sets in transaction checkpointed VMX registers. 1169 - * 1170 - * When the transaction is active 'ckvr_state' and 'ckvrsave' hold 1171 - * the checkpointed values for the current transaction to fall 1172 - * back on if it aborts in between. The userspace interface buffer 1173 - * layout is as follows. 1174 - * 1175 - * struct data { 1176 - * vector128 vr[32]; 1177 - * vector128 vscr; 1178 - * vector128 vrsave; 1179 - *}; 1180 - */ 1181 - static int tm_cvmx_set(struct task_struct *target, 1182 - const struct user_regset *regset, 1183 - unsigned int pos, unsigned int count, 1184 - const void *kbuf, const void __user *ubuf) 1185 - { 1186 - int ret; 1187 - 1188 - BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32])); 1189 - 1190 - if (!cpu_has_feature(CPU_FTR_TM)) 1191 - return -ENODEV; 1192 - 1193 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1194 - return -ENODATA; 1195 - 1196 - flush_tmregs_to_thread(target); 1197 - flush_fp_to_thread(target); 1198 - flush_altivec_to_thread(target); 1199 - 1200 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1201 - &target->thread.ckvr_state, 0, 1202 - 33 * sizeof(vector128)); 1203 - if (!ret && count > 0) { 1204 - /* 1205 - * We use only the low-order word of vrsave. 1206 - */ 1207 - union { 1208 - elf_vrreg_t reg; 1209 - u32 word; 1210 - } vrsave; 1211 - memset(&vrsave, 0, sizeof(vrsave)); 1212 - vrsave.word = target->thread.ckvrsave; 1213 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, 1214 - 33 * sizeof(vector128), -1); 1215 - if (!ret) 1216 - target->thread.ckvrsave = vrsave.word; 1217 - } 1218 - 1219 - return ret; 1220 - } 1221 - 1222 - /** 1223 - * tm_cvsx_active - get active number of registers in CVSX 1224 - * @target: The target task. 1225 - * @regset: The user regset structure. 1226 - * 1227 - * This function checks for the active number of available 1228 - * regisers in transaction checkpointed VSX category. 1229 - */ 1230 - static int tm_cvsx_active(struct task_struct *target, 1231 - const struct user_regset *regset) 1232 - { 1233 - if (!cpu_has_feature(CPU_FTR_TM)) 1234 - return -ENODEV; 1235 - 1236 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1237 - return 0; 1238 - 1239 - flush_vsx_to_thread(target); 1240 - return target->thread.used_vsr ? regset->n : 0; 1241 - } 1242 - 1243 - /** 1244 - * tm_cvsx_get - get CVSX registers 1245 - * @target: The target task. 1246 - * @regset: The user regset structure. 1247 - * @pos: The buffer position. 1248 - * @count: Number of bytes to copy. 1249 - * @kbuf: Kernel buffer to copy from. 1250 - * @ubuf: User buffer to copy into. 1251 - * 1252 - * This function gets in transaction checkpointed VSX registers. 1253 - * 1254 - * When the transaction is active 'ckfp_state' holds the checkpointed 1255 - * values for the current transaction to fall back on if it aborts 1256 - * in between. This function gets those checkpointed VSX registers. 1257 - * The userspace interface buffer layout is as follows. 1258 - * 1259 - * struct data { 1260 - * u64 vsx[32]; 1261 - *}; 1262 - */ 1263 - static int tm_cvsx_get(struct task_struct *target, 1264 - const struct user_regset *regset, 1265 - unsigned int pos, unsigned int count, 1266 - void *kbuf, void __user *ubuf) 1267 - { 1268 - u64 buf[32]; 1269 - int ret, i; 1270 - 1271 - if (!cpu_has_feature(CPU_FTR_TM)) 1272 - return -ENODEV; 1273 - 1274 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1275 - return -ENODATA; 1276 - 1277 - /* Flush the state */ 1278 - flush_tmregs_to_thread(target); 1279 - flush_fp_to_thread(target); 1280 - flush_altivec_to_thread(target); 1281 - flush_vsx_to_thread(target); 1282 - 1283 - for (i = 0; i < 32 ; i++) 1284 - buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET]; 1285 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1286 - buf, 0, 32 * sizeof(double)); 1287 - 1288 - return ret; 1289 - } 1290 - 1291 - /** 1292 - * tm_cvsx_set - set CFPR registers 1293 - * @target: The target task. 1294 - * @regset: The user regset structure. 1295 - * @pos: The buffer position. 1296 - * @count: Number of bytes to copy. 1297 - * @kbuf: Kernel buffer to copy into. 1298 - * @ubuf: User buffer to copy from. 1299 - * 1300 - * This function sets in transaction checkpointed VSX registers. 1301 - * 1302 - * When the transaction is active 'ckfp_state' holds the checkpointed 1303 - * VSX register values for the current transaction to fall back on 1304 - * if it aborts in between. This function sets these checkpointed 1305 - * FPR registers. The userspace interface buffer layout is as follows. 1306 - * 1307 - * struct data { 1308 - * u64 vsx[32]; 1309 - *}; 1310 - */ 1311 - static int tm_cvsx_set(struct task_struct *target, 1312 - const struct user_regset *regset, 1313 - unsigned int pos, unsigned int count, 1314 - const void *kbuf, const void __user *ubuf) 1315 - { 1316 - u64 buf[32]; 1317 - int ret, i; 1318 - 1319 - if (!cpu_has_feature(CPU_FTR_TM)) 1320 - return -ENODEV; 1321 - 1322 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1323 - return -ENODATA; 1324 - 1325 - /* Flush the state */ 1326 - flush_tmregs_to_thread(target); 1327 - flush_fp_to_thread(target); 1328 - flush_altivec_to_thread(target); 1329 - flush_vsx_to_thread(target); 1330 - 1331 - for (i = 0; i < 32 ; i++) 1332 - buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET]; 1333 - 1334 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1335 - buf, 0, 32 * sizeof(double)); 1336 - if (!ret) 1337 - for (i = 0; i < 32 ; i++) 1338 - target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i]; 1339 - 1340 - return ret; 1341 - } 1342 - 1343 - /** 1344 - * tm_spr_active - get active number of registers in TM SPR 1345 - * @target: The target task. 1346 - * @regset: The user regset structure. 1347 - * 1348 - * This function checks the active number of available 1349 - * regisers in the transactional memory SPR category. 1350 - */ 1351 - static int tm_spr_active(struct task_struct *target, 1352 - const struct user_regset *regset) 1353 - { 1354 - if (!cpu_has_feature(CPU_FTR_TM)) 1355 - return -ENODEV; 1356 - 1357 - return regset->n; 1358 - } 1359 - 1360 - /** 1361 - * tm_spr_get - get the TM related SPR registers 1362 - * @target: The target task. 1363 - * @regset: The user regset structure. 1364 - * @pos: The buffer position. 1365 - * @count: Number of bytes to copy. 1366 - * @kbuf: Kernel buffer to copy from. 1367 - * @ubuf: User buffer to copy into. 1368 - * 1369 - * This function gets transactional memory related SPR registers. 1370 - * The userspace interface buffer layout is as follows. 1371 - * 1372 - * struct { 1373 - * u64 tm_tfhar; 1374 - * u64 tm_texasr; 1375 - * u64 tm_tfiar; 1376 - * }; 1377 - */ 1378 - static int tm_spr_get(struct task_struct *target, 1379 - const struct user_regset *regset, 1380 - unsigned int pos, unsigned int count, 1381 - void *kbuf, void __user *ubuf) 1382 - { 1383 - int ret; 1384 - 1385 - /* Build tests */ 1386 - BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr)); 1387 - BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar)); 1388 - BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs)); 1389 - 1390 - if (!cpu_has_feature(CPU_FTR_TM)) 1391 - return -ENODEV; 1392 - 1393 - /* Flush the states */ 1394 - flush_tmregs_to_thread(target); 1395 - flush_fp_to_thread(target); 1396 - flush_altivec_to_thread(target); 1397 - 1398 - /* TFHAR register */ 1399 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1400 - &target->thread.tm_tfhar, 0, sizeof(u64)); 1401 - 1402 - /* TEXASR register */ 1403 - if (!ret) 1404 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1405 - &target->thread.tm_texasr, sizeof(u64), 1406 - 2 * sizeof(u64)); 1407 - 1408 - /* TFIAR register */ 1409 - if (!ret) 1410 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1411 - &target->thread.tm_tfiar, 1412 - 2 * sizeof(u64), 3 * sizeof(u64)); 1413 - return ret; 1414 - } 1415 - 1416 - /** 1417 - * tm_spr_set - set the TM related SPR registers 1418 - * @target: The target task. 1419 - * @regset: The user regset structure. 1420 - * @pos: The buffer position. 1421 - * @count: Number of bytes to copy. 1422 - * @kbuf: Kernel buffer to copy into. 1423 - * @ubuf: User buffer to copy from. 1424 - * 1425 - * This function sets transactional memory related SPR registers. 1426 - * The userspace interface buffer layout is as follows. 1427 - * 1428 - * struct { 1429 - * u64 tm_tfhar; 1430 - * u64 tm_texasr; 1431 - * u64 tm_tfiar; 1432 - * }; 1433 - */ 1434 - static int tm_spr_set(struct task_struct *target, 1435 - const struct user_regset *regset, 1436 - unsigned int pos, unsigned int count, 1437 - const void *kbuf, const void __user *ubuf) 1438 - { 1439 - int ret; 1440 - 1441 - /* Build tests */ 1442 - BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr)); 1443 - BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar)); 1444 - BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs)); 1445 - 1446 - if (!cpu_has_feature(CPU_FTR_TM)) 1447 - return -ENODEV; 1448 - 1449 - /* Flush the states */ 1450 - flush_tmregs_to_thread(target); 1451 - flush_fp_to_thread(target); 1452 - flush_altivec_to_thread(target); 1453 - 1454 - /* TFHAR register */ 1455 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1456 - &target->thread.tm_tfhar, 0, sizeof(u64)); 1457 - 1458 - /* TEXASR register */ 1459 - if (!ret) 1460 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1461 - &target->thread.tm_texasr, sizeof(u64), 1462 - 2 * sizeof(u64)); 1463 - 1464 - /* TFIAR register */ 1465 - if (!ret) 1466 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1467 - &target->thread.tm_tfiar, 1468 - 2 * sizeof(u64), 3 * sizeof(u64)); 1469 - return ret; 1470 - } 1471 - 1472 - static int tm_tar_active(struct task_struct *target, 1473 - const struct user_regset *regset) 1474 - { 1475 - if (!cpu_has_feature(CPU_FTR_TM)) 1476 - return -ENODEV; 1477 - 1478 - if (MSR_TM_ACTIVE(target->thread.regs->msr)) 1479 - return regset->n; 1480 - 1481 - return 0; 1482 - } 1483 - 1484 - static int tm_tar_get(struct task_struct *target, 1485 - const struct user_regset *regset, 1486 - unsigned int pos, unsigned int count, 1487 - void *kbuf, void __user *ubuf) 1488 - { 1489 - int ret; 1490 - 1491 - if (!cpu_has_feature(CPU_FTR_TM)) 1492 - return -ENODEV; 1493 - 1494 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1495 - return -ENODATA; 1496 - 1497 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1498 - &target->thread.tm_tar, 0, sizeof(u64)); 1499 - return ret; 1500 - } 1501 - 1502 - static int tm_tar_set(struct task_struct *target, 1503 - const struct user_regset *regset, 1504 - unsigned int pos, unsigned int count, 1505 - const void *kbuf, const void __user *ubuf) 1506 - { 1507 - int ret; 1508 - 1509 - if (!cpu_has_feature(CPU_FTR_TM)) 1510 - return -ENODEV; 1511 - 1512 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1513 - return -ENODATA; 1514 - 1515 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1516 - &target->thread.tm_tar, 0, sizeof(u64)); 1517 - return ret; 1518 - } 1519 - 1520 - static int tm_ppr_active(struct task_struct *target, 1521 - const struct user_regset *regset) 1522 - { 1523 - if (!cpu_has_feature(CPU_FTR_TM)) 1524 - return -ENODEV; 1525 - 1526 - if (MSR_TM_ACTIVE(target->thread.regs->msr)) 1527 - return regset->n; 1528 - 1529 - return 0; 1530 - } 1531 - 1532 - 1533 - static int tm_ppr_get(struct task_struct *target, 1534 - const struct user_regset *regset, 1535 - unsigned int pos, unsigned int count, 1536 - void *kbuf, void __user *ubuf) 1537 - { 1538 - int ret; 1539 - 1540 - if (!cpu_has_feature(CPU_FTR_TM)) 1541 - return -ENODEV; 1542 - 1543 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1544 - return -ENODATA; 1545 - 1546 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1547 - &target->thread.tm_ppr, 0, sizeof(u64)); 1548 - return ret; 1549 - } 1550 - 1551 - static int tm_ppr_set(struct task_struct *target, 1552 - const struct user_regset *regset, 1553 - unsigned int pos, unsigned int count, 1554 - const void *kbuf, const void __user *ubuf) 1555 - { 1556 - int ret; 1557 - 1558 - if (!cpu_has_feature(CPU_FTR_TM)) 1559 - return -ENODEV; 1560 - 1561 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1562 - return -ENODATA; 1563 - 1564 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1565 - &target->thread.tm_ppr, 0, sizeof(u64)); 1566 - return ret; 1567 - } 1568 - 1569 - static int tm_dscr_active(struct task_struct *target, 1570 - const struct user_regset *regset) 1571 - { 1572 - if (!cpu_has_feature(CPU_FTR_TM)) 1573 - return -ENODEV; 1574 - 1575 - if (MSR_TM_ACTIVE(target->thread.regs->msr)) 1576 - return regset->n; 1577 - 1578 - return 0; 1579 - } 1580 - 1581 - static int tm_dscr_get(struct task_struct *target, 1582 - const struct user_regset *regset, 1583 - unsigned int pos, unsigned int count, 1584 - void *kbuf, void __user *ubuf) 1585 - { 1586 - int ret; 1587 - 1588 - if (!cpu_has_feature(CPU_FTR_TM)) 1589 - return -ENODEV; 1590 - 1591 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1592 - return -ENODATA; 1593 - 1594 - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1595 - &target->thread.tm_dscr, 0, sizeof(u64)); 1596 - return ret; 1597 - } 1598 - 1599 - static int tm_dscr_set(struct task_struct *target, 1600 - const struct user_regset *regset, 1601 - unsigned int pos, unsigned int count, 1602 - const void *kbuf, const void __user *ubuf) 1603 - { 1604 - int ret; 1605 - 1606 - if (!cpu_has_feature(CPU_FTR_TM)) 1607 - return -ENODEV; 1608 - 1609 - if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 1610 - return -ENODATA; 1611 - 1612 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1613 - &target->thread.tm_dscr, 0, sizeof(u64)); 1614 - return ret; 1615 - } 1616 - #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 1617 - 1618 - #ifdef CONFIG_PPC64 1619 - static int ppr_get(struct task_struct *target, 1620 - const struct user_regset *regset, 1621 - unsigned int pos, unsigned int count, 1622 - void *kbuf, void __user *ubuf) 1623 - { 1624 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1625 - &target->thread.regs->ppr, 0, sizeof(u64)); 1626 - } 1627 - 1628 - static int ppr_set(struct task_struct *target, 1629 - const struct user_regset *regset, 1630 - unsigned int pos, unsigned int count, 1631 - const void *kbuf, const void __user *ubuf) 1632 - { 1633 - return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1634 - &target->thread.regs->ppr, 0, sizeof(u64)); 1635 - } 1636 - 1637 - static int dscr_get(struct task_struct *target, 1638 - const struct user_regset *regset, 1639 - unsigned int pos, unsigned int count, 1640 - void *kbuf, void __user *ubuf) 1641 - { 1642 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1643 - &target->thread.dscr, 0, sizeof(u64)); 1644 - } 1645 - static int dscr_set(struct task_struct *target, 1646 - const struct user_regset *regset, 1647 - unsigned int pos, unsigned int count, 1648 - const void *kbuf, const void __user *ubuf) 1649 - { 1650 - return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1651 - &target->thread.dscr, 0, sizeof(u64)); 1652 - } 1653 - #endif 1654 - #ifdef CONFIG_PPC_BOOK3S_64 1655 - static int tar_get(struct task_struct *target, 1656 - const struct user_regset *regset, 1657 - unsigned int pos, unsigned int count, 1658 - void *kbuf, void __user *ubuf) 1659 - { 1660 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1661 - &target->thread.tar, 0, sizeof(u64)); 1662 - } 1663 - static int tar_set(struct task_struct *target, 1664 - const struct user_regset *regset, 1665 - unsigned int pos, unsigned int count, 1666 - const void *kbuf, const void __user *ubuf) 1667 - { 1668 - return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1669 - &target->thread.tar, 0, sizeof(u64)); 1670 - } 1671 - 1672 - static int ebb_active(struct task_struct *target, 1673 - const struct user_regset *regset) 1674 - { 1675 - if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 1676 - return -ENODEV; 1677 - 1678 - if (target->thread.used_ebb) 1679 - return regset->n; 1680 - 1681 - return 0; 1682 - } 1683 - 1684 - static int ebb_get(struct task_struct *target, 1685 - const struct user_regset *regset, 1686 - unsigned int pos, unsigned int count, 1687 - void *kbuf, void __user *ubuf) 1688 - { 1689 - /* Build tests */ 1690 - BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr)); 1691 - BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr)); 1692 - 1693 - if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 1694 - return -ENODEV; 1695 - 1696 - if (!target->thread.used_ebb) 1697 - return -ENODATA; 1698 - 1699 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1700 - &target->thread.ebbrr, 0, 3 * sizeof(unsigned long)); 1701 - } 1702 - 1703 - static int ebb_set(struct task_struct *target, 1704 - const struct user_regset *regset, 1705 - unsigned int pos, unsigned int count, 1706 - const void *kbuf, const void __user *ubuf) 1707 - { 1708 - int ret = 0; 1709 - 1710 - /* Build tests */ 1711 - BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr)); 1712 - BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr)); 1713 - 1714 - if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 1715 - return -ENODEV; 1716 - 1717 - if (target->thread.used_ebb) 1718 - return -ENODATA; 1719 - 1720 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1721 - &target->thread.ebbrr, 0, sizeof(unsigned long)); 1722 - 1723 - if (!ret) 1724 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1725 - &target->thread.ebbhr, sizeof(unsigned long), 1726 - 2 * sizeof(unsigned long)); 1727 - 1728 - if (!ret) 1729 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1730 - &target->thread.bescr, 1731 - 2 * sizeof(unsigned long), 3 * sizeof(unsigned long)); 1732 - 1733 - return ret; 1734 - } 1735 - static int pmu_active(struct task_struct *target, 1736 - const struct user_regset *regset) 1737 - { 1738 - if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 1739 - return -ENODEV; 1740 - 1741 - return regset->n; 1742 - } 1743 - 1744 - static int pmu_get(struct task_struct *target, 1745 - const struct user_regset *regset, 1746 - unsigned int pos, unsigned int count, 1747 - void *kbuf, void __user *ubuf) 1748 - { 1749 - /* Build tests */ 1750 - BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar)); 1751 - BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier)); 1752 - BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2)); 1753 - BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0)); 1754 - 1755 - if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 1756 - return -ENODEV; 1757 - 1758 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1759 - &target->thread.siar, 0, 1760 - 5 * sizeof(unsigned long)); 1761 - } 1762 - 1763 - static int pmu_set(struct task_struct *target, 1764 - const struct user_regset *regset, 1765 - unsigned int pos, unsigned int count, 1766 - const void *kbuf, const void __user *ubuf) 1767 - { 1768 - int ret = 0; 1769 - 1770 - /* Build tests */ 1771 - BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar)); 1772 - BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier)); 1773 - BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2)); 1774 - BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0)); 1775 - 1776 - if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 1777 - return -ENODEV; 1778 - 1779 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1780 - &target->thread.siar, 0, 1781 - sizeof(unsigned long)); 1782 - 1783 - if (!ret) 1784 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1785 - &target->thread.sdar, sizeof(unsigned long), 1786 - 2 * sizeof(unsigned long)); 1787 - 1788 - if (!ret) 1789 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1790 - &target->thread.sier, 2 * sizeof(unsigned long), 1791 - 3 * sizeof(unsigned long)); 1792 - 1793 - if (!ret) 1794 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1795 - &target->thread.mmcr2, 3 * sizeof(unsigned long), 1796 - 4 * sizeof(unsigned long)); 1797 - 1798 - if (!ret) 1799 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1800 - &target->thread.mmcr0, 4 * sizeof(unsigned long), 1801 - 5 * sizeof(unsigned long)); 1802 - return ret; 1803 - } 1804 - #endif 1805 - 1806 - #ifdef CONFIG_PPC_MEM_KEYS 1807 - static int pkey_active(struct task_struct *target, 1808 - const struct user_regset *regset) 1809 - { 1810 - if (!arch_pkeys_enabled()) 1811 - return -ENODEV; 1812 - 1813 - return regset->n; 1814 - } 1815 - 1816 - static int pkey_get(struct task_struct *target, 1817 - const struct user_regset *regset, 1818 - unsigned int pos, unsigned int count, 1819 - void *kbuf, void __user *ubuf) 1820 - { 1821 - BUILD_BUG_ON(TSO(amr) + sizeof(unsigned long) != TSO(iamr)); 1822 - BUILD_BUG_ON(TSO(iamr) + sizeof(unsigned long) != TSO(uamor)); 1823 - 1824 - if (!arch_pkeys_enabled()) 1825 - return -ENODEV; 1826 - 1827 - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1828 - &target->thread.amr, 0, 1829 - ELF_NPKEY * sizeof(unsigned long)); 1830 - } 1831 - 1832 - static int pkey_set(struct task_struct *target, 1833 - const struct user_regset *regset, 1834 - unsigned int pos, unsigned int count, 1835 - const void *kbuf, const void __user *ubuf) 1836 - { 1837 - u64 new_amr; 1838 - int ret; 1839 - 1840 - if (!arch_pkeys_enabled()) 1841 - return -ENODEV; 1842 - 1843 - /* Only the AMR can be set from userspace */ 1844 - if (pos != 0 || count != sizeof(new_amr)) 1845 - return -EINVAL; 1846 - 1847 - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1848 - &new_amr, 0, sizeof(new_amr)); 1849 - if (ret) 1850 - return ret; 1851 - 1852 - /* UAMOR determines which bits of the AMR can be set from userspace. */ 1853 - target->thread.amr = (new_amr & target->thread.uamor) | 1854 - (target->thread.amr & ~target->thread.uamor); 1855 - 1856 - return 0; 1857 - } 1858 - #endif /* CONFIG_PPC_MEM_KEYS */ 1859 - 1860 - /* 1861 - * These are our native regset flavors. 1862 - */ 1863 - enum powerpc_regset { 1864 - REGSET_GPR, 1865 - REGSET_FPR, 1866 - #ifdef CONFIG_ALTIVEC 1867 - REGSET_VMX, 1868 - #endif 1869 - #ifdef CONFIG_VSX 1870 - REGSET_VSX, 1871 - #endif 1872 - #ifdef CONFIG_SPE 1873 - REGSET_SPE, 1874 - #endif 1875 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1876 - REGSET_TM_CGPR, /* TM checkpointed GPR registers */ 1877 - REGSET_TM_CFPR, /* TM checkpointed FPR registers */ 1878 - REGSET_TM_CVMX, /* TM checkpointed VMX registers */ 1879 - REGSET_TM_CVSX, /* TM checkpointed VSX registers */ 1880 - REGSET_TM_SPR, /* TM specific SPR registers */ 1881 - REGSET_TM_CTAR, /* TM checkpointed TAR register */ 1882 - REGSET_TM_CPPR, /* TM checkpointed PPR register */ 1883 - REGSET_TM_CDSCR, /* TM checkpointed DSCR register */ 1884 - #endif 1885 - #ifdef CONFIG_PPC64 1886 - REGSET_PPR, /* PPR register */ 1887 - REGSET_DSCR, /* DSCR register */ 1888 - #endif 1889 - #ifdef CONFIG_PPC_BOOK3S_64 1890 - REGSET_TAR, /* TAR register */ 1891 - REGSET_EBB, /* EBB registers */ 1892 - REGSET_PMR, /* Performance Monitor Registers */ 1893 - #endif 1894 - #ifdef CONFIG_PPC_MEM_KEYS 1895 - REGSET_PKEY, /* AMR register */ 1896 - #endif 1897 - }; 1898 - 1899 - static const struct user_regset native_regsets[] = { 1900 - [REGSET_GPR] = { 1901 - .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, 1902 - .size = sizeof(long), .align = sizeof(long), 1903 - .get = gpr_get, .set = gpr_set 1904 - }, 1905 - [REGSET_FPR] = { 1906 - .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, 1907 - .size = sizeof(double), .align = sizeof(double), 1908 - .get = fpr_get, .set = fpr_set 1909 - }, 1910 - #ifdef CONFIG_ALTIVEC 1911 - [REGSET_VMX] = { 1912 - .core_note_type = NT_PPC_VMX, .n = 34, 1913 - .size = sizeof(vector128), .align = sizeof(vector128), 1914 - .active = vr_active, .get = vr_get, .set = vr_set 1915 - }, 1916 - #endif 1917 - #ifdef CONFIG_VSX 1918 - [REGSET_VSX] = { 1919 - .core_note_type = NT_PPC_VSX, .n = 32, 1920 - .size = sizeof(double), .align = sizeof(double), 1921 - .active = vsr_active, .get = vsr_get, .set = vsr_set 1922 - }, 1923 - #endif 1924 - #ifdef CONFIG_SPE 1925 - [REGSET_SPE] = { 1926 - .core_note_type = NT_PPC_SPE, .n = 35, 1927 - .size = sizeof(u32), .align = sizeof(u32), 1928 - .active = evr_active, .get = evr_get, .set = evr_set 1929 - }, 1930 - #endif 1931 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1932 - [REGSET_TM_CGPR] = { 1933 - .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG, 1934 - .size = sizeof(long), .align = sizeof(long), 1935 - .active = tm_cgpr_active, .get = tm_cgpr_get, .set = tm_cgpr_set 1936 - }, 1937 - [REGSET_TM_CFPR] = { 1938 - .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG, 1939 - .size = sizeof(double), .align = sizeof(double), 1940 - .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set 1941 - }, 1942 - [REGSET_TM_CVMX] = { 1943 - .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX, 1944 - .size = sizeof(vector128), .align = sizeof(vector128), 1945 - .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set 1946 - }, 1947 - [REGSET_TM_CVSX] = { 1948 - .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX, 1949 - .size = sizeof(double), .align = sizeof(double), 1950 - .active = tm_cvsx_active, .get = tm_cvsx_get, .set = tm_cvsx_set 1951 - }, 1952 - [REGSET_TM_SPR] = { 1953 - .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG, 1954 - .size = sizeof(u64), .align = sizeof(u64), 1955 - .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set 1956 - }, 1957 - [REGSET_TM_CTAR] = { 1958 - .core_note_type = NT_PPC_TM_CTAR, .n = 1, 1959 - .size = sizeof(u64), .align = sizeof(u64), 1960 - .active = tm_tar_active, .get = tm_tar_get, .set = tm_tar_set 1961 - }, 1962 - [REGSET_TM_CPPR] = { 1963 - .core_note_type = NT_PPC_TM_CPPR, .n = 1, 1964 - .size = sizeof(u64), .align = sizeof(u64), 1965 - .active = tm_ppr_active, .get = tm_ppr_get, .set = tm_ppr_set 1966 - }, 1967 - [REGSET_TM_CDSCR] = { 1968 - .core_note_type = NT_PPC_TM_CDSCR, .n = 1, 1969 - .size = sizeof(u64), .align = sizeof(u64), 1970 - .active = tm_dscr_active, .get = tm_dscr_get, .set = tm_dscr_set 1971 - }, 1972 - #endif 1973 - #ifdef CONFIG_PPC64 1974 - [REGSET_PPR] = { 1975 - .core_note_type = NT_PPC_PPR, .n = 1, 1976 - .size = sizeof(u64), .align = sizeof(u64), 1977 - .get = ppr_get, .set = ppr_set 1978 - }, 1979 - [REGSET_DSCR] = { 1980 - .core_note_type = NT_PPC_DSCR, .n = 1, 1981 - .size = sizeof(u64), .align = sizeof(u64), 1982 - .get = dscr_get, .set = dscr_set 1983 - }, 1984 - #endif 1985 - #ifdef CONFIG_PPC_BOOK3S_64 1986 - [REGSET_TAR] = { 1987 - .core_note_type = NT_PPC_TAR, .n = 1, 1988 - .size = sizeof(u64), .align = sizeof(u64), 1989 - .get = tar_get, .set = tar_set 1990 - }, 1991 - [REGSET_EBB] = { 1992 - .core_note_type = NT_PPC_EBB, .n = ELF_NEBB, 1993 - .size = sizeof(u64), .align = sizeof(u64), 1994 - .active = ebb_active, .get = ebb_get, .set = ebb_set 1995 - }, 1996 - [REGSET_PMR] = { 1997 - .core_note_type = NT_PPC_PMU, .n = ELF_NPMU, 1998 - .size = sizeof(u64), .align = sizeof(u64), 1999 - .active = pmu_active, .get = pmu_get, .set = pmu_set 2000 - }, 2001 - #endif 2002 - #ifdef CONFIG_PPC_MEM_KEYS 2003 - [REGSET_PKEY] = { 2004 - .core_note_type = NT_PPC_PKEY, .n = ELF_NPKEY, 2005 - .size = sizeof(u64), .align = sizeof(u64), 2006 - .active = pkey_active, .get = pkey_get, .set = pkey_set 2007 - }, 2008 - #endif 2009 - }; 2010 - 2011 - static const struct user_regset_view user_ppc_native_view = { 2012 - .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI, 2013 - .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets) 2014 - }; 2015 - 2016 - #ifdef CONFIG_PPC64 2017 - #include <linux/compat.h> 2018 - 2019 - static int gpr32_get_common(struct task_struct *target, 2020 - const struct user_regset *regset, 2021 - unsigned int pos, unsigned int count, 2022 - void *kbuf, void __user *ubuf, 2023 - unsigned long *regs) 2024 - { 2025 - compat_ulong_t *k = kbuf; 2026 - compat_ulong_t __user *u = ubuf; 2027 - compat_ulong_t reg; 2028 - 2029 - pos /= sizeof(reg); 2030 - count /= sizeof(reg); 2031 - 2032 - if (kbuf) 2033 - for (; count > 0 && pos < PT_MSR; --count) 2034 - *k++ = regs[pos++]; 2035 - else 2036 - for (; count > 0 && pos < PT_MSR; --count) 2037 - if (__put_user((compat_ulong_t) regs[pos++], u++)) 2038 - return -EFAULT; 2039 - 2040 - if (count > 0 && pos == PT_MSR) { 2041 - reg = get_user_msr(target); 2042 - if (kbuf) 2043 - *k++ = reg; 2044 - else if (__put_user(reg, u++)) 2045 - return -EFAULT; 2046 - ++pos; 2047 - --count; 2048 - } 2049 - 2050 - if (kbuf) 2051 - for (; count > 0 && pos < PT_REGS_COUNT; --count) 2052 - *k++ = regs[pos++]; 2053 - else 2054 - for (; count > 0 && pos < PT_REGS_COUNT; --count) 2055 - if (__put_user((compat_ulong_t) regs[pos++], u++)) 2056 - return -EFAULT; 2057 - 2058 - kbuf = k; 2059 - ubuf = u; 2060 - pos *= sizeof(reg); 2061 - count *= sizeof(reg); 2062 - return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, 2063 - PT_REGS_COUNT * sizeof(reg), -1); 2064 - } 2065 - 2066 - static int gpr32_set_common(struct task_struct *target, 2067 - const struct user_regset *regset, 2068 - unsigned int pos, unsigned int count, 2069 - const void *kbuf, const void __user *ubuf, 2070 - unsigned long *regs) 2071 - { 2072 - const compat_ulong_t *k = kbuf; 2073 - const compat_ulong_t __user *u = ubuf; 2074 - compat_ulong_t reg; 2075 - 2076 - pos /= sizeof(reg); 2077 - count /= sizeof(reg); 2078 - 2079 - if (kbuf) 2080 - for (; count > 0 && pos < PT_MSR; --count) 2081 - regs[pos++] = *k++; 2082 - else 2083 - for (; count > 0 && pos < PT_MSR; --count) { 2084 - if (__get_user(reg, u++)) 2085 - return -EFAULT; 2086 - regs[pos++] = reg; 2087 - } 2088 - 2089 - 2090 - if (count > 0 && pos == PT_MSR) { 2091 - if (kbuf) 2092 - reg = *k++; 2093 - else if (__get_user(reg, u++)) 2094 - return -EFAULT; 2095 - set_user_msr(target, reg); 2096 - ++pos; 2097 - --count; 2098 - } 2099 - 2100 - if (kbuf) { 2101 - for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) 2102 - regs[pos++] = *k++; 2103 - for (; count > 0 && pos < PT_TRAP; --count, ++pos) 2104 - ++k; 2105 - } else { 2106 - for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) { 2107 - if (__get_user(reg, u++)) 2108 - return -EFAULT; 2109 - regs[pos++] = reg; 2110 - } 2111 - for (; count > 0 && pos < PT_TRAP; --count, ++pos) 2112 - if (__get_user(reg, u++)) 2113 - return -EFAULT; 2114 - } 2115 - 2116 - if (count > 0 && pos == PT_TRAP) { 2117 - if (kbuf) 2118 - reg = *k++; 2119 - else if (__get_user(reg, u++)) 2120 - return -EFAULT; 2121 - set_user_trap(target, reg); 2122 - ++pos; 2123 - --count; 2124 - } 2125 - 2126 - kbuf = k; 2127 - ubuf = u; 2128 - pos *= sizeof(reg); 2129 - count *= sizeof(reg); 2130 - return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 2131 - (PT_TRAP + 1) * sizeof(reg), -1); 2132 - } 2133 - 2134 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 2135 - static int tm_cgpr32_get(struct task_struct *target, 2136 - const struct user_regset *regset, 2137 - unsigned int pos, unsigned int count, 2138 - void *kbuf, void __user *ubuf) 2139 - { 2140 - return gpr32_get_common(target, regset, pos, count, kbuf, ubuf, 2141 - &target->thread.ckpt_regs.gpr[0]); 2142 - } 2143 - 2144 - static int tm_cgpr32_set(struct task_struct *target, 2145 - const struct user_regset *regset, 2146 - unsigned int pos, unsigned int count, 2147 - const void *kbuf, const void __user *ubuf) 2148 - { 2149 - return gpr32_set_common(target, regset, pos, count, kbuf, ubuf, 2150 - &target->thread.ckpt_regs.gpr[0]); 2151 - } 2152 - #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 2153 - 2154 - static int gpr32_get(struct task_struct *target, 2155 - const struct user_regset *regset, 2156 - unsigned int pos, unsigned int count, 2157 - void *kbuf, void __user *ubuf) 2158 - { 2159 - int i; 2160 - 2161 - if (target->thread.regs == NULL) 2162 - return -EIO; 2163 - 2164 - if (!FULL_REGS(target->thread.regs)) { 2165 - /* 2166 - * We have a partial register set. 2167 - * Fill 14-31 with bogus values. 2168 - */ 2169 - for (i = 14; i < 32; i++) 2170 - target->thread.regs->gpr[i] = NV_REG_POISON; 2171 - } 2172 - return gpr32_get_common(target, regset, pos, count, kbuf, ubuf, 2173 - &target->thread.regs->gpr[0]); 2174 - } 2175 - 2176 - static int gpr32_set(struct task_struct *target, 2177 - const struct user_regset *regset, 2178 - unsigned int pos, unsigned int count, 2179 - const void *kbuf, const void __user *ubuf) 2180 - { 2181 - if (target->thread.regs == NULL) 2182 - return -EIO; 2183 - 2184 - CHECK_FULL_REGS(target->thread.regs); 2185 - return gpr32_set_common(target, regset, pos, count, kbuf, ubuf, 2186 - &target->thread.regs->gpr[0]); 2187 - } 2188 - 2189 - /* 2190 - * These are the regset flavors matching the CONFIG_PPC32 native set. 2191 - */ 2192 - static const struct user_regset compat_regsets[] = { 2193 - [REGSET_GPR] = { 2194 - .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, 2195 - .size = sizeof(compat_long_t), .align = sizeof(compat_long_t), 2196 - .get = gpr32_get, .set = gpr32_set 2197 - }, 2198 - [REGSET_FPR] = { 2199 - .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, 2200 - .size = sizeof(double), .align = sizeof(double), 2201 - .get = fpr_get, .set = fpr_set 2202 - }, 2203 - #ifdef CONFIG_ALTIVEC 2204 - [REGSET_VMX] = { 2205 - .core_note_type = NT_PPC_VMX, .n = 34, 2206 - .size = sizeof(vector128), .align = sizeof(vector128), 2207 - .active = vr_active, .get = vr_get, .set = vr_set 2208 - }, 2209 - #endif 2210 - #ifdef CONFIG_SPE 2211 - [REGSET_SPE] = { 2212 - .core_note_type = NT_PPC_SPE, .n = 35, 2213 - .size = sizeof(u32), .align = sizeof(u32), 2214 - .active = evr_active, .get = evr_get, .set = evr_set 2215 - }, 2216 - #endif 2217 - #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 2218 - [REGSET_TM_CGPR] = { 2219 - .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG, 2220 - .size = sizeof(long), .align = sizeof(long), 2221 - .active = tm_cgpr_active, 2222 - .get = tm_cgpr32_get, .set = tm_cgpr32_set 2223 - }, 2224 - [REGSET_TM_CFPR] = { 2225 - .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG, 2226 - .size = sizeof(double), .align = sizeof(double), 2227 - .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set 2228 - }, 2229 - [REGSET_TM_CVMX] = { 2230 - .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX, 2231 - .size = sizeof(vector128), .align = sizeof(vector128), 2232 - .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set 2233 - }, 2234 - [REGSET_TM_CVSX] = { 2235 - .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX, 2236 - .size = sizeof(double), .align = sizeof(double), 2237 - .active = tm_cvsx_active, .get = tm_cvsx_get, .set = tm_cvsx_set 2238 - }, 2239 - [REGSET_TM_SPR] = { 2240 - .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG, 2241 - .size = sizeof(u64), .align = sizeof(u64), 2242 - .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set 2243 - }, 2244 - [REGSET_TM_CTAR] = { 2245 - .core_note_type = NT_PPC_TM_CTAR, .n = 1, 2246 - .size = sizeof(u64), .align = sizeof(u64), 2247 - .active = tm_tar_active, .get = tm_tar_get, .set = tm_tar_set 2248 - }, 2249 - [REGSET_TM_CPPR] = { 2250 - .core_note_type = NT_PPC_TM_CPPR, .n = 1, 2251 - .size = sizeof(u64), .align = sizeof(u64), 2252 - .active = tm_ppr_active, .get = tm_ppr_get, .set = tm_ppr_set 2253 - }, 2254 - [REGSET_TM_CDSCR] = { 2255 - .core_note_type = NT_PPC_TM_CDSCR, .n = 1, 2256 - .size = sizeof(u64), .align = sizeof(u64), 2257 - .active = tm_dscr_active, .get = tm_dscr_get, .set = tm_dscr_set 2258 - }, 2259 - #endif 2260 - #ifdef CONFIG_PPC64 2261 - [REGSET_PPR] = { 2262 - .core_note_type = NT_PPC_PPR, .n = 1, 2263 - .size = sizeof(u64), .align = sizeof(u64), 2264 - .get = ppr_get, .set = ppr_set 2265 - }, 2266 - [REGSET_DSCR] = { 2267 - .core_note_type = NT_PPC_DSCR, .n = 1, 2268 - .size = sizeof(u64), .align = sizeof(u64), 2269 - .get = dscr_get, .set = dscr_set 2270 - }, 2271 - #endif 2272 - #ifdef CONFIG_PPC_BOOK3S_64 2273 - [REGSET_TAR] = { 2274 - .core_note_type = NT_PPC_TAR, .n = 1, 2275 - .size = sizeof(u64), .align = sizeof(u64), 2276 - .get = tar_get, .set = tar_set 2277 - }, 2278 - [REGSET_EBB] = { 2279 - .core_note_type = NT_PPC_EBB, .n = ELF_NEBB, 2280 - .size = sizeof(u64), .align = sizeof(u64), 2281 - .active = ebb_active, .get = ebb_get, .set = ebb_set 2282 - }, 2283 - #endif 2284 - }; 2285 - 2286 - static const struct user_regset_view user_ppc_compat_view = { 2287 - .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI, 2288 - .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets) 2289 - }; 2290 - #endif /* CONFIG_PPC64 */ 2291 - 2292 - const struct user_regset_view *task_user_regset_view(struct task_struct *task) 2293 - { 2294 - #ifdef CONFIG_PPC64 2295 - if (test_tsk_thread_flag(task, TIF_32BIT)) 2296 - return &user_ppc_compat_view; 2297 - #endif 2298 - return &user_ppc_native_view; 2299 - } 2300 - 2301 - 2302 - void user_enable_single_step(struct task_struct *task) 2303 - { 2304 - struct pt_regs *regs = task->thread.regs; 2305 - 2306 - if (regs != NULL) { 2307 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 2308 - task->thread.debug.dbcr0 &= ~DBCR0_BT; 2309 - task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; 2310 - regs->msr |= MSR_DE; 2311 - #else 2312 - regs->msr &= ~MSR_BE; 2313 - regs->msr |= MSR_SE; 2314 - #endif 2315 - } 2316 - set_tsk_thread_flag(task, TIF_SINGLESTEP); 2317 - } 2318 - 2319 - void user_enable_block_step(struct task_struct *task) 2320 - { 2321 - struct pt_regs *regs = task->thread.regs; 2322 - 2323 - if (regs != NULL) { 2324 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 2325 - task->thread.debug.dbcr0 &= ~DBCR0_IC; 2326 - task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT; 2327 - regs->msr |= MSR_DE; 2328 - #else 2329 - regs->msr &= ~MSR_SE; 2330 - regs->msr |= MSR_BE; 2331 - #endif 2332 - } 2333 - set_tsk_thread_flag(task, TIF_SINGLESTEP); 2334 - } 2335 - 2336 - void user_disable_single_step(struct task_struct *task) 2337 - { 2338 - struct pt_regs *regs = task->thread.regs; 2339 - 2340 - if (regs != NULL) { 2341 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 2342 - /* 2343 - * The logic to disable single stepping should be as 2344 - * simple as turning off the Instruction Complete flag. 2345 - * And, after doing so, if all debug flags are off, turn 2346 - * off DBCR0(IDM) and MSR(DE) .... Torez 2347 - */ 2348 - task->thread.debug.dbcr0 &= ~(DBCR0_IC|DBCR0_BT); 2349 - /* 2350 - * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set. 2351 - */ 2352 - if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, 2353 - task->thread.debug.dbcr1)) { 2354 - /* 2355 - * All debug events were off..... 2356 - */ 2357 - task->thread.debug.dbcr0 &= ~DBCR0_IDM; 2358 - regs->msr &= ~MSR_DE; 2359 - } 2360 - #else 2361 - regs->msr &= ~(MSR_SE | MSR_BE); 2362 - #endif 2363 - } 2364 - clear_tsk_thread_flag(task, TIF_SINGLESTEP); 2365 - } 2366 - 2367 - #ifdef CONFIG_HAVE_HW_BREAKPOINT 2368 - void ptrace_triggered(struct perf_event *bp, 2369 - struct perf_sample_data *data, struct pt_regs *regs) 2370 - { 2371 - struct perf_event_attr attr; 2372 - 2373 - /* 2374 - * Disable the breakpoint request here since ptrace has defined a 2375 - * one-shot behaviour for breakpoint exceptions in PPC64. 2376 - * The SIGTRAP signal is generated automatically for us in do_dabr(). 2377 - * We don't have to do anything about that here 2378 - */ 2379 - attr = bp->attr; 2380 - attr.disabled = true; 2381 - modify_user_hw_breakpoint(bp, &attr); 2382 - } 2383 - #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 2384 - 2385 - static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, 2386 - unsigned long data) 2387 - { 2388 - #ifdef CONFIG_HAVE_HW_BREAKPOINT 2389 - int ret; 2390 - struct thread_struct *thread = &(task->thread); 2391 - struct perf_event *bp; 2392 - struct perf_event_attr attr; 2393 - #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 2394 - #ifndef CONFIG_PPC_ADV_DEBUG_REGS 2395 - bool set_bp = true; 2396 - struct arch_hw_breakpoint hw_brk; 2397 - #endif 2398 - 2399 - /* For ppc64 we support one DABR and no IABR's at the moment (ppc64). 2400 - * For embedded processors we support one DAC and no IAC's at the 2401 - * moment. 2402 - */ 2403 - if (addr > 0) 2404 - return -EINVAL; 2405 - 2406 - /* The bottom 3 bits in dabr are flags */ 2407 - if ((data & ~0x7UL) >= TASK_SIZE) 2408 - return -EIO; 2409 - 2410 - #ifndef CONFIG_PPC_ADV_DEBUG_REGS 2411 - /* For processors using DABR (i.e. 970), the bottom 3 bits are flags. 2412 - * It was assumed, on previous implementations, that 3 bits were 2413 - * passed together with the data address, fitting the design of the 2414 - * DABR register, as follows: 2415 - * 2416 - * bit 0: Read flag 2417 - * bit 1: Write flag 2418 - * bit 2: Breakpoint translation 2419 - * 2420 - * Thus, we use them here as so. 2421 - */ 2422 - 2423 - /* Ensure breakpoint translation bit is set */ 2424 - if (data && !(data & HW_BRK_TYPE_TRANSLATE)) 2425 - return -EIO; 2426 - hw_brk.address = data & (~HW_BRK_TYPE_DABR); 2427 - hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL; 2428 - hw_brk.len = DABR_MAX_LEN; 2429 - hw_brk.hw_len = DABR_MAX_LEN; 2430 - set_bp = (data) && (hw_brk.type & HW_BRK_TYPE_RDWR); 2431 - #ifdef CONFIG_HAVE_HW_BREAKPOINT 2432 - bp = thread->ptrace_bps[0]; 2433 - if (!set_bp) { 2434 - if (bp) { 2435 - unregister_hw_breakpoint(bp); 2436 - thread->ptrace_bps[0] = NULL; 2437 - } 2438 - return 0; 2439 - } 2440 - if (bp) { 2441 - attr = bp->attr; 2442 - attr.bp_addr = hw_brk.address; 2443 - attr.bp_len = DABR_MAX_LEN; 2444 - arch_bp_generic_fields(hw_brk.type, &attr.bp_type); 2445 - 2446 - /* Enable breakpoint */ 2447 - attr.disabled = false; 2448 - 2449 - ret = modify_user_hw_breakpoint(bp, &attr); 2450 - if (ret) { 2451 - return ret; 2452 - } 2453 - thread->ptrace_bps[0] = bp; 2454 - thread->hw_brk = hw_brk; 2455 - return 0; 2456 - } 2457 - 2458 - /* Create a new breakpoint request if one doesn't exist already */ 2459 - hw_breakpoint_init(&attr); 2460 - attr.bp_addr = hw_brk.address; 2461 - attr.bp_len = DABR_MAX_LEN; 2462 - arch_bp_generic_fields(hw_brk.type, 2463 - &attr.bp_type); 2464 - 2465 - thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, 2466 - ptrace_triggered, NULL, task); 2467 - if (IS_ERR(bp)) { 2468 - thread->ptrace_bps[0] = NULL; 2469 - return PTR_ERR(bp); 2470 - } 2471 - 2472 - #else /* !CONFIG_HAVE_HW_BREAKPOINT */ 2473 - if (set_bp && (!ppc_breakpoint_available())) 2474 - return -ENODEV; 2475 - #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 2476 - task->thread.hw_brk = hw_brk; 2477 - #else /* CONFIG_PPC_ADV_DEBUG_REGS */ 2478 - /* As described above, it was assumed 3 bits were passed with the data 2479 - * address, but we will assume only the mode bits will be passed 2480 - * as to not cause alignment restrictions for DAC-based processors. 2481 - */ 2482 - 2483 - /* DAC's hold the whole address without any mode flags */ 2484 - task->thread.debug.dac1 = data & ~0x3UL; 2485 - 2486 - if (task->thread.debug.dac1 == 0) { 2487 - dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W); 2488 - if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, 2489 - task->thread.debug.dbcr1)) { 2490 - task->thread.regs->msr &= ~MSR_DE; 2491 - task->thread.debug.dbcr0 &= ~DBCR0_IDM; 2492 - } 2493 - return 0; 2494 - } 2495 - 2496 - /* Read or Write bits must be set */ 2497 - 2498 - if (!(data & 0x3UL)) 2499 - return -EINVAL; 2500 - 2501 - /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0 2502 - register */ 2503 - task->thread.debug.dbcr0 |= DBCR0_IDM; 2504 - 2505 - /* Check for write and read flags and set DBCR0 2506 - accordingly */ 2507 - dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W); 2508 - if (data & 0x1UL) 2509 - dbcr_dac(task) |= DBCR_DAC1R; 2510 - if (data & 0x2UL) 2511 - dbcr_dac(task) |= DBCR_DAC1W; 2512 - task->thread.regs->msr |= MSR_DE; 2513 - #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 2514 - return 0; 2515 - } 2516 - 2517 - /* 2518 - * Called by kernel/ptrace.c when detaching.. 2519 - * 2520 - * Make sure single step bits etc are not set. 2521 - */ 2522 - void ptrace_disable(struct task_struct *child) 2523 - { 2524 - /* make sure the single step bit is not set. */ 2525 - user_disable_single_step(child); 2526 - } 2527 - 2528 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 2529 - static long set_instruction_bp(struct task_struct *child, 2530 - struct ppc_hw_breakpoint *bp_info) 2531 - { 2532 - int slot; 2533 - int slot1_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC1) != 0); 2534 - int slot2_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC2) != 0); 2535 - int slot3_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC3) != 0); 2536 - int slot4_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC4) != 0); 2537 - 2538 - if (dbcr_iac_range(child) & DBCR_IAC12MODE) 2539 - slot2_in_use = 1; 2540 - if (dbcr_iac_range(child) & DBCR_IAC34MODE) 2541 - slot4_in_use = 1; 2542 - 2543 - if (bp_info->addr >= TASK_SIZE) 2544 - return -EIO; 2545 - 2546 - if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) { 2547 - 2548 - /* Make sure range is valid. */ 2549 - if (bp_info->addr2 >= TASK_SIZE) 2550 - return -EIO; 2551 - 2552 - /* We need a pair of IAC regsisters */ 2553 - if ((!slot1_in_use) && (!slot2_in_use)) { 2554 - slot = 1; 2555 - child->thread.debug.iac1 = bp_info->addr; 2556 - child->thread.debug.iac2 = bp_info->addr2; 2557 - child->thread.debug.dbcr0 |= DBCR0_IAC1; 2558 - if (bp_info->addr_mode == 2559 - PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) 2560 - dbcr_iac_range(child) |= DBCR_IAC12X; 2561 - else 2562 - dbcr_iac_range(child) |= DBCR_IAC12I; 2563 - #if CONFIG_PPC_ADV_DEBUG_IACS > 2 2564 - } else if ((!slot3_in_use) && (!slot4_in_use)) { 2565 - slot = 3; 2566 - child->thread.debug.iac3 = bp_info->addr; 2567 - child->thread.debug.iac4 = bp_info->addr2; 2568 - child->thread.debug.dbcr0 |= DBCR0_IAC3; 2569 - if (bp_info->addr_mode == 2570 - PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) 2571 - dbcr_iac_range(child) |= DBCR_IAC34X; 2572 - else 2573 - dbcr_iac_range(child) |= DBCR_IAC34I; 2574 - #endif 2575 - } else 2576 - return -ENOSPC; 2577 - } else { 2578 - /* We only need one. If possible leave a pair free in 2579 - * case a range is needed later 2580 - */ 2581 - if (!slot1_in_use) { 2582 - /* 2583 - * Don't use iac1 if iac1-iac2 are free and either 2584 - * iac3 or iac4 (but not both) are free 2585 - */ 2586 - if (slot2_in_use || (slot3_in_use == slot4_in_use)) { 2587 - slot = 1; 2588 - child->thread.debug.iac1 = bp_info->addr; 2589 - child->thread.debug.dbcr0 |= DBCR0_IAC1; 2590 - goto out; 2591 - } 2592 - } 2593 - if (!slot2_in_use) { 2594 - slot = 2; 2595 - child->thread.debug.iac2 = bp_info->addr; 2596 - child->thread.debug.dbcr0 |= DBCR0_IAC2; 2597 - #if CONFIG_PPC_ADV_DEBUG_IACS > 2 2598 - } else if (!slot3_in_use) { 2599 - slot = 3; 2600 - child->thread.debug.iac3 = bp_info->addr; 2601 - child->thread.debug.dbcr0 |= DBCR0_IAC3; 2602 - } else if (!slot4_in_use) { 2603 - slot = 4; 2604 - child->thread.debug.iac4 = bp_info->addr; 2605 - child->thread.debug.dbcr0 |= DBCR0_IAC4; 2606 - #endif 2607 - } else 2608 - return -ENOSPC; 2609 - } 2610 - out: 2611 - child->thread.debug.dbcr0 |= DBCR0_IDM; 2612 - child->thread.regs->msr |= MSR_DE; 2613 - 2614 - return slot; 2615 - } 2616 - 2617 - static int del_instruction_bp(struct task_struct *child, int slot) 2618 - { 2619 - switch (slot) { 2620 - case 1: 2621 - if ((child->thread.debug.dbcr0 & DBCR0_IAC1) == 0) 2622 - return -ENOENT; 2623 - 2624 - if (dbcr_iac_range(child) & DBCR_IAC12MODE) { 2625 - /* address range - clear slots 1 & 2 */ 2626 - child->thread.debug.iac2 = 0; 2627 - dbcr_iac_range(child) &= ~DBCR_IAC12MODE; 2628 - } 2629 - child->thread.debug.iac1 = 0; 2630 - child->thread.debug.dbcr0 &= ~DBCR0_IAC1; 2631 - break; 2632 - case 2: 2633 - if ((child->thread.debug.dbcr0 & DBCR0_IAC2) == 0) 2634 - return -ENOENT; 2635 - 2636 - if (dbcr_iac_range(child) & DBCR_IAC12MODE) 2637 - /* used in a range */ 2638 - return -EINVAL; 2639 - child->thread.debug.iac2 = 0; 2640 - child->thread.debug.dbcr0 &= ~DBCR0_IAC2; 2641 - break; 2642 - #if CONFIG_PPC_ADV_DEBUG_IACS > 2 2643 - case 3: 2644 - if ((child->thread.debug.dbcr0 & DBCR0_IAC3) == 0) 2645 - return -ENOENT; 2646 - 2647 - if (dbcr_iac_range(child) & DBCR_IAC34MODE) { 2648 - /* address range - clear slots 3 & 4 */ 2649 - child->thread.debug.iac4 = 0; 2650 - dbcr_iac_range(child) &= ~DBCR_IAC34MODE; 2651 - } 2652 - child->thread.debug.iac3 = 0; 2653 - child->thread.debug.dbcr0 &= ~DBCR0_IAC3; 2654 - break; 2655 - case 4: 2656 - if ((child->thread.debug.dbcr0 & DBCR0_IAC4) == 0) 2657 - return -ENOENT; 2658 - 2659 - if (dbcr_iac_range(child) & DBCR_IAC34MODE) 2660 - /* Used in a range */ 2661 - return -EINVAL; 2662 - child->thread.debug.iac4 = 0; 2663 - child->thread.debug.dbcr0 &= ~DBCR0_IAC4; 2664 - break; 2665 - #endif 2666 - default: 2667 - return -EINVAL; 2668 - } 2669 - return 0; 2670 - } 2671 - 2672 - static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) 2673 - { 2674 - int byte_enable = 2675 - (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT) 2676 - & 0xf; 2677 - int condition_mode = 2678 - bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE; 2679 - int slot; 2680 - 2681 - if (byte_enable && (condition_mode == 0)) 2682 - return -EINVAL; 2683 - 2684 - if (bp_info->addr >= TASK_SIZE) 2685 - return -EIO; 2686 - 2687 - if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) { 2688 - slot = 1; 2689 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) 2690 - dbcr_dac(child) |= DBCR_DAC1R; 2691 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 2692 - dbcr_dac(child) |= DBCR_DAC1W; 2693 - child->thread.debug.dac1 = (unsigned long)bp_info->addr; 2694 - #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 2695 - if (byte_enable) { 2696 - child->thread.debug.dvc1 = 2697 - (unsigned long)bp_info->condition_value; 2698 - child->thread.debug.dbcr2 |= 2699 - ((byte_enable << DBCR2_DVC1BE_SHIFT) | 2700 - (condition_mode << DBCR2_DVC1M_SHIFT)); 2701 - } 2702 - #endif 2703 - #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 2704 - } else if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) { 2705 - /* Both dac1 and dac2 are part of a range */ 2706 - return -ENOSPC; 2707 - #endif 2708 - } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) { 2709 - slot = 2; 2710 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) 2711 - dbcr_dac(child) |= DBCR_DAC2R; 2712 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 2713 - dbcr_dac(child) |= DBCR_DAC2W; 2714 - child->thread.debug.dac2 = (unsigned long)bp_info->addr; 2715 - #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 2716 - if (byte_enable) { 2717 - child->thread.debug.dvc2 = 2718 - (unsigned long)bp_info->condition_value; 2719 - child->thread.debug.dbcr2 |= 2720 - ((byte_enable << DBCR2_DVC2BE_SHIFT) | 2721 - (condition_mode << DBCR2_DVC2M_SHIFT)); 2722 - } 2723 - #endif 2724 - } else 2725 - return -ENOSPC; 2726 - child->thread.debug.dbcr0 |= DBCR0_IDM; 2727 - child->thread.regs->msr |= MSR_DE; 2728 - 2729 - return slot + 4; 2730 - } 2731 - 2732 - static int del_dac(struct task_struct *child, int slot) 2733 - { 2734 - if (slot == 1) { 2735 - if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) 2736 - return -ENOENT; 2737 - 2738 - child->thread.debug.dac1 = 0; 2739 - dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W); 2740 - #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 2741 - if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) { 2742 - child->thread.debug.dac2 = 0; 2743 - child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; 2744 - } 2745 - child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE); 2746 - #endif 2747 - #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 2748 - child->thread.debug.dvc1 = 0; 2749 - #endif 2750 - } else if (slot == 2) { 2751 - if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) 2752 - return -ENOENT; 2753 - 2754 - #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 2755 - if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) 2756 - /* Part of a range */ 2757 - return -EINVAL; 2758 - child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE); 2759 - #endif 2760 - #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 2761 - child->thread.debug.dvc2 = 0; 2762 - #endif 2763 - child->thread.debug.dac2 = 0; 2764 - dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W); 2765 - } else 2766 - return -EINVAL; 2767 - 2768 - return 0; 2769 - } 2770 - #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 2771 - 2772 - #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 2773 - static int set_dac_range(struct task_struct *child, 2774 - struct ppc_hw_breakpoint *bp_info) 2775 - { 2776 - int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK; 2777 - 2778 - /* We don't allow range watchpoints to be used with DVC */ 2779 - if (bp_info->condition_mode) 2780 - return -EINVAL; 2781 - 2782 - /* 2783 - * Best effort to verify the address range. The user/supervisor bits 2784 - * prevent trapping in kernel space, but let's fail on an obvious bad 2785 - * range. The simple test on the mask is not fool-proof, and any 2786 - * exclusive range will spill over into kernel space. 2787 - */ 2788 - if (bp_info->addr >= TASK_SIZE) 2789 - return -EIO; 2790 - if (mode == PPC_BREAKPOINT_MODE_MASK) { 2791 - /* 2792 - * dac2 is a bitmask. Don't allow a mask that makes a 2793 - * kernel space address from a valid dac1 value 2794 - */ 2795 - if (~((unsigned long)bp_info->addr2) >= TASK_SIZE) 2796 - return -EIO; 2797 - } else { 2798 - /* 2799 - * For range breakpoints, addr2 must also be a valid address 2800 - */ 2801 - if (bp_info->addr2 >= TASK_SIZE) 2802 - return -EIO; 2803 - } 2804 - 2805 - if (child->thread.debug.dbcr0 & 2806 - (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W)) 2807 - return -ENOSPC; 2808 - 2809 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) 2810 - child->thread.debug.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM); 2811 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 2812 - child->thread.debug.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM); 2813 - child->thread.debug.dac1 = bp_info->addr; 2814 - child->thread.debug.dac2 = bp_info->addr2; 2815 - if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) 2816 - child->thread.debug.dbcr2 |= DBCR2_DAC12M; 2817 - else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) 2818 - child->thread.debug.dbcr2 |= DBCR2_DAC12MX; 2819 - else /* PPC_BREAKPOINT_MODE_MASK */ 2820 - child->thread.debug.dbcr2 |= DBCR2_DAC12MM; 2821 - child->thread.regs->msr |= MSR_DE; 2822 - 2823 - return 5; 2824 - } 2825 - #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */ 2826 - 2827 - static long ppc_set_hwdebug(struct task_struct *child, 2828 - struct ppc_hw_breakpoint *bp_info) 2829 - { 2830 - #ifdef CONFIG_HAVE_HW_BREAKPOINT 2831 - int len = 0; 2832 - struct thread_struct *thread = &(child->thread); 2833 - struct perf_event *bp; 2834 - struct perf_event_attr attr; 2835 - #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 2836 - #ifndef CONFIG_PPC_ADV_DEBUG_REGS 2837 - struct arch_hw_breakpoint brk; 2838 - #endif 2839 - 2840 - if (bp_info->version != 1) 2841 - return -ENOTSUPP; 2842 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 2843 - /* 2844 - * Check for invalid flags and combinations 2845 - */ 2846 - if ((bp_info->trigger_type == 0) || 2847 - (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE | 2848 - PPC_BREAKPOINT_TRIGGER_RW)) || 2849 - (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) || 2850 - (bp_info->condition_mode & 2851 - ~(PPC_BREAKPOINT_CONDITION_MODE | 2852 - PPC_BREAKPOINT_CONDITION_BE_ALL))) 2853 - return -EINVAL; 2854 - #if CONFIG_PPC_ADV_DEBUG_DVCS == 0 2855 - if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) 2856 - return -EINVAL; 2857 - #endif 2858 - 2859 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) { 2860 - if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) || 2861 - (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)) 2862 - return -EINVAL; 2863 - return set_instruction_bp(child, bp_info); 2864 - } 2865 - if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) 2866 - return set_dac(child, bp_info); 2867 - 2868 - #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 2869 - return set_dac_range(child, bp_info); 2870 - #else 2871 - return -EINVAL; 2872 - #endif 2873 - #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */ 2874 - /* 2875 - * We only support one data breakpoint 2876 - */ 2877 - if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 || 2878 - (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 || 2879 - bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) 2880 - return -EINVAL; 2881 - 2882 - if ((unsigned long)bp_info->addr >= TASK_SIZE) 2883 - return -EIO; 2884 - 2885 - brk.address = bp_info->addr & ~HW_BREAKPOINT_ALIGN; 2886 - brk.type = HW_BRK_TYPE_TRANSLATE; 2887 - brk.len = DABR_MAX_LEN; 2888 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) 2889 - brk.type |= HW_BRK_TYPE_READ; 2890 - if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 2891 - brk.type |= HW_BRK_TYPE_WRITE; 2892 - #ifdef CONFIG_HAVE_HW_BREAKPOINT 2893 - if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) 2894 - len = bp_info->addr2 - bp_info->addr; 2895 - else if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) 2896 - len = 1; 2897 - else 2898 - return -EINVAL; 2899 - bp = thread->ptrace_bps[0]; 2900 - if (bp) 2901 - return -ENOSPC; 2902 - 2903 - /* Create a new breakpoint request if one doesn't exist already */ 2904 - hw_breakpoint_init(&attr); 2905 - attr.bp_addr = (unsigned long)bp_info->addr; 2906 - attr.bp_len = len; 2907 - arch_bp_generic_fields(brk.type, &attr.bp_type); 2908 - 2909 - thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, 2910 - ptrace_triggered, NULL, child); 2911 - if (IS_ERR(bp)) { 2912 - thread->ptrace_bps[0] = NULL; 2913 - return PTR_ERR(bp); 2914 - } 2915 - 2916 - return 1; 2917 - #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 2918 - 2919 - if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) 2920 - return -EINVAL; 2921 - 2922 - if (child->thread.hw_brk.address) 2923 - return -ENOSPC; 2924 - 2925 - if (!ppc_breakpoint_available()) 2926 - return -ENODEV; 2927 - 2928 - child->thread.hw_brk = brk; 2929 - 2930 - return 1; 2931 - #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */ 2932 - } 2933 - 2934 - static long ppc_del_hwdebug(struct task_struct *child, long data) 2935 - { 2936 - #ifdef CONFIG_HAVE_HW_BREAKPOINT 2937 - int ret = 0; 2938 - struct thread_struct *thread = &(child->thread); 2939 - struct perf_event *bp; 2940 - #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 2941 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 2942 - int rc; 2943 - 2944 - if (data <= 4) 2945 - rc = del_instruction_bp(child, (int)data); 2946 - else 2947 - rc = del_dac(child, (int)data - 4); 2948 - 2949 - if (!rc) { 2950 - if (!DBCR_ACTIVE_EVENTS(child->thread.debug.dbcr0, 2951 - child->thread.debug.dbcr1)) { 2952 - child->thread.debug.dbcr0 &= ~DBCR0_IDM; 2953 - child->thread.regs->msr &= ~MSR_DE; 2954 - } 2955 - } 2956 - return rc; 2957 - #else 2958 - if (data != 1) 2959 - return -EINVAL; 2960 - 2961 - #ifdef CONFIG_HAVE_HW_BREAKPOINT 2962 - bp = thread->ptrace_bps[0]; 2963 - if (bp) { 2964 - unregister_hw_breakpoint(bp); 2965 - thread->ptrace_bps[0] = NULL; 2966 - } else 2967 - ret = -ENOENT; 2968 - return ret; 2969 - #else /* CONFIG_HAVE_HW_BREAKPOINT */ 2970 - if (child->thread.hw_brk.address == 0) 2971 - return -ENOENT; 2972 - 2973 - child->thread.hw_brk.address = 0; 2974 - child->thread.hw_brk.type = 0; 2975 - #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 2976 - 2977 - return 0; 2978 - #endif 2979 - } 2980 - 2981 - long arch_ptrace(struct task_struct *child, long request, 2982 - unsigned long addr, unsigned long data) 2983 - { 2984 - int ret = -EPERM; 2985 - void __user *datavp = (void __user *) data; 2986 - unsigned long __user *datalp = datavp; 2987 - 2988 - switch (request) { 2989 - /* read the word at location addr in the USER area. */ 2990 - case PTRACE_PEEKUSR: { 2991 - unsigned long index, tmp; 2992 - 2993 - ret = -EIO; 2994 - /* convert to index and check */ 2995 - #ifdef CONFIG_PPC32 2996 - index = addr >> 2; 2997 - if ((addr & 3) || (index > PT_FPSCR) 2998 - || (child->thread.regs == NULL)) 2999 - #else 3000 - index = addr >> 3; 3001 - if ((addr & 7) || (index > PT_FPSCR)) 3002 - #endif 3003 - break; 3004 - 3005 - CHECK_FULL_REGS(child->thread.regs); 3006 - if (index < PT_FPR0) { 3007 - ret = ptrace_get_reg(child, (int) index, &tmp); 3008 - if (ret) 3009 - break; 3010 - } else { 3011 - unsigned int fpidx = index - PT_FPR0; 3012 - 3013 - flush_fp_to_thread(child); 3014 - if (fpidx < (PT_FPSCR - PT_FPR0)) 3015 - memcpy(&tmp, &child->thread.TS_FPR(fpidx), 3016 - sizeof(long)); 3017 - else 3018 - tmp = child->thread.fp_state.fpscr; 3019 - } 3020 - ret = put_user(tmp, datalp); 3021 - break; 3022 - } 3023 - 3024 - /* write the word at location addr in the USER area */ 3025 - case PTRACE_POKEUSR: { 3026 - unsigned long index; 3027 - 3028 - ret = -EIO; 3029 - /* convert to index and check */ 3030 - #ifdef CONFIG_PPC32 3031 - index = addr >> 2; 3032 - if ((addr & 3) || (index > PT_FPSCR) 3033 - || (child->thread.regs == NULL)) 3034 - #else 3035 - index = addr >> 3; 3036 - if ((addr & 7) || (index > PT_FPSCR)) 3037 - #endif 3038 - break; 3039 - 3040 - CHECK_FULL_REGS(child->thread.regs); 3041 - if (index < PT_FPR0) { 3042 - ret = ptrace_put_reg(child, index, data); 3043 - } else { 3044 - unsigned int fpidx = index - PT_FPR0; 3045 - 3046 - flush_fp_to_thread(child); 3047 - if (fpidx < (PT_FPSCR - PT_FPR0)) 3048 - memcpy(&child->thread.TS_FPR(fpidx), &data, 3049 - sizeof(long)); 3050 - else 3051 - child->thread.fp_state.fpscr = data; 3052 - ret = 0; 3053 - } 3054 - break; 3055 - } 3056 - 3057 - case PPC_PTRACE_GETHWDBGINFO: { 3058 - struct ppc_debug_info dbginfo; 3059 - 3060 - dbginfo.version = 1; 3061 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 3062 - dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS; 3063 - dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS; 3064 - dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS; 3065 - dbginfo.data_bp_alignment = 4; 3066 - dbginfo.sizeof_condition = 4; 3067 - dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE | 3068 - PPC_DEBUG_FEATURE_INSN_BP_MASK; 3069 - #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 3070 - dbginfo.features |= 3071 - PPC_DEBUG_FEATURE_DATA_BP_RANGE | 3072 - PPC_DEBUG_FEATURE_DATA_BP_MASK; 3073 - #endif 3074 - #else /* !CONFIG_PPC_ADV_DEBUG_REGS */ 3075 - dbginfo.num_instruction_bps = 0; 3076 - if (ppc_breakpoint_available()) 3077 - dbginfo.num_data_bps = 1; 3078 - else 3079 - dbginfo.num_data_bps = 0; 3080 - dbginfo.num_condition_regs = 0; 3081 - #ifdef CONFIG_PPC64 3082 - dbginfo.data_bp_alignment = 8; 3083 - #else 3084 - dbginfo.data_bp_alignment = 4; 3085 - #endif 3086 - dbginfo.sizeof_condition = 0; 3087 - #ifdef CONFIG_HAVE_HW_BREAKPOINT 3088 - dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE; 3089 - if (dawr_enabled()) 3090 - dbginfo.features |= PPC_DEBUG_FEATURE_DATA_BP_DAWR; 3091 - #else 3092 - dbginfo.features = 0; 3093 - #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 3094 - #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 3095 - 3096 - if (copy_to_user(datavp, &dbginfo, 3097 - sizeof(struct ppc_debug_info))) 3098 - return -EFAULT; 3099 - return 0; 3100 - } 3101 - 3102 - case PPC_PTRACE_SETHWDEBUG: { 3103 - struct ppc_hw_breakpoint bp_info; 3104 - 3105 - if (copy_from_user(&bp_info, datavp, 3106 - sizeof(struct ppc_hw_breakpoint))) 3107 - return -EFAULT; 3108 - return ppc_set_hwdebug(child, &bp_info); 3109 - } 3110 - 3111 - case PPC_PTRACE_DELHWDEBUG: { 3112 - ret = ppc_del_hwdebug(child, data); 3113 - break; 3114 - } 3115 - 3116 - case PTRACE_GET_DEBUGREG: { 3117 - #ifndef CONFIG_PPC_ADV_DEBUG_REGS 3118 - unsigned long dabr_fake; 3119 - #endif 3120 - ret = -EINVAL; 3121 - /* We only support one DABR and no IABRS at the moment */ 3122 - if (addr > 0) 3123 - break; 3124 - #ifdef CONFIG_PPC_ADV_DEBUG_REGS 3125 - ret = put_user(child->thread.debug.dac1, datalp); 3126 - #else 3127 - dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) | 3128 - (child->thread.hw_brk.type & HW_BRK_TYPE_DABR)); 3129 - ret = put_user(dabr_fake, datalp); 3130 - #endif 3131 - break; 3132 - } 3133 - 3134 - case PTRACE_SET_DEBUGREG: 3135 - ret = ptrace_set_debugreg(child, addr, data); 3136 - break; 3137 - 3138 - #ifdef CONFIG_PPC64 3139 - case PTRACE_GETREGS64: 3140 - #endif 3141 - case PTRACE_GETREGS: /* Get all pt_regs from the child. */ 3142 - return copy_regset_to_user(child, &user_ppc_native_view, 3143 - REGSET_GPR, 3144 - 0, sizeof(struct user_pt_regs), 3145 - datavp); 3146 - 3147 - #ifdef CONFIG_PPC64 3148 - case PTRACE_SETREGS64: 3149 - #endif 3150 - case PTRACE_SETREGS: /* Set all gp regs in the child. */ 3151 - return copy_regset_from_user(child, &user_ppc_native_view, 3152 - REGSET_GPR, 3153 - 0, sizeof(struct user_pt_regs), 3154 - datavp); 3155 - 3156 - case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */ 3157 - return copy_regset_to_user(child, &user_ppc_native_view, 3158 - REGSET_FPR, 3159 - 0, sizeof(elf_fpregset_t), 3160 - datavp); 3161 - 3162 - case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */ 3163 - return copy_regset_from_user(child, &user_ppc_native_view, 3164 - REGSET_FPR, 3165 - 0, sizeof(elf_fpregset_t), 3166 - datavp); 3167 - 3168 - #ifdef CONFIG_ALTIVEC 3169 - case PTRACE_GETVRREGS: 3170 - return copy_regset_to_user(child, &user_ppc_native_view, 3171 - REGSET_VMX, 3172 - 0, (33 * sizeof(vector128) + 3173 - sizeof(u32)), 3174 - datavp); 3175 - 3176 - case PTRACE_SETVRREGS: 3177 - return copy_regset_from_user(child, &user_ppc_native_view, 3178 - REGSET_VMX, 3179 - 0, (33 * sizeof(vector128) + 3180 - sizeof(u32)), 3181 - datavp); 3182 - #endif 3183 - #ifdef CONFIG_VSX 3184 - case PTRACE_GETVSRREGS: 3185 - return copy_regset_to_user(child, &user_ppc_native_view, 3186 - REGSET_VSX, 3187 - 0, 32 * sizeof(double), 3188 - datavp); 3189 - 3190 - case PTRACE_SETVSRREGS: 3191 - return copy_regset_from_user(child, &user_ppc_native_view, 3192 - REGSET_VSX, 3193 - 0, 32 * sizeof(double), 3194 - datavp); 3195 - #endif 3196 - #ifdef CONFIG_SPE 3197 - case PTRACE_GETEVRREGS: 3198 - /* Get the child spe register state. */ 3199 - return copy_regset_to_user(child, &user_ppc_native_view, 3200 - REGSET_SPE, 0, 35 * sizeof(u32), 3201 - datavp); 3202 - 3203 - case PTRACE_SETEVRREGS: 3204 - /* Set the child spe register state. */ 3205 - return copy_regset_from_user(child, &user_ppc_native_view, 3206 - REGSET_SPE, 0, 35 * sizeof(u32), 3207 - datavp); 3208 - #endif 3209 - 3210 - default: 3211 - ret = ptrace_request(child, request, addr, data); 3212 - break; 3213 - } 3214 - return ret; 3215 - } 3216 - 3217 - #ifdef CONFIG_SECCOMP 3218 - static int do_seccomp(struct pt_regs *regs) 3219 - { 3220 - if (!test_thread_flag(TIF_SECCOMP)) 3221 - return 0; 3222 - 3223 - /* 3224 - * The ABI we present to seccomp tracers is that r3 contains 3225 - * the syscall return value and orig_gpr3 contains the first 3226 - * syscall parameter. This is different to the ptrace ABI where 3227 - * both r3 and orig_gpr3 contain the first syscall parameter. 3228 - */ 3229 - regs->gpr[3] = -ENOSYS; 3230 - 3231 - /* 3232 - * We use the __ version here because we have already checked 3233 - * TIF_SECCOMP. If this fails, there is nothing left to do, we 3234 - * have already loaded -ENOSYS into r3, or seccomp has put 3235 - * something else in r3 (via SECCOMP_RET_ERRNO/TRACE). 3236 - */ 3237 - if (__secure_computing(NULL)) 3238 - return -1; 3239 - 3240 - /* 3241 - * The syscall was allowed by seccomp, restore the register 3242 - * state to what audit expects. 3243 - * Note that we use orig_gpr3, which means a seccomp tracer can 3244 - * modify the first syscall parameter (in orig_gpr3) and also 3245 - * allow the syscall to proceed. 3246 - */ 3247 - regs->gpr[3] = regs->orig_gpr3; 3248 - 3249 - return 0; 3250 - } 3251 - #else 3252 - static inline int do_seccomp(struct pt_regs *regs) { return 0; } 3253 - #endif /* CONFIG_SECCOMP */ 3254 - 3255 - /** 3256 - * do_syscall_trace_enter() - Do syscall tracing on kernel entry. 3257 - * @regs: the pt_regs of the task to trace (current) 3258 - * 3259 - * Performs various types of tracing on syscall entry. This includes seccomp, 3260 - * ptrace, syscall tracepoints and audit. 3261 - * 3262 - * The pt_regs are potentially visible to userspace via ptrace, so their 3263 - * contents is ABI. 3264 - * 3265 - * One or more of the tracers may modify the contents of pt_regs, in particular 3266 - * to modify arguments or even the syscall number itself. 3267 - * 3268 - * It's also possible that a tracer can choose to reject the system call. In 3269 - * that case this function will return an illegal syscall number, and will put 3270 - * an appropriate return value in regs->r3. 3271 - * 3272 - * Return: the (possibly changed) syscall number. 3273 - */ 3274 - long do_syscall_trace_enter(struct pt_regs *regs) 3275 - { 3276 - u32 flags; 3277 - 3278 - user_exit(); 3279 - 3280 - flags = READ_ONCE(current_thread_info()->flags) & 3281 - (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE); 3282 - 3283 - if (flags) { 3284 - int rc = tracehook_report_syscall_entry(regs); 3285 - 3286 - if (unlikely(flags & _TIF_SYSCALL_EMU)) { 3287 - /* 3288 - * A nonzero return code from 3289 - * tracehook_report_syscall_entry() tells us to prevent 3290 - * the syscall execution, but we are not going to 3291 - * execute it anyway. 3292 - * 3293 - * Returning -1 will skip the syscall execution. We want 3294 - * to avoid clobbering any registers, so we don't goto 3295 - * the skip label below. 3296 - */ 3297 - return -1; 3298 - } 3299 - 3300 - if (rc) { 3301 - /* 3302 - * The tracer decided to abort the syscall. Note that 3303 - * the tracer may also just change regs->gpr[0] to an 3304 - * invalid syscall number, that is handled below on the 3305 - * exit path. 3306 - */ 3307 - goto skip; 3308 - } 3309 - } 3310 - 3311 - /* Run seccomp after ptrace; allow it to set gpr[3]. */ 3312 - if (do_seccomp(regs)) 3313 - return -1; 3314 - 3315 - /* Avoid trace and audit when syscall is invalid. */ 3316 - if (regs->gpr[0] >= NR_syscalls) 3317 - goto skip; 3318 - 3319 - if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) 3320 - trace_sys_enter(regs, regs->gpr[0]); 3321 - 3322 - #ifdef CONFIG_PPC64 3323 - if (!is_32bit_task()) 3324 - audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4], 3325 - regs->gpr[5], regs->gpr[6]); 3326 - else 3327 - #endif 3328 - audit_syscall_entry(regs->gpr[0], 3329 - regs->gpr[3] & 0xffffffff, 3330 - regs->gpr[4] & 0xffffffff, 3331 - regs->gpr[5] & 0xffffffff, 3332 - regs->gpr[6] & 0xffffffff); 3333 - 3334 - /* Return the possibly modified but valid syscall number */ 3335 - return regs->gpr[0]; 3336 - 3337 - skip: 3338 - /* 3339 - * If we are aborting explicitly, or if the syscall number is 3340 - * now invalid, set the return value to -ENOSYS. 3341 - */ 3342 - regs->gpr[3] = -ENOSYS; 3343 - return -1; 3344 - } 3345 - 3346 - void do_syscall_trace_leave(struct pt_regs *regs) 3347 - { 3348 - int step; 3349 - 3350 - audit_syscall_exit(regs); 3351 - 3352 - if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) 3353 - trace_sys_exit(regs, regs->result); 3354 - 3355 - step = test_thread_flag(TIF_SINGLESTEP); 3356 - if (step || test_thread_flag(TIF_SYSCALL_TRACE)) 3357 - tracehook_report_syscall_exit(regs, step); 3358 - 3359 - user_enter(); 3360 - } 3361 - 3362 - void __init pt_regs_check(void); 3363 - 3364 - /* 3365 - * Dummy function, its purpose is to break the build if struct pt_regs and 3366 - * struct user_pt_regs don't match. 3367 - */ 3368 - void __init pt_regs_check(void) 3369 - { 3370 - BUILD_BUG_ON(offsetof(struct pt_regs, gpr) != 3371 - offsetof(struct user_pt_regs, gpr)); 3372 - BUILD_BUG_ON(offsetof(struct pt_regs, nip) != 3373 - offsetof(struct user_pt_regs, nip)); 3374 - BUILD_BUG_ON(offsetof(struct pt_regs, msr) != 3375 - offsetof(struct user_pt_regs, msr)); 3376 - BUILD_BUG_ON(offsetof(struct pt_regs, msr) != 3377 - offsetof(struct user_pt_regs, msr)); 3378 - BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 3379 - offsetof(struct user_pt_regs, orig_gpr3)); 3380 - BUILD_BUG_ON(offsetof(struct pt_regs, ctr) != 3381 - offsetof(struct user_pt_regs, ctr)); 3382 - BUILD_BUG_ON(offsetof(struct pt_regs, link) != 3383 - offsetof(struct user_pt_regs, link)); 3384 - BUILD_BUG_ON(offsetof(struct pt_regs, xer) != 3385 - offsetof(struct user_pt_regs, xer)); 3386 - BUILD_BUG_ON(offsetof(struct pt_regs, ccr) != 3387 - offsetof(struct user_pt_regs, ccr)); 3388 - #ifdef __powerpc64__ 3389 - BUILD_BUG_ON(offsetof(struct pt_regs, softe) != 3390 - offsetof(struct user_pt_regs, softe)); 3391 - #else 3392 - BUILD_BUG_ON(offsetof(struct pt_regs, mq) != 3393 - offsetof(struct user_pt_regs, mq)); 3394 - #endif 3395 - BUILD_BUG_ON(offsetof(struct pt_regs, trap) != 3396 - offsetof(struct user_pt_regs, trap)); 3397 - BUILD_BUG_ON(offsetof(struct pt_regs, dar) != 3398 - offsetof(struct user_pt_regs, dar)); 3399 - BUILD_BUG_ON(offsetof(struct pt_regs, dsisr) != 3400 - offsetof(struct user_pt_regs, dsisr)); 3401 - BUILD_BUG_ON(offsetof(struct pt_regs, result) != 3402 - offsetof(struct user_pt_regs, result)); 3403 - 3404 - BUILD_BUG_ON(sizeof(struct user_pt_regs) > sizeof(struct pt_regs)); 3405 - 3406 - // Now check that the pt_regs offsets match the uapi #defines 3407 - #define CHECK_REG(_pt, _reg) \ 3408 - BUILD_BUG_ON(_pt != (offsetof(struct user_pt_regs, _reg) / \ 3409 - sizeof(unsigned long))); 3410 - 3411 - CHECK_REG(PT_R0, gpr[0]); 3412 - CHECK_REG(PT_R1, gpr[1]); 3413 - CHECK_REG(PT_R2, gpr[2]); 3414 - CHECK_REG(PT_R3, gpr[3]); 3415 - CHECK_REG(PT_R4, gpr[4]); 3416 - CHECK_REG(PT_R5, gpr[5]); 3417 - CHECK_REG(PT_R6, gpr[6]); 3418 - CHECK_REG(PT_R7, gpr[7]); 3419 - CHECK_REG(PT_R8, gpr[8]); 3420 - CHECK_REG(PT_R9, gpr[9]); 3421 - CHECK_REG(PT_R10, gpr[10]); 3422 - CHECK_REG(PT_R11, gpr[11]); 3423 - CHECK_REG(PT_R12, gpr[12]); 3424 - CHECK_REG(PT_R13, gpr[13]); 3425 - CHECK_REG(PT_R14, gpr[14]); 3426 - CHECK_REG(PT_R15, gpr[15]); 3427 - CHECK_REG(PT_R16, gpr[16]); 3428 - CHECK_REG(PT_R17, gpr[17]); 3429 - CHECK_REG(PT_R18, gpr[18]); 3430 - CHECK_REG(PT_R19, gpr[19]); 3431 - CHECK_REG(PT_R20, gpr[20]); 3432 - CHECK_REG(PT_R21, gpr[21]); 3433 - CHECK_REG(PT_R22, gpr[22]); 3434 - CHECK_REG(PT_R23, gpr[23]); 3435 - CHECK_REG(PT_R24, gpr[24]); 3436 - CHECK_REG(PT_R25, gpr[25]); 3437 - CHECK_REG(PT_R26, gpr[26]); 3438 - CHECK_REG(PT_R27, gpr[27]); 3439 - CHECK_REG(PT_R28, gpr[28]); 3440 - CHECK_REG(PT_R29, gpr[29]); 3441 - CHECK_REG(PT_R30, gpr[30]); 3442 - CHECK_REG(PT_R31, gpr[31]); 3443 - CHECK_REG(PT_NIP, nip); 3444 - CHECK_REG(PT_MSR, msr); 3445 - CHECK_REG(PT_ORIG_R3, orig_gpr3); 3446 - CHECK_REG(PT_CTR, ctr); 3447 - CHECK_REG(PT_LNK, link); 3448 - CHECK_REG(PT_XER, xer); 3449 - CHECK_REG(PT_CCR, ccr); 3450 - #ifdef CONFIG_PPC64 3451 - CHECK_REG(PT_SOFTE, softe); 3452 - #else 3453 - CHECK_REG(PT_MQ, mq); 3454 - #endif 3455 - CHECK_REG(PT_TRAP, trap); 3456 - CHECK_REG(PT_DAR, dar); 3457 - CHECK_REG(PT_DSISR, dsisr); 3458 - CHECK_REG(PT_RESULT, result); 3459 - #undef CHECK_REG 3460 - 3461 - BUILD_BUG_ON(PT_REGS_COUNT != sizeof(struct user_pt_regs) / sizeof(unsigned long)); 3462 - 3463 - /* 3464 - * PT_DSCR isn't a real reg, but it's important that it doesn't overlap the 3465 - * real registers. 3466 - */ 3467 - BUILD_BUG_ON(PT_DSCR < sizeof(struct user_pt_regs) / sizeof(unsigned long)); 3468 - }
+20
arch/powerpc/kernel/ptrace/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # Makefile for the linux kernel. 4 + # 5 + 6 + CFLAGS_ptrace-view.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' 7 + 8 + obj-y += ptrace.o ptrace-view.o 9 + obj-$(CONFIG_PPC64) += ptrace32.o 10 + obj-$(CONFIG_VSX) += ptrace-vsx.o 11 + ifneq ($(CONFIG_VSX),y) 12 + obj-y += ptrace-novsx.o 13 + endif 14 + obj-$(CONFIG_ALTIVEC) += ptrace-altivec.o 15 + obj-$(CONFIG_SPE) += ptrace-spe.o 16 + obj-$(CONFIG_PPC_TRANSACTIONAL_MEM) += ptrace-tm.o 17 + obj-$(CONFIG_PPC_ADV_DEBUG_REGS) += ptrace-adv.o 18 + ifneq ($(CONFIG_PPC_ADV_DEBUG_REGS),y) 19 + obj-y += ptrace-noadv.o 20 + endif
+492
arch/powerpc/kernel/ptrace/ptrace-adv.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/regset.h> 4 + #include <linux/hw_breakpoint.h> 5 + 6 + #include "ptrace-decl.h" 7 + 8 + void user_enable_single_step(struct task_struct *task) 9 + { 10 + struct pt_regs *regs = task->thread.regs; 11 + 12 + if (regs != NULL) { 13 + task->thread.debug.dbcr0 &= ~DBCR0_BT; 14 + task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; 15 + regs->msr |= MSR_DE; 16 + } 17 + set_tsk_thread_flag(task, TIF_SINGLESTEP); 18 + } 19 + 20 + void user_enable_block_step(struct task_struct *task) 21 + { 22 + struct pt_regs *regs = task->thread.regs; 23 + 24 + if (regs != NULL) { 25 + task->thread.debug.dbcr0 &= ~DBCR0_IC; 26 + task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT; 27 + regs->msr |= MSR_DE; 28 + } 29 + set_tsk_thread_flag(task, TIF_SINGLESTEP); 30 + } 31 + 32 + void user_disable_single_step(struct task_struct *task) 33 + { 34 + struct pt_regs *regs = task->thread.regs; 35 + 36 + if (regs != NULL) { 37 + /* 38 + * The logic to disable single stepping should be as 39 + * simple as turning off the Instruction Complete flag. 40 + * And, after doing so, if all debug flags are off, turn 41 + * off DBCR0(IDM) and MSR(DE) .... Torez 42 + */ 43 + task->thread.debug.dbcr0 &= ~(DBCR0_IC | DBCR0_BT); 44 + /* 45 + * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set. 46 + */ 47 + if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, 48 + task->thread.debug.dbcr1)) { 49 + /* 50 + * All debug events were off..... 51 + */ 52 + task->thread.debug.dbcr0 &= ~DBCR0_IDM; 53 + regs->msr &= ~MSR_DE; 54 + } 55 + } 56 + clear_tsk_thread_flag(task, TIF_SINGLESTEP); 57 + } 58 + 59 + void ppc_gethwdinfo(struct ppc_debug_info *dbginfo) 60 + { 61 + dbginfo->version = 1; 62 + dbginfo->num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS; 63 + dbginfo->num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS; 64 + dbginfo->num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS; 65 + dbginfo->data_bp_alignment = 4; 66 + dbginfo->sizeof_condition = 4; 67 + dbginfo->features = PPC_DEBUG_FEATURE_INSN_BP_RANGE | 68 + PPC_DEBUG_FEATURE_INSN_BP_MASK; 69 + if (IS_ENABLED(CONFIG_PPC_ADV_DEBUG_DAC_RANGE)) 70 + dbginfo->features |= PPC_DEBUG_FEATURE_DATA_BP_RANGE | 71 + PPC_DEBUG_FEATURE_DATA_BP_MASK; 72 + } 73 + 74 + int ptrace_get_debugreg(struct task_struct *child, unsigned long addr, 75 + unsigned long __user *datalp) 76 + { 77 + /* We only support one DABR and no IABRS at the moment */ 78 + if (addr > 0) 79 + return -EINVAL; 80 + return put_user(child->thread.debug.dac1, datalp); 81 + } 82 + 83 + int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned long data) 84 + { 85 + #ifdef CONFIG_HAVE_HW_BREAKPOINT 86 + int ret; 87 + struct thread_struct *thread = &task->thread; 88 + struct perf_event *bp; 89 + struct perf_event_attr attr; 90 + #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 91 + 92 + /* For ppc64 we support one DABR and no IABR's at the moment (ppc64). 93 + * For embedded processors we support one DAC and no IAC's at the 94 + * moment. 95 + */ 96 + if (addr > 0) 97 + return -EINVAL; 98 + 99 + /* The bottom 3 bits in dabr are flags */ 100 + if ((data & ~0x7UL) >= TASK_SIZE) 101 + return -EIO; 102 + 103 + /* As described above, it was assumed 3 bits were passed with the data 104 + * address, but we will assume only the mode bits will be passed 105 + * as to not cause alignment restrictions for DAC-based processors. 106 + */ 107 + 108 + /* DAC's hold the whole address without any mode flags */ 109 + task->thread.debug.dac1 = data & ~0x3UL; 110 + 111 + if (task->thread.debug.dac1 == 0) { 112 + dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W); 113 + if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, 114 + task->thread.debug.dbcr1)) { 115 + task->thread.regs->msr &= ~MSR_DE; 116 + task->thread.debug.dbcr0 &= ~DBCR0_IDM; 117 + } 118 + return 0; 119 + } 120 + 121 + /* Read or Write bits must be set */ 122 + 123 + if (!(data & 0x3UL)) 124 + return -EINVAL; 125 + 126 + /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0 register */ 127 + task->thread.debug.dbcr0 |= DBCR0_IDM; 128 + 129 + /* Check for write and read flags and set DBCR0 accordingly */ 130 + dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W); 131 + if (data & 0x1UL) 132 + dbcr_dac(task) |= DBCR_DAC1R; 133 + if (data & 0x2UL) 134 + dbcr_dac(task) |= DBCR_DAC1W; 135 + task->thread.regs->msr |= MSR_DE; 136 + return 0; 137 + } 138 + 139 + static long set_instruction_bp(struct task_struct *child, 140 + struct ppc_hw_breakpoint *bp_info) 141 + { 142 + int slot; 143 + int slot1_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC1) != 0); 144 + int slot2_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC2) != 0); 145 + int slot3_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC3) != 0); 146 + int slot4_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC4) != 0); 147 + 148 + if (dbcr_iac_range(child) & DBCR_IAC12MODE) 149 + slot2_in_use = 1; 150 + if (dbcr_iac_range(child) & DBCR_IAC34MODE) 151 + slot4_in_use = 1; 152 + 153 + if (bp_info->addr >= TASK_SIZE) 154 + return -EIO; 155 + 156 + if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) { 157 + /* Make sure range is valid. */ 158 + if (bp_info->addr2 >= TASK_SIZE) 159 + return -EIO; 160 + 161 + /* We need a pair of IAC regsisters */ 162 + if (!slot1_in_use && !slot2_in_use) { 163 + slot = 1; 164 + child->thread.debug.iac1 = bp_info->addr; 165 + child->thread.debug.iac2 = bp_info->addr2; 166 + child->thread.debug.dbcr0 |= DBCR0_IAC1; 167 + if (bp_info->addr_mode == 168 + PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) 169 + dbcr_iac_range(child) |= DBCR_IAC12X; 170 + else 171 + dbcr_iac_range(child) |= DBCR_IAC12I; 172 + #if CONFIG_PPC_ADV_DEBUG_IACS > 2 173 + } else if ((!slot3_in_use) && (!slot4_in_use)) { 174 + slot = 3; 175 + child->thread.debug.iac3 = bp_info->addr; 176 + child->thread.debug.iac4 = bp_info->addr2; 177 + child->thread.debug.dbcr0 |= DBCR0_IAC3; 178 + if (bp_info->addr_mode == 179 + PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) 180 + dbcr_iac_range(child) |= DBCR_IAC34X; 181 + else 182 + dbcr_iac_range(child) |= DBCR_IAC34I; 183 + #endif 184 + } else { 185 + return -ENOSPC; 186 + } 187 + } else { 188 + /* We only need one. If possible leave a pair free in 189 + * case a range is needed later 190 + */ 191 + if (!slot1_in_use) { 192 + /* 193 + * Don't use iac1 if iac1-iac2 are free and either 194 + * iac3 or iac4 (but not both) are free 195 + */ 196 + if (slot2_in_use || slot3_in_use == slot4_in_use) { 197 + slot = 1; 198 + child->thread.debug.iac1 = bp_info->addr; 199 + child->thread.debug.dbcr0 |= DBCR0_IAC1; 200 + goto out; 201 + } 202 + } 203 + if (!slot2_in_use) { 204 + slot = 2; 205 + child->thread.debug.iac2 = bp_info->addr; 206 + child->thread.debug.dbcr0 |= DBCR0_IAC2; 207 + #if CONFIG_PPC_ADV_DEBUG_IACS > 2 208 + } else if (!slot3_in_use) { 209 + slot = 3; 210 + child->thread.debug.iac3 = bp_info->addr; 211 + child->thread.debug.dbcr0 |= DBCR0_IAC3; 212 + } else if (!slot4_in_use) { 213 + slot = 4; 214 + child->thread.debug.iac4 = bp_info->addr; 215 + child->thread.debug.dbcr0 |= DBCR0_IAC4; 216 + #endif 217 + } else { 218 + return -ENOSPC; 219 + } 220 + } 221 + out: 222 + child->thread.debug.dbcr0 |= DBCR0_IDM; 223 + child->thread.regs->msr |= MSR_DE; 224 + 225 + return slot; 226 + } 227 + 228 + static int del_instruction_bp(struct task_struct *child, int slot) 229 + { 230 + switch (slot) { 231 + case 1: 232 + if ((child->thread.debug.dbcr0 & DBCR0_IAC1) == 0) 233 + return -ENOENT; 234 + 235 + if (dbcr_iac_range(child) & DBCR_IAC12MODE) { 236 + /* address range - clear slots 1 & 2 */ 237 + child->thread.debug.iac2 = 0; 238 + dbcr_iac_range(child) &= ~DBCR_IAC12MODE; 239 + } 240 + child->thread.debug.iac1 = 0; 241 + child->thread.debug.dbcr0 &= ~DBCR0_IAC1; 242 + break; 243 + case 2: 244 + if ((child->thread.debug.dbcr0 & DBCR0_IAC2) == 0) 245 + return -ENOENT; 246 + 247 + if (dbcr_iac_range(child) & DBCR_IAC12MODE) 248 + /* used in a range */ 249 + return -EINVAL; 250 + child->thread.debug.iac2 = 0; 251 + child->thread.debug.dbcr0 &= ~DBCR0_IAC2; 252 + break; 253 + #if CONFIG_PPC_ADV_DEBUG_IACS > 2 254 + case 3: 255 + if ((child->thread.debug.dbcr0 & DBCR0_IAC3) == 0) 256 + return -ENOENT; 257 + 258 + if (dbcr_iac_range(child) & DBCR_IAC34MODE) { 259 + /* address range - clear slots 3 & 4 */ 260 + child->thread.debug.iac4 = 0; 261 + dbcr_iac_range(child) &= ~DBCR_IAC34MODE; 262 + } 263 + child->thread.debug.iac3 = 0; 264 + child->thread.debug.dbcr0 &= ~DBCR0_IAC3; 265 + break; 266 + case 4: 267 + if ((child->thread.debug.dbcr0 & DBCR0_IAC4) == 0) 268 + return -ENOENT; 269 + 270 + if (dbcr_iac_range(child) & DBCR_IAC34MODE) 271 + /* Used in a range */ 272 + return -EINVAL; 273 + child->thread.debug.iac4 = 0; 274 + child->thread.debug.dbcr0 &= ~DBCR0_IAC4; 275 + break; 276 + #endif 277 + default: 278 + return -EINVAL; 279 + } 280 + return 0; 281 + } 282 + 283 + static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) 284 + { 285 + int byte_enable = 286 + (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT) 287 + & 0xf; 288 + int condition_mode = 289 + bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE; 290 + int slot; 291 + 292 + if (byte_enable && condition_mode == 0) 293 + return -EINVAL; 294 + 295 + if (bp_info->addr >= TASK_SIZE) 296 + return -EIO; 297 + 298 + if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) { 299 + slot = 1; 300 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) 301 + dbcr_dac(child) |= DBCR_DAC1R; 302 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 303 + dbcr_dac(child) |= DBCR_DAC1W; 304 + child->thread.debug.dac1 = (unsigned long)bp_info->addr; 305 + #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 306 + if (byte_enable) { 307 + child->thread.debug.dvc1 = 308 + (unsigned long)bp_info->condition_value; 309 + child->thread.debug.dbcr2 |= 310 + ((byte_enable << DBCR2_DVC1BE_SHIFT) | 311 + (condition_mode << DBCR2_DVC1M_SHIFT)); 312 + } 313 + #endif 314 + #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 315 + } else if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) { 316 + /* Both dac1 and dac2 are part of a range */ 317 + return -ENOSPC; 318 + #endif 319 + } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) { 320 + slot = 2; 321 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) 322 + dbcr_dac(child) |= DBCR_DAC2R; 323 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 324 + dbcr_dac(child) |= DBCR_DAC2W; 325 + child->thread.debug.dac2 = (unsigned long)bp_info->addr; 326 + #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 327 + if (byte_enable) { 328 + child->thread.debug.dvc2 = 329 + (unsigned long)bp_info->condition_value; 330 + child->thread.debug.dbcr2 |= 331 + ((byte_enable << DBCR2_DVC2BE_SHIFT) | 332 + (condition_mode << DBCR2_DVC2M_SHIFT)); 333 + } 334 + #endif 335 + } else { 336 + return -ENOSPC; 337 + } 338 + child->thread.debug.dbcr0 |= DBCR0_IDM; 339 + child->thread.regs->msr |= MSR_DE; 340 + 341 + return slot + 4; 342 + } 343 + 344 + static int del_dac(struct task_struct *child, int slot) 345 + { 346 + if (slot == 1) { 347 + if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) 348 + return -ENOENT; 349 + 350 + child->thread.debug.dac1 = 0; 351 + dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W); 352 + #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 353 + if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) { 354 + child->thread.debug.dac2 = 0; 355 + child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; 356 + } 357 + child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE); 358 + #endif 359 + #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 360 + child->thread.debug.dvc1 = 0; 361 + #endif 362 + } else if (slot == 2) { 363 + if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) 364 + return -ENOENT; 365 + 366 + #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 367 + if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) 368 + /* Part of a range */ 369 + return -EINVAL; 370 + child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE); 371 + #endif 372 + #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 373 + child->thread.debug.dvc2 = 0; 374 + #endif 375 + child->thread.debug.dac2 = 0; 376 + dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W); 377 + } else { 378 + return -EINVAL; 379 + } 380 + 381 + return 0; 382 + } 383 + 384 + #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 385 + static int set_dac_range(struct task_struct *child, 386 + struct ppc_hw_breakpoint *bp_info) 387 + { 388 + int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK; 389 + 390 + /* We don't allow range watchpoints to be used with DVC */ 391 + if (bp_info->condition_mode) 392 + return -EINVAL; 393 + 394 + /* 395 + * Best effort to verify the address range. The user/supervisor bits 396 + * prevent trapping in kernel space, but let's fail on an obvious bad 397 + * range. The simple test on the mask is not fool-proof, and any 398 + * exclusive range will spill over into kernel space. 399 + */ 400 + if (bp_info->addr >= TASK_SIZE) 401 + return -EIO; 402 + if (mode == PPC_BREAKPOINT_MODE_MASK) { 403 + /* 404 + * dac2 is a bitmask. Don't allow a mask that makes a 405 + * kernel space address from a valid dac1 value 406 + */ 407 + if (~((unsigned long)bp_info->addr2) >= TASK_SIZE) 408 + return -EIO; 409 + } else { 410 + /* 411 + * For range breakpoints, addr2 must also be a valid address 412 + */ 413 + if (bp_info->addr2 >= TASK_SIZE) 414 + return -EIO; 415 + } 416 + 417 + if (child->thread.debug.dbcr0 & 418 + (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W)) 419 + return -ENOSPC; 420 + 421 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) 422 + child->thread.debug.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM); 423 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 424 + child->thread.debug.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM); 425 + child->thread.debug.dac1 = bp_info->addr; 426 + child->thread.debug.dac2 = bp_info->addr2; 427 + if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) 428 + child->thread.debug.dbcr2 |= DBCR2_DAC12M; 429 + else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) 430 + child->thread.debug.dbcr2 |= DBCR2_DAC12MX; 431 + else /* PPC_BREAKPOINT_MODE_MASK */ 432 + child->thread.debug.dbcr2 |= DBCR2_DAC12MM; 433 + child->thread.regs->msr |= MSR_DE; 434 + 435 + return 5; 436 + } 437 + #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */ 438 + 439 + long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) 440 + { 441 + if (bp_info->version != 1) 442 + return -ENOTSUPP; 443 + /* 444 + * Check for invalid flags and combinations 445 + */ 446 + if (bp_info->trigger_type == 0 || 447 + (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE | 448 + PPC_BREAKPOINT_TRIGGER_RW)) || 449 + (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) || 450 + (bp_info->condition_mode & 451 + ~(PPC_BREAKPOINT_CONDITION_MODE | 452 + PPC_BREAKPOINT_CONDITION_BE_ALL))) 453 + return -EINVAL; 454 + #if CONFIG_PPC_ADV_DEBUG_DVCS == 0 455 + if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) 456 + return -EINVAL; 457 + #endif 458 + 459 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) { 460 + if (bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE || 461 + bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) 462 + return -EINVAL; 463 + return set_instruction_bp(child, bp_info); 464 + } 465 + if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) 466 + return set_dac(child, bp_info); 467 + 468 + #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 469 + return set_dac_range(child, bp_info); 470 + #else 471 + return -EINVAL; 472 + #endif 473 + } 474 + 475 + long ppc_del_hwdebug(struct task_struct *child, long data) 476 + { 477 + int rc; 478 + 479 + if (data <= 4) 480 + rc = del_instruction_bp(child, (int)data); 481 + else 482 + rc = del_dac(child, (int)data - 4); 483 + 484 + if (!rc) { 485 + if (!DBCR_ACTIVE_EVENTS(child->thread.debug.dbcr0, 486 + child->thread.debug.dbcr1)) { 487 + child->thread.debug.dbcr0 &= ~DBCR0_IDM; 488 + child->thread.regs->msr &= ~MSR_DE; 489 + } 490 + } 491 + return rc; 492 + }
+128
arch/powerpc/kernel/ptrace/ptrace-altivec.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/regset.h> 4 + #include <linux/elf.h> 5 + 6 + #include <asm/switch_to.h> 7 + 8 + #include "ptrace-decl.h" 9 + 10 + /* 11 + * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go. 12 + * The transfer totals 34 quadword. Quadwords 0-31 contain the 13 + * corresponding vector registers. Quadword 32 contains the vscr as the 14 + * last word (offset 12) within that quadword. Quadword 33 contains the 15 + * vrsave as the first word (offset 0) within the quadword. 16 + * 17 + * This definition of the VMX state is compatible with the current PPC32 18 + * ptrace interface. This allows signal handling and ptrace to use the 19 + * same structures. This also simplifies the implementation of a bi-arch 20 + * (combined (32- and 64-bit) gdb. 21 + */ 22 + 23 + int vr_active(struct task_struct *target, const struct user_regset *regset) 24 + { 25 + flush_altivec_to_thread(target); 26 + return target->thread.used_vr ? regset->n : 0; 27 + } 28 + 29 + /* 30 + * Regardless of transactions, 'vr_state' holds the current running 31 + * value of all the VMX registers and 'ckvr_state' holds the last 32 + * checkpointed value of all the VMX registers for the current 33 + * transaction to fall back on in case it aborts. 34 + * 35 + * Userspace interface buffer layout: 36 + * 37 + * struct data { 38 + * vector128 vr[32]; 39 + * vector128 vscr; 40 + * vector128 vrsave; 41 + * }; 42 + */ 43 + int vr_get(struct task_struct *target, const struct user_regset *regset, 44 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 45 + { 46 + int ret; 47 + 48 + flush_altivec_to_thread(target); 49 + 50 + BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) != 51 + offsetof(struct thread_vr_state, vr[32])); 52 + 53 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 54 + &target->thread.vr_state, 0, 55 + 33 * sizeof(vector128)); 56 + if (!ret) { 57 + /* 58 + * Copy out only the low-order word of vrsave. 59 + */ 60 + int start, end; 61 + union { 62 + elf_vrreg_t reg; 63 + u32 word; 64 + } vrsave; 65 + memset(&vrsave, 0, sizeof(vrsave)); 66 + 67 + vrsave.word = target->thread.vrsave; 68 + 69 + start = 33 * sizeof(vector128); 70 + end = start + sizeof(vrsave); 71 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, 72 + start, end); 73 + } 74 + 75 + return ret; 76 + } 77 + 78 + /* 79 + * Regardless of transactions, 'vr_state' holds the current running 80 + * value of all the VMX registers and 'ckvr_state' holds the last 81 + * checkpointed value of all the VMX registers for the current 82 + * transaction to fall back on in case it aborts. 83 + * 84 + * Userspace interface buffer layout: 85 + * 86 + * struct data { 87 + * vector128 vr[32]; 88 + * vector128 vscr; 89 + * vector128 vrsave; 90 + * }; 91 + */ 92 + int vr_set(struct task_struct *target, const struct user_regset *regset, 93 + unsigned int pos, unsigned int count, 94 + const void *kbuf, const void __user *ubuf) 95 + { 96 + int ret; 97 + 98 + flush_altivec_to_thread(target); 99 + 100 + BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) != 101 + offsetof(struct thread_vr_state, vr[32])); 102 + 103 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 104 + &target->thread.vr_state, 0, 105 + 33 * sizeof(vector128)); 106 + if (!ret && count > 0) { 107 + /* 108 + * We use only the first word of vrsave. 109 + */ 110 + int start, end; 111 + union { 112 + elf_vrreg_t reg; 113 + u32 word; 114 + } vrsave; 115 + memset(&vrsave, 0, sizeof(vrsave)); 116 + 117 + vrsave.word = target->thread.vrsave; 118 + 119 + start = 33 * sizeof(vector128); 120 + end = start + sizeof(vrsave); 121 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, 122 + start, end); 123 + if (!ret) 124 + target->thread.vrsave = vrsave.word; 125 + } 126 + 127 + return ret; 128 + }
+184
arch/powerpc/kernel/ptrace/ptrace-decl.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + 3 + /* 4 + * Set of msr bits that gdb can change on behalf of a process. 5 + */ 6 + #ifdef CONFIG_PPC_ADV_DEBUG_REGS 7 + #define MSR_DEBUGCHANGE 0 8 + #else 9 + #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE) 10 + #endif 11 + 12 + /* 13 + * Max register writeable via put_reg 14 + */ 15 + #ifdef CONFIG_PPC32 16 + #define PT_MAX_PUT_REG PT_MQ 17 + #else 18 + #define PT_MAX_PUT_REG PT_CCR 19 + #endif 20 + 21 + #define TVSO(f) (offsetof(struct thread_vr_state, f)) 22 + #define TFSO(f) (offsetof(struct thread_fp_state, f)) 23 + #define TSO(f) (offsetof(struct thread_struct, f)) 24 + 25 + /* 26 + * These are our native regset flavors. 27 + */ 28 + enum powerpc_regset { 29 + REGSET_GPR, 30 + REGSET_FPR, 31 + #ifdef CONFIG_ALTIVEC 32 + REGSET_VMX, 33 + #endif 34 + #ifdef CONFIG_VSX 35 + REGSET_VSX, 36 + #endif 37 + #ifdef CONFIG_SPE 38 + REGSET_SPE, 39 + #endif 40 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 41 + REGSET_TM_CGPR, /* TM checkpointed GPR registers */ 42 + REGSET_TM_CFPR, /* TM checkpointed FPR registers */ 43 + REGSET_TM_CVMX, /* TM checkpointed VMX registers */ 44 + REGSET_TM_CVSX, /* TM checkpointed VSX registers */ 45 + REGSET_TM_SPR, /* TM specific SPR registers */ 46 + REGSET_TM_CTAR, /* TM checkpointed TAR register */ 47 + REGSET_TM_CPPR, /* TM checkpointed PPR register */ 48 + REGSET_TM_CDSCR, /* TM checkpointed DSCR register */ 49 + #endif 50 + #ifdef CONFIG_PPC64 51 + REGSET_PPR, /* PPR register */ 52 + REGSET_DSCR, /* DSCR register */ 53 + #endif 54 + #ifdef CONFIG_PPC_BOOK3S_64 55 + REGSET_TAR, /* TAR register */ 56 + REGSET_EBB, /* EBB registers */ 57 + REGSET_PMR, /* Performance Monitor Registers */ 58 + #endif 59 + #ifdef CONFIG_PPC_MEM_KEYS 60 + REGSET_PKEY, /* AMR register */ 61 + #endif 62 + }; 63 + 64 + /* ptrace-(no)vsx */ 65 + 66 + int fpr_get(struct task_struct *target, const struct user_regset *regset, 67 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 68 + int fpr_set(struct task_struct *target, const struct user_regset *regset, 69 + unsigned int pos, unsigned int count, 70 + const void *kbuf, const void __user *ubuf); 71 + 72 + /* ptrace-vsx */ 73 + 74 + int vsr_active(struct task_struct *target, const struct user_regset *regset); 75 + int vsr_get(struct task_struct *target, const struct user_regset *regset, 76 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 77 + int vsr_set(struct task_struct *target, const struct user_regset *regset, 78 + unsigned int pos, unsigned int count, 79 + const void *kbuf, const void __user *ubuf); 80 + 81 + /* ptrace-altivec */ 82 + 83 + int vr_active(struct task_struct *target, const struct user_regset *regset); 84 + int vr_get(struct task_struct *target, const struct user_regset *regset, 85 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 86 + int vr_set(struct task_struct *target, const struct user_regset *regset, 87 + unsigned int pos, unsigned int count, 88 + const void *kbuf, const void __user *ubuf); 89 + 90 + /* ptrace-spe */ 91 + 92 + int evr_active(struct task_struct *target, const struct user_regset *regset); 93 + int evr_get(struct task_struct *target, const struct user_regset *regset, 94 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 95 + int evr_set(struct task_struct *target, const struct user_regset *regset, 96 + unsigned int pos, unsigned int count, 97 + const void *kbuf, const void __user *ubuf); 98 + 99 + /* ptrace */ 100 + 101 + int gpr32_get_common(struct task_struct *target, 102 + const struct user_regset *regset, 103 + unsigned int pos, unsigned int count, 104 + void *kbuf, void __user *ubuf, 105 + unsigned long *regs); 106 + int gpr32_set_common(struct task_struct *target, 107 + const struct user_regset *regset, 108 + unsigned int pos, unsigned int count, 109 + const void *kbuf, const void __user *ubuf, 110 + unsigned long *regs); 111 + 112 + /* ptrace-tm */ 113 + 114 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 115 + void flush_tmregs_to_thread(struct task_struct *tsk); 116 + #else 117 + static inline void flush_tmregs_to_thread(struct task_struct *tsk) { } 118 + #endif 119 + 120 + int tm_cgpr_active(struct task_struct *target, const struct user_regset *regset); 121 + int tm_cgpr_get(struct task_struct *target, const struct user_regset *regset, 122 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 123 + int tm_cgpr_set(struct task_struct *target, const struct user_regset *regset, 124 + unsigned int pos, unsigned int count, 125 + const void *kbuf, const void __user *ubuf); 126 + int tm_cfpr_active(struct task_struct *target, const struct user_regset *regset); 127 + int tm_cfpr_get(struct task_struct *target, const struct user_regset *regset, 128 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 129 + int tm_cfpr_set(struct task_struct *target, const struct user_regset *regset, 130 + unsigned int pos, unsigned int count, 131 + const void *kbuf, const void __user *ubuf); 132 + int tm_cvmx_active(struct task_struct *target, const struct user_regset *regset); 133 + int tm_cvmx_get(struct task_struct *target, const struct user_regset *regset, 134 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 135 + int tm_cvmx_set(struct task_struct *target, const struct user_regset *regset, 136 + unsigned int pos, unsigned int count, 137 + const void *kbuf, const void __user *ubuf); 138 + int tm_cvsx_active(struct task_struct *target, const struct user_regset *regset); 139 + int tm_cvsx_get(struct task_struct *target, const struct user_regset *regset, 140 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 141 + int tm_cvsx_set(struct task_struct *target, const struct user_regset *regset, 142 + unsigned int pos, unsigned int count, 143 + const void *kbuf, const void __user *ubuf); 144 + int tm_spr_active(struct task_struct *target, const struct user_regset *regset); 145 + int tm_spr_get(struct task_struct *target, const struct user_regset *regset, 146 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 147 + int tm_spr_set(struct task_struct *target, const struct user_regset *regset, 148 + unsigned int pos, unsigned int count, 149 + const void *kbuf, const void __user *ubuf); 150 + int tm_tar_active(struct task_struct *target, const struct user_regset *regset); 151 + int tm_tar_get(struct task_struct *target, const struct user_regset *regset, 152 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 153 + int tm_tar_set(struct task_struct *target, const struct user_regset *regset, 154 + unsigned int pos, unsigned int count, 155 + const void *kbuf, const void __user *ubuf); 156 + int tm_ppr_active(struct task_struct *target, const struct user_regset *regset); 157 + int tm_ppr_get(struct task_struct *target, const struct user_regset *regset, 158 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 159 + int tm_ppr_set(struct task_struct *target, const struct user_regset *regset, 160 + unsigned int pos, unsigned int count, 161 + const void *kbuf, const void __user *ubuf); 162 + int tm_dscr_active(struct task_struct *target, const struct user_regset *regset); 163 + int tm_dscr_get(struct task_struct *target, const struct user_regset *regset, 164 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 165 + int tm_dscr_set(struct task_struct *target, const struct user_regset *regset, 166 + unsigned int pos, unsigned int count, 167 + const void *kbuf, const void __user *ubuf); 168 + int tm_cgpr32_get(struct task_struct *target, const struct user_regset *regset, 169 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); 170 + int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset, 171 + unsigned int pos, unsigned int count, 172 + const void *kbuf, const void __user *ubuf); 173 + 174 + /* ptrace-view */ 175 + 176 + extern const struct user_regset_view user_ppc_native_view; 177 + 178 + /* ptrace-(no)adv */ 179 + void ppc_gethwdinfo(struct ppc_debug_info *dbginfo); 180 + int ptrace_get_debugreg(struct task_struct *child, unsigned long addr, 181 + unsigned long __user *datalp); 182 + int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned long data); 183 + long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_info); 184 + long ppc_del_hwdebug(struct task_struct *child, long data);
+265
arch/powerpc/kernel/ptrace/ptrace-noadv.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/regset.h> 4 + #include <linux/hw_breakpoint.h> 5 + 6 + #include <asm/debug.h> 7 + 8 + #include "ptrace-decl.h" 9 + 10 + void user_enable_single_step(struct task_struct *task) 11 + { 12 + struct pt_regs *regs = task->thread.regs; 13 + 14 + if (regs != NULL) { 15 + regs->msr &= ~MSR_BE; 16 + regs->msr |= MSR_SE; 17 + } 18 + set_tsk_thread_flag(task, TIF_SINGLESTEP); 19 + } 20 + 21 + void user_enable_block_step(struct task_struct *task) 22 + { 23 + struct pt_regs *regs = task->thread.regs; 24 + 25 + if (regs != NULL) { 26 + regs->msr &= ~MSR_SE; 27 + regs->msr |= MSR_BE; 28 + } 29 + set_tsk_thread_flag(task, TIF_SINGLESTEP); 30 + } 31 + 32 + void user_disable_single_step(struct task_struct *task) 33 + { 34 + struct pt_regs *regs = task->thread.regs; 35 + 36 + if (regs != NULL) 37 + regs->msr &= ~(MSR_SE | MSR_BE); 38 + 39 + clear_tsk_thread_flag(task, TIF_SINGLESTEP); 40 + } 41 + 42 + void ppc_gethwdinfo(struct ppc_debug_info *dbginfo) 43 + { 44 + dbginfo->version = 1; 45 + dbginfo->num_instruction_bps = 0; 46 + if (ppc_breakpoint_available()) 47 + dbginfo->num_data_bps = 1; 48 + else 49 + dbginfo->num_data_bps = 0; 50 + dbginfo->num_condition_regs = 0; 51 + dbginfo->data_bp_alignment = sizeof(long); 52 + dbginfo->sizeof_condition = 0; 53 + if (IS_ENABLED(CONFIG_HAVE_HW_BREAKPOINT)) { 54 + dbginfo->features = PPC_DEBUG_FEATURE_DATA_BP_RANGE; 55 + if (dawr_enabled()) 56 + dbginfo->features |= PPC_DEBUG_FEATURE_DATA_BP_DAWR; 57 + } else { 58 + dbginfo->features = 0; 59 + } 60 + } 61 + 62 + int ptrace_get_debugreg(struct task_struct *child, unsigned long addr, 63 + unsigned long __user *datalp) 64 + { 65 + unsigned long dabr_fake; 66 + 67 + /* We only support one DABR and no IABRS at the moment */ 68 + if (addr > 0) 69 + return -EINVAL; 70 + dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) | 71 + (child->thread.hw_brk.type & HW_BRK_TYPE_DABR)); 72 + return put_user(dabr_fake, datalp); 73 + } 74 + 75 + int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned long data) 76 + { 77 + #ifdef CONFIG_HAVE_HW_BREAKPOINT 78 + int ret; 79 + struct thread_struct *thread = &task->thread; 80 + struct perf_event *bp; 81 + struct perf_event_attr attr; 82 + #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 83 + bool set_bp = true; 84 + struct arch_hw_breakpoint hw_brk; 85 + 86 + /* For ppc64 we support one DABR and no IABR's at the moment (ppc64). 87 + * For embedded processors we support one DAC and no IAC's at the 88 + * moment. 89 + */ 90 + if (addr > 0) 91 + return -EINVAL; 92 + 93 + /* The bottom 3 bits in dabr are flags */ 94 + if ((data & ~0x7UL) >= TASK_SIZE) 95 + return -EIO; 96 + 97 + /* For processors using DABR (i.e. 970), the bottom 3 bits are flags. 98 + * It was assumed, on previous implementations, that 3 bits were 99 + * passed together with the data address, fitting the design of the 100 + * DABR register, as follows: 101 + * 102 + * bit 0: Read flag 103 + * bit 1: Write flag 104 + * bit 2: Breakpoint translation 105 + * 106 + * Thus, we use them here as so. 107 + */ 108 + 109 + /* Ensure breakpoint translation bit is set */ 110 + if (data && !(data & HW_BRK_TYPE_TRANSLATE)) 111 + return -EIO; 112 + hw_brk.address = data & (~HW_BRK_TYPE_DABR); 113 + hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL; 114 + hw_brk.len = DABR_MAX_LEN; 115 + hw_brk.hw_len = DABR_MAX_LEN; 116 + set_bp = (data) && (hw_brk.type & HW_BRK_TYPE_RDWR); 117 + #ifdef CONFIG_HAVE_HW_BREAKPOINT 118 + bp = thread->ptrace_bps[0]; 119 + if (!set_bp) { 120 + if (bp) { 121 + unregister_hw_breakpoint(bp); 122 + thread->ptrace_bps[0] = NULL; 123 + } 124 + return 0; 125 + } 126 + if (bp) { 127 + attr = bp->attr; 128 + attr.bp_addr = hw_brk.address; 129 + attr.bp_len = DABR_MAX_LEN; 130 + arch_bp_generic_fields(hw_brk.type, &attr.bp_type); 131 + 132 + /* Enable breakpoint */ 133 + attr.disabled = false; 134 + 135 + ret = modify_user_hw_breakpoint(bp, &attr); 136 + if (ret) 137 + return ret; 138 + 139 + thread->ptrace_bps[0] = bp; 140 + thread->hw_brk = hw_brk; 141 + return 0; 142 + } 143 + 144 + /* Create a new breakpoint request if one doesn't exist already */ 145 + hw_breakpoint_init(&attr); 146 + attr.bp_addr = hw_brk.address; 147 + attr.bp_len = DABR_MAX_LEN; 148 + arch_bp_generic_fields(hw_brk.type, 149 + &attr.bp_type); 150 + 151 + thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, 152 + ptrace_triggered, NULL, task); 153 + if (IS_ERR(bp)) { 154 + thread->ptrace_bps[0] = NULL; 155 + return PTR_ERR(bp); 156 + } 157 + 158 + #else /* !CONFIG_HAVE_HW_BREAKPOINT */ 159 + if (set_bp && (!ppc_breakpoint_available())) 160 + return -ENODEV; 161 + #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 162 + task->thread.hw_brk = hw_brk; 163 + return 0; 164 + } 165 + 166 + long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) 167 + { 168 + #ifdef CONFIG_HAVE_HW_BREAKPOINT 169 + int len = 0; 170 + struct thread_struct *thread = &child->thread; 171 + struct perf_event *bp; 172 + struct perf_event_attr attr; 173 + #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 174 + struct arch_hw_breakpoint brk; 175 + 176 + if (bp_info->version != 1) 177 + return -ENOTSUPP; 178 + /* 179 + * We only support one data breakpoint 180 + */ 181 + if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 || 182 + (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 || 183 + bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) 184 + return -EINVAL; 185 + 186 + if ((unsigned long)bp_info->addr >= TASK_SIZE) 187 + return -EIO; 188 + 189 + brk.address = bp_info->addr & ~HW_BREAKPOINT_ALIGN; 190 + brk.type = HW_BRK_TYPE_TRANSLATE; 191 + brk.len = DABR_MAX_LEN; 192 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) 193 + brk.type |= HW_BRK_TYPE_READ; 194 + if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 195 + brk.type |= HW_BRK_TYPE_WRITE; 196 + #ifdef CONFIG_HAVE_HW_BREAKPOINT 197 + if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) 198 + len = bp_info->addr2 - bp_info->addr; 199 + else if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) 200 + len = 1; 201 + else 202 + return -EINVAL; 203 + bp = thread->ptrace_bps[0]; 204 + if (bp) 205 + return -ENOSPC; 206 + 207 + /* Create a new breakpoint request if one doesn't exist already */ 208 + hw_breakpoint_init(&attr); 209 + attr.bp_addr = (unsigned long)bp_info->addr; 210 + attr.bp_len = len; 211 + arch_bp_generic_fields(brk.type, &attr.bp_type); 212 + 213 + bp = register_user_hw_breakpoint(&attr, ptrace_triggered, NULL, child); 214 + thread->ptrace_bps[0] = bp; 215 + if (IS_ERR(bp)) { 216 + thread->ptrace_bps[0] = NULL; 217 + return PTR_ERR(bp); 218 + } 219 + 220 + return 1; 221 + #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 222 + 223 + if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) 224 + return -EINVAL; 225 + 226 + if (child->thread.hw_brk.address) 227 + return -ENOSPC; 228 + 229 + if (!ppc_breakpoint_available()) 230 + return -ENODEV; 231 + 232 + child->thread.hw_brk = brk; 233 + 234 + return 1; 235 + } 236 + 237 + long ppc_del_hwdebug(struct task_struct *child, long data) 238 + { 239 + #ifdef CONFIG_HAVE_HW_BREAKPOINT 240 + int ret = 0; 241 + struct thread_struct *thread = &child->thread; 242 + struct perf_event *bp; 243 + #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 244 + if (data != 1) 245 + return -EINVAL; 246 + 247 + #ifdef CONFIG_HAVE_HW_BREAKPOINT 248 + bp = thread->ptrace_bps[0]; 249 + if (bp) { 250 + unregister_hw_breakpoint(bp); 251 + thread->ptrace_bps[0] = NULL; 252 + } else { 253 + ret = -ENOENT; 254 + } 255 + return ret; 256 + #else /* CONFIG_HAVE_HW_BREAKPOINT */ 257 + if (child->thread.hw_brk.address == 0) 258 + return -ENOENT; 259 + 260 + child->thread.hw_brk.address = 0; 261 + child->thread.hw_brk.type = 0; 262 + #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 263 + 264 + return 0; 265 + }
+57
arch/powerpc/kernel/ptrace/ptrace-novsx.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/regset.h> 4 + 5 + #include <asm/switch_to.h> 6 + 7 + #include "ptrace-decl.h" 8 + 9 + /* 10 + * Regardless of transactions, 'fp_state' holds the current running 11 + * value of all FPR registers and 'ckfp_state' holds the last checkpointed 12 + * value of all FPR registers for the current transaction. 13 + * 14 + * Userspace interface buffer layout: 15 + * 16 + * struct data { 17 + * u64 fpr[32]; 18 + * u64 fpscr; 19 + * }; 20 + */ 21 + int fpr_get(struct task_struct *target, const struct user_regset *regset, 22 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 23 + { 24 + BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) != 25 + offsetof(struct thread_fp_state, fpr[32])); 26 + 27 + flush_fp_to_thread(target); 28 + 29 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 30 + &target->thread.fp_state, 0, -1); 31 + } 32 + 33 + /* 34 + * Regardless of transactions, 'fp_state' holds the current running 35 + * value of all FPR registers and 'ckfp_state' holds the last checkpointed 36 + * value of all FPR registers for the current transaction. 37 + * 38 + * Userspace interface buffer layout: 39 + * 40 + * struct data { 41 + * u64 fpr[32]; 42 + * u64 fpscr; 43 + * }; 44 + * 45 + */ 46 + int fpr_set(struct task_struct *target, const struct user_regset *regset, 47 + unsigned int pos, unsigned int count, 48 + const void *kbuf, const void __user *ubuf) 49 + { 50 + BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) != 51 + offsetof(struct thread_fp_state, fpr[32])); 52 + 53 + flush_fp_to_thread(target); 54 + 55 + return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 56 + &target->thread.fp_state, 0, -1); 57 + }
+68
arch/powerpc/kernel/ptrace/ptrace-spe.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/regset.h> 4 + 5 + #include <asm/switch_to.h> 6 + 7 + #include "ptrace-decl.h" 8 + 9 + /* 10 + * For get_evrregs/set_evrregs functions 'data' has the following layout: 11 + * 12 + * struct { 13 + * u32 evr[32]; 14 + * u64 acc; 15 + * u32 spefscr; 16 + * } 17 + */ 18 + 19 + int evr_active(struct task_struct *target, const struct user_regset *regset) 20 + { 21 + flush_spe_to_thread(target); 22 + return target->thread.used_spe ? regset->n : 0; 23 + } 24 + 25 + int evr_get(struct task_struct *target, const struct user_regset *regset, 26 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 27 + { 28 + int ret; 29 + 30 + flush_spe_to_thread(target); 31 + 32 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 33 + &target->thread.evr, 34 + 0, sizeof(target->thread.evr)); 35 + 36 + BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != 37 + offsetof(struct thread_struct, spefscr)); 38 + 39 + if (!ret) 40 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 41 + &target->thread.acc, 42 + sizeof(target->thread.evr), -1); 43 + 44 + return ret; 45 + } 46 + 47 + int evr_set(struct task_struct *target, const struct user_regset *regset, 48 + unsigned int pos, unsigned int count, 49 + const void *kbuf, const void __user *ubuf) 50 + { 51 + int ret; 52 + 53 + flush_spe_to_thread(target); 54 + 55 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 56 + &target->thread.evr, 57 + 0, sizeof(target->thread.evr)); 58 + 59 + BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != 60 + offsetof(struct thread_struct, spefscr)); 61 + 62 + if (!ret) 63 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 64 + &target->thread.acc, 65 + sizeof(target->thread.evr), -1); 66 + 67 + return ret; 68 + }
+851
arch/powerpc/kernel/ptrace/ptrace-tm.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/regset.h> 4 + 5 + #include <asm/switch_to.h> 6 + #include <asm/tm.h> 7 + #include <asm/asm-prototypes.h> 8 + 9 + #include "ptrace-decl.h" 10 + 11 + void flush_tmregs_to_thread(struct task_struct *tsk) 12 + { 13 + /* 14 + * If task is not current, it will have been flushed already to 15 + * it's thread_struct during __switch_to(). 16 + * 17 + * A reclaim flushes ALL the state or if not in TM save TM SPRs 18 + * in the appropriate thread structures from live. 19 + */ 20 + 21 + if (!cpu_has_feature(CPU_FTR_TM) || tsk != current) 22 + return; 23 + 24 + if (MSR_TM_SUSPENDED(mfmsr())) { 25 + tm_reclaim_current(TM_CAUSE_SIGNAL); 26 + } else { 27 + tm_enable(); 28 + tm_save_sprs(&tsk->thread); 29 + } 30 + } 31 + 32 + static unsigned long get_user_ckpt_msr(struct task_struct *task) 33 + { 34 + return task->thread.ckpt_regs.msr | task->thread.fpexc_mode; 35 + } 36 + 37 + static int set_user_ckpt_msr(struct task_struct *task, unsigned long msr) 38 + { 39 + task->thread.ckpt_regs.msr &= ~MSR_DEBUGCHANGE; 40 + task->thread.ckpt_regs.msr |= msr & MSR_DEBUGCHANGE; 41 + return 0; 42 + } 43 + 44 + static int set_user_ckpt_trap(struct task_struct *task, unsigned long trap) 45 + { 46 + task->thread.ckpt_regs.trap = trap & 0xfff0; 47 + return 0; 48 + } 49 + 50 + /** 51 + * tm_cgpr_active - get active number of registers in CGPR 52 + * @target: The target task. 53 + * @regset: The user regset structure. 54 + * 55 + * This function checks for the active number of available 56 + * regisers in transaction checkpointed GPR category. 57 + */ 58 + int tm_cgpr_active(struct task_struct *target, const struct user_regset *regset) 59 + { 60 + if (!cpu_has_feature(CPU_FTR_TM)) 61 + return -ENODEV; 62 + 63 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 64 + return 0; 65 + 66 + return regset->n; 67 + } 68 + 69 + /** 70 + * tm_cgpr_get - get CGPR registers 71 + * @target: The target task. 72 + * @regset: The user regset structure. 73 + * @pos: The buffer position. 74 + * @count: Number of bytes to copy. 75 + * @kbuf: Kernel buffer to copy from. 76 + * @ubuf: User buffer to copy into. 77 + * 78 + * This function gets transaction checkpointed GPR registers. 79 + * 80 + * When the transaction is active, 'ckpt_regs' holds all the checkpointed 81 + * GPR register values for the current transaction to fall back on if it 82 + * aborts in between. This function gets those checkpointed GPR registers. 83 + * The userspace interface buffer layout is as follows. 84 + * 85 + * struct data { 86 + * struct pt_regs ckpt_regs; 87 + * }; 88 + */ 89 + int tm_cgpr_get(struct task_struct *target, const struct user_regset *regset, 90 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 91 + { 92 + int ret; 93 + 94 + if (!cpu_has_feature(CPU_FTR_TM)) 95 + return -ENODEV; 96 + 97 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 98 + return -ENODATA; 99 + 100 + flush_tmregs_to_thread(target); 101 + flush_fp_to_thread(target); 102 + flush_altivec_to_thread(target); 103 + 104 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 105 + &target->thread.ckpt_regs, 106 + 0, offsetof(struct pt_regs, msr)); 107 + if (!ret) { 108 + unsigned long msr = get_user_ckpt_msr(target); 109 + 110 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr, 111 + offsetof(struct pt_regs, msr), 112 + offsetof(struct pt_regs, msr) + 113 + sizeof(msr)); 114 + } 115 + 116 + BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 117 + offsetof(struct pt_regs, msr) + sizeof(long)); 118 + 119 + if (!ret) 120 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 121 + &target->thread.ckpt_regs.orig_gpr3, 122 + offsetof(struct pt_regs, orig_gpr3), 123 + sizeof(struct user_pt_regs)); 124 + if (!ret) 125 + ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, 126 + sizeof(struct user_pt_regs), -1); 127 + 128 + return ret; 129 + } 130 + 131 + /* 132 + * tm_cgpr_set - set the CGPR registers 133 + * @target: The target task. 134 + * @regset: The user regset structure. 135 + * @pos: The buffer position. 136 + * @count: Number of bytes to copy. 137 + * @kbuf: Kernel buffer to copy into. 138 + * @ubuf: User buffer to copy from. 139 + * 140 + * This function sets in transaction checkpointed GPR registers. 141 + * 142 + * When the transaction is active, 'ckpt_regs' holds the checkpointed 143 + * GPR register values for the current transaction to fall back on if it 144 + * aborts in between. This function sets those checkpointed GPR registers. 145 + * The userspace interface buffer layout is as follows. 146 + * 147 + * struct data { 148 + * struct pt_regs ckpt_regs; 149 + * }; 150 + */ 151 + int tm_cgpr_set(struct task_struct *target, const struct user_regset *regset, 152 + unsigned int pos, unsigned int count, 153 + const void *kbuf, const void __user *ubuf) 154 + { 155 + unsigned long reg; 156 + int ret; 157 + 158 + if (!cpu_has_feature(CPU_FTR_TM)) 159 + return -ENODEV; 160 + 161 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 162 + return -ENODATA; 163 + 164 + flush_tmregs_to_thread(target); 165 + flush_fp_to_thread(target); 166 + flush_altivec_to_thread(target); 167 + 168 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 169 + &target->thread.ckpt_regs, 170 + 0, PT_MSR * sizeof(reg)); 171 + 172 + if (!ret && count > 0) { 173 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg, 174 + PT_MSR * sizeof(reg), 175 + (PT_MSR + 1) * sizeof(reg)); 176 + if (!ret) 177 + ret = set_user_ckpt_msr(target, reg); 178 + } 179 + 180 + BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 181 + offsetof(struct pt_regs, msr) + sizeof(long)); 182 + 183 + if (!ret) 184 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 185 + &target->thread.ckpt_regs.orig_gpr3, 186 + PT_ORIG_R3 * sizeof(reg), 187 + (PT_MAX_PUT_REG + 1) * sizeof(reg)); 188 + 189 + if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret) 190 + ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 191 + (PT_MAX_PUT_REG + 1) * sizeof(reg), 192 + PT_TRAP * sizeof(reg)); 193 + 194 + if (!ret && count > 0) { 195 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg, 196 + PT_TRAP * sizeof(reg), 197 + (PT_TRAP + 1) * sizeof(reg)); 198 + if (!ret) 199 + ret = set_user_ckpt_trap(target, reg); 200 + } 201 + 202 + if (!ret) 203 + ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 204 + (PT_TRAP + 1) * sizeof(reg), -1); 205 + 206 + return ret; 207 + } 208 + 209 + /** 210 + * tm_cfpr_active - get active number of registers in CFPR 211 + * @target: The target task. 212 + * @regset: The user regset structure. 213 + * 214 + * This function checks for the active number of available 215 + * regisers in transaction checkpointed FPR category. 216 + */ 217 + int tm_cfpr_active(struct task_struct *target, const struct user_regset *regset) 218 + { 219 + if (!cpu_has_feature(CPU_FTR_TM)) 220 + return -ENODEV; 221 + 222 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 223 + return 0; 224 + 225 + return regset->n; 226 + } 227 + 228 + /** 229 + * tm_cfpr_get - get CFPR registers 230 + * @target: The target task. 231 + * @regset: The user regset structure. 232 + * @pos: The buffer position. 233 + * @count: Number of bytes to copy. 234 + * @kbuf: Kernel buffer to copy from. 235 + * @ubuf: User buffer to copy into. 236 + * 237 + * This function gets in transaction checkpointed FPR registers. 238 + * 239 + * When the transaction is active 'ckfp_state' holds the checkpointed 240 + * values for the current transaction to fall back on if it aborts 241 + * in between. This function gets those checkpointed FPR registers. 242 + * The userspace interface buffer layout is as follows. 243 + * 244 + * struct data { 245 + * u64 fpr[32]; 246 + * u64 fpscr; 247 + *}; 248 + */ 249 + int tm_cfpr_get(struct task_struct *target, const struct user_regset *regset, 250 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 251 + { 252 + u64 buf[33]; 253 + int i; 254 + 255 + if (!cpu_has_feature(CPU_FTR_TM)) 256 + return -ENODEV; 257 + 258 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 259 + return -ENODATA; 260 + 261 + flush_tmregs_to_thread(target); 262 + flush_fp_to_thread(target); 263 + flush_altivec_to_thread(target); 264 + 265 + /* copy to local buffer then write that out */ 266 + for (i = 0; i < 32 ; i++) 267 + buf[i] = target->thread.TS_CKFPR(i); 268 + buf[32] = target->thread.ckfp_state.fpscr; 269 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); 270 + } 271 + 272 + /** 273 + * tm_cfpr_set - set CFPR registers 274 + * @target: The target task. 275 + * @regset: The user regset structure. 276 + * @pos: The buffer position. 277 + * @count: Number of bytes to copy. 278 + * @kbuf: Kernel buffer to copy into. 279 + * @ubuf: User buffer to copy from. 280 + * 281 + * This function sets in transaction checkpointed FPR registers. 282 + * 283 + * When the transaction is active 'ckfp_state' holds the checkpointed 284 + * FPR register values for the current transaction to fall back on 285 + * if it aborts in between. This function sets these checkpointed 286 + * FPR registers. The userspace interface buffer layout is as follows. 287 + * 288 + * struct data { 289 + * u64 fpr[32]; 290 + * u64 fpscr; 291 + *}; 292 + */ 293 + int tm_cfpr_set(struct task_struct *target, const struct user_regset *regset, 294 + unsigned int pos, unsigned int count, 295 + const void *kbuf, const void __user *ubuf) 296 + { 297 + u64 buf[33]; 298 + int i; 299 + 300 + if (!cpu_has_feature(CPU_FTR_TM)) 301 + return -ENODEV; 302 + 303 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 304 + return -ENODATA; 305 + 306 + flush_tmregs_to_thread(target); 307 + flush_fp_to_thread(target); 308 + flush_altivec_to_thread(target); 309 + 310 + for (i = 0; i < 32; i++) 311 + buf[i] = target->thread.TS_CKFPR(i); 312 + buf[32] = target->thread.ckfp_state.fpscr; 313 + 314 + /* copy to local buffer then write that out */ 315 + i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); 316 + if (i) 317 + return i; 318 + for (i = 0; i < 32 ; i++) 319 + target->thread.TS_CKFPR(i) = buf[i]; 320 + target->thread.ckfp_state.fpscr = buf[32]; 321 + return 0; 322 + } 323 + 324 + /** 325 + * tm_cvmx_active - get active number of registers in CVMX 326 + * @target: The target task. 327 + * @regset: The user regset structure. 328 + * 329 + * This function checks for the active number of available 330 + * regisers in checkpointed VMX category. 331 + */ 332 + int tm_cvmx_active(struct task_struct *target, const struct user_regset *regset) 333 + { 334 + if (!cpu_has_feature(CPU_FTR_TM)) 335 + return -ENODEV; 336 + 337 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 338 + return 0; 339 + 340 + return regset->n; 341 + } 342 + 343 + /** 344 + * tm_cvmx_get - get CMVX registers 345 + * @target: The target task. 346 + * @regset: The user regset structure. 347 + * @pos: The buffer position. 348 + * @count: Number of bytes to copy. 349 + * @kbuf: Kernel buffer to copy from. 350 + * @ubuf: User buffer to copy into. 351 + * 352 + * This function gets in transaction checkpointed VMX registers. 353 + * 354 + * When the transaction is active 'ckvr_state' and 'ckvrsave' hold 355 + * the checkpointed values for the current transaction to fall 356 + * back on if it aborts in between. The userspace interface buffer 357 + * layout is as follows. 358 + * 359 + * struct data { 360 + * vector128 vr[32]; 361 + * vector128 vscr; 362 + * vector128 vrsave; 363 + *}; 364 + */ 365 + int tm_cvmx_get(struct task_struct *target, const struct user_regset *regset, 366 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 367 + { 368 + int ret; 369 + 370 + BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32])); 371 + 372 + if (!cpu_has_feature(CPU_FTR_TM)) 373 + return -ENODEV; 374 + 375 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 376 + return -ENODATA; 377 + 378 + /* Flush the state */ 379 + flush_tmregs_to_thread(target); 380 + flush_fp_to_thread(target); 381 + flush_altivec_to_thread(target); 382 + 383 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &target->thread.ckvr_state, 384 + 0, 33 * sizeof(vector128)); 385 + if (!ret) { 386 + /* 387 + * Copy out only the low-order word of vrsave. 388 + */ 389 + union { 390 + elf_vrreg_t reg; 391 + u32 word; 392 + } vrsave; 393 + memset(&vrsave, 0, sizeof(vrsave)); 394 + vrsave.word = target->thread.ckvrsave; 395 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, 396 + 33 * sizeof(vector128), -1); 397 + } 398 + 399 + return ret; 400 + } 401 + 402 + /** 403 + * tm_cvmx_set - set CMVX registers 404 + * @target: The target task. 405 + * @regset: The user regset structure. 406 + * @pos: The buffer position. 407 + * @count: Number of bytes to copy. 408 + * @kbuf: Kernel buffer to copy into. 409 + * @ubuf: User buffer to copy from. 410 + * 411 + * This function sets in transaction checkpointed VMX registers. 412 + * 413 + * When the transaction is active 'ckvr_state' and 'ckvrsave' hold 414 + * the checkpointed values for the current transaction to fall 415 + * back on if it aborts in between. The userspace interface buffer 416 + * layout is as follows. 417 + * 418 + * struct data { 419 + * vector128 vr[32]; 420 + * vector128 vscr; 421 + * vector128 vrsave; 422 + *}; 423 + */ 424 + int tm_cvmx_set(struct task_struct *target, const struct user_regset *regset, 425 + unsigned int pos, unsigned int count, 426 + const void *kbuf, const void __user *ubuf) 427 + { 428 + int ret; 429 + 430 + BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32])); 431 + 432 + if (!cpu_has_feature(CPU_FTR_TM)) 433 + return -ENODEV; 434 + 435 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 436 + return -ENODATA; 437 + 438 + flush_tmregs_to_thread(target); 439 + flush_fp_to_thread(target); 440 + flush_altivec_to_thread(target); 441 + 442 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &target->thread.ckvr_state, 443 + 0, 33 * sizeof(vector128)); 444 + if (!ret && count > 0) { 445 + /* 446 + * We use only the low-order word of vrsave. 447 + */ 448 + union { 449 + elf_vrreg_t reg; 450 + u32 word; 451 + } vrsave; 452 + memset(&vrsave, 0, sizeof(vrsave)); 453 + vrsave.word = target->thread.ckvrsave; 454 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, 455 + 33 * sizeof(vector128), -1); 456 + if (!ret) 457 + target->thread.ckvrsave = vrsave.word; 458 + } 459 + 460 + return ret; 461 + } 462 + 463 + /** 464 + * tm_cvsx_active - get active number of registers in CVSX 465 + * @target: The target task. 466 + * @regset: The user regset structure. 467 + * 468 + * This function checks for the active number of available 469 + * regisers in transaction checkpointed VSX category. 470 + */ 471 + int tm_cvsx_active(struct task_struct *target, const struct user_regset *regset) 472 + { 473 + if (!cpu_has_feature(CPU_FTR_TM)) 474 + return -ENODEV; 475 + 476 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 477 + return 0; 478 + 479 + flush_vsx_to_thread(target); 480 + return target->thread.used_vsr ? regset->n : 0; 481 + } 482 + 483 + /** 484 + * tm_cvsx_get - get CVSX registers 485 + * @target: The target task. 486 + * @regset: The user regset structure. 487 + * @pos: The buffer position. 488 + * @count: Number of bytes to copy. 489 + * @kbuf: Kernel buffer to copy from. 490 + * @ubuf: User buffer to copy into. 491 + * 492 + * This function gets in transaction checkpointed VSX registers. 493 + * 494 + * When the transaction is active 'ckfp_state' holds the checkpointed 495 + * values for the current transaction to fall back on if it aborts 496 + * in between. This function gets those checkpointed VSX registers. 497 + * The userspace interface buffer layout is as follows. 498 + * 499 + * struct data { 500 + * u64 vsx[32]; 501 + *}; 502 + */ 503 + int tm_cvsx_get(struct task_struct *target, const struct user_regset *regset, 504 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 505 + { 506 + u64 buf[32]; 507 + int ret, i; 508 + 509 + if (!cpu_has_feature(CPU_FTR_TM)) 510 + return -ENODEV; 511 + 512 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 513 + return -ENODATA; 514 + 515 + /* Flush the state */ 516 + flush_tmregs_to_thread(target); 517 + flush_fp_to_thread(target); 518 + flush_altivec_to_thread(target); 519 + flush_vsx_to_thread(target); 520 + 521 + for (i = 0; i < 32 ; i++) 522 + buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET]; 523 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 524 + buf, 0, 32 * sizeof(double)); 525 + 526 + return ret; 527 + } 528 + 529 + /** 530 + * tm_cvsx_set - set CFPR registers 531 + * @target: The target task. 532 + * @regset: The user regset structure. 533 + * @pos: The buffer position. 534 + * @count: Number of bytes to copy. 535 + * @kbuf: Kernel buffer to copy into. 536 + * @ubuf: User buffer to copy from. 537 + * 538 + * This function sets in transaction checkpointed VSX registers. 539 + * 540 + * When the transaction is active 'ckfp_state' holds the checkpointed 541 + * VSX register values for the current transaction to fall back on 542 + * if it aborts in between. This function sets these checkpointed 543 + * FPR registers. The userspace interface buffer layout is as follows. 544 + * 545 + * struct data { 546 + * u64 vsx[32]; 547 + *}; 548 + */ 549 + int tm_cvsx_set(struct task_struct *target, const struct user_regset *regset, 550 + unsigned int pos, unsigned int count, 551 + const void *kbuf, const void __user *ubuf) 552 + { 553 + u64 buf[32]; 554 + int ret, i; 555 + 556 + if (!cpu_has_feature(CPU_FTR_TM)) 557 + return -ENODEV; 558 + 559 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 560 + return -ENODATA; 561 + 562 + /* Flush the state */ 563 + flush_tmregs_to_thread(target); 564 + flush_fp_to_thread(target); 565 + flush_altivec_to_thread(target); 566 + flush_vsx_to_thread(target); 567 + 568 + for (i = 0; i < 32 ; i++) 569 + buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET]; 570 + 571 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 572 + buf, 0, 32 * sizeof(double)); 573 + if (!ret) 574 + for (i = 0; i < 32 ; i++) 575 + target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i]; 576 + 577 + return ret; 578 + } 579 + 580 + /** 581 + * tm_spr_active - get active number of registers in TM SPR 582 + * @target: The target task. 583 + * @regset: The user regset structure. 584 + * 585 + * This function checks the active number of available 586 + * regisers in the transactional memory SPR category. 587 + */ 588 + int tm_spr_active(struct task_struct *target, const struct user_regset *regset) 589 + { 590 + if (!cpu_has_feature(CPU_FTR_TM)) 591 + return -ENODEV; 592 + 593 + return regset->n; 594 + } 595 + 596 + /** 597 + * tm_spr_get - get the TM related SPR registers 598 + * @target: The target task. 599 + * @regset: The user regset structure. 600 + * @pos: The buffer position. 601 + * @count: Number of bytes to copy. 602 + * @kbuf: Kernel buffer to copy from. 603 + * @ubuf: User buffer to copy into. 604 + * 605 + * This function gets transactional memory related SPR registers. 606 + * The userspace interface buffer layout is as follows. 607 + * 608 + * struct { 609 + * u64 tm_tfhar; 610 + * u64 tm_texasr; 611 + * u64 tm_tfiar; 612 + * }; 613 + */ 614 + int tm_spr_get(struct task_struct *target, const struct user_regset *regset, 615 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 616 + { 617 + int ret; 618 + 619 + /* Build tests */ 620 + BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr)); 621 + BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar)); 622 + BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs)); 623 + 624 + if (!cpu_has_feature(CPU_FTR_TM)) 625 + return -ENODEV; 626 + 627 + /* Flush the states */ 628 + flush_tmregs_to_thread(target); 629 + flush_fp_to_thread(target); 630 + flush_altivec_to_thread(target); 631 + 632 + /* TFHAR register */ 633 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 634 + &target->thread.tm_tfhar, 0, sizeof(u64)); 635 + 636 + /* TEXASR register */ 637 + if (!ret) 638 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 639 + &target->thread.tm_texasr, sizeof(u64), 640 + 2 * sizeof(u64)); 641 + 642 + /* TFIAR register */ 643 + if (!ret) 644 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 645 + &target->thread.tm_tfiar, 646 + 2 * sizeof(u64), 3 * sizeof(u64)); 647 + return ret; 648 + } 649 + 650 + /** 651 + * tm_spr_set - set the TM related SPR registers 652 + * @target: The target task. 653 + * @regset: The user regset structure. 654 + * @pos: The buffer position. 655 + * @count: Number of bytes to copy. 656 + * @kbuf: Kernel buffer to copy into. 657 + * @ubuf: User buffer to copy from. 658 + * 659 + * This function sets transactional memory related SPR registers. 660 + * The userspace interface buffer layout is as follows. 661 + * 662 + * struct { 663 + * u64 tm_tfhar; 664 + * u64 tm_texasr; 665 + * u64 tm_tfiar; 666 + * }; 667 + */ 668 + int tm_spr_set(struct task_struct *target, const struct user_regset *regset, 669 + unsigned int pos, unsigned int count, 670 + const void *kbuf, const void __user *ubuf) 671 + { 672 + int ret; 673 + 674 + /* Build tests */ 675 + BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr)); 676 + BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar)); 677 + BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs)); 678 + 679 + if (!cpu_has_feature(CPU_FTR_TM)) 680 + return -ENODEV; 681 + 682 + /* Flush the states */ 683 + flush_tmregs_to_thread(target); 684 + flush_fp_to_thread(target); 685 + flush_altivec_to_thread(target); 686 + 687 + /* TFHAR register */ 688 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 689 + &target->thread.tm_tfhar, 0, sizeof(u64)); 690 + 691 + /* TEXASR register */ 692 + if (!ret) 693 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 694 + &target->thread.tm_texasr, sizeof(u64), 695 + 2 * sizeof(u64)); 696 + 697 + /* TFIAR register */ 698 + if (!ret) 699 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 700 + &target->thread.tm_tfiar, 701 + 2 * sizeof(u64), 3 * sizeof(u64)); 702 + return ret; 703 + } 704 + 705 + int tm_tar_active(struct task_struct *target, const struct user_regset *regset) 706 + { 707 + if (!cpu_has_feature(CPU_FTR_TM)) 708 + return -ENODEV; 709 + 710 + if (MSR_TM_ACTIVE(target->thread.regs->msr)) 711 + return regset->n; 712 + 713 + return 0; 714 + } 715 + 716 + int tm_tar_get(struct task_struct *target, const struct user_regset *regset, 717 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 718 + { 719 + int ret; 720 + 721 + if (!cpu_has_feature(CPU_FTR_TM)) 722 + return -ENODEV; 723 + 724 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 725 + return -ENODATA; 726 + 727 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 728 + &target->thread.tm_tar, 0, sizeof(u64)); 729 + return ret; 730 + } 731 + 732 + int tm_tar_set(struct task_struct *target, const struct user_regset *regset, 733 + unsigned int pos, unsigned int count, 734 + const void *kbuf, const void __user *ubuf) 735 + { 736 + int ret; 737 + 738 + if (!cpu_has_feature(CPU_FTR_TM)) 739 + return -ENODEV; 740 + 741 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 742 + return -ENODATA; 743 + 744 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 745 + &target->thread.tm_tar, 0, sizeof(u64)); 746 + return ret; 747 + } 748 + 749 + int tm_ppr_active(struct task_struct *target, const struct user_regset *regset) 750 + { 751 + if (!cpu_has_feature(CPU_FTR_TM)) 752 + return -ENODEV; 753 + 754 + if (MSR_TM_ACTIVE(target->thread.regs->msr)) 755 + return regset->n; 756 + 757 + return 0; 758 + } 759 + 760 + 761 + int tm_ppr_get(struct task_struct *target, const struct user_regset *regset, 762 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 763 + { 764 + int ret; 765 + 766 + if (!cpu_has_feature(CPU_FTR_TM)) 767 + return -ENODEV; 768 + 769 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 770 + return -ENODATA; 771 + 772 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 773 + &target->thread.tm_ppr, 0, sizeof(u64)); 774 + return ret; 775 + } 776 + 777 + int tm_ppr_set(struct task_struct *target, const struct user_regset *regset, 778 + unsigned int pos, unsigned int count, 779 + const void *kbuf, const void __user *ubuf) 780 + { 781 + int ret; 782 + 783 + if (!cpu_has_feature(CPU_FTR_TM)) 784 + return -ENODEV; 785 + 786 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 787 + return -ENODATA; 788 + 789 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 790 + &target->thread.tm_ppr, 0, sizeof(u64)); 791 + return ret; 792 + } 793 + 794 + int tm_dscr_active(struct task_struct *target, const struct user_regset *regset) 795 + { 796 + if (!cpu_has_feature(CPU_FTR_TM)) 797 + return -ENODEV; 798 + 799 + if (MSR_TM_ACTIVE(target->thread.regs->msr)) 800 + return regset->n; 801 + 802 + return 0; 803 + } 804 + 805 + int tm_dscr_get(struct task_struct *target, const struct user_regset *regset, 806 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 807 + { 808 + int ret; 809 + 810 + if (!cpu_has_feature(CPU_FTR_TM)) 811 + return -ENODEV; 812 + 813 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 814 + return -ENODATA; 815 + 816 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 817 + &target->thread.tm_dscr, 0, sizeof(u64)); 818 + return ret; 819 + } 820 + 821 + int tm_dscr_set(struct task_struct *target, const struct user_regset *regset, 822 + unsigned int pos, unsigned int count, 823 + const void *kbuf, const void __user *ubuf) 824 + { 825 + int ret; 826 + 827 + if (!cpu_has_feature(CPU_FTR_TM)) 828 + return -ENODEV; 829 + 830 + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) 831 + return -ENODATA; 832 + 833 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 834 + &target->thread.tm_dscr, 0, sizeof(u64)); 835 + return ret; 836 + } 837 + 838 + int tm_cgpr32_get(struct task_struct *target, const struct user_regset *regset, 839 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 840 + { 841 + return gpr32_get_common(target, regset, pos, count, kbuf, ubuf, 842 + &target->thread.ckpt_regs.gpr[0]); 843 + } 844 + 845 + int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset, 846 + unsigned int pos, unsigned int count, 847 + const void *kbuf, const void __user *ubuf) 848 + { 849 + return gpr32_set_common(target, regset, pos, count, kbuf, ubuf, 850 + &target->thread.ckpt_regs.gpr[0]); 851 + }
+904
arch/powerpc/kernel/ptrace/ptrace-view.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/regset.h> 4 + #include <linux/elf.h> 5 + #include <linux/nospec.h> 6 + #include <linux/pkeys.h> 7 + 8 + #include "ptrace-decl.h" 9 + 10 + struct pt_regs_offset { 11 + const char *name; 12 + int offset; 13 + }; 14 + 15 + #define STR(s) #s /* convert to string */ 16 + #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)} 17 + #define GPR_OFFSET_NAME(num) \ 18 + {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \ 19 + {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])} 20 + #define REG_OFFSET_END {.name = NULL, .offset = 0} 21 + 22 + static const struct pt_regs_offset regoffset_table[] = { 23 + GPR_OFFSET_NAME(0), 24 + GPR_OFFSET_NAME(1), 25 + GPR_OFFSET_NAME(2), 26 + GPR_OFFSET_NAME(3), 27 + GPR_OFFSET_NAME(4), 28 + GPR_OFFSET_NAME(5), 29 + GPR_OFFSET_NAME(6), 30 + GPR_OFFSET_NAME(7), 31 + GPR_OFFSET_NAME(8), 32 + GPR_OFFSET_NAME(9), 33 + GPR_OFFSET_NAME(10), 34 + GPR_OFFSET_NAME(11), 35 + GPR_OFFSET_NAME(12), 36 + GPR_OFFSET_NAME(13), 37 + GPR_OFFSET_NAME(14), 38 + GPR_OFFSET_NAME(15), 39 + GPR_OFFSET_NAME(16), 40 + GPR_OFFSET_NAME(17), 41 + GPR_OFFSET_NAME(18), 42 + GPR_OFFSET_NAME(19), 43 + GPR_OFFSET_NAME(20), 44 + GPR_OFFSET_NAME(21), 45 + GPR_OFFSET_NAME(22), 46 + GPR_OFFSET_NAME(23), 47 + GPR_OFFSET_NAME(24), 48 + GPR_OFFSET_NAME(25), 49 + GPR_OFFSET_NAME(26), 50 + GPR_OFFSET_NAME(27), 51 + GPR_OFFSET_NAME(28), 52 + GPR_OFFSET_NAME(29), 53 + GPR_OFFSET_NAME(30), 54 + GPR_OFFSET_NAME(31), 55 + REG_OFFSET_NAME(nip), 56 + REG_OFFSET_NAME(msr), 57 + REG_OFFSET_NAME(ctr), 58 + REG_OFFSET_NAME(link), 59 + REG_OFFSET_NAME(xer), 60 + REG_OFFSET_NAME(ccr), 61 + #ifdef CONFIG_PPC64 62 + REG_OFFSET_NAME(softe), 63 + #else 64 + REG_OFFSET_NAME(mq), 65 + #endif 66 + REG_OFFSET_NAME(trap), 67 + REG_OFFSET_NAME(dar), 68 + REG_OFFSET_NAME(dsisr), 69 + REG_OFFSET_END, 70 + }; 71 + 72 + /** 73 + * regs_query_register_offset() - query register offset from its name 74 + * @name: the name of a register 75 + * 76 + * regs_query_register_offset() returns the offset of a register in struct 77 + * pt_regs from its name. If the name is invalid, this returns -EINVAL; 78 + */ 79 + int regs_query_register_offset(const char *name) 80 + { 81 + const struct pt_regs_offset *roff; 82 + for (roff = regoffset_table; roff->name != NULL; roff++) 83 + if (!strcmp(roff->name, name)) 84 + return roff->offset; 85 + return -EINVAL; 86 + } 87 + 88 + /** 89 + * regs_query_register_name() - query register name from its offset 90 + * @offset: the offset of a register in struct pt_regs. 91 + * 92 + * regs_query_register_name() returns the name of a register from its 93 + * offset in struct pt_regs. If the @offset is invalid, this returns NULL; 94 + */ 95 + const char *regs_query_register_name(unsigned int offset) 96 + { 97 + const struct pt_regs_offset *roff; 98 + for (roff = regoffset_table; roff->name != NULL; roff++) 99 + if (roff->offset == offset) 100 + return roff->name; 101 + return NULL; 102 + } 103 + 104 + /* 105 + * does not yet catch signals sent when the child dies. 106 + * in exit.c or in signal.c. 107 + */ 108 + 109 + static unsigned long get_user_msr(struct task_struct *task) 110 + { 111 + return task->thread.regs->msr | task->thread.fpexc_mode; 112 + } 113 + 114 + static int set_user_msr(struct task_struct *task, unsigned long msr) 115 + { 116 + task->thread.regs->msr &= ~MSR_DEBUGCHANGE; 117 + task->thread.regs->msr |= msr & MSR_DEBUGCHANGE; 118 + return 0; 119 + } 120 + 121 + #ifdef CONFIG_PPC64 122 + static int get_user_dscr(struct task_struct *task, unsigned long *data) 123 + { 124 + *data = task->thread.dscr; 125 + return 0; 126 + } 127 + 128 + static int set_user_dscr(struct task_struct *task, unsigned long dscr) 129 + { 130 + task->thread.dscr = dscr; 131 + task->thread.dscr_inherit = 1; 132 + return 0; 133 + } 134 + #else 135 + static int get_user_dscr(struct task_struct *task, unsigned long *data) 136 + { 137 + return -EIO; 138 + } 139 + 140 + static int set_user_dscr(struct task_struct *task, unsigned long dscr) 141 + { 142 + return -EIO; 143 + } 144 + #endif 145 + 146 + /* 147 + * We prevent mucking around with the reserved area of trap 148 + * which are used internally by the kernel. 149 + */ 150 + static int set_user_trap(struct task_struct *task, unsigned long trap) 151 + { 152 + task->thread.regs->trap = trap & 0xfff0; 153 + return 0; 154 + } 155 + 156 + /* 157 + * Get contents of register REGNO in task TASK. 158 + */ 159 + int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data) 160 + { 161 + unsigned int regs_max; 162 + 163 + if (task->thread.regs == NULL || !data) 164 + return -EIO; 165 + 166 + if (regno == PT_MSR) { 167 + *data = get_user_msr(task); 168 + return 0; 169 + } 170 + 171 + if (regno == PT_DSCR) 172 + return get_user_dscr(task, data); 173 + 174 + /* 175 + * softe copies paca->irq_soft_mask variable state. Since irq_soft_mask is 176 + * no more used as a flag, lets force usr to alway see the softe value as 1 177 + * which means interrupts are not soft disabled. 178 + */ 179 + if (IS_ENABLED(CONFIG_PPC64) && regno == PT_SOFTE) { 180 + *data = 1; 181 + return 0; 182 + } 183 + 184 + regs_max = sizeof(struct user_pt_regs) / sizeof(unsigned long); 185 + if (regno < regs_max) { 186 + regno = array_index_nospec(regno, regs_max); 187 + *data = ((unsigned long *)task->thread.regs)[regno]; 188 + return 0; 189 + } 190 + 191 + return -EIO; 192 + } 193 + 194 + /* 195 + * Write contents of register REGNO in task TASK. 196 + */ 197 + int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data) 198 + { 199 + if (task->thread.regs == NULL) 200 + return -EIO; 201 + 202 + if (regno == PT_MSR) 203 + return set_user_msr(task, data); 204 + if (regno == PT_TRAP) 205 + return set_user_trap(task, data); 206 + if (regno == PT_DSCR) 207 + return set_user_dscr(task, data); 208 + 209 + if (regno <= PT_MAX_PUT_REG) { 210 + regno = array_index_nospec(regno, PT_MAX_PUT_REG + 1); 211 + ((unsigned long *)task->thread.regs)[regno] = data; 212 + return 0; 213 + } 214 + return -EIO; 215 + } 216 + 217 + static int gpr_get(struct task_struct *target, const struct user_regset *regset, 218 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 219 + { 220 + int i, ret; 221 + 222 + if (target->thread.regs == NULL) 223 + return -EIO; 224 + 225 + if (!FULL_REGS(target->thread.regs)) { 226 + /* We have a partial register set. Fill 14-31 with bogus values */ 227 + for (i = 14; i < 32; i++) 228 + target->thread.regs->gpr[i] = NV_REG_POISON; 229 + } 230 + 231 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 232 + target->thread.regs, 233 + 0, offsetof(struct pt_regs, msr)); 234 + if (!ret) { 235 + unsigned long msr = get_user_msr(target); 236 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr, 237 + offsetof(struct pt_regs, msr), 238 + offsetof(struct pt_regs, msr) + 239 + sizeof(msr)); 240 + } 241 + 242 + BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 243 + offsetof(struct pt_regs, msr) + sizeof(long)); 244 + 245 + if (!ret) 246 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 247 + &target->thread.regs->orig_gpr3, 248 + offsetof(struct pt_regs, orig_gpr3), 249 + sizeof(struct user_pt_regs)); 250 + if (!ret) 251 + ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, 252 + sizeof(struct user_pt_regs), -1); 253 + 254 + return ret; 255 + } 256 + 257 + static int gpr_set(struct task_struct *target, const struct user_regset *regset, 258 + unsigned int pos, unsigned int count, const void *kbuf, 259 + const void __user *ubuf) 260 + { 261 + unsigned long reg; 262 + int ret; 263 + 264 + if (target->thread.regs == NULL) 265 + return -EIO; 266 + 267 + CHECK_FULL_REGS(target->thread.regs); 268 + 269 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 270 + target->thread.regs, 271 + 0, PT_MSR * sizeof(reg)); 272 + 273 + if (!ret && count > 0) { 274 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg, 275 + PT_MSR * sizeof(reg), 276 + (PT_MSR + 1) * sizeof(reg)); 277 + if (!ret) 278 + ret = set_user_msr(target, reg); 279 + } 280 + 281 + BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 282 + offsetof(struct pt_regs, msr) + sizeof(long)); 283 + 284 + if (!ret) 285 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 286 + &target->thread.regs->orig_gpr3, 287 + PT_ORIG_R3 * sizeof(reg), 288 + (PT_MAX_PUT_REG + 1) * sizeof(reg)); 289 + 290 + if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret) 291 + ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 292 + (PT_MAX_PUT_REG + 1) * sizeof(reg), 293 + PT_TRAP * sizeof(reg)); 294 + 295 + if (!ret && count > 0) { 296 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg, 297 + PT_TRAP * sizeof(reg), 298 + (PT_TRAP + 1) * sizeof(reg)); 299 + if (!ret) 300 + ret = set_user_trap(target, reg); 301 + } 302 + 303 + if (!ret) 304 + ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 305 + (PT_TRAP + 1) * sizeof(reg), -1); 306 + 307 + return ret; 308 + } 309 + 310 + #ifdef CONFIG_PPC64 311 + static int ppr_get(struct task_struct *target, const struct user_regset *regset, 312 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 313 + { 314 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 315 + &target->thread.regs->ppr, 0, sizeof(u64)); 316 + } 317 + 318 + static int ppr_set(struct task_struct *target, const struct user_regset *regset, 319 + unsigned int pos, unsigned int count, const void *kbuf, 320 + const void __user *ubuf) 321 + { 322 + return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 323 + &target->thread.regs->ppr, 0, sizeof(u64)); 324 + } 325 + 326 + static int dscr_get(struct task_struct *target, const struct user_regset *regset, 327 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 328 + { 329 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 330 + &target->thread.dscr, 0, sizeof(u64)); 331 + } 332 + static int dscr_set(struct task_struct *target, const struct user_regset *regset, 333 + unsigned int pos, unsigned int count, const void *kbuf, 334 + const void __user *ubuf) 335 + { 336 + return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 337 + &target->thread.dscr, 0, sizeof(u64)); 338 + } 339 + #endif 340 + #ifdef CONFIG_PPC_BOOK3S_64 341 + static int tar_get(struct task_struct *target, const struct user_regset *regset, 342 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 343 + { 344 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 345 + &target->thread.tar, 0, sizeof(u64)); 346 + } 347 + static int tar_set(struct task_struct *target, const struct user_regset *regset, 348 + unsigned int pos, unsigned int count, const void *kbuf, 349 + const void __user *ubuf) 350 + { 351 + return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 352 + &target->thread.tar, 0, sizeof(u64)); 353 + } 354 + 355 + static int ebb_active(struct task_struct *target, const struct user_regset *regset) 356 + { 357 + if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 358 + return -ENODEV; 359 + 360 + if (target->thread.used_ebb) 361 + return regset->n; 362 + 363 + return 0; 364 + } 365 + 366 + static int ebb_get(struct task_struct *target, const struct user_regset *regset, 367 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 368 + { 369 + /* Build tests */ 370 + BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr)); 371 + BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr)); 372 + 373 + if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 374 + return -ENODEV; 375 + 376 + if (!target->thread.used_ebb) 377 + return -ENODATA; 378 + 379 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &target->thread.ebbrr, 380 + 0, 3 * sizeof(unsigned long)); 381 + } 382 + 383 + static int ebb_set(struct task_struct *target, const struct user_regset *regset, 384 + unsigned int pos, unsigned int count, const void *kbuf, 385 + const void __user *ubuf) 386 + { 387 + int ret = 0; 388 + 389 + /* Build tests */ 390 + BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr)); 391 + BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr)); 392 + 393 + if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 394 + return -ENODEV; 395 + 396 + if (target->thread.used_ebb) 397 + return -ENODATA; 398 + 399 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &target->thread.ebbrr, 400 + 0, sizeof(unsigned long)); 401 + 402 + if (!ret) 403 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 404 + &target->thread.ebbhr, sizeof(unsigned long), 405 + 2 * sizeof(unsigned long)); 406 + 407 + if (!ret) 408 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 409 + &target->thread.bescr, 2 * sizeof(unsigned long), 410 + 3 * sizeof(unsigned long)); 411 + 412 + return ret; 413 + } 414 + static int pmu_active(struct task_struct *target, const struct user_regset *regset) 415 + { 416 + if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 417 + return -ENODEV; 418 + 419 + return regset->n; 420 + } 421 + 422 + static int pmu_get(struct task_struct *target, const struct user_regset *regset, 423 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 424 + { 425 + /* Build tests */ 426 + BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar)); 427 + BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier)); 428 + BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2)); 429 + BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0)); 430 + 431 + if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 432 + return -ENODEV; 433 + 434 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &target->thread.siar, 435 + 0, 5 * sizeof(unsigned long)); 436 + } 437 + 438 + static int pmu_set(struct task_struct *target, const struct user_regset *regset, 439 + unsigned int pos, unsigned int count, const void *kbuf, 440 + const void __user *ubuf) 441 + { 442 + int ret = 0; 443 + 444 + /* Build tests */ 445 + BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar)); 446 + BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier)); 447 + BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2)); 448 + BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0)); 449 + 450 + if (!cpu_has_feature(CPU_FTR_ARCH_207S)) 451 + return -ENODEV; 452 + 453 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &target->thread.siar, 454 + 0, sizeof(unsigned long)); 455 + 456 + if (!ret) 457 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 458 + &target->thread.sdar, sizeof(unsigned long), 459 + 2 * sizeof(unsigned long)); 460 + 461 + if (!ret) 462 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 463 + &target->thread.sier, 2 * sizeof(unsigned long), 464 + 3 * sizeof(unsigned long)); 465 + 466 + if (!ret) 467 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 468 + &target->thread.mmcr2, 3 * sizeof(unsigned long), 469 + 4 * sizeof(unsigned long)); 470 + 471 + if (!ret) 472 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 473 + &target->thread.mmcr0, 4 * sizeof(unsigned long), 474 + 5 * sizeof(unsigned long)); 475 + return ret; 476 + } 477 + #endif 478 + 479 + #ifdef CONFIG_PPC_MEM_KEYS 480 + static int pkey_active(struct task_struct *target, const struct user_regset *regset) 481 + { 482 + if (!arch_pkeys_enabled()) 483 + return -ENODEV; 484 + 485 + return regset->n; 486 + } 487 + 488 + static int pkey_get(struct task_struct *target, const struct user_regset *regset, 489 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 490 + { 491 + BUILD_BUG_ON(TSO(amr) + sizeof(unsigned long) != TSO(iamr)); 492 + BUILD_BUG_ON(TSO(iamr) + sizeof(unsigned long) != TSO(uamor)); 493 + 494 + if (!arch_pkeys_enabled()) 495 + return -ENODEV; 496 + 497 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &target->thread.amr, 498 + 0, ELF_NPKEY * sizeof(unsigned long)); 499 + } 500 + 501 + static int pkey_set(struct task_struct *target, const struct user_regset *regset, 502 + unsigned int pos, unsigned int count, const void *kbuf, 503 + const void __user *ubuf) 504 + { 505 + u64 new_amr; 506 + int ret; 507 + 508 + if (!arch_pkeys_enabled()) 509 + return -ENODEV; 510 + 511 + /* Only the AMR can be set from userspace */ 512 + if (pos != 0 || count != sizeof(new_amr)) 513 + return -EINVAL; 514 + 515 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 516 + &new_amr, 0, sizeof(new_amr)); 517 + if (ret) 518 + return ret; 519 + 520 + /* UAMOR determines which bits of the AMR can be set from userspace. */ 521 + target->thread.amr = (new_amr & target->thread.uamor) | 522 + (target->thread.amr & ~target->thread.uamor); 523 + 524 + return 0; 525 + } 526 + #endif /* CONFIG_PPC_MEM_KEYS */ 527 + 528 + static const struct user_regset native_regsets[] = { 529 + [REGSET_GPR] = { 530 + .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, 531 + .size = sizeof(long), .align = sizeof(long), 532 + .get = gpr_get, .set = gpr_set 533 + }, 534 + [REGSET_FPR] = { 535 + .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, 536 + .size = sizeof(double), .align = sizeof(double), 537 + .get = fpr_get, .set = fpr_set 538 + }, 539 + #ifdef CONFIG_ALTIVEC 540 + [REGSET_VMX] = { 541 + .core_note_type = NT_PPC_VMX, .n = 34, 542 + .size = sizeof(vector128), .align = sizeof(vector128), 543 + .active = vr_active, .get = vr_get, .set = vr_set 544 + }, 545 + #endif 546 + #ifdef CONFIG_VSX 547 + [REGSET_VSX] = { 548 + .core_note_type = NT_PPC_VSX, .n = 32, 549 + .size = sizeof(double), .align = sizeof(double), 550 + .active = vsr_active, .get = vsr_get, .set = vsr_set 551 + }, 552 + #endif 553 + #ifdef CONFIG_SPE 554 + [REGSET_SPE] = { 555 + .core_note_type = NT_PPC_SPE, .n = 35, 556 + .size = sizeof(u32), .align = sizeof(u32), 557 + .active = evr_active, .get = evr_get, .set = evr_set 558 + }, 559 + #endif 560 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 561 + [REGSET_TM_CGPR] = { 562 + .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG, 563 + .size = sizeof(long), .align = sizeof(long), 564 + .active = tm_cgpr_active, .get = tm_cgpr_get, .set = tm_cgpr_set 565 + }, 566 + [REGSET_TM_CFPR] = { 567 + .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG, 568 + .size = sizeof(double), .align = sizeof(double), 569 + .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set 570 + }, 571 + [REGSET_TM_CVMX] = { 572 + .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX, 573 + .size = sizeof(vector128), .align = sizeof(vector128), 574 + .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set 575 + }, 576 + [REGSET_TM_CVSX] = { 577 + .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX, 578 + .size = sizeof(double), .align = sizeof(double), 579 + .active = tm_cvsx_active, .get = tm_cvsx_get, .set = tm_cvsx_set 580 + }, 581 + [REGSET_TM_SPR] = { 582 + .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG, 583 + .size = sizeof(u64), .align = sizeof(u64), 584 + .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set 585 + }, 586 + [REGSET_TM_CTAR] = { 587 + .core_note_type = NT_PPC_TM_CTAR, .n = 1, 588 + .size = sizeof(u64), .align = sizeof(u64), 589 + .active = tm_tar_active, .get = tm_tar_get, .set = tm_tar_set 590 + }, 591 + [REGSET_TM_CPPR] = { 592 + .core_note_type = NT_PPC_TM_CPPR, .n = 1, 593 + .size = sizeof(u64), .align = sizeof(u64), 594 + .active = tm_ppr_active, .get = tm_ppr_get, .set = tm_ppr_set 595 + }, 596 + [REGSET_TM_CDSCR] = { 597 + .core_note_type = NT_PPC_TM_CDSCR, .n = 1, 598 + .size = sizeof(u64), .align = sizeof(u64), 599 + .active = tm_dscr_active, .get = tm_dscr_get, .set = tm_dscr_set 600 + }, 601 + #endif 602 + #ifdef CONFIG_PPC64 603 + [REGSET_PPR] = { 604 + .core_note_type = NT_PPC_PPR, .n = 1, 605 + .size = sizeof(u64), .align = sizeof(u64), 606 + .get = ppr_get, .set = ppr_set 607 + }, 608 + [REGSET_DSCR] = { 609 + .core_note_type = NT_PPC_DSCR, .n = 1, 610 + .size = sizeof(u64), .align = sizeof(u64), 611 + .get = dscr_get, .set = dscr_set 612 + }, 613 + #endif 614 + #ifdef CONFIG_PPC_BOOK3S_64 615 + [REGSET_TAR] = { 616 + .core_note_type = NT_PPC_TAR, .n = 1, 617 + .size = sizeof(u64), .align = sizeof(u64), 618 + .get = tar_get, .set = tar_set 619 + }, 620 + [REGSET_EBB] = { 621 + .core_note_type = NT_PPC_EBB, .n = ELF_NEBB, 622 + .size = sizeof(u64), .align = sizeof(u64), 623 + .active = ebb_active, .get = ebb_get, .set = ebb_set 624 + }, 625 + [REGSET_PMR] = { 626 + .core_note_type = NT_PPC_PMU, .n = ELF_NPMU, 627 + .size = sizeof(u64), .align = sizeof(u64), 628 + .active = pmu_active, .get = pmu_get, .set = pmu_set 629 + }, 630 + #endif 631 + #ifdef CONFIG_PPC_MEM_KEYS 632 + [REGSET_PKEY] = { 633 + .core_note_type = NT_PPC_PKEY, .n = ELF_NPKEY, 634 + .size = sizeof(u64), .align = sizeof(u64), 635 + .active = pkey_active, .get = pkey_get, .set = pkey_set 636 + }, 637 + #endif 638 + }; 639 + 640 + const struct user_regset_view user_ppc_native_view = { 641 + .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI, 642 + .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets) 643 + }; 644 + 645 + #include <linux/compat.h> 646 + 647 + int gpr32_get_common(struct task_struct *target, 648 + const struct user_regset *regset, 649 + unsigned int pos, unsigned int count, 650 + void *kbuf, void __user *ubuf, 651 + unsigned long *regs) 652 + { 653 + compat_ulong_t *k = kbuf; 654 + compat_ulong_t __user *u = ubuf; 655 + compat_ulong_t reg; 656 + 657 + pos /= sizeof(reg); 658 + count /= sizeof(reg); 659 + 660 + if (kbuf) 661 + for (; count > 0 && pos < PT_MSR; --count) 662 + *k++ = regs[pos++]; 663 + else 664 + for (; count > 0 && pos < PT_MSR; --count) 665 + if (__put_user((compat_ulong_t)regs[pos++], u++)) 666 + return -EFAULT; 667 + 668 + if (count > 0 && pos == PT_MSR) { 669 + reg = get_user_msr(target); 670 + if (kbuf) 671 + *k++ = reg; 672 + else if (__put_user(reg, u++)) 673 + return -EFAULT; 674 + ++pos; 675 + --count; 676 + } 677 + 678 + if (kbuf) 679 + for (; count > 0 && pos < PT_REGS_COUNT; --count) 680 + *k++ = regs[pos++]; 681 + else 682 + for (; count > 0 && pos < PT_REGS_COUNT; --count) 683 + if (__put_user((compat_ulong_t)regs[pos++], u++)) 684 + return -EFAULT; 685 + 686 + kbuf = k; 687 + ubuf = u; 688 + pos *= sizeof(reg); 689 + count *= sizeof(reg); 690 + return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, 691 + PT_REGS_COUNT * sizeof(reg), -1); 692 + } 693 + 694 + int gpr32_set_common(struct task_struct *target, 695 + const struct user_regset *regset, 696 + unsigned int pos, unsigned int count, 697 + const void *kbuf, const void __user *ubuf, 698 + unsigned long *regs) 699 + { 700 + const compat_ulong_t *k = kbuf; 701 + const compat_ulong_t __user *u = ubuf; 702 + compat_ulong_t reg; 703 + 704 + pos /= sizeof(reg); 705 + count /= sizeof(reg); 706 + 707 + if (kbuf) 708 + for (; count > 0 && pos < PT_MSR; --count) 709 + regs[pos++] = *k++; 710 + else 711 + for (; count > 0 && pos < PT_MSR; --count) { 712 + if (__get_user(reg, u++)) 713 + return -EFAULT; 714 + regs[pos++] = reg; 715 + } 716 + 717 + 718 + if (count > 0 && pos == PT_MSR) { 719 + if (kbuf) 720 + reg = *k++; 721 + else if (__get_user(reg, u++)) 722 + return -EFAULT; 723 + set_user_msr(target, reg); 724 + ++pos; 725 + --count; 726 + } 727 + 728 + if (kbuf) { 729 + for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) 730 + regs[pos++] = *k++; 731 + for (; count > 0 && pos < PT_TRAP; --count, ++pos) 732 + ++k; 733 + } else { 734 + for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) { 735 + if (__get_user(reg, u++)) 736 + return -EFAULT; 737 + regs[pos++] = reg; 738 + } 739 + for (; count > 0 && pos < PT_TRAP; --count, ++pos) 740 + if (__get_user(reg, u++)) 741 + return -EFAULT; 742 + } 743 + 744 + if (count > 0 && pos == PT_TRAP) { 745 + if (kbuf) 746 + reg = *k++; 747 + else if (__get_user(reg, u++)) 748 + return -EFAULT; 749 + set_user_trap(target, reg); 750 + ++pos; 751 + --count; 752 + } 753 + 754 + kbuf = k; 755 + ubuf = u; 756 + pos *= sizeof(reg); 757 + count *= sizeof(reg); 758 + return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 759 + (PT_TRAP + 1) * sizeof(reg), -1); 760 + } 761 + 762 + static int gpr32_get(struct task_struct *target, 763 + const struct user_regset *regset, 764 + unsigned int pos, unsigned int count, 765 + void *kbuf, void __user *ubuf) 766 + { 767 + int i; 768 + 769 + if (target->thread.regs == NULL) 770 + return -EIO; 771 + 772 + if (!FULL_REGS(target->thread.regs)) { 773 + /* 774 + * We have a partial register set. 775 + * Fill 14-31 with bogus values. 776 + */ 777 + for (i = 14; i < 32; i++) 778 + target->thread.regs->gpr[i] = NV_REG_POISON; 779 + } 780 + return gpr32_get_common(target, regset, pos, count, kbuf, ubuf, 781 + &target->thread.regs->gpr[0]); 782 + } 783 + 784 + static int gpr32_set(struct task_struct *target, 785 + const struct user_regset *regset, 786 + unsigned int pos, unsigned int count, 787 + const void *kbuf, const void __user *ubuf) 788 + { 789 + if (target->thread.regs == NULL) 790 + return -EIO; 791 + 792 + CHECK_FULL_REGS(target->thread.regs); 793 + return gpr32_set_common(target, regset, pos, count, kbuf, ubuf, 794 + &target->thread.regs->gpr[0]); 795 + } 796 + 797 + /* 798 + * These are the regset flavors matching the CONFIG_PPC32 native set. 799 + */ 800 + static const struct user_regset compat_regsets[] = { 801 + [REGSET_GPR] = { 802 + .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, 803 + .size = sizeof(compat_long_t), .align = sizeof(compat_long_t), 804 + .get = gpr32_get, .set = gpr32_set 805 + }, 806 + [REGSET_FPR] = { 807 + .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, 808 + .size = sizeof(double), .align = sizeof(double), 809 + .get = fpr_get, .set = fpr_set 810 + }, 811 + #ifdef CONFIG_ALTIVEC 812 + [REGSET_VMX] = { 813 + .core_note_type = NT_PPC_VMX, .n = 34, 814 + .size = sizeof(vector128), .align = sizeof(vector128), 815 + .active = vr_active, .get = vr_get, .set = vr_set 816 + }, 817 + #endif 818 + #ifdef CONFIG_SPE 819 + [REGSET_SPE] = { 820 + .core_note_type = NT_PPC_SPE, .n = 35, 821 + .size = sizeof(u32), .align = sizeof(u32), 822 + .active = evr_active, .get = evr_get, .set = evr_set 823 + }, 824 + #endif 825 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 826 + [REGSET_TM_CGPR] = { 827 + .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG, 828 + .size = sizeof(long), .align = sizeof(long), 829 + .active = tm_cgpr_active, 830 + .get = tm_cgpr32_get, .set = tm_cgpr32_set 831 + }, 832 + [REGSET_TM_CFPR] = { 833 + .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG, 834 + .size = sizeof(double), .align = sizeof(double), 835 + .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set 836 + }, 837 + [REGSET_TM_CVMX] = { 838 + .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX, 839 + .size = sizeof(vector128), .align = sizeof(vector128), 840 + .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set 841 + }, 842 + [REGSET_TM_CVSX] = { 843 + .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX, 844 + .size = sizeof(double), .align = sizeof(double), 845 + .active = tm_cvsx_active, .get = tm_cvsx_get, .set = tm_cvsx_set 846 + }, 847 + [REGSET_TM_SPR] = { 848 + .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG, 849 + .size = sizeof(u64), .align = sizeof(u64), 850 + .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set 851 + }, 852 + [REGSET_TM_CTAR] = { 853 + .core_note_type = NT_PPC_TM_CTAR, .n = 1, 854 + .size = sizeof(u64), .align = sizeof(u64), 855 + .active = tm_tar_active, .get = tm_tar_get, .set = tm_tar_set 856 + }, 857 + [REGSET_TM_CPPR] = { 858 + .core_note_type = NT_PPC_TM_CPPR, .n = 1, 859 + .size = sizeof(u64), .align = sizeof(u64), 860 + .active = tm_ppr_active, .get = tm_ppr_get, .set = tm_ppr_set 861 + }, 862 + [REGSET_TM_CDSCR] = { 863 + .core_note_type = NT_PPC_TM_CDSCR, .n = 1, 864 + .size = sizeof(u64), .align = sizeof(u64), 865 + .active = tm_dscr_active, .get = tm_dscr_get, .set = tm_dscr_set 866 + }, 867 + #endif 868 + #ifdef CONFIG_PPC64 869 + [REGSET_PPR] = { 870 + .core_note_type = NT_PPC_PPR, .n = 1, 871 + .size = sizeof(u64), .align = sizeof(u64), 872 + .get = ppr_get, .set = ppr_set 873 + }, 874 + [REGSET_DSCR] = { 875 + .core_note_type = NT_PPC_DSCR, .n = 1, 876 + .size = sizeof(u64), .align = sizeof(u64), 877 + .get = dscr_get, .set = dscr_set 878 + }, 879 + #endif 880 + #ifdef CONFIG_PPC_BOOK3S_64 881 + [REGSET_TAR] = { 882 + .core_note_type = NT_PPC_TAR, .n = 1, 883 + .size = sizeof(u64), .align = sizeof(u64), 884 + .get = tar_get, .set = tar_set 885 + }, 886 + [REGSET_EBB] = { 887 + .core_note_type = NT_PPC_EBB, .n = ELF_NEBB, 888 + .size = sizeof(u64), .align = sizeof(u64), 889 + .active = ebb_active, .get = ebb_get, .set = ebb_set 890 + }, 891 + #endif 892 + }; 893 + 894 + static const struct user_regset_view user_ppc_compat_view = { 895 + .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI, 896 + .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets) 897 + }; 898 + 899 + const struct user_regset_view *task_user_regset_view(struct task_struct *task) 900 + { 901 + if (IS_ENABLED(CONFIG_PPC64) && test_tsk_thread_flag(task, TIF_32BIT)) 902 + return &user_ppc_compat_view; 903 + return &user_ppc_native_view; 904 + }
+151
arch/powerpc/kernel/ptrace/ptrace-vsx.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/regset.h> 4 + 5 + #include <asm/switch_to.h> 6 + 7 + #include "ptrace-decl.h" 8 + 9 + /* 10 + * Regardless of transactions, 'fp_state' holds the current running 11 + * value of all FPR registers and 'ckfp_state' holds the last checkpointed 12 + * value of all FPR registers for the current transaction. 13 + * 14 + * Userspace interface buffer layout: 15 + * 16 + * struct data { 17 + * u64 fpr[32]; 18 + * u64 fpscr; 19 + * }; 20 + */ 21 + int fpr_get(struct task_struct *target, const struct user_regset *regset, 22 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 23 + { 24 + u64 buf[33]; 25 + int i; 26 + 27 + flush_fp_to_thread(target); 28 + 29 + /* copy to local buffer then write that out */ 30 + for (i = 0; i < 32 ; i++) 31 + buf[i] = target->thread.TS_FPR(i); 32 + buf[32] = target->thread.fp_state.fpscr; 33 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); 34 + } 35 + 36 + /* 37 + * Regardless of transactions, 'fp_state' holds the current running 38 + * value of all FPR registers and 'ckfp_state' holds the last checkpointed 39 + * value of all FPR registers for the current transaction. 40 + * 41 + * Userspace interface buffer layout: 42 + * 43 + * struct data { 44 + * u64 fpr[32]; 45 + * u64 fpscr; 46 + * }; 47 + * 48 + */ 49 + int fpr_set(struct task_struct *target, const struct user_regset *regset, 50 + unsigned int pos, unsigned int count, 51 + const void *kbuf, const void __user *ubuf) 52 + { 53 + u64 buf[33]; 54 + int i; 55 + 56 + flush_fp_to_thread(target); 57 + 58 + for (i = 0; i < 32 ; i++) 59 + buf[i] = target->thread.TS_FPR(i); 60 + buf[32] = target->thread.fp_state.fpscr; 61 + 62 + /* copy to local buffer then write that out */ 63 + i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); 64 + if (i) 65 + return i; 66 + 67 + for (i = 0; i < 32 ; i++) 68 + target->thread.TS_FPR(i) = buf[i]; 69 + target->thread.fp_state.fpscr = buf[32]; 70 + return 0; 71 + } 72 + 73 + /* 74 + * Currently to set and and get all the vsx state, you need to call 75 + * the fp and VMX calls as well. This only get/sets the lower 32 76 + * 128bit VSX registers. 77 + */ 78 + 79 + int vsr_active(struct task_struct *target, const struct user_regset *regset) 80 + { 81 + flush_vsx_to_thread(target); 82 + return target->thread.used_vsr ? regset->n : 0; 83 + } 84 + 85 + /* 86 + * Regardless of transactions, 'fp_state' holds the current running 87 + * value of all FPR registers and 'ckfp_state' holds the last 88 + * checkpointed value of all FPR registers for the current 89 + * transaction. 90 + * 91 + * Userspace interface buffer layout: 92 + * 93 + * struct data { 94 + * u64 vsx[32]; 95 + * }; 96 + */ 97 + int vsr_get(struct task_struct *target, const struct user_regset *regset, 98 + unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) 99 + { 100 + u64 buf[32]; 101 + int ret, i; 102 + 103 + flush_tmregs_to_thread(target); 104 + flush_fp_to_thread(target); 105 + flush_altivec_to_thread(target); 106 + flush_vsx_to_thread(target); 107 + 108 + for (i = 0; i < 32 ; i++) 109 + buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET]; 110 + 111 + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 112 + buf, 0, 32 * sizeof(double)); 113 + 114 + return ret; 115 + } 116 + 117 + /* 118 + * Regardless of transactions, 'fp_state' holds the current running 119 + * value of all FPR registers and 'ckfp_state' holds the last 120 + * checkpointed value of all FPR registers for the current 121 + * transaction. 122 + * 123 + * Userspace interface buffer layout: 124 + * 125 + * struct data { 126 + * u64 vsx[32]; 127 + * }; 128 + */ 129 + int vsr_set(struct task_struct *target, const struct user_regset *regset, 130 + unsigned int pos, unsigned int count, 131 + const void *kbuf, const void __user *ubuf) 132 + { 133 + u64 buf[32]; 134 + int ret, i; 135 + 136 + flush_tmregs_to_thread(target); 137 + flush_fp_to_thread(target); 138 + flush_altivec_to_thread(target); 139 + flush_vsx_to_thread(target); 140 + 141 + for (i = 0; i < 32 ; i++) 142 + buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET]; 143 + 144 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 145 + buf, 0, 32 * sizeof(double)); 146 + if (!ret) 147 + for (i = 0; i < 32 ; i++) 148 + target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i]; 149 + 150 + return ret; 151 + }
+481
arch/powerpc/kernel/ptrace/ptrace.c
··· 1 + /* 2 + * PowerPC version 3 + * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 4 + * 5 + * Derived from "arch/m68k/kernel/ptrace.c" 6 + * Copyright (C) 1994 by Hamish Macdonald 7 + * Taken from linux/kernel/ptrace.c and modified for M680x0. 8 + * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds 9 + * 10 + * Modified by Cort Dougan (cort@hq.fsmlabs.com) 11 + * and Paul Mackerras (paulus@samba.org). 12 + * 13 + * This file is subject to the terms and conditions of the GNU General 14 + * Public License. See the file README.legal in the main directory of 15 + * this archive for more details. 16 + */ 17 + 18 + #include <linux/regset.h> 19 + #include <linux/tracehook.h> 20 + #include <linux/audit.h> 21 + #include <linux/context_tracking.h> 22 + #include <linux/syscalls.h> 23 + 24 + #include <asm/switch_to.h> 25 + #include <asm/asm-prototypes.h> 26 + #include <asm/debug.h> 27 + 28 + #define CREATE_TRACE_POINTS 29 + #include <trace/events/syscalls.h> 30 + 31 + #include "ptrace-decl.h" 32 + 33 + /* 34 + * Called by kernel/ptrace.c when detaching.. 35 + * 36 + * Make sure single step bits etc are not set. 37 + */ 38 + void ptrace_disable(struct task_struct *child) 39 + { 40 + /* make sure the single step bit is not set. */ 41 + user_disable_single_step(child); 42 + } 43 + 44 + long arch_ptrace(struct task_struct *child, long request, 45 + unsigned long addr, unsigned long data) 46 + { 47 + int ret = -EPERM; 48 + void __user *datavp = (void __user *) data; 49 + unsigned long __user *datalp = datavp; 50 + 51 + switch (request) { 52 + /* read the word at location addr in the USER area. */ 53 + case PTRACE_PEEKUSR: { 54 + unsigned long index, tmp; 55 + 56 + ret = -EIO; 57 + /* convert to index and check */ 58 + #ifdef CONFIG_PPC32 59 + index = addr >> 2; 60 + if ((addr & 3) || (index > PT_FPSCR) 61 + || (child->thread.regs == NULL)) 62 + #else 63 + index = addr >> 3; 64 + if ((addr & 7) || (index > PT_FPSCR)) 65 + #endif 66 + break; 67 + 68 + CHECK_FULL_REGS(child->thread.regs); 69 + if (index < PT_FPR0) { 70 + ret = ptrace_get_reg(child, (int) index, &tmp); 71 + if (ret) 72 + break; 73 + } else { 74 + unsigned int fpidx = index - PT_FPR0; 75 + 76 + flush_fp_to_thread(child); 77 + if (fpidx < (PT_FPSCR - PT_FPR0)) 78 + memcpy(&tmp, &child->thread.TS_FPR(fpidx), 79 + sizeof(long)); 80 + else 81 + tmp = child->thread.fp_state.fpscr; 82 + } 83 + ret = put_user(tmp, datalp); 84 + break; 85 + } 86 + 87 + /* write the word at location addr in the USER area */ 88 + case PTRACE_POKEUSR: { 89 + unsigned long index; 90 + 91 + ret = -EIO; 92 + /* convert to index and check */ 93 + #ifdef CONFIG_PPC32 94 + index = addr >> 2; 95 + if ((addr & 3) || (index > PT_FPSCR) 96 + || (child->thread.regs == NULL)) 97 + #else 98 + index = addr >> 3; 99 + if ((addr & 7) || (index > PT_FPSCR)) 100 + #endif 101 + break; 102 + 103 + CHECK_FULL_REGS(child->thread.regs); 104 + if (index < PT_FPR0) { 105 + ret = ptrace_put_reg(child, index, data); 106 + } else { 107 + unsigned int fpidx = index - PT_FPR0; 108 + 109 + flush_fp_to_thread(child); 110 + if (fpidx < (PT_FPSCR - PT_FPR0)) 111 + memcpy(&child->thread.TS_FPR(fpidx), &data, 112 + sizeof(long)); 113 + else 114 + child->thread.fp_state.fpscr = data; 115 + ret = 0; 116 + } 117 + break; 118 + } 119 + 120 + case PPC_PTRACE_GETHWDBGINFO: { 121 + struct ppc_debug_info dbginfo; 122 + 123 + ppc_gethwdinfo(&dbginfo); 124 + 125 + if (copy_to_user(datavp, &dbginfo, 126 + sizeof(struct ppc_debug_info))) 127 + return -EFAULT; 128 + return 0; 129 + } 130 + 131 + case PPC_PTRACE_SETHWDEBUG: { 132 + struct ppc_hw_breakpoint bp_info; 133 + 134 + if (copy_from_user(&bp_info, datavp, 135 + sizeof(struct ppc_hw_breakpoint))) 136 + return -EFAULT; 137 + return ppc_set_hwdebug(child, &bp_info); 138 + } 139 + 140 + case PPC_PTRACE_DELHWDEBUG: { 141 + ret = ppc_del_hwdebug(child, data); 142 + break; 143 + } 144 + 145 + case PTRACE_GET_DEBUGREG: 146 + ret = ptrace_get_debugreg(child, addr, datalp); 147 + break; 148 + 149 + case PTRACE_SET_DEBUGREG: 150 + ret = ptrace_set_debugreg(child, addr, data); 151 + break; 152 + 153 + #ifdef CONFIG_PPC64 154 + case PTRACE_GETREGS64: 155 + #endif 156 + case PTRACE_GETREGS: /* Get all pt_regs from the child. */ 157 + return copy_regset_to_user(child, &user_ppc_native_view, 158 + REGSET_GPR, 159 + 0, sizeof(struct user_pt_regs), 160 + datavp); 161 + 162 + #ifdef CONFIG_PPC64 163 + case PTRACE_SETREGS64: 164 + #endif 165 + case PTRACE_SETREGS: /* Set all gp regs in the child. */ 166 + return copy_regset_from_user(child, &user_ppc_native_view, 167 + REGSET_GPR, 168 + 0, sizeof(struct user_pt_regs), 169 + datavp); 170 + 171 + case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */ 172 + return copy_regset_to_user(child, &user_ppc_native_view, 173 + REGSET_FPR, 174 + 0, sizeof(elf_fpregset_t), 175 + datavp); 176 + 177 + case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */ 178 + return copy_regset_from_user(child, &user_ppc_native_view, 179 + REGSET_FPR, 180 + 0, sizeof(elf_fpregset_t), 181 + datavp); 182 + 183 + #ifdef CONFIG_ALTIVEC 184 + case PTRACE_GETVRREGS: 185 + return copy_regset_to_user(child, &user_ppc_native_view, 186 + REGSET_VMX, 187 + 0, (33 * sizeof(vector128) + 188 + sizeof(u32)), 189 + datavp); 190 + 191 + case PTRACE_SETVRREGS: 192 + return copy_regset_from_user(child, &user_ppc_native_view, 193 + REGSET_VMX, 194 + 0, (33 * sizeof(vector128) + 195 + sizeof(u32)), 196 + datavp); 197 + #endif 198 + #ifdef CONFIG_VSX 199 + case PTRACE_GETVSRREGS: 200 + return copy_regset_to_user(child, &user_ppc_native_view, 201 + REGSET_VSX, 202 + 0, 32 * sizeof(double), 203 + datavp); 204 + 205 + case PTRACE_SETVSRREGS: 206 + return copy_regset_from_user(child, &user_ppc_native_view, 207 + REGSET_VSX, 208 + 0, 32 * sizeof(double), 209 + datavp); 210 + #endif 211 + #ifdef CONFIG_SPE 212 + case PTRACE_GETEVRREGS: 213 + /* Get the child spe register state. */ 214 + return copy_regset_to_user(child, &user_ppc_native_view, 215 + REGSET_SPE, 0, 35 * sizeof(u32), 216 + datavp); 217 + 218 + case PTRACE_SETEVRREGS: 219 + /* Set the child spe register state. */ 220 + return copy_regset_from_user(child, &user_ppc_native_view, 221 + REGSET_SPE, 0, 35 * sizeof(u32), 222 + datavp); 223 + #endif 224 + 225 + default: 226 + ret = ptrace_request(child, request, addr, data); 227 + break; 228 + } 229 + return ret; 230 + } 231 + 232 + #ifdef CONFIG_SECCOMP 233 + static int do_seccomp(struct pt_regs *regs) 234 + { 235 + if (!test_thread_flag(TIF_SECCOMP)) 236 + return 0; 237 + 238 + /* 239 + * The ABI we present to seccomp tracers is that r3 contains 240 + * the syscall return value and orig_gpr3 contains the first 241 + * syscall parameter. This is different to the ptrace ABI where 242 + * both r3 and orig_gpr3 contain the first syscall parameter. 243 + */ 244 + regs->gpr[3] = -ENOSYS; 245 + 246 + /* 247 + * We use the __ version here because we have already checked 248 + * TIF_SECCOMP. If this fails, there is nothing left to do, we 249 + * have already loaded -ENOSYS into r3, or seccomp has put 250 + * something else in r3 (via SECCOMP_RET_ERRNO/TRACE). 251 + */ 252 + if (__secure_computing(NULL)) 253 + return -1; 254 + 255 + /* 256 + * The syscall was allowed by seccomp, restore the register 257 + * state to what audit expects. 258 + * Note that we use orig_gpr3, which means a seccomp tracer can 259 + * modify the first syscall parameter (in orig_gpr3) and also 260 + * allow the syscall to proceed. 261 + */ 262 + regs->gpr[3] = regs->orig_gpr3; 263 + 264 + return 0; 265 + } 266 + #else 267 + static inline int do_seccomp(struct pt_regs *regs) { return 0; } 268 + #endif /* CONFIG_SECCOMP */ 269 + 270 + /** 271 + * do_syscall_trace_enter() - Do syscall tracing on kernel entry. 272 + * @regs: the pt_regs of the task to trace (current) 273 + * 274 + * Performs various types of tracing on syscall entry. This includes seccomp, 275 + * ptrace, syscall tracepoints and audit. 276 + * 277 + * The pt_regs are potentially visible to userspace via ptrace, so their 278 + * contents is ABI. 279 + * 280 + * One or more of the tracers may modify the contents of pt_regs, in particular 281 + * to modify arguments or even the syscall number itself. 282 + * 283 + * It's also possible that a tracer can choose to reject the system call. In 284 + * that case this function will return an illegal syscall number, and will put 285 + * an appropriate return value in regs->r3. 286 + * 287 + * Return: the (possibly changed) syscall number. 288 + */ 289 + long do_syscall_trace_enter(struct pt_regs *regs) 290 + { 291 + u32 flags; 292 + 293 + user_exit(); 294 + 295 + flags = READ_ONCE(current_thread_info()->flags) & 296 + (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE); 297 + 298 + if (flags) { 299 + int rc = tracehook_report_syscall_entry(regs); 300 + 301 + if (unlikely(flags & _TIF_SYSCALL_EMU)) { 302 + /* 303 + * A nonzero return code from 304 + * tracehook_report_syscall_entry() tells us to prevent 305 + * the syscall execution, but we are not going to 306 + * execute it anyway. 307 + * 308 + * Returning -1 will skip the syscall execution. We want 309 + * to avoid clobbering any registers, so we don't goto 310 + * the skip label below. 311 + */ 312 + return -1; 313 + } 314 + 315 + if (rc) { 316 + /* 317 + * The tracer decided to abort the syscall. Note that 318 + * the tracer may also just change regs->gpr[0] to an 319 + * invalid syscall number, that is handled below on the 320 + * exit path. 321 + */ 322 + goto skip; 323 + } 324 + } 325 + 326 + /* Run seccomp after ptrace; allow it to set gpr[3]. */ 327 + if (do_seccomp(regs)) 328 + return -1; 329 + 330 + /* Avoid trace and audit when syscall is invalid. */ 331 + if (regs->gpr[0] >= NR_syscalls) 332 + goto skip; 333 + 334 + if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) 335 + trace_sys_enter(regs, regs->gpr[0]); 336 + 337 + if (!is_32bit_task()) 338 + audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4], 339 + regs->gpr[5], regs->gpr[6]); 340 + else 341 + audit_syscall_entry(regs->gpr[0], 342 + regs->gpr[3] & 0xffffffff, 343 + regs->gpr[4] & 0xffffffff, 344 + regs->gpr[5] & 0xffffffff, 345 + regs->gpr[6] & 0xffffffff); 346 + 347 + /* Return the possibly modified but valid syscall number */ 348 + return regs->gpr[0]; 349 + 350 + skip: 351 + /* 352 + * If we are aborting explicitly, or if the syscall number is 353 + * now invalid, set the return value to -ENOSYS. 354 + */ 355 + regs->gpr[3] = -ENOSYS; 356 + return -1; 357 + } 358 + 359 + void do_syscall_trace_leave(struct pt_regs *regs) 360 + { 361 + int step; 362 + 363 + audit_syscall_exit(regs); 364 + 365 + if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) 366 + trace_sys_exit(regs, regs->result); 367 + 368 + step = test_thread_flag(TIF_SINGLESTEP); 369 + if (step || test_thread_flag(TIF_SYSCALL_TRACE)) 370 + tracehook_report_syscall_exit(regs, step); 371 + 372 + user_enter(); 373 + } 374 + 375 + void __init pt_regs_check(void); 376 + 377 + /* 378 + * Dummy function, its purpose is to break the build if struct pt_regs and 379 + * struct user_pt_regs don't match. 380 + */ 381 + void __init pt_regs_check(void) 382 + { 383 + BUILD_BUG_ON(offsetof(struct pt_regs, gpr) != 384 + offsetof(struct user_pt_regs, gpr)); 385 + BUILD_BUG_ON(offsetof(struct pt_regs, nip) != 386 + offsetof(struct user_pt_regs, nip)); 387 + BUILD_BUG_ON(offsetof(struct pt_regs, msr) != 388 + offsetof(struct user_pt_regs, msr)); 389 + BUILD_BUG_ON(offsetof(struct pt_regs, msr) != 390 + offsetof(struct user_pt_regs, msr)); 391 + BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != 392 + offsetof(struct user_pt_regs, orig_gpr3)); 393 + BUILD_BUG_ON(offsetof(struct pt_regs, ctr) != 394 + offsetof(struct user_pt_regs, ctr)); 395 + BUILD_BUG_ON(offsetof(struct pt_regs, link) != 396 + offsetof(struct user_pt_regs, link)); 397 + BUILD_BUG_ON(offsetof(struct pt_regs, xer) != 398 + offsetof(struct user_pt_regs, xer)); 399 + BUILD_BUG_ON(offsetof(struct pt_regs, ccr) != 400 + offsetof(struct user_pt_regs, ccr)); 401 + #ifdef __powerpc64__ 402 + BUILD_BUG_ON(offsetof(struct pt_regs, softe) != 403 + offsetof(struct user_pt_regs, softe)); 404 + #else 405 + BUILD_BUG_ON(offsetof(struct pt_regs, mq) != 406 + offsetof(struct user_pt_regs, mq)); 407 + #endif 408 + BUILD_BUG_ON(offsetof(struct pt_regs, trap) != 409 + offsetof(struct user_pt_regs, trap)); 410 + BUILD_BUG_ON(offsetof(struct pt_regs, dar) != 411 + offsetof(struct user_pt_regs, dar)); 412 + BUILD_BUG_ON(offsetof(struct pt_regs, dsisr) != 413 + offsetof(struct user_pt_regs, dsisr)); 414 + BUILD_BUG_ON(offsetof(struct pt_regs, result) != 415 + offsetof(struct user_pt_regs, result)); 416 + 417 + BUILD_BUG_ON(sizeof(struct user_pt_regs) > sizeof(struct pt_regs)); 418 + 419 + // Now check that the pt_regs offsets match the uapi #defines 420 + #define CHECK_REG(_pt, _reg) \ 421 + BUILD_BUG_ON(_pt != (offsetof(struct user_pt_regs, _reg) / \ 422 + sizeof(unsigned long))); 423 + 424 + CHECK_REG(PT_R0, gpr[0]); 425 + CHECK_REG(PT_R1, gpr[1]); 426 + CHECK_REG(PT_R2, gpr[2]); 427 + CHECK_REG(PT_R3, gpr[3]); 428 + CHECK_REG(PT_R4, gpr[4]); 429 + CHECK_REG(PT_R5, gpr[5]); 430 + CHECK_REG(PT_R6, gpr[6]); 431 + CHECK_REG(PT_R7, gpr[7]); 432 + CHECK_REG(PT_R8, gpr[8]); 433 + CHECK_REG(PT_R9, gpr[9]); 434 + CHECK_REG(PT_R10, gpr[10]); 435 + CHECK_REG(PT_R11, gpr[11]); 436 + CHECK_REG(PT_R12, gpr[12]); 437 + CHECK_REG(PT_R13, gpr[13]); 438 + CHECK_REG(PT_R14, gpr[14]); 439 + CHECK_REG(PT_R15, gpr[15]); 440 + CHECK_REG(PT_R16, gpr[16]); 441 + CHECK_REG(PT_R17, gpr[17]); 442 + CHECK_REG(PT_R18, gpr[18]); 443 + CHECK_REG(PT_R19, gpr[19]); 444 + CHECK_REG(PT_R20, gpr[20]); 445 + CHECK_REG(PT_R21, gpr[21]); 446 + CHECK_REG(PT_R22, gpr[22]); 447 + CHECK_REG(PT_R23, gpr[23]); 448 + CHECK_REG(PT_R24, gpr[24]); 449 + CHECK_REG(PT_R25, gpr[25]); 450 + CHECK_REG(PT_R26, gpr[26]); 451 + CHECK_REG(PT_R27, gpr[27]); 452 + CHECK_REG(PT_R28, gpr[28]); 453 + CHECK_REG(PT_R29, gpr[29]); 454 + CHECK_REG(PT_R30, gpr[30]); 455 + CHECK_REG(PT_R31, gpr[31]); 456 + CHECK_REG(PT_NIP, nip); 457 + CHECK_REG(PT_MSR, msr); 458 + CHECK_REG(PT_ORIG_R3, orig_gpr3); 459 + CHECK_REG(PT_CTR, ctr); 460 + CHECK_REG(PT_LNK, link); 461 + CHECK_REG(PT_XER, xer); 462 + CHECK_REG(PT_CCR, ccr); 463 + #ifdef CONFIG_PPC64 464 + CHECK_REG(PT_SOFTE, softe); 465 + #else 466 + CHECK_REG(PT_MQ, mq); 467 + #endif 468 + CHECK_REG(PT_TRAP, trap); 469 + CHECK_REG(PT_DAR, dar); 470 + CHECK_REG(PT_DSISR, dsisr); 471 + CHECK_REG(PT_RESULT, result); 472 + #undef CHECK_REG 473 + 474 + BUILD_BUG_ON(PT_REGS_COUNT != sizeof(struct user_pt_regs) / sizeof(unsigned long)); 475 + 476 + /* 477 + * PT_DSCR isn't a real reg, but it's important that it doesn't overlap the 478 + * real registers. 479 + */ 480 + BUILD_BUG_ON(PT_DSCR < sizeof(struct user_pt_regs) / sizeof(unsigned long)); 481 + }
-11
arch/powerpc/kernel/ptrace32.c arch/powerpc/kernel/ptrace/ptrace32.c
··· 17 17 * this archive for more details. 18 18 */ 19 19 20 - #include <linux/kernel.h> 21 - #include <linux/sched.h> 22 - #include <linux/mm.h> 23 - #include <linux/smp.h> 24 - #include <linux/errno.h> 25 20 #include <linux/ptrace.h> 26 21 #include <linux/regset.h> 27 - #include <linux/user.h> 28 - #include <linux/security.h> 29 - #include <linux/signal.h> 30 22 #include <linux/compat.h> 31 23 32 - #include <linux/uaccess.h> 33 - #include <asm/page.h> 34 - #include <asm/pgtable.h> 35 24 #include <asm/switch_to.h> 36 25 37 26 /*
+1 -2
arch/powerpc/kernel/setup-common.c
··· 787 787 static int powerpc_debugfs_init(void) 788 788 { 789 789 powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL); 790 - 791 - return powerpc_debugfs_root == NULL; 790 + return 0; 792 791 } 793 792 arch_initcall(powerpc_debugfs_init); 794 793 #endif
+6
arch/powerpc/kernel/setup.h
··· 8 8 #ifndef __ARCH_POWERPC_KERNEL_SETUP_H 9 9 #define __ARCH_POWERPC_KERNEL_SETUP_H 10 10 11 + #ifdef CONFIG_CC_IS_CLANG 12 + #define __nostackprotector 13 + #else 14 + #define __nostackprotector __attribute__((__optimize__("no-stack-protector"))) 15 + #endif 16 + 11 17 void initialize_cache_info(void); 12 18 void irqstack_early_init(void); 13 19
-1
arch/powerpc/kernel/setup_32.c
··· 58 58 int smp_hw_index[NR_CPUS]; 59 59 EXPORT_SYMBOL(smp_hw_index); 60 60 61 - unsigned long ISA_DMA_THRESHOLD; 62 61 unsigned int DMA_MODE_READ; 63 62 unsigned int DMA_MODE_WRITE; 64 63
+25 -7
arch/powerpc/kernel/setup_64.c
··· 279 279 * device-tree is not accessible via normal means at this point. 280 280 */ 281 281 282 - void __init early_setup(unsigned long dt_ptr) 282 + void __init __nostackprotector early_setup(unsigned long dt_ptr) 283 283 { 284 284 static __initdata struct paca_struct boot_paca; 285 285 286 286 /* -------- printk is _NOT_ safe to use here ! ------- */ 287 287 288 - /* Try new device tree based feature discovery ... */ 289 - if (!dt_cpu_ftrs_init(__va(dt_ptr))) 290 - /* Otherwise use the old style CPU table */ 291 - identify_cpu(0, mfspr(SPRN_PVR)); 292 - 293 - /* Assume we're on cpu 0 for now. Don't write to the paca yet! */ 288 + /* 289 + * Assume we're on cpu 0 for now. 290 + * 291 + * We need to load a PACA very early for a few reasons. 292 + * 293 + * The stack protector canary is stored in the paca, so as soon as we 294 + * call any stack protected code we need r13 pointing somewhere valid. 295 + * 296 + * If we are using kcov it will call in_task() in its instrumentation, 297 + * which relies on the current task from the PACA. 298 + * 299 + * dt_cpu_ftrs_init() calls into generic OF/fdt code, as well as 300 + * printk(), which can trigger both stack protector and kcov. 301 + * 302 + * percpu variables and spin locks also use the paca. 303 + * 304 + * So set up a temporary paca. It will be replaced below once we know 305 + * what CPU we are on. 306 + */ 294 307 initialise_paca(&boot_paca, 0); 295 308 setup_paca(&boot_paca); 296 309 fixup_boot_paca(); 297 310 298 311 /* -------- printk is now safe to use ------- */ 312 + 313 + /* Try new device tree based feature discovery ... */ 314 + if (!dt_cpu_ftrs_init(__va(dt_ptr))) 315 + /* Otherwise use the old style CPU table */ 316 + identify_cpu(0, mfspr(SPRN_PVR)); 299 317 300 318 /* Enable early debugging if any specified (see udbg.h) */ 301 319 udbg_early_init();
-2
arch/powerpc/kernel/signal.h
··· 10 10 #ifndef _POWERPC_ARCH_SIGNAL_H 11 11 #define _POWERPC_ARCH_SIGNAL_H 12 12 13 - extern void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags); 14 - 15 13 extern void __user *get_sigframe(struct ksignal *ksig, unsigned long sp, 16 14 size_t frame_size, int is_32); 17 15
+3 -1
arch/powerpc/kernel/signal_64.c
··· 473 473 err |= __get_user(tsk->thread.ckpt_regs.ccr, 474 474 &sc->gp_regs[PT_CCR]); 475 475 476 + /* Don't allow userspace to set the trap value */ 477 + regs->trap = 0; 478 + 476 479 /* These regs are not checkpointed; they can go in 'regs'. */ 477 - err |= __get_user(regs->trap, &sc->gp_regs[PT_TRAP]); 478 480 err |= __get_user(regs->dar, &sc->gp_regs[PT_DAR]); 479 481 err |= __get_user(regs->dsisr, &sc->gp_regs[PT_DSISR]); 480 482 err |= __get_user(regs->result, &sc->gp_regs[PT_RESULT]);
+23 -8
arch/powerpc/kernel/smp.c
··· 1185 1185 } 1186 1186 } 1187 1187 1188 + int get_physical_package_id(int cpu) 1189 + { 1190 + int pkg_id = cpu_to_chip_id(cpu); 1191 + 1192 + /* 1193 + * If the platform is PowerNV or Guest on KVM, ibm,chip-id is 1194 + * defined. Hence we would return the chip-id as the result of 1195 + * get_physical_package_id. 1196 + */ 1197 + if (pkg_id == -1 && firmware_has_feature(FW_FEATURE_LPAR) && 1198 + IS_ENABLED(CONFIG_PPC_SPLPAR)) { 1199 + struct device_node *np = of_get_cpu_node(cpu, NULL); 1200 + pkg_id = of_node_to_nid(np); 1201 + of_node_put(np); 1202 + } 1203 + 1204 + return pkg_id; 1205 + } 1206 + EXPORT_SYMBOL_GPL(get_physical_package_id); 1207 + 1188 1208 static void add_cpu_to_masks(int cpu) 1189 1209 { 1190 1210 int first_thread = cpu_first_thread_sibling(cpu); 1191 - int chipid = cpu_to_chip_id(cpu); 1211 + int pkg_id = get_physical_package_id(cpu); 1192 1212 int i; 1193 1213 1194 1214 /* ··· 1237 1217 for_each_cpu(i, cpu_l2_cache_mask(cpu)) 1238 1218 set_cpus_related(cpu, i, cpu_core_mask); 1239 1219 1240 - if (chipid == -1) 1220 + if (pkg_id == -1) 1241 1221 return; 1242 1222 1243 1223 for_each_cpu(i, cpu_online_mask) 1244 - if (cpu_to_chip_id(i) == chipid) 1224 + if (get_physical_package_id(i) == pkg_id) 1245 1225 set_cpus_related(cpu, i, cpu_core_mask); 1246 1226 } 1247 1227 ··· 1379 1359 if (smp_ops && smp_ops->bringup_done) 1380 1360 smp_ops->bringup_done(); 1381 1361 1382 - /* 1383 - * On a shared LPAR, associativity needs to be requested. 1384 - * Hence, get numa topology before dumping cpu topology 1385 - */ 1386 - shared_proc_topology_init(); 1387 1362 dump_numa_cpu_topology(); 1388 1363 1389 1364 #ifdef CONFIG_SCHED_SMT
+3 -3
arch/powerpc/kernel/stacktrace.c
··· 57 57 { 58 58 unsigned long sp; 59 59 60 - sp = current_stack_pointer(); 60 + sp = current_stack_frame(); 61 61 62 62 save_context_stack(trace, sp, current, 1); 63 63 } ··· 71 71 return; 72 72 73 73 if (tsk == current) 74 - sp = current_stack_pointer(); 74 + sp = current_stack_frame(); 75 75 else 76 76 sp = tsk->thread.ksp; 77 77 ··· 131 131 } 132 132 133 133 if (tsk == current) 134 - sp = current_stack_pointer(); 134 + sp = current_stack_frame(); 135 135 else 136 136 sp = tsk->thread.ksp; 137 137
+379
arch/powerpc/kernel/syscall_64.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/err.h> 4 + #include <asm/asm-prototypes.h> 5 + #include <asm/book3s/64/kup-radix.h> 6 + #include <asm/cputime.h> 7 + #include <asm/hw_irq.h> 8 + #include <asm/kprobes.h> 9 + #include <asm/paca.h> 10 + #include <asm/ptrace.h> 11 + #include <asm/reg.h> 12 + #include <asm/signal.h> 13 + #include <asm/switch_to.h> 14 + #include <asm/syscall.h> 15 + #include <asm/time.h> 16 + #include <asm/unistd.h> 17 + 18 + typedef long (*syscall_fn)(long, long, long, long, long, long); 19 + 20 + /* Has to run notrace because it is entered not completely "reconciled" */ 21 + notrace long system_call_exception(long r3, long r4, long r5, 22 + long r6, long r7, long r8, 23 + unsigned long r0, struct pt_regs *regs) 24 + { 25 + unsigned long ti_flags; 26 + syscall_fn f; 27 + 28 + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 29 + BUG_ON(irq_soft_mask_return() != IRQS_ALL_DISABLED); 30 + 31 + trace_hardirqs_off(); /* finish reconciling */ 32 + 33 + if (IS_ENABLED(CONFIG_PPC_BOOK3S)) 34 + BUG_ON(!(regs->msr & MSR_RI)); 35 + BUG_ON(!(regs->msr & MSR_PR)); 36 + BUG_ON(!FULL_REGS(regs)); 37 + BUG_ON(regs->softe != IRQS_ENABLED); 38 + 39 + account_cpu_user_entry(); 40 + 41 + #ifdef CONFIG_PPC_SPLPAR 42 + if (IS_ENABLED(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && 43 + firmware_has_feature(FW_FEATURE_SPLPAR)) { 44 + struct lppaca *lp = local_paca->lppaca_ptr; 45 + 46 + if (unlikely(local_paca->dtl_ridx != be64_to_cpu(lp->dtl_idx))) 47 + accumulate_stolen_time(); 48 + } 49 + #endif 50 + 51 + kuap_check_amr(); 52 + 53 + /* 54 + * This is not required for the syscall exit path, but makes the 55 + * stack frame look nicer. If this was initialised in the first stack 56 + * frame, or if the unwinder was taught the first stack frame always 57 + * returns to user with IRQS_ENABLED, this store could be avoided! 58 + */ 59 + regs->softe = IRQS_ENABLED; 60 + 61 + local_irq_enable(); 62 + 63 + ti_flags = current_thread_info()->flags; 64 + if (unlikely(ti_flags & _TIF_SYSCALL_DOTRACE)) { 65 + /* 66 + * We use the return value of do_syscall_trace_enter() as the 67 + * syscall number. If the syscall was rejected for any reason 68 + * do_syscall_trace_enter() returns an invalid syscall number 69 + * and the test against NR_syscalls will fail and the return 70 + * value to be used is in regs->gpr[3]. 71 + */ 72 + r0 = do_syscall_trace_enter(regs); 73 + if (unlikely(r0 >= NR_syscalls)) 74 + return regs->gpr[3]; 75 + r3 = regs->gpr[3]; 76 + r4 = regs->gpr[4]; 77 + r5 = regs->gpr[5]; 78 + r6 = regs->gpr[6]; 79 + r7 = regs->gpr[7]; 80 + r8 = regs->gpr[8]; 81 + 82 + } else if (unlikely(r0 >= NR_syscalls)) { 83 + return -ENOSYS; 84 + } 85 + 86 + /* May be faster to do array_index_nospec? */ 87 + barrier_nospec(); 88 + 89 + if (unlikely(ti_flags & _TIF_32BIT)) { 90 + f = (void *)compat_sys_call_table[r0]; 91 + 92 + r3 &= 0x00000000ffffffffULL; 93 + r4 &= 0x00000000ffffffffULL; 94 + r5 &= 0x00000000ffffffffULL; 95 + r6 &= 0x00000000ffffffffULL; 96 + r7 &= 0x00000000ffffffffULL; 97 + r8 &= 0x00000000ffffffffULL; 98 + 99 + } else { 100 + f = (void *)sys_call_table[r0]; 101 + } 102 + 103 + return f(r3, r4, r5, r6, r7, r8); 104 + } 105 + 106 + /* 107 + * This should be called after a syscall returns, with r3 the return value 108 + * from the syscall. If this function returns non-zero, the system call 109 + * exit assembly should additionally load all GPR registers and CTR and XER 110 + * from the interrupt frame. 111 + * 112 + * The function graph tracer can not trace the return side of this function, 113 + * because RI=0 and soft mask state is "unreconciled", so it is marked notrace. 114 + */ 115 + notrace unsigned long syscall_exit_prepare(unsigned long r3, 116 + struct pt_regs *regs) 117 + { 118 + unsigned long *ti_flagsp = &current_thread_info()->flags; 119 + unsigned long ti_flags; 120 + unsigned long ret = 0; 121 + 122 + regs->result = r3; 123 + 124 + /* Check whether the syscall is issued inside a restartable sequence */ 125 + rseq_syscall(regs); 126 + 127 + ti_flags = *ti_flagsp; 128 + 129 + if (unlikely(r3 >= (unsigned long)-MAX_ERRNO)) { 130 + if (likely(!(ti_flags & (_TIF_NOERROR | _TIF_RESTOREALL)))) { 131 + r3 = -r3; 132 + regs->ccr |= 0x10000000; /* Set SO bit in CR */ 133 + } 134 + } 135 + 136 + if (unlikely(ti_flags & _TIF_PERSYSCALL_MASK)) { 137 + if (ti_flags & _TIF_RESTOREALL) 138 + ret = _TIF_RESTOREALL; 139 + else 140 + regs->gpr[3] = r3; 141 + clear_bits(_TIF_PERSYSCALL_MASK, ti_flagsp); 142 + } else { 143 + regs->gpr[3] = r3; 144 + } 145 + 146 + if (unlikely(ti_flags & _TIF_SYSCALL_DOTRACE)) { 147 + do_syscall_trace_leave(regs); 148 + ret |= _TIF_RESTOREALL; 149 + } 150 + 151 + again: 152 + local_irq_disable(); 153 + ti_flags = READ_ONCE(*ti_flagsp); 154 + while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) { 155 + local_irq_enable(); 156 + if (ti_flags & _TIF_NEED_RESCHED) { 157 + schedule(); 158 + } else { 159 + /* 160 + * SIGPENDING must restore signal handler function 161 + * argument GPRs, and some non-volatiles (e.g., r1). 162 + * Restore all for now. This could be made lighter. 163 + */ 164 + if (ti_flags & _TIF_SIGPENDING) 165 + ret |= _TIF_RESTOREALL; 166 + do_notify_resume(regs, ti_flags); 167 + } 168 + local_irq_disable(); 169 + ti_flags = READ_ONCE(*ti_flagsp); 170 + } 171 + 172 + if (IS_ENABLED(CONFIG_PPC_BOOK3S) && IS_ENABLED(CONFIG_PPC_FPU)) { 173 + if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) && 174 + unlikely((ti_flags & _TIF_RESTORE_TM))) { 175 + restore_tm_state(regs); 176 + } else { 177 + unsigned long mathflags = MSR_FP; 178 + 179 + if (cpu_has_feature(CPU_FTR_VSX)) 180 + mathflags |= MSR_VEC | MSR_VSX; 181 + else if (cpu_has_feature(CPU_FTR_ALTIVEC)) 182 + mathflags |= MSR_VEC; 183 + 184 + if ((regs->msr & mathflags) != mathflags) 185 + restore_math(regs); 186 + } 187 + } 188 + 189 + /* This must be done with RI=1 because tracing may touch vmaps */ 190 + trace_hardirqs_on(); 191 + 192 + /* This pattern matches prep_irq_for_idle */ 193 + __hard_EE_RI_disable(); 194 + if (unlikely(lazy_irq_pending())) { 195 + __hard_RI_enable(); 196 + trace_hardirqs_off(); 197 + local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 198 + local_irq_enable(); 199 + /* Took an interrupt, may have more exit work to do. */ 200 + goto again; 201 + } 202 + local_paca->irq_happened = 0; 203 + irq_soft_mask_set(IRQS_ENABLED); 204 + 205 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 206 + local_paca->tm_scratch = regs->msr; 207 + #endif 208 + 209 + kuap_check_amr(); 210 + 211 + account_cpu_user_exit(); 212 + 213 + return ret; 214 + } 215 + 216 + #ifdef CONFIG_PPC_BOOK3S /* BOOK3E not yet using this */ 217 + notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long msr) 218 + { 219 + #ifdef CONFIG_PPC_BOOK3E 220 + struct thread_struct *ts = &current->thread; 221 + #endif 222 + unsigned long *ti_flagsp = &current_thread_info()->flags; 223 + unsigned long ti_flags; 224 + unsigned long flags; 225 + unsigned long ret = 0; 226 + 227 + if (IS_ENABLED(CONFIG_PPC_BOOK3S)) 228 + BUG_ON(!(regs->msr & MSR_RI)); 229 + BUG_ON(!(regs->msr & MSR_PR)); 230 + BUG_ON(!FULL_REGS(regs)); 231 + BUG_ON(regs->softe != IRQS_ENABLED); 232 + 233 + local_irq_save(flags); 234 + 235 + again: 236 + ti_flags = READ_ONCE(*ti_flagsp); 237 + while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) { 238 + local_irq_enable(); /* returning to user: may enable */ 239 + if (ti_flags & _TIF_NEED_RESCHED) { 240 + schedule(); 241 + } else { 242 + if (ti_flags & _TIF_SIGPENDING) 243 + ret |= _TIF_RESTOREALL; 244 + do_notify_resume(regs, ti_flags); 245 + } 246 + local_irq_disable(); 247 + ti_flags = READ_ONCE(*ti_flagsp); 248 + } 249 + 250 + if (IS_ENABLED(CONFIG_PPC_BOOK3S) && IS_ENABLED(CONFIG_PPC_FPU)) { 251 + if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) && 252 + unlikely((ti_flags & _TIF_RESTORE_TM))) { 253 + restore_tm_state(regs); 254 + } else { 255 + unsigned long mathflags = MSR_FP; 256 + 257 + if (cpu_has_feature(CPU_FTR_VSX)) 258 + mathflags |= MSR_VEC | MSR_VSX; 259 + else if (cpu_has_feature(CPU_FTR_ALTIVEC)) 260 + mathflags |= MSR_VEC; 261 + 262 + if ((regs->msr & mathflags) != mathflags) 263 + restore_math(regs); 264 + } 265 + } 266 + 267 + trace_hardirqs_on(); 268 + __hard_EE_RI_disable(); 269 + if (unlikely(lazy_irq_pending())) { 270 + __hard_RI_enable(); 271 + trace_hardirqs_off(); 272 + local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 273 + local_irq_enable(); 274 + local_irq_disable(); 275 + /* Took an interrupt, may have more exit work to do. */ 276 + goto again; 277 + } 278 + local_paca->irq_happened = 0; 279 + irq_soft_mask_set(IRQS_ENABLED); 280 + 281 + #ifdef CONFIG_PPC_BOOK3E 282 + if (unlikely(ts->debug.dbcr0 & DBCR0_IDM)) { 283 + /* 284 + * Check to see if the dbcr0 register is set up to debug. 285 + * Use the internal debug mode bit to do this. 286 + */ 287 + mtmsr(mfmsr() & ~MSR_DE); 288 + mtspr(SPRN_DBCR0, ts->debug.dbcr0); 289 + mtspr(SPRN_DBSR, -1); 290 + } 291 + #endif 292 + 293 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 294 + local_paca->tm_scratch = regs->msr; 295 + #endif 296 + 297 + kuap_check_amr(); 298 + 299 + account_cpu_user_exit(); 300 + 301 + return ret; 302 + } 303 + 304 + void unrecoverable_exception(struct pt_regs *regs); 305 + void preempt_schedule_irq(void); 306 + 307 + notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsigned long msr) 308 + { 309 + unsigned long *ti_flagsp = &current_thread_info()->flags; 310 + unsigned long flags; 311 + unsigned long ret = 0; 312 + 313 + if (IS_ENABLED(CONFIG_PPC_BOOK3S) && unlikely(!(regs->msr & MSR_RI))) 314 + unrecoverable_exception(regs); 315 + BUG_ON(regs->msr & MSR_PR); 316 + BUG_ON(!FULL_REGS(regs)); 317 + 318 + if (unlikely(*ti_flagsp & _TIF_EMULATE_STACK_STORE)) { 319 + clear_bits(_TIF_EMULATE_STACK_STORE, ti_flagsp); 320 + ret = 1; 321 + } 322 + 323 + local_irq_save(flags); 324 + 325 + if (regs->softe == IRQS_ENABLED) { 326 + /* Returning to a kernel context with local irqs enabled. */ 327 + WARN_ON_ONCE(!(regs->msr & MSR_EE)); 328 + again: 329 + if (IS_ENABLED(CONFIG_PREEMPT)) { 330 + /* Return to preemptible kernel context */ 331 + if (unlikely(*ti_flagsp & _TIF_NEED_RESCHED)) { 332 + if (preempt_count() == 0) 333 + preempt_schedule_irq(); 334 + } 335 + } 336 + 337 + trace_hardirqs_on(); 338 + __hard_EE_RI_disable(); 339 + if (unlikely(lazy_irq_pending())) { 340 + __hard_RI_enable(); 341 + irq_soft_mask_set(IRQS_ALL_DISABLED); 342 + trace_hardirqs_off(); 343 + local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 344 + /* 345 + * Can't local_irq_restore to replay if we were in 346 + * interrupt context. Must replay directly. 347 + */ 348 + if (irqs_disabled_flags(flags)) { 349 + replay_soft_interrupts(); 350 + } else { 351 + local_irq_restore(flags); 352 + local_irq_save(flags); 353 + } 354 + /* Took an interrupt, may have more exit work to do. */ 355 + goto again; 356 + } 357 + local_paca->irq_happened = 0; 358 + irq_soft_mask_set(IRQS_ENABLED); 359 + } else { 360 + /* Returning to a kernel context with local irqs disabled. */ 361 + __hard_EE_RI_disable(); 362 + if (regs->msr & MSR_EE) 363 + local_paca->irq_happened &= ~PACA_IRQ_HARD_DIS; 364 + } 365 + 366 + 367 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 368 + local_paca->tm_scratch = regs->msr; 369 + #endif 370 + 371 + /* 372 + * We don't need to restore AMR on the way back to userspace for KUAP. 373 + * The value of AMR only matters while we're in the kernel. 374 + */ 375 + kuap_restore_amr(regs); 376 + 377 + return ret; 378 + } 379 + #endif
+15 -7
arch/powerpc/kernel/syscalls/syscall.tbl
··· 9 9 # 10 10 0 nospu restart_syscall sys_restart_syscall 11 11 1 nospu exit sys_exit 12 - 2 nospu fork ppc_fork 12 + 2 32 fork ppc_fork sys_fork 13 + 2 64 fork sys_fork 14 + 2 spu fork sys_ni_syscall 13 15 3 common read sys_read 14 16 4 common write sys_write 15 17 5 common open sys_open compat_sys_open ··· 160 158 119 32 sigreturn sys_sigreturn compat_sys_sigreturn 161 159 119 64 sigreturn sys_ni_syscall 162 160 119 spu sigreturn sys_ni_syscall 163 - 120 nospu clone ppc_clone 161 + 120 32 clone ppc_clone sys_clone 162 + 120 64 clone sys_clone 163 + 120 spu clone sys_ni_syscall 164 164 121 common setdomainname sys_setdomainname 165 165 122 common uname sys_newuname 166 166 123 common modify_ldt sys_ni_syscall ··· 244 240 186 spu sendfile sys_sendfile64 245 241 187 common getpmsg sys_ni_syscall 246 242 188 common putpmsg sys_ni_syscall 247 - 189 nospu vfork ppc_vfork 243 + 189 32 vfork ppc_vfork sys_vfork 244 + 189 64 vfork sys_vfork 245 + 189 spu vfork sys_ni_syscall 248 246 190 common ugetrlimit sys_getrlimit compat_sys_getrlimit 249 247 191 common readahead sys_readahead compat_sys_readahead 250 248 192 32 mmap2 sys_mmap2 compat_sys_mmap2 ··· 322 316 248 32 clock_nanosleep sys_clock_nanosleep_time32 323 317 248 64 clock_nanosleep sys_clock_nanosleep 324 318 248 spu clock_nanosleep sys_clock_nanosleep 325 - 249 32 swapcontext ppc_swapcontext ppc32_swapcontext 326 - 249 64 swapcontext ppc64_swapcontext 319 + 249 32 swapcontext ppc_swapcontext compat_sys_swapcontext 320 + 249 64 swapcontext sys_swapcontext 327 321 249 spu swapcontext sys_ni_syscall 328 322 250 common tgkill sys_tgkill 329 323 251 32 utimes sys_utimes_time32 ··· 462 456 361 common bpf sys_bpf 463 457 362 nospu execveat sys_execveat compat_sys_execveat 464 458 363 32 switch_endian sys_ni_syscall 465 - 363 64 switch_endian ppc_switch_endian 459 + 363 64 switch_endian sys_switch_endian 466 460 363 spu switch_endian sys_ni_syscall 467 461 364 common userfaultfd sys_userfaultfd 468 462 365 common membarrier sys_membarrier ··· 522 516 432 common fsmount sys_fsmount 523 517 433 common fspick sys_fspick 524 518 434 common pidfd_open sys_pidfd_open 525 - 435 nospu clone3 ppc_clone3 519 + 435 32 clone3 ppc_clone3 sys_clone3 520 + 435 64 clone3 sys_clone3 521 + 435 spu clone3 sys_ni_syscall 526 522 437 common openat2 sys_openat2 527 523 438 common pidfd_getfd sys_pidfd_getfd
+215 -184
arch/powerpc/kernel/sysfs.c
··· 87 87 88 88 #endif /* CONFIG_PPC64 */ 89 89 90 + #define __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, EXTRA) \ 91 + static void read_##NAME(void *val) \ 92 + { \ 93 + *(unsigned long *)val = mfspr(ADDRESS); \ 94 + } \ 95 + static void write_##NAME(void *val) \ 96 + { \ 97 + EXTRA; \ 98 + mtspr(ADDRESS, *(unsigned long *)val); \ 99 + } 100 + 101 + #define __SYSFS_SPRSETUP_SHOW_STORE(NAME) \ 102 + static ssize_t show_##NAME(struct device *dev, \ 103 + struct device_attribute *attr, \ 104 + char *buf) \ 105 + { \ 106 + struct cpu *cpu = container_of(dev, struct cpu, dev); \ 107 + unsigned long val; \ 108 + smp_call_function_single(cpu->dev.id, read_##NAME, &val, 1); \ 109 + return sprintf(buf, "%lx\n", val); \ 110 + } \ 111 + static ssize_t __used \ 112 + store_##NAME(struct device *dev, struct device_attribute *attr, \ 113 + const char *buf, size_t count) \ 114 + { \ 115 + struct cpu *cpu = container_of(dev, struct cpu, dev); \ 116 + unsigned long val; \ 117 + int ret = sscanf(buf, "%lx", &val); \ 118 + if (ret != 1) \ 119 + return -EINVAL; \ 120 + smp_call_function_single(cpu->dev.id, write_##NAME, &val, 1); \ 121 + return count; \ 122 + } 123 + 124 + #define SYSFS_PMCSETUP(NAME, ADDRESS) \ 125 + __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, ppc_enable_pmcs()) \ 126 + __SYSFS_SPRSETUP_SHOW_STORE(NAME) 127 + #define SYSFS_SPRSETUP(NAME, ADDRESS) \ 128 + __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, ) \ 129 + __SYSFS_SPRSETUP_SHOW_STORE(NAME) 130 + 131 + #define SYSFS_SPRSETUP_SHOW_STORE(NAME) \ 132 + __SYSFS_SPRSETUP_SHOW_STORE(NAME) 133 + 134 + #ifdef CONFIG_PPC64 135 + 136 + /* 137 + * This is the system wide DSCR register default value. Any 138 + * change to this default value through the sysfs interface 139 + * will update all per cpu DSCR default values across the 140 + * system stored in their respective PACA structures. 141 + */ 142 + static unsigned long dscr_default; 143 + 144 + /** 145 + * read_dscr() - Fetch the cpu specific DSCR default 146 + * @val: Returned cpu specific DSCR default value 147 + * 148 + * This function returns the per cpu DSCR default value 149 + * for any cpu which is contained in it's PACA structure. 150 + */ 151 + static void read_dscr(void *val) 152 + { 153 + *(unsigned long *)val = get_paca()->dscr_default; 154 + } 155 + 156 + 157 + /** 158 + * write_dscr() - Update the cpu specific DSCR default 159 + * @val: New cpu specific DSCR default value to update 160 + * 161 + * This function updates the per cpu DSCR default value 162 + * for any cpu which is contained in it's PACA structure. 163 + */ 164 + static void write_dscr(void *val) 165 + { 166 + get_paca()->dscr_default = *(unsigned long *)val; 167 + if (!current->thread.dscr_inherit) { 168 + current->thread.dscr = *(unsigned long *)val; 169 + mtspr(SPRN_DSCR, *(unsigned long *)val); 170 + } 171 + } 172 + 173 + SYSFS_SPRSETUP_SHOW_STORE(dscr); 174 + static DEVICE_ATTR(dscr, 0600, show_dscr, store_dscr); 175 + 176 + static void add_write_permission_dev_attr(struct device_attribute *attr) 177 + { 178 + attr->attr.mode |= 0200; 179 + } 180 + 181 + /** 182 + * show_dscr_default() - Fetch the system wide DSCR default 183 + * @dev: Device structure 184 + * @attr: Device attribute structure 185 + * @buf: Interface buffer 186 + * 187 + * This function returns the system wide DSCR default value. 188 + */ 189 + static ssize_t show_dscr_default(struct device *dev, 190 + struct device_attribute *attr, char *buf) 191 + { 192 + return sprintf(buf, "%lx\n", dscr_default); 193 + } 194 + 195 + /** 196 + * store_dscr_default() - Update the system wide DSCR default 197 + * @dev: Device structure 198 + * @attr: Device attribute structure 199 + * @buf: Interface buffer 200 + * @count: Size of the update 201 + * 202 + * This function updates the system wide DSCR default value. 203 + */ 204 + static ssize_t __used store_dscr_default(struct device *dev, 205 + struct device_attribute *attr, const char *buf, 206 + size_t count) 207 + { 208 + unsigned long val; 209 + int ret = 0; 210 + 211 + ret = sscanf(buf, "%lx", &val); 212 + if (ret != 1) 213 + return -EINVAL; 214 + dscr_default = val; 215 + 216 + on_each_cpu(write_dscr, &val, 1); 217 + 218 + return count; 219 + } 220 + 221 + static DEVICE_ATTR(dscr_default, 0600, 222 + show_dscr_default, store_dscr_default); 223 + 224 + static void sysfs_create_dscr_default(void) 225 + { 226 + if (cpu_has_feature(CPU_FTR_DSCR)) { 227 + int err = 0; 228 + int cpu; 229 + 230 + dscr_default = spr_default_dscr; 231 + for_each_possible_cpu(cpu) 232 + paca_ptrs[cpu]->dscr_default = dscr_default; 233 + 234 + err = device_create_file(cpu_subsys.dev_root, &dev_attr_dscr_default); 235 + } 236 + } 237 + #endif /* CONFIG_PPC64 */ 238 + 90 239 #ifdef CONFIG_PPC_FSL_BOOK3E 91 240 #define MAX_BIT 63 92 241 ··· 556 407 } 557 408 EXPORT_SYMBOL(ppc_enable_pmcs); 558 409 559 - #define __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, EXTRA) \ 560 - static void read_##NAME(void *val) \ 561 - { \ 562 - *(unsigned long *)val = mfspr(ADDRESS); \ 563 - } \ 564 - static void write_##NAME(void *val) \ 565 - { \ 566 - EXTRA; \ 567 - mtspr(ADDRESS, *(unsigned long *)val); \ 568 - } 569 410 570 - #define __SYSFS_SPRSETUP_SHOW_STORE(NAME) \ 571 - static ssize_t show_##NAME(struct device *dev, \ 572 - struct device_attribute *attr, \ 573 - char *buf) \ 574 - { \ 575 - struct cpu *cpu = container_of(dev, struct cpu, dev); \ 576 - unsigned long val; \ 577 - smp_call_function_single(cpu->dev.id, read_##NAME, &val, 1); \ 578 - return sprintf(buf, "%lx\n", val); \ 579 - } \ 580 - static ssize_t __used \ 581 - store_##NAME(struct device *dev, struct device_attribute *attr, \ 582 - const char *buf, size_t count) \ 583 - { \ 584 - struct cpu *cpu = container_of(dev, struct cpu, dev); \ 585 - unsigned long val; \ 586 - int ret = sscanf(buf, "%lx", &val); \ 587 - if (ret != 1) \ 588 - return -EINVAL; \ 589 - smp_call_function_single(cpu->dev.id, write_##NAME, &val, 1); \ 590 - return count; \ 591 - } 592 - 593 - #define SYSFS_PMCSETUP(NAME, ADDRESS) \ 594 - __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, ppc_enable_pmcs()) \ 595 - __SYSFS_SPRSETUP_SHOW_STORE(NAME) 596 - #define SYSFS_SPRSETUP(NAME, ADDRESS) \ 597 - __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, ) \ 598 - __SYSFS_SPRSETUP_SHOW_STORE(NAME) 599 - 600 - #define SYSFS_SPRSETUP_SHOW_STORE(NAME) \ 601 - __SYSFS_SPRSETUP_SHOW_STORE(NAME) 602 411 603 412 /* Let's define all possible registers, we'll only hook up the ones 604 413 * that are implemented on the current processor 605 414 */ 606 415 607 - #if defined(CONFIG_PPC64) 416 + #ifdef CONFIG_PMU_SYSFS 417 + #if defined(CONFIG_PPC64) || defined(CONFIG_PPC_BOOK3S_32) 608 418 #define HAS_PPC_PMC_CLASSIC 1 609 419 #define HAS_PPC_PMC_IBM 1 610 - #define HAS_PPC_PMC_PA6T 1 611 - #elif defined(CONFIG_PPC_BOOK3S_32) 612 - #define HAS_PPC_PMC_CLASSIC 1 613 - #define HAS_PPC_PMC_IBM 1 614 - #define HAS_PPC_PMC_G4 1 615 - #endif 616 - 617 - 618 - #ifdef HAS_PPC_PMC_CLASSIC 619 - SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0); 620 - SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1); 621 - SYSFS_PMCSETUP(pmc1, SPRN_PMC1); 622 - SYSFS_PMCSETUP(pmc2, SPRN_PMC2); 623 - SYSFS_PMCSETUP(pmc3, SPRN_PMC3); 624 - SYSFS_PMCSETUP(pmc4, SPRN_PMC4); 625 - SYSFS_PMCSETUP(pmc5, SPRN_PMC5); 626 - SYSFS_PMCSETUP(pmc6, SPRN_PMC6); 627 - 628 - #ifdef HAS_PPC_PMC_G4 629 - SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2); 630 420 #endif 631 421 632 422 #ifdef CONFIG_PPC64 633 - SYSFS_PMCSETUP(pmc7, SPRN_PMC7); 634 - SYSFS_PMCSETUP(pmc8, SPRN_PMC8); 423 + #define HAS_PPC_PMC_PA6T 1 424 + #define HAS_PPC_PMC56 1 425 + #endif 635 426 636 - SYSFS_PMCSETUP(mmcra, SPRN_MMCRA); 427 + #ifdef CONFIG_PPC_BOOK3S_32 428 + #define HAS_PPC_PMC_G4 1 429 + #endif 430 + #endif /* CONFIG_PMU_SYSFS */ 431 + 432 + #if defined(CONFIG_PPC64) && defined(CONFIG_DEBUG_MISC) 433 + #define HAS_PPC_PA6T 434 + #endif 435 + /* 436 + * SPRs which are not related to PMU. 437 + */ 438 + #ifdef CONFIG_PPC64 637 439 SYSFS_SPRSETUP(purr, SPRN_PURR); 638 440 SYSFS_SPRSETUP(spurr, SPRN_SPURR); 639 441 SYSFS_SPRSETUP(pir, SPRN_PIR); ··· 595 495 enable write when needed with a separate function. 596 496 Lets be conservative and default to pseries. 597 497 */ 598 - static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra); 599 498 static DEVICE_ATTR(spurr, 0400, show_spurr, NULL); 600 499 static DEVICE_ATTR(purr, 0400, show_purr, store_purr); 601 500 static DEVICE_ATTR(pir, 0400, show_pir, NULL); 602 501 static DEVICE_ATTR(tscr, 0600, show_tscr, store_tscr); 603 - 604 - /* 605 - * This is the system wide DSCR register default value. Any 606 - * change to this default value through the sysfs interface 607 - * will update all per cpu DSCR default values across the 608 - * system stored in their respective PACA structures. 609 - */ 610 - static unsigned long dscr_default; 611 - 612 - /** 613 - * read_dscr() - Fetch the cpu specific DSCR default 614 - * @val: Returned cpu specific DSCR default value 615 - * 616 - * This function returns the per cpu DSCR default value 617 - * for any cpu which is contained in it's PACA structure. 618 - */ 619 - static void read_dscr(void *val) 620 - { 621 - *(unsigned long *)val = get_paca()->dscr_default; 622 - } 623 - 624 - 625 - /** 626 - * write_dscr() - Update the cpu specific DSCR default 627 - * @val: New cpu specific DSCR default value to update 628 - * 629 - * This function updates the per cpu DSCR default value 630 - * for any cpu which is contained in it's PACA structure. 631 - */ 632 - static void write_dscr(void *val) 633 - { 634 - get_paca()->dscr_default = *(unsigned long *)val; 635 - if (!current->thread.dscr_inherit) { 636 - current->thread.dscr = *(unsigned long *)val; 637 - mtspr(SPRN_DSCR, *(unsigned long *)val); 638 - } 639 - } 640 - 641 - SYSFS_SPRSETUP_SHOW_STORE(dscr); 642 - static DEVICE_ATTR(dscr, 0600, show_dscr, store_dscr); 643 - 644 - static void add_write_permission_dev_attr(struct device_attribute *attr) 645 - { 646 - attr->attr.mode |= 0200; 647 - } 648 - 649 - /** 650 - * show_dscr_default() - Fetch the system wide DSCR default 651 - * @dev: Device structure 652 - * @attr: Device attribute structure 653 - * @buf: Interface buffer 654 - * 655 - * This function returns the system wide DSCR default value. 656 - */ 657 - static ssize_t show_dscr_default(struct device *dev, 658 - struct device_attribute *attr, char *buf) 659 - { 660 - return sprintf(buf, "%lx\n", dscr_default); 661 - } 662 - 663 - /** 664 - * store_dscr_default() - Update the system wide DSCR default 665 - * @dev: Device structure 666 - * @attr: Device attribute structure 667 - * @buf: Interface buffer 668 - * @count: Size of the update 669 - * 670 - * This function updates the system wide DSCR default value. 671 - */ 672 - static ssize_t __used store_dscr_default(struct device *dev, 673 - struct device_attribute *attr, const char *buf, 674 - size_t count) 675 - { 676 - unsigned long val; 677 - int ret = 0; 678 - 679 - ret = sscanf(buf, "%lx", &val); 680 - if (ret != 1) 681 - return -EINVAL; 682 - dscr_default = val; 683 - 684 - on_each_cpu(write_dscr, &val, 1); 685 - 686 - return count; 687 - } 688 - 689 - static DEVICE_ATTR(dscr_default, 0600, 690 - show_dscr_default, store_dscr_default); 691 - 692 - static void sysfs_create_dscr_default(void) 693 - { 694 - if (cpu_has_feature(CPU_FTR_DSCR)) { 695 - int err = 0; 696 - int cpu; 697 - 698 - dscr_default = spr_default_dscr; 699 - for_each_possible_cpu(cpu) 700 - paca_ptrs[cpu]->dscr_default = dscr_default; 701 - 702 - err = device_create_file(cpu_subsys.dev_root, &dev_attr_dscr_default); 703 - } 704 - } 705 - 706 502 #endif /* CONFIG_PPC64 */ 503 + 504 + #ifdef HAS_PPC_PMC_CLASSIC 505 + SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0); 506 + SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1); 507 + SYSFS_PMCSETUP(pmc1, SPRN_PMC1); 508 + SYSFS_PMCSETUP(pmc2, SPRN_PMC2); 509 + SYSFS_PMCSETUP(pmc3, SPRN_PMC3); 510 + SYSFS_PMCSETUP(pmc4, SPRN_PMC4); 511 + SYSFS_PMCSETUP(pmc5, SPRN_PMC5); 512 + SYSFS_PMCSETUP(pmc6, SPRN_PMC6); 513 + #endif 514 + 515 + #ifdef HAS_PPC_PMC_G4 516 + SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2); 517 + #endif 518 + 519 + #ifdef HAS_PPC_PMC56 520 + SYSFS_PMCSETUP(pmc7, SPRN_PMC7); 521 + SYSFS_PMCSETUP(pmc8, SPRN_PMC8); 522 + 523 + SYSFS_PMCSETUP(mmcra, SPRN_MMCRA); 524 + 525 + static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra); 526 + #endif /* HAS_PPC_PMC56 */ 527 + 528 + 529 + 707 530 708 531 #ifdef HAS_PPC_PMC_PA6T 709 532 SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0); ··· 635 612 SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3); 636 613 SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4); 637 614 SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5); 638 - #ifdef CONFIG_DEBUG_MISC 615 + #endif 616 + 617 + #ifdef HAS_PPC_PA6T 639 618 SYSFS_SPRSETUP(hid0, SPRN_HID0); 640 619 SYSFS_SPRSETUP(hid1, SPRN_HID1); 641 620 SYSFS_SPRSETUP(hid4, SPRN_HID4); ··· 666 641 SYSFS_SPRSETUP(tsr1, SPRN_PA6T_TSR1); 667 642 SYSFS_SPRSETUP(tsr2, SPRN_PA6T_TSR2); 668 643 SYSFS_SPRSETUP(tsr3, SPRN_PA6T_TSR3); 669 - #endif /* CONFIG_DEBUG_MISC */ 670 - #endif /* HAS_PPC_PMC_PA6T */ 644 + #endif /* HAS_PPC_PA6T */ 671 645 672 646 #ifdef HAS_PPC_PMC_IBM 673 647 static struct device_attribute ibm_common_attrs[] = { 674 648 __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), 675 649 __ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), 676 650 }; 677 - #endif /* HAS_PPC_PMC_G4 */ 651 + #endif /* HAS_PPC_PMC_IBM */ 678 652 679 653 #ifdef HAS_PPC_PMC_G4 680 654 static struct device_attribute g4_common_attrs[] = { ··· 683 659 }; 684 660 #endif /* HAS_PPC_PMC_G4 */ 685 661 662 + #ifdef HAS_PPC_PMC_CLASSIC 686 663 static struct device_attribute classic_pmc_attrs[] = { 687 664 __ATTR(pmc1, 0600, show_pmc1, store_pmc1), 688 665 __ATTR(pmc2, 0600, show_pmc2, store_pmc2), ··· 691 666 __ATTR(pmc4, 0600, show_pmc4, store_pmc4), 692 667 __ATTR(pmc5, 0600, show_pmc5, store_pmc5), 693 668 __ATTR(pmc6, 0600, show_pmc6, store_pmc6), 694 - #ifdef CONFIG_PPC64 669 + #ifdef HAS_PPC_PMC56 695 670 __ATTR(pmc7, 0600, show_pmc7, store_pmc7), 696 671 __ATTR(pmc8, 0600, show_pmc8, store_pmc8), 697 672 #endif 698 673 }; 674 + #endif 699 675 700 - #ifdef HAS_PPC_PMC_PA6T 676 + #if defined(HAS_PPC_PMC_PA6T) || defined(HAS_PPC_PA6T) 701 677 static struct device_attribute pa6t_attrs[] = { 678 + #ifdef HAS_PPC_PMC_PA6T 702 679 __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), 703 680 __ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), 704 681 __ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0), ··· 709 682 __ATTR(pmc3, 0600, show_pa6t_pmc3, store_pa6t_pmc3), 710 683 __ATTR(pmc4, 0600, show_pa6t_pmc4, store_pa6t_pmc4), 711 684 __ATTR(pmc5, 0600, show_pa6t_pmc5, store_pa6t_pmc5), 712 - #ifdef CONFIG_DEBUG_MISC 685 + #endif 686 + #ifdef HAS_PPC_PA6T 713 687 __ATTR(hid0, 0600, show_hid0, store_hid0), 714 688 __ATTR(hid1, 0600, show_hid1, store_hid1), 715 689 __ATTR(hid4, 0600, show_hid4, store_hid4), ··· 739 711 __ATTR(tsr1, 0600, show_tsr1, store_tsr1), 740 712 __ATTR(tsr2, 0600, show_tsr2, store_tsr2), 741 713 __ATTR(tsr3, 0600, show_tsr3, store_tsr3), 742 - #endif /* CONFIG_DEBUG_MISC */ 714 + #endif /* HAS_PPC_PA6T */ 743 715 }; 744 - #endif /* HAS_PPC_PMC_PA6T */ 745 - #endif /* HAS_PPC_PMC_CLASSIC */ 716 + #endif 746 717 747 718 #ifdef CONFIG_PPC_SVM 748 719 static ssize_t show_svm(struct device *dev, struct device_attribute *attr, char *buf) ··· 792 765 pmc_attrs = classic_pmc_attrs; 793 766 break; 794 767 #endif /* HAS_PPC_PMC_G4 */ 795 - #ifdef HAS_PPC_PMC_PA6T 768 + #if defined(HAS_PPC_PMC_PA6T) || defined(HAS_PPC_PA6T) 796 769 case PPC_PMC_PA6T: 797 770 /* PA Semi starts counting at PMC0 */ 798 771 attrs = pa6t_attrs; 799 772 nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute); 800 773 pmc_attrs = NULL; 801 774 break; 802 - #endif /* HAS_PPC_PMC_PA6T */ 775 + #endif 803 776 default: 804 777 attrs = NULL; 805 778 nattrs = 0; ··· 814 787 device_create_file(s, &pmc_attrs[i]); 815 788 816 789 #ifdef CONFIG_PPC64 790 + #ifdef CONFIG_PMU_SYSFS 817 791 if (cpu_has_feature(CPU_FTR_MMCRA)) 818 792 device_create_file(s, &dev_attr_mmcra); 793 + #endif /* CONFIG_PMU_SYSFS */ 819 794 820 795 if (cpu_has_feature(CPU_FTR_PURR)) { 821 796 if (!firmware_has_feature(FW_FEATURE_LPAR)) ··· 883 854 pmc_attrs = classic_pmc_attrs; 884 855 break; 885 856 #endif /* HAS_PPC_PMC_G4 */ 886 - #ifdef HAS_PPC_PMC_PA6T 857 + #if defined(HAS_PPC_PMC_PA6T) || defined(HAS_PPC_PA6T) 887 858 case PPC_PMC_PA6T: 888 859 /* PA Semi starts counting at PMC0 */ 889 860 attrs = pa6t_attrs; 890 861 nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute); 891 862 pmc_attrs = NULL; 892 863 break; 893 - #endif /* HAS_PPC_PMC_PA6T */ 864 + #endif 894 865 default: 895 866 attrs = NULL; 896 867 nattrs = 0; ··· 905 876 device_remove_file(s, &pmc_attrs[i]); 906 877 907 878 #ifdef CONFIG_PPC64 879 + #ifdef CONFIG_PMU_SYSFS 908 880 if (cpu_has_feature(CPU_FTR_MMCRA)) 909 881 device_remove_file(s, &dev_attr_mmcra); 882 + #endif /* CONFIG_PMU_SYSFS */ 910 883 911 884 if (cpu_has_feature(CPU_FTR_PURR)) 912 885 device_remove_file(s, &dev_attr_purr);
+3 -6
arch/powerpc/kernel/systbl.S
··· 16 16 17 17 #ifdef CONFIG_PPC64 18 18 .p2align 3 19 + #define __SYSCALL(nr, entry) .8byte entry 20 + #else 21 + #define __SYSCALL(nr, entry) .long entry 19 22 #endif 20 23 21 24 .globl sys_call_table 22 25 sys_call_table: 23 26 #ifdef CONFIG_PPC64 24 - #define __SYSCALL(nr, entry) .8byte DOTSYM(entry) 25 27 #include <asm/syscall_table_64.h> 26 - #undef __SYSCALL 27 28 #else 28 - #define __SYSCALL(nr, entry) .long entry 29 29 #include <asm/syscall_table_32.h> 30 - #undef __SYSCALL 31 30 #endif 32 31 33 32 #ifdef CONFIG_COMPAT 34 33 .globl compat_sys_call_table 35 34 compat_sys_call_table: 36 35 #define compat_sys_sigsuspend sys_sigsuspend 37 - #define __SYSCALL(nr, entry) .8byte DOTSYM(entry) 38 36 #include <asm/syscall_table_c32.h> 39 - #undef __SYSCALL 40 37 #endif
-9
arch/powerpc/kernel/time.c
··· 663 663 } 664 664 #endif 665 665 666 - /* 667 - * Hypervisor decrementer interrupts shouldn't occur but are sometimes 668 - * left pending on exit from a KVM guest. We don't need to do anything 669 - * to clear them, as they are edge-triggered. 670 - */ 671 - void hdec_interrupt(struct pt_regs *regs) 672 - { 673 - } 674 - 675 666 #ifdef CONFIG_SUSPEND 676 667 static void generic_suspend_disable_irqs(void) 677 668 {
+5 -20
arch/powerpc/kernel/traps.c
··· 2278 2278 2279 2279 static int __init ppc_warn_emulated_init(void) 2280 2280 { 2281 - struct dentry *dir, *d; 2281 + struct dentry *dir; 2282 2282 unsigned int i; 2283 2283 struct ppc_emulated_entry *entries = (void *)&ppc_emulated; 2284 2284 2285 - if (!powerpc_debugfs_root) 2286 - return -ENODEV; 2287 - 2288 2285 dir = debugfs_create_dir("emulated_instructions", 2289 2286 powerpc_debugfs_root); 2290 - if (!dir) 2291 - return -ENOMEM; 2292 2287 2293 - d = debugfs_create_u32("do_warn", 0644, dir, 2294 - &ppc_warn_emulated); 2295 - if (!d) 2296 - goto fail; 2288 + debugfs_create_u32("do_warn", 0644, dir, &ppc_warn_emulated); 2297 2289 2298 - for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) { 2299 - d = debugfs_create_u32(entries[i].name, 0644, dir, 2300 - (u32 *)&entries[i].val.counter); 2301 - if (!d) 2302 - goto fail; 2303 - } 2290 + for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) 2291 + debugfs_create_u32(entries[i].name, 0644, dir, 2292 + (u32 *)&entries[i].val.counter); 2304 2293 2305 2294 return 0; 2306 - 2307 - fail: 2308 - debugfs_remove_recursive(dir); 2309 - return -ENOMEM; 2310 2295 } 2311 2296 2312 2297 device_initcall(ppc_warn_emulated_init);
-5
arch/powerpc/kernel/vdso.c
··· 391 391 symname); 392 392 return 0; 393 393 } 394 - #ifdef VDS64_HAS_DESCRIPTORS 395 - return *((u64 *)(vdso64_kbase + sym->st_value - VDSO64_LBASE)) - 396 - VDSO64_LBASE; 397 - #else 398 394 return sym->st_value - VDSO64_LBASE; 399 - #endif 400 395 } 401 396 402 397 static int __init vdso_do_func_patch64(struct lib32_elfinfo *v32,
+1 -1
arch/powerpc/kernel/vector.S
··· 134 134 /* enable use of VSX after return */ 135 135 oris r12,r12,MSR_VSX@h 136 136 std r12,_MSR(r1) 137 - b fast_exception_return 137 + b fast_interrupt_return 138 138 139 139 #endif /* CONFIG_VSX */ 140 140
+1
arch/powerpc/kernel/vmlinux.lds.S
··· 256 256 *(.dynamic) 257 257 } 258 258 .hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) } 259 + .gnu.hash : AT(ADDR(.gnu.hash) - LOAD_OFFSET) { *(.gnu.hash) } 259 260 .interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) } 260 261 .rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET) 261 262 {
-3
arch/powerpc/kexec/Makefile
··· 3 3 # Makefile for the linux kernel. 4 4 # 5 5 6 - # Avoid clang warnings around longjmp/setjmp declarations 7 - CFLAGS_crash.o += -ffreestanding 8 - 9 6 obj-y += core.o crash.o core_$(BITS).o 10 7 11 8 obj-$(CONFIG_PPC32) += relocate_32.o
+2 -3
arch/powerpc/kvm/book3s_64_mmu_hv.c
··· 2133 2133 2134 2134 void kvmppc_mmu_debugfs_init(struct kvm *kvm) 2135 2135 { 2136 - kvm->arch.htab_dentry = debugfs_create_file("htab", 0400, 2137 - kvm->arch.debugfs_dir, kvm, 2138 - &debugfs_htab_fops); 2136 + debugfs_create_file("htab", 0400, kvm->arch.debugfs_dir, kvm, 2137 + &debugfs_htab_fops); 2139 2138 } 2140 2139 2141 2140 void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu)
+2 -3
arch/powerpc/kvm/book3s_64_mmu_radix.c
··· 1376 1376 1377 1377 void kvmhv_radix_debugfs_init(struct kvm *kvm) 1378 1378 { 1379 - kvm->arch.radix_dentry = debugfs_create_file("radix", 0400, 1380 - kvm->arch.debugfs_dir, kvm, 1381 - &debugfs_radix_fops); 1379 + debugfs_create_file("radix", 0400, kvm->arch.debugfs_dir, kvm, 1380 + &debugfs_radix_fops); 1382 1381 } 1383 1382 1384 1383 int kvmppc_radix_init(void)
+2 -7
arch/powerpc/kvm/book3s_hv.c
··· 2267 2267 struct kvm *kvm = vcpu->kvm; 2268 2268 2269 2269 snprintf(buf, sizeof(buf), "vcpu%u", id); 2270 - if (IS_ERR_OR_NULL(kvm->arch.debugfs_dir)) 2271 - return; 2272 2270 vcpu->arch.debugfs_dir = debugfs_create_dir(buf, kvm->arch.debugfs_dir); 2273 - if (IS_ERR_OR_NULL(vcpu->arch.debugfs_dir)) 2274 - return; 2275 - vcpu->arch.debugfs_timings = 2276 - debugfs_create_file("timings", 0444, vcpu->arch.debugfs_dir, 2277 - vcpu, &debugfs_timings_ops); 2271 + debugfs_create_file("timings", 0444, vcpu->arch.debugfs_dir, vcpu, 2272 + &debugfs_timings_ops); 2278 2273 } 2279 2274 2280 2275 #else /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
-11
arch/powerpc/kvm/book3s_hv_rmhandlers.S
··· 1266 1266 * R12 = (guest CR << 32) | interrupt vector 1267 1267 * R13 = PACA 1268 1268 * guest R12 saved in shadow VCPU SCRATCH0 1269 - * guest CTR saved in shadow VCPU SCRATCH1 if RELOCATABLE 1270 1269 * guest R13 saved in SPRN_SCRATCH0 1271 1270 */ 1272 1271 std r9, HSTATE_SCRATCH2(r13) ··· 1366 1367 11: stw r3,VCPU_HEIR(r9) 1367 1368 1368 1369 /* these are volatile across C function calls */ 1369 - #ifdef CONFIG_RELOCATABLE 1370 - ld r3, HSTATE_SCRATCH1(r13) 1371 - mtctr r3 1372 - #else 1373 1370 mfctr r3 1374 - #endif 1375 1371 mfxer r4 1376 1372 std r3, VCPU_CTR(r9) 1377 1373 std r4, VCPU_XER(r9) ··· 3252 3258 * r12 is (CR << 32) | vector 3253 3259 * r13 points to our PACA 3254 3260 * r12 is saved in HSTATE_SCRATCH0(r13) 3255 - * ctr is saved in HSTATE_SCRATCH1(r13) if RELOCATABLE 3256 3261 * r9 is saved in HSTATE_SCRATCH2(r13) 3257 3262 * r13 is saved in HSPRG1 3258 3263 * cfar is saved in HSTATE_CFAR(r13) ··· 3300 3307 ld r5, HSTATE_CFAR(r13) 3301 3308 std r5, ORIG_GPR3(r1) 3302 3309 mflr r3 3303 - #ifdef CONFIG_RELOCATABLE 3304 - ld r4, HSTATE_SCRATCH1(r13) 3305 - #else 3306 3310 mfctr r4 3307 - #endif 3308 3311 mfxer r5 3309 3312 lbz r6, PACAIRQSOFTMASK(r13) 3310 3313 std r3, _LINK(r1)
-7
arch/powerpc/kvm/book3s_segment.S
··· 167 167 * R12 = (guest CR << 32) | exit handler id 168 168 * R13 = PACA 169 169 * HSTATE.SCRATCH0 = guest R12 170 - * HSTATE.SCRATCH1 = guest CTR if RELOCATABLE 171 170 */ 172 171 #ifdef CONFIG_PPC64 173 172 /* Match 32-bit entry */ 174 - #ifdef CONFIG_RELOCATABLE 175 - std r9, HSTATE_SCRATCH2(r13) 176 - ld r9, HSTATE_SCRATCH1(r13) 177 - mtctr r9 178 - ld r9, HSTATE_SCRATCH2(r13) 179 - #endif 180 173 rotldi r12, r12, 32 /* Flip R12 halves for stw */ 181 174 stw r12, HSTATE_SCRATCH1(r13) /* CR is now in the low half */ 182 175 srdi r12, r12, 32 /* shift trap into low half */
+4 -13
arch/powerpc/kvm/timing.c
··· 211 211 212 212 snprintf(dbg_fname, sizeof(dbg_fname), "vm%u_vcpu%u_timing", 213 213 current->pid, id); 214 - debugfs_file = debugfs_create_file(dbg_fname, 0666, 215 - kvm_debugfs_dir, vcpu, 216 - &kvmppc_exit_timing_fops); 217 - 218 - if (!debugfs_file) { 219 - printk(KERN_ERR"%s: error creating debugfs file %s\n", 220 - __func__, dbg_fname); 221 - return; 222 - } 214 + debugfs_file = debugfs_create_file(dbg_fname, 0666, kvm_debugfs_dir, 215 + vcpu, &kvmppc_exit_timing_fops); 223 216 224 217 vcpu->arch.debugfs_exit_timing = debugfs_file; 225 218 } 226 219 227 220 void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu) 228 221 { 229 - if (vcpu->arch.debugfs_exit_timing) { 230 - debugfs_remove(vcpu->arch.debugfs_exit_timing); 231 - vcpu->arch.debugfs_exit_timing = NULL; 232 - } 222 + debugfs_remove(vcpu->arch.debugfs_exit_timing); 223 + vcpu->arch.debugfs_exit_timing = NULL; 233 224 }
+3 -2
arch/powerpc/lib/sstep.c
··· 3179 3179 * entry code works. If that is changed, this will 3180 3180 * need to be changed also. 3181 3181 */ 3182 - if (regs->gpr[0] == 0x1ebe && 3183 - cpu_has_feature(CPU_FTR_REAL_LE)) { 3182 + if (IS_ENABLED(CONFIG_PPC_FAST_ENDIAN_SWITCH) && 3183 + cpu_has_feature(CPU_FTR_REAL_LE) && 3184 + regs->gpr[0] == 0x1ebe) { 3184 3185 regs->msr ^= MSR_LE; 3185 3186 goto instr_done; 3186 3187 }
+4 -3
arch/powerpc/lib/test_emulate_step.c
··· 13 13 #include <asm/code-patching.h> 14 14 15 15 #define IMM_L(i) ((uintptr_t)(i) & 0xffff) 16 + #define IMM_DS(i) ((uintptr_t)(i) & 0xfffc) 16 17 17 18 /* 18 19 * Defined with TEST_ prefix so it does not conflict with other 19 20 * definitions. 20 21 */ 21 22 #define TEST_LD(r, base, i) (PPC_INST_LD | ___PPC_RT(r) | \ 22 - ___PPC_RA(base) | IMM_L(i)) 23 + ___PPC_RA(base) | IMM_DS(i)) 23 24 #define TEST_LWZ(r, base, i) (PPC_INST_LWZ | ___PPC_RT(r) | \ 24 25 ___PPC_RA(base) | IMM_L(i)) 25 26 #define TEST_LWZX(t, a, b) (PPC_INST_LWZX | ___PPC_RT(t) | \ 26 27 ___PPC_RA(a) | ___PPC_RB(b)) 27 28 #define TEST_STD(r, base, i) (PPC_INST_STD | ___PPC_RS(r) | \ 28 - ___PPC_RA(base) | ((i) & 0xfffc)) 29 + ___PPC_RA(base) | IMM_DS(i)) 29 30 #define TEST_LDARX(t, a, b, eh) (PPC_INST_LDARX | ___PPC_RT(t) | \ 30 31 ___PPC_RA(a) | ___PPC_RB(b) | \ 31 32 __PPC_EH(eh)) ··· 161 160 162 161 /* std r5, 0(r3) */ 163 162 stepped = emulate_step(&regs, TEST_STD(5, 3, 0)); 164 - if (stepped == 1 || regs.gpr[5] == a) 163 + if (stepped == 1 && regs.gpr[5] == a) 165 164 show_result("std", "PASS"); 166 165 else 167 166 show_result("std", "FAIL");
+14 -13
arch/powerpc/mm/book3s32/hash_low.S
··· 35 35 /* 36 36 * Load a PTE into the hash table, if possible. 37 37 * The address is in r4, and r3 contains an access flag: 38 - * _PAGE_RW (0x400) if a write. 38 + * _PAGE_RW (0x002) if a write. 39 39 * r9 contains the SRR1 value, from which we use the MSR_PR bit. 40 40 * SPRG_THREAD contains the physical address of the current task's thread. 41 41 * ··· 69 69 blt+ 112f /* assume user more likely */ 70 70 lis r5, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */ 71 71 addi r5 ,r5 ,(swapper_pg_dir - PAGE_OFFSET)@l /* kernel page table */ 72 - rlwimi r3,r9,32-12,29,29 /* MSR_PR -> _PAGE_USER */ 72 + rlwimi r3,r9,32-14,31,31 /* MSR_PR -> _PAGE_USER */ 73 73 112: 74 74 #ifndef CONFIG_PTE_64BIT 75 75 rlwimi r5,r4,12,20,29 /* insert top 10 bits of address */ ··· 94 94 #else 95 95 rlwimi r8,r4,23,20,28 /* compute pte address */ 96 96 #endif 97 - rlwinm r0,r3,32-3,24,24 /* _PAGE_RW access -> _PAGE_DIRTY */ 97 + rlwinm r0,r3,6,24,24 /* _PAGE_RW access -> _PAGE_DIRTY */ 98 98 ori r0,r0,_PAGE_ACCESSED|_PAGE_HASHPTE 99 99 100 100 /* ··· 310 310 311 311 _GLOBAL(create_hpte) 312 312 /* Convert linux-style PTE (r5) to low word of PPC-style PTE (r8) */ 313 - rlwinm r8,r5,32-9,30,30 /* _PAGE_RW -> PP msb */ 314 313 rlwinm r0,r5,32-6,30,30 /* _PAGE_DIRTY -> PP msb */ 315 - and r8,r8,r0 /* writable if _RW & _DIRTY */ 316 - rlwimi r5,r5,32-1,30,30 /* _PAGE_USER -> PP msb */ 317 - rlwimi r5,r5,32-2,31,31 /* _PAGE_USER -> PP lsb */ 314 + and r8,r5,r0 /* writable if _RW & _DIRTY */ 315 + rlwimi r5,r5,1,30,30 /* _PAGE_USER -> PP msb */ 318 316 ori r8,r8,0xe04 /* clear out reserved bits */ 319 317 andc r8,r5,r8 /* PP = user? (rw&dirty? 1: 3): 0 */ 320 318 BEGIN_FTR_SECTION ··· 564 566 33: lwarx r8,0,r5 /* fetch the pte flags word */ 565 567 andi. r0,r8,_PAGE_HASHPTE 566 568 beq 8f /* done if HASHPTE is already clear */ 567 - rlwinm r8,r8,0,31,29 /* clear HASHPTE bit */ 569 + rlwinm r8,r8,0,~_PAGE_HASHPTE /* clear HASHPTE bit */ 568 570 stwcx. r8,0,r5 /* update the pte */ 569 571 bne- 33b 570 572 ··· 688 690 bne- 10b 689 691 stwcx. r8,0,r9 690 692 bne- 10b 693 + #endif /* CONFIG_SMP */ 694 + li r5, 32 695 + lis r4, KERNELBASE@h 696 + mtctr r5 691 697 sync 692 - tlbia 698 + 0: tlbie r4 699 + addi r4, r4, 0x1000 700 + bdnz 0b 693 701 sync 702 + #ifdef CONFIG_SMP 694 703 TLBSYNC 695 704 li r0,0 696 705 stw r0,0(r9) /* clear mmu_hash_lock */ 697 706 mtmsr r10 698 707 SYNC_601 699 708 isync 700 - #else /* CONFIG_SMP */ 701 - sync 702 - tlbia 703 - sync 704 709 #endif /* CONFIG_SMP */ 705 710 blr
+1 -1
arch/powerpc/mm/book3s32/mmu.c
··· 312 312 313 313 if (!Hash) 314 314 return; 315 - pmd = pmd_offset(pud_offset(pgd_offset(mm, ea), ea), ea); 315 + pmd = pmd_ptr(mm, ea); 316 316 if (!pmd_none(*pmd)) 317 317 add_hash_page(mm->context.id, ea, pmd_val(*pmd)); 318 318 }
+7 -4
arch/powerpc/mm/book3s32/tlb.c
··· 79 79 int count; 80 80 unsigned int ctx = mm->context.id; 81 81 82 + start &= PAGE_MASK; 82 83 if (!Hash) { 83 - _tlbia(); 84 + if (end - start <= PAGE_SIZE) 85 + _tlbie(start); 86 + else 87 + _tlbia(); 84 88 return; 85 89 } 86 - start &= PAGE_MASK; 87 90 if (start >= end) 88 91 return; 89 92 end = (end - 1) | ~PAGE_MASK; 90 - pmd = pmd_offset(pud_offset(pgd_offset(mm, start), start), start); 93 + pmd = pmd_ptr(mm, start); 91 94 for (;;) { 92 95 pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1; 93 96 if (pmd_end > end) ··· 148 145 return; 149 146 } 150 147 mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm; 151 - pmd = pmd_offset(pud_offset(pgd_offset(mm, vmaddr), vmaddr), vmaddr); 148 + pmd = pmd_ptr(mm, vmaddr); 152 149 if (!pmd_none(*pmd)) 153 150 flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1); 154 151 }
+2 -5
arch/powerpc/mm/book3s64/hash_utils.c
··· 2018 2018 2019 2019 static int __init hash64_debugfs(void) 2020 2020 { 2021 - if (!debugfs_create_file_unsafe("hpt_order", 0600, powerpc_debugfs_root, 2022 - NULL, &fops_hpt_order)) { 2023 - pr_err("lpar: unable to create hpt_order debugsfs file\n"); 2024 - } 2025 - 2021 + debugfs_create_file("hpt_order", 0600, powerpc_debugfs_root, NULL, 2022 + &fops_hpt_order); 2026 2023 return 0; 2027 2024 } 2028 2025 machine_device_initcall(pseries, hash64_debugfs);
+21 -18
arch/powerpc/mm/book3s64/iommu_api.c
··· 121 121 goto free_exit; 122 122 } 123 123 124 - pageshift = PAGE_SHIFT; 125 - for (i = 0; i < entries; ++i) { 126 - struct page *page = mem->hpages[i]; 127 - 128 - /* 129 - * Allow to use larger than 64k IOMMU pages. Only do that 130 - * if we are backed by hugetlb. 131 - */ 132 - if ((mem->pageshift > PAGE_SHIFT) && PageHuge(page)) 133 - pageshift = page_shift(compound_head(page)); 134 - mem->pageshift = min(mem->pageshift, pageshift); 135 - /* 136 - * We don't need struct page reference any more, switch 137 - * to physical address. 138 - */ 139 - mem->hpas[i] = page_to_pfn(page) << PAGE_SHIFT; 140 - } 141 - 142 124 good_exit: 143 125 atomic64_set(&mem->mapped, 1); 144 126 mem->used = 1; ··· 137 155 ret = -EINVAL; 138 156 mutex_unlock(&mem_list_mutex); 139 157 goto free_exit; 158 + } 159 + } 160 + 161 + if (mem->dev_hpa == MM_IOMMU_TABLE_INVALID_HPA) { 162 + /* 163 + * Allow to use larger than 64k IOMMU pages. Only do that 164 + * if we are backed by hugetlb. Skip device memory as it is not 165 + * backed with page structs. 166 + */ 167 + pageshift = PAGE_SHIFT; 168 + for (i = 0; i < entries; ++i) { 169 + struct page *page = mem->hpages[i]; 170 + 171 + if ((mem->pageshift > PAGE_SHIFT) && PageHuge(page)) 172 + pageshift = page_shift(compound_head(page)); 173 + mem->pageshift = min(mem->pageshift, pageshift); 174 + /* 175 + * We don't need struct page reference any more, switch 176 + * to physical address. 177 + */ 178 + mem->hpas[i] = page_to_pfn(page) << PAGE_SHIFT; 140 179 } 141 180 } 142 181
+1
arch/powerpc/mm/book3s64/radix_pgtable.c
··· 26 26 #include <asm/firmware.h> 27 27 #include <asm/powernv.h> 28 28 #include <asm/sections.h> 29 + #include <asm/smp.h> 29 30 #include <asm/trace.h> 30 31 #include <asm/uaccess.h> 31 32 #include <asm/ultravisor.h>
+6 -1
arch/powerpc/mm/book3s64/radix_tlb.c
··· 587 587 preempt_enable(); 588 588 } 589 589 EXPORT_SYMBOL(radix__local_flush_all_mm); 590 + 591 + static void __flush_all_mm(struct mm_struct *mm, bool fullmm) 592 + { 593 + radix__local_flush_all_mm(mm); 594 + } 590 595 #endif /* CONFIG_SMP */ 591 596 592 597 void radix__local_flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr, ··· 782 777 EXPORT_SYMBOL(radix__flush_tlb_page); 783 778 784 779 #else /* CONFIG_SMP */ 785 - #define radix__flush_all_mm radix__local_flush_all_mm 780 + static inline void exit_flush_lazy_tlbs(struct mm_struct *mm) { } 786 781 #endif /* CONFIG_SMP */ 787 782 788 783 static void do_tlbiel_kernel(void *info)
+5 -5
arch/powerpc/mm/kasan/kasan_init_32.c
··· 36 36 unsigned long k_cur, k_next; 37 37 pte_t *new = NULL; 38 38 39 - pmd = pmd_offset(pud_offset(pgd_offset_k(k_start), k_start), k_start); 39 + pmd = pmd_ptr_k(k_start); 40 40 41 41 for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pmd++) { 42 42 k_next = pgd_addr_end(k_cur, k_end); ··· 78 78 block = memblock_alloc(k_end - k_start, PAGE_SIZE); 79 79 80 80 for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) { 81 - pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur); 81 + pmd_t *pmd = pmd_ptr_k(k_cur); 82 82 void *va = block + k_cur - k_start; 83 83 pte_t pte = pfn_pte(PHYS_PFN(__pa(va)), PAGE_KERNEL); 84 84 ··· 101 101 102 102 kasan_populate_pte(kasan_early_shadow_pte, prot); 103 103 104 - for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) { 105 - pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur); 104 + for (k_cur = k_start & PAGE_MASK; k_cur != k_end; k_cur += PAGE_SIZE) { 105 + pmd_t *pmd = pmd_ptr_k(k_cur); 106 106 pte_t *ptep = pte_offset_kernel(pmd, k_cur); 107 107 108 108 if ((pte_val(*ptep) & PTE_RPN_MASK) != pa) ··· 196 196 unsigned long addr = KASAN_SHADOW_START; 197 197 unsigned long end = KASAN_SHADOW_END; 198 198 unsigned long next; 199 - pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(addr), addr), addr); 199 + pmd_t *pmd = pmd_ptr_k(addr); 200 200 201 201 BUILD_BUG_ON(KASAN_SHADOW_START & ~PGDIR_MASK); 202 202
-6
arch/powerpc/mm/mem.c
··· 66 66 EXPORT_SYMBOL(kmap_pte); 67 67 pgprot_t kmap_prot; 68 68 EXPORT_SYMBOL(kmap_prot); 69 - 70 - static inline pte_t *virt_to_kpte(unsigned long vaddr) 71 - { 72 - return pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), 73 - vaddr), vaddr), vaddr); 74 - } 75 69 #endif 76 70 77 71 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
+2 -2
arch/powerpc/mm/nohash/40x.c
··· 104 104 pmd_t *pmdp; 105 105 unsigned long val = p | _PMD_SIZE_16M | _PAGE_EXEC | _PAGE_HWWRITE; 106 106 107 - pmdp = pmd_offset(pud_offset(pgd_offset_k(v), v), v); 107 + pmdp = pmd_ptr_k(v); 108 108 *pmdp++ = __pmd(val); 109 109 *pmdp++ = __pmd(val); 110 110 *pmdp++ = __pmd(val); ··· 119 119 pmd_t *pmdp; 120 120 unsigned long val = p | _PMD_SIZE_4M | _PAGE_EXEC | _PAGE_HWWRITE; 121 121 122 - pmdp = pmd_offset(pud_offset(pgd_offset_k(v), v), v); 122 + pmdp = pmd_ptr_k(v); 123 123 *pmdp = __pmd(val); 124 124 125 125 v += LARGE_PAGE_SIZE_4M;
+11 -1
arch/powerpc/mm/nohash/tlb_low.S
··· 397 397 * extern void loadcam_entry(unsigned int index) 398 398 * 399 399 * Load TLBCAM[index] entry in to the L2 CAM MMU 400 - * Must preserve r7, r8, r9, and r10 400 + * Must preserve r7, r8, r9, r10 and r11 401 401 */ 402 402 _GLOBAL(loadcam_entry) 403 403 mflr r5 ··· 433 433 */ 434 434 _GLOBAL(loadcam_multi) 435 435 mflr r8 436 + /* Don't switch to AS=1 if already there */ 437 + mfmsr r11 438 + andi. r11,r11,MSR_IS 439 + bne 10f 436 440 437 441 /* 438 442 * Set up temporary TLB entry that is the same as what we're ··· 462 458 mtmsr r6 463 459 isync 464 460 461 + 10: 465 462 mr r9,r3 466 463 add r10,r3,r4 467 464 2: bl loadcam_entry ··· 470 465 cmpw r9,r10 471 466 mr r3,r9 472 467 blt 2b 468 + 469 + /* Don't return to AS=0 if we were in AS=1 at function start */ 470 + andi. r11,r11,MSR_IS 471 + bne 3f 473 472 474 473 /* Return to AS=0 and clear the temporary entry */ 475 474 mfmsr r6 ··· 490 481 tlbwe 491 482 isync 492 483 484 + 3: 493 485 mtlr r8 494 486 blr 495 487 #endif
+78 -23
arch/powerpc/mm/numa.c
··· 461 461 return nid; 462 462 } 463 463 464 + #ifdef CONFIG_PPC_SPLPAR 465 + static int vphn_get_nid(long lcpu) 466 + { 467 + __be32 associativity[VPHN_ASSOC_BUFSIZE] = {0}; 468 + long rc, hwid; 469 + 470 + /* 471 + * On a shared lpar, device tree will not have node associativity. 472 + * At this time lppaca, or its __old_status field may not be 473 + * updated. Hence kernel cannot detect if its on a shared lpar. So 474 + * request an explicit associativity irrespective of whether the 475 + * lpar is shared or dedicated. Use the device tree property as a 476 + * fallback. cpu_to_phys_id is only valid between 477 + * smp_setup_cpu_maps() and smp_setup_pacas(). 478 + */ 479 + if (firmware_has_feature(FW_FEATURE_VPHN)) { 480 + if (cpu_to_phys_id) 481 + hwid = cpu_to_phys_id[lcpu]; 482 + else 483 + hwid = get_hard_smp_processor_id(lcpu); 484 + 485 + rc = hcall_vphn(hwid, VPHN_FLAG_VCPU, associativity); 486 + if (rc == H_SUCCESS) 487 + return associativity_to_nid(associativity); 488 + } 489 + 490 + return NUMA_NO_NODE; 491 + } 492 + #else 493 + static int vphn_get_nid(long unused) 494 + { 495 + return NUMA_NO_NODE; 496 + } 497 + #endif /* CONFIG_PPC_SPLPAR */ 498 + 464 499 /* 465 500 * Figure out to which domain a cpu belongs and stick it there. 466 501 * Return the id of the domain used. 467 502 */ 468 503 static int numa_setup_cpu(unsigned long lcpu) 469 504 { 470 - int nid = NUMA_NO_NODE; 471 505 struct device_node *cpu; 506 + int fcpu = cpu_first_thread_sibling(lcpu); 507 + int nid = NUMA_NO_NODE; 472 508 473 509 /* 474 510 * If a valid cpu-to-node mapping is already available, use it 475 511 * directly instead of querying the firmware, since it represents 476 512 * the most recent mapping notified to us by the platform (eg: VPHN). 513 + * Since cpu_to_node binding remains the same for all threads in the 514 + * core. If a valid cpu-to-node mapping is already available, for 515 + * the first thread in the core, use it. 477 516 */ 478 - if ((nid = numa_cpu_lookup_table[lcpu]) >= 0) { 517 + nid = numa_cpu_lookup_table[fcpu]; 518 + if (nid >= 0) { 479 519 map_cpu_to_node(lcpu, nid); 480 520 return nid; 481 521 } 522 + 523 + nid = vphn_get_nid(lcpu); 524 + if (nid != NUMA_NO_NODE) 525 + goto out_present; 482 526 483 527 cpu = of_get_cpu_node(lcpu, NULL); 484 528 ··· 535 491 } 536 492 537 493 nid = of_node_to_nid_single(cpu); 494 + of_node_put(cpu); 538 495 539 496 out_present: 540 497 if (nid < 0 || !node_possible(nid)) 541 498 nid = first_online_node; 542 499 500 + /* 501 + * Update for the first thread of the core. All threads of a core 502 + * have to be part of the same node. This not only avoids querying 503 + * for every other thread in the core, but always avoids a case 504 + * where virtual node associativity change causes subsequent threads 505 + * of a core to be associated with different nid. However if first 506 + * thread is already online, expect it to have a valid mapping. 507 + */ 508 + if (fcpu != lcpu) { 509 + WARN_ON(cpu_online(fcpu)); 510 + map_cpu_to_node(fcpu, nid); 511 + } 512 + 543 513 map_cpu_to_node(lcpu, nid); 544 - of_node_put(cpu); 545 514 out: 546 515 return nid; 547 516 } ··· 1248 1191 VPHN_FLAG_VCPU, associativity); 1249 1192 1250 1193 switch (rc) { 1251 - case H_FUNCTION: 1252 - printk_once(KERN_INFO 1253 - "VPHN is not supported. Disabling polling...\n"); 1254 - stop_topology_update(); 1255 - break; 1256 - case H_HARDWARE: 1257 - printk(KERN_ERR 1258 - "hcall_vphn() experienced a hardware fault " 1259 - "preventing VPHN. Disabling polling...\n"); 1260 - stop_topology_update(); 1261 - break; 1262 1194 case H_SUCCESS: 1263 1195 dbg("VPHN hcall succeeded. Reset polling...\n"); 1264 1196 timed_topology_update(0); 1197 + goto out; 1198 + 1199 + case H_FUNCTION: 1200 + pr_err_ratelimited("VPHN unsupported. Disabling polling...\n"); 1201 + break; 1202 + case H_HARDWARE: 1203 + pr_err_ratelimited("hcall_vphn() experienced a hardware fault " 1204 + "preventing VPHN. Disabling polling...\n"); 1205 + break; 1206 + case H_PARAMETER: 1207 + pr_err_ratelimited("hcall_vphn() was passed an invalid parameter. " 1208 + "Disabling polling...\n"); 1209 + break; 1210 + default: 1211 + pr_err_ratelimited("hcall_vphn() returned %ld. Disabling polling...\n" 1212 + , rc); 1265 1213 break; 1266 1214 } 1267 1215 1216 + stop_topology_update(); 1217 + out: 1268 1218 return rc; 1269 1219 } 1270 1220 ··· 1630 1566 int prrn_is_enabled(void) 1631 1567 { 1632 1568 return prrn_enabled; 1633 - } 1634 - 1635 - void __init shared_proc_topology_init(void) 1636 - { 1637 - if (lppaca_shared_proc(get_lppaca())) { 1638 - bitmap_fill(cpumask_bits(&cpu_associativity_changes_mask), 1639 - nr_cpumask_bits); 1640 - numa_update_cpu_topology(false); 1641 - } 1642 1569 } 1643 1570 1644 1571 static int topology_read(struct seq_file *file, void *v)
+3 -38
arch/powerpc/mm/pgtable_32.c
··· 63 63 int err = -ENOMEM; 64 64 65 65 /* Use upper 10 bits of VA to index the first level map */ 66 - pd = pmd_offset(pud_offset(pgd_offset_k(va), va), va); 66 + pd = pmd_ptr_k(va); 67 67 /* Use middle 10 bits of VA to index the second-level map */ 68 68 if (likely(slab_is_available())) 69 69 pg = pte_alloc_kernel(pd, va); ··· 121 121 } 122 122 } 123 123 124 - /* Scan the real Linux page tables and return a PTE pointer for 125 - * a virtual address in a context. 126 - * Returns true (1) if PTE was found, zero otherwise. The pointer to 127 - * the PTE pointer is unmodified if PTE is not found. 128 - */ 129 - static int 130 - get_pteptr(struct mm_struct *mm, unsigned long addr, pte_t **ptep, pmd_t **pmdp) 131 - { 132 - pgd_t *pgd; 133 - pud_t *pud; 134 - pmd_t *pmd; 135 - pte_t *pte; 136 - int retval = 0; 137 - 138 - pgd = pgd_offset(mm, addr & PAGE_MASK); 139 - if (pgd) { 140 - pud = pud_offset(pgd, addr & PAGE_MASK); 141 - if (pud && pud_present(*pud)) { 142 - pmd = pmd_offset(pud, addr & PAGE_MASK); 143 - if (pmd_present(*pmd)) { 144 - pte = pte_offset_map(pmd, addr & PAGE_MASK); 145 - if (pte) { 146 - retval = 1; 147 - *ptep = pte; 148 - if (pmdp) 149 - *pmdp = pmd; 150 - /* XXX caller needs to do pte_unmap, yuck */ 151 - } 152 - } 153 - } 154 - } 155 - return(retval); 156 - } 157 - 158 124 static int __change_page_attr_noflush(struct page *page, pgprot_t prot) 159 125 { 160 126 pte_t *kpte; 161 - pmd_t *kpmd; 162 127 unsigned long address; 163 128 164 129 BUG_ON(PageHighMem(page)); ··· 131 166 132 167 if (v_block_mapped(address)) 133 168 return 0; 134 - if (!get_pteptr(&init_mm, address, &kpte, &kpmd)) 169 + kpte = virt_to_kpte(address); 170 + if (!kpte) 135 171 return -EINVAL; 136 172 __set_pte_at(&init_mm, address, kpte, mk_pte(page, prot), 0); 137 - pte_unmap(kpte); 138 173 139 174 return 0; 140 175 }
+3 -5
arch/powerpc/mm/ptdump/bats.c
··· 164 164 165 165 static int __init bats_init(void) 166 166 { 167 - struct dentry *debugfs_file; 168 - 169 - debugfs_file = debugfs_create_file("block_address_translation", 0400, 170 - powerpc_debugfs_root, NULL, &bats_fops); 171 - return debugfs_file ? 0 : -ENOMEM; 167 + debugfs_create_file("block_address_translation", 0400, 168 + powerpc_debugfs_root, NULL, &bats_fops); 169 + return 0; 172 170 } 173 171 device_initcall(bats_init);
+2 -5
arch/powerpc/mm/ptdump/hashpagetable.c
··· 527 527 528 528 static int ptdump_init(void) 529 529 { 530 - struct dentry *debugfs_file; 531 - 532 530 if (!radix_enabled()) { 533 531 populate_markers(); 534 - debugfs_file = debugfs_create_file("kernel_hash_pagetable", 535 - 0400, NULL, NULL, &ptdump_fops); 536 - return debugfs_file ? 0 : -ENOMEM; 532 + debugfs_create_file("kernel_hash_pagetable", 0400, NULL, NULL, 533 + &ptdump_fops); 537 534 } 538 535 return 0; 539 536 }
+3 -5
arch/powerpc/mm/ptdump/ptdump.c
··· 417 417 418 418 static int ptdump_init(void) 419 419 { 420 - struct dentry *debugfs_file; 421 - 422 420 populate_markers(); 423 421 build_pgtable_complete_mask(); 424 - debugfs_file = debugfs_create_file("kernel_page_tables", 0400, NULL, 425 - NULL, &ptdump_fops); 426 - return debugfs_file ? 0 : -ENOMEM; 422 + debugfs_create_file("kernel_page_tables", 0400, NULL, NULL, 423 + &ptdump_fops); 424 + return 0; 427 425 } 428 426 device_initcall(ptdump_init);
+3 -5
arch/powerpc/mm/ptdump/segment_regs.c
··· 55 55 56 56 static int __init sr_init(void) 57 57 { 58 - struct dentry *debugfs_file; 59 - 60 - debugfs_file = debugfs_create_file("segment_registers", 0400, 61 - powerpc_debugfs_root, NULL, &sr_fops); 62 - return debugfs_file ? 0 : -ENOMEM; 58 + debugfs_create_file("segment_registers", 0400, powerpc_debugfs_root, 59 + NULL, &sr_fops); 60 + return 0; 63 61 } 64 62 device_initcall(sr_init);
-3
arch/powerpc/platforms/44x/warp.c
··· 43 43 if (!of_machine_is_compatible("pika,warp")) 44 44 return 0; 45 45 46 - /* For arch_dma_alloc */ 47 - ISA_DMA_THRESHOLD = ~0L; 48 - 49 46 return 1; 50 47 } 51 48
-1
arch/powerpc/platforms/52xx/efika.c
··· 205 205 if (strcmp(model, "EFIKA5K2")) 206 206 return 0; 207 207 208 - ISA_DMA_THRESHOLD = ~0L; 209 208 DMA_MODE_READ = 0x44; 210 209 DMA_MODE_WRITE = 0x48; 211 210
+6 -3
arch/powerpc/platforms/83xx/km83xx.c
··· 53 53 54 54 np_par = of_find_node_by_name(NULL, "par_io"); 55 55 if (np_par == NULL) { 56 - pr_warn("%s couldn;t find par_io node\n", __func__); 56 + pr_warn("%s couldn't find par_io node\n", __func__); 57 57 return; 58 58 } 59 59 /* Map Parallel I/O ports registers */ 60 60 ret = of_address_to_resource(np_par, 0, &res); 61 61 if (ret) { 62 - pr_warn("%s couldn;t map par_io registers\n", __func__); 63 - return; 62 + pr_warn("%s couldn't map par_io registers\n", __func__); 63 + goto out; 64 64 } 65 65 66 66 base = ioremap(res.start, resource_size(&res)); 67 + if (!base) 68 + goto out; 67 69 68 70 /* 69 71 * set output delay adjustments to default values according ··· 113 111 setbits32((base + 0xac), 0x0000c000); 114 112 } 115 113 iounmap(base); 114 + out: 116 115 of_node_put(np_par); 117 116 } 118 117
+4 -7
arch/powerpc/platforms/85xx/mpc85xx_cds.c
··· 218 218 { 219 219 return IRQ_HANDLED; 220 220 } 221 - 222 - static struct irqaction mpc85xxcds_8259_irqaction = { 223 - .handler = mpc85xx_8259_cascade_action, 224 - .flags = IRQF_SHARED | IRQF_NO_THREAD, 225 - .name = "8259 cascade", 226 - }; 227 221 #endif /* PPC_I8259 */ 228 222 #endif /* CONFIG_PCI */ 229 223 ··· 265 271 * disabled when the last user of the shared IRQ line frees their 266 272 * interrupt. 267 273 */ 268 - if ((ret = setup_irq(cascade_irq, &mpc85xxcds_8259_irqaction))) { 274 + ret = request_irq(cascade_irq, mpc85xx_8259_cascade_action, 275 + IRQF_SHARED | IRQF_NO_THREAD, "8259 cascade", 276 + cascade_node); 277 + if (ret) { 269 278 printk(KERN_ERR "Failed to setup cascade interrupt\n"); 270 279 return ret; 271 280 }
+2 -7
arch/powerpc/platforms/8xx/cpm1.c
··· 120 120 return IRQ_HANDLED; 121 121 } 122 122 123 - static struct irqaction cpm_error_irqaction = { 124 - .handler = cpm_error_interrupt, 125 - .flags = IRQF_NO_THREAD, 126 - .name = "error", 127 - }; 128 - 129 123 static const struct irq_domain_ops cpm_pic_host_ops = { 130 124 .map = cpm_pic_host_map, 131 125 }; ··· 181 187 if (!eirq) 182 188 goto end; 183 189 184 - if (setup_irq(eirq, &cpm_error_irqaction)) 190 + if (request_irq(eirq, cpm_error_interrupt, IRQF_NO_THREAD, "error", 191 + NULL)) 185 192 printk(KERN_ERR "Could not allocate CPM error IRQ!"); 186 193 187 194 setbits32(&cpic_reg->cpic_cicr, CICR_IEN);
+2 -7
arch/powerpc/platforms/8xx/m8xx_setup.c
··· 39 39 return IRQ_HANDLED; 40 40 } 41 41 42 - static struct irqaction tbint_irqaction = { 43 - .handler = timebase_interrupt, 44 - .flags = IRQF_NO_THREAD, 45 - .name = "tbint", 46 - }; 47 - 48 42 /* per-board overridable init_internal_rtc() function. */ 49 43 void __init __attribute__ ((weak)) 50 44 init_internal_rtc(void) ··· 151 157 (TBSCR_TBF | TBSCR_TBE)); 152 158 immr_unmap(sys_tmr2); 153 159 154 - if (setup_irq(virq, &tbint_irqaction)) 160 + if (request_irq(virq, timebase_interrupt, IRQF_NO_THREAD, "tbint", 161 + NULL)) 155 162 panic("Could not allocate timer IRQ!"); 156 163 } 157 164
+7 -1
arch/powerpc/platforms/Kconfig.cputype
··· 397 397 398 398 config PPC_KUAP_DEBUG 399 399 bool "Extra debugging for Kernel Userspace Access Protection" 400 - depends on PPC_HAVE_KUAP && (PPC_RADIX_MMU || PPC_32) 400 + depends on PPC_KUAP && (PPC_RADIX_MMU || PPC_32) 401 401 help 402 402 Add extra debugging for Kernel Userspace Access Protection (KUAP) 403 403 If you're unsure, say N. ··· 424 424 425 425 config PPC_HAVE_PMU_SUPPORT 426 426 bool 427 + 428 + config PMU_SYSFS 429 + bool "Create PMU SPRs sysfs file" 430 + default n 431 + help 432 + This option enables sysfs file creation for PMU SPRs like MMCR* and PMC*. 427 433 428 434 config PPC_PERF_CTRS 429 435 def_bool y
-1
arch/powerpc/platforms/amigaone/setup.c
··· 146 146 */ 147 147 cur_cpu_spec->cpu_features &= ~CPU_FTR_NEED_COHERENT; 148 148 149 - ISA_DMA_THRESHOLD = 0x00ffffff; 150 149 DMA_MODE_READ = 0x44; 151 150 DMA_MODE_WRITE = 0x48; 152 151
+1 -5
arch/powerpc/platforms/cell/axon_msi.c
··· 480 480 481 481 snprintf(name, sizeof(name), "msic_%d", of_node_to_nid(dn)); 482 482 483 - if (!debugfs_create_file(name, 0600, powerpc_debugfs_root, 484 - msic, &fops_msic)) { 485 - pr_devel("axon_msi: debugfs_create_file failed!\n"); 486 - return; 487 - } 483 + debugfs_create_file(name, 0600, powerpc_debugfs_root, msic, &fops_msic); 488 484 } 489 485 #endif /* DEBUG */
+1 -1
arch/powerpc/platforms/cell/spufs/switch.c
··· 177 177 POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) & 178 178 MFC_CNTL_SUSPEND_DMA_STATUS_MASK) == 179 179 MFC_CNTL_SUSPEND_COMPLETE); 180 - /* fall through */ 180 + fallthrough; 181 181 case MFC_CNTL_SUSPEND_COMPLETE: 182 182 if (csa) 183 183 csa->priv2.mfc_control_RW =
+5 -10
arch/powerpc/platforms/chrp/setup.c
··· 451 451 of_node_put(np); 452 452 } 453 453 454 - #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_XMON) 455 - static struct irqaction xmon_irqaction = { 456 - .handler = xmon_irq, 457 - .name = "XMON break", 458 - }; 459 - #endif 460 - 461 454 static void __init chrp_find_8259(void) 462 455 { 463 456 struct device_node *np, *pic = NULL; ··· 534 541 if (of_node_is_type(kbd->parent, "adb")) 535 542 break; 536 543 of_node_put(kbd); 537 - if (kbd) 538 - setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction); 544 + if (kbd) { 545 + if (request_irq(HYDRA_INT_ADB_NMI, xmon_irq, 0, "XMON break", 546 + NULL)) 547 + pr_err("Failed to register XMON break interrupt\n"); 548 + } 539 549 #endif 540 550 } 541 551 ··· 569 573 if (strcmp(dtype, "chrp")) 570 574 return 0; 571 575 572 - ISA_DMA_THRESHOLD = ~0L; 573 576 DMA_MODE_READ = 0x44; 574 577 DMA_MODE_WRITE = 0x48; 575 578
+17 -17
arch/powerpc/platforms/maple/setup.c
··· 291 291 return 1; 292 292 } 293 293 294 - define_machine(maple) { 295 - .name = "Maple", 296 - .probe = maple_probe, 297 - .setup_arch = maple_setup_arch, 298 - .init_IRQ = maple_init_IRQ, 299 - .pci_irq_fixup = maple_pci_irq_fixup, 300 - .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq, 301 - .restart = maple_restart, 302 - .halt = maple_halt, 303 - .get_boot_time = maple_get_boot_time, 304 - .set_rtc_time = maple_set_rtc_time, 305 - .get_rtc_time = maple_get_rtc_time, 306 - .calibrate_decr = generic_calibrate_decr, 307 - .progress = maple_progress, 308 - .power_save = power4_idle, 309 - }; 310 - 311 294 #ifdef CONFIG_EDAC 312 295 /* 313 296 * Register a platform device for CPC925 memory controller on ··· 347 364 } 348 365 machine_device_initcall(maple, maple_cpc925_edac_setup); 349 366 #endif 367 + 368 + define_machine(maple) { 369 + .name = "Maple", 370 + .probe = maple_probe, 371 + .setup_arch = maple_setup_arch, 372 + .init_IRQ = maple_init_IRQ, 373 + .pci_irq_fixup = maple_pci_irq_fixup, 374 + .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq, 375 + .restart = maple_restart, 376 + .halt = maple_halt, 377 + .get_boot_time = maple_get_boot_time, 378 + .set_rtc_time = maple_set_rtc_time, 379 + .get_rtc_time = maple_get_rtc_time, 380 + .calibrate_decr = generic_calibrate_decr, 381 + .progress = maple_progress, 382 + .power_save = power4_idle, 383 + };
+11 -18
arch/powerpc/platforms/powermac/pic.c
··· 250 250 return irq_linear_revmap(pmac_pic_host, irq); 251 251 } 252 252 253 - #ifdef CONFIG_XMON 254 - static struct irqaction xmon_action = { 255 - .handler = xmon_irq, 256 - .flags = IRQF_NO_THREAD, 257 - .name = "NMI - XMON" 258 - }; 259 - #endif 260 - 261 - static struct irqaction gatwick_cascade_action = { 262 - .handler = gatwick_action, 263 - .flags = IRQF_NO_THREAD, 264 - .name = "cascade", 265 - }; 266 - 267 253 static int pmac_pic_host_match(struct irq_domain *h, struct device_node *node, 268 254 enum irq_domain_bus_token bus_token) 269 255 { ··· 370 384 out_le32(&pmac_irq_hw[i]->enable, 0); 371 385 372 386 /* Hookup cascade irq */ 373 - if (slave && pmac_irq_cascade) 374 - setup_irq(pmac_irq_cascade, &gatwick_cascade_action); 387 + if (slave && pmac_irq_cascade) { 388 + if (request_irq(pmac_irq_cascade, gatwick_action, 389 + IRQF_NO_THREAD, "cascade", NULL)) 390 + pr_err("Failed to register cascade interrupt\n"); 391 + } 375 392 376 393 printk(KERN_INFO "irq: System has %d possible interrupts\n", max_irqs); 377 394 #ifdef CONFIG_XMON 378 - setup_irq(irq_create_mapping(NULL, 20), &xmon_action); 395 + i = irq_create_mapping(NULL, 20); 396 + if (request_irq(i, xmon_irq, IRQF_NO_THREAD, "NMI - XMON", NULL)) 397 + pr_err("Failed to register NMI-XMON interrupt\n"); 379 398 #endif 380 399 } 381 400 ··· 432 441 nmi_irq = irq_of_parse_and_map(pswitch, 0); 433 442 if (nmi_irq) { 434 443 mpic_irq_set_priority(nmi_irq, 9); 435 - setup_irq(nmi_irq, &xmon_action); 444 + if (request_irq(nmi_irq, xmon_irq, IRQF_NO_THREAD, 445 + "NMI - XMON", NULL)) 446 + pr_err("Failed to register NMI-XMON interrupt\n"); 436 447 } 437 448 of_node_put(pswitch); 438 449 }
-1
arch/powerpc/platforms/powermac/setup.c
··· 586 586 587 587 #ifdef CONFIG_PPC32 588 588 /* isa_io_base gets set in pmac_pci_init */ 589 - ISA_DMA_THRESHOLD = ~0L; 590 589 DMA_MODE_READ = 1; 591 590 DMA_MODE_WRITE = 2; 592 591 #endif /* CONFIG_PPC32 */
+9 -11
arch/powerpc/platforms/powermac/smp.c
··· 399 399 return 0; 400 400 } 401 401 402 - static struct irqaction psurge_irqaction = { 403 - .handler = psurge_ipi_intr, 404 - .flags = IRQF_PERCPU | IRQF_NO_THREAD, 405 - .name = "primary IPI", 406 - }; 407 - 408 402 static void __init smp_psurge_setup_cpu(int cpu_nr) 409 403 { 404 + unsigned long flags = IRQF_PERCPU | IRQF_NO_THREAD; 405 + int irq; 406 + 410 407 if (cpu_nr != 0 || !psurge_start) 411 408 return; 412 409 413 410 /* reset the entry point so if we get another intr we won't 414 411 * try to startup again */ 415 412 out_be32(psurge_start, 0x100); 416 - if (setup_irq(irq_create_mapping(NULL, 30), &psurge_irqaction)) 413 + irq = irq_create_mapping(NULL, 30); 414 + if (request_irq(irq, psurge_ipi_intr, flags, "primary IPI", NULL)) 417 415 printk(KERN_ERR "Couldn't get primary IPI interrupt"); 418 416 } 419 417 ··· 658 660 659 661 #endif /* !CONFIG_PPC64 */ 660 662 661 - /* L2 and L3 cache settings to pass from CPU0 to CPU1 on G4 cpus */ 662 - volatile static long int core99_l2_cache; 663 - volatile static long int core99_l3_cache; 664 - 665 663 static void core99_init_caches(int cpu) 666 664 { 667 665 #ifndef CONFIG_PPC64 666 + /* L2 and L3 cache settings to pass from CPU0 to CPU1 on G4 cpus */ 667 + static long int core99_l2_cache; 668 + static long int core99_l3_cache; 669 + 668 670 if (!cpu_has_feature(CPU_FTR_L2CR)) 669 671 return; 670 672
+14 -23
arch/powerpc/platforms/powernv/eeh-powernv.c
··· 40 40 41 41 void pnv_pcibios_bus_add_device(struct pci_dev *pdev) 42 42 { 43 - struct pci_dn *pdn = pci_get_pdn(pdev); 44 - 45 - if (!pdn || eeh_has_flag(EEH_FORCE_DISABLED)) 46 - return; 47 - 48 43 dev_dbg(&pdev->dev, "EEH: Setting up device\n"); 49 - eeh_add_device_early(pdn); 50 - eeh_add_device_late(pdev); 51 - eeh_sysfs_add_device(pdev); 44 + eeh_probe_device(pdev); 52 45 } 53 46 54 47 static int pnv_eeh_init(void) ··· 340 347 341 348 /** 342 349 * pnv_eeh_probe - Do probe on PCI device 343 - * @pdn: PCI device node 344 - * @data: unused 350 + * @pdev: pci_dev to probe 345 351 * 346 - * When EEH module is installed during system boot, all PCI devices 347 - * are checked one by one to see if it supports EEH. The function 348 - * is introduced for the purpose. By default, EEH has been enabled 349 - * on all PCI devices. That's to say, we only need do necessary 350 - * initialization on the corresponding eeh device and create PE 351 - * accordingly. 352 - * 353 - * It's notable that's unsafe to retrieve the EEH device through 354 - * the corresponding PCI device. During the PCI device hotplug, which 355 - * was possiblly triggered by EEH core, the binding between EEH device 356 - * and the PCI device isn't built yet. 352 + * Create, or find the existing, eeh_dev for this pci_dev. 357 353 */ 358 - static void *pnv_eeh_probe(struct pci_dn *pdn, void *data) 354 + static struct eeh_dev *pnv_eeh_probe(struct pci_dev *pdev) 359 355 { 356 + struct pci_dn *pdn = pci_get_pdn(pdev); 360 357 struct pci_controller *hose = pdn->phb; 361 358 struct pnv_phb *phb = hose->private_data; 362 359 struct eeh_dev *edev = pdn_to_eeh_dev(pdn); ··· 362 379 */ 363 380 if (!edev || edev->pe) 364 381 return NULL; 382 + 383 + /* already configured? */ 384 + if (edev->pdev) { 385 + pr_debug("%s: found existing edev for %04x:%02x:%02x.%01x\n", 386 + __func__, hose->global_number, config_addr >> 8, 387 + PCI_SLOT(config_addr), PCI_FUNC(config_addr)); 388 + return edev; 389 + } 365 390 366 391 /* Skip for PCI-ISA bridge */ 367 392 if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_ISA) ··· 462 471 463 472 eeh_edev_dbg(edev, "EEH enabled on device\n"); 464 473 465 - return NULL; 474 + return edev; 466 475 } 467 476 468 477 /**
-7
arch/powerpc/platforms/powernv/memtrace.c
··· 187 187 188 188 snprintf(ent->name, 16, "%08x", ent->nid); 189 189 dir = debugfs_create_dir(ent->name, memtrace_debugfs_dir); 190 - if (!dir) { 191 - pr_err("Failed to create debugfs directory for node %d\n", 192 - ent->nid); 193 - return -1; 194 - } 195 190 196 191 ent->dir = dir; 197 192 debugfs_create_file("trace", 0400, dir, ent, &memtrace_fops); ··· 309 314 { 310 315 memtrace_debugfs_dir = debugfs_create_dir("memtrace", 311 316 powerpc_debugfs_root); 312 - if (!memtrace_debugfs_dir) 313 - return -1; 314 317 315 318 debugfs_create_file("enable", 0600, memtrace_debugfs_dir, 316 319 NULL, &memtrace_init_fops);
+40 -15
arch/powerpc/platforms/powernv/opal-core.c
··· 71 71 static struct opalcore_config *oc_conf; 72 72 static const struct opal_mpipl_fadump *opalc_metadata; 73 73 static const struct opal_mpipl_fadump *opalc_cpu_metadata; 74 + struct kobject *mpipl_kobj; 74 75 75 76 /* 76 77 * Set crashing CPU's signal to SIGUSR1. if the kernel is triggered ··· 429 428 return; 430 429 431 430 /* Remove OPAL core sysfs file */ 432 - sysfs_remove_bin_file(opal_kobj, &opal_core_attr); 431 + sysfs_remove_bin_file(mpipl_kobj, &opal_core_attr); 433 432 oc_conf->ptload_phdr = NULL; 434 433 oc_conf->ptload_cnt = 0; 435 434 ··· 564 563 of_node_put(np); 565 564 } 566 565 567 - static ssize_t fadump_release_opalcore_store(struct kobject *kobj, 568 - struct kobj_attribute *attr, 569 - const char *buf, size_t count) 566 + static ssize_t release_core_store(struct kobject *kobj, 567 + struct kobj_attribute *attr, 568 + const char *buf, size_t count) 570 569 { 571 570 int input = -1; 572 571 ··· 590 589 return count; 591 590 } 592 591 593 - static struct kobj_attribute opalcore_rel_attr = __ATTR(fadump_release_opalcore, 594 - 0200, NULL, 595 - fadump_release_opalcore_store); 592 + static struct kobj_attribute opalcore_rel_attr = __ATTR_WO(release_core); 593 + 594 + static struct attribute *mpipl_attr[] = { 595 + &opalcore_rel_attr.attr, 596 + NULL, 597 + }; 598 + 599 + static struct bin_attribute *mpipl_bin_attr[] = { 600 + &opal_core_attr, 601 + NULL, 602 + 603 + }; 604 + 605 + static struct attribute_group mpipl_group = { 606 + .attrs = mpipl_attr, 607 + .bin_attrs = mpipl_bin_attr, 608 + }; 596 609 597 610 static int __init opalcore_init(void) 598 611 { ··· 624 609 * then capture the dump. 625 610 */ 626 611 if (!(is_opalcore_usable())) { 627 - pr_err("Failed to export /sys/firmware/opal/core\n"); 612 + pr_err("Failed to export /sys/firmware/opal/mpipl/core\n"); 628 613 opalcore_cleanup(); 629 614 return rc; 630 615 } ··· 632 617 /* Set OPAL core file size */ 633 618 opal_core_attr.size = oc_conf->opalcore_size; 634 619 620 + mpipl_kobj = kobject_create_and_add("mpipl", opal_kobj); 621 + if (!mpipl_kobj) { 622 + pr_err("unable to create mpipl kobject\n"); 623 + return -ENOMEM; 624 + } 625 + 635 626 /* Export OPAL core sysfs file */ 636 - rc = sysfs_create_bin_file(opal_kobj, &opal_core_attr); 637 - if (rc != 0) { 638 - pr_err("Failed to export /sys/firmware/opal/core\n"); 627 + rc = sysfs_create_group(mpipl_kobj, &mpipl_group); 628 + if (rc) { 629 + pr_err("mpipl sysfs group creation failed (%d)", rc); 639 630 opalcore_cleanup(); 640 631 return rc; 641 632 } 642 - 643 - rc = sysfs_create_file(kernel_kobj, &opalcore_rel_attr.attr); 633 + /* The /sys/firmware/opal/core is moved to /sys/firmware/opal/mpipl/ 634 + * directory, need to create symlink at old location to maintain 635 + * backward compatibility. 636 + */ 637 + rc = compat_only_sysfs_link_entry_to_kobj(opal_kobj, mpipl_kobj, 638 + "core", NULL); 644 639 if (rc) { 645 - pr_warn("unable to create sysfs file fadump_release_opalcore (%d)\n", 646 - rc); 640 + pr_err("unable to create core symlink (%d)\n", rc); 641 + return rc; 647 642 } 648 643 649 644 return 0;
+7 -17
arch/powerpc/platforms/powernv/opal-imc.c
··· 35 35 } 36 36 DEFINE_DEBUGFS_ATTRIBUTE(fops_imc_x64, imc_mem_get, imc_mem_set, "0x%016llx\n"); 37 37 38 - static struct dentry *imc_debugfs_create_x64(const char *name, umode_t mode, 39 - struct dentry *parent, u64 *value) 38 + static void imc_debugfs_create_x64(const char *name, umode_t mode, 39 + struct dentry *parent, u64 *value) 40 40 { 41 - return debugfs_create_file_unsafe(name, mode, parent, 42 - value, &fops_imc_x64); 41 + debugfs_create_file_unsafe(name, mode, parent, value, &fops_imc_x64); 43 42 } 44 43 45 44 /* ··· 58 59 59 60 imc_debugfs_parent = debugfs_create_dir("imc", powerpc_debugfs_root); 60 61 61 - if (!imc_debugfs_parent) 62 - return; 63 - 64 62 if (of_property_read_u32(node, "cb_offset", &cb_offset)) 65 63 cb_offset = IMC_CNTL_BLK_OFFSET; 66 64 ··· 65 69 loc = (u64)(ptr->vbase) + cb_offset; 66 70 imc_mode_addr = (u64 *)(loc + IMC_CNTL_BLK_MODE_OFFSET); 67 71 sprintf(mode, "imc_mode_%d", (u32)(ptr->id)); 68 - if (!imc_debugfs_create_x64(mode, 0600, imc_debugfs_parent, 69 - imc_mode_addr)) 70 - goto err; 72 + imc_debugfs_create_x64(mode, 0600, imc_debugfs_parent, 73 + imc_mode_addr); 71 74 72 75 imc_cmd_addr = (u64 *)(loc + IMC_CNTL_BLK_CMD_OFFSET); 73 76 sprintf(cmd, "imc_cmd_%d", (u32)(ptr->id)); 74 - if (!imc_debugfs_create_x64(cmd, 0600, imc_debugfs_parent, 75 - imc_cmd_addr)) 76 - goto err; 77 + imc_debugfs_create_x64(cmd, 0600, imc_debugfs_parent, 78 + imc_cmd_addr); 77 79 ptr++; 78 80 } 79 - return; 80 - 81 - err: 82 - debugfs_remove_recursive(imc_debugfs_parent); 83 81 } 84 82 85 83 /*
-5
arch/powerpc/platforms/powernv/pci-ioda.c
··· 3174 3174 3175 3175 sprintf(name, "PCI%04x", hose->global_number); 3176 3176 phb->dbgfs = debugfs_create_dir(name, powerpc_debugfs_root); 3177 - if (!phb->dbgfs) { 3178 - pr_warn("%s: Error on creating debugfs on PHB#%x\n", 3179 - __func__, hose->global_number); 3180 - continue; 3181 - } 3182 3177 3183 3178 debugfs_create_file_unsafe("dump_diag_regs", 0200, phb->dbgfs, 3184 3179 phb, &pnv_pci_diag_data_fops);
+3 -1
arch/powerpc/platforms/powernv/setup.c
··· 229 229 pnv_prepare_going_down(); 230 230 231 231 do { 232 - if (!cmd) 232 + if (!cmd || !strlen(cmd)) 233 233 rc = opal_cec_reboot(); 234 234 else if (strcmp(cmd, "full") == 0) 235 235 rc = opal_cec_reboot2(OPAL_REBOOT_FULL_IPL, NULL); ··· 237 237 rc = opal_cec_reboot2(OPAL_REBOOT_MPIPL, NULL); 238 238 else if (strcmp(cmd, "error") == 0) 239 239 rc = opal_cec_reboot2(OPAL_REBOOT_PLATFORM_ERROR, NULL); 240 + else if (strcmp(cmd, "fast") == 0) 241 + rc = opal_cec_reboot2(OPAL_REBOOT_FAST, NULL); 240 242 else 241 243 rc = OPAL_UNSUPPORTED; 242 244
+3 -34
arch/powerpc/platforms/powernv/vas-debug.c
··· 115 115 116 116 void vas_window_init_dbgdir(struct vas_window *window) 117 117 { 118 - struct dentry *f, *d; 118 + struct dentry *d; 119 119 120 120 if (!window->vinst->dbgdir) 121 121 return; ··· 127 127 snprintf(window->dbgname, 16, "w%d", window->winid); 128 128 129 129 d = debugfs_create_dir(window->dbgname, window->vinst->dbgdir); 130 - if (IS_ERR(d)) 131 - goto free_name; 132 - 133 130 window->dbgdir = d; 134 131 135 - f = debugfs_create_file("info", 0444, d, window, &info_fops); 136 - if (IS_ERR(f)) 137 - goto remove_dir; 138 - 139 - f = debugfs_create_file("hvwc", 0444, d, window, &hvwc_fops); 140 - if (IS_ERR(f)) 141 - goto remove_dir; 142 - 143 - return; 144 - 145 - remove_dir: 146 - debugfs_remove_recursive(window->dbgdir); 147 - window->dbgdir = NULL; 148 - 149 - free_name: 150 - kfree(window->dbgname); 151 - window->dbgname = NULL; 132 + debugfs_create_file("info", 0444, d, window, &info_fops); 133 + debugfs_create_file("hvwc", 0444, d, window, &hvwc_fops); 152 134 } 153 135 154 136 void vas_instance_init_dbgdir(struct vas_instance *vinst) ··· 138 156 struct dentry *d; 139 157 140 158 vas_init_dbgdir(); 141 - if (!vas_debugfs) 142 - return; 143 159 144 160 vinst->dbgname = kzalloc(16, GFP_KERNEL); 145 161 if (!vinst->dbgname) ··· 146 166 snprintf(vinst->dbgname, 16, "v%d", vinst->vas_id); 147 167 148 168 d = debugfs_create_dir(vinst->dbgname, vas_debugfs); 149 - if (IS_ERR(d)) 150 - goto free_name; 151 - 152 169 vinst->dbgdir = d; 153 - return; 154 - 155 - free_name: 156 - kfree(vinst->dbgname); 157 - vinst->dbgname = NULL; 158 - vinst->dbgdir = NULL; 159 170 } 160 171 161 172 /* ··· 162 191 163 192 first_time = false; 164 193 vas_debugfs = debugfs_create_dir("vas", NULL); 165 - if (IS_ERR(vas_debugfs)) 166 - vas_debugfs = NULL; 167 194 }
-2
arch/powerpc/platforms/pseries/Makefile
··· 29 29 obj-$(CONFIG_PPC_SVM) += svm.o 30 30 obj-$(CONFIG_FA_DUMP) += rtas-fadump.o 31 31 32 - ifdef CONFIG_PPC_PSERIES 33 32 obj-$(CONFIG_SUSPEND) += suspend.o 34 - endif
+74 -17
arch/powerpc/platforms/pseries/eeh_pseries.c
··· 67 67 pdn->pe_number = physfn_pdn->pe_num_map[pdn->vf_index]; 68 68 } 69 69 #endif 70 - eeh_add_device_early(pdn); 71 - eeh_add_device_late(pdev); 70 + pseries_eeh_init_edev(pdn); 72 71 #ifdef CONFIG_PCI_IOV 73 72 if (pdev->is_virtfn) { 74 73 struct eeh_dev *edev = pdn_to_eeh_dev(pdn); ··· 77 78 eeh_add_to_parent_pe(edev); /* Add as VF PE type */ 78 79 } 79 80 #endif 80 - eeh_sysfs_add_device(pdev); 81 + eeh_probe_device(pdev); 81 82 } 82 83 83 84 /* ··· 221 222 } 222 223 223 224 /** 224 - * pseries_eeh_probe - EEH probe on the given device 225 - * @pdn: PCI device node 226 - * @data: Unused 225 + * pseries_eeh_init_edev - initialise the eeh_dev and eeh_pe for a pci_dn 227 226 * 228 - * When EEH module is installed during system boot, all PCI devices 229 - * are checked one by one to see if it supports EEH. The function 230 - * is introduced for the purpose. 227 + * @pdn: PCI device node 228 + * 229 + * When we discover a new PCI device via the device-tree we create a 230 + * corresponding pci_dn and we allocate, but don't initialise, an eeh_dev. 231 + * This function takes care of the initialisation and inserts the eeh_dev 232 + * into the correct eeh_pe. If no eeh_pe exists we'll allocate one. 231 233 */ 232 - static void *pseries_eeh_probe(struct pci_dn *pdn, void *data) 234 + void pseries_eeh_init_edev(struct pci_dn *pdn) 233 235 { 234 236 struct eeh_dev *edev; 235 237 struct eeh_pe pe; ··· 238 238 int enable = 0; 239 239 int ret; 240 240 241 - /* Retrieve OF node and eeh device */ 241 + if (WARN_ON_ONCE(!eeh_has_flag(EEH_PROBE_MODE_DEVTREE))) 242 + return; 243 + 244 + /* 245 + * Find the eeh_dev for this pdn. The storage for the eeh_dev was 246 + * allocated at the same time as the pci_dn. 247 + * 248 + * XXX: We should probably re-visit that. 249 + */ 242 250 edev = pdn_to_eeh_dev(pdn); 243 - if (!edev || edev->pe) 244 - return NULL; 251 + if (!edev) 252 + return; 253 + 254 + /* 255 + * If ->pe is set then we've already probed this device. We hit 256 + * this path when a pci_dev is removed and rescanned while recovering 257 + * a PE (i.e. for devices where the driver doesn't support error 258 + * recovery). 259 + */ 260 + if (edev->pe) 261 + return; 245 262 246 263 /* Check class/vendor/device IDs */ 247 264 if (!pdn->vendor_id || !pdn->device_id || !pdn->class_code) 248 - return NULL; 265 + return; 249 266 250 267 /* Skip for PCI-ISA bridge */ 251 268 if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_ISA) 252 - return NULL; 269 + return; 253 270 254 271 eeh_edev_dbg(edev, "Probing device\n"); 255 272 ··· 333 316 334 317 /* Save memory bars */ 335 318 eeh_save_bars(edev); 336 - 337 - return NULL; 338 319 } 320 + 321 + static struct eeh_dev *pseries_eeh_probe(struct pci_dev *pdev) 322 + { 323 + struct eeh_dev *edev; 324 + struct pci_dn *pdn; 325 + 326 + pdn = pci_get_pdn_by_devfn(pdev->bus, pdev->devfn); 327 + if (!pdn) 328 + return NULL; 329 + 330 + /* 331 + * If the system supports EEH on this device then the eeh_dev was 332 + * configured and inserted into a PE in pseries_eeh_init_edev() 333 + */ 334 + edev = pdn_to_eeh_dev(pdn); 335 + if (!edev || !edev->pe) 336 + return NULL; 337 + 338 + return edev; 339 + } 340 + 341 + /** 342 + * pseries_eeh_init_edev_recursive - Enable EEH for the indicated device 343 + * @pdn: PCI device node 344 + * 345 + * This routine must be used to perform EEH initialization for the 346 + * indicated PCI device that was added after system boot (e.g. 347 + * hotplug, dlpar). 348 + */ 349 + void pseries_eeh_init_edev_recursive(struct pci_dn *pdn) 350 + { 351 + struct pci_dn *n; 352 + 353 + if (!pdn) 354 + return; 355 + 356 + list_for_each_entry(n, &pdn->child_list, list) 357 + pseries_eeh_init_edev_recursive(n); 358 + 359 + pseries_eeh_init_edev(pdn); 360 + } 361 + EXPORT_SYMBOL_GPL(pseries_eeh_init_edev_recursive); 339 362 340 363 /** 341 364 * pseries_eeh_set_option - Initialize EEH or MMIO/DMA reenable
+4 -4
arch/powerpc/platforms/pseries/hotplug-memory.c
··· 223 223 struct drmem_lmb **end_lmb) 224 224 { 225 225 struct drmem_lmb *lmb, *start, *end; 226 - struct drmem_lmb *last_lmb; 226 + struct drmem_lmb *limit; 227 227 228 228 start = NULL; 229 229 for_each_drmem_lmb(lmb) { ··· 236 236 if (!start) 237 237 return -EINVAL; 238 238 239 - end = &start[n_lmbs - 1]; 239 + end = &start[n_lmbs]; 240 240 241 - last_lmb = &drmem_info->lmbs[drmem_info->n_lmbs - 1]; 242 - if (end > last_lmb) 241 + limit = &drmem_info->lmbs[drmem_info->n_lmbs]; 242 + if (end > limit) 243 243 return -EINVAL; 244 244 245 245 *start_lmb = start;
+9 -1
arch/powerpc/platforms/pseries/lpar.c
··· 636 636 637 637 static int __init vcpudispatch_stats_procfs_init(void) 638 638 { 639 - if (!lppaca_shared_proc(get_lppaca())) 639 + /* 640 + * Avoid smp_processor_id while preemptible. All CPUs should have 641 + * the same value for lppaca_shared_proc. 642 + */ 643 + preempt_disable(); 644 + if (!lppaca_shared_proc(get_lppaca())) { 645 + preempt_enable(); 640 646 return 0; 647 + } 648 + preempt_enable(); 641 649 642 650 if (!proc_create("powerpc/vcpudispatch_stats", 0600, NULL, 643 651 &vcpudispatch_stats_proc_ops))
+1 -1
arch/powerpc/platforms/pseries/of_helpers.c
··· 88 88 return -EINVAL; 89 89 90 90 /* Should now know end of current entry */ 91 - (*curval) = (void *)p2; 91 + (*curval) = (void *)(++p2); 92 92 data->last_drc_index = data->drc_index_start + 93 93 ((data->num_sequential_elems - 1) * data->sequential_inc); 94 94
+3 -2
arch/powerpc/platforms/pseries/papr_scm.c
··· 246 246 return 0; 247 247 } 248 248 249 - int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, 250 - unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc) 249 + static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, 250 + struct nvdimm *nvdimm, unsigned int cmd, void *buf, 251 + unsigned int buf_len, int *cmd_rc) 251 252 { 252 253 struct nd_cmd_get_config_size *get_size_hdr; 253 254 struct papr_scm_priv *p;
+1 -1
arch/powerpc/platforms/pseries/pci_dlpar.c
··· 37 37 eeh_dev_phb_init_dynamic(phb); 38 38 39 39 if (dn->child) 40 - eeh_add_device_tree_early(PCI_DN(dn)); 40 + pseries_eeh_init_edev_recursive(PCI_DN(dn)); 41 41 42 42 pcibios_scan_phb(phb); 43 43 pcibios_finish_adding_to_bus(phb->bus);
+3
arch/powerpc/platforms/pseries/ras.c
··· 558 558 switch (mce_log->error_type) { 559 559 case MC_ERROR_TYPE_UE: 560 560 mce_err.error_type = MCE_ERROR_TYPE_UE; 561 + mce_common_process_ue(regs, &mce_err); 562 + if (mce_err.ignore_event) 563 + disposition = RTAS_DISP_FULLY_RECOVERED; 561 564 switch (err_sub_type) { 562 565 case MC_ERROR_UE_IFETCH: 563 566 mce_err.u.ue_error_type = MCE_UE_ERROR_IFETCH;
-2
arch/powerpc/platforms/pseries/vio.c
··· 1628 1628 } 1629 1629 EXPORT_SYMBOL(vio_get_attribute); 1630 1630 1631 - #ifdef CONFIG_PPC_PSERIES 1632 1631 /* vio_find_name() - internal because only vio.c knows how we formatted the 1633 1632 * kobject name 1634 1633 */ ··· 1697 1698 return rc; 1698 1699 } 1699 1700 EXPORT_SYMBOL(vio_disable_interrupts); 1700 - #endif /* CONFIG_PPC_PSERIES */ 1701 1701 1702 1702 static int __init vio_init(void) 1703 1703 {
+2 -1
arch/powerpc/platforms/pseries/vphn.c
··· 82 82 long retbuf[PLPAR_HCALL9_BUFSIZE] = {0}; 83 83 84 84 rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, retbuf, flags, cpu); 85 - vphn_unpack_associativity(retbuf, associativity); 85 + if (rc == H_SUCCESS) 86 + vphn_unpack_associativity(retbuf, associativity); 86 87 87 88 return rc; 88 89 }
+116 -10
arch/powerpc/sysdev/xive/common.c
··· 20 20 #include <linux/spinlock.h> 21 21 #include <linux/msi.h> 22 22 23 + #include <asm/debugfs.h> 23 24 #include <asm/prom.h> 24 25 #include <asm/io.h> 25 26 #include <asm/smp.h> ··· 68 67 69 68 /* Xive state for each CPU */ 70 69 static DEFINE_PER_CPU(struct xive_cpu *, xive_cpu); 71 - 72 - /* 73 - * A "disabled" interrupt should never fire, to catch problems 74 - * we set its logical number to this 75 - */ 76 - #define XIVE_BAD_IRQ 0x7fffffff 77 - #define XIVE_MAX_IRQ (XIVE_BAD_IRQ - 1) 78 70 79 71 /* An invalid CPU target */ 80 72 #define XIVE_INVALID_TARGET (-1) ··· 259 265 260 266 int xmon_xive_get_irq_config(u32 hw_irq, struct irq_data *d) 261 267 { 268 + struct irq_chip *chip = irq_data_get_irq_chip(d); 262 269 int rc; 263 270 u32 target; 264 271 u8 prio; 265 272 u32 lirq; 273 + 274 + if (!is_xive_irq(chip)) 275 + return -EINVAL; 266 276 267 277 rc = xive_ops->get_irq_config(hw_irq, &target, &prio, &lirq); 268 278 if (rc) { ··· 281 283 struct xive_irq_data *xd = irq_data_get_irq_handler_data(d); 282 284 u64 val = xive_esb_read(xd, XIVE_ESB_GET); 283 285 284 - xmon_printf("PQ=%c%c", 286 + xmon_printf("flags=%c%c%c PQ=%c%c", 287 + xd->flags & XIVE_IRQ_FLAG_STORE_EOI ? 'S' : ' ', 288 + xd->flags & XIVE_IRQ_FLAG_LSI ? 'L' : ' ', 289 + xd->flags & XIVE_IRQ_FLAG_H_INT_ESB ? 'H' : ' ', 285 290 val & XIVE_ESB_VAL_P ? 'P' : '-', 286 291 val & XIVE_ESB_VAL_Q ? 'Q' : '-'); 287 292 } ··· 1151 1150 xc = per_cpu(xive_cpu, cpu); 1152 1151 1153 1152 /* Check if we are already setup */ 1154 - if (xc->hw_ipi != 0) 1153 + if (xc->hw_ipi != XIVE_BAD_IRQ) 1155 1154 return 0; 1156 1155 1157 1156 /* Grab an IPI from the backend, this will populate xc->hw_ipi */ ··· 1188 1187 /* Disable the IPI and free the IRQ data */ 1189 1188 1190 1189 /* Already cleaned up ? */ 1191 - if (xc->hw_ipi == 0) 1190 + if (xc->hw_ipi == XIVE_BAD_IRQ) 1192 1191 return; 1193 1192 1194 1193 /* Mask the IPI */ ··· 1344 1343 if (np) 1345 1344 xc->chip_id = of_get_ibm_chip_id(np); 1346 1345 of_node_put(np); 1346 + xc->hw_ipi = XIVE_BAD_IRQ; 1347 1347 1348 1348 per_cpu(xive_cpu, cpu) = xc; 1349 1349 } ··· 1556 1554 return 0; 1557 1555 } 1558 1556 __setup("xive=off", xive_off); 1557 + 1558 + void xive_debug_show_cpu(struct seq_file *m, int cpu) 1559 + { 1560 + struct xive_cpu *xc = per_cpu(xive_cpu, cpu); 1561 + 1562 + seq_printf(m, "CPU %d:", cpu); 1563 + if (xc) { 1564 + seq_printf(m, "pp=%02x CPPR=%02x ", xc->pending_prio, xc->cppr); 1565 + 1566 + #ifdef CONFIG_SMP 1567 + { 1568 + u64 val = xive_esb_read(&xc->ipi_data, XIVE_ESB_GET); 1569 + 1570 + seq_printf(m, "IPI=0x%08x PQ=%c%c ", xc->hw_ipi, 1571 + val & XIVE_ESB_VAL_P ? 'P' : '-', 1572 + val & XIVE_ESB_VAL_Q ? 'Q' : '-'); 1573 + } 1574 + #endif 1575 + { 1576 + struct xive_q *q = &xc->queue[xive_irq_priority]; 1577 + u32 i0, i1, idx; 1578 + 1579 + if (q->qpage) { 1580 + idx = q->idx; 1581 + i0 = be32_to_cpup(q->qpage + idx); 1582 + idx = (idx + 1) & q->msk; 1583 + i1 = be32_to_cpup(q->qpage + idx); 1584 + seq_printf(m, "EQ idx=%d T=%d %08x %08x ...", 1585 + q->idx, q->toggle, i0, i1); 1586 + } 1587 + } 1588 + } 1589 + seq_puts(m, "\n"); 1590 + } 1591 + 1592 + void xive_debug_show_irq(struct seq_file *m, u32 hw_irq, struct irq_data *d) 1593 + { 1594 + struct irq_chip *chip = irq_data_get_irq_chip(d); 1595 + int rc; 1596 + u32 target; 1597 + u8 prio; 1598 + u32 lirq; 1599 + 1600 + if (!is_xive_irq(chip)) 1601 + return; 1602 + 1603 + rc = xive_ops->get_irq_config(hw_irq, &target, &prio, &lirq); 1604 + if (rc) { 1605 + seq_printf(m, "IRQ 0x%08x : no config rc=%d\n", hw_irq, rc); 1606 + return; 1607 + } 1608 + 1609 + seq_printf(m, "IRQ 0x%08x : target=0x%x prio=%02x lirq=0x%x ", 1610 + hw_irq, target, prio, lirq); 1611 + 1612 + if (d) { 1613 + struct xive_irq_data *xd = irq_data_get_irq_handler_data(d); 1614 + u64 val = xive_esb_read(xd, XIVE_ESB_GET); 1615 + 1616 + seq_printf(m, "flags=%c%c%c PQ=%c%c", 1617 + xd->flags & XIVE_IRQ_FLAG_STORE_EOI ? 'S' : ' ', 1618 + xd->flags & XIVE_IRQ_FLAG_LSI ? 'L' : ' ', 1619 + xd->flags & XIVE_IRQ_FLAG_H_INT_ESB ? 'H' : ' ', 1620 + val & XIVE_ESB_VAL_P ? 'P' : '-', 1621 + val & XIVE_ESB_VAL_Q ? 'Q' : '-'); 1622 + } 1623 + seq_puts(m, "\n"); 1624 + } 1625 + 1626 + static int xive_core_debug_show(struct seq_file *m, void *private) 1627 + { 1628 + unsigned int i; 1629 + struct irq_desc *desc; 1630 + int cpu; 1631 + 1632 + if (xive_ops->debug_show) 1633 + xive_ops->debug_show(m, private); 1634 + 1635 + for_each_possible_cpu(cpu) 1636 + xive_debug_show_cpu(m, cpu); 1637 + 1638 + for_each_irq_desc(i, desc) { 1639 + struct irq_data *d = irq_desc_get_irq_data(desc); 1640 + unsigned int hw_irq; 1641 + 1642 + if (!d) 1643 + continue; 1644 + 1645 + hw_irq = (unsigned int)irqd_to_hwirq(d); 1646 + 1647 + /* IPIs are special (HW number 0) */ 1648 + if (hw_irq) 1649 + xive_debug_show_irq(m, hw_irq, d); 1650 + } 1651 + return 0; 1652 + } 1653 + DEFINE_SHOW_ATTRIBUTE(xive_core_debug); 1654 + 1655 + int xive_core_debug_init(void) 1656 + { 1657 + debugfs_create_file("xive", 0400, powerpc_debugfs_root, 1658 + NULL, &xive_core_debug_fops); 1659 + return 0; 1660 + }
+5 -2
arch/powerpc/sysdev/xive/native.c
··· 19 19 #include <linux/cpumask.h> 20 20 #include <linux/mm.h> 21 21 22 + #include <asm/machdep.h> 22 23 #include <asm/prom.h> 23 24 #include <asm/io.h> 24 25 #include <asm/smp.h> ··· 313 312 s64 rc; 314 313 315 314 /* Free the IPI */ 316 - if (!xc->hw_ipi) 315 + if (xc->hw_ipi == XIVE_BAD_IRQ) 317 316 return; 318 317 for (;;) { 319 318 rc = opal_xive_free_irq(xc->hw_ipi); ··· 321 320 msleep(OPAL_BUSY_DELAY_MS); 322 321 continue; 323 322 } 324 - xc->hw_ipi = 0; 323 + xc->hw_ipi = XIVE_BAD_IRQ; 325 324 break; 326 325 } 327 326 } ··· 851 850 return 0; 852 851 } 853 852 EXPORT_SYMBOL_GPL(xive_native_get_vp_state); 853 + 854 + machine_arch_initcall(powernv, xive_core_debug_init);
+21 -2
arch/powerpc/sysdev/xive/spapr.c
··· 18 18 #include <linux/delay.h> 19 19 #include <linux/libfdt.h> 20 20 21 + #include <asm/machdep.h> 21 22 #include <asm/prom.h> 22 23 #include <asm/io.h> 23 24 #include <asm/smp.h> ··· 561 560 562 561 static void xive_spapr_put_ipi(unsigned int cpu, struct xive_cpu *xc) 563 562 { 564 - if (!xc->hw_ipi) 563 + if (xc->hw_ipi == XIVE_BAD_IRQ) 565 564 return; 566 565 567 566 xive_irq_bitmap_free(xc->hw_ipi); 568 - xc->hw_ipi = 0; 567 + xc->hw_ipi = XIVE_BAD_IRQ; 569 568 } 570 569 #endif /* CONFIG_SMP */ 571 570 ··· 646 645 plpar_int_sync(0, hw_irq); 647 646 } 648 647 648 + static int xive_spapr_debug_show(struct seq_file *m, void *private) 649 + { 650 + struct xive_irq_bitmap *xibm; 651 + char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 652 + 653 + list_for_each_entry(xibm, &xive_irq_bitmaps, list) { 654 + memset(buf, 0, PAGE_SIZE); 655 + bitmap_print_to_pagebuf(true, buf, xibm->bitmap, xibm->count); 656 + seq_printf(m, "bitmap #%d: %s", xibm->count, buf); 657 + } 658 + kfree(buf); 659 + 660 + return 0; 661 + } 662 + 649 663 static const struct xive_ops xive_spapr_ops = { 650 664 .populate_irq_data = xive_spapr_populate_irq_data, 651 665 .configure_irq = xive_spapr_configure_irq, ··· 678 662 #ifdef CONFIG_SMP 679 663 .get_ipi = xive_spapr_get_ipi, 680 664 .put_ipi = xive_spapr_put_ipi, 665 + .debug_show = xive_spapr_debug_show, 681 666 #endif /* CONFIG_SMP */ 682 667 .name = "spapr", 683 668 }; ··· 856 839 pr_info("Using %dkB queues\n", 1 << (xive_queue_shift - 10)); 857 840 return true; 858 841 } 842 + 843 + machine_arch_initcall(pseries, xive_core_debug_init);
+9
arch/powerpc/sysdev/xive/xive-internal.h
··· 5 5 #ifndef __XIVE_INTERNAL_H 6 6 #define __XIVE_INTERNAL_H 7 7 8 + /* 9 + * A "disabled" interrupt should never fire, to catch problems 10 + * we set its logical number to this 11 + */ 12 + #define XIVE_BAD_IRQ 0x7fffffff 13 + #define XIVE_MAX_IRQ (XIVE_BAD_IRQ - 1) 14 + 8 15 /* Each CPU carry one of these with various per-CPU state */ 9 16 struct xive_cpu { 10 17 #ifdef CONFIG_SMP ··· 57 50 int (*get_ipi)(unsigned int cpu, struct xive_cpu *xc); 58 51 void (*put_ipi)(unsigned int cpu, struct xive_cpu *xc); 59 52 #endif 53 + int (*debug_show)(struct seq_file *m, void *private); 60 54 const char *name; 61 55 }; 62 56 63 57 bool xive_core_init(const struct xive_ops *ops, void __iomem *area, u32 offset, 64 58 u8 max_prio); 65 59 __be32 *xive_queue_page_alloc(unsigned int cpu, u32 queue_shift); 60 + int xive_core_debug_init(void); 66 61 67 62 static inline u32 xive_alloc_order(u32 queue_shift) 68 63 {
-3
arch/powerpc/xmon/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # Makefile for xmon 3 3 4 - # Avoid clang warnings around longjmp/setjmp declarations 5 - subdir-ccflags-y := -ffreestanding 6 - 7 4 GCOV_PROFILE := n 8 5 KCOV_INSTRUMENT := n 9 6 UBSAN_SANITIZE := n
+10 -4
arch/powerpc/xmon/xmon.c
··· 81 81 82 82 static unsigned long adrs; 83 83 static int size = 1; 84 - #define MAX_DUMP (128 * 1024) 84 + #define MAX_DUMP (64 * 1024) 85 85 static unsigned long ndump = 64; 86 + #define MAX_IDUMP (MAX_DUMP >> 2) 86 87 static unsigned long nidump = 16; 87 88 static unsigned long ncsum = 4096; 88 89 static int termch; ··· 2713 2712 2714 2713 printf("%0*llx", size * 2, val); 2715 2714 } 2716 - printf("\n"); 2715 + printf(" |"); 2716 + for (j = 0; j < 16; ++j) { 2717 + val = temp[j]; 2718 + putchar(' ' <= val && val <= '~' ? val : '.'); 2719 + } 2720 + printf("|\n"); 2717 2721 } 2718 2722 } 2719 2723 ··· 2762 2756 scanhex(&nidump); 2763 2757 if (nidump == 0) 2764 2758 nidump = 16; 2765 - else if (nidump > MAX_DUMP) 2766 - nidump = MAX_DUMP; 2759 + else if (nidump > MAX_IDUMP) 2760 + nidump = MAX_IDUMP; 2767 2761 adrs += ppc_inst_dump(adrs, nidump, 1); 2768 2762 last_cmd = "di\n"; 2769 2763 } else if (c == 'l') {
+19 -11
drivers/cpufreq/powernv-cpufreq.c
··· 902 902 void powernv_cpufreq_work_fn(struct work_struct *work) 903 903 { 904 904 struct chip *chip = container_of(work, struct chip, throttle); 905 + struct cpufreq_policy *policy; 905 906 unsigned int cpu; 906 907 cpumask_t mask; 907 908 ··· 917 916 chip->restore = false; 918 917 for_each_cpu(cpu, &mask) { 919 918 int index; 920 - struct cpufreq_policy policy; 921 919 922 - cpufreq_get_policy(&policy, cpu); 923 - index = cpufreq_table_find_index_c(&policy, policy.cur); 924 - powernv_cpufreq_target_index(&policy, index); 925 - cpumask_andnot(&mask, &mask, policy.cpus); 920 + policy = cpufreq_cpu_get(cpu); 921 + if (!policy) 922 + continue; 923 + index = cpufreq_table_find_index_c(policy, policy->cur); 924 + powernv_cpufreq_target_index(policy, index); 925 + cpumask_andnot(&mask, &mask, policy->cpus); 926 + cpufreq_cpu_put(policy); 926 927 } 927 928 out: 928 929 put_online_cpus(); ··· 1083 1080 1084 1081 static inline void clean_chip_info(void) 1085 1082 { 1083 + int i; 1084 + 1085 + /* flush any pending work items */ 1086 + if (chips) 1087 + for (i = 0; i < nr_chips; i++) 1088 + cancel_work_sync(&chips[i].throttle); 1086 1089 kfree(chips); 1087 1090 } 1088 1091 ··· 1117 1108 if (rc) 1118 1109 goto out; 1119 1110 1120 - register_reboot_notifier(&powernv_cpufreq_reboot_nb); 1121 - opal_message_notifier_register(OPAL_MSG_OCC, &powernv_cpufreq_opal_nb); 1122 - 1123 1111 if (powernv_pstate_info.wof_enabled) 1124 1112 powernv_cpufreq_driver.boost_enabled = true; 1125 1113 else ··· 1125 1119 rc = cpufreq_register_driver(&powernv_cpufreq_driver); 1126 1120 if (rc) { 1127 1121 pr_info("Failed to register the cpufreq driver (%d)\n", rc); 1128 - goto cleanup_notifiers; 1122 + goto cleanup; 1129 1123 } 1130 1124 1131 1125 if (powernv_pstate_info.wof_enabled) 1132 1126 cpufreq_enable_boost_support(); 1133 1127 1128 + register_reboot_notifier(&powernv_cpufreq_reboot_nb); 1129 + opal_message_notifier_register(OPAL_MSG_OCC, &powernv_cpufreq_opal_nb); 1130 + 1134 1131 return 0; 1135 - cleanup_notifiers: 1136 - unregister_all_notifiers(); 1132 + cleanup: 1137 1133 clean_chip_info(); 1138 1134 out: 1139 1135 pr_info("Platform driver disabled. System does not support PState control\n");
+1 -1
drivers/pci/hotplug/rpadlpar_core.c
··· 140 140 struct pci_controller *phb = pdn->phb; 141 141 struct pci_dev *dev = NULL; 142 142 143 - eeh_add_device_tree_early(pdn); 143 + pseries_eeh_init_edev_recursive(pdn); 144 144 145 145 /* Add EADS device to PHB bus, adding new entry to bus->devices */ 146 146 dev = of_create_pci_dev(dn, phb->bus, pdn->devfn);
+3 -2
drivers/pci/hotplug/rpaphp_core.c
··· 288 288 289 289 static int is_php_type(char *drc_type) 290 290 { 291 - unsigned long value; 292 291 char *endptr; 293 292 294 293 /* PCI Hotplug nodes have an integer for drc_type */ 295 - value = simple_strtoul(drc_type, &endptr, 10); 294 + simple_strtoul(drc_type, &endptr, 10); 296 295 if (endptr == drc_type) 297 296 return 0; 298 297 ··· 493 494 return retval; 494 495 495 496 if (state == PRESENT) { 497 + pseries_eeh_init_edev_recursive(PCI_DN(slot->dn)); 498 + 496 499 pci_lock_rescan_remove(); 497 500 pci_hp_add_devices(slot->bus); 498 501 pci_unlock_rescan_remove();
+3 -1
drivers/pci/hotplug/rpaphp_pci.c
··· 95 95 return -EINVAL; 96 96 } 97 97 98 - if (list_empty(&bus->devices)) 98 + if (list_empty(&bus->devices)) { 99 + pseries_eeh_init_edev_recursive(PCI_DN(slot->dn)); 99 100 pci_hp_add_devices(bus); 101 + } 100 102 101 103 if (!list_empty(&bus->devices)) { 102 104 slot->state = CONFIGURED;
+18 -3
drivers/tty/ehv_bytechan.c
··· 136 136 return 1; 137 137 } 138 138 139 + static unsigned int local_ev_byte_channel_send(unsigned int handle, 140 + unsigned int *count, 141 + const char *p) 142 + { 143 + char buffer[EV_BYTE_CHANNEL_MAX_BYTES]; 144 + unsigned int c = *count; 145 + 146 + if (c < sizeof(buffer)) { 147 + memcpy(buffer, p, c); 148 + memset(&buffer[c], 0, sizeof(buffer) - c); 149 + p = buffer; 150 + } 151 + return ev_byte_channel_send(handle, count, p); 152 + } 153 + 139 154 /*************************** EARLY CONSOLE DRIVER ***************************/ 140 155 141 156 #ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC ··· 169 154 170 155 do { 171 156 count = 1; 172 - ret = ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE, 157 + ret = local_ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE, 173 158 &count, &data); 174 159 } while (ret == EV_EAGAIN); 175 160 } ··· 236 221 while (count) { 237 222 len = min_t(unsigned int, count, EV_BYTE_CHANNEL_MAX_BYTES); 238 223 do { 239 - ret = ev_byte_channel_send(handle, &len, s); 224 + ret = local_ev_byte_channel_send(handle, &len, s); 240 225 } while (ret == EV_EAGAIN); 241 226 count -= len; 242 227 s += len; ··· 416 401 CIRC_CNT_TO_END(bc->head, bc->tail, BUF_SIZE), 417 402 EV_BYTE_CHANNEL_MAX_BYTES); 418 403 419 - ret = ev_byte_channel_send(bc->handle, &len, bc->buf + bc->tail); 404 + ret = local_ev_byte_channel_send(bc->handle, &len, bc->buf + bc->tail); 420 405 421 406 /* 'len' is valid only if the return code is 0 or EV_EAGAIN */ 422 407 if (!ret || (ret == EV_EAGAIN))
+25 -3
fs/sysfs/group.c
··· 426 426 struct kobject *target_kobj, 427 427 const char *target_name) 428 428 { 429 + return compat_only_sysfs_link_entry_to_kobj(kobj, target_kobj, 430 + target_name, NULL); 431 + } 432 + EXPORT_SYMBOL_GPL(__compat_only_sysfs_link_entry_to_kobj); 433 + 434 + /** 435 + * compat_only_sysfs_link_entry_to_kobj - add a symlink to a kobject pointing 436 + * to a group or an attribute 437 + * @kobj: The kobject containing the group. 438 + * @target_kobj: The target kobject. 439 + * @target_name: The name of the target group or attribute. 440 + * @symlink_name: The name of the symlink file (target_name will be 441 + * considered if symlink_name is NULL). 442 + */ 443 + int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, 444 + struct kobject *target_kobj, 445 + const char *target_name, 446 + const char *symlink_name) 447 + { 429 448 struct kernfs_node *target; 430 449 struct kernfs_node *entry; 431 450 struct kernfs_node *link; ··· 468 449 return -ENOENT; 469 450 } 470 451 471 - link = kernfs_create_link(kobj->sd, target_name, entry); 452 + if (!symlink_name) 453 + symlink_name = target_name; 454 + 455 + link = kernfs_create_link(kobj->sd, symlink_name, entry); 472 456 if (PTR_ERR(link) == -EEXIST) 473 - sysfs_warn_dup(kobj->sd, target_name); 457 + sysfs_warn_dup(kobj->sd, symlink_name); 474 458 475 459 kernfs_put(entry); 476 460 kernfs_put(target); 477 461 return PTR_ERR_OR_ZERO(link); 478 462 } 479 - EXPORT_SYMBOL_GPL(__compat_only_sysfs_link_entry_to_kobj); 463 + EXPORT_SYMBOL_GPL(compat_only_sysfs_link_entry_to_kobj); 480 464 481 465 static int sysfs_group_attrs_change_owner(struct kernfs_node *grp_kn, 482 466 const struct attribute_group *grp,
+12
include/linux/sysfs.h
··· 300 300 int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, 301 301 struct kobject *target_kobj, 302 302 const char *target_name); 303 + int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, 304 + struct kobject *target_kobj, 305 + const char *target_name, 306 + const char *symlink_name); 303 307 304 308 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); 305 309 ··· 520 516 struct kobject *kobj, 521 517 struct kobject *target_kobj, 522 518 const char *target_name) 519 + { 520 + return 0; 521 + } 522 + 523 + static inline int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, 524 + struct kobject *target_kobj, 525 + const char *target_name, 526 + const char *symlink_name) 523 527 { 524 528 return 0; 525 529 }
+2
tools/testing/selftests/powerpc/benchmarks/Makefile
··· 2 2 TEST_GEN_PROGS := gettimeofday context_switch fork mmap_bench futex_bench null_syscall 3 3 TEST_GEN_FILES := exec_target 4 4 5 + TEST_FILES := settings 6 + 5 7 CFLAGS += -O2 6 8 7 9 top_srcdir = ../../../../..
+1
tools/testing/selftests/powerpc/benchmarks/settings
··· 1 + timeout=0
+2
tools/testing/selftests/powerpc/dscr/Makefile
··· 3 3 dscr_inherit_test dscr_inherit_exec_test dscr_sysfs_test \ 4 4 dscr_sysfs_thread_test 5 5 6 + TEST_FILES := settings 7 + 6 8 top_srcdir = ../../../../.. 7 9 include ../../lib.mk 8 10
+1
tools/testing/selftests/powerpc/dscr/settings
··· 1 + timeout=0
+1
tools/testing/selftests/powerpc/mm/.gitignore
··· 7 7 wild_bctr 8 8 large_vm_fork_separation 9 9 bad_accesses 10 + tlbie_test
+1
tools/testing/selftests/powerpc/pmu/ebb/Makefile
··· 7 7 # The EBB handler is 64-bit code and everything links against it 8 8 CFLAGS += -m64 9 9 10 + TMPOUT = $(OUTPUT)/ 10 11 # Toolchains may build PIE by default which breaks the assembly 11 12 no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \ 12 13 $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -no-pie -x c - -o "$$TMP", -no-pie)
+1
tools/testing/selftests/powerpc/signal/.gitignore
··· 2 2 signal 3 3 signal_tm 4 4 sigfuz 5 + sigreturn_vdso
+3 -1
tools/testing/selftests/powerpc/signal/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - TEST_GEN_PROGS := signal signal_tm sigfuz 2 + TEST_GEN_PROGS := signal signal_tm sigfuz sigreturn_vdso 3 3 4 4 CFLAGS += -maltivec 5 5 $(OUTPUT)/signal_tm: CFLAGS += -mhtm 6 6 $(OUTPUT)/sigfuz: CFLAGS += -pthread -m64 7 + 8 + TEST_FILES := settings 7 9 8 10 top_srcdir = ../../../../.. 9 11 include ../../lib.mk
+1
tools/testing/selftests/powerpc/signal/settings
··· 1 + timeout=0
+127
tools/testing/selftests/powerpc/signal/sigreturn_vdso.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Test that we can take signals with and without the VDSO mapped, which trigger 4 + * different paths in the signal handling code. 5 + * 6 + * See handle_rt_signal64() and setup_trampoline() in signal_64.c 7 + */ 8 + 9 + #define _GNU_SOURCE 10 + 11 + #include <errno.h> 12 + #include <stdio.h> 13 + #include <signal.h> 14 + #include <stdlib.h> 15 + #include <string.h> 16 + #include <sys/mman.h> 17 + #include <sys/types.h> 18 + #include <unistd.h> 19 + 20 + // Ensure assert() is not compiled out 21 + #undef NDEBUG 22 + #include <assert.h> 23 + 24 + #include "utils.h" 25 + 26 + static int search_proc_maps(char *needle, unsigned long *low, unsigned long *high) 27 + { 28 + unsigned long start, end; 29 + static char buf[4096]; 30 + char name[128]; 31 + FILE *f; 32 + int rc = -1; 33 + 34 + f = fopen("/proc/self/maps", "r"); 35 + if (!f) { 36 + perror("fopen"); 37 + return -1; 38 + } 39 + 40 + while (fgets(buf, sizeof(buf), f)) { 41 + rc = sscanf(buf, "%lx-%lx %*c%*c%*c%*c %*x %*d:%*d %*d %127s\n", 42 + &start, &end, name); 43 + if (rc == 2) 44 + continue; 45 + 46 + if (rc != 3) { 47 + printf("sscanf errored\n"); 48 + rc = -1; 49 + break; 50 + } 51 + 52 + if (strstr(name, needle)) { 53 + *low = start; 54 + *high = end - 1; 55 + rc = 0; 56 + break; 57 + } 58 + } 59 + 60 + fclose(f); 61 + 62 + return rc; 63 + } 64 + 65 + static volatile sig_atomic_t took_signal = 0; 66 + 67 + static void sigusr1_handler(int sig) 68 + { 69 + took_signal++; 70 + } 71 + 72 + int test_sigreturn_vdso(void) 73 + { 74 + unsigned long low, high, size; 75 + struct sigaction act; 76 + char *p; 77 + 78 + act.sa_handler = sigusr1_handler; 79 + act.sa_flags = 0; 80 + sigemptyset(&act.sa_mask); 81 + 82 + assert(sigaction(SIGUSR1, &act, NULL) == 0); 83 + 84 + // Confirm the VDSO is mapped, and work out where it is 85 + assert(search_proc_maps("[vdso]", &low, &high) == 0); 86 + size = high - low + 1; 87 + printf("VDSO is at 0x%lx-0x%lx (%lu bytes)\n", low, high, size); 88 + 89 + kill(getpid(), SIGUSR1); 90 + assert(took_signal == 1); 91 + printf("Signal delivered OK with VDSO mapped\n"); 92 + 93 + // Remap the VDSO somewhere else 94 + p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); 95 + assert(p != MAP_FAILED); 96 + assert(mremap((void *)low, size, size, MREMAP_MAYMOVE|MREMAP_FIXED, p) != MAP_FAILED); 97 + assert(search_proc_maps("[vdso]", &low, &high) == 0); 98 + size = high - low + 1; 99 + printf("VDSO moved to 0x%lx-0x%lx (%lu bytes)\n", low, high, size); 100 + 101 + kill(getpid(), SIGUSR1); 102 + assert(took_signal == 2); 103 + printf("Signal delivered OK with VDSO moved\n"); 104 + 105 + assert(munmap((void *)low, size) == 0); 106 + printf("Unmapped VDSO\n"); 107 + 108 + // Confirm the VDSO is not mapped anymore 109 + assert(search_proc_maps("[vdso]", &low, &high) != 0); 110 + 111 + // Make the stack executable 112 + assert(search_proc_maps("[stack]", &low, &high) == 0); 113 + size = high - low + 1; 114 + mprotect((void *)low, size, PROT_READ|PROT_WRITE|PROT_EXEC); 115 + printf("Remapped the stack executable\n"); 116 + 117 + kill(getpid(), SIGUSR1); 118 + assert(took_signal == 3); 119 + printf("Signal delivered OK with VDSO unmapped\n"); 120 + 121 + return 0; 122 + } 123 + 124 + int main(void) 125 + { 126 + return test_harness(test_sigreturn_vdso, "sigreturn_vdso"); 127 + }
+1
tools/testing/selftests/powerpc/tm/.gitignore
··· 14 14 tm-signal-context-chk-vsx 15 15 tm-signal-context-force-tm 16 16 tm-signal-sigreturn-nt 17 + tm-signal-pagefault 17 18 tm-vmx-unavail 18 19 tm-unavailable 19 20 tm-trap
+4 -1
tools/testing/selftests/powerpc/tm/Makefile
··· 5 5 TEST_GEN_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \ 6 6 tm-vmxcopy tm-fork tm-tar tm-tmspr tm-vmx-unavail tm-unavailable tm-trap \ 7 7 $(SIGNAL_CONTEXT_CHK_TESTS) tm-sigreturn tm-signal-sigreturn-nt \ 8 - tm-signal-context-force-tm tm-poison 8 + tm-signal-context-force-tm tm-poison tm-signal-pagefault 9 + 10 + TEST_FILES := settings 9 11 10 12 top_srcdir = ../../../../.. 11 13 include ../../lib.mk ··· 24 22 $(OUTPUT)/tm-unavailable: CFLAGS += -O0 -pthread -m64 -Wno-error=uninitialized -mvsx 25 23 $(OUTPUT)/tm-trap: CFLAGS += -O0 -pthread -m64 26 24 $(OUTPUT)/tm-signal-context-force-tm: CFLAGS += -pthread -m64 25 + $(OUTPUT)/tm-signal-pagefault: CFLAGS += -pthread -m64 27 26 28 27 SIGNAL_CONTEXT_CHK_TESTS := $(patsubst %,$(OUTPUT)/%,$(SIGNAL_CONTEXT_CHK_TESTS)) 29 28 $(SIGNAL_CONTEXT_CHK_TESTS): tm-signal.S
+1
tools/testing/selftests/powerpc/tm/settings
··· 1 + timeout=0
+37 -41
tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c
··· 42 42 #endif 43 43 44 44 /* Setting contexts because the test will crash and we want to recover */ 45 - ucontext_t init_context, main_context; 45 + ucontext_t init_context; 46 46 47 - static int count, first_time; 47 + /* count is changed in the signal handler, so it must be volatile */ 48 + static volatile int count; 48 49 49 50 void usr_signal_handler(int signo, siginfo_t *si, void *uc) 50 51 { ··· 99 98 100 99 void seg_signal_handler(int signo, siginfo_t *si, void *uc) 101 100 { 102 - if (count == COUNT_MAX) { 103 - /* Return to tm_signal_force_msr() and exit */ 104 - setcontext(&main_context); 105 - } 106 - 107 101 count++; 108 102 109 103 /* Reexecute the test */ ··· 122 126 */ 123 127 getcontext(&init_context); 124 128 125 - /* Allocated an alternative signal stack area */ 126 - ss.ss_sp = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, 127 - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); 128 - ss.ss_size = SIGSTKSZ; 129 - ss.ss_flags = 0; 129 + while (count < COUNT_MAX) { 130 + /* Allocated an alternative signal stack area */ 131 + ss.ss_sp = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, 132 + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); 133 + ss.ss_size = SIGSTKSZ; 134 + ss.ss_flags = 0; 130 135 131 - if (ss.ss_sp == (void *)-1) { 132 - perror("mmap error\n"); 133 - exit(-1); 136 + if (ss.ss_sp == (void *)-1) { 137 + perror("mmap error\n"); 138 + exit(-1); 139 + } 140 + 141 + /* Force the allocation through a page fault */ 142 + if (madvise(ss.ss_sp, SIGSTKSZ, MADV_DONTNEED)) { 143 + perror("madvise\n"); 144 + exit(-1); 145 + } 146 + 147 + /* 148 + * Setting an alternative stack to generate a page fault when 149 + * the signal is raised. 150 + */ 151 + if (sigaltstack(&ss, NULL)) { 152 + perror("sigaltstack\n"); 153 + exit(-1); 154 + } 155 + 156 + /* The signal handler will enable MSR_TS */ 157 + sigaction(SIGUSR1, &usr_sa, NULL); 158 + /* If it does not crash, it might segfault, avoid it to retest */ 159 + sigaction(SIGSEGV, &seg_sa, NULL); 160 + 161 + raise(SIGUSR1); 162 + count++; 134 163 } 135 - 136 - /* Force the allocation through a page fault */ 137 - if (madvise(ss.ss_sp, SIGSTKSZ, MADV_DONTNEED)) { 138 - perror("madvise\n"); 139 - exit(-1); 140 - } 141 - 142 - /* Setting an alternative stack to generate a page fault when 143 - * the signal is raised. 144 - */ 145 - if (sigaltstack(&ss, NULL)) { 146 - perror("sigaltstack\n"); 147 - exit(-1); 148 - } 149 - 150 - /* The signal handler will enable MSR_TS */ 151 - sigaction(SIGUSR1, &usr_sa, NULL); 152 - /* If it does not crash, it will segfault, avoid it to retest */ 153 - sigaction(SIGSEGV, &seg_sa, NULL); 154 - 155 - raise(SIGUSR1); 156 164 } 157 165 158 166 int tm_signal_context_force_tm(void) ··· 169 169 */ 170 170 SKIP_IF(!is_ppc64le()); 171 171 172 - /* Will get back here after COUNT_MAX interactions */ 173 - getcontext(&main_context); 174 - 175 - if (!first_time++) 176 - tm_trap_test(); 172 + tm_trap_test(); 177 173 178 174 return EXIT_SUCCESS; 179 175 }
+284
tools/testing/selftests/powerpc/tm/tm-signal-pagefault.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright 2020, Gustavo Luiz Duarte, IBM Corp. 4 + * 5 + * This test starts a transaction and triggers a signal, forcing a pagefault to 6 + * happen when the kernel signal handling code touches the user signal stack. 7 + * 8 + * In order to avoid pre-faulting the signal stack memory and to force the 9 + * pagefault to happen precisely in the kernel signal handling code, the 10 + * pagefault handling is done in userspace using the userfaultfd facility. 11 + * 12 + * Further pagefaults are triggered by crafting the signal handler's ucontext 13 + * to point to additional memory regions managed by the userfaultfd, so using 14 + * the same mechanism used to avoid pre-faulting the signal stack memory. 15 + * 16 + * On failure (bug is present) kernel crashes or never returns control back to 17 + * userspace. If bug is not present, tests completes almost immediately. 18 + */ 19 + 20 + #include <stdio.h> 21 + #include <stdlib.h> 22 + #include <string.h> 23 + #include <linux/userfaultfd.h> 24 + #include <poll.h> 25 + #include <unistd.h> 26 + #include <sys/ioctl.h> 27 + #include <sys/syscall.h> 28 + #include <fcntl.h> 29 + #include <sys/mman.h> 30 + #include <pthread.h> 31 + #include <signal.h> 32 + #include <errno.h> 33 + 34 + #include "tm.h" 35 + 36 + 37 + #define UF_MEM_SIZE 655360 /* 10 x 64k pages */ 38 + 39 + /* Memory handled by userfaultfd */ 40 + static char *uf_mem; 41 + static size_t uf_mem_offset = 0; 42 + 43 + /* 44 + * Data that will be copied into the faulting pages (instead of zero-filled 45 + * pages). This is used to make the test more reliable and avoid segfaulting 46 + * when we return from the signal handler. Since we are making the signal 47 + * handler's ucontext point to newly allocated memory, when that memory is 48 + * paged-in it will contain the expected content. 49 + */ 50 + static char backing_mem[UF_MEM_SIZE]; 51 + 52 + static size_t pagesize; 53 + 54 + /* 55 + * Return a chunk of at least 'size' bytes of memory that will be handled by 56 + * userfaultfd. If 'backing_data' is not NULL, its content will be save to 57 + * 'backing_mem' and then copied into the faulting pages when the page fault 58 + * is handled. 59 + */ 60 + void *get_uf_mem(size_t size, void *backing_data) 61 + { 62 + void *ret; 63 + 64 + if (uf_mem_offset + size > UF_MEM_SIZE) { 65 + fprintf(stderr, "Requesting more uf_mem than expected!\n"); 66 + exit(EXIT_FAILURE); 67 + } 68 + 69 + ret = &uf_mem[uf_mem_offset]; 70 + 71 + /* Save the data that will be copied into the faulting page */ 72 + if (backing_data != NULL) 73 + memcpy(&backing_mem[uf_mem_offset], backing_data, size); 74 + 75 + /* Reserve the requested amount of uf_mem */ 76 + uf_mem_offset += size; 77 + /* Keep uf_mem_offset aligned to the page size (round up) */ 78 + uf_mem_offset = (uf_mem_offset + pagesize - 1) & ~(pagesize - 1); 79 + 80 + return ret; 81 + } 82 + 83 + void *fault_handler_thread(void *arg) 84 + { 85 + struct uffd_msg msg; /* Data read from userfaultfd */ 86 + long uffd; /* userfaultfd file descriptor */ 87 + struct uffdio_copy uffdio_copy; 88 + struct pollfd pollfd; 89 + ssize_t nread, offset; 90 + 91 + uffd = (long) arg; 92 + 93 + for (;;) { 94 + pollfd.fd = uffd; 95 + pollfd.events = POLLIN; 96 + if (poll(&pollfd, 1, -1) == -1) { 97 + perror("poll() failed"); 98 + exit(EXIT_FAILURE); 99 + } 100 + 101 + nread = read(uffd, &msg, sizeof(msg)); 102 + if (nread == 0) { 103 + fprintf(stderr, "read(): EOF on userfaultfd\n"); 104 + exit(EXIT_FAILURE); 105 + } 106 + 107 + if (nread == -1) { 108 + perror("read() failed"); 109 + exit(EXIT_FAILURE); 110 + } 111 + 112 + /* We expect only one kind of event */ 113 + if (msg.event != UFFD_EVENT_PAGEFAULT) { 114 + fprintf(stderr, "Unexpected event on userfaultfd\n"); 115 + exit(EXIT_FAILURE); 116 + } 117 + 118 + /* 119 + * We need to handle page faults in units of pages(!). 120 + * So, round faulting address down to page boundary. 121 + */ 122 + uffdio_copy.dst = msg.arg.pagefault.address & ~(pagesize-1); 123 + 124 + offset = (char *) uffdio_copy.dst - uf_mem; 125 + uffdio_copy.src = (unsigned long) &backing_mem[offset]; 126 + 127 + uffdio_copy.len = pagesize; 128 + uffdio_copy.mode = 0; 129 + uffdio_copy.copy = 0; 130 + if (ioctl(uffd, UFFDIO_COPY, &uffdio_copy) == -1) { 131 + perror("ioctl-UFFDIO_COPY failed"); 132 + exit(EXIT_FAILURE); 133 + } 134 + } 135 + } 136 + 137 + void setup_uf_mem(void) 138 + { 139 + long uffd; /* userfaultfd file descriptor */ 140 + pthread_t thr; 141 + struct uffdio_api uffdio_api; 142 + struct uffdio_register uffdio_register; 143 + int ret; 144 + 145 + pagesize = sysconf(_SC_PAGE_SIZE); 146 + 147 + /* Create and enable userfaultfd object */ 148 + uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); 149 + if (uffd == -1) { 150 + perror("userfaultfd() failed"); 151 + exit(EXIT_FAILURE); 152 + } 153 + uffdio_api.api = UFFD_API; 154 + uffdio_api.features = 0; 155 + if (ioctl(uffd, UFFDIO_API, &uffdio_api) == -1) { 156 + perror("ioctl-UFFDIO_API failed"); 157 + exit(EXIT_FAILURE); 158 + } 159 + 160 + /* 161 + * Create a private anonymous mapping. The memory will be demand-zero 162 + * paged, that is, not yet allocated. When we actually touch the memory 163 + * the related page will be allocated via the userfaultfd mechanism. 164 + */ 165 + uf_mem = mmap(NULL, UF_MEM_SIZE, PROT_READ | PROT_WRITE, 166 + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 167 + if (uf_mem == MAP_FAILED) { 168 + perror("mmap() failed"); 169 + exit(EXIT_FAILURE); 170 + } 171 + 172 + /* 173 + * Register the memory range of the mapping we've just mapped to be 174 + * handled by the userfaultfd object. In 'mode' we request to track 175 + * missing pages (i.e. pages that have not yet been faulted-in). 176 + */ 177 + uffdio_register.range.start = (unsigned long) uf_mem; 178 + uffdio_register.range.len = UF_MEM_SIZE; 179 + uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; 180 + if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1) { 181 + perror("ioctl-UFFDIO_REGISTER"); 182 + exit(EXIT_FAILURE); 183 + } 184 + 185 + /* Create a thread that will process the userfaultfd events */ 186 + ret = pthread_create(&thr, NULL, fault_handler_thread, (void *) uffd); 187 + if (ret != 0) { 188 + fprintf(stderr, "pthread_create(): Error. Returned %d\n", ret); 189 + exit(EXIT_FAILURE); 190 + } 191 + } 192 + 193 + /* 194 + * Assumption: the signal was delivered while userspace was in transactional or 195 + * suspended state, i.e. uc->uc_link != NULL. 196 + */ 197 + void signal_handler(int signo, siginfo_t *si, void *uc) 198 + { 199 + ucontext_t *ucp = uc; 200 + 201 + /* Skip 'trap' after returning, otherwise we get a SIGTRAP again */ 202 + ucp->uc_link->uc_mcontext.regs->nip += 4; 203 + 204 + ucp->uc_mcontext.v_regs = 205 + get_uf_mem(sizeof(elf_vrreg_t), ucp->uc_mcontext.v_regs); 206 + 207 + ucp->uc_link->uc_mcontext.v_regs = 208 + get_uf_mem(sizeof(elf_vrreg_t), ucp->uc_link->uc_mcontext.v_regs); 209 + 210 + ucp->uc_link = get_uf_mem(sizeof(ucontext_t), ucp->uc_link); 211 + } 212 + 213 + bool have_userfaultfd(void) 214 + { 215 + long rc; 216 + 217 + errno = 0; 218 + rc = syscall(__NR_userfaultfd, -1); 219 + 220 + return rc == 0 || errno != ENOSYS; 221 + } 222 + 223 + int tm_signal_pagefault(void) 224 + { 225 + struct sigaction sa; 226 + stack_t ss; 227 + 228 + SKIP_IF(!have_htm()); 229 + SKIP_IF(!have_userfaultfd()); 230 + 231 + setup_uf_mem(); 232 + 233 + /* 234 + * Set an alternative stack that will generate a page fault when the 235 + * signal is raised. The page fault will be treated via userfaultfd, 236 + * i.e. via fault_handler_thread. 237 + */ 238 + ss.ss_sp = get_uf_mem(SIGSTKSZ, NULL); 239 + ss.ss_size = SIGSTKSZ; 240 + ss.ss_flags = 0; 241 + if (sigaltstack(&ss, NULL) == -1) { 242 + perror("sigaltstack() failed"); 243 + exit(EXIT_FAILURE); 244 + } 245 + 246 + sa.sa_flags = SA_SIGINFO | SA_ONSTACK; 247 + sa.sa_sigaction = signal_handler; 248 + if (sigaction(SIGTRAP, &sa, NULL) == -1) { 249 + perror("sigaction() failed"); 250 + exit(EXIT_FAILURE); 251 + } 252 + 253 + /* Trigger a SIGTRAP in transactional state */ 254 + asm __volatile__( 255 + "tbegin.;" 256 + "beq 1f;" 257 + "trap;" 258 + "1: ;" 259 + : : : "memory"); 260 + 261 + /* Trigger a SIGTRAP in suspended state */ 262 + asm __volatile__( 263 + "tbegin.;" 264 + "beq 1f;" 265 + "tsuspend.;" 266 + "trap;" 267 + "tresume.;" 268 + "1: ;" 269 + : : : "memory"); 270 + 271 + return EXIT_SUCCESS; 272 + } 273 + 274 + int main(int argc, char **argv) 275 + { 276 + /* 277 + * Depending on kernel config, the TM Bad Thing might not result in a 278 + * crash, instead the kernel never returns control back to userspace, so 279 + * set a tight timeout. If the test passes it completes almost 280 + * immediately. 281 + */ 282 + test_harness_set_timeout(2); 283 + return test_harness(tm_signal_pagefault, "tm_signal_pagefault"); 284 + }