[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180315081845.GS4064@hirez.programming.kicks-ass.net>
Date: Thu, 15 Mar 2018 09:18:45 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Alexey Brodkin <Alexey.Brodkin@...opsys.com>
Cc: "Vineet.Gupta1@...opsys.com" <Vineet.Gupta1@...opsys.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-arch@...r.kernel.org" <linux-arch@...r.kernel.org>,
"linux-snps-arc@...ts.infradead.org"
<linux-snps-arc@...ts.infradead.org>
Subject: Re: arc_usr_cmpxchg and preemption
On Wed, Mar 14, 2018 at 08:38:53PM +0000, Alexey Brodkin wrote:
> > 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;
>
> I guess this jump we need to do only once, right?
Typically, yes. It is theoretically possible for the page to get
paged-out right after we do put_page() and before we do get/put_user(),
But if that happens the machine likely has bigger problems than having
to do this loop again.
FWIW, look at kernel/futex.c for working examples of this pattern, the
above was written purely from memory and could contain a fail or two ;-)
Also, it might make sense to stuff this implementation in some lib/ file
somewhere and make all platforms that need it use the same code, afaict
there really isn't anything platform specific to it.
Powered by blists - more mailing lists