]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
kexec: use atomic_try_cmpxchg_acquire() in kexec_trylock()
authorUros Bizjak <ubizjak@gmail.com>
Fri, 19 Jul 2024 10:38:52 +0000 (12:38 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 2 Sep 2024 03:43:23 +0000 (20:43 -0700)
Use atomic_try_cmpxchg_acquire(*ptr, &old, new) instead of
atomic_cmpxchg_acquire(*ptr, old, new) == old in kexec_trylock().
x86 CMPXCHG instruction returns success in ZF flag, so
this change saves a compare after cmpxchg.

Link: https://lkml.kernel.org/r/20240719103937.53742-1-ubizjak@gmail.com
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Acked-by: Baoquan He <bhe@redhat.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/kexec_internal.h

index 2595defe8c0d92dd3ec395da082b3c0909ff06eb..d35d9792402d13ddfd2491962f473afd6c966b19 100644 (file)
@@ -23,7 +23,8 @@ int kimage_is_destination_range(struct kimage *image,
 extern atomic_t __kexec_lock;
 static inline bool kexec_trylock(void)
 {
-       return atomic_cmpxchg_acquire(&__kexec_lock, 0, 1) == 0;
+       int old = 0;
+       return atomic_try_cmpxchg_acquire(&__kexec_lock, &old, 1);
 }
 static inline void kexec_unlock(void)
 {