cregit-Linux how code gets into the kernel

Release 4.14 arch/s390/lib/uaccess.c

Directory: arch/s390/lib
// SPDX-License-Identifier: GPL-2.0
/*
 *  Standard user space access functions based on mvcp/mvcs and doing
 *  interesting things in the secondary space mode.
 *
 *    Copyright IBM Corp. 2006,2014
 *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
 *               Gerald Schaefer (gerald.schaefer@de.ibm.com)
 */

#include <linux/jump_label.h>
#include <linux/uaccess.h>
#include <linux/export.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <asm/mmu_context.h>
#include <asm/facility.h>

#ifndef CONFIG_HAVE_MARCH_Z10_FEATURES
static DEFINE_STATIC_KEY_FALSE(have_mvcos);


static int __init uaccess_init(void) { if (test_facility(27)) static_branch_enable(&have_mvcos); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky25100.00%1100.00%
Total25100.00%1100.00%

early_initcall(uaccess_init);
static inline int copy_with_mvcos(void) { if (static_branch_likely(&have_mvcos)) return 1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky23100.00%1100.00%
Total23100.00%1100.00%

#else
static inline int copy_with_mvcos(void) { return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky12100.00%1100.00%
Total12100.00%1100.00%

#endif
static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr, unsigned long size) { register unsigned long reg0 asm("0") = 0x81UL; unsigned long tmp1, tmp2; tmp1 = -4096UL; asm volatile( "0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n" "6: jz 4f\n" "1: algr %0,%3\n" " slgr %1,%3\n" " slgr %2,%3\n" " j 0b\n" "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */ " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */ " slgr %4,%1\n" " clgr %0,%4\n" /* copy crosses next page boundary? */ " jnh 5f\n" "3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n" "7: slgr %0,%4\n" " j 5f\n" "4: slgr %0,%0\n" "5:\n" EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b) : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2) : "d" (reg0) : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Gerald Schaefer3969.64%112.50%
Heiko Carstens1526.79%675.00%
Al Viro23.57%112.50%
Total56100.00%8100.00%


static inline unsigned long copy_from_user_mvcp(void *x, const void __user *ptr, unsigned long size) { unsigned long tmp1, tmp2; load_kernel_asce(); tmp1 = -256UL; asm volatile( " sacf 0\n" "0: mvcp 0(%0,%2),0(%1),%3\n" "7: jz 5f\n" "1: algr %0,%3\n" " la %1,256(%1)\n" " la %2,256(%2)\n" "2: mvcp 0(%0,%2),0(%1),%3\n" "8: jnz 1b\n" " j 5f\n" "3: la %4,255(%1)\n" /* %4 = ptr + 255 */ " lghi %3,-4096\n" " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */ " slgr %4,%1\n" " clgr %0,%4\n" /* copy crosses next page boundary? */ " jnh 6f\n" "4: mvcp 0(%4,%2),0(%1),%3\n" "9: slgr %0,%4\n" " j 6f\n" "5: slgr %0,%0\n" "6: sacf 768\n" EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b) EX_TABLE(7b,3b) EX_TABLE(8b,3b) EX_TABLE(9b,6b) : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2) : : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens4083.33%240.00%
Gerald Schaefer48.33%120.00%
Al Viro24.17%120.00%
Martin Schwidefsky24.17%120.00%
Total48100.00%5100.00%


unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n) { if (copy_with_mvcos()) return copy_from_user_mvcos(to, from, n); return copy_from_user_mvcp(to, from, n); }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens4293.33%360.00%
Martin Schwidefsky24.44%120.00%
Al Viro12.22%120.00%
Total45100.00%5100.00%

EXPORT_SYMBOL(raw_copy_from_user);
static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x, unsigned long size) { register unsigned long reg0 asm("0") = 0x810000UL; unsigned long tmp1, tmp2; tmp1 = -4096UL; asm volatile( "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n" "6: jz 4f\n" "1: algr %0,%3\n" " slgr %1,%3\n" " slgr %2,%3\n" " j 0b\n" "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */ " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */ " slgr %4,%1\n" " clgr %0,%4\n" /* copy crosses next page boundary? */ " jnh 5f\n" "3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n" "7: slgr %0,%4\n" " j 5f\n" "4: slgr %0,%0\n" "5:\n" EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b) : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2) : "d" (reg0) : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Gerald Schaefer4173.21%114.29%
Heiko Carstens1526.79%685.71%
Total56100.00%7100.00%


static inline unsigned long copy_to_user_mvcs(void __user *ptr, const void *x, unsigned long size) { unsigned long tmp1, tmp2; load_kernel_asce(); tmp1 = -256UL; asm volatile( " sacf 0\n" "0: mvcs 0(%0,%1),0(%2),%3\n" "7: jz 5f\n" "1: algr %0,%3\n" " la %1,256(%1)\n" " la %2,256(%2)\n" "2: mvcs 0(%0,%1),0(%2),%3\n" "8: jnz 1b\n" " j 5f\n" "3: la %4,255(%1)\n" /* %4 = ptr + 255 */ " lghi %3,-4096\n" " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */ " slgr %4,%1\n" " clgr %0,%4\n" /* copy crosses next page boundary? */ " jnh 6f\n" "4: mvcs 0(%4,%1),0(%2),%3\n" "9: slgr %0,%4\n" " j 6f\n" "5: slgr %0,%0\n" "6: sacf 768\n" EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b) EX_TABLE(7b,3b) EX_TABLE(8b,3b) EX_TABLE(9b,6b) : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2) : : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens4287.50%250.00%
Gerald Schaefer48.33%125.00%
Martin Schwidefsky24.17%125.00%
Total48100.00%4100.00%


unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n) { if (copy_with_mvcos()) return copy_to_user_mvcos(to, from, n); return copy_to_user_mvcs(to, from, n); }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens4293.33%360.00%
Martin Schwidefsky24.44%120.00%
Al Viro12.22%120.00%
Total45100.00%5100.00%

EXPORT_SYMBOL(raw_copy_to_user);
static inline unsigned long copy_in_user_mvcos(void __user *to, const void __user *from, unsigned long size) { register unsigned long reg0 asm("0") = 0x810081UL; unsigned long tmp1, tmp2; tmp1 = -4096UL; /* FIXME: copy with reduced length. */ asm volatile( "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n" " jz 2f\n" "1: algr %0,%3\n" " slgr %1,%3\n" " slgr %2,%3\n" " j 0b\n" "2:slgr %0,%0\n" "3: \n" EX_TABLE(0b,3b) : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2) : "d" (reg0) : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Gerald Schaefer3975.00%114.29%
Heiko Carstens1325.00%685.71%
Total52100.00%7100.00%


static inline unsigned long copy_in_user_mvc(void __user *to, const void __user *from, unsigned long size) { unsigned long tmp1; load_kernel_asce(); asm volatile( " sacf 256\n" " aghi %0,-1\n" " jo 5f\n" " bras %3,3f\n" "0: aghi %0,257\n" "1: mvc 0(1,%1),0(%2)\n" " la %1,1(%1)\n" " la %2,1(%2)\n" " aghi %0,-1\n" " jnz 1b\n" " j 5f\n" "2: mvc 0(256,%1),0(%2)\n" " la %1,256(%1)\n" " la %2,256(%2)\n" "3: aghi %0,-256\n" " jnm 2b\n" "4: ex %0,1b-0b(%3)\n" "5: slgr %0,%0\n" "6: sacf 768\n" EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b) : "+a" (size), "+a" (to), "+a" (from), "=a" (tmp1) : : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens3083.33%250.00%
Gerald Schaefer411.11%125.00%
Martin Schwidefsky25.56%125.00%
Total36100.00%4100.00%


unsigned long raw_copy_in_user(void __user *to, const void __user *from, unsigned long n) { if (copy_with_mvcos()) return copy_in_user_mvcos(to, from, n); return copy_in_user_mvc(to, from, n); }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens4393.48%360.00%
Martin Schwidefsky24.35%120.00%
Al Viro12.17%120.00%
Total46100.00%5100.00%

EXPORT_SYMBOL(raw_copy_in_user);
static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size) { register unsigned long reg0 asm("0") = 0x810000UL; unsigned long tmp1, tmp2; tmp1 = -4096UL; asm volatile( "0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n" " jz 4f\n" "1: algr %0,%2\n" " slgr %1,%2\n" " j 0b\n" "2: la %3,4095(%1)\n"/* %4 = to + 4095 */ " nr %3,%2\n" /* %4 = (to + 4095) & -4096 */ " slgr %3,%1\n" " clgr %0,%3\n" /* copy crosses next page boundary? */ " jnh 5f\n" "3: .insn ss,0xc80000000000,0(%3,%1),0(%4),0\n" " slgr %0,%3\n" " j 5f\n" "4: slgr %0,%0\n" "5:\n" EX_TABLE(0b,2b) EX_TABLE(3b,5b) : "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2) : "a" (empty_zero_page), "d" (reg0) : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Gerald Schaefer3568.63%112.50%
Heiko Carstens1631.37%787.50%
Total51100.00%8100.00%


static inline unsigned long clear_user_xc(void __user *to, unsigned long size) { unsigned long tmp1, tmp2; load_kernel_asce(); asm volatile( " sacf 256\n" " aghi %0,-1\n" " jo 5f\n" " bras %3,3f\n" " xc 0(1,%1),0(%1)\n" "0: aghi %0,257\n" " la %2,255(%1)\n" /* %2 = ptr + 255 */ " srl %2,12\n" " sll %2,12\n" /* %2 = (ptr + 255) & -4096 */ " slgr %2,%1\n" " clgr %0,%2\n" /* clear crosses next page boundary? */ " jnh 5f\n" " aghi %2,-1\n" "1: ex %2,0(%3)\n" " aghi %2,1\n" " slgr %0,%2\n" " j 5f\n" "2: xc 0(256,%1),0(%1)\n" " la %1,256(%1)\n" "3: aghi %0,-256\n" " jnm 2b\n" "4: ex %0,0(%3)\n" "5: slgr %0,%0\n" "6: sacf 768\n" EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b) : "+a" (size), "+a" (to), "=a" (tmp1), "=a" (tmp2) : : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens3284.21%250.00%
Gerald Schaefer410.53%125.00%
Martin Schwidefsky25.26%125.00%
Total38100.00%4100.00%


unsigned long __clear_user(void __user *to, unsigned long size) { if (copy_with_mvcos()) return clear_user_mvcos(to, size); return clear_user_xc(to, size); }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens3494.44%375.00%
Martin Schwidefsky25.56%125.00%
Total36100.00%4100.00%

EXPORT_SYMBOL(__clear_user);
static inline unsigned long strnlen_user_srst(const char __user *src, unsigned long size) { register unsigned long reg0 asm("0") = 0; unsigned long tmp1, tmp2; asm volatile( " la %2,0(%1)\n" " la %3,0(%0,%1)\n" " slgr %0,%0\n" " sacf 256\n" "0: srst %3,%2\n" " jo 0b\n" " la %0,1(%3)\n" /* strnlen_user results includes \0 */ " slgr %0,%1\n" "1: sacf 768\n" EX_TABLE(0b,1b) : "+a" (size), "+a" (src), "=a" (tmp1), "=a" (tmp2) : "d" (reg0) : "cc", "memory"); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens3069.77%583.33%
Gerald Schaefer1330.23%116.67%
Total43100.00%6100.00%


unsigned long __strnlen_user(const char __user *src, unsigned long size) { if (unlikely(!size)) return 0; load_kernel_asce(); return strnlen_user_srst(src, size); }

Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens3694.74%480.00%
Martin Schwidefsky25.26%120.00%
Total38100.00%5100.00%

EXPORT_SYMBOL(__strnlen_user);
long __strncpy_from_user(char *dst, const char __user *src, long size) { size_t done, len, offset, len_str; if (unlikely(size <= 0)) return 0; done = 0; do { offset = (size_t)src & (L1_CACHE_BYTES - 1); len = min(size - done, L1_CACHE_BYTES - offset); if (copy_from_user(dst, src, len)) return -EFAULT; len_str = strnlen(dst, len); done += len_str; src += len_str; dst += len_str; } while ((len_str == len) && (done < size)); return done; }

Contributors

PersonTokensPropCommitsCommitProp
Gerald Schaefer7357.94%114.29%
Heiko Carstens5342.06%685.71%
Total126100.00%7100.00%

EXPORT_SYMBOL(__strncpy_from_user);

Overall Contributors

PersonTokensPropCommitsCommitProp
Heiko Carstens53259.44%1368.42%
Gerald Schaefer26229.27%210.53%
Martin Schwidefsky9010.06%210.53%
Al Viro101.12%15.26%
Greg Kroah-Hartman10.11%15.26%
Total895100.00%19100.00%
Directory: arch/s390/lib
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.