All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: kernel test robot <lkp@intel.com>, Ian Rogers <irogers@google.com>
Cc: oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org,
	x86@kernel.org, sparse@chrisli.org, linux-sparse@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Marco Elver <elver@google.com>
Subject: Re: [tip:timers/vdso 12/14] net/rds/ib_cm.c:96:35: sparse: sparse: incorrect type in argument 1 (different modifiers)
Date: Thu, 15 Jan 2026 20:28:51 +0100	[thread overview]
Message-ID: <87v7h23cb0.ffs@tglx> (raw)
In-Reply-To: <202601150001.sKSN644a-lkp@intel.com>

On Thu, Jan 15 2026 at 00:36, kernel test robot wrote:

Cc+ sparse folks.

> sparse warnings: (new ones prefixed by >>)
>>> net/rds/ib_cm.c:96:35: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected void * @@     got restricted __be64 const * @@
>    net/rds/ib_cm.c:96:35: sparse:     expected void *
>    net/rds/ib_cm.c:96:35: sparse:     got restricted __be64 const *
>    net/rds/ib_cm.c:103:27: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected void * @@     got restricted __be64 const * @@
>    net/rds/ib_cm.c:103:27: sparse:     expected void *
>    net/rds/ib_cm.c:103:27: sparse:     got restricted __be64 const *

After staring a while at it, it turns out that get_unaligned_t(), which
uses __unqual_scalar_typeof() to get an unqualified type makes sparse
unhappy when the data type is __be64 (or any other __beNN variant).

__beNN is annotated with __attribute__((bitwise)) when sparse is invoked
(#ifdef CHECKER). That allows sparse to detect incompatible math
operations with __beNN variables.

That annotation also causes the type comparison in the sparse _Generic()
evaluation to fail so that it ends up with the default, i.e. the
original qualified type of a 'const __beNN' pointer. That then ends up as
the first pointer argument to builtin_memcpy(), which obviously causes
the above sparse warnings.

The easiest solution would be to force cast the pointer to void * when
CHECKER is defined, but that reduces coverage.

I've come up with the below, but it's clearly a hack... __CAST_SPARSE()
is required as sparse otherwise complains about storing __u64 in __be64.

Thanks,

        tglx
---
 include/linux/compiler_types.h |   10 ++++++++++
 include/vdso/unaligned.h       |   16 +++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -577,6 +577,15 @@ struct ftrace_likely_data {
 		unsigned type:	(unsigned type)0,			\
 		signed type:	(signed type)0
 
+#ifdef __CHECKER__
+#define __be_types_expr_cases()						\
+	__be16: (__u16)0,						\
+	__be32: (__u32)0,						\
+	__be64: (__u64)0,
+#else
+#define __be_types_expr_cases()
+#endif
+
 #define __unqual_scalar_typeof(x) typeof(				\
 		_Generic((x),						\
 			 char:	(char)0,				\
@@ -585,6 +594,7 @@ struct ftrace_likely_data {
 			 __scalar_type_to_expr_cases(int),		\
 			 __scalar_type_to_expr_cases(long),		\
 			 __scalar_type_to_expr_cases(long long),	\
+			 __be_types_expr_cases()			\
 			 default: (x)))
 
 /* Is this type a native word size -- useful for atomic operations */
--- a/include/vdso/unaligned.h
+++ b/include/vdso/unaligned.h
@@ -4,6 +4,12 @@
 
 #include <linux/compiler_types.h>
 
+#ifdef __CHECKER__
+#define __CAST_SPARSE(type) (type __force)
+#else
+#define __CAST_SPARSE(type)
+#endif
+
 /**
  * __get_unaligned_t - read an unaligned value from memory.
  * @type:	the type to load from the pointer.
@@ -17,12 +23,12 @@
  * expression rather than type, a pointer is used to avoid warnings about mixing
  * the use of 0 and NULL. The void* cast silences ubsan warnings.
  */
-#define __get_unaligned_t(type, ptr) ({					\
-	type *__get_unaligned_ctrl_type __always_unused = NULL;		\
+#define __get_unaligned_t(type, ptr) ({						\
+	type *__get_unaligned_ctrl_type __always_unused = NULL;			\
 	__unqual_scalar_typeof(*__get_unaligned_ctrl_type) __get_unaligned_val; \
-	__builtin_memcpy(&__get_unaligned_val, (void *)(ptr),		\
-			 sizeof(__get_unaligned_val));			\
-	__get_unaligned_val;						\
+	__builtin_memcpy(&__get_unaligned_val, (void *)(ptr),			\
+			 sizeof(__get_unaligned_val));				\
+	__CAST_SPARSE(type) __get_unaligned_val;				\
 })
 
 /**




    

      

  parent reply	other threads:[~2026-01-15 19:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-14 16:36 [tip:timers/vdso 12/14] net/rds/ib_cm.c:96:35: sparse: sparse: incorrect type in argument 1 (different modifiers) kernel test robot
2026-01-14 17:51 ` Ian Rogers
2026-01-14 20:04   ` Thomas Gleixner
2026-01-14 21:03     ` Ian Rogers
2026-01-14 21:27       ` Thomas Gleixner
2026-01-14 21:42         ` Ian Rogers
2026-01-15 19:28 ` Thomas Gleixner [this message]
2026-01-15 21:11   ` Peter Zijlstra
2026-01-15 21:19     ` Linus Torvalds
2026-01-15 21:30       ` Peter Zijlstra
2026-01-15 23:03         ` Linus Torvalds
2026-01-16  8:28           ` Peter Zijlstra
2026-01-15 23:01     ` Thomas Gleixner
2026-01-16 11:25       ` Thomas Gleixner
2026-01-16 18:18         ` [PATCH] compiler: Use __typeof_unqual__() for __unqual_scalar_typeof() Thomas Gleixner
2026-01-17  5:25           ` Ian Rogers
2026-01-17 21:25           ` [tip: timers/vdso] " tip-bot2 for Peter Zijlstra
2026-01-18  9:38           ` tip-bot2 for Peter Zijlstra
2026-02-25  8:15           ` [PATCH] " Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2026-01-14  7:13 [tip:timers/vdso 12/14] net/rds/ib_cm.c:96:35: sparse: sparse: incorrect type in argument 1 (different modifiers) kernel test robot

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=87v7h23cb0.ffs@tglx \
    --to=tglx@kernel.org \
    --cc=elver@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=sparse@chrisli.org \
    --cc=x86@kernel.org \
    /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.