Commit dc36d55d authored by Marco Elver's avatar Marco Elver Committed by Peter Zijlstra
Browse files

crypto: Enable context analysis



Enable context analysis for crypto subsystem.

This demonstrates a larger conversion to use Clang's context
analysis. The benefit is additional static checking of locking rules,
along with better documentation.

Note the use of the __acquire_ret macro how to define an API where a
function returns a pointer to an object (struct scomp_scratch) with a
lock held. Additionally, the analysis only resolves aliases where the
analysis unambiguously sees that a variable was not reassigned after
initialization, requiring minor code changes.

Signed-off-by: default avatarMarco Elver <elver@google.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251219154418.3592607-36-elver@google.com
parent 87335b61
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
# Cryptographic API
#

CONTEXT_ANALYSIS := y

obj-$(CONFIG_CRYPTO) += crypto.o
crypto-y := api.o cipher.o

+3 −3
Original line number Diff line number Diff line
@@ -449,8 +449,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();
@@ -469,7 +469,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)
{
+2 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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));

	crypto_init_queue(&engine->queue, qlen);
	spin_lock_init(&engine->queue_lock);
	crypto_init_queue(&engine->queue, qlen);

	engine->kworker = kthread_run_worker(0, "%s", engine->name);
	if (IS_ERR(engine->kworker)) {
Loading