Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 2 | #ifndef _ASM_PARISC_FUTEX_H |
| 3 | #define _ASM_PARISC_FUTEX_H |
Jakub Jelinek | 4732efbe | 2005-09-06 15:16:25 -0700 | [diff] [blame] | 4 | |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 5 | #ifdef __KERNEL__ |
Jakub Jelinek | 4732efbe | 2005-09-06 15:16:25 -0700 | [diff] [blame] | 6 | |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 7 | #include <linux/futex.h> |
Jeff Dike | 730f412 | 2008-04-30 00:54:49 -0700 | [diff] [blame] | 8 | #include <linux/uaccess.h> |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 9 | #include <asm/atomic.h> |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 10 | #include <asm/errno.h> |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 11 | |
John David Anglin | 8b23281 | 2011-10-09 16:40:10 -0400 | [diff] [blame] | 12 | /* The following has to match the LWS code in syscall.S. We have |
| 13 | sixteen four-word locks. */ |
| 14 | |
| 15 | static inline void |
| 16 | _futex_spin_lock_irqsave(u32 __user *uaddr, unsigned long int *flags) |
| 17 | { |
| 18 | extern u32 lws_lock_start[]; |
| 19 | long index = ((long)uaddr & 0xf0) >> 2; |
| 20 | arch_spinlock_t *s = (arch_spinlock_t *)&lws_lock_start[index]; |
| 21 | local_irq_save(*flags); |
| 22 | arch_spin_lock(s); |
| 23 | } |
| 24 | |
| 25 | static inline void |
| 26 | _futex_spin_unlock_irqrestore(u32 __user *uaddr, unsigned long int *flags) |
| 27 | { |
| 28 | extern u32 lws_lock_start[]; |
| 29 | long index = ((long)uaddr & 0xf0) >> 2; |
| 30 | arch_spinlock_t *s = (arch_spinlock_t *)&lws_lock_start[index]; |
| 31 | arch_spin_unlock(s); |
| 32 | local_irq_restore(*flags); |
| 33 | } |
| 34 | |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 35 | static inline int |
Jiri Slaby | 30d6e0a | 2017-08-24 09:31:05 +0200 | [diff] [blame] | 36 | arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr) |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 37 | { |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 38 | unsigned long int flags; |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 39 | int oldval, ret; |
| 40 | u32 tmp; |
| 41 | |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 42 | _futex_spin_lock_irqsave(uaddr, &flags); |
Peter Zijlstra | a866374 | 2006-12-06 20:32:20 -0800 | [diff] [blame] | 43 | pagefault_disable(); |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 44 | |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 45 | ret = -EFAULT; |
| 46 | if (unlikely(get_user(oldval, uaddr) != 0)) |
| 47 | goto out_pagefault_enable; |
| 48 | |
| 49 | ret = 0; |
| 50 | tmp = oldval; |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 51 | |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 52 | switch (op) { |
| 53 | case FUTEX_OP_SET: |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 54 | tmp = oparg; |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 55 | break; |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 56 | case FUTEX_OP_ADD: |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 57 | tmp += oparg; |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 58 | break; |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 59 | case FUTEX_OP_OR: |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 60 | tmp |= oparg; |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 61 | break; |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 62 | case FUTEX_OP_ANDN: |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 63 | tmp &= ~oparg; |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 64 | break; |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 65 | case FUTEX_OP_XOR: |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 66 | tmp ^= oparg; |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 67 | break; |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 68 | default: |
| 69 | ret = -ENOSYS; |
| 70 | } |
| 71 | |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 72 | if (ret == 0 && unlikely(put_user(tmp, uaddr) != 0)) |
| 73 | ret = -EFAULT; |
| 74 | |
| 75 | out_pagefault_enable: |
| 76 | pagefault_enable(); |
John David Anglin | 8b23281 | 2011-10-09 16:40:10 -0400 | [diff] [blame] | 77 | _futex_spin_unlock_irqrestore(uaddr, &flags); |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 78 | |
Jiri Slaby | 30d6e0a | 2017-08-24 09:31:05 +0200 | [diff] [blame] | 79 | if (!ret) |
| 80 | *oval = oldval; |
| 81 | |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 82 | return ret; |
| 83 | } |
| 84 | |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 85 | static inline int |
Michel Lespinasse | 8d7718a | 2011-03-10 18:50:58 -0800 | [diff] [blame] | 86 | futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, |
| 87 | u32 oldval, u32 newval) |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 88 | { |
Michel Lespinasse | 8d7718a | 2011-03-10 18:50:58 -0800 | [diff] [blame] | 89 | u32 val; |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 90 | unsigned long flags; |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 91 | |
Kyle McMartin | c20a84c | 2008-03-01 10:25:52 -0800 | [diff] [blame] | 92 | /* futex.c wants to do a cmpxchg_inatomic on kernel NULL, which is |
| 93 | * our gateway page, and causes no end of trouble... |
| 94 | */ |
Al Viro | db68ce1 | 2017-03-20 21:08:07 -0400 | [diff] [blame] | 95 | if (uaccess_kernel() && !uaddr) |
Kyle McMartin | c20a84c | 2008-03-01 10:25:52 -0800 | [diff] [blame] | 96 | return -EFAULT; |
| 97 | |
Linus Torvalds | 96d4f26 | 2019-01-03 18:57:57 -0800 | [diff] [blame^] | 98 | if (!access_ok(uaddr, sizeof(u32))) |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 99 | return -EFAULT; |
| 100 | |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 101 | /* HPPA has no cmpxchg in hardware and therefore the |
| 102 | * best we can do here is use an array of locks. The |
| 103 | * lock selected is based on a hash of the userspace |
| 104 | * address. This should scale to a couple of CPUs. |
| 105 | */ |
| 106 | |
John David Anglin | 8b23281 | 2011-10-09 16:40:10 -0400 | [diff] [blame] | 107 | _futex_spin_lock_irqsave(uaddr, &flags); |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 108 | if (unlikely(get_user(val, uaddr) != 0)) { |
| 109 | _futex_spin_unlock_irqrestore(uaddr, &flags); |
| 110 | return -EFAULT; |
| 111 | } |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 112 | |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 113 | if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) { |
| 114 | _futex_spin_unlock_irqrestore(uaddr, &flags); |
| 115 | return -EFAULT; |
| 116 | } |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 117 | |
Michel Lespinasse | 37a9d91 | 2011-03-10 18:48:51 -0800 | [diff] [blame] | 118 | *uval = val; |
John David Anglin | 8b23281 | 2011-10-09 16:40:10 -0400 | [diff] [blame] | 119 | _futex_spin_unlock_irqrestore(uaddr, &flags); |
Carlos O'Donell | d9ba5fe | 2011-07-08 17:27:00 -0400 | [diff] [blame] | 120 | |
John David Anglin | 99aed91 | 2016-05-21 15:03:54 -0400 | [diff] [blame] | 121 | return 0; |
Carlos O'Donell | 342a049 | 2006-09-07 13:05:17 -0400 | [diff] [blame] | 122 | } |
| 123 | |
Kyle McMartin | c20a84c | 2008-03-01 10:25:52 -0800 | [diff] [blame] | 124 | #endif /*__KERNEL__*/ |
| 125 | #endif /*_ASM_PARISC_FUTEX_H*/ |