lkml.org 
[lkml]   [2018]   [Mar]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: arc_usr_cmpxchg and preemption
On Wed, Mar 14, 2018 at 09:58:19AM -0700, Vineet Gupta wrote:

> Well it is broken wrt the semantics the syscall is supposed to provide.
> Preemption disabling is what prevents a concurrent thread from coming in and
> modifying the same location (Imagine a variable which is being cmpxchg
> concurrently by 2 threads).
>
> One approach is to do it the MIPS way, emulate the llsc flag - set it under
> preemption disabled section and clear it in switch_to

*shudder*... just catch the -EFAULT, force the write fault and retry.

Something like:

int sys_cmpxchg(u32 __user *user_ptr, u32 old, u32 new)
{
u32 val;
int ret;

again:
ret = 0;

preempt_disable();
val = get_user(user_ptr);
if (val == old)
ret = put_user(new, user_ptr);
preempt_enable();

if (ret == -EFAULT) {
struct page *page;
ret = get_user_pages_fast((unsigned long)user_ptr, 1, 1, &page);
if (ret < 0)
return ret;
put_page(page);
goto again;
}

return ret;
}

\
 
 \ /
  Last update: 2018-03-14 18:54    [W:0.125 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site