mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:24:47 +01:00
Locking updates for v6.20:
Lock debugging:
- Implement compiler-driven static analysis locking context
checking, using the upcoming Clang 22 compiler's context
analysis features. (Marco Elver)
We removed Sparse context analysis support, because prior to
removal even a defconfig kernel produced 1,700+ context
tracking Sparse warnings, the overwhelming majority of which
are false positives. On an allmodconfig kernel the number of
false positive context tracking Sparse warnings grows to
over 5,200... On the plus side of the balance actual locking
bugs found by Sparse context analysis is also rather ... sparse:
I found only 3 such commits in the last 3 years. So the
rate of false positives and the maintenance overhead is
rather high and there appears to be no active policy in
place to achieve a zero-warnings baseline to move the
annotations & fixers to developers who introduce new code.
Clang context analysis is more complete and more aggressive
in trying to find bugs, at least in principle. Plus it has
a different model to enabling it: it's enabled subsystem by
subsystem, which results in zero warnings on all relevant
kernel builds (as far as our testing managed to cover it).
Which allowed us to enable it by default, similar to other
compiler warnings, with the expectation that there are no
warnings going forward. This enforces a zero-warnings baseline
on clang-22+ builds. (Which are still limited in distribution,
admittedly.)
Hopefully the Clang approach can lead to a more maintainable
zero-warnings status quo and policy, with more and more
subsystems and drivers enabling the feature. Context tracking
can be enabled for all kernel code via WARN_CONTEXT_ANALYSIS_ALL=y
(default disabled), but this will generate a lot of false positives.
( Having said that, Sparse support could still be added back,
if anyone is interested - the removal patch is still
relatively straightforward to revert at this stage. )
Rust integration updates: (Alice Ryhl, Fujita Tomonori, Boqun Feng)
- Add support for Atomic<i8/i16/bool> and replace most Rust native
AtomicBool usages with Atomic<bool>
- Clean up LockClassKey and improve its documentation
- Add missing Send and Sync trait implementation for SetOnce
- Make ARef Unpin as it is supposed to be
- Add __rust_helper to a few Rust helpers as a preparation for
helper LTO
- Inline various lock related functions to avoid additional
function calls.
WW mutexes:
- Extend ww_mutex tests and other test-ww_mutex updates (John Stultz)
Misc fixes and cleanups:
- rcu: Mark lockdep_assert_rcu_helper() __always_inline
(Arnd Bergmann)
- locking/local_lock: Include more missing headers (Peter Zijlstra)
- seqlock: fix scoped_seqlock_read kernel-doc (Randy Dunlap)
- rust: sync: Replace `kernel::c_str!` with C-Strings
(Tamir Duberstein)
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-----BEGIN PGP SIGNATURE-----
iQJFBAABCgAvFiEEBpT5eoXrXCwVQwEKEnMQ0APhK1gFAmmIXiURHG1pbmdvQGtl
cm5lbC5vcmcACgkQEnMQ0APhK1gH+A/9GX5UmU6+HuDfDrCtXm9GDve6wkwahvcW
jLDxOYjs764I2BhyjZnjKjyF5zw60hbykem7Wcf5EV2YH30nM4XRgEWVJfkr1UAI
Pra415X4DdOzZ6qYQIpO8Udt1LtR7BMSaXITVLJaLicxEoOVtq3SKxjqyhCFs7UW
MfJdqleB+RMLqq3LlzgB4l43eKk1xyeHh+oQwI0RSxuIpVZme3p4TObnCKjIWnK7
Ihd+dkgC852WBjANgNL7F/sd5UsF5QX3wjtOrLhMKvkIgTPdXln0g398pivjN/G/
Kpnw18SFeb159JfJu8eMotsYvVnQ0D5aOcTBfL4qvOHCImhpcu2s6ik9BcXqt2yT
8IiuWk9xEM3Ok+I/I4ClT5cf5GYpyigV2QsXxn+IjDX5Na8v4zlHh0r8SElP8fOt
7dpQx7iw8UghAib3AzA3suN78Oh39m8l5BNobj7LAjnqOQcVvoPo4o7/48ntuH7A
38EucFrXfxQBMfGbMwvxEmgYuX7MyVfQLaPE06MHy1BkZkffT8Um38TB0iNtZmtf
WUx01yLKWYspehlwFi319uVI4/Zp7FnTfqa5uKv1oSXVdL9vZojSXUzrgDV7FVqT
Z4xAAw/kwNHpUG7y0zNOqd6PukovG1t+CjbLvK+eHPwc5c0vEGG2oTRAfEvvP1z/
kesYDmCyJnk=
=N1gA
-----END PGP SIGNATURE-----
Merge tag 'locking-core-2026-02-08' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking updates from Ingo Molnar:
"Lock debugging:
- Implement compiler-driven static analysis locking context checking,
using the upcoming Clang 22 compiler's context analysis features
(Marco Elver)
We removed Sparse context analysis support, because prior to
removal even a defconfig kernel produced 1,700+ context tracking
Sparse warnings, the overwhelming majority of which are false
positives. On an allmodconfig kernel the number of false positive
context tracking Sparse warnings grows to over 5,200... On the plus
side of the balance actual locking bugs found by Sparse context
analysis is also rather ... sparse: I found only 3 such commits in
the last 3 years. So the rate of false positives and the
maintenance overhead is rather high and there appears to be no
active policy in place to achieve a zero-warnings baseline to move
the annotations & fixers to developers who introduce new code.
Clang context analysis is more complete and more aggressive in
trying to find bugs, at least in principle. Plus it has a different
model to enabling it: it's enabled subsystem by subsystem, which
results in zero warnings on all relevant kernel builds (as far as
our testing managed to cover it). Which allowed us to enable it by
default, similar to other compiler warnings, with the expectation
that there are no warnings going forward. This enforces a
zero-warnings baseline on clang-22+ builds (Which are still limited
in distribution, admittedly)
Hopefully the Clang approach can lead to a more maintainable
zero-warnings status quo and policy, with more and more subsystems
and drivers enabling the feature. Context tracking can be enabled
for all kernel code via WARN_CONTEXT_ANALYSIS_ALL=y (default
disabled), but this will generate a lot of false positives.
( Having said that, Sparse support could still be added back,
if anyone is interested - the removal patch is still
relatively straightforward to revert at this stage. )
Rust integration updates: (Alice Ryhl, Fujita Tomonori, Boqun Feng)
- Add support for Atomic<i8/i16/bool> and replace most Rust native
AtomicBool usages with Atomic<bool>
- Clean up LockClassKey and improve its documentation
- Add missing Send and Sync trait implementation for SetOnce
- Make ARef Unpin as it is supposed to be
- Add __rust_helper to a few Rust helpers as a preparation for
helper LTO
- Inline various lock related functions to avoid additional function
calls
WW mutexes:
- Extend ww_mutex tests and other test-ww_mutex updates (John
Stultz)
Misc fixes and cleanups:
- rcu: Mark lockdep_assert_rcu_helper() __always_inline (Arnd
Bergmann)
- locking/local_lock: Include more missing headers (Peter Zijlstra)
- seqlock: fix scoped_seqlock_read kernel-doc (Randy Dunlap)
- rust: sync: Replace `kernel::c_str!` with C-Strings (Tamir
Duberstein)"
* tag 'locking-core-2026-02-08' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (90 commits)
locking/rwlock: Fix write_trylock_irqsave() with CONFIG_INLINE_WRITE_TRYLOCK
rcu: Mark lockdep_assert_rcu_helper() __always_inline
compiler-context-analysis: Remove __assume_ctx_lock from initializers
tomoyo: Use scoped init guard
crypto: Use scoped init guard
kcov: Use scoped init guard
compiler-context-analysis: Introduce scoped init guards
cleanup: Make __DEFINE_LOCK_GUARD handle commas in initializers
seqlock: fix scoped_seqlock_read kernel-doc
tools: Update context analysis macros in compiler_types.h
rust: sync: Replace `kernel::c_str!` with C-Strings
rust: sync: Inline various lock related methods
rust: helpers: Move #define __rust_helper out of atomic.c
rust: wait: Add __rust_helper to helpers
rust: time: Add __rust_helper to helpers
rust: task: Add __rust_helper to helpers
rust: sync: Add __rust_helper to helpers
rust: refcount: Add __rust_helper to helpers
rust: rcu: Add __rust_helper to helpers
rust: processor: Add __rust_helper to helpers
...
This commit is contained in:
commit
0923fd0419
144 changed files with 3233 additions and 872 deletions
|
|
@ -3,6 +3,8 @@
|
|||
# Cryptographic API
|
||||
#
|
||||
|
||||
CONTEXT_ANALYSIS := y
|
||||
|
||||
obj-$(CONFIG_CRYPTO) += crypto.o
|
||||
crypto-y := api.o cipher.o
|
||||
|
||||
|
|
|
|||
|
|
@ -443,8 +443,8 @@ int crypto_acomp_alloc_streams(struct crypto_acomp_streams *s)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_acomp_alloc_streams);
|
||||
|
||||
struct crypto_acomp_stream *crypto_acomp_lock_stream_bh(
|
||||
struct crypto_acomp_streams *s) __acquires(stream)
|
||||
struct crypto_acomp_stream *_crypto_acomp_lock_stream_bh(
|
||||
struct crypto_acomp_streams *s)
|
||||
{
|
||||
struct crypto_acomp_stream __percpu *streams = s->streams;
|
||||
int cpu = raw_smp_processor_id();
|
||||
|
|
@ -463,7 +463,7 @@ struct crypto_acomp_stream *crypto_acomp_lock_stream_bh(
|
|||
spin_lock(&ps->lock);
|
||||
return ps;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_acomp_lock_stream_bh);
|
||||
EXPORT_SYMBOL_GPL(_crypto_acomp_lock_stream_bh);
|
||||
|
||||
void acomp_walk_done_src(struct acomp_walk *walk, int used)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -244,6 +244,7 @@ EXPORT_SYMBOL_GPL(crypto_remove_spawns);
|
|||
|
||||
static void crypto_alg_finish_registration(struct crypto_alg *alg,
|
||||
struct list_head *algs_to_put)
|
||||
__must_hold(&crypto_alg_sem)
|
||||
{
|
||||
struct crypto_alg *q;
|
||||
|
||||
|
|
@ -299,6 +300,7 @@ static struct crypto_larval *crypto_alloc_test_larval(struct crypto_alg *alg)
|
|||
|
||||
static struct crypto_larval *
|
||||
__crypto_register_alg(struct crypto_alg *alg, struct list_head *algs_to_put)
|
||||
__must_hold(&crypto_alg_sem)
|
||||
{
|
||||
struct crypto_alg *q;
|
||||
struct crypto_larval *larval;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ EXPORT_SYMBOL_GPL(crypto_mod_put);
|
|||
|
||||
static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type,
|
||||
u32 mask)
|
||||
__must_hold_shared(&crypto_alg_sem)
|
||||
{
|
||||
struct crypto_alg *q, *alg = NULL;
|
||||
int best = -2;
|
||||
|
|
|
|||
|
|
@ -453,8 +453,8 @@ struct crypto_engine *crypto_engine_alloc_init_and_set(struct device *dev,
|
|||
snprintf(engine->name, sizeof(engine->name),
|
||||
"%s-engine", dev_name(dev));
|
||||
|
||||
guard(spinlock_init)(&engine->queue_lock);
|
||||
crypto_init_queue(&engine->queue, qlen);
|
||||
spin_lock_init(&engine->queue_lock);
|
||||
|
||||
engine->kworker = kthread_run_worker(0, "%s", engine->name);
|
||||
if (IS_ERR(engine->kworker)) {
|
||||
|
|
|
|||
|
|
@ -231,6 +231,7 @@ static inline unsigned short drbg_sec_strength(drbg_flag_t flags)
|
|||
*/
|
||||
static bool drbg_fips_continuous_test(struct drbg_state *drbg,
|
||||
const unsigned char *entropy)
|
||||
__must_hold(&drbg->drbg_mutex)
|
||||
{
|
||||
unsigned short entropylen = drbg_sec_strength(drbg->core->flags);
|
||||
|
||||
|
|
@ -845,6 +846,7 @@ static inline int __drbg_seed(struct drbg_state *drbg, struct list_head *seed,
|
|||
static inline void drbg_get_random_bytes(struct drbg_state *drbg,
|
||||
unsigned char *entropy,
|
||||
unsigned int entropylen)
|
||||
__must_hold(&drbg->drbg_mutex)
|
||||
{
|
||||
do
|
||||
get_random_bytes(entropy, entropylen);
|
||||
|
|
@ -852,6 +854,7 @@ static inline void drbg_get_random_bytes(struct drbg_state *drbg,
|
|||
}
|
||||
|
||||
static int drbg_seed_from_random(struct drbg_state *drbg)
|
||||
__must_hold(&drbg->drbg_mutex)
|
||||
{
|
||||
struct drbg_string data;
|
||||
LIST_HEAD(seedlist);
|
||||
|
|
@ -906,6 +909,7 @@ static bool drbg_nopr_reseed_interval_elapsed(struct drbg_state *drbg)
|
|||
*/
|
||||
static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers,
|
||||
bool reseed)
|
||||
__must_hold(&drbg->drbg_mutex)
|
||||
{
|
||||
int ret;
|
||||
unsigned char entropy[((32 + 16) * 2)];
|
||||
|
|
@ -1138,6 +1142,7 @@ err:
|
|||
static int drbg_generate(struct drbg_state *drbg,
|
||||
unsigned char *buf, unsigned int buflen,
|
||||
struct drbg_string *addtl)
|
||||
__must_hold(&drbg->drbg_mutex)
|
||||
{
|
||||
int len = 0;
|
||||
LIST_HEAD(addtllist);
|
||||
|
|
@ -1760,7 +1765,7 @@ static inline int __init drbg_healthcheck_sanity(void)
|
|||
if (!drbg)
|
||||
return -ENOMEM;
|
||||
|
||||
mutex_init(&drbg->drbg_mutex);
|
||||
guard(mutex_init)(&drbg->drbg_mutex);
|
||||
drbg->core = &drbg_cores[coreref];
|
||||
drbg->reseed_threshold = drbg_max_requests(drbg);
|
||||
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ enum {
|
|||
/* Maximum number of (rtattr) parameters for each template. */
|
||||
#define CRYPTO_MAX_ATTRS 32
|
||||
|
||||
extern struct list_head crypto_alg_list;
|
||||
extern struct rw_semaphore crypto_alg_sem;
|
||||
extern struct list_head crypto_alg_list __guarded_by(&crypto_alg_sem);
|
||||
extern struct blocking_notifier_head crypto_chain;
|
||||
|
||||
int alg_test(const char *driver, const char *alg, u32 type, u32 mask);
|
||||
|
|
|
|||
|
|
@ -19,17 +19,20 @@
|
|||
#include "internal.h"
|
||||
|
||||
static void *c_start(struct seq_file *m, loff_t *pos)
|
||||
__acquires_shared(&crypto_alg_sem)
|
||||
{
|
||||
down_read(&crypto_alg_sem);
|
||||
return seq_list_start(&crypto_alg_list, *pos);
|
||||
}
|
||||
|
||||
static void *c_next(struct seq_file *m, void *p, loff_t *pos)
|
||||
__must_hold_shared(&crypto_alg_sem)
|
||||
{
|
||||
return seq_list_next(p, &crypto_alg_list, pos);
|
||||
}
|
||||
|
||||
static void c_stop(struct seq_file *m, void *p)
|
||||
__releases_shared(&crypto_alg_sem)
|
||||
{
|
||||
up_read(&crypto_alg_sem);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
struct scomp_scratch {
|
||||
spinlock_t lock;
|
||||
union {
|
||||
void *src;
|
||||
unsigned long saddr;
|
||||
void *src __guarded_by(&lock);
|
||||
unsigned long saddr __guarded_by(&lock);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -38,8 +38,8 @@ static DEFINE_PER_CPU(struct scomp_scratch, scomp_scratch) = {
|
|||
};
|
||||
|
||||
static const struct crypto_type crypto_scomp_type;
|
||||
static int scomp_scratch_users;
|
||||
static DEFINE_MUTEX(scomp_lock);
|
||||
static int scomp_scratch_users __guarded_by(&scomp_lock);
|
||||
|
||||
static cpumask_t scomp_scratch_want;
|
||||
static void scomp_scratch_workfn(struct work_struct *work);
|
||||
|
|
@ -65,6 +65,7 @@ static void __maybe_unused crypto_scomp_show(struct seq_file *m,
|
|||
}
|
||||
|
||||
static void crypto_scomp_free_scratches(void)
|
||||
__context_unsafe(/* frees @scratch */)
|
||||
{
|
||||
struct scomp_scratch *scratch;
|
||||
int i;
|
||||
|
|
@ -99,7 +100,7 @@ static void scomp_scratch_workfn(struct work_struct *work)
|
|||
struct scomp_scratch *scratch;
|
||||
|
||||
scratch = per_cpu_ptr(&scomp_scratch, cpu);
|
||||
if (scratch->src)
|
||||
if (context_unsafe(scratch->src))
|
||||
continue;
|
||||
if (scomp_alloc_scratch(scratch, cpu))
|
||||
break;
|
||||
|
|
@ -109,6 +110,7 @@ static void scomp_scratch_workfn(struct work_struct *work)
|
|||
}
|
||||
|
||||
static int crypto_scomp_alloc_scratches(void)
|
||||
__context_unsafe(/* allocates @scratch */)
|
||||
{
|
||||
unsigned int i = cpumask_first(cpu_possible_mask);
|
||||
struct scomp_scratch *scratch;
|
||||
|
|
@ -137,7 +139,8 @@ unlock:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static struct scomp_scratch *scomp_lock_scratch(void) __acquires(scratch)
|
||||
#define scomp_lock_scratch(...) __acquire_ret(_scomp_lock_scratch(__VA_ARGS__), &__ret->lock)
|
||||
static struct scomp_scratch *_scomp_lock_scratch(void) __acquires_ret
|
||||
{
|
||||
int cpu = raw_smp_processor_id();
|
||||
struct scomp_scratch *scratch;
|
||||
|
|
@ -157,7 +160,7 @@ static struct scomp_scratch *scomp_lock_scratch(void) __acquires(scratch)
|
|||
}
|
||||
|
||||
static inline void scomp_unlock_scratch(struct scomp_scratch *scratch)
|
||||
__releases(scratch)
|
||||
__releases(&scratch->lock)
|
||||
{
|
||||
spin_unlock(&scratch->lock);
|
||||
}
|
||||
|
|
@ -169,8 +172,6 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
|
|||
bool src_isvirt = acomp_request_src_isvirt(req);
|
||||
bool dst_isvirt = acomp_request_dst_isvirt(req);
|
||||
struct crypto_scomp *scomp = *tfm_ctx;
|
||||
struct crypto_acomp_stream *stream;
|
||||
struct scomp_scratch *scratch;
|
||||
unsigned int slen = req->slen;
|
||||
unsigned int dlen = req->dlen;
|
||||
struct page *spage, *dpage;
|
||||
|
|
@ -230,13 +231,12 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
|
|||
} while (0);
|
||||
}
|
||||
|
||||
stream = crypto_acomp_lock_stream_bh(&crypto_scomp_alg(scomp)->streams);
|
||||
struct crypto_acomp_stream *stream = crypto_acomp_lock_stream_bh(&crypto_scomp_alg(scomp)->streams);
|
||||
|
||||
if (!src_isvirt && !src) {
|
||||
const u8 *src;
|
||||
struct scomp_scratch *scratch = scomp_lock_scratch();
|
||||
const u8 *src = scratch->src;
|
||||
|
||||
scratch = scomp_lock_scratch();
|
||||
src = scratch->src;
|
||||
memcpy_from_sglist(scratch->src, req->src, 0, slen);
|
||||
|
||||
if (dir)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue