Skip to contentSkip to conversation

net/rds/ib_cm.c:96:35: sparse: sparse: incorrect type in argument 1 (different modifiers)

PATCH Applied kernel test robot 7 participants 19 messages Jan 14 – Feb 25

Subsystems (3)
lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/vdso
head:   759a1f97373f25770cf438d9fb5f2bddf4d77a54
commit: e04a494143bab7ea804fe1ebe286701ee8288e4a [12/14] vdso: Switch get/put_unaligned() from packed struct to memcpy()
config: x86_64-randconfig-122-20260114 (https://download.01.org/0day-ci/archive/20260115/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260115/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

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 *

vim +96 net/rds/ib_cm.c

ec16227e14141e Andy Grover                  2009-02-24   69  
ec16227e14141e Andy Grover                  2009-02-24   70  /*
ec16227e14141e Andy Grover                  2009-02-24   71   * Connection established.
ec16227e14141e Andy Grover                  2009-02-24   72   * We get here for both outgoing and incoming connection.
ec16227e14141e Andy Grover                  2009-02-24   73   */
ec16227e14141e Andy Grover                  2009-02-24   74  void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_event *event)
ec16227e14141e Andy Grover                  2009-02-24   75  {
ec16227e14141e Andy Grover                  2009-02-24   76  	struct rds_ib_connection *ic = conn->c_transport_data;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   77  	const union rds_ib_conn_priv *dp = NULL;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   78  	__be64 ack_seq = 0;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   79  	__be32 credit = 0;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   80  	u8 major = 0;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   81  	u8 minor = 0;
ec16227e14141e Andy Grover                  2009-02-24   82  	int err;
ec16227e14141e Andy Grover                  2009-02-24   83  
ec16227e14141e Andy Grover                  2009-02-24   84  	dp = event->param.conn.private_data;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   85  	if (conn->c_isv6) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   86  		if (event->param.conn.private_data_len >=
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   87  		    sizeof(struct rds6_ib_connect_private)) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   88  			major = dp->ricp_v6.dp_protocol_major;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   89  			minor = dp->ricp_v6.dp_protocol_minor;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   90  			credit = dp->ricp_v6.dp_credit;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   91  			/* dp structure start is not guaranteed to be 8 bytes
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   92  			 * aligned.  Since dp_ack_seq is 64-bit extended load
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   93  			 * operations can be used so go through get_unaligned
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   94  			 * to avoid unaligned errors.
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   95  			 */
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  @96  			ack_seq = get_unaligned(&dp->ricp_v6.dp_ack_seq);
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   97  		}
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   98  	} else if (event->param.conn.private_data_len >=
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   99  		   sizeof(struct rds_ib_connect_private)) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  100  		major = dp->ricp_v4.dp_protocol_major;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  101  		minor = dp->ricp_v4.dp_protocol_minor;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  102  		credit = dp->ricp_v4.dp_credit;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  103  		ack_seq = get_unaligned(&dp->ricp_v4.dp_ack_seq);
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  104  	}
ec16227e14141e Andy Grover                  2009-02-24  105  
02a6a2592e41d2 Andy Grover                  2009-07-17  106  	/* make sure it isn't empty data */
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  107  	if (major) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  108  		rds_ib_set_protocol(conn, RDS_PROTOCOL(major, minor));
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  109  		rds_ib_set_flow_control(conn, be32_to_cpu(credit));
02a6a2592e41d2 Andy Grover                  2009-07-17  110  	}
ec16227e14141e Andy Grover                  2009-02-24  111  
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  112  	if (conn->c_version < RDS_PROTOCOL_VERSION) {
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  113  		if (conn->c_version != RDS_PROTOCOL_COMPAT_VERSION) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  114  			pr_notice("RDS/IB: Connection <%pI6c,%pI6c> version %u.%u no longer supported\n",
ff3f19a2f608ee Santosh Shilimkar            2016-03-14  115  				  &conn->c_laddr, &conn->c_faddr,
f147dd9ecabf23 Andy Grover                  2010-01-13  116  				  RDS_PROTOCOL_MAJOR(conn->c_version),
f147dd9ecabf23 Andy Grover                  2010-01-13  117  				  RDS_PROTOCOL_MINOR(conn->c_version));
f147dd9ecabf23 Andy Grover                  2010-01-13  118  			rds_conn_destroy(conn);
f147dd9ecabf23 Andy Grover                  2010-01-13  119  			return;
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  120  		}
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  121  	}
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  122  
fd261ce6a30e01 Santosh Shilimkar            2018-10-13  123  	pr_notice("RDS/IB: %s conn connected <%pI6c,%pI6c,%d> version %u.%u%s\n",
581d53c91cbf7b Santosh Shilimkar            2016-07-09  124  		  ic->i_active_side ? "Active" : "Passive",
fd261ce6a30e01 Santosh Shilimkar            2018-10-13  125  		  &conn->c_laddr, &conn->c_faddr, conn->c_tos,
ec16227e14141e Andy Grover                  2009-02-24  126  		  RDS_PROTOCOL_MAJOR(conn->c_version),
ec16227e14141e Andy Grover                  2009-02-24  127  		  RDS_PROTOCOL_MINOR(conn->c_version),
ec16227e14141e Andy Grover                  2009-02-24  128  		  ic->i_flowctl ? ", flow control" : "");
ec16227e14141e Andy Grover                  2009-02-24  129  
e0e6d062822529 Zhu Yanjun                   2019-08-23  130  	/* receive sl from the peer */
e0e6d062822529 Zhu Yanjun                   2019-08-23  131  	ic->i_sl = ic->i_cm_id->route.path_rec->sl;
e0e6d062822529 Zhu Yanjun                   2019-08-23  132  
cf657269d311d5 Santosh Shilimkar            2016-09-29  133  	atomic_set(&ic->i_cq_quiesce, 0);
cf657269d311d5 Santosh Shilimkar            2016-09-29  134  
581d53c91cbf7b Santosh Shilimkar            2016-07-09  135  	/* Init rings and fill recv. this needs to wait until protocol
581d53c91cbf7b Santosh Shilimkar            2016-07-09  136  	 * negotiation is complete, since ring layout is different
581d53c91cbf7b Santosh Shilimkar            2016-07-09  137  	 * from 3.1 to 4.1.
e11d912a7dd4df Andy Grover                  2009-07-17  138  	 */
e11d912a7dd4df Andy Grover                  2009-07-17  139  	rds_ib_send_init_ring(ic);
e11d912a7dd4df Andy Grover                  2009-07-17  140  	rds_ib_recv_init_ring(ic);
e11d912a7dd4df Andy Grover                  2009-07-17  141  	/* Post receive buffers - as a side effect, this will update
e11d912a7dd4df Andy Grover                  2009-07-17  142  	 * the posted credit count. */
73ce4317bf9832 [email protected] 2015-08-22  143  	rds_ib_recv_refill(conn, 1, GFP_KERNEL);
e11d912a7dd4df Andy Grover                  2009-07-17  144  
3e0249f9c05cb7 Zach Brown                   2010-05-18  145  	/* update ib_device with this local ipaddr */
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  146  	err = rds_ib_update_ipaddr(ic->rds_ibdev, &conn->c_laddr);
ec16227e14141e Andy Grover                  2009-02-24  147  	if (err)
3e0249f9c05cb7 Zach Brown                   2010-05-18  148  		printk(KERN_ERR "rds_ib_update_ipaddr failed (%d)\n",
3e0249f9c05cb7 Zach Brown                   2010-05-18  149  			err);
ec16227e14141e Andy Grover                  2009-02-24  150  
ec16227e14141e Andy Grover                  2009-02-24  151  	/* If the peer gave us the last packet it saw, process this as if
ec16227e14141e Andy Grover                  2009-02-24  152  	 * we had received a regular ACK. */
c0adf54a10903b shamir rabinovitch           2015-04-30  153  	if (dp) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  154  		if (ack_seq)
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  155  			rds_send_drop_acked(conn, be64_to_cpu(ack_seq),
c0adf54a10903b shamir rabinovitch           2015-04-30  156  					    NULL);
c0adf54a10903b shamir rabinovitch           2015-04-30  157  	}
ec16227e14141e Andy Grover                  2009-02-24  158  
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  159  	conn->c_proposed_version = conn->c_version;
ec16227e14141e Andy Grover                  2009-02-24  160  	rds_connect_complete(conn);
ec16227e14141e Andy Grover                  2009-02-24  161  }
ec16227e14141e Andy Grover                  2009-02-24  162  

:::::: The code at line 96 was first introduced by commit
:::::: eee2fa6ab3225192d6d894c54a6fb02ac9efdff6 rds: Changing IP address internal representation to struct in6_addr

:::::: TO: Ka-Cheong Poon <[email protected]> :::::: CC: David S. Miller <[email protected]>

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw
Quoted 24 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/vdso
head:   759a1f97373f25770cf438d9fb5f2bddf4d77a54
commit: e04a494143bab7ea804fe1ebe286701ee8288e4a [12/14] vdso: Switch get/put_unaligned() from packed struct to memcpy()
config: x86_64-randconfig-122-20260114 (https://download.01.org/0day-ci/archive/20260115/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260115/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

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 *

vim +96 net/rds/ib_cm.c

Quoted 9 lines
ec16227e14141e Andy Grover                  2009-02-24   69
ec16227e14141e Andy Grover                  2009-02-24   70  /*
ec16227e14141e Andy Grover                  2009-02-24   71   * Connection established.
ec16227e14141e Andy Grover                  2009-02-24   72   * We get here for both outgoing and incoming connection.
ec16227e14141e Andy Grover                  2009-02-24   73   */
ec16227e14141e Andy Grover                  2009-02-24   74  void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_event *event)
ec16227e14141e Andy Grover                  2009-02-24   75  {
ec16227e14141e Andy Grover                  2009-02-24   76     struct rds_ib_connection *ic = conn->c_transport_data;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   77     const union rds_ib_conn_priv *dp = NULL;

Here dp is a pointer to a constant value.

Quoted 11 lines
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   78     __be64 ack_seq = 0;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   79     __be32 credit = 0;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   80     u8 major = 0;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   81     u8 minor = 0;
ec16227e14141e Andy Grover                  2009-02-24   82     int err;
ec16227e14141e Andy Grover                  2009-02-24   83
ec16227e14141e Andy Grover                  2009-02-24   84     dp = event->param.conn.private_data;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   85     if (conn->c_isv6) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   86             if (event->param.conn.private_data_len >=
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   87                 sizeof(struct rds6_ib_connect_private)) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   88                     major = dp->ricp_v6.dp_protocol_major;
Quoted 8 lines
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   89                     minor = dp->ricp_v6.dp_protocol_minor;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   90                     credit = dp->ricp_v6.dp_credit;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   91                     /* dp structure start is not guaranteed to be 8 bytes
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   92                      * aligned.  Since dp_ack_seq is 64-bit extended load
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   93                      * operations can be used so go through get_unaligned
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   94                      * to avoid unaligned errors.
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   95                      */
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  @96                     ack_seq = get_unaligned(&dp->ricp_v6.dp_ack_seq);

This is a warned about get_unaligned reported here.

In my patch:

+/**
+ * __get_unaligned_t - read an unaligned value from memory.
+ * @type: the type to load from the pointer.
+ * @ptr: the pointer to load from.
+ *
+ * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
+ * from approaches like type punning that require -fno-strict-aliasing in order
+ * to be correct. As type may be const, use __unqual_scalar_typeof to map to a
+ * non-const type - you can't memcpy into a const type. The
+ * __get_unaligned_ctrl_type gives __unqual_scalar_typeof its required
+ * 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;         \
+       __unqual_scalar_typeof(*__get_unaligned_ctrl_type)
__get_unaligned_val; \
+       __builtin_memcpy(&__get_unaligned_val, (void *)(ptr),           \
+                        sizeof(__get_unaligned_val));                  \
+       __get_unaligned_val;                                            \

})

in "__builtin_memcpy(&__get_unaligned_val, (void *)(ptr)" there is a void* cast and I believe this is what sparse is now warning about - I don't believe the warning was present at the time of the original series.

I believe, although it is a distant memory, I tried making the cast a "(const void*)" cast rather than a "void*" cast but this caused different warnings/issues. My patch is going through a compiler warning, sparse, etc. wac-a-mole and the comment notes the cast is present to avoid warnings with ubsan (undefined behavior sanitizer).

I think there are 2 options:
1) ignore the new sparse warning as tech debt for later clean up,
2) modify the cast to be "const void*" instead of "void *" and play more wac-a-mole.

My preference would be 1 as I have a suspicion I played 2 and thought the non-const cast was best (hence it being in the patch) given other issues.

Thanks,
Ian

Quoted 76 lines
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   97             }
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   98     } else if (event->param.conn.private_data_len >=
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23   99                sizeof(struct rds_ib_connect_private)) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  100             major = dp->ricp_v4.dp_protocol_major;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  101             minor = dp->ricp_v4.dp_protocol_minor;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  102             credit = dp->ricp_v4.dp_credit;
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  103             ack_seq = get_unaligned(&dp->ricp_v4.dp_ack_seq);
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  104     }
ec16227e14141e Andy Grover                  2009-02-24  105
02a6a2592e41d2 Andy Grover                  2009-07-17  106     /* make sure it isn't empty data */
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  107     if (major) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  108             rds_ib_set_protocol(conn, RDS_PROTOCOL(major, minor));
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  109             rds_ib_set_flow_control(conn, be32_to_cpu(credit));
02a6a2592e41d2 Andy Grover                  2009-07-17  110     }
ec16227e14141e Andy Grover                  2009-02-24  111
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  112     if (conn->c_version < RDS_PROTOCOL_VERSION) {
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  113             if (conn->c_version != RDS_PROTOCOL_COMPAT_VERSION) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  114                     pr_notice("RDS/IB: Connection <%pI6c,%pI6c> version %u.%u no longer supported\n",
ff3f19a2f608ee Santosh Shilimkar            2016-03-14  115                               &conn->c_laddr, &conn->c_faddr,
f147dd9ecabf23 Andy Grover                  2010-01-13  116                               RDS_PROTOCOL_MAJOR(conn->c_version),
f147dd9ecabf23 Andy Grover                  2010-01-13  117                               RDS_PROTOCOL_MINOR(conn->c_version));
f147dd9ecabf23 Andy Grover                  2010-01-13  118                     rds_conn_destroy(conn);
f147dd9ecabf23 Andy Grover                  2010-01-13  119                     return;
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  120             }
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  121     }
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  122
fd261ce6a30e01 Santosh Shilimkar            2018-10-13  123     pr_notice("RDS/IB: %s conn connected <%pI6c,%pI6c,%d> version %u.%u%s\n",
581d53c91cbf7b Santosh Shilimkar            2016-07-09  124               ic->i_active_side ? "Active" : "Passive",
fd261ce6a30e01 Santosh Shilimkar            2018-10-13  125               &conn->c_laddr, &conn->c_faddr, conn->c_tos,
ec16227e14141e Andy Grover                  2009-02-24  126               RDS_PROTOCOL_MAJOR(conn->c_version),
ec16227e14141e Andy Grover                  2009-02-24  127               RDS_PROTOCOL_MINOR(conn->c_version),
ec16227e14141e Andy Grover                  2009-02-24  128               ic->i_flowctl ? ", flow control" : "");
ec16227e14141e Andy Grover                  2009-02-24  129
e0e6d062822529 Zhu Yanjun                   2019-08-23  130     /* receive sl from the peer */
e0e6d062822529 Zhu Yanjun                   2019-08-23  131     ic->i_sl = ic->i_cm_id->route.path_rec->sl;
e0e6d062822529 Zhu Yanjun                   2019-08-23  132
cf657269d311d5 Santosh Shilimkar            2016-09-29  133     atomic_set(&ic->i_cq_quiesce, 0);
cf657269d311d5 Santosh Shilimkar            2016-09-29  134
581d53c91cbf7b Santosh Shilimkar            2016-07-09  135     /* Init rings and fill recv. this needs to wait until protocol
581d53c91cbf7b Santosh Shilimkar            2016-07-09  136      * negotiation is complete, since ring layout is different
581d53c91cbf7b Santosh Shilimkar            2016-07-09  137      * from 3.1 to 4.1.
e11d912a7dd4df Andy Grover                  2009-07-17  138      */
e11d912a7dd4df Andy Grover                  2009-07-17  139     rds_ib_send_init_ring(ic);
e11d912a7dd4df Andy Grover                  2009-07-17  140     rds_ib_recv_init_ring(ic);
e11d912a7dd4df Andy Grover                  2009-07-17  141     /* Post receive buffers - as a side effect, this will update
e11d912a7dd4df Andy Grover                  2009-07-17  142      * the posted credit count. */
73ce4317bf9832 [email protected] 2015-08-22  143     rds_ib_recv_refill(conn, 1, GFP_KERNEL);
e11d912a7dd4df Andy Grover                  2009-07-17  144
3e0249f9c05cb7 Zach Brown                   2010-05-18  145     /* update ib_device with this local ipaddr */
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  146     err = rds_ib_update_ipaddr(ic->rds_ibdev, &conn->c_laddr);
ec16227e14141e Andy Grover                  2009-02-24  147     if (err)
3e0249f9c05cb7 Zach Brown                   2010-05-18  148             printk(KERN_ERR "rds_ib_update_ipaddr failed (%d)\n",
3e0249f9c05cb7 Zach Brown                   2010-05-18  149                     err);
ec16227e14141e Andy Grover                  2009-02-24  150
ec16227e14141e Andy Grover                  2009-02-24  151     /* If the peer gave us the last packet it saw, process this as if
ec16227e14141e Andy Grover                  2009-02-24  152      * we had received a regular ACK. */
c0adf54a10903b shamir rabinovitch           2015-04-30  153     if (dp) {
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  154             if (ack_seq)
eee2fa6ab32251 Ka-Cheong Poon               2018-07-23  155                     rds_send_drop_acked(conn, be64_to_cpu(ack_seq),
c0adf54a10903b shamir rabinovitch           2015-04-30  156                                         NULL);
c0adf54a10903b shamir rabinovitch           2015-04-30  157     }
ec16227e14141e Andy Grover                  2009-02-24  158
cdc306a5c9cd36 Santosh Shilimkar            2018-10-13  159     conn->c_proposed_version = conn->c_version;
ec16227e14141e Andy Grover                  2009-02-24  160     rds_connect_complete(conn);
ec16227e14141e Andy Grover                  2009-02-24  161  }
ec16227e14141e Andy Grover                  2009-02-24  162

:::::: The code at line 96 was first introduced by commit
:::::: eee2fa6ab3225192d6d894c54a6fb02ac9efdff6 rds: Changing IP address internal representation to struct in6_addr

:::::: TO: Ka-Cheong Poon <[email protected]> :::::: CC: David S. Miller <[email protected]>

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

maintainer
#2 lore raw
Quoted 5 lines · Ian Rogers

On Wed, Jan 14, 2026 at 8:37 AM kernel test robot <[email protected]> wrote:
I think there are 2 options:
1) ignore the new sparse warning as tech debt for later clean up,
2) modify the cast to be "const void*" instead of "void *" and play more wac-a-mole.

Option #3:

You might have tried the 'const void*' cast and figured out that sparse is still unhappy. I actually did, but I didn't try to figure out why as that's really not my duty.

Quoted 3 lines

My preference would be 1 as I have a suspicion I played 2 and thought the non-const cast was best (hence it being in the patch) given other issues.

Preferences based on suspicions are not really usefull. Please go and figure out what's going on and either fix it in the kernel code or tell the sparse folks what they are missing.

Leaving it unresolved and handwaved away is not an option.

Thanks,

tglx

#3 lore raw
Quoted 18 lines · Thomas Gleixner
Quoted 5 lines · Ian Rogers

On Wed, Jan 14, 2026 at 8:37 AM kernel test robot <[email protected]> wrote:
I think there are 2 options:
1) ignore the new sparse warning as tech debt for later clean up,
2) modify the cast to be "const void*" instead of "void *" and play more wac-a-mole.

Option #3:

You might have tried the 'const void*' cast and figured out that sparse is still unhappy. I actually did, but I didn't try to figure out why as that's really not my duty.

Quoted 3 lines

My preference would be 1 as I have a suspicion I played 2 and thought the non-const cast was best (hence it being in the patch) given other issues.

Quoted 5 lines

Preferences based on suspicions are not really usefull. Please go and figure out what's going on and either fix it in the kernel code or tell the sparse folks what they are missing.

Leaving it unresolved and handwaved away is not an option.

I'd like to call this option, play a bunch of wac-a-mole but then still don't really progress. I had tried out I believe all the options 6 months ago where the builds were clean. There's always 1 more tool that's going to raise its head and complain about types, my motivation remains clang and gcc for user space copies of this code so we don't need to propagate -fno-strict-aliasing into places like perf. Tbh, I'm not going to be able to look at this for a while so I'd suggest just dropping the patches.

Thanks,
Ian

Quoted 3 lines

Thanks,

tglx

maintainer
#4 lore raw
Quoted 5 lines · Ian Rogers
Quoted 4 lines · Thomas Gleixner
Quoted 3 lines

My preference would be 1 as I have a suspicion I played 2 and thought the non-const cast was best (hence it being in the patch) given other issues.

Quoted 7 lines
Quoted 5 lines

Preferences based on suspicions are not really usefull. Please go and figure out what's going on and either fix it in the kernel code or tell the sparse folks what they are missing.

Leaving it unresolved and handwaved away is not an option.

I'd like to call this option, play a bunch of wac-a-mole but then

I'm not familiar enough with internet slang, but to my limited knowledge it's spelled 'Whack-a-mole'. That aside:

"Whack-a-mole" without a real conclusive explanation is really a
lame excuse, actually it's beyond lame.

Quoted 5 lines

still don't really progress. I had tried out I believe all the options 6 months ago where the builds were clean. There's always 1 more tool that's going to raise its head and complain about types, my motivation remains clang and gcc for user space copies of this code so we don't need to propagate -fno-strict-aliasing into places like perf.

So because your motivation ends there and other tools which raise their ugly heads are not relevant to you ...

Quoted 2 lines

Tbh, I'm not going to be able to look at this for a while so I'd suggest just dropping the patches.

... everything stays with the status quo, i.e. unresolved.

That makes a lot of sense - NOT!

Thanks for wasting my time to deal with your patches and welcome to my extremly short ignore list!

Your's grumpy

Thomas

#5 lore raw
Quoted 33 lines · Thomas Gleixner
Quoted 5 lines · Ian Rogers
Quoted 4 lines · Thomas Gleixner
Quoted 3 lines

My preference would be 1 as I have a suspicion I played 2 and thought the non-const cast was best (hence it being in the patch) given other issues.

Quoted 7 lines
Quoted 5 lines

Preferences based on suspicions are not really usefull. Please go and figure out what's going on and either fix it in the kernel code or tell the sparse folks what they are missing.

Leaving it unresolved and handwaved away is not an option.

I'd like to call this option, play a bunch of wac-a-mole but then

I'm not familiar enough with internet slang, but to my limited knowledge it's spelled 'Whack-a-mole'. That aside:

"Whack-a-mole" without a real conclusive explanation is really a
lame excuse, actually it's beyond lame.

Quoted 5 lines

still don't really progress. I had tried out I believe all the options 6 months ago where the builds were clean. There's always 1 more tool that's going to raise its head and complain about types, my motivation remains clang and gcc for user space copies of this code so we don't need to propagate -fno-strict-aliasing into places like perf.

So because your motivation ends there and other tools which raise their ugly heads are not relevant to you ...

Quoted 2 lines

Tbh, I'm not going to be able to look at this for a while so I'd suggest just dropping the patches.

Quoted 6 lines

... everything stays with the status quo, i.e. unresolved.

That makes a lot of sense - NOT!

Thanks for wasting my time to deal with your patches and welcome to my extremly short ignore list!

The patches have been through 5 versions with considerable hurdles jumped, testing my ending, both kernel building and user space tool building and running with sanitizers, etc. My work commitments mean I can't just leap up and say I'm going to explore the ramifications of moving the (void*) to (const void*) in all these combinations again, but as a a const lover (even having published papers on it [1]) I doubt the choice of using "void*" rather than "const void*" is likely no accident. Even if I come up with a new series, waiting months for any kind of review, merging, feedback, .. I'm just left in limbo and I lose the context that I've built up and we end up here. In perf changes we often end up with good patches vs perfect patches and I don't believe with these patches we'll ever get perfect, hence saying we should move forward even with the sparse regression that may only be fixable with #ifdef DOING_A_SPARSE_BUILD... Given the bar seems to be perfect, I'm recommending just dropping the patches.

Sorry to be on your ignore list,
Ian

[1] https://research.manchester.ac.uk/en/publications/constraint-based-optimization-of-stationary-fields/

Quoted 6 lines

Your's grumpy

Thomas

maintainer
#6 lore raw
In reply to kernel test robot

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

Cc+ sparse folks.

Quoted 7 lines

sparse warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

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(-)
include/linux/compiler_types.h +10 -0
@@ -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 */
include/vdso/unaligned.h +11 -5
@@ -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;				\
 })
 
 /**
#7 lore raw
Quoted 12 lines · Thomas Gleixner

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

Cc+ sparse folks.

Quoted 7 lines

sparse warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

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 *

Quoted 8 lines

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.

Per:

https://git.kernel.org/pub/scm/devel/sparse/sparse-dev.git/commit/?id=dc9efe442b8949234a6599fdc94dc7221dd040e1

it seems Sparse now knows about __typeof_unqual__; and it looks like the implementation does what you want here (although I've not tested it).

Something like so perhaps, which then mandates the very latest Sparse.

---

include/linux/compiler.h +1 -4
index 04487c9bd751..7e0583ceb49f 100644
@@ -232,11 +232,8 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 
 /*
  * Use __typeof_unqual__() when available.
- *
- * XXX: Remove test for __CHECKER__ once
- * sparse learns about __typeof_unqual__().
  */
-#if CC_HAS_TYPEOF_UNQUAL && !defined(__CHECKER__)
+#if CC_HAS_TYPEOF_UNQUAL || defined(__CHECKER__)
 # define USE_TYPEOF_UNQUAL 1
 #endif
 
include/linux/compiler_types.h +4 -0
index d3318a3c2577..a37d832d99a8 100644
@@ -569,6 +569,7 @@ struct ftrace_likely_data {
  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
  *			       non-scalar types unchanged.
  */
+#ifndef USE_TYPEOF_UNQUAL
 /*
  * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
  * is not type-compatible with 'signed char', and we define a separate case.
@@ -586,6 +587,9 @@ struct ftrace_likely_data {
 			 __scalar_type_to_expr_cases(long),		\
 			 __scalar_type_to_expr_cases(long long),	\
 			 default: (x)))
+#else
+#define __unqual_scalar_typeof(x) __typeof_unqual__(x)
+#endif
 
 /* Is this type a native word size -- useful for atomic operations */
 #define __native_word(t) \
#8 lore raw
Quoted 2 lines · Peter Zijlstra

Something like so perhaps, which then mandates the very latest Sparse.

Ack. We want that compiler_tpes.h change for the real compilers that support __typeof_unqual__ anyway.

Eventually we can just force that everywhere, but as Al pointed out in another thread, we're not quite there yet (ie we'd need clang-19.0.1 and gcc-8.4 to be able to just switch entirely over to __typeof_unqual__).

For sparse users, I think we should have the policy that we just don't support older versions at all, since it just gets too painful.

Linus

#9 lore raw
Quoted 4 lines · Linus Torvalds

Eventually we can just force that everywhere, but as Al pointed out in another thread, we're not quite there yet (ie we'd need clang-19.0.1 and gcc-8.4 to be able to just switch entirely over to __typeof_unqual__).

GCC-14 :-/ The GCC-8.4 one was the function return value trick.

#10 lore raw
Quoted 2 lines · Peter Zijlstra

GCC-14 :-/ The GCC-8.4 one was the function return value trick.

Right you are. And yeah, us moving on to gcc-14 as a minimum version is not imminent.

Still, while we can't force it, lots of distros are on gcc-15, so while we'd have the _Generic() macro as a fallback for older versions, at least most developers would hopefully get the nice clean modern __typeof_unqual__ thing...

Linus

#11 lore raw
Quoted 11 lines · Linus Torvalds
Quoted 2 lines · Peter Zijlstra

GCC-14 :-/ The GCC-8.4 one was the function return value trick.

Right you are. And yeah, us moving on to gcc-14 as a minimum version is not imminent.

Still, while we can't force it, lots of distros are on gcc-15, so while we'd have the _Generic() macro as a fallback for older versions, at least most developers would hopefully get the nice clean modern __typeof_unqual__ thing...

Absolutely. I'll try and make it happen if tglx doesn't.

maintainer
#12 lore raw
In reply to Peter Zijlstra
Quoted 22 lines · Peter Zijlstra
Quoted 12 lines · Thomas Gleixner

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

Cc+ sparse folks.

Quoted 7 lines

sparse warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

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 *

Quoted 8 lines

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.

Quoted 8 lines

Per:

https://git.kernel.org/pub/scm/devel/sparse/sparse-dev.git/commit/?id=dc9efe442b8949234a6599fdc94dc7221dd040e1

it seems Sparse now knows about __typeof_unqual__; and it looks like the implementation does what you want here (although I've not tested it).

Something like so perhaps, which then mandates the very latest Sparse.

I tried that before and sparse is still upset:

net/rds/ib_cm.c:96:35: warning: incorrect type in argument 1 (different modifiers)
net/rds/ib_cm.c:96:35: expected void *
net/rds/ib_cm.c:96:35: got restricted __be64 const *
net/rds/ib_cm.c:103:27: warning: incorrect type in argument 1 (different modifiers)
net/rds/ib_cm.c:103:27: expected void *
net/rds/ib_cm.c:103:27: got restricted __be64 const *

This time I looked deeper and it seems that USE_TYPEOF_UNQUAL is not set.

If I force it to be set and use a proper compiler and top of tree sparse, everything seems to be happy.

Figuring that out is something for tomorrow...

Thanks,

tglx

maintainer
#13 lore raw
Quoted 7 lines · Thomas Gleixner

This time I looked deeper and it seems that USE_TYPEOF_UNQUAL is not set.

If I force it to be set and use a proper compiler and top of tree sparse, everything seems to be happy.

Figuring that out is something for tomorrow...

USE_TYPEOF_UNQUAL is set _after_ the __unqual_scalar muck is processed...

Updated fix below.

Thanks,

tglx

---
 include/linux/compiler.h       |   10 ----------
 include/linux/compiler_types.h |   11 +++++++++++
 2 files changed, 11 insertions(+), 10 deletions(-)
include/linux/compiler.h +0 -10
@@ -231,16 +231,6 @@ void ftrace_likely_update(struct ftrace_
 				"must be non-C-string (not NUL-terminated)")
 
 /*
- * Use __typeof_unqual__() when available.
- *
- * XXX: Remove test for __CHECKER__ once
- * sparse learns about __typeof_unqual__().
- */
-#if CC_HAS_TYPEOF_UNQUAL && !defined(__CHECKER__)
-# define USE_TYPEOF_UNQUAL 1
-#endif
-
-/*
  * Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof
  * operator when available, to return an unqualified type of the exp.
  */
include/linux/compiler_types.h +11 -0
@@ -562,6 +562,13 @@ struct ftrace_likely_data {
 #define asm_inline asm
 #endif
 
+/*
+ * Use __typeof_unqual__() when available.
+ */
+#if CC_HAS_TYPEOF_UNQUAL || defined(__CHECKER__)
+# define USE_TYPEOF_UNQUAL 1
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
@@ -569,6 +576,7 @@ struct ftrace_likely_data {
  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
  *			       non-scalar types unchanged.
  */
+#ifndef USE_TYPEOF_UNQUAL
 /*
  * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
  * is not type-compatible with 'signed char', and we define a separate case.
@@ -586,6 +594,9 @@ struct ftrace_likely_data {
 			 __scalar_type_to_expr_cases(long),		\
 			 __scalar_type_to_expr_cases(long long),	\
 			 default: (x)))
+#else
+#define __unqual_scalar_typeof(x) __typeof_unqual__(x)
+#endif
 
 /* Is this type a native word size -- useful for atomic operations */
 #define __native_word(t) \
maintainer
#14 lore raw

PATCH 1/1 compiler: Use __typeof_unqual__() for __unqual_scalar_typeof()

From: Peter Zijlstra <[email protected]>

The recent changes to get_unaligned() resulted in a new sparse warning:

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 *

The updated get_unaligned_t() uses __unqual_scalar_typeof() to get an unqualified type. This works correctly for the compilers, but fails for sparse when the data type is __be64 (or any other __beNN variant).

On sparse runs (C=[12]) __beNN types are annotated with __attribute__((bitwise)).

That annotation allows sparse to detect incompatible operations on __beNN variables, but it also prevents sparse from evaluating the _Generic() in __unqual_scalar_typeof() and map __beNN to a unqualified scalar type, so 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 sparse git tree supports typeof_unqual() now, which allows to use it instead of the _Generic() based __unqual_scalar_typeof(). With that sparse correctly evaluates the unqualified type and keeps the __beNN logic intact.

The downside is that this requires a top of tree sparse build and an old sparse version will emit a metric ton of incomprehensible error messages before it dies with a segfault.

Therefore implement a sanity check which validates that the checker is available and capable of handling typeof_unqual(). Emit a warning if not so the user can take informed action.

[ tglx: Move the evaluation of USE_TYPEOF_UNQUAL to compiler_types.h so it is
set before use and implement the sanity checker ]

---
 Makefile                       |    8 ++++++++
 include/linux/compiler.h       |   10 ----------
 include/linux/compiler_types.h |   11 +++++++++++
 scripts/checker-valid.sh       |   19 +++++++++++++++++++
 4 files changed, 38 insertions(+), 10 deletions(-)
Makefile +8 -0
@@ -1178,6 +1178,14 @@ ifdef CONFIG_CC_IS_CLANG
 KBUILD_USERLDFLAGS += --ld-path=$(LD)
 endif
 
+# Validate the checker is available and functional
+ifneq ($(KBUILD_CHECKSRC), 0)
+  ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK)), 1)
+    $(warning C=$(KBUILD_CHECKSRC) specified, but $(CHECK) is not available or not up to date)
+    KBUILD_CHECKSRC = 0
+  endif
+endif
+
 # make the checker run with the right architecture
 CHECKFLAGS += --arch=$(ARCH)
 
include/linux/compiler.h +0 -10
@@ -231,16 +231,6 @@ void ftrace_likely_update(struct ftrace_
 				"must be non-C-string (not NUL-terminated)")
 
 /*
- * Use __typeof_unqual__() when available.
- *
- * XXX: Remove test for __CHECKER__ once
- * sparse learns about __typeof_unqual__().
- */
-#if CC_HAS_TYPEOF_UNQUAL && !defined(__CHECKER__)
-# define USE_TYPEOF_UNQUAL 1
-#endif
-
-/*
  * Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof
  * operator when available, to return an unqualified type of the exp.
  */
include/linux/compiler_types.h +11 -0
@@ -562,6 +562,13 @@ struct ftrace_likely_data {
 #define asm_inline asm
 #endif
 
+/*
+ * Use __typeof_unqual__() when available.
+ */
+#if CC_HAS_TYPEOF_UNQUAL || defined(__CHECKER__)
+# define USE_TYPEOF_UNQUAL 1
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
@@ -569,6 +576,7 @@ struct ftrace_likely_data {
  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
  *			       non-scalar types unchanged.
  */
+#ifndef USE_TYPEOF_UNQUAL
 /*
  * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
  * is not type-compatible with 'signed char', and we define a separate case.
@@ -586,6 +594,9 @@ struct ftrace_likely_data {
 			 __scalar_type_to_expr_cases(long),		\
 			 __scalar_type_to_expr_cases(long long),	\
 			 default: (x)))
+#else
+#define __unqual_scalar_typeof(x) __typeof_unqual__(x)
+#endif
 
 /* Is this type a native word size -- useful for atomic operations */
 #define __native_word(t) \
scripts/checker-valid.sh new file +19 -0
@@ -0,0 +1,19 @@
+#!/bin/sh -eu
+# SPDX-License-Identifier: GPL-2.0
+
+[ ! -x "$(command -v "$1")" ] && exit 1
+
+tmp_file=$(mktemp)
+trap "rm -f $tmp_file" EXIT
+
+cat << EOF >$tmp_file
+static inline int u(const int *q)
+{
+	__typeof_unqual__(*q) v = *q;
+	return v;
+}
+EOF
+
+# sparse happily exits with 0 on error so validate
+# there is none on stderr. Use awk as grep is a pain with sh -e
+$1 $tmp_file 2>&1 | awk -v c=1 '/error/{c=0}END{print c}'
Acked-by on v1 1/1
#15 lore raw

Re: [PATCH] compiler: Use __typeof_unqual__() for __unqual_scalar_typeof()

Quoted 23 lines · Thomas Gleixner

From: Peter Zijlstra <[email protected]>

The recent changes to get_unaligned() resulted in a new sparse warning:

   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 *

The updated get_unaligned_t() uses __unqual_scalar_typeof() to get an unqualified type. This works correctly for the compilers, but fails for sparse when the data type is __be64 (or any other __beNN variant).

On sparse runs (C=[12]) __beNN types are annotated with __attribute__((bitwise)).

That annotation allows sparse to detect incompatible operations on __beNN variables, but it also prevents sparse from evaluating the _Generic() in __unqual_scalar_typeof() and map __beNN to a unqualified scalar type, so 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.

Quoted 3 lines

The sparse git tree supports typeof_unqual() now, which allows to use it instead of the _Generic() based __unqual_scalar_typeof(). With that sparse correctly evaluates the unqualified type and keeps the __beNN logic intact.

Wow, that's painful. Congratulations on finding the root case.

Thanks,
Ian

Quoted 114 lines

The downside is that this requires a top of tree sparse build and an old sparse version will emit a metric ton of incomprehensible error messages before it dies with a segfault.

Therefore implement a sanity check which validates that the checker is available and capable of handling typeof_unqual(). Emit a warning if not so the user can take informed action.

[ tglx: Move the evaluation of USE_TYPEOF_UNQUAL to compiler_types.h so it is
set before use and implement the sanity checker ]

---
 Makefile                       |    8 ++++++++
 include/linux/compiler.h       |   10 ----------
 include/linux/compiler_types.h |   11 +++++++++++
 scripts/checker-valid.sh       |   19 +++++++++++++++++++
 4 files changed, 38 insertions(+), 10 deletions(-)
Makefile +8 -0
@@ -1178,6 +1178,14 @@ ifdef CONFIG_CC_IS_CLANG
 KBUILD_USERLDFLAGS += --ld-path=$(LD)
 endif
 
+# Validate the checker is available and functional
+ifneq ($(KBUILD_CHECKSRC), 0)
+  ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK)), 1)
+    $(warning C=$(KBUILD_CHECKSRC) specified, but $(CHECK) is not available or not up to date)
+    KBUILD_CHECKSRC = 0
+  endif
+endif
+
 # make the checker run with the right architecture
 CHECKFLAGS += --arch=$(ARCH)
 
include/linux/compiler.h +0 -10
@@ -231,16 +231,6 @@ void ftrace_likely_update(struct ftrace_
                                "must be non-C-string (not NUL-terminated)")
 
 /*
- * Use __typeof_unqual__() when available.
- *
- * XXX: Remove test for __CHECKER__ once
- * sparse learns about __typeof_unqual__().
- */
-#if CC_HAS_TYPEOF_UNQUAL && !defined(__CHECKER__)
-# define USE_TYPEOF_UNQUAL 1
-#endif
-
-/*
  * Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof
  * operator when available, to return an unqualified type of the exp.
  */
include/linux/compiler_types.h +11 -0
@@ -562,6 +562,13 @@ struct ftrace_likely_data {
 #define asm_inline asm
 #endif
 
+/*
+ * Use __typeof_unqual__() when available.
+ */
+#if CC_HAS_TYPEOF_UNQUAL || defined(__CHECKER__)
+# define USE_TYPEOF_UNQUAL 1
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
@@ -569,6 +576,7 @@ struct ftrace_likely_data {
  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
  *                            non-scalar types unchanged.
  */
+#ifndef USE_TYPEOF_UNQUAL
 /*
  * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
  * is not type-compatible with 'signed char', and we define a separate case.
@@ -586,6 +594,9 @@ struct ftrace_likely_data {
                         __scalar_type_to_expr_cases(long),             \
                         __scalar_type_to_expr_cases(long long),        \
                         default: (x)))
+#else
+#define __unqual_scalar_typeof(x) __typeof_unqual__(x)
+#endif
 
 /* Is this type a native word size -- useful for atomic operations */
 #define __native_word(t) \
scripts/checker-valid.sh new file +19 -0
@@ -0,0 +1,19 @@
+#!/bin/sh -eu
+# SPDX-License-Identifier: GPL-2.0
+
+[ ! -x "$(command -v "$1")" ] && exit 1
+
+tmp_file=$(mktemp)
+trap "rm -f $tmp_file" EXIT
+
+cat << EOF >$tmp_file
+static inline int u(const int *q)
+{
+       __typeof_unqual__(*q) v = *q;
+       return v;
+}
+EOF
+
+# sparse happily exits with 0 on error so validate
+# there is none on stderr. Use awk as grep is a pain with sh -e
+$1 $tmp_file 2>&1 | awk -v c=1 '/error/{c=0}END{print c}'
merge bot Applied
#16 lore raw

[tip: timers/vdso] compiler: Use __typeof_unqual__() for __unqual_scalar_typeof()

In reply to Thomas Gleixner
The following commit has been merged into the timers/vdso branch of tip:

The following commit has been merged into the timers/vdso branch of tip:

Commit-ID:     adc00a0daf1bb08915bceee9ae73cca682e7d5bb
Gitweb:        https://git.kernel.org/tip/adc00a0daf1bb08915bceee9ae73cca682e7d5bb
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Fri, 16 Jan 2026 19:18:16 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sat, 17 Jan 2026 22:18:40 +01:00

compiler: Use __typeof_unqual__() for __unqual_scalar_typeof()

The recent changes to get_unaligned() resulted in a new sparse warning:

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 *

The updated get_unaligned_t() uses __unqual_scalar_typeof() to get an unqualified type. This works correctly for the compilers, but fails for sparse when the data type is __be64 (or any other __beNN variant).

On sparse runs (C=[12]) __beNN types are annotated with __attribute__((bitwise)).

That annotation allows sparse to detect incompatible operations on __beNN variables, but it also prevents sparse from evaluating the _Generic() in __unqual_scalar_typeof() and map __beNN to a unqualified scalar type, so 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 sparse git tree supports typeof_unqual() now, which allows to use it instead of the _Generic() based __unqual_scalar_typeof(). With that sparse correctly evaluates the unqualified type and keeps the __beNN logic intact.

The downside is that this requires a top of tree sparse build and an old sparse version will emit a metric ton of incomprehensible error messages before it dies with a segfault.

Therefore implement a sanity check which validates that the checker is available and capable of handling typeof_unqual(). Emit a warning if not so the user can take informed action.

[ tglx: Move the evaluation of USE_TYPEOF_UNQUAL to compiler_types.h so it is
set before use and implement the sanity checker ]

---
 Makefile                       |  8 ++++++++
 include/linux/compiler.h       | 10 ----------
 include/linux/compiler_types.h | 11 +++++++++++
 scripts/checker-valid.sh       | 19 +++++++++++++++++++
 4 files changed, 38 insertions(+), 10 deletions(-)
 create mode 100755 scripts/checker-valid.sh
Makefile +8 -0
index 9d38125..179c9d9 100644
@@ -1187,6 +1187,14 @@ CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
 # the checker needs the correct machine size
 CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
 
+# Validate the checker is available and functional
+ifneq ($(KBUILD_CHECKSRC), 0)
+  ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK) $(CHECKFLAGS)), 1)
+    $(warning C=$(KBUILD_CHECKSRC) specified, but $(CHECK) is not available or not up to date)
+    KBUILD_CHECKSRC = 0
+  endif
+endif
+
 # Default kernel image to build when no specific target is given.
 # KBUILD_IMAGE may be overruled on the command line or
 # set in the environment
include/linux/compiler.h +0 -10
index 04487c9..c601222 100644
@@ -231,16 +231,6 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 				"must be non-C-string (not NUL-terminated)")
 
 /*
- * Use __typeof_unqual__() when available.
- *
- * XXX: Remove test for __CHECKER__ once
- * sparse learns about __typeof_unqual__().
- */
-#if CC_HAS_TYPEOF_UNQUAL && !defined(__CHECKER__)
-# define USE_TYPEOF_UNQUAL 1
-#endif
-
-/*
  * Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof
  * operator when available, to return an unqualified type of the exp.
  */
include/linux/compiler_types.h +11 -0
index d3318a3..9cf4dcf 100644
@@ -562,6 +562,13 @@ struct ftrace_likely_data {
 #define asm_inline asm
 #endif
 
+/*
+ * Use __typeof_unqual__() when available.
+ */
+#if CC_HAS_TYPEOF_UNQUAL || defined(__CHECKER__)
+# define USE_TYPEOF_UNQUAL 1
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
@@ -569,6 +576,7 @@ struct ftrace_likely_data {
  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
  *			       non-scalar types unchanged.
  */
+#ifndef USE_TYPEOF_UNQUAL
 /*
  * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
  * is not type-compatible with 'signed char', and we define a separate case.
@@ -586,6 +594,9 @@ struct ftrace_likely_data {
 			 __scalar_type_to_expr_cases(long),		\
 			 __scalar_type_to_expr_cases(long long),	\
 			 default: (x)))
+#else
+#define __unqual_scalar_typeof(x) __typeof_unqual__(x)
+#endif
 
 /* Is this type a native word size -- useful for atomic operations */
 #define __native_word(t) \
scripts/checker-valid.sh new file +19 -0
new file mode 100755
index 0000000..625a789
@@ -0,0 +1,19 @@
+#!/bin/sh -eu
+# SPDX-License-Identifier: GPL-2.0
+
+[ ! -x "$(command -v "$1")" ] && exit 1
+
+tmp_file=$(mktemp)
+trap "rm -f $tmp_file" EXIT
+
+cat << EOF >$tmp_file
+static inline int u(const int *q)
+{
+	__typeof_unqual__(*q) v = *q;
+	return v;
+}
+EOF
+
+# sparse happily exits with 0 on error so validate
+# there is none on stderr. Use awk as grep is a pain with sh -e
+$@ $tmp_file 2>&1 | awk -v c=1 '/error/{c=0}END{print c}'
merge bot Applied
#17 lore raw

[tip: timers/vdso] compiler: Use __typeof_unqual__() for __unqual_scalar_typeof()

In reply to Thomas Gleixner
The following commit has been merged into the timers/vdso branch of tip:

The following commit has been merged into the timers/vdso branch of tip:

Commit-ID:     fd69b2f7d5f4e1d89cea4cdfa6f15e7fa53d8358
Gitweb:        https://git.kernel.org/tip/fd69b2f7d5f4e1d89cea4cdfa6f15e7fa53d8358
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Fri, 16 Jan 2026 19:18:16 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 18 Jan 2026 10:32:03 +01:00

compiler: Use __typeof_unqual__() for __unqual_scalar_typeof()

The recent changes to get_unaligned() resulted in a new sparse warning:

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 *

The updated get_unaligned_t() uses __unqual_scalar_typeof() to get an unqualified type. This works correctly for the compilers, but fails for sparse when the data type is __be64 (or any other __beNN variant).

On sparse runs (C=[12]) __beNN types are annotated with __attribute__((bitwise)).

That annotation allows sparse to detect incompatible operations on __beNN variables, but it also prevents sparse from evaluating the _Generic() in __unqual_scalar_typeof() and map __beNN to a unqualified scalar type, so 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 sparse git tree supports typeof_unqual() now, which allows to use it instead of the _Generic() based __unqual_scalar_typeof(). With that sparse correctly evaluates the unqualified type and keeps the __beNN logic intact.

The downside is that this requires a top of tree sparse build and an old sparse version will emit a metric ton of incomprehensible error messages before it dies with a segfault.

Therefore implement a sanity check which validates that the checker is available and capable of handling typeof_unqual(). Emit a warning if not so the user can take informed action.

[ tglx: Move the evaluation of USE_TYPEOF_UNQUAL to compiler_types.h so it is
set before use and implement the sanity checker ]

---
 Makefile                       |  8 ++++++++
 include/linux/compiler.h       | 10 ----------
 include/linux/compiler_types.h | 13 +++++++++++++
 scripts/checker-valid.sh       | 19 +++++++++++++++++++
 4 files changed, 40 insertions(+), 10 deletions(-)
 create mode 100755 scripts/checker-valid.sh
Makefile +8 -0
index 9d38125..179c9d9 100644
@@ -1187,6 +1187,14 @@ CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
 # the checker needs the correct machine size
 CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
 
+# Validate the checker is available and functional
+ifneq ($(KBUILD_CHECKSRC), 0)
+  ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK) $(CHECKFLAGS)), 1)
+    $(warning C=$(KBUILD_CHECKSRC) specified, but $(CHECK) is not available or not up to date)
+    KBUILD_CHECKSRC = 0
+  endif
+endif
+
 # Default kernel image to build when no specific target is given.
 # KBUILD_IMAGE may be overruled on the command line or
 # set in the environment
include/linux/compiler.h +0 -10
index 04487c9..c601222 100644
@@ -231,16 +231,6 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 				"must be non-C-string (not NUL-terminated)")
 
 /*
- * Use __typeof_unqual__() when available.
- *
- * XXX: Remove test for __CHECKER__ once
- * sparse learns about __typeof_unqual__().
- */
-#if CC_HAS_TYPEOF_UNQUAL && !defined(__CHECKER__)
-# define USE_TYPEOF_UNQUAL 1
-#endif
-
-/*
  * Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof
  * operator when available, to return an unqualified type of the exp.
  */
include/linux/compiler_types.h +13 -0
index d3318a3..377df1e 100644
@@ -562,6 +562,14 @@ struct ftrace_likely_data {
 #define asm_inline asm
 #endif
 
+#ifndef __ASSEMBLY__
+/*
+ * Use __typeof_unqual__() when available.
+ */
+#if CC_HAS_TYPEOF_UNQUAL || defined(__CHECKER__)
+# define USE_TYPEOF_UNQUAL 1
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
@@ -569,6 +577,7 @@ struct ftrace_likely_data {
  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
  *			       non-scalar types unchanged.
  */
+#ifndef USE_TYPEOF_UNQUAL
 /*
  * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
  * is not type-compatible with 'signed char', and we define a separate case.
@@ -586,6 +595,10 @@ struct ftrace_likely_data {
 			 __scalar_type_to_expr_cases(long),		\
 			 __scalar_type_to_expr_cases(long long),	\
 			 default: (x)))
+#else
+#define __unqual_scalar_typeof(x) __typeof_unqual__(x)
+#endif
+#endif /* !__ASSEMBLY__ */
 
 /* Is this type a native word size -- useful for atomic operations */
 #define __native_word(t) \
scripts/checker-valid.sh new file +19 -0
new file mode 100755
index 0000000..625a789
@@ -0,0 +1,19 @@
+#!/bin/sh -eu
+# SPDX-License-Identifier: GPL-2.0
+
+[ ! -x "$(command -v "$1")" ] && exit 1
+
+tmp_file=$(mktemp)
+trap "rm -f $tmp_file" EXIT
+
+cat << EOF >$tmp_file
+static inline int u(const int *q)
+{
+	__typeof_unqual__(*q) v = *q;
+	return v;
+}
+EOF
+
+# sparse happily exits with 0 on error so validate
+# there is none on stderr. Use awk as grep is a pain with sh -e
+$@ $tmp_file 2>&1 | awk -v c=1 '/error/{c=0}END{print c}'
#18 lore raw

Re: [PATCH] compiler: Use __typeof_unqual__() for __unqual_scalar_typeof()

In reply to Thomas Gleixner
Quoted 4 lines · Thomas Gleixner
Makefile +0 -0
@@ -1178,6 +1178,14 @@ ifdef CONFIG_CC_IS_CLANG
 KBUILD_USERLDFLAGS += --ld-path=$(LD)

Makefile ifdef CONFIG_CC_IS_CLANG · line 1188

Quoted 10 lines
Makefile +8 -0
 endif
 
+# Validate the checker is available and functional
+ifneq ($(KBUILD_CHECKSRC), 0)
+  ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK)), 1)
+    $(warning C=$(KBUILD_CHECKSRC) specified, but $(CHECK) is not available or not up to date)
+    KBUILD_CHECKSRC = 0
+  endif
+endif
+

This means we can't run "CHECK="valgrind smatch -p=kernel" because valgrind always prints output to stderr. So hopefully we can eventually remove this check.

regards,
dan carpenter