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: <ZV22j+C+D7ZnKzqD@MiWiFi-R3L-srv>
Date:   Wed, 22 Nov 2023 16:06:39 +0800
From:   Baoquan He <bhe@...hat.com>
To:     Uros Bizjak <ubizjak@...il.com>
Cc:     kexec@...ts.infradead.org, linux-kernel@...r.kernel.org,
        akpm@...ux-foundation.org, Eric Biederman <ebiederm@...ssion.com>
Subject: Re: [PATCH] kexec: Use atomic_try_cmpxchg in crash_kexec

On 11/14/23 at 05:12pm, Uros Bizjak wrote:
> Use atomic_try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
> crash_kexec().  x86 CMPXCHG instruction returns success in ZF flag,
> so this change saves a compare after cmpxchg.
> 
> No functional change intended.

And code is simplified a little bit, so looks good to me,

Acked-by: Baoquan He <bhe@...hat.com>

> 
> Cc: Eric Biederman <ebiederm@...ssion.com>
> Signed-off-by: Uros Bizjak <ubizjak@...il.com>
> ---
>  kernel/kexec_core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index be5642a4ec49..bc4c096ab1f3 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -1063,9 +1063,10 @@ __bpf_kfunc void crash_kexec(struct pt_regs *regs)
>  	 * panic().  Otherwise parallel calls of panic() and crash_kexec()
>  	 * may stop each other.  To exclude them, we use panic_cpu here too.
>  	 */
> +	old_cpu = PANIC_CPU_INVALID;
>  	this_cpu = raw_smp_processor_id();
> -	old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu);
> -	if (old_cpu == PANIC_CPU_INVALID) {
> +
> +	if (atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu)) {
>  		/* This is the 1st CPU which comes here, so go ahead. */
>  		__crash_kexec(regs);
>  
> -- 
> 2.41.0
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@...ts.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ