* [GIT PULL] [PATCH 0/9] Locking changes for v6.17
@ 2025-07-16 14:48 Boqun Feng
2025-07-16 14:48 ` [PATCH 1/9] spi: spi-nxp-fspi: Check return value of devm_mutex_init() Boqun Feng
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney, Boqun Feng
Hi Ingo & Peter,
Please pull the lockdep changes for v6.17 into tip. One thing to notice
is that I would like to add Breno Leitao's workaround in
lockdep_unregister_key(), since the alternative requires hazptr and I'm
not near to get it done. I added comments explaining this and left a
TODO there, and I will replace it once the shazptr patch is in a good
shape. Peter, if you have any concern about it, either we can drop the
patch #9 or I can create another tag. Thanks!
The following changes since commit 7ff495e26a39f3e7a3d4058df59b5b6d6f943cab:
local_lock: Move this_cpu_ptr() notation from internal to main header (2025-06-30 17:45:35 +0200)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git tags/lockdep-for-tip.2025.07.16
for you to fetch changes up to 7a3cedafccf8e7d038ad4cfec5b38052647ceac5:
lockdep: Speed up lockdep_unregister_key() with expedited RCU synchronization (2025-07-14 21:57:29 -0700)
----------------------------------------------------------------
Locking changes for v6.17:
- General
- Mark devm_mutex_init() as __must_check
- Add #[must_use] to Lock::try_lock()
- Remove OWNER_SPINNABLE in rwsem
- Remove redundant #ifdefs in mutex
- Lockdep
- Avoid returning struct in lock_stats()
- Change `static const` into enum for LOCKF_*_IRQ_*
- Temporarily use synchronize_rcu_expedited() in
lockdep_unregister_key() to speed things up.
----------------------------------------------------------------
Regards,
Boqun
Arnd Bergmann (2):
locking/lockdep: Avoid struct return in lock_stats()
locking/lockdep: Change 'static const' variables to enum values
Breno Leitao (1):
lockdep: Speed up lockdep_unregister_key() with expedited RCU synchronization
Jason Devers (1):
rust: sync: Add #[must_use] to Lock::try_lock()
Jinliang Zheng (1):
locking/rwsem: Use OWNER_NONSPINNABLE directly instead of OWNER_SPINNABLE
Ran Xiaokai (1):
locking/mutex: Remove redundant #ifdefs
Thomas Weißschuh (3):
spi: spi-nxp-fspi: Check return value of devm_mutex_init()
leds: lp8860: Check return value of devm_mutex_init()
locking/mutex: Mark devm_mutex_init() as __must_check
drivers/leds/leds-lp8860.c | 4 +++-
drivers/spi/spi-nxp-fspi.c | 4 +++-
include/linux/lockdep_types.h | 2 +-
include/linux/mutex.h | 11 +++++++----
kernel/locking/lockdep.c | 39 +++++++++++++++++++++-----------------
kernel/locking/lockdep_internals.h | 18 ++++++++++--------
kernel/locking/lockdep_proc.c | 2 +-
kernel/locking/mutex.c | 4 ----
kernel/locking/rwsem.c | 4 +---
rust/kernel/sync/lock.rs | 2 ++
10 files changed, 50 insertions(+), 40 deletions(-)
--
2.39.5 (Apple Git-154)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/9] spi: spi-nxp-fspi: Check return value of devm_mutex_init()
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
2025-07-16 14:48 ` [PATCH 2/9] leds: lp8860: " Boqun Feng
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney,
Thomas Weißschuh, Mark Brown, Boqun Feng
From: Thomas Weißschuh <linux@weissschuh.net>
devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will
be marked as unusable and trigger errors on usage.
Add the missed check.
Fixes: 48900813abd2 ("spi: spi-nxp-fspi: remove the goto in probe")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250617-must_check-devm_mutex_init-v7-1-d9e449f4d224@weissschuh.net
---
drivers/spi/spi-nxp-fspi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index e63c77e41823..f3d576505413 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -1273,7 +1273,9 @@ static int nxp_fspi_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "Failed to request irq\n");
- devm_mutex_init(dev, &f->lock);
+ ret = devm_mutex_init(dev, &f->lock);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to initialize lock\n");
ctlr->bus_num = -1;
ctlr->num_chipselect = NXP_FSPI_MAX_CHIPSELECT;
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/9] leds: lp8860: Check return value of devm_mutex_init()
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
2025-07-16 14:48 ` [PATCH 1/9] spi: spi-nxp-fspi: Check return value of devm_mutex_init() Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
2025-07-16 14:48 ` [PATCH 3/9] locking/mutex: Mark devm_mutex_init() as __must_check Boqun Feng
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney,
Thomas Weißschuh, Andrew Davis, Lee Jones, Boqun Feng
From: Thomas Weißschuh <linux@weissschuh.net>
devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
marked as unusable and trigger errors on usage.
Add the missed check.
Fixes: 87a59548af95 ("leds: lp8860: Use new mutex guards to cleanup function exits")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Andrew Davis <afd@ti.com>
Acked-by: Lee Jones <lee@kernel.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250617-must_check-devm_mutex_init-v7-2-d9e449f4d224@weissschuh.net
---
drivers/leds/leds-lp8860.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c
index 52b97c9f2a03..0962c00c215a 100644
--- a/drivers/leds/leds-lp8860.c
+++ b/drivers/leds/leds-lp8860.c
@@ -307,7 +307,9 @@ static int lp8860_probe(struct i2c_client *client)
led->client = client;
led->led_dev.brightness_set_blocking = lp8860_brightness_set;
- devm_mutex_init(&client->dev, &led->lock);
+ ret = devm_mutex_init(&client->dev, &led->lock);
+ if (ret)
+ return dev_err_probe(&client->dev, ret, "Failed to initialize lock\n");
led->regmap = devm_regmap_init_i2c(client, &lp8860_regmap_config);
if (IS_ERR(led->regmap)) {
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/9] locking/mutex: Mark devm_mutex_init() as __must_check
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
2025-07-16 14:48 ` [PATCH 1/9] spi: spi-nxp-fspi: Check return value of devm_mutex_init() Boqun Feng
2025-07-16 14:48 ` [PATCH 2/9] leds: lp8860: " Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
2025-07-16 14:48 ` [PATCH 4/9] rust: sync: Add #[must_use] to Lock::try_lock() Boqun Feng
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney,
Thomas Weißschuh, Andy Shevchenko, Bartosz Golaszewski,
Boqun Feng
From: Thomas Weißschuh <linux@weissschuh.net>
devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
marked as unusable and trigger errors on usage.
Enforce all callers check the return value through the compiler.
As devm_mutex_init() itself is a macro, it can not be annotated
directly. Annotate __devm_mutex_init() instead.
Unfortunately __must_check/warn_unused_result don't propagate through
statement expression. So move the statement expression into the argument
list of the call to __devm_mutex_init() through a helper macro.
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250617-must_check-devm_mutex_init-v7-3-d9e449f4d224@weissschuh.net
---
include/linux/mutex.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index a039fa8c1780..00afd341d293 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -126,11 +126,11 @@ do { \
#ifdef CONFIG_DEBUG_MUTEXES
-int __devm_mutex_init(struct device *dev, struct mutex *lock);
+int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock);
#else
-static inline int __devm_mutex_init(struct device *dev, struct mutex *lock)
+static inline int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock)
{
/*
* When CONFIG_DEBUG_MUTEXES is off mutex_destroy() is just a nop so
@@ -141,14 +141,17 @@ static inline int __devm_mutex_init(struct device *dev, struct mutex *lock)
#endif
-#define devm_mutex_init(dev, mutex) \
+#define __mutex_init_ret(mutex) \
({ \
typeof(mutex) mutex_ = (mutex); \
\
mutex_init(mutex_); \
- __devm_mutex_init(dev, mutex_); \
+ mutex_; \
})
+#define devm_mutex_init(dev, mutex) \
+ __devm_mutex_init(dev, __mutex_init_ret(mutex))
+
/*
* See kernel/locking/mutex.c for detailed documentation of these APIs.
* Also see Documentation/locking/mutex-design.rst.
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/9] rust: sync: Add #[must_use] to Lock::try_lock()
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
` (2 preceding siblings ...)
2025-07-16 14:48 ` [PATCH 3/9] locking/mutex: Mark devm_mutex_init() as __must_check Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
2025-07-16 14:48 ` [PATCH 5/9] locking/rwsem: Use OWNER_NONSPINNABLE directly instead of OWNER_SPINNABLE Boqun Feng
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney, Jason Devers,
Boqun Feng
From: Jason Devers <dev.json2@gmail.com>
The `Lock::try_lock()` function returns an `Option<Guard<...>>`, but it
currently does not issue a warning if the return value is unused.
To avoid potential bugs, the `#[must_use]` annotation is added to ensure
proper usage.
Note that `T` is `#[must_use]` but `Option<T>` is not.
For more context, see: https://github.com/rust-lang/rust/issues/71368.
Suggested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1133
Signed-off-by: Jason Devers <dev.json2@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20241212154753.139563-1-dev.json2@gmail.com
---
rust/kernel/sync/lock.rs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
index e82fa5be289c..27202beef90c 100644
--- a/rust/kernel/sync/lock.rs
+++ b/rust/kernel/sync/lock.rs
@@ -175,6 +175,8 @@ pub fn lock(&self) -> Guard<'_, T, B> {
/// Tries to acquire the lock.
///
/// Returns a guard that can be used to access the data protected by the lock if successful.
+ // `Option<T>` is not `#[must_use]` even if `T` is, thus the attribute is needed here.
+ #[must_use = "if unused, the lock will be immediately unlocked"]
pub fn try_lock(&self) -> Option<Guard<'_, T, B>> {
// SAFETY: The constructor of the type calls `init`, so the existence of the object proves
// that `init` was called.
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/9] locking/rwsem: Use OWNER_NONSPINNABLE directly instead of OWNER_SPINNABLE
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
` (3 preceding siblings ...)
2025-07-16 14:48 ` [PATCH 4/9] rust: sync: Add #[must_use] to Lock::try_lock() Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
2025-07-16 14:48 ` [PATCH 6/9] locking/lockdep: Avoid struct return in lock_stats() Boqun Feng
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney, Jinliang Zheng,
Boqun Feng
From: Jinliang Zheng <alexjlzheng@tencent.com>
After commit 7d43f1ce9dd0 ("locking/rwsem: Enable time-based spinning on
reader-owned rwsem"), OWNER_SPINNABLE contains all possible values except
OWNER_NONSPINNABLE, namely OWNER_NULL | OWNER_WRITER | OWNER_READER.
Therefore, it is better to use OWNER_NONSPINNABLE directly to determine
whether to exit optimistic spin.
And, remove useless OWNER_SPINNABLE to simplify the code.
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
Acked-by: Waiman Long <longman@redhat.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250610130158.4876-1-alexjlzheng@tencent.com
---
kernel/locking/rwsem.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 2ddb827e3bea..8572dba95af4 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -727,8 +727,6 @@ static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
return ret;
}
-#define OWNER_SPINNABLE (OWNER_NULL | OWNER_WRITER | OWNER_READER)
-
static inline enum owner_state
rwsem_owner_state(struct task_struct *owner, unsigned long flags)
{
@@ -835,7 +833,7 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem)
enum owner_state owner_state;
owner_state = rwsem_spin_on_owner(sem);
- if (!(owner_state & OWNER_SPINNABLE))
+ if (owner_state == OWNER_NONSPINNABLE)
break;
/*
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/9] locking/lockdep: Avoid struct return in lock_stats()
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
` (4 preceding siblings ...)
2025-07-16 14:48 ` [PATCH 5/9] locking/rwsem: Use OWNER_NONSPINNABLE directly instead of OWNER_SPINNABLE Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
2025-07-16 14:48 ` [PATCH 7/9] locking/lockdep: Change 'static const' variables to enum values Boqun Feng
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney, Arnd Bergmann,
Boqun Feng
From: Arnd Bergmann <arnd@arndb.de>
Returning a large structure from the lock_stats() function causes clang
to have multiple copies of it on the stack and copy between them, which
can end up exceeding the frame size warning limit:
kernel/locking/lockdep.c:300:25: error: stack frame size (1464) exceeds limit (1280) in 'lock_stats' [-Werror,-Wframe-larger-than]
300 | struct lock_class_stats lock_stats(struct lock_class *class)
Change the calling conventions to directly operate on the caller's copy,
which apparently is what gcc does already.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250610092941.2642847-1-arnd@kernel.org
---
include/linux/lockdep_types.h | 2 +-
kernel/locking/lockdep.c | 27 ++++++++++++---------------
kernel/locking/lockdep_proc.c | 2 +-
3 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
index 9f361d3ab9d9..eae115a26488 100644
--- a/include/linux/lockdep_types.h
+++ b/include/linux/lockdep_types.h
@@ -175,7 +175,7 @@ struct lock_class_stats {
unsigned long bounces[nr_bounce_types];
};
-struct lock_class_stats lock_stats(struct lock_class *class);
+void lock_stats(struct lock_class *class, struct lock_class_stats *stats);
void clear_lock_stats(struct lock_class *class);
#endif
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index dd2bbf73718b..0c941418a215 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -297,33 +297,30 @@ static inline void lock_time_add(struct lock_time *src, struct lock_time *dst)
dst->nr += src->nr;
}
-struct lock_class_stats lock_stats(struct lock_class *class)
+void lock_stats(struct lock_class *class, struct lock_class_stats *stats)
{
- struct lock_class_stats stats;
int cpu, i;
- memset(&stats, 0, sizeof(struct lock_class_stats));
+ memset(stats, 0, sizeof(struct lock_class_stats));
for_each_possible_cpu(cpu) {
struct lock_class_stats *pcs =
&per_cpu(cpu_lock_stats, cpu)[class - lock_classes];
- for (i = 0; i < ARRAY_SIZE(stats.contention_point); i++)
- stats.contention_point[i] += pcs->contention_point[i];
+ for (i = 0; i < ARRAY_SIZE(stats->contention_point); i++)
+ stats->contention_point[i] += pcs->contention_point[i];
- for (i = 0; i < ARRAY_SIZE(stats.contending_point); i++)
- stats.contending_point[i] += pcs->contending_point[i];
+ for (i = 0; i < ARRAY_SIZE(stats->contending_point); i++)
+ stats->contending_point[i] += pcs->contending_point[i];
- lock_time_add(&pcs->read_waittime, &stats.read_waittime);
- lock_time_add(&pcs->write_waittime, &stats.write_waittime);
+ lock_time_add(&pcs->read_waittime, &stats->read_waittime);
+ lock_time_add(&pcs->write_waittime, &stats->write_waittime);
- lock_time_add(&pcs->read_holdtime, &stats.read_holdtime);
- lock_time_add(&pcs->write_holdtime, &stats.write_holdtime);
+ lock_time_add(&pcs->read_holdtime, &stats->read_holdtime);
+ lock_time_add(&pcs->write_holdtime, &stats->write_holdtime);
- for (i = 0; i < ARRAY_SIZE(stats.bounces); i++)
- stats.bounces[i] += pcs->bounces[i];
+ for (i = 0; i < ARRAY_SIZE(stats->bounces); i++)
+ stats->bounces[i] += pcs->bounces[i];
}
-
- return stats;
}
void clear_lock_stats(struct lock_class *class)
diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index b52c07c4707c..1916db9aa46b 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -657,7 +657,7 @@ static int lock_stat_open(struct inode *inode, struct file *file)
if (!test_bit(idx, lock_classes_in_use))
continue;
iter->class = class;
- iter->stats = lock_stats(class);
+ lock_stats(class, &iter->stats);
iter++;
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/9] locking/lockdep: Change 'static const' variables to enum values
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
` (5 preceding siblings ...)
2025-07-16 14:48 ` [PATCH 6/9] locking/lockdep: Avoid struct return in lock_stats() Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
2025-07-16 14:48 ` [PATCH 8/9] locking/mutex: Remove redundant #ifdefs Boqun Feng
2025-07-16 14:48 ` [PATCH 9/9] lockdep: Speed up lockdep_unregister_key() with expedited RCU synchronization Boqun Feng
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney, Arnd Bergmann,
Andy Shevchenko, Boqun Feng
From: Arnd Bergmann <arnd@arndb.de>
gcc warns about 'static const' variables even in headers when building
with -Wunused-const-variables enabled:
In file included from kernel/locking/lockdep_proc.c:25:
kernel/locking/lockdep_internals.h:69:28: error: 'LOCKF_USED_IN_IRQ_READ' defined but not used [-Werror=unused-const-variable=]
69 | static const unsigned long LOCKF_USED_IN_IRQ_READ =
| ^~~~~~~~~~~~~~~~~~~~~~
kernel/locking/lockdep_internals.h:63:28: error: 'LOCKF_ENABLED_IRQ_READ' defined but not used [-Werror=unused-const-variable=]
63 | static const unsigned long LOCKF_ENABLED_IRQ_READ =
| ^~~~~~~~~~~~~~~~~~~~~~
kernel/locking/lockdep_internals.h:57:28: error: 'LOCKF_USED_IN_IRQ' defined but not used [-Werror=unused-const-variable=]
57 | static const unsigned long LOCKF_USED_IN_IRQ =
| ^~~~~~~~~~~~~~~~~
kernel/locking/lockdep_internals.h:51:28: error: 'LOCKF_ENABLED_IRQ' defined but not used [-Werror=unused-const-variable=]
51 | static const unsigned long LOCKF_ENABLED_IRQ =
| ^~~~~~~~~~~~~~~~~
This one is easy to avoid by changing the generated constant definition
into an equivalent enum.
Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250409122314.2848028-6-arnd@kernel.org
---
kernel/locking/lockdep_internals.h | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h
index 82156caf77d1..0e5e6ffe91a3 100644
--- a/kernel/locking/lockdep_internals.h
+++ b/kernel/locking/lockdep_internals.h
@@ -47,29 +47,31 @@ enum {
__LOCKF(USED_READ)
};
+enum {
#define LOCKDEP_STATE(__STATE) LOCKF_ENABLED_##__STATE |
-static const unsigned long LOCKF_ENABLED_IRQ =
+ LOCKF_ENABLED_IRQ =
#include "lockdep_states.h"
- 0;
+ 0,
#undef LOCKDEP_STATE
#define LOCKDEP_STATE(__STATE) LOCKF_USED_IN_##__STATE |
-static const unsigned long LOCKF_USED_IN_IRQ =
+ LOCKF_USED_IN_IRQ =
#include "lockdep_states.h"
- 0;
+ 0,
#undef LOCKDEP_STATE
#define LOCKDEP_STATE(__STATE) LOCKF_ENABLED_##__STATE##_READ |
-static const unsigned long LOCKF_ENABLED_IRQ_READ =
+ LOCKF_ENABLED_IRQ_READ =
#include "lockdep_states.h"
- 0;
+ 0,
#undef LOCKDEP_STATE
#define LOCKDEP_STATE(__STATE) LOCKF_USED_IN_##__STATE##_READ |
-static const unsigned long LOCKF_USED_IN_IRQ_READ =
+ LOCKF_USED_IN_IRQ_READ =
#include "lockdep_states.h"
- 0;
+ 0,
#undef LOCKDEP_STATE
+};
#define LOCKF_ENABLED_IRQ_ALL (LOCKF_ENABLED_IRQ | LOCKF_ENABLED_IRQ_READ)
#define LOCKF_USED_IN_IRQ_ALL (LOCKF_USED_IN_IRQ | LOCKF_USED_IN_IRQ_READ)
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 8/9] locking/mutex: Remove redundant #ifdefs
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
` (6 preceding siblings ...)
2025-07-16 14:48 ` [PATCH 7/9] locking/lockdep: Change 'static const' variables to enum values Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
2025-07-16 14:48 ` [PATCH 9/9] lockdep: Speed up lockdep_unregister_key() with expedited RCU synchronization Boqun Feng
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney, Ran Xiaokai,
Boqun Feng
From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
hung_task_{set,clear}_blocker() is already guarded by
CONFIG_DETECT_HUNG_TASK_BLOCKER in hung_task.h, So remove
the redudant check of #ifdef.
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Acked-by: Waiman Long <longman@redhat.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250704015218.359754-1-ranxiaokai627@163.com
---
kernel/locking/mutex.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index a39ecccbd106..d4210dc97b6a 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -191,9 +191,7 @@ static void
__mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
struct list_head *list)
{
-#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
hung_task_set_blocker(lock, BLOCKER_TYPE_MUTEX);
-#endif
debug_mutex_add_waiter(lock, waiter, current);
list_add_tail(&waiter->list, list);
@@ -209,9 +207,7 @@ __mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter)
__mutex_clear_flag(lock, MUTEX_FLAGS);
debug_mutex_remove_waiter(lock, waiter, current);
-#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
hung_task_clear_blocker();
-#endif
}
/*
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 9/9] lockdep: Speed up lockdep_unregister_key() with expedited RCU synchronization
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
` (7 preceding siblings ...)
2025-07-16 14:48 ` [PATCH 8/9] locking/mutex: Remove redundant #ifdefs Boqun Feng
@ 2025-07-16 14:48 ` Boqun Feng
8 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-07-16 14:48 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Will Deacon, Waiman Long, Miguel Ojeda, Alice Ryhl, linux-kernel,
rust-for-linux, Breno Leitao, Paul E. McKenney, Erik Lundgren,
Eric Dumazet, Boqun Feng
From: Breno Leitao <leitao@debian.org>
lockdep_unregister_key() is called from critical code paths, including
sections where rtnl_lock() is held. For example, when replacing a qdisc
in a network device, network egress traffic is disabled while
__qdisc_destroy() is called for every network queue.
If lockdep is enabled, __qdisc_destroy() calls lockdep_unregister_key(),
which gets blocked waiting for synchronize_rcu() to complete.
For example, a simple tc command to replace a qdisc could take 13
seconds:
# time /usr/sbin/tc qdisc replace dev eth0 root handle 0x1: mq
real 0m13.195s
user 0m0.001s
sys 0m2.746s
During this time, network egress is completely frozen while waiting for
RCU synchronization.
Use synchronize_rcu_expedited() instead to minimize the impact on
critical operations like network connectivity changes.
This improves 10x the function call to tc, when replacing the qdisc for
a network card.
# time /usr/sbin/tc qdisc replace dev eth0 root handle 0x1: mq
real 0m1.789s
user 0m0.000s
sys 0m1.613s
[boqun: Fixed the comment and add more information for the temporary
workaround, and add TODO information for hazptr]
Reported-by: Erik Lundgren <elundgren@meta.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250321-lockdep-v1-1-78b732d195fb@debian.org
---
kernel/locking/lockdep.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 0c941418a215..2d4c5bab5af8 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -6616,8 +6616,16 @@ void lockdep_unregister_key(struct lock_class_key *key)
if (need_callback)
call_rcu(&delayed_free.rcu_head, free_zapped_rcu);
- /* Wait until is_dynamic_key() has finished accessing k->hash_entry. */
- synchronize_rcu();
+ /*
+ * Wait until is_dynamic_key() has finished accessing k->hash_entry.
+ *
+ * Some operations like __qdisc_destroy() will call this in a debug
+ * kernel, and the network traffic is disabled while waiting, hence
+ * the delay of the wait matters in debugging cases. Currently use a
+ * synchronize_rcu_expedited() to speed up the wait at the cost of
+ * system IPIs. TODO: Replace RCU with hazptr for this.
+ */
+ synchronize_rcu_expedited();
}
EXPORT_SYMBOL_GPL(lockdep_unregister_key);
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-07-16 14:48 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 14:48 [GIT PULL] [PATCH 0/9] Locking changes for v6.17 Boqun Feng
2025-07-16 14:48 ` [PATCH 1/9] spi: spi-nxp-fspi: Check return value of devm_mutex_init() Boqun Feng
2025-07-16 14:48 ` [PATCH 2/9] leds: lp8860: " Boqun Feng
2025-07-16 14:48 ` [PATCH 3/9] locking/mutex: Mark devm_mutex_init() as __must_check Boqun Feng
2025-07-16 14:48 ` [PATCH 4/9] rust: sync: Add #[must_use] to Lock::try_lock() Boqun Feng
2025-07-16 14:48 ` [PATCH 5/9] locking/rwsem: Use OWNER_NONSPINNABLE directly instead of OWNER_SPINNABLE Boqun Feng
2025-07-16 14:48 ` [PATCH 6/9] locking/lockdep: Avoid struct return in lock_stats() Boqun Feng
2025-07-16 14:48 ` [PATCH 7/9] locking/lockdep: Change 'static const' variables to enum values Boqun Feng
2025-07-16 14:48 ` [PATCH 8/9] locking/mutex: Remove redundant #ifdefs Boqun Feng
2025-07-16 14:48 ` [PATCH 9/9] lockdep: Speed up lockdep_unregister_key() with expedited RCU synchronization Boqun Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).