Skip to content

Commit 91e040a

Browse files
committed
ARC: syscall for userspace cmpxchg assist
Older ARC700 cores (ARC750 specifically) lack instructions to implement atomic r-w-w. This is problematic for userspace libraries such as NPTL which need atomic primitives. So enable them by providing kernel assist. This is costly but really the only sane soluton (othern than tight spinning using the otherwise availiable atomic exchange EX instruciton). Good thing is there are only a few of these cores running Linux out in the wild. This only works on UP systems. Reviewed-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
1 parent 1dec785 commit 91e040a

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎arch/arc/include/asm/syscalls.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ int sys_clone_wrapper(int, int, int, int, int);
1717
int sys_cacheflush(uint32_t, uint32_t uint32_t);
1818
int sys_arc_settls(void *);
1919
int sys_arc_gettls(void);
20+
int sys_arc_usr_cmpxchg(int *, int, int);
2021

2122
#include <asm-generic/syscalls.h>
2223

‎arch/arc/include/uapi/asm/unistd.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@
2727

2828
#define NR_syscalls __NR_syscalls
2929

30+
/* Generic syscall (fs/filesystems.c - lost in asm-generic/unistd.h */
31+
#define __NR_sysfs (__NR_arch_specific_syscall + 3)
32+
3033
/* ARC specific syscall */
3134
#define __NR_cacheflush (__NR_arch_specific_syscall + 0)
3235
#define __NR_arc_settls (__NR_arch_specific_syscall + 1)
3336
#define __NR_arc_gettls (__NR_arch_specific_syscall + 2)
37+
#define __NR_arc_usr_cmpxchg (__NR_arch_specific_syscall + 4)
3438

3539
__SYSCALL(__NR_cacheflush, sys_cacheflush)
3640
__SYSCALL(__NR_arc_settls, sys_arc_settls)
3741
__SYSCALL(__NR_arc_gettls, sys_arc_gettls)
38-
39-
40-
/* Generic syscall (fs/filesystems.c - lost in asm-generic/unistd.h */
41-
#define __NR_sysfs (__NR_arch_specific_syscall + 3)
42+
__SYSCALL(__NR_arc_usr_cmpxchg, sys_arc_usr_cmpxchg)
4243
__SYSCALL(__NR_sysfs, sys_sysfs)
4344

4445
#undef __SYSCALL

‎arch/arc/kernel/process.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,39 @@ SYSCALL_DEFINE0(arc_gettls)
4141
return task_thread_info(current)->thr_ptr;
4242
}
4343

44+
SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
45+
{
46+
int uval;
47+
int ret;
48+
49+
/*
50+
* This is only for old cores lacking LLOCK/SCOND, which by defintion
51+
* can't possibly be SMP. Thus doesn't need to be SMP safe.
52+
* And this also helps reduce the overhead for serializing in
53+
* the UP case
54+
*/
55+
WARN_ON_ONCE(IS_ENABLED(CONFIG_SMP));
56+
57+
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
58+
return -EFAULT;
59+
60+
preempt_disable();
61+
62+
ret = __get_user(uval, uaddr);
63+
if (ret)
64+
goto done;
65+
66+
if (uval != expected)
67+
ret = -EAGAIN;
68+
else
69+
ret = __put_user(new, uaddr);
70+
71+
done:
72+
preempt_enable();
73+
74+
return ret;
75+
}
76+
4477
void arch_cpu_idle(void)
4578
{
4679
/* sleep, but enable all interrupts before committing */

0 commit comments

Comments
 (0)