All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Yury Norov <yury.norov@gmail.com>,
	Matthew Wilcox <willy@infradead.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Chris Li <sparse@chrisli.org>, Alice Ryhl <aliceryhl@google.com>,
	Andrew Ballance <andrewjballance@gmail.com>,
	linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	maple-tree@lists.infradead.org
Subject: Re: [PATCH 1/3] compiler.h: add ASSERT_STATIC_STORAGE()
Date: Sat, 12 Sep 2026 18:31:03 -0400	[thread overview]
Message-ID: <aqXSkthkUVJNu2FD@yury> (raw)
In-Reply-To: <20260911225749.8727d23eb76b93141f08e574@linux-foundation.org>

On Fri, Sep 11, 2026 at 10:57:49PM -0700, Andrew Morton wrote:
> On Fri, 11 Sep 2026 18:14:41 -0400 Yury Norov <yury.norov@gmail.com> wrote:
> 
> > Static lock initializers rely on a persistent object address when lockdep
> > assigns a lock-class key. Using such an initializer for an automatic local
> > object can compile successfully but disable lockdep on the first lock
> > acquisition.
> > 
> > Add ASSERT_STATIC_STORAGE() for declaration macros that require
> > static storage duration. It declares an unused static pointer initialized
> > with the object's address. An automatic local object's address is not a
> > valid static initializer, so the compiler rejects it.
> > 
> > Mirror the helper in tools/include/linux/compiler.h because the userspace
> > radix-tree tests include the kernel IDA and Maple Tree headers with the
> > tools compiler definitions.
> > 
> > For example:
> > 
> >   void example(void)
> >   {
> >           int object;
> >           ASSERT_STATIC_STORAGE(object);
> >   }
> > 
> > GCC reports:
> > 
> >   error: initializer element is not constant
> >     name##_storage_check = &(name)
> >                            ^
> >   note: in expansion of macro 'ASSERT_STATIC_STORAGE'
> >     ASSERT_STATIC_STORAGE(object);
> > 
> > File-scope objects and static local objects remain valid. The helper takes
> > an object identifier and must be used as a declaration after that object
> > has been declared.
> > 
> 
> Thanks, I'll queue it.
> 
> Sashiko wants the same treatment for a few other macros:
> 	https://sashiko.dev/#/patchset/20260911221444.1523311-1-ynorov@nvidia.com

Below is the list of candidates that my AI finds relevant:

 /* Primitive locks */
  DEFINE_RAW_SPINLOCK()
  DEFINE_SPINLOCK()                /* both non-RT and RT definitions */
  DEFINE_RWLOCK()                  /* both non-RT and RT definitions */
  DEFINE_MUTEX()                   /* both non-RT and RT definitions */
  DEFINE_RT_MUTEX()
  DECLARE_RWSEM()                  /* both non-RT and RT definitions */
  DEFINE_SEMAPHORE()
  DEFINE_SEQLOCK()

  /* Wait queues and completions — preserve _ONSTACK aliases */
  DECLARE_WAIT_QUEUE_HEAD()
  DECLARE_SWAIT_QUEUE_HEAD()
  DECLARE_COMPLETION()

  /* Containers */
  DEFINE_XARRAY_FLAGS()            /* covers DEFINE_XARRAY(),
                                   * DEFINE_XARRAY_ALLOC(),
                                   * DEFINE_XARRAY_ALLOC1() */
  DEFINE_IDA()                     /* already enforced */
  DEFINE_MTREE()                   /* already enforced */
  DEFINE_KLIST()

  /* Work and timers */
  DECLARE_WORK()
  DECLARE_DELAYED_WORK()
  DECLARE_DEFERRABLE_WORK()
  DEFINE_TIMER()
  DEFINE_KTHREAD_DELAYED_WORK()

  /* Other objects containing locks */
  DEFINE_RATELIMIT_STATE()
  ATOMIC_NOTIFIER_HEAD()
  BLOCKING_NOTIFIER_HEAD()
  DEFINE_RCU_SYNC()
  DEFINE_CTL_TABLE_POLL()
  DEFINE_BPF_STORAGE_CACHE()

  Lower-priority or configuration-dependent candidates:

  DEFINE_IDR()                    /* normal operations don't use embedded lock */
  RADIX_TREE()                    /* normal operations don't use embedded lock */

  __DEFINE_PERCPU_RWSEM()          /* covers DEFINE_PERCPU_RWSEM(),
                                   * DEFINE_STATIC_PERCPU_RWSEM() */

  __DEFINE_SRCU()                  /* Tree SRCU: covers all six wrappers */
  DEFINE_SRCU()                    /* Tiny SRCU: shared non-static declaration */

  _SRCU_NOTIFIER_HEAD()            /* covers SRCU_NOTIFIER_HEAD(),
                                   * SRCU_NOTIFIER_HEAD_STATIC() */

I planned to submit this hardening for them per the relevant subsystems
after at least landing the ASSERT_STATIC_STORAGE() in -next.

If you're OK to move that material through your tree all in one,
I can prepare it as a single series.

Thanks,
Yury


  reply	other threads:[~2026-09-12 22:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 22:14 [PATCH 0/3] Catch automatic storage in IDA and Maple Tree definitions Yury Norov
2026-09-11 22:14 ` [PATCH 1/3] compiler.h: add ASSERT_STATIC_STORAGE() Yury Norov
2026-09-12  5:57   ` Andrew Morton
2026-09-12 22:31     ` Yury Norov [this message]
2026-09-11 22:14 ` [PATCH 2/3] idr: assert static storage for DEFINE_IDA() Yury Norov
2026-09-11 22:14 ` [PATCH 3/3] maple_tree: assert static storage for DEFINE_MTREE() Yury Norov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aqXSkthkUVJNu2FD@yury \
    --to=ynorov@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=andrewjballance@gmail.com \
    --cc=liam@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=maple-tree@lists.infradead.org \
    --cc=sparse@chrisli.org \
    --cc=willy@infradead.org \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.