All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: elver@google.com
Cc: oe-kbuild-all@lists.linux.dev
Subject: [melver:ctx-analysis/dev 19/35] include/linux/cleanup.h:554:73: warning: cast to generic address space pointer from disjoint '__seg_fs' address space pointer
Date: Wed, 17 Dec 2025 11:54:08 +0800	[thread overview]
Message-ID: <202512171127.RpZhinvv-lkp@intel.com> (raw)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/melver/linux.git ctx-analysis/dev
head:   ce5acac3089f2dd72a384cbcd3f0e4ec28e9cf29
commit: 55ba795143c3f548c5d0d7ead143ebea3ee8405c [19/35] locking/local_lock: Support Clang's context analysis
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20251217/202512171127.RpZhinvv-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251217/202512171127.RpZhinvv-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512171127.RpZhinvv-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/jump_label.h:78,
                    from include/linux/dynamic_debug.h:6,
                    from include/linux/printk.h:621,
                    from include/asm-generic/bug.h:31,
                    from arch/x86/include/asm/bug.h:193,
                    from arch/x86/include/asm/alternative.h:9,
                    from arch/x86/include/asm/barrier.h:5,
                    from include/asm-generic/bitops/generic-non-atomic.h:7,
                    from include/linux/bitops.h:28,
                    from include/linux/kernel.h:23,
                    from include/linux/bit_spinlock.h:5,
                    from lib/test_context-analysis.c:7:
   lib/test_context-analysis.c: In function 'test_local_lock_guard':
>> include/linux/cleanup.h:554:73: warning: cast to generic address space pointer from disjoint '__seg_fs' address space pointer
     554 |         *__UNIQUE_ID(unlock) __cleanup(__class_##_name##_cleanup_ctx) = (void *)(_T)
         |                                                                         ^
   include/linux/local_lock.h:108:42: note: in expansion of macro 'WITH_LOCK_GUARD_1_ATTRS'
     108 | #define class_local_lock_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(local_lock, _T)
         |                                          ^~~~~~~~~~~~~~~~~~~~~~~
   include/linux/cleanup.h:300:17: note: in expansion of macro 'class_local_lock_constructor'
     300 |                 class_##_name##_constructor
         |                 ^~~~~~
   include/linux/cleanup.h:419:9: note: in expansion of macro 'CLASS'
     419 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^~~~~
   lib/test_context-analysis.c:502:11: note: in expansion of macro 'guard'
     502 |         { guard(local_lock)(&test_local_lock_data.lock); this_cpu_add(test_local_lock_data.counter, 1); }
         |           ^~~~~
>> include/linux/cleanup.h:554:73: warning: cast to generic address space pointer from disjoint '__seg_fs' address space pointer
     554 |         *__UNIQUE_ID(unlock) __cleanup(__class_##_name##_cleanup_ctx) = (void *)(_T)
         |                                                                         ^
   include/linux/local_lock.h:110:46: note: in expansion of macro 'WITH_LOCK_GUARD_1_ATTRS'
     110 | #define class_local_lock_irq_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(local_lock_irq, _T)
         |                                              ^~~~~~~~~~~~~~~~~~~~~~~
   include/linux/cleanup.h:300:17: note: in expansion of macro 'class_local_lock_irq_constructor'
     300 |                 class_##_name##_constructor
         |                 ^~~~~~
   include/linux/cleanup.h:419:9: note: in expansion of macro 'CLASS'
     419 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^~~~~
   lib/test_context-analysis.c:503:11: note: in expansion of macro 'guard'
     503 |         { guard(local_lock_irq)(&test_local_lock_data.lock); this_cpu_add(test_local_lock_data.counter, 1); }
         |           ^~~~~
>> include/linux/cleanup.h:554:73: warning: cast to generic address space pointer from disjoint '__seg_fs' address space pointer
     554 |         *__UNIQUE_ID(unlock) __cleanup(__class_##_name##_cleanup_ctx) = (void *)(_T)
         |                                                                         ^
   include/linux/local_lock.h:112:50: note: in expansion of macro 'WITH_LOCK_GUARD_1_ATTRS'
     112 | #define class_local_lock_irqsave_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(local_lock_irqsave, _T)
         |                                                  ^~~~~~~~~~~~~~~~~~~~~~~
   include/linux/cleanup.h:300:17: note: in expansion of macro 'class_local_lock_irqsave_constructor'
     300 |                 class_##_name##_constructor
         |                 ^~~~~~
   include/linux/cleanup.h:419:9: note: in expansion of macro 'CLASS'
     419 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^~~~~
   lib/test_context-analysis.c:504:11: note: in expansion of macro 'guard'
     504 |         { guard(local_lock_irqsave)(&test_local_lock_data.lock); this_cpu_add(test_local_lock_data.counter, 1); }
         |           ^~~~~
>> include/linux/cleanup.h:554:73: warning: cast to generic address space pointer from disjoint '__seg_fs' address space pointer
     554 |         *__UNIQUE_ID(unlock) __cleanup(__class_##_name##_cleanup_ctx) = (void *)(_T)
         |                                                                         ^
   include/linux/local_lock.h:114:52: note: in expansion of macro 'WITH_LOCK_GUARD_1_ATTRS'
     114 | #define class_local_lock_nested_bh_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(local_lock_nested_bh, _T)
         |                                                    ^~~~~~~~~~~~~~~~~~~~~~~
   include/linux/cleanup.h:300:17: note: in expansion of macro 'class_local_lock_nested_bh_constructor'
     300 |                 class_##_name##_constructor
         |                 ^~~~~~
   include/linux/cleanup.h:419:9: note: in expansion of macro 'CLASS'
     419 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^~~~~
   lib/test_context-analysis.c:505:11: note: in expansion of macro 'guard'
     505 |         { guard(local_lock_nested_bh)(&test_local_lock_data.lock); this_cpu_add(test_local_lock_data.counter, 1); }
         |           ^~~~~


vim +/__seg_fs +554 include/linux/cleanup.h

5acc03642ea67f Marco Elver 2025-01-17  518  
5acc03642ea67f Marco Elver 2025-01-17  519  /*
5acc03642ea67f Marco Elver 2025-01-17  520   * To support Context Analysis, we need to allow the compiler to see the
5acc03642ea67f Marco Elver 2025-01-17  521   * acquisition and release of the context lock. However, the "cleanup" helpers
5acc03642ea67f Marco Elver 2025-01-17  522   * wrap the lock in a struct passed through seperate helper functions, which
5acc03642ea67f Marco Elver 2025-01-17  523   * hides the lock alias from the compiler (no inter-procedural analysis).
5acc03642ea67f Marco Elver 2025-01-17  524   *
5acc03642ea67f Marco Elver 2025-01-17  525   * To make it work, we introduce an explicit alias to the context lock instance
5acc03642ea67f Marco Elver 2025-01-17  526   * that is "cleaned" up with a separate cleanup helper. This helper is a dummy
5acc03642ea67f Marco Elver 2025-01-17  527   * function that does nothing at runtime, but has the "_unlock" attribute to
5acc03642ea67f Marco Elver 2025-01-17  528   * tell the compiler what happens at the end of the scope.
5acc03642ea67f Marco Elver 2025-01-17  529   *
5acc03642ea67f Marco Elver 2025-01-17  530   * To generalize the pattern, the WITH_LOCK_GUARD_1_ATTRS() macro should be used
5acc03642ea67f Marco Elver 2025-01-17  531   * to redefine the constructor, which then also creates the alias variable with
5acc03642ea67f Marco Elver 2025-01-17  532   * the right "cleanup" attribute, *after* DECLARE_LOCK_GUARD_1_ATTRS() has been
5acc03642ea67f Marco Elver 2025-01-17  533   * used.
5acc03642ea67f Marco Elver 2025-01-17  534   *
5acc03642ea67f Marco Elver 2025-01-17  535   * Example usage:
5acc03642ea67f Marco Elver 2025-01-17  536   *
5acc03642ea67f Marco Elver 2025-01-17  537   *   DECLARE_LOCK_GUARD_1_ATTRS(mutex, __acquires(_T), __releases(*(struct mutex **)_T))
5acc03642ea67f Marco Elver 2025-01-17  538   *   #define class_mutex_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex, _T)
5acc03642ea67f Marco Elver 2025-01-17  539   *
5acc03642ea67f Marco Elver 2025-01-17  540   * Note: To support the for-loop based scoped helpers, the auxiliary variable
5acc03642ea67f Marco Elver 2025-01-17  541   * must be a pointer to the "class" type because it is defined in the same
5acc03642ea67f Marco Elver 2025-01-17  542   * statement as the guard variable. However, we initialize it with the lock
5acc03642ea67f Marco Elver 2025-01-17  543   * pointer (despite the type mismatch, the compiler's alias analysis still works
5acc03642ea67f Marco Elver 2025-01-17  544   * as expected). The "_unlock" attribute receives a pointer to the auxiliary
5acc03642ea67f Marco Elver 2025-01-17  545   * variable (a double pointer to the class type), and must be cast and
5acc03642ea67f Marco Elver 2025-01-17  546   * dereferenced appropriately.
5acc03642ea67f Marco Elver 2025-01-17  547   */
5acc03642ea67f Marco Elver 2025-01-17  548  #define DECLARE_LOCK_GUARD_1_ATTRS(_name, _lock, _unlock)		\
5acc03642ea67f Marco Elver 2025-01-17  549  static inline class_##_name##_t class_##_name##_constructor(lock_##_name##_t *_T) _lock;\
5acc03642ea67f Marco Elver 2025-01-17  550  static __always_inline void __class_##_name##_cleanup_ctx(class_##_name##_t **_T) \
5acc03642ea67f Marco Elver 2025-01-17  551  	__no_context_analysis _unlock { }
5acc03642ea67f Marco Elver 2025-01-17  552  #define WITH_LOCK_GUARD_1_ATTRS(_name, _T)				\
5acc03642ea67f Marco Elver 2025-01-17  553  	class_##_name##_constructor(_T),				\
5acc03642ea67f Marco Elver 2025-01-17 @554  	*__UNIQUE_ID(unlock) __cleanup(__class_##_name##_cleanup_ctx) = (void *)(_T)
5acc03642ea67f Marco Elver 2025-01-17  555  

:::::: The code at line 554 was first introduced by commit
:::::: 5acc03642ea67f590f3c0995602631339d26ec01 cleanup: Basic compatibility with context analysis

:::::: TO: Marco Elver <elver@google.com>
:::::: CC: Marco Elver <elver@google.com>

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

                 reply	other threads:[~2025-12-17  3:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=202512171127.RpZhinvv-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=elver@google.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    /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.