locking/seqlock: Support Clang's context analysis

Add support for Clang's context analysis for seqlock_t.

Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251219154418.3592607-12-elver@google.com
This commit is contained in:
Marco Elver
2025-12-19 16:40:00 +01:00
committed by Peter Zijlstra
parent 370f0a345a
commit 8f8a55f49c
4 changed files with 91 additions and 4 deletions

View File

@@ -6,6 +6,7 @@
#include <linux/build_bug.h>
#include <linux/mutex.h>
#include <linux/seqlock.h>
#include <linux/spinlock.h>
/*
@@ -208,3 +209,52 @@ static void __used test_mutex_cond_guard(struct test_mutex_data *d)
d->counter++;
}
}
struct test_seqlock_data {
seqlock_t sl;
int counter __guarded_by(&sl);
};
static void __used test_seqlock_init(struct test_seqlock_data *d)
{
seqlock_init(&d->sl);
d->counter = 0;
}
static void __used test_seqlock_reader(struct test_seqlock_data *d)
{
unsigned int seq;
do {
seq = read_seqbegin(&d->sl);
(void)d->counter;
} while (read_seqretry(&d->sl, seq));
}
static void __used test_seqlock_writer(struct test_seqlock_data *d)
{
unsigned long flags;
write_seqlock(&d->sl);
d->counter++;
write_sequnlock(&d->sl);
write_seqlock_irq(&d->sl);
d->counter++;
write_sequnlock_irq(&d->sl);
write_seqlock_bh(&d->sl);
d->counter++;
write_sequnlock_bh(&d->sl);
write_seqlock_irqsave(&d->sl, flags);
d->counter++;
write_sequnlock_irqrestore(&d->sl, flags);
}
static void __used test_seqlock_scoped(struct test_seqlock_data *d)
{
scoped_seqlock_read (&d->sl, ss_lockless) {
(void)d->counter;
}
}