public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, Eric Biederman <ebiederm@xmission.com>
Subject: Re: [PATCH] kexec: Use atomic_try_cmpxchg in crash_kexec
Date: Wed, 22 Nov 2023 16:06:39 +0800	[thread overview]
Message-ID: <ZV22j+C+D7ZnKzqD@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20231114161228.108516-1-ubizjak@gmail.com>

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@redhat.com>

> 
> Cc: Eric Biederman <ebiederm@xmission.com>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.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@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 


      reply	other threads:[~2023-11-22  8:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 16:12 [PATCH] kexec: Use atomic_try_cmpxchg in crash_kexec Uros Bizjak
2023-11-22  8:06 ` Baoquan He [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZV22j+C+D7ZnKzqD@MiWiFi-R3L-srv \
    --to=bhe@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ubizjak@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox