From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Guo Ren <guoren@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Waiman Long <longman@redhat.com>, Sasha Levin <sashal@kernel.org>,
linux-arch@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 10/11] asm-generic: qspinlock: fix queued_spin_value_unlocked() implementation
Date: Tue, 28 Nov 2023 16:09:34 -0500 [thread overview]
Message-ID: <20231128210941.877094-10-sashal@kernel.org> (raw)
In-Reply-To: <20231128210941.877094-1-sashal@kernel.org>
From: Linus Torvalds <torvalds@linux-foundation.org>
[ Upstream commit 125b0bb95dd6bec81b806b997a4ccb026eeecf8f ]
We really don't want to do atomic_read() or anything like that, since we
already have the value, not the lock. The whole point of this is that
we've loaded the lock from memory, and we want to check whether the
value we loaded was a locked one or not.
The main use of this is the lockref code, which loads both the lock and
the reference count in one atomic operation, and then works on that
combined value. With the atomic_read(), the compiler would pointlessly
spill the value to the stack, in order to then be able to read it back
"atomically".
This is the qspinlock version of commit c6f4a9002252 ("asm-generic:
ticket-lock: Optimize arch_spin_value_unlocked()") which fixed this same
bug for ticket locks.
Cc: Guo Ren <guoren@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Link: https://lore.kernel.org/all/CAHk-=whNRv0v6kQiV5QO6DJhjH4KEL36vWQ6Re8Csrnh4zbRkQ@mail.gmail.com/
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/asm-generic/qspinlock.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/asm-generic/qspinlock.h b/include/asm-generic/qspinlock.h
index fde943d180e03..6dc2269a5398a 100644
--- a/include/asm-generic/qspinlock.h
+++ b/include/asm-generic/qspinlock.h
@@ -38,7 +38,7 @@ static __always_inline int queued_spin_is_locked(struct qspinlock *lock)
*/
static __always_inline int queued_spin_value_unlocked(struct qspinlock lock)
{
- return !atomic_read(&lock.val);
+ return !lock.val.counter;
}
/**
--
2.42.0
next prev parent reply other threads:[~2023-11-28 21:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 21:09 [PATCH AUTOSEL 5.4 01/11] usb: aqc111: check packet for fixup for true limit Sasha Levin
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 02/11] blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock required!" Sasha Levin
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 03/11] bcache: avoid oversize memory allocation by small stripe_size Sasha Levin
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 04/11] bcache: add code comments for bch_btree_node_get() and __bch_btree_node_alloc() Sasha Levin
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 05/11] bcache: avoid NULL checking to c->root in run_cache_set() Sasha Levin
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 06/11] platform/x86: intel_telemetry: Fix kernel doc descriptions Sasha Levin
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 07/11] HID: add ALWAYS_POLL quirk for Apple kb Sasha Levin
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 08/11] HID: hid-asus: reset the backlight brightness level on resume Sasha Levin
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 09/11] HID: multitouch: Add quirk for HONOR GLO-GXXX touchpad Sasha Levin
2023-11-28 21:09 ` Sasha Levin [this message]
2023-11-28 21:09 ` [PATCH AUTOSEL 5.4 11/11] net: usb: qmi_wwan: claim interface 4 for ZTE MF290 Sasha Levin
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=20231128210941.877094-10-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=guoren@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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