On Mon, 27 Apr 2026, Mikulas Patocka wrote:

> Hi
> 
> 
> On Mon, 13 Apr 2026, Benjamin Marzinski wrote:
> 
> > +   smp_mb__before_atomic();
> > +   atomic_inc(&ima->measure_idx);
> > +   wake_up_all(&ima->ima_wq);
> 
> There should be smp_mb__after_atomic() after atomic_inc() and before 
> wake_up_all(). Otherwise, the increment of atomic_inc could be moved 
> inside the wait queue spinlock in wake_up_all and executed after the wait 
> queue is checked for being empty.
> 
> Generally, the atomic variables and barriers are very hard to get right, 
> this is not performance-critical code that would justify the 
> complications, so I suggest to use a normal spinlock instead.
> 
> You can use something like:
>       spin_lock_irq(&ima->ima_wq.lock);
>       ima->measure_idx++;
>       wake_up_all_locked(&ima->ima_wq);
>       spin_unlock_irq(&ima->ima_wq.lock);
> 
> --- this would be obviously safe and easy to verify.
> 
> Mikulas

BTW. you can see "&ic->endio_wait.lock" in drivers/md/dm-integrity.c for 
an example, how to use this pattern.

Mikulas


Reply via email to