Re: [PATCH tip/locking/core] compiler-context-analysis: Support immediate acquisition after initialization
From: Steven Rostedt
Date: Wed Jan 21 2026 - 20:24:37 EST
On Fri, 16 Jan 2026 16:47:54 +0100
Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> struct obj {
> spinlock_t lock;
> int state __guarded_by(lock);
> };
>
> struct obj *create_obj(void)
> {
> struct obj *obj = kzmalloc(sizeof(*obj), GFP_KERNEL);
> if (!obj)
> return NULL;
>
> spin_lock_init(&obj->lock);
> obj->state = INIT_STATE; // error: ->state demands ->lock is held
> }
I haven't seen all the other approaches, but would a macro be able to hide
it with some kind of obfuscation from the compiler?
GUARD_INIT(obj->state, INIT_STATE);
which would be something like a WRITE_ONCE() macro. I'm not sure what
tooling there is to disable checks for a small bit of code like this.
-- Steve