On Mon, Dec 15, 2025 at 02:38:52PM +0100, Marco Elver wrote:

> Working on rebasing this to v6.19-rc1 and saw this new scoped seqlock
> abstraction. For that one I was able to make it work like I thought we
> could (below). Some awkwardness is required to make it work in
> for-loops, which only let you define variables with the same type.

> 
> diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
> index b5563dc83aba..5162962b4b26 100644
> --- a/include/linux/seqlock.h
> +++ b/include/linux/seqlock.h
> @@ -1249,6 +1249,7 @@ struct ss_tmp {
>  };
>  
>  static __always_inline void __scoped_seqlock_cleanup(struct ss_tmp *sst)
> +     __no_context_analysis
>  {
>       if (sst->lock)
>               spin_unlock(sst->lock);
> @@ -1278,6 +1279,7 @@ extern void __scoped_seqlock_bug(void);
>  
>  static __always_inline void
>  __scoped_seqlock_next(struct ss_tmp *sst, seqlock_t *lock, enum ss_state 
> target)
> +     __no_context_analysis
>  {
>       switch (sst->state) {
>       case ss_done:
> @@ -1320,9 +1322,18 @@ __scoped_seqlock_next(struct ss_tmp *sst, seqlock_t 
> *lock, enum ss_state target)
>       }
>  }
>  
> +/*
> + * Context analysis helper to release seqlock at the end of the for-scope; 
> the
> + * alias analysis of the compiler will recognize that the pointer @s is is an
> + * alias to @_seqlock passed to read_seqbegin(_seqlock) below.
> + */
> +static __always_inline void __scoped_seqlock_cleanup_ctx(struct ss_tmp **s)
> +     __releases_shared(*((seqlock_t **)s)) __no_context_analysis {}
> +
>  #define __scoped_seqlock_read(_seqlock, _target, _s)                 \
>       for (struct ss_tmp _s __cleanup(__scoped_seqlock_cleanup) =     \
> -          { .state = ss_lockless, .data = read_seqbegin(_seqlock) }; \
> +          { .state = ss_lockless, .data = read_seqbegin(_seqlock) }, \
> +          *__UNIQUE_ID(ctx) __cleanup(__scoped_seqlock_cleanup_ctx) = 
> (struct ss_tmp *)_seqlock; \
>            _s.state != ss_done;                                       \
>            __scoped_seqlock_next(&_s, _seqlock, _target))
>  

I am ever so confused.. where is the __acquire_shared(), in read_seqbegin() ?

Also, why do we need this second variable with cleanup; can't the
existing __scoped_seqlock_cleanup() get the __releases_shared()
attribute?

Reply via email to