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)  *  Standard user space access functions based on mvcp/mvcs and doing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  interesting things in the secondary space mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *    Copyright IBM Corp. 2006,2014
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *		 Gerald Schaefer (gerald.schaefer@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/jump_label.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #ifndef CONFIG_HAVE_MARCH_Z10_FEATURES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static DEFINE_STATIC_KEY_FALSE(have_mvcos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static int __init uaccess_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (test_facility(27))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		static_branch_enable(&have_mvcos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) early_initcall(uaccess_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static inline int copy_with_mvcos(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (static_branch_likely(&have_mvcos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static inline int copy_with_mvcos(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) void set_fs(mm_segment_t fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	current->thread.mm_segment = fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (fs == USER_DS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		__ctl_load(S390_lowcore.user_asce, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		clear_cpu_flag(CIF_ASCE_PRIMARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		__ctl_load(S390_lowcore.kernel_asce, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		set_cpu_flag(CIF_ASCE_PRIMARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (fs & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		if (fs == USER_DS_SACF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			__ctl_load(S390_lowcore.user_asce, 7, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			__ctl_load(S390_lowcore.kernel_asce, 7, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		set_cpu_flag(CIF_ASCE_SECONDARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) EXPORT_SYMBOL(set_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) mm_segment_t enable_sacf_uaccess(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	mm_segment_t old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned long asce, cr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	old_fs = current->thread.mm_segment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (old_fs & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* protect against a concurrent page table upgrade */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	current->thread.mm_segment |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	asce = S390_lowcore.kernel_asce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (likely(old_fs == USER_DS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		__ctl_store(cr, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		if (cr != S390_lowcore.kernel_asce) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			__ctl_load(S390_lowcore.kernel_asce, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			set_cpu_flag(CIF_ASCE_PRIMARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		asce = S390_lowcore.user_asce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	__ctl_store(cr, 7, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (cr != asce) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		__ctl_load(asce, 7, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		set_cpu_flag(CIF_ASCE_SECONDARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) EXPORT_SYMBOL(enable_sacf_uaccess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) void disable_sacf_uaccess(mm_segment_t old_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	current->thread.mm_segment = old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (old_fs == USER_DS && test_facility(27)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		__ctl_load(S390_lowcore.user_asce, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		clear_cpu_flag(CIF_ASCE_PRIMARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) EXPORT_SYMBOL(disable_sacf_uaccess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 						 unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	register unsigned long reg0 asm("0") = 0x01UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	unsigned long tmp1, tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	tmp1 = -4096UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		"0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		"6: jz    4f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		"1: algr  %0,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		"   slgr  %1,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		"   slgr  %2,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		"   j     0b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		"2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		"   nr    %4,%3\n"	/* %4 = (ptr + 4095) & -4096 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		"   slgr  %4,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		"   clgr  %0,%4\n"	/* copy crosses next page boundary? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		"   jnh   5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		"3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		"7: slgr  %0,%4\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		"   j     5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		"4: slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		"5:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		: "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		: "d" (reg0) : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return size;
^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) static inline unsigned long copy_from_user_mvcp(void *x, const void __user *ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 						unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	unsigned long tmp1, tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	mm_segment_t old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	old_fs = enable_sacf_uaccess();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	tmp1 = -256UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		"   sacf  0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		"0: mvcp  0(%0,%2),0(%1),%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		"7: jz    5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		"1: algr  %0,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		"   la    %1,256(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		"   la    %2,256(%2)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		"2: mvcp  0(%0,%2),0(%1),%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		"8: jnz   1b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		"   j     5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		"3: la    %4,255(%1)\n"	/* %4 = ptr + 255 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		"   lghi  %3,-4096\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		"   nr    %4,%3\n"	/* %4 = (ptr + 255) & -4096 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		"   slgr  %4,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		"   clgr  %0,%4\n"	/* copy crosses next page boundary? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		"   jnh   6f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		"4: mvcp  0(%4,%2),0(%1),%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		"9: slgr  %0,%4\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		"   j     6f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		"5: slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		"6: sacf  768\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		EX_TABLE(7b,3b) EX_TABLE(8b,3b) EX_TABLE(9b,6b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		: "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		: : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	disable_sacf_uaccess(old_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (copy_with_mvcos())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return copy_from_user_mvcos(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return copy_from_user_mvcp(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) EXPORT_SYMBOL(raw_copy_from_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 					       unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	register unsigned long reg0 asm("0") = 0x010000UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	unsigned long tmp1, tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	tmp1 = -4096UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		"0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		"6: jz    4f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		"1: algr  %0,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		"   slgr  %1,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		"   slgr  %2,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		"   j     0b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		"2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		"   nr    %4,%3\n"	/* %4 = (ptr + 4095) & -4096 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		"   slgr  %4,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		"   clgr  %0,%4\n"	/* copy crosses next page boundary? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		"   jnh   5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		"3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		"7: slgr  %0,%4\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		"   j     5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		"4: slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		"5:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		: "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		: "d" (reg0) : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static inline unsigned long copy_to_user_mvcs(void __user *ptr, const void *x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 					      unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	unsigned long tmp1, tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	mm_segment_t old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	old_fs = enable_sacf_uaccess();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	tmp1 = -256UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		"   sacf  0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		"0: mvcs  0(%0,%1),0(%2),%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		"7: jz    5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		"1: algr  %0,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		"   la    %1,256(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		"   la    %2,256(%2)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		"2: mvcs  0(%0,%1),0(%2),%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		"8: jnz   1b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		"   j     5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		"3: la    %4,255(%1)\n" /* %4 = ptr + 255 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		"   lghi  %3,-4096\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		"   nr    %4,%3\n"	/* %4 = (ptr + 255) & -4096 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		"   slgr  %4,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		"   clgr  %0,%4\n"	/* copy crosses next page boundary? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		"   jnh   6f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		"4: mvcs  0(%4,%1),0(%2),%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		"9: slgr  %0,%4\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		"   j     6f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		"5: slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		"6: sacf  768\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		EX_TABLE(7b,3b) EX_TABLE(8b,3b) EX_TABLE(9b,6b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		: "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		: : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	disable_sacf_uaccess(old_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (copy_with_mvcos())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return copy_to_user_mvcos(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return copy_to_user_mvcs(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) EXPORT_SYMBOL(raw_copy_to_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline unsigned long copy_in_user_mvcos(void __user *to, const void __user *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 					       unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	register unsigned long reg0 asm("0") = 0x010001UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	unsigned long tmp1, tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	tmp1 = -4096UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/* FIXME: copy with reduced length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		"0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		"   jz	  2f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		"1: algr  %0,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		"   slgr  %1,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		"   slgr  %2,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		"   j	  0b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		"2:slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		"3: \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		EX_TABLE(0b,3b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		: "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		: "d" (reg0) : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static inline unsigned long copy_in_user_mvc(void __user *to, const void __user *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 					     unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	mm_segment_t old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	unsigned long tmp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	old_fs = enable_sacf_uaccess();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		"   sacf  256\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		"   aghi  %0,-1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		"   jo	  5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		"   bras  %3,3f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		"0: aghi  %0,257\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		"1: mvc	  0(1,%1),0(%2)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		"   la	  %1,1(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		"   la	  %2,1(%2)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		"   aghi  %0,-1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		"   jnz	  1b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		"   j	  5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		"2: mvc	  0(256,%1),0(%2)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		"   la	  %1,256(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		"   la	  %2,256(%2)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		"3: aghi  %0,-256\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		"   jnm	  2b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		"4: ex	  %0,1b-0b(%3)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		"5: slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		"6: sacf  768\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		: "+a" (size), "+a" (to), "+a" (from), "=a" (tmp1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		: : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	disable_sacf_uaccess(old_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) unsigned long raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (copy_with_mvcos())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return copy_in_user_mvcos(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return copy_in_user_mvc(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) EXPORT_SYMBOL(raw_copy_in_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	register unsigned long reg0 asm("0") = 0x010000UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	unsigned long tmp1, tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	tmp1 = -4096UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		"0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		"   jz	  4f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		"1: algr  %0,%2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		"   slgr  %1,%2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		"   j	  0b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		"2: la	  %3,4095(%1)\n"/* %4 = to + 4095 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		"   nr	  %3,%2\n"	/* %4 = (to + 4095) & -4096 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		"   slgr  %3,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		"   clgr  %0,%3\n"	/* copy crosses next page boundary? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		"   jnh	  5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		"3: .insn ss,0xc80000000000,0(%3,%1),0(%4),0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		"   slgr  %0,%3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		"   j	  5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		"4: slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		"5:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		EX_TABLE(0b,2b) EX_TABLE(3b,5b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		: "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		: "a" (empty_zero_page), "d" (reg0) : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static inline unsigned long clear_user_xc(void __user *to, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	mm_segment_t old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	unsigned long tmp1, tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	old_fs = enable_sacf_uaccess();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		"   sacf  256\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		"   aghi  %0,-1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		"   jo    5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		"   bras  %3,3f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		"   xc    0(1,%1),0(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		"0: aghi  %0,257\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		"   la    %2,255(%1)\n" /* %2 = ptr + 255 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		"   srl   %2,12\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		"   sll   %2,12\n"	/* %2 = (ptr + 255) & -4096 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		"   slgr  %2,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		"   clgr  %0,%2\n"	/* clear crosses next page boundary? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		"   jnh   5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		"   aghi  %2,-1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		"1: ex    %2,0(%3)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		"   aghi  %2,1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		"   slgr  %0,%2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		"   j     5f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		"2: xc    0(256,%1),0(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		"   la    %1,256(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		"3: aghi  %0,-256\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		"   jnm   2b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		"4: ex    %0,0(%3)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		"5: slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		"6: sacf  768\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		: "+a" (size), "+a" (to), "=a" (tmp1), "=a" (tmp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		: : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	disable_sacf_uaccess(old_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) unsigned long __clear_user(void __user *to, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (copy_with_mvcos())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			return clear_user_mvcos(to, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	return clear_user_xc(to, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) EXPORT_SYMBOL(__clear_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static inline unsigned long strnlen_user_srst(const char __user *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 					      unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	register unsigned long reg0 asm("0") = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	unsigned long tmp1, tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		"   la    %2,0(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		"   la    %3,0(%0,%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		"   slgr  %0,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		"   sacf  256\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		"0: srst  %3,%2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		"   jo    0b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		"   la    %0,1(%3)\n"	/* strnlen_user results includes \0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		"   slgr  %0,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		"1: sacf  768\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		EX_TABLE(0b,1b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		: "+a" (size), "+a" (src), "=a" (tmp1), "=a" (tmp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		: "d" (reg0) : "cc", "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) unsigned long __strnlen_user(const char __user *src, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	mm_segment_t old_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	unsigned long len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	if (unlikely(!size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	old_fs = enable_sacf_uaccess();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	len = strnlen_user_srst(src, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	disable_sacf_uaccess(old_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) EXPORT_SYMBOL(__strnlen_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) long __strncpy_from_user(char *dst, const char __user *src, long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	size_t done, len, offset, len_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if (unlikely(size <= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		offset = (size_t)src & (L1_CACHE_BYTES - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		len = min(size - done, L1_CACHE_BYTES - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		if (copy_from_user(dst, src, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		len_str = strnlen(dst, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		done += len_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		src += len_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		dst += len_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	} while ((len_str == len) && (done < size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	return done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) EXPORT_SYMBOL(__strncpy_from_user);