Commit e6e335bf authored by Vineet Gupta's avatar Vineet Gupta

ARC: change return value of userspace cmpxchg assist syscall

The original syscall only used to return errno to indicate if cmpxchg
succeeded. It was not returning the "previous" value which typical cmpxchg
callers are interested in to build their slowpaths or retry loops.
Given user preemption in syscall return path etc, it is not wise to
check this in userspace afterwards, but should be what kernel actually
observed in the syscall.

So change the syscall interface to always return the previous value and
additionally set Z flag to indicate whether operation succeeded or not
(just like ARM implementation when they used to have this syscall)
The flag approach avoids having to put_user errno which is nice given
the use case for this syscall cares mostly about the "previous" value.
Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
parent a79a8121
...@@ -43,12 +43,14 @@ ...@@ -43,12 +43,14 @@
#define STATUS_AE_BIT 5 /* Exception active */ #define STATUS_AE_BIT 5 /* Exception active */
#define STATUS_DE_BIT 6 /* PC is in delay slot */ #define STATUS_DE_BIT 6 /* PC is in delay slot */
#define STATUS_U_BIT 7 /* User/Kernel mode */ #define STATUS_U_BIT 7 /* User/Kernel mode */
#define STATUS_Z_BIT 11
#define STATUS_L_BIT 12 /* Loop inhibit */ #define STATUS_L_BIT 12 /* Loop inhibit */
/* These masks correspond to the status word(STATUS_32) bits */ /* These masks correspond to the status word(STATUS_32) bits */
#define STATUS_AE_MASK (1<<STATUS_AE_BIT) #define STATUS_AE_MASK (1<<STATUS_AE_BIT)
#define STATUS_DE_MASK (1<<STATUS_DE_BIT) #define STATUS_DE_MASK (1<<STATUS_DE_BIT)
#define STATUS_U_MASK (1<<STATUS_U_BIT) #define STATUS_U_MASK (1<<STATUS_U_BIT)
#define STATUS_Z_MASK (1<<STATUS_Z_BIT)
#define STATUS_L_MASK (1<<STATUS_L_BIT) #define STATUS_L_MASK (1<<STATUS_L_BIT)
/* /*
......
...@@ -43,8 +43,8 @@ SYSCALL_DEFINE0(arc_gettls) ...@@ -43,8 +43,8 @@ SYSCALL_DEFINE0(arc_gettls)
SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new) SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
{ {
int uval; struct pt_regs *regs = current_pt_regs();
int ret; int uval = -EFAULT;
/* /*
* This is only for old cores lacking LLOCK/SCOND, which by defintion * This is only for old cores lacking LLOCK/SCOND, which by defintion
...@@ -54,24 +54,26 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new) ...@@ -54,24 +54,26 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
*/ */
WARN_ON_ONCE(IS_ENABLED(CONFIG_SMP)); WARN_ON_ONCE(IS_ENABLED(CONFIG_SMP));
/* Z indicates to userspace if operation succeded */
regs->status32 &= ~STATUS_Z_MASK;
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int))) if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
return -EFAULT; return -EFAULT;
preempt_disable(); preempt_disable();
ret = __get_user(uval, uaddr); if (__get_user(uval, uaddr))
if (ret)
goto done; goto done;
if (uval != expected) if (uval == expected) {
ret = -EAGAIN; if (!__put_user(new, uaddr))
else regs->status32 |= STATUS_Z_MASK;
ret = __put_user(new, uaddr); }
done: done:
preempt_enable(); preempt_enable();
return ret; return uval;
} }
void arch_cpu_idle(void) void arch_cpu_idle(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment