Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  Ptrace user space interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *    Copyright IBM Corp. 1999, 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *    Author(s): Denis Joseph Barrow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/audit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/regset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/seccomp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <trace/syscall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <asm/runtime_instr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include "entry.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include "compat_ptrace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <trace/events/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) void update_cr_regs(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	struct pt_regs *regs = task_pt_regs(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	struct thread_struct *thread = &task->thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	struct per_regs old, new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	union ctlreg0 cr0_old, cr0_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	union ctlreg2 cr2_old, cr2_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	int cr0_changed, cr2_changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	__ctl_store(cr0_old.val, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	__ctl_store(cr2_old.val, 2, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	cr0_new = cr0_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	cr2_new = cr2_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	/* Take care of the enable/disable of transactional execution. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	if (MACHINE_HAS_TE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 		/* Set or clear transaction execution TXC bit 8. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		cr0_new.tcx = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 		if (task->thread.per_flags & PER_FLAG_NO_TE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 			cr0_new.tcx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 		/* Set or clear transaction execution TDC bits 62 and 63. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		cr2_new.tdc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 		if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 			if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND_TEND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 				cr2_new.tdc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 				cr2_new.tdc = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	/* Take care of enable/disable of guarded storage. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	if (MACHINE_HAS_GS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 		cr2_new.gse = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		if (task->thread.gs_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 			cr2_new.gse = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	/* Load control register 0/2 iff changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	cr0_changed = cr0_new.val != cr0_old.val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	cr2_changed = cr2_new.val != cr2_old.val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	if (cr0_changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 		__ctl_load(cr0_new.val, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	if (cr2_changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 		__ctl_load(cr2_new.val, 2, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	/* Copy user specified PER registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	new.control = thread->per_user.control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	new.start = thread->per_user.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	new.end = thread->per_user.end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	/* merge TIF_SINGLE_STEP into user specified PER registers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	if (test_tsk_thread_flag(task, TIF_SINGLE_STEP) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	    test_tsk_thread_flag(task, TIF_UPROBE_SINGLESTEP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 		if (test_tsk_thread_flag(task, TIF_BLOCK_STEP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 			new.control |= PER_EVENT_BRANCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 			new.control |= PER_EVENT_IFETCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		new.control |= PER_CONTROL_SUSPENSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 		new.control |= PER_EVENT_TRANSACTION_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 		if (test_tsk_thread_flag(task, TIF_UPROBE_SINGLESTEP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 			new.control |= PER_EVENT_IFETCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		new.start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		new.end = -1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	/* Take care of the PER enablement bit in the PSW. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	if (!(new.control & PER_EVENT_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 		regs->psw.mask &= ~PSW_MASK_PER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	regs->psw.mask |= PSW_MASK_PER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	__ctl_store(old, 9, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 		__ctl_load(new, 9, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) void user_enable_single_step(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	set_tsk_thread_flag(task, TIF_SINGLE_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) void user_disable_single_step(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) void user_enable_block_step(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	set_tsk_thread_flag(task, TIF_SINGLE_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	set_tsk_thread_flag(task, TIF_BLOCK_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)  * Called by kernel/ptrace.c when detaching..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)  * Clear all debugging related fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) void ptrace_disable(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	memset(&task->thread.per_user, 0, sizeof(task->thread.per_user));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	memset(&task->thread.per_event, 0, sizeof(task->thread.per_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	clear_pt_regs_flag(task_pt_regs(task), PIF_PER_TRAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	task->thread.per_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) #define __ADDR_MASK 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) static inline unsigned long __peek_user_per(struct task_struct *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 					    addr_t addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	struct per_struct_kernel *dummy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	if (addr == (addr_t) &dummy->cr9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		/* Control bits of the active per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 		return test_thread_flag(TIF_SINGLE_STEP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 			PER_EVENT_IFETCH : child->thread.per_user.control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	else if (addr == (addr_t) &dummy->cr10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		/* Start address of the active per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 		return test_thread_flag(TIF_SINGLE_STEP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 			0 : child->thread.per_user.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	else if (addr == (addr_t) &dummy->cr11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		/* End address of the active per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		return test_thread_flag(TIF_SINGLE_STEP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 			-1UL : child->thread.per_user.end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	else if (addr == (addr_t) &dummy->bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		/* Single-step bit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		return test_thread_flag(TIF_SINGLE_STEP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 			(1UL << (BITS_PER_LONG - 1)) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	else if (addr == (addr_t) &dummy->starting_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		/* Start address of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		return child->thread.per_user.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	else if (addr == (addr_t) &dummy->ending_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		/* End address of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		return child->thread.per_user.end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	else if (addr == (addr_t) &dummy->perc_atmid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		/* PER code, ATMID and AI of the last PER trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		return (unsigned long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 			child->thread.per_event.cause << (BITS_PER_LONG - 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	else if (addr == (addr_t) &dummy->address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		/* Address of the last PER trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		return child->thread.per_event.address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	else if (addr == (addr_t) &dummy->access_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		/* Access id of the last PER trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		return (unsigned long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 			child->thread.per_event.paid << (BITS_PER_LONG - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  * Read the word at offset addr from the user area of a process. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)  * trouble here is that the information is littered over different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193)  * locations. The process registers are found on the kernel stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)  * the floating point stuff and the trace settings are stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)  * the task structure. In addition the different structures in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  * struct user contain pad bytes that should be read as zeroes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  * Lovely...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) static unsigned long __peek_user(struct task_struct *child, addr_t addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	struct user *dummy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	addr_t offset, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	if (addr < (addr_t) &dummy->regs.acrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		 * psw and gprs are stored on the stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		if (addr == (addr_t) &dummy->regs.psw.mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			/* Return a clean psw mask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 			tmp &= PSW_MASK_USER | PSW_MASK_RI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 			tmp |= PSW_USER_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	} else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		 * access registers are stored in the thread structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		offset = addr - (addr_t) &dummy->regs.acrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		 * Very special case: old & broken 64 bit gdb reading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		 * from acrs[15]. Result is a 64 bit value. Read the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		 * 32 bit acrs[15] value and shift it by 32. Sick...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		if (addr == (addr_t) &dummy->regs.acrs[15])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 			tmp = ((unsigned long) child->thread.acrs[15]) << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 			tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	} else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		 * orig_gpr2 is stored on the kernel stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	} else if (addr < (addr_t) &dummy->regs.fp_regs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		 * prevent reads of padding hole between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		 * orig_gpr2 and fp_regs on s390.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	} else if (addr == (addr_t) &dummy->regs.fp_regs.fpc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		 * floating point control reg. is in the thread structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		tmp = child->thread.fpu.fpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		tmp <<= BITS_PER_LONG - 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	} else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		 * floating point regs. are either in child->thread.fpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		 * or the child->thread.fpu.vxrs array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		offset = addr - (addr_t) &dummy->regs.fp_regs.fprs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		if (MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 			tmp = *(addr_t *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 			       ((addr_t) child->thread.fpu.vxrs + 2*offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 			tmp = *(addr_t *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 			       ((addr_t) child->thread.fpu.fprs + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	} else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		 * Handle access to the per_info structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		addr -= (addr_t) &dummy->regs.per_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		tmp = __peek_user_per(child, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	return tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) peek_user(struct task_struct *child, addr_t addr, addr_t data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	addr_t tmp, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	 * Stupid gdb peeks/pokes the access registers in 64 bit with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	 * an alignment of 4. Programmers from hell...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	mask = __ADDR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	    addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		mask = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	tmp = __peek_user(child, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	return put_user(tmp, (addr_t __user *) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) static inline void __poke_user_per(struct task_struct *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 				   addr_t addr, addr_t data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	struct per_struct_kernel *dummy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	 * There are only three fields in the per_info struct that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	 * debugger user can write to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	 * 1) cr9: the debugger wants to set a new PER event mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	 * 2) starting_addr: the debugger wants to set a new starting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	 *    address to use with the PER event mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	 * 3) ending_addr: the debugger wants to set a new ending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	 *    address to use with the PER event mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	 * The user specified PER event mask and the start and end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	 * addresses are used only if single stepping is not in effect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	 * Writes to any other field in per_info are ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	if (addr == (addr_t) &dummy->cr9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		/* PER event mask of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		child->thread.per_user.control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 			data & (PER_EVENT_MASK | PER_CONTROL_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	else if (addr == (addr_t) &dummy->starting_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		/* Starting address of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		child->thread.per_user.start = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	else if (addr == (addr_t) &dummy->ending_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		/* Ending address of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		child->thread.per_user.end = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) static void fixup_int_code(struct task_struct *child, addr_t data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	struct pt_regs *regs = task_pt_regs(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	int ilc = regs->int_code >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	u16 insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	if (ilc > 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	if (ptrace_access_vm(child, regs->psw.addr - (regs->int_code >> 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 			&insn, sizeof(insn), FOLL_FORCE) != sizeof(insn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	/* double check that tracee stopped on svc instruction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	if ((insn >> 8) != 0xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	regs->int_code = 0x20000 | (data & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345)  * Write a word to the user area of a process at location addr. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346)  * operation does have an additional problem compared to peek_user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347)  * Stores to the program status word and on the floating point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348)  * control register needs to get checked for validity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	struct user *dummy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	addr_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	if (addr < (addr_t) &dummy->regs.acrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		struct pt_regs *regs = task_pt_regs(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		 * psw and gprs are stored on the stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		if (addr == (addr_t) &dummy->regs.psw.mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			unsigned long mask = PSW_MASK_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			mask |= is_ri_task(child) ? PSW_MASK_RI : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			if ((data ^ PSW_USER_BITS) & ~mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 				/* Invalid psw mask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			if ((data & PSW_MASK_ASC) == PSW_ASC_HOME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 				/* Invalid address-space-control bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			if ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 				/* Invalid addressing mode bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		if (test_pt_regs_flag(regs, PIF_SYSCALL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 			addr == offsetof(struct user, regs.gprs[2]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			fixup_int_code(child, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		*(addr_t *)((addr_t) &regs->psw + addr) = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	} else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		 * access registers are stored in the thread structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		offset = addr - (addr_t) &dummy->regs.acrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		 * Very special case: old & broken 64 bit gdb writing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		 * to acrs[15] with a 64 bit value. Ignore the lower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		 * half of the value and write the upper 32 bit to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		 * acrs[15]. Sick...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		if (addr == (addr_t) &dummy->regs.acrs[15])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			child->thread.acrs[15] = (unsigned int) (data >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			*(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	} else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		 * orig_gpr2 is stored on the kernel stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		task_pt_regs(child)->orig_gpr2 = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	} else if (addr < (addr_t) &dummy->regs.fp_regs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		 * prevent writes of padding hole between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		 * orig_gpr2 and fp_regs on s390.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	} else if (addr == (addr_t) &dummy->regs.fp_regs.fpc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		 * floating point control reg. is in the thread structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		if ((unsigned int) data != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		    test_fp_ctl(data >> (BITS_PER_LONG - 32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		child->thread.fpu.fpc = data >> (BITS_PER_LONG - 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	} else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		 * floating point regs. are either in child->thread.fpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		 * or the child->thread.fpu.vxrs array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		offset = addr - (addr_t) &dummy->regs.fp_regs.fprs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		if (MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 			*(addr_t *)((addr_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 				child->thread.fpu.vxrs + 2*offset) = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 			*(addr_t *)((addr_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 				child->thread.fpu.fprs + offset) = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	} else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		 * Handle access to the per_info structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		addr -= (addr_t) &dummy->regs.per_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		__poke_user_per(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	addr_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	 * Stupid gdb peeks/pokes the access registers in 64 bit with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	 * an alignment of 4. Programmers from hell indeed...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	mask = __ADDR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	    addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		mask = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	return __poke_user(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) long arch_ptrace(struct task_struct *child, long request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		 unsigned long addr, unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	ptrace_area parea; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	int copied, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	switch (request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	case PTRACE_PEEKUSR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		/* read the word at location addr in the USER area. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		return peek_user(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	case PTRACE_POKEUSR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		/* write the word at location addr in the USER area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		return poke_user(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	case PTRACE_PEEKUSR_AREA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	case PTRACE_POKEUSR_AREA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		if (copy_from_user(&parea, (void __force __user *) addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 							sizeof(parea)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		addr = parea.kernel_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		data = parea.process_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		copied = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		while (copied < parea.len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			if (request == PTRACE_PEEKUSR_AREA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 				ret = peek_user(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 				addr_t utmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 				if (get_user(utmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 					     (addr_t __force __user *) data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 					return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 				ret = poke_user(child, addr, utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 			addr += sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			data += sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			copied += sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	case PTRACE_GET_LAST_BREAK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		put_user(child->thread.last_break,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 			 (unsigned long __user *) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	case PTRACE_ENABLE_TE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		if (!MACHINE_HAS_TE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		child->thread.per_flags &= ~PER_FLAG_NO_TE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	case PTRACE_DISABLE_TE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		if (!MACHINE_HAS_TE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		child->thread.per_flags |= PER_FLAG_NO_TE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	case PTRACE_TE_ABORT_RAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		switch (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		case 0UL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		case 1UL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 			child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		case 2UL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		return ptrace_request(child, request, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)  * Now the fun part starts... a 31 bit program running in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544)  * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545)  * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546)  * to handle, the difference to the 64 bit versions of the requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547)  * is that the access is done in multiples of 4 byte instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548)  * 8 bytes (sizeof(unsigned long) on 31/64 bit).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549)  * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550)  * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  * is a 31 bit program too, the content of struct user can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552)  * emulated. A 31 bit program peeking into the struct user of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553)  * a 64 bit program is a no-no.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557)  * Same as peek_user_per but for a 31 bit program.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) static inline __u32 __peek_user_per_compat(struct task_struct *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 					   addr_t addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	struct compat_per_struct_kernel *dummy32 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	if (addr == (addr_t) &dummy32->cr9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		/* Control bits of the active per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 			PER_EVENT_IFETCH : child->thread.per_user.control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	else if (addr == (addr_t) &dummy32->cr10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		/* Start address of the active per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 			0 : child->thread.per_user.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	else if (addr == (addr_t) &dummy32->cr11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		/* End address of the active per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		return test_thread_flag(TIF_SINGLE_STEP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 			PSW32_ADDR_INSN : child->thread.per_user.end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	else if (addr == (addr_t) &dummy32->bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		/* Single-step bit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			0x80000000 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	else if (addr == (addr_t) &dummy32->starting_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		/* Start address of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		return (__u32) child->thread.per_user.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	else if (addr == (addr_t) &dummy32->ending_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		/* End address of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		return (__u32) child->thread.per_user.end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	else if (addr == (addr_t) &dummy32->perc_atmid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		/* PER code, ATMID and AI of the last PER trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		return (__u32) child->thread.per_event.cause << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	else if (addr == (addr_t) &dummy32->address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		/* Address of the last PER trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		return (__u32) child->thread.per_event.address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	else if (addr == (addr_t) &dummy32->access_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		/* Access id of the last PER trap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		return (__u32) child->thread.per_event.paid << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599)  * Same as peek_user but for a 31 bit program.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	struct compat_user *dummy32 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	addr_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	__u32 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	if (addr < (addr_t) &dummy32->regs.acrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		struct pt_regs *regs = task_pt_regs(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		 * psw and gprs are stored on the stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		if (addr == (addr_t) &dummy32->regs.psw.mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			/* Fake a 31 bit psw mask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			tmp = (__u32)(regs->psw.mask >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			tmp &= PSW32_MASK_USER | PSW32_MASK_RI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			tmp |= PSW32_USER_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		} else if (addr == (addr_t) &dummy32->regs.psw.addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 			/* Fake a 31 bit psw address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 			tmp = (__u32) regs->psw.addr |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 				(__u32)(regs->psw.mask & PSW_MASK_BA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			/* gpr 0-15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 			tmp = *(__u32 *)((addr_t) &regs->psw + addr*2 + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	} else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		 * access registers are stored in the thread structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		offset = addr - (addr_t) &dummy32->regs.acrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	} else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		 * orig_gpr2 is stored on the kernel stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	} else if (addr < (addr_t) &dummy32->regs.fp_regs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		 * prevent reads of padding hole between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		 * orig_gpr2 and fp_regs on s390.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	} else if (addr == (addr_t) &dummy32->regs.fp_regs.fpc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		 * floating point control reg. is in the thread structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		tmp = child->thread.fpu.fpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	} else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		 * floating point regs. are either in child->thread.fpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		 * or the child->thread.fpu.vxrs array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		offset = addr - (addr_t) &dummy32->regs.fp_regs.fprs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		if (MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 			tmp = *(__u32 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			       ((addr_t) child->thread.fpu.vxrs + 2*offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 			tmp = *(__u32 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			       ((addr_t) child->thread.fpu.fprs + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	} else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		 * Handle access to the per_info structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		addr -= (addr_t) &dummy32->regs.per_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		tmp = __peek_user_per_compat(child, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	return tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) static int peek_user_compat(struct task_struct *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 			    addr_t addr, addr_t data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	__u32 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	tmp = __peek_user_compat(child, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	return put_user(tmp, (__u32 __user *) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690)  * Same as poke_user_per but for a 31 bit program.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) static inline void __poke_user_per_compat(struct task_struct *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 					  addr_t addr, __u32 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	struct compat_per_struct_kernel *dummy32 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	if (addr == (addr_t) &dummy32->cr9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		/* PER event mask of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		child->thread.per_user.control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			data & (PER_EVENT_MASK | PER_CONTROL_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	else if (addr == (addr_t) &dummy32->starting_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		/* Starting address of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		child->thread.per_user.start = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	else if (addr == (addr_t) &dummy32->ending_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		/* Ending address of the user specified per set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		child->thread.per_user.end = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710)  * Same as poke_user but for a 31 bit program.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) static int __poke_user_compat(struct task_struct *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 			      addr_t addr, addr_t data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	struct compat_user *dummy32 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	__u32 tmp = (__u32) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	addr_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	if (addr < (addr_t) &dummy32->regs.acrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		struct pt_regs *regs = task_pt_regs(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		 * psw, gprs, acrs and orig_gpr2 are stored on the stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		if (addr == (addr_t) &dummy32->regs.psw.mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 			__u32 mask = PSW32_MASK_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 			mask |= is_ri_task(child) ? PSW32_MASK_RI : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			/* Build a 64 bit psw mask from 31 bit mask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 			if ((tmp ^ PSW32_USER_BITS) & ~mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 				/* Invalid psw mask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 			if ((data & PSW32_MASK_ASC) == PSW32_ASC_HOME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 				/* Invalid address-space-control bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 				(regs->psw.mask & PSW_MASK_BA) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 				(__u64)(tmp & mask) << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		} else if (addr == (addr_t) &dummy32->regs.psw.addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 			/* Build a 64 bit psw address from 31 bit address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 			/* Transfer 31 bit amode bit to psw mask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 			regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 				(__u64)(tmp & PSW32_ADDR_AMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			if (test_pt_regs_flag(regs, PIF_SYSCALL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 				addr == offsetof(struct compat_user, regs.gprs[2]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 				fixup_int_code(child, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			/* gpr 0-15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 			*(__u32*)((addr_t) &regs->psw + addr*2 + 4) = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	} else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		 * access registers are stored in the thread structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		offset = addr - (addr_t) &dummy32->regs.acrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		*(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	} else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		 * orig_gpr2 is stored on the kernel stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		*(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	} else if (addr < (addr_t) &dummy32->regs.fp_regs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		 * prevent writess of padding hole between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		 * orig_gpr2 and fp_regs on s390.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	} else if (addr == (addr_t) &dummy32->regs.fp_regs.fpc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		 * floating point control reg. is in the thread structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		if (test_fp_ctl(tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		child->thread.fpu.fpc = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	} else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		 * floating point regs. are either in child->thread.fpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		 * or the child->thread.fpu.vxrs array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		offset = addr - (addr_t) &dummy32->regs.fp_regs.fprs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		if (MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			*(__u32 *)((addr_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 				child->thread.fpu.vxrs + 2*offset) = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			*(__u32 *)((addr_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 				child->thread.fpu.fprs + offset) = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	} else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		 * Handle access to the per_info structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		addr -= (addr_t) &dummy32->regs.per_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		__poke_user_per_compat(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) static int poke_user_compat(struct task_struct *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			    addr_t addr, addr_t data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	if (!is_compat_task() || (addr & 3) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	    addr > sizeof(struct compat_user) - 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	return __poke_user_compat(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			compat_ulong_t caddr, compat_ulong_t cdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	unsigned long addr = caddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	unsigned long data = cdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	compat_ptrace_area parea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	int copied, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	switch (request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	case PTRACE_PEEKUSR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		/* read the word at location addr in the USER area. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		return peek_user_compat(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	case PTRACE_POKEUSR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		/* write the word at location addr in the USER area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		return poke_user_compat(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	case PTRACE_PEEKUSR_AREA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	case PTRACE_POKEUSR_AREA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		if (copy_from_user(&parea, (void __force __user *) addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 							sizeof(parea)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		addr = parea.kernel_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		data = parea.process_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		copied = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		while (copied < parea.len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 			if (request == PTRACE_PEEKUSR_AREA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 				ret = peek_user_compat(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 				__u32 utmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 				if (get_user(utmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 					     (__u32 __force __user *) data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 					return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 				ret = poke_user_compat(child, addr, utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 			addr += sizeof(unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 			data += sizeof(unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 			copied += sizeof(unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	case PTRACE_GET_LAST_BREAK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		put_user(child->thread.last_break,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			 (unsigned int __user *) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	return compat_ptrace_request(child, request, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	unsigned long mask = -1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	long ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	if (is_compat_task())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		mask = 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	 * The sysc_tracesys code in entry.S stored the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	 * call number to gprs[2].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	if (test_thread_flag(TIF_SYSCALL_TRACE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	    tracehook_report_syscall_entry(regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		 * Tracing decided this syscall should not happen. Skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		 * the system call and the system call restart handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) #ifdef CONFIG_SECCOMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	/* Do the secure computing check after ptrace. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	if (unlikely(test_thread_flag(TIF_SECCOMP))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		struct seccomp_data sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		if (is_compat_task()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 			sd.instruction_pointer = regs->psw.addr & 0x7fffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 			sd.arch = AUDIT_ARCH_S390;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 			sd.instruction_pointer = regs->psw.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 			sd.arch = AUDIT_ARCH_S390X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		sd.nr = regs->int_code & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		sd.args[0] = regs->orig_gpr2 & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		sd.args[1] = regs->gprs[3] & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		sd.args[2] = regs->gprs[4] & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		sd.args[3] = regs->gprs[5] & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		sd.args[4] = regs->gprs[6] & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		sd.args[5] = regs->gprs[7] & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		if (__secure_computing(&sd) == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 			goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) #endif /* CONFIG_SECCOMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		trace_sys_enter(regs, regs->int_code & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	audit_syscall_entry(regs->int_code & 0xffff, regs->orig_gpr2 & mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 			    regs->gprs[3] &mask, regs->gprs[4] &mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 			    regs->gprs[5] &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	if ((signed long)regs->gprs[2] >= NR_syscalls) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		regs->gprs[2] = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		ret = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	return regs->gprs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) skip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	clear_pt_regs_flag(regs, PIF_SYSCALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	audit_syscall_exit(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		trace_sys_exit(regs, regs->gprs[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (test_thread_flag(TIF_SYSCALL_TRACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		tracehook_report_syscall_exit(regs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942)  * user_regset definitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) static int s390_regs_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 			 const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			 struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	unsigned pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		save_access_regs(target->thread.acrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	for (pos = 0; pos < sizeof(s390_regs); pos += sizeof(long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		membuf_store(&to, __peek_user(target, pos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) static int s390_regs_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 			 const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			 unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 			 const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		save_access_regs(target->thread.acrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	if (kbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		const unsigned long *k = kbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		while (count > 0 && !rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 			rc = __poke_user(target, pos, *k++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			count -= sizeof(*k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			pos += sizeof(*k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		const unsigned long  __user *u = ubuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		while (count > 0 && !rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 			unsigned long word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			rc = __get_user(word, u++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			rc = __poke_user(target, pos, word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			count -= sizeof(*u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 			pos += sizeof(*u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	if (rc == 0 && target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		restore_access_regs(target->thread.acrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) static int s390_fpregs_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 			   const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			   struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	_s390_fp_regs fp_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		save_fpu_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	fp_regs.fpc = target->thread.fpu.fpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	fpregs_store(&fp_regs, &target->thread.fpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	return membuf_write(&to, &fp_regs, sizeof(fp_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) static int s390_fpregs_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 			   const struct user_regset *regset, unsigned int pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 			   unsigned int count, const void *kbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 			   const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	freg_t fprs[__NUM_FPRS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		save_fpu_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	if (MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		convert_vx_to_fp(fprs, target->thread.fpu.vxrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		memcpy(&fprs, target->thread.fpu.fprs, sizeof(fprs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	/* If setting FPC, must validate it first. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		u32 ufpc[2] = { target->thread.fpu.fpc, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 					0, offsetof(s390_fp_regs, fprs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		if (ufpc[1] != 0 || test_fp_ctl(ufpc[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		target->thread.fpu.fpc = ufpc[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	if (rc == 0 && count > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 					fprs, offsetof(s390_fp_regs, fprs), -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	if (MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		convert_fp_to_vx(target->thread.fpu.vxrs, fprs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		memcpy(target->thread.fpu.fprs, &fprs, sizeof(fprs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) static int s390_last_break_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 			       const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 			       struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	return membuf_store(&to, target->thread.last_break);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) static int s390_last_break_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 			       const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 			       unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 			       const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) static int s390_tdb_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 			const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 			struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	struct pt_regs *regs = task_pt_regs(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	if (!(regs->int_code & 0x200))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	return membuf_write(&to, target->thread.trap_tdb, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) static int s390_tdb_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 			const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 			unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 			const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) static int s390_vxrs_low_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 			     const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			     struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	__u64 vxrs[__NUM_VXRS_LOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	if (!MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		save_fpu_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	for (i = 0; i < __NUM_VXRS_LOW; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		vxrs[i] = *((__u64 *)(target->thread.fpu.vxrs + i) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	return membuf_write(&to, vxrs, sizeof(vxrs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static int s390_vxrs_low_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			     const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			     unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			     const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	__u64 vxrs[__NUM_VXRS_LOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	if (!MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		save_fpu_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	for (i = 0; i < __NUM_VXRS_LOW; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		vxrs[i] = *((__u64 *)(target->thread.fpu.vxrs + i) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		for (i = 0; i < __NUM_VXRS_LOW; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 			*((__u64 *)(target->thread.fpu.vxrs + i) + 1) = vxrs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static int s390_vxrs_high_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 			      const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 			      struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	if (!MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		save_fpu_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	return membuf_write(&to, target->thread.fpu.vxrs + __NUM_VXRS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 			    __NUM_VXRS_HIGH * sizeof(__vector128));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) static int s390_vxrs_high_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 			      const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 			      unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 			      const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	if (!MACHINE_HAS_VX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		save_fpu_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 				target->thread.fpu.vxrs + __NUM_VXRS_LOW, 0, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) static int s390_system_call_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 				const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 				struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	return membuf_store(&to, target->thread.system_call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) static int s390_system_call_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 				const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 				unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 				const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	unsigned int *data = &target->thread.system_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 				  data, 0, sizeof(unsigned int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) static int s390_gs_cb_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 			  const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 			  struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	struct gs_cb *data = target->thread.gs_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	if (!MACHINE_HAS_GS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 		save_gs_cb(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	return membuf_write(&to, data, sizeof(struct gs_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) static int s390_gs_cb_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			  const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 			  unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 			  const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	struct gs_cb gs_cb = { }, *data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	if (!MACHINE_HAS_GS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	if (!target->thread.gs_cb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 		if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	if (!target->thread.gs_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 		gs_cb.gsd = 25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	else if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		save_gs_cb(&gs_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		gs_cb = *target->thread.gs_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 				&gs_cb, 0, sizeof(gs_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	if (!target->thread.gs_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		target->thread.gs_cb = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	*target->thread.gs_cb = gs_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	if (target == current) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		__ctl_set_bit(2, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		restore_gs_cb(target->thread.gs_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) static int s390_gs_bc_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 			  const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 			  struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	struct gs_cb *data = target->thread.gs_bc_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	if (!MACHINE_HAS_GS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	return membuf_write(&to, data, sizeof(struct gs_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) static int s390_gs_bc_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 			  const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 			  unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 			  const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	struct gs_cb *data = target->thread.gs_bc_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	if (!MACHINE_HAS_GS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		target->thread.gs_bc_cb = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 				  data, 0, sizeof(struct gs_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) static bool is_ri_cb_valid(struct runtime_instr_cb *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	return (cb->rca & 0x1f) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		(cb->roa & 0xfff) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 		(cb->rla & 0xfff) == 0xfff &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		cb->s == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		cb->k == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		cb->h == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 		cb->reserved1 == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 		cb->ps == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		cb->qs == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		cb->pc == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		cb->qc == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 		cb->reserved2 == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		cb->reserved3 == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		cb->reserved4 == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		cb->reserved5 == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		cb->reserved6 == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		cb->reserved7 == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		cb->reserved8 == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		cb->rla >= cb->roa &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		cb->rca >= cb->roa &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		cb->rca <= cb->rla+1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		cb->m < 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) static int s390_runtime_instr_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 				const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 				struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	struct runtime_instr_cb *data = target->thread.ri_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	if (!test_facility(64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 		return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	return membuf_write(&to, data, sizeof(struct runtime_instr_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) static int s390_runtime_instr_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 				  const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 				  unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 				  const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	struct runtime_instr_cb ri_cb = { }, *data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	if (!test_facility(64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	if (!target->thread.ri_cb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	if (target->thread.ri_cb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 			store_runtime_instr_cb(&ri_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			ri_cb = *target->thread.ri_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 				&ri_cb, 0, sizeof(struct runtime_instr_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	if (!is_ri_cb_valid(&ri_cb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	 * Override access key in any case, since user space should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	 * not be able to set it, nor should it care about it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	ri_cb.key = PAGE_DEFAULT_KEY >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	if (!target->thread.ri_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		target->thread.ri_cb = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	*target->thread.ri_cb = ri_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		load_runtime_instr_cb(target->thread.ri_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) static const struct user_regset s390_regsets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		.core_note_type = NT_PRSTATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		.n = sizeof(s390_regs) / sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		.size = sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		.align = sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		.regset_get = s390_regs_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		.set = s390_regs_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		.core_note_type = NT_PRFPREG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		.n = sizeof(s390_fp_regs) / sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		.size = sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		.align = sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		.regset_get = s390_fpregs_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		.set = s390_fpregs_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		.core_note_type = NT_S390_SYSTEM_CALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		.n = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		.size = sizeof(unsigned int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		.align = sizeof(unsigned int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		.regset_get = s390_system_call_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		.set = s390_system_call_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		.core_note_type = NT_S390_LAST_BREAK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 		.n = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		.size = sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		.align = sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 		.regset_get = s390_last_break_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 		.set = s390_last_break_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		.core_note_type = NT_S390_TDB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		.n = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		.size = 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		.align = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 		.regset_get = s390_tdb_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 		.set = s390_tdb_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		.core_note_type = NT_S390_VXRS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		.n = __NUM_VXRS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		.size = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		.align = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		.regset_get = s390_vxrs_low_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 		.set = s390_vxrs_low_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		.core_note_type = NT_S390_VXRS_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 		.n = __NUM_VXRS_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		.size = sizeof(__vector128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		.align = sizeof(__vector128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		.regset_get = s390_vxrs_high_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		.set = s390_vxrs_high_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		.core_note_type = NT_S390_GS_CB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		.n = sizeof(struct gs_cb) / sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		.size = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		.align = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		.regset_get = s390_gs_cb_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		.set = s390_gs_cb_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		.core_note_type = NT_S390_GS_BC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		.n = sizeof(struct gs_cb) / sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		.size = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		.align = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		.regset_get = s390_gs_bc_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 		.set = s390_gs_bc_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		.core_note_type = NT_S390_RI_CB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 		.n = sizeof(struct runtime_instr_cb) / sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		.size = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 		.align = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 		.regset_get = s390_runtime_instr_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		.set = s390_runtime_instr_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) static const struct user_regset_view user_s390_view = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	.name = "s390x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	.e_machine = EM_S390,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	.regsets = s390_regsets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	.n = ARRAY_SIZE(s390_regsets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) static int s390_compat_regs_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 				const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 				struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	unsigned n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		save_access_regs(target->thread.acrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	for (n = 0; n < sizeof(s390_compat_regs); n += sizeof(compat_ulong_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		membuf_store(&to, __peek_user_compat(target, n));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) static int s390_compat_regs_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 				const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 				unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 				const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		save_access_regs(target->thread.acrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	if (kbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 		const compat_ulong_t *k = kbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		while (count > 0 && !rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 			rc = __poke_user_compat(target, pos, *k++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 			count -= sizeof(*k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 			pos += sizeof(*k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		const compat_ulong_t  __user *u = ubuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		while (count > 0 && !rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 			compat_ulong_t word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 			rc = __get_user(word, u++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 			rc = __poke_user_compat(target, pos, word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			count -= sizeof(*u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 			pos += sizeof(*u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	if (rc == 0 && target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		restore_access_regs(target->thread.acrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) static int s390_compat_regs_high_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 				     const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 				     struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	compat_ulong_t *gprs_high;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	gprs_high = (compat_ulong_t *)task_pt_regs(target)->gprs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	for (i = 0; i < NUM_GPRS; i++, gprs_high += 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 		membuf_store(&to, *gprs_high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) static int s390_compat_regs_high_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 				     const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 				     unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 				     const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	compat_ulong_t *gprs_high;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	gprs_high = (compat_ulong_t *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		&task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	if (kbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 		const compat_ulong_t *k = kbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		while (count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 			*gprs_high = *k++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 			*gprs_high += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 			count -= sizeof(*k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		const compat_ulong_t  __user *u = ubuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		while (count > 0 && !rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 			unsigned long word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 			rc = __get_user(word, u++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 			*gprs_high = word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 			*gprs_high += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 			count -= sizeof(*u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) static int s390_compat_last_break_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 				      const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 				      struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	compat_ulong_t last_break = target->thread.last_break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	return membuf_store(&to, (unsigned long)last_break);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) static int s390_compat_last_break_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 				      const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 				      unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 				      const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) static const struct user_regset s390_compat_regsets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		.core_note_type = NT_PRSTATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		.n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 		.size = sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		.align = sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 		.regset_get = s390_compat_regs_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 		.set = s390_compat_regs_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		.core_note_type = NT_PRFPREG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 		.n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		.size = sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		.align = sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		.regset_get = s390_fpregs_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		.set = s390_fpregs_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		.core_note_type = NT_S390_SYSTEM_CALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		.n = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 		.size = sizeof(compat_uint_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		.align = sizeof(compat_uint_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		.regset_get = s390_system_call_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		.set = s390_system_call_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		.core_note_type = NT_S390_LAST_BREAK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 		.n = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 		.size = sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		.align = sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		.regset_get = s390_compat_last_break_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 		.set = s390_compat_last_break_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 		.core_note_type = NT_S390_TDB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		.n = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 		.size = 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		.align = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		.regset_get = s390_tdb_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		.set = s390_tdb_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		.core_note_type = NT_S390_VXRS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 		.n = __NUM_VXRS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 		.size = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 		.align = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		.regset_get = s390_vxrs_low_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		.set = s390_vxrs_low_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		.core_note_type = NT_S390_VXRS_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 		.n = __NUM_VXRS_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		.size = sizeof(__vector128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 		.align = sizeof(__vector128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		.regset_get = s390_vxrs_high_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 		.set = s390_vxrs_high_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 		.core_note_type = NT_S390_HIGH_GPRS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 		.n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 		.size = sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 		.align = sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		.regset_get = s390_compat_regs_high_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 		.set = s390_compat_regs_high_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		.core_note_type = NT_S390_GS_CB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 		.n = sizeof(struct gs_cb) / sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		.size = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 		.align = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 		.regset_get = s390_gs_cb_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		.set = s390_gs_cb_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 		.core_note_type = NT_S390_GS_BC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 		.n = sizeof(struct gs_cb) / sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 		.size = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 		.align = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 		.regset_get = s390_gs_bc_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 		.set = s390_gs_bc_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 		.core_note_type = NT_S390_RI_CB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 		.n = sizeof(struct runtime_instr_cb) / sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 		.size = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 		.align = sizeof(__u64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 		.regset_get = s390_runtime_instr_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 		.set = s390_runtime_instr_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) static const struct user_regset_view user_s390_compat_view = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	.name = "s390",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	.e_machine = EM_S390,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	.regsets = s390_compat_regsets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	.n = ARRAY_SIZE(s390_compat_regsets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) const struct user_regset_view *task_user_regset_view(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	if (test_tsk_thread_flag(task, TIF_31BIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		return &user_s390_compat_view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	return &user_s390_view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) static const char *gpr_names[NUM_GPRS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	"r0", "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	if (offset >= NUM_GPRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	return regs->gprs[offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) int regs_query_register_offset(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	unsigned long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	if (!name || *name != 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	if (kstrtoul(name + 1, 10, &offset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	if (offset >= NUM_GPRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) const char *regs_query_register_name(unsigned int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	if (offset >= NUM_GPRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	return gpr_names[offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	unsigned long ksp = kernel_stack_pointer(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)  * regs_get_kernel_stack_nth() - get Nth entry of the stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)  * @regs:pt_regs which contains kernel stack pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)  * @n:stack entry number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)  * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)  * this returns 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	addr = kernel_stack_pointer(regs) + n * sizeof(long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	if (!regs_within_kernel_stack(regs, addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	return *(unsigned long *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) }