summaryrefslogtreecommitdiff
path: root/kernel/kexec_internal.h
diff options
context:
space:
mode:
authorUros Bizjak <ubizjak@gmail.com>2024-07-19 12:38:52 +0200
committerAndrew Morton <akpm@linux-foundation.org>2024-09-01 20:43:23 -0700
commitacf02be3c72f12c31f916d3465c4c716b4729538 (patch)
tree9f247e7a5d880e4f6d20a108c7c68680d7545b0f /kernel/kexec_internal.h
parente24f4de8a72b50b67ea116b38152bb98360f81b3 (diff)
downloadlwn-acf02be3c72f12c31f916d3465c4c716b4729538.tar.gz
lwn-acf02be3c72f12c31f916d3465c4c716b4729538.zip
kexec: use atomic_try_cmpxchg_acquire() in kexec_trylock()
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>
Diffstat (limited to 'kernel/kexec_internal.h')
-rw-r--r--kernel/kexec_internal.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h
index 2595defe8c0d..d35d9792402d 100644
--- a/kernel/kexec_internal.h
+++ b/kernel/kexec_internal.h
@@ -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)
{