The patch titled Subject: kexec: use atomic_try_cmpxchg_acquire() in kexec_trylock() has been added to the -mm mm-nonmm-unstable branch. Its filename is kexec-use-atomic_try_cmpxchg_acquire-in-kexec_trylock.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/kexec-use-atomic_try_cmpxchg_acquire-in-kexec_trylock.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Uros Bizjak <ubizjak@xxxxxxxxx> Subject: kexec: use atomic_try_cmpxchg_acquire() in kexec_trylock() Date: Fri, 19 Jul 2024 12:38:52 +0200 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@xxxxxxxxx Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx> Acked-by: Baoquan He <bhe@xxxxxxxxxx> Cc: Eric Biederman <ebiederm@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/kexec_internal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/kexec_internal.h~kexec-use-atomic_try_cmpxchg_acquire-in-kexec_trylock +++ a/kernel/kexec_internal.h @@ -23,7 +23,8 @@ int kimage_is_destination_range(struct k 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) { _ Patches currently in -mm which might be from ubizjak@xxxxxxxxx are kexec-use-atomic_try_cmpxchg_acquire-in-kexec_trylock.patch