lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAFULd4Zck5YRfhoXsg_aPKpFbnkkr_xZ6ejDpmp=ysZemwoQAg@mail.gmail.com>
Date:   Fri, 13 May 2022 17:36:19 +0200
From:   Uros Bizjak <ubizjak@...il.com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     X86 ML <x86@...nel.org>, LKML <linux-kernel@...r.kernel.org>,
        kvm@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        "H. Peter Anvin" <hpa@...or.com>, Will Deacon <will@...nel.org>,
        Boqun Feng <boqun.feng@...il.com>,
        Mark Rutland <mark.rutland@....com>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        Marco Elver <elver@...gle.com>
Subject: Re: [PATCH] locking/atomic/x86: Introduce try_cmpxchg64

On Fri, May 13, 2022 at 12:20 PM Uros Bizjak <ubizjak@...il.com> wrote:

> > > +#define arch_try_cmpxchg64(ptr, po, n)                               \
> > > +({                                                           \
> > > +     bool success;                                           \
> > > +     __typeof__(*(ptr)) __prev;                              \
> > > +     __typeof__(ptr) _old = (__typeof__(ptr))(po);           \
> > > +     __typeof__(*(ptr)) __old = *_old;                       \
> > > +     __typeof__(*(ptr)) __new = (n);                         \
> > > +     alternative_io(LOCK_PREFIX_HERE                         \
> > > +                     "call cmpxchg8b_emu",                   \
> > > +                     "lock; cmpxchg8b (%%esi)" ,             \
> > > +                    X86_FEATURE_CX8,                         \
> > > +                    "=A" (__prev),                           \
> > > +                    "S" ((ptr)), "0" (__old),                \
> > > +                    "b" ((unsigned int)__new),               \
> > > +                    "c" ((unsigned int)(__new>>32))          \
> > > +                    : "memory");                             \
> > > +     success = (__prev == __old);                            \
> > > +     if (unlikely(!success))                                 \
> > > +             *_old = __prev;                                 \
> > > +     likely(success);                                        \
> > > +})
> >
> > Wouldn't this be better written like the normal fallback wrapper?
> >
> > static __always_inline bool
> > arch_try_cmpxchg64(u64 *v, u64 *old, u64 new)
> > {
> >         u64 r, o = *old;
> >         r = arch_cmpxchg64(v, o, new);
> >         if (unlikely(r != o))
> >                 *old = r;
> >         return likely(r == o);
> > }
> >
> > Less magical, same exact code.
>
> Also, I tried to follow up the existing #defines. Will improve the
> code according to your suggestion here.

In the v2 patch, generic fallbacks were introduced, so that
arch_try_cmpxchg64 can be used when only arch_cmpxchg64 is defined.

Uros.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ