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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAFULd4ZxrkbmUbzD52_HQJcounWQNsDkC0vHCKjSvMrBh0wmPw@mail.gmail.com>
Date: Thu, 3 Oct 2024 15:44:43 +0200
From: Uros Bizjak <ubizjak@...il.com>
To: André Almeida <andrealmeid@...lia.com>
Cc: Thomas Gleixner <tglx@...utronix.de>, linux-kernel@...r.kernel.org, 
	Ingo Molnar <mingo@...nel.org>, Peter Zijlstra <peterz@...radead.org>, 
	Darren Hart <dvhart@...radead.org>, Davidlohr Bueso <dave@...olabs.net>
Subject: Re: [PATCH] futex: Improve get_inode_sequence_number()

On Thu, Oct 3, 2024 at 3:29 PM André Almeida <andrealmeid@...lia.com> wrote:
>
> Hi Uros,
>
> Em 03/10/2024 09:18, Uros Bizjak escreveu:
> > Rewrite FOR loop to a DO-WHILE loop where returns are moved out of
> > the loop. Use atomic64_inc_return() instead of atomic64_add_return().
> >
> > Use !atomic64_try_cmpxchg_relaxed(*ptr, &old, new) instead of
> > atomic64_cmpxchg_relaxed (*ptr, old, new) != old.  x86 CMPXCHG
> > instruction returns success in ZF flag, so this change saves
> > a compare after CMPXCHG..
> >
> > Note that due to early return, "old" equals to 0 before
> > atomic64_cmpxchg_relaxed(), so initialization of variable to 0
> > is not needed.
> >
>
> Despite the implicitly `old = 0`, I think it makes people life easier to
> know explicitly that `old = 0` in the cmpxchg() call.

No problem; in this place the compiler is smart enough that explicit
initialization doesn't make a difference.

> Also, please state in the commit message the motivation of doing this
> change. Is to make the code simpler or to try to save some instructions?

I tried to modernize the usage of cmpxchg with try_cmpxchg, but then I
noticed the opportunity to make the code simpler (please see the
"continue" in the for loop that creates some kind of degenerated for
loop). So, the motivation is to simplify and modernize the code.

> The compiler might be already saving such instructions for us :)

That would be nice, but unfortunately, the case of cmpxchg() vs.
try_cmpxchg() is too hard for the compiler to optimize.

I will prepare a v2 that incorporates all your suggestions.

Thanks,
Uros.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ