Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  Standard user space access functions based on mvcp/mvcs and doing
  4 *  interesting things in the secondary space mode.
  5 *
  6 *    Copyright IBM Corp. 2006,2014
  7 *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  8 *		 Gerald Schaefer (gerald.schaefer@de.ibm.com)
  9 */
 10
 11#include <linux/uaccess.h>
 12#include <linux/export.h>
 13#include <linux/mm.h>
 14#include <asm/asm-extable.h>
 15#include <asm/ctlreg.h>
 16
 17#ifdef CONFIG_DEBUG_ENTRY
 18void debug_user_asce(int exit)
 19{
 20	struct ctlreg cr1, cr7;
 21
 22	local_ctl_store(1, &cr1);
 23	local_ctl_store(7, &cr7);
 24	if (cr1.val == get_lowcore()->kernel_asce.val && cr7.val == get_lowcore()->user_asce.val)
 25		return;
 26	panic("incorrect ASCE on kernel %s\n"
 27	      "cr1:    %016lx cr7:  %016lx\n"
 28	      "kernel: %016lx user: %016lx\n",
 29	      exit ? "exit" : "entry", cr1.val, cr7.val,
 30	      get_lowcore()->kernel_asce.val, get_lowcore()->user_asce.val);
 
 31}
 32#endif /*CONFIG_DEBUG_ENTRY */
 33
 34static unsigned long raw_copy_from_user_key(void *to, const void __user *from,
 35					    unsigned long size, unsigned long key)
 36{
 37	unsigned long rem;
 38	union oac spec = {
 39		.oac2.key = key,
 40		.oac2.as = PSW_BITS_AS_SECONDARY,
 41		.oac2.k = 1,
 42		.oac2.a = 1,
 43	};
 44
 
 45	asm volatile(
 46		"	lr	0,%[spec]\n"
 47		"0:	mvcos	0(%[to]),0(%[from]),%[size]\n"
 48		"1:	jz	5f\n"
 49		"	algr	%[size],%[val]\n"
 50		"	slgr	%[from],%[val]\n"
 51		"	slgr	%[to],%[val]\n"
 52		"	j	0b\n"
 53		"2:	la	%[rem],4095(%[from])\n"	/* rem = from + 4095 */
 54		"	nr	%[rem],%[val]\n"	/* rem = (from + 4095) & -4096 */
 55		"	slgr	%[rem],%[from]\n"
 56		"	clgr	%[size],%[rem]\n"	/* copy crosses next page boundary? */
 57		"	jnh	6f\n"
 58		"3:	mvcos	0(%[to]),0(%[from]),%[rem]\n"
 59		"4:	slgr	%[size],%[rem]\n"
 60		"	j	6f\n"
 61		"5:	slgr	%[size],%[size]\n"
 62		"6:\n"
 63		EX_TABLE(0b, 2b)
 64		EX_TABLE(1b, 2b)
 65		EX_TABLE(3b, 6b)
 66		EX_TABLE(4b, 6b)
 67		: [size] "+&a" (size), [from] "+&a" (from), [to] "+&a" (to), [rem] "=&a" (rem)
 68		: [val] "a" (-4096UL), [spec] "d" (spec.val)
 69		: "cc", "memory", "0");
 70	return size;
 71}
 72
 73unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n)
 74{
 75	return raw_copy_from_user_key(to, from, n, 0);
 76}
 77EXPORT_SYMBOL(raw_copy_from_user);
 78
 79unsigned long _copy_from_user_key(void *to, const void __user *from,
 80				  unsigned long n, unsigned long key)
 81{
 82	unsigned long res = n;
 83
 84	might_fault();
 85	if (!should_fail_usercopy()) {
 86		instrument_copy_from_user_before(to, from, n);
 87		res = raw_copy_from_user_key(to, from, n, key);
 88		instrument_copy_from_user_after(to, from, n, res);
 89	}
 90	if (unlikely(res))
 91		memset(to + (n - res), 0, res);
 92	return res;
 93}
 94EXPORT_SYMBOL(_copy_from_user_key);
 95
 96static unsigned long raw_copy_to_user_key(void __user *to, const void *from,
 97					  unsigned long size, unsigned long key)
 98{
 99	unsigned long rem;
100	union oac spec = {
101		.oac1.key = key,
102		.oac1.as = PSW_BITS_AS_SECONDARY,
103		.oac1.k = 1,
104		.oac1.a = 1,
105	};
106
 
107	asm volatile(
108		"	lr	0,%[spec]\n"
109		"0:	mvcos	0(%[to]),0(%[from]),%[size]\n"
110		"1:	jz	5f\n"
111		"	algr	%[size],%[val]\n"
112		"	slgr	%[to],%[val]\n"
113		"	slgr	%[from],%[val]\n"
114		"	j	0b\n"
115		"2:	la	%[rem],4095(%[to])\n"	/* rem = to + 4095 */
116		"	nr	%[rem],%[val]\n"	/* rem = (to + 4095) & -4096 */
117		"	slgr	%[rem],%[to]\n"
118		"	clgr	%[size],%[rem]\n"	/* copy crosses next page boundary? */
119		"	jnh	6f\n"
120		"3:	mvcos	0(%[to]),0(%[from]),%[rem]\n"
121		"4:	slgr	%[size],%[rem]\n"
122		"	j	6f\n"
123		"5:	slgr	%[size],%[size]\n"
124		"6:\n"
125		EX_TABLE(0b, 2b)
126		EX_TABLE(1b, 2b)
127		EX_TABLE(3b, 6b)
128		EX_TABLE(4b, 6b)
129		: [size] "+&a" (size), [to] "+&a" (to), [from] "+&a" (from), [rem] "=&a" (rem)
130		: [val] "a" (-4096UL), [spec] "d" (spec.val)
131		: "cc", "memory", "0");
132	return size;
133}
134
135unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n)
136{
137	return raw_copy_to_user_key(to, from, n, 0);
138}
139EXPORT_SYMBOL(raw_copy_to_user);
140
141unsigned long _copy_to_user_key(void __user *to, const void *from,
142				unsigned long n, unsigned long key)
143{
144	might_fault();
145	if (should_fail_usercopy())
146		return n;
147	instrument_copy_to_user(to, from, n);
148	return raw_copy_to_user_key(to, from, n, key);
149}
150EXPORT_SYMBOL(_copy_to_user_key);
151
152unsigned long __clear_user(void __user *to, unsigned long size)
153{
154	unsigned long rem;
155	union oac spec = {
156		.oac1.as = PSW_BITS_AS_SECONDARY,
157		.oac1.a = 1,
158	};
159
 
160	asm volatile(
161		"	lr	0,%[spec]\n"
162		"0:	mvcos	0(%[to]),0(%[zeropg]),%[size]\n"
163		"1:	jz	5f\n"
164		"	algr	%[size],%[val]\n"
165		"	slgr	%[to],%[val]\n"
166		"	j	0b\n"
167		"2:	la	%[rem],4095(%[to])\n"	/* rem = to + 4095 */
168		"	nr	%[rem],%[val]\n"	/* rem = (to + 4095) & -4096 */
169		"	slgr	%[rem],%[to]\n"
170		"	clgr	%[size],%[rem]\n"	/* copy crosses next page boundary? */
171		"	jnh	6f\n"
172		"3:	mvcos	0(%[to]),0(%[zeropg]),%[rem]\n"
173		"4:	slgr	%[size],%[rem]\n"
174		"	j	6f\n"
175		"5:	slgr	%[size],%[size]\n"
176		"6:\n"
177		EX_TABLE(0b, 2b)
178		EX_TABLE(1b, 2b)
179		EX_TABLE(3b, 6b)
180		EX_TABLE(4b, 6b)
181		: [size] "+&a" (size), [to] "+&a" (to), [rem] "=&a" (rem)
182		: [val] "a" (-4096UL), [zeropg] "a" (empty_zero_page), [spec] "d" (spec.val)
183		: "cc", "memory", "0");
184	return size;
185}
186EXPORT_SYMBOL(__clear_user);
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  Standard user space access functions based on mvcp/mvcs and doing
  4 *  interesting things in the secondary space mode.
  5 *
  6 *    Copyright IBM Corp. 2006,2014
  7 *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  8 *		 Gerald Schaefer (gerald.schaefer@de.ibm.com)
  9 */
 10
 11#include <linux/uaccess.h>
 12#include <linux/export.h>
 13#include <linux/mm.h>
 14#include <asm/asm-extable.h>
 
 15
 16#ifdef CONFIG_DEBUG_ENTRY
 17void debug_user_asce(int exit)
 18{
 19	unsigned long cr1, cr7;
 20
 21	__ctl_store(cr1, 1, 1);
 22	__ctl_store(cr7, 7, 7);
 23	if (cr1 == S390_lowcore.kernel_asce && cr7 == S390_lowcore.user_asce)
 24		return;
 25	panic("incorrect ASCE on kernel %s\n"
 26	      "cr1:    %016lx cr7:  %016lx\n"
 27	      "kernel: %016llx user: %016llx\n",
 28	      exit ? "exit" : "entry", cr1, cr7,
 29	      S390_lowcore.kernel_asce, S390_lowcore.user_asce);
 30
 31}
 32#endif /*CONFIG_DEBUG_ENTRY */
 33
 34static unsigned long raw_copy_from_user_key(void *to, const void __user *from,
 35					    unsigned long size, unsigned long key)
 36{
 37	unsigned long tmp1, tmp2;
 38	union oac spec = {
 39		.oac2.key = key,
 40		.oac2.as = PSW_BITS_AS_SECONDARY,
 41		.oac2.k = 1,
 42		.oac2.a = 1,
 43	};
 44
 45	tmp1 = -4096UL;
 46	asm volatile(
 47		"   lr	  0,%[spec]\n"
 48		"0: mvcos 0(%2),0(%1),%0\n"
 49		"6: jz    4f\n"
 50		"1: algr  %0,%3\n"
 51		"   slgr  %1,%3\n"
 52		"   slgr  %2,%3\n"
 53		"   j     0b\n"
 54		"2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
 55		"   nr    %4,%3\n"	/* %4 = (ptr + 4095) & -4096 */
 56		"   slgr  %4,%1\n"
 57		"   clgr  %0,%4\n"	/* copy crosses next page boundary? */
 58		"   jnh   5f\n"
 59		"3: mvcos 0(%2),0(%1),%4\n"
 60		"7: slgr  %0,%4\n"
 61		"   j     5f\n"
 62		"4: slgr  %0,%0\n"
 63		"5:\n"
 64		EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
 65		: "+a" (size), "+a" (from), "+a" (to), "+a" (tmp1), "=a" (tmp2)
 66		: [spec] "d" (spec.val)
 
 
 
 67		: "cc", "memory", "0");
 68	return size;
 69}
 70
 71unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n)
 72{
 73	return raw_copy_from_user_key(to, from, n, 0);
 74}
 75EXPORT_SYMBOL(raw_copy_from_user);
 76
 77unsigned long _copy_from_user_key(void *to, const void __user *from,
 78				  unsigned long n, unsigned long key)
 79{
 80	unsigned long res = n;
 81
 82	might_fault();
 83	if (!should_fail_usercopy()) {
 84		instrument_copy_from_user_before(to, from, n);
 85		res = raw_copy_from_user_key(to, from, n, key);
 86		instrument_copy_from_user_after(to, from, n, res);
 87	}
 88	if (unlikely(res))
 89		memset(to + (n - res), 0, res);
 90	return res;
 91}
 92EXPORT_SYMBOL(_copy_from_user_key);
 93
 94static unsigned long raw_copy_to_user_key(void __user *to, const void *from,
 95					  unsigned long size, unsigned long key)
 96{
 97	unsigned long tmp1, tmp2;
 98	union oac spec = {
 99		.oac1.key = key,
100		.oac1.as = PSW_BITS_AS_SECONDARY,
101		.oac1.k = 1,
102		.oac1.a = 1,
103	};
104
105	tmp1 = -4096UL;
106	asm volatile(
107		"   lr	  0,%[spec]\n"
108		"0: mvcos 0(%1),0(%2),%0\n"
109		"6: jz    4f\n"
110		"1: algr  %0,%3\n"
111		"   slgr  %1,%3\n"
112		"   slgr  %2,%3\n"
113		"   j     0b\n"
114		"2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
115		"   nr    %4,%3\n"	/* %4 = (ptr + 4095) & -4096 */
116		"   slgr  %4,%1\n"
117		"   clgr  %0,%4\n"	/* copy crosses next page boundary? */
118		"   jnh   5f\n"
119		"3: mvcos 0(%1),0(%2),%4\n"
120		"7: slgr  %0,%4\n"
121		"   j     5f\n"
122		"4: slgr  %0,%0\n"
123		"5:\n"
124		EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
125		: "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
126		: [spec] "d" (spec.val)
 
 
 
127		: "cc", "memory", "0");
128	return size;
129}
130
131unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n)
132{
133	return raw_copy_to_user_key(to, from, n, 0);
134}
135EXPORT_SYMBOL(raw_copy_to_user);
136
137unsigned long _copy_to_user_key(void __user *to, const void *from,
138				unsigned long n, unsigned long key)
139{
140	might_fault();
141	if (should_fail_usercopy())
142		return n;
143	instrument_copy_to_user(to, from, n);
144	return raw_copy_to_user_key(to, from, n, key);
145}
146EXPORT_SYMBOL(_copy_to_user_key);
147
148unsigned long __clear_user(void __user *to, unsigned long size)
149{
150	unsigned long tmp1, tmp2;
151	union oac spec = {
152		.oac1.as = PSW_BITS_AS_SECONDARY,
153		.oac1.a = 1,
154	};
155
156	tmp1 = -4096UL;
157	asm volatile(
158		"   lr	  0,%[spec]\n"
159		"0: mvcos 0(%1),0(%4),%0\n"
160		"6: jz	  4f\n"
161		"1: algr  %0,%2\n"
162		"   slgr  %1,%2\n"
163		"   j	  0b\n"
164		"2: la	  %3,4095(%1)\n"/* %4 = to + 4095 */
165		"   nr	  %3,%2\n"	/* %4 = (to + 4095) & -4096 */
166		"   slgr  %3,%1\n"
167		"   clgr  %0,%3\n"	/* copy crosses next page boundary? */
168		"   jnh	  5f\n"
169		"3: mvcos 0(%1),0(%4),%3\n"
170		"7: slgr  %0,%3\n"
171		"   j	  5f\n"
172		"4: slgr  %0,%0\n"
173		"5:\n"
174		EX_TABLE(0b,2b) EX_TABLE(6b,2b) EX_TABLE(3b,5b) EX_TABLE(7b,5b)
175		: "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2)
176		: "a" (empty_zero_page), [spec] "d" (spec.val)
 
 
 
177		: "cc", "memory", "0");
178	return size;
179}
180EXPORT_SYMBOL(__clear_user);