cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

futex.h (1930B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2#ifndef _ASM_S390_FUTEX_H
      3#define _ASM_S390_FUTEX_H
      4
      5#include <linux/uaccess.h>
      6#include <linux/futex.h>
      7#include <asm/asm-extable.h>
      8#include <asm/mmu_context.h>
      9#include <asm/errno.h>
     10
     11#define __futex_atomic_op(insn, ret, oldval, newval, uaddr, oparg)	\
     12	asm volatile(							\
     13		"   sacf  256\n"					\
     14		"0: l     %1,0(%6)\n"					\
     15		"1:"insn						\
     16		"2: cs    %1,%2,0(%6)\n"				\
     17		"3: jl    1b\n"						\
     18		"   lhi   %0,0\n"					\
     19		"4: sacf  768\n"					\
     20		EX_TABLE(0b,4b) EX_TABLE(2b,4b) EX_TABLE(3b,4b)		\
     21		: "=d" (ret), "=&d" (oldval), "=&d" (newval),		\
     22		  "=m" (*uaddr)						\
     23		: "0" (-EFAULT), "d" (oparg), "a" (uaddr),		\
     24		  "m" (*uaddr) : "cc");
     25
     26static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
     27		u32 __user *uaddr)
     28{
     29	int oldval = 0, newval, ret;
     30
     31	switch (op) {
     32	case FUTEX_OP_SET:
     33		__futex_atomic_op("lr %2,%5\n",
     34				  ret, oldval, newval, uaddr, oparg);
     35		break;
     36	case FUTEX_OP_ADD:
     37		__futex_atomic_op("lr %2,%1\nar %2,%5\n",
     38				  ret, oldval, newval, uaddr, oparg);
     39		break;
     40	case FUTEX_OP_OR:
     41		__futex_atomic_op("lr %2,%1\nor %2,%5\n",
     42				  ret, oldval, newval, uaddr, oparg);
     43		break;
     44	case FUTEX_OP_ANDN:
     45		__futex_atomic_op("lr %2,%1\nnr %2,%5\n",
     46				  ret, oldval, newval, uaddr, oparg);
     47		break;
     48	case FUTEX_OP_XOR:
     49		__futex_atomic_op("lr %2,%1\nxr %2,%5\n",
     50				  ret, oldval, newval, uaddr, oparg);
     51		break;
     52	default:
     53		ret = -ENOSYS;
     54	}
     55
     56	if (!ret)
     57		*oval = oldval;
     58
     59	return ret;
     60}
     61
     62static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
     63						u32 oldval, u32 newval)
     64{
     65	int ret;
     66
     67	asm volatile(
     68		"   sacf 256\n"
     69		"0: cs   %1,%4,0(%5)\n"
     70		"1: la   %0,0\n"
     71		"2: sacf 768\n"
     72		EX_TABLE(0b,2b) EX_TABLE(1b,2b)
     73		: "=d" (ret), "+d" (oldval), "=m" (*uaddr)
     74		: "0" (-EFAULT), "d" (newval), "a" (uaddr), "m" (*uaddr)
     75		: "cc", "memory");
     76	*uval = oldval;
     77	return ret;
     78}
     79
     80#endif /* _ASM_S390_FUTEX_H */