kexec: Use atomic_try_cmpxchg in crash_kexec
Subsystems (3)
PATCH 1/1 kexec: Use atomic_try_cmpxchg in crash_kexec
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.
Cc Eric Biederman <[email protected]>
Signed-off-by Uros Bizjak <[email protected]>
--- kernel/kexec_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kexec_core.c +3 -2
@@ -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);
Signature · 1 line
2.41.0
Quoted 5 lines · Uros Bizjak
Use
atomic_try_cmpxchginstead of cmpxchg (*ptr, old, new) == old incrash_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 <[email protected]>
Quoted 33 lines
Cc Eric Biederman <[email protected]>Signed-off-by Uros Bizjak <[email protected]>--- kernel/kexec_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/kexec_core.c +3
-2@@ -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);Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec