From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ley Foon Tan Subject: Re: [PATCH v3 01/29] asm-generic: add generic futex for !CONFIG_SMP Date: Wed, 24 Sep 2014 18:29:27 +0800 Message-ID: References: <1410168160-3624-1-git-send-email-lftan@altera.com> <1410168160-3624-2-git-send-email-lftan@altera.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Thomas Gleixner Cc: Linux-Arch , "linux-kernel@vger.kernel.org" , "linux-doc@vger.kernel.org" , Arnd Bergmann , Chung-Lin Tang List-Id: linux-arch.vger.kernel.org On Wed, Sep 24, 2014 at 5:47 AM, Thomas Gleixner wrote: > On Tue, 23 Sep 2014, LF.Tan wrote: >> On Mon, Sep 8, 2014 at 5:22 PM, Ley Foon Tan wrote: >> > Follow m68k futex implementation for !CONFIG_SMP. > > Great. Follow arch/random implementation blindly and copy all the bugs > in it. > >> > +static inline int >> > +futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, >> > + u32 oldval, u32 newval) >> > +{ >> > + u32 val; >> > + >> > + if (unlikely(get_user(val, uaddr) != 0)) >> > + return -EFAULT; >> > + >> > + if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) >> > + return -EFAULT; >> > + >> > + *uval = val; >> > + >> > + return 0; >> > +} > > Care to explain how this works reliably and resembles proper cmpxchg > semantics under all circumstances? kernel/futex.c:cmpxchg_futex_value_locked() is already called to pagefault_disable() before call to futex_atomic_cmpxchg_inatomic(). For UP kernel and pagefault_disable() also means there is no preemption. Regards Ley Foon From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-la0-f54.google.com ([209.85.215.54]:39049 "EHLO mail-la0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752806AbaIXK33 (ORCPT ); Wed, 24 Sep 2014 06:29:29 -0400 MIME-Version: 1.0 In-Reply-To: References: <1410168160-3624-1-git-send-email-lftan@altera.com> <1410168160-3624-2-git-send-email-lftan@altera.com> Date: Wed, 24 Sep 2014 18:29:27 +0800 Message-ID: Subject: Re: [PATCH v3 01/29] asm-generic: add generic futex for !CONFIG_SMP From: Ley Foon Tan Content-Type: text/plain; charset=UTF-8 Sender: linux-arch-owner@vger.kernel.org List-ID: To: Thomas Gleixner Cc: Linux-Arch , "linux-kernel@vger.kernel.org" , "linux-doc@vger.kernel.org" , Arnd Bergmann , Chung-Lin Tang Message-ID: <20140924102927.T1Ka6sD_dqblbmOg6AXnksiUD13Tm0l4ftOpCr2BnKk@z> On Wed, Sep 24, 2014 at 5:47 AM, Thomas Gleixner wrote: > On Tue, 23 Sep 2014, LF.Tan wrote: >> On Mon, Sep 8, 2014 at 5:22 PM, Ley Foon Tan wrote: >> > Follow m68k futex implementation for !CONFIG_SMP. > > Great. Follow arch/random implementation blindly and copy all the bugs > in it. > >> > +static inline int >> > +futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, >> > + u32 oldval, u32 newval) >> > +{ >> > + u32 val; >> > + >> > + if (unlikely(get_user(val, uaddr) != 0)) >> > + return -EFAULT; >> > + >> > + if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) >> > + return -EFAULT; >> > + >> > + *uval = val; >> > + >> > + return 0; >> > +} > > Care to explain how this works reliably and resembles proper cmpxchg > semantics under all circumstances? kernel/futex.c:cmpxchg_futex_value_locked() is already called to pagefault_disable() before call to futex_atomic_cmpxchg_inatomic(). For UP kernel and pagefault_disable() also means there is no preemption. Regards Ley Foon