public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
@ 2025-08-25  4:45 kernel test robot
  0 siblings, 0 replies; 19+ messages in thread
From: kernel test robot @ 2025-08-25  4:45 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: oe-kbuild-all, linux-kernel, Jakub Kicinski,
	Maciej Żenczykowski

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   1b237f190eb3d36f52dffe07a40b5eb210280e00
commit: e84a4927a404f369c842c19de93b216627fcc690 net: annotate races around sk->sk_uid
date:   9 weeks ago
config: alpha-randconfig-r131-20250824 (https://download.01.org/0day-ci/archive/20250825/202508251226.ArERUcGn-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 9.5.0
reproduce: (https://download.01.org/0day-ci/archive/20250825/202508251226.ArERUcGn-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/202508251226.ArERUcGn-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   net/core/lwt_bpf.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h, include/net/ipv6.h, include/net/inetpeer.h, ...):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/route.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv4/route.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
--
   net/ipv4/ip_output.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/inet_connection_sock.c:328:36: sparse: sparse: context imbalance in 'inet_csk_find_open_port' - wrong count at exit
   net/ipv4/inet_connection_sock.c:605:23: sparse: sparse: context imbalance in 'inet_csk_get_port' - unexpected unlock
   net/ipv4/inet_connection_sock.c: note: in included file (through include/net/inet_sock.h, include/net/inet_connection_sock.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv4/inet_connection_sock.c:1467:9: sparse: sparse: context imbalance in 'inet_csk_complete_hashdance' - unexpected unlock
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/tcp_ipv4.c:3415:41: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@
   net/ipv4/tcp_ipv4.c:3415:41: sparse:     expected void const *data
   net/ipv4/tcp_ipv4.c:3415:41: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3537:45: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control @@
   net/ipv4/tcp_ipv4.c:3537:45: sparse:     expected void const *data
   net/ipv4/tcp_ipv4.c:3537:45: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3541:50: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@     got struct tcp_congestion_ops * @@
   net/ipv4/tcp_ipv4.c:3541:50: sparse:     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3541:50: sparse:     got struct tcp_congestion_ops *
   net/ipv4/tcp_ipv4.c: note: in included file (through include/net/inet_sock.h, include/net/icmp.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv4/tcp_ipv4.c:1846:25: sparse: sparse: context imbalance in 'tcp_v4_syn_recv_sock' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2139:17: sparse: sparse: context imbalance in 'tcp_add_backlog' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2401:21: sparse: sparse: context imbalance in 'tcp_v4_rcv' - different lock contexts for basic block
   net/ipv4/tcp_ipv4.c:2612:13: sparse: sparse: context imbalance in 'listening_get_first' - wrong count at exit
   net/ipv4/tcp_ipv4.c:2660:29: sparse: sparse: context imbalance in 'listening_get_next' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2693:13: sparse: sparse: context imbalance in 'established_get_first' - wrong count at exit
   net/ipv4/tcp_ipv4.c:2738:40: sparse: sparse: context imbalance in 'established_get_next' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2870:36: sparse: sparse: context imbalance in 'tcp_seq_stop' - unexpected unlock
   net/ipv4/tcp_ipv4.c:3091:20: sparse: sparse: context imbalance in 'bpf_iter_tcp_listening_batch' - unexpected unlock
   net/ipv4/tcp_ipv4.c:3119:40: sparse: sparse: context imbalance in 'bpf_iter_tcp_established_batch' - unexpected unlock
   net/ipv4/tcp_ipv4.c:3416:41: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3416:41: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3538:45: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3538:45: sparse: sparse: dereference of noderef expression
--
   net/ipv4/datagram.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/raw.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/udp.c: note: in included file (through include/linux/bpf-cgroup.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv4/udp.c:1668:28: sparse: sparse: context imbalance in 'udp_rmem_release' - unexpected unlock
   net/ipv4/udp.c:1700:19: sparse: sparse: context imbalance in 'busylock_acquire' - wrong count at exit
   net/ipv4/udp.c:1712:28: sparse: sparse: context imbalance in 'busylock_release' - unexpected unlock
   net/ipv4/udp.c:3305:9: sparse: sparse: context imbalance in 'udp_get_first' - wrong count at exit
   net/ipv4/udp.c:3322:39: sparse: sparse: context imbalance in 'udp_get_next' - unexpected unlock
   net/ipv4/udp.c:3370:31: sparse: sparse: context imbalance in 'udp_seq_stop' - unexpected unlock
--
   net/ipv4/af_inet.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/ping.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/af_inet6.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h, include/linux/icmpv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/route.c:2382:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned int [usertype] flow_label @@     got restricted __be32 @@
   net/ipv6/route.c:2382:39: sparse:     expected unsigned int [usertype] flow_label
   net/ipv6/route.c:2382:39: sparse:     got restricted __be32
   net/ipv6/route.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute6.h):
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast to non-scalar
   include/net/ip_fib.h:562:19: sparse: sparse: cast from non-scalar
   net/ipv6/route.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/udp.c: note: in included file (through include/linux/bpf-cgroup.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/raw.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h, include/linux/icmpv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/ping.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h, include/net/addrconf.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/datagram.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/tcp_ipv6.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv6/tcp_ipv6.c:1565:25: sparse: sparse: context imbalance in 'tcp_v6_syn_recv_sock' - unexpected unlock
   net/ipv6/tcp_ipv6.c:1956:21: sparse: sparse: context imbalance in 'tcp_v6_rcv' - different lock contexts for basic block
--
   net/ipv6/inet6_connection_sock.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/netfilter.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar

vim +2100 include/net/sock.h

  2096	
  2097	static inline kuid_t sk_uid(const struct sock *sk)
  2098	{
  2099		/* Paired with WRITE_ONCE() in sockfs_setattr() */
> 2100		return READ_ONCE(sk->sk_uid);
  2101	}
  2102	

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
@ 2025-12-06 10:09 kernel test robot
  0 siblings, 0 replies; 19+ messages in thread
From: kernel test robot @ 2025-12-06 10:09 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: oe-kbuild-all, linux-kernel, Jakub Kicinski,
	Maciej Żenczykowski

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   416f99c3b16f582a3fc6d64a1f77f39d94b76de5
commit: e84a4927a404f369c842c19de93b216627fcc690 net: annotate races around sk->sk_uid
date:   6 months ago
config: arm64-randconfig-r121-20251206 (https://download.01.org/0day-ci/archive/20251206/202512061811.TwIhRj4D-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 14bf95b06a18b9b59c89601cbc0e5a6f2176b118)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251206/202512061811.TwIhRj4D-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/202512061811.TwIhRj4D-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   net/ipv6/af_inet6.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h, include/linux/icmpv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/datagram.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/ping.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h, include/net/addrconf.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/inet6_connection_sock.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/raw.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h, include/linux/icmpv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/tcp_ipv6.c: note: in included file (through include/linux/tcp.h, include/linux/ipv6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv6/tcp_ipv6.c:1565:25: sparse: sparse: context imbalance in 'tcp_v6_syn_recv_sock' - unexpected unlock
   net/ipv6/tcp_ipv6.c:1956:21: sparse: sparse: context imbalance in 'tcp_v6_rcv' - different lock contexts for basic block
--
   net/ipv6/udp.c: note: in included file (through include/linux/bpf-cgroup.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv6/route.c:2382:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned int [usertype] flow_label @@     got restricted __be32 @@
   net/ipv6/route.c:2382:39: sparse:     expected unsigned int [usertype] flow_label
   net/ipv6/route.c:2382:39: sparse:     got restricted __be32
   net/ipv6/route.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute6.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar

vim +2100 include/net/sock.h

  2096	
  2097	static inline kuid_t sk_uid(const struct sock *sk)
  2098	{
  2099		/* Paired with WRITE_ONCE() in sockfs_setattr() */
> 2100		return READ_ONCE(sk->sk_uid);
  2101	}
  2102	

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
@ 2026-01-10 21:06 kernel test robot
  2026-01-10 22:15 ` Al Viro
  0 siblings, 1 reply; 19+ messages in thread
From: kernel test robot @ 2026-01-10 21:06 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: oe-kbuild-all, linux-kernel, Jakub Kicinski,
	Maciej Żenczykowski 

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   97313d6113ab4362ad15076f65560e65288fbcb8
commit: e84a4927a404f369c842c19de93b216627fcc690 net: annotate races around sk->sk_uid
date:   7 months ago
config: alpha-randconfig-r112-20260110 (https://download.01.org/0day-ci/archive/20260111/202601110443.5ENBRFej-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260111/202601110443.5ENBRFej-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/202601110443.5ENBRFej-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   net/ipv4/datagram.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/raw.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/inet_connection_sock.c:328:36: sparse: sparse: context imbalance in 'inet_csk_find_open_port' - wrong count at exit
   net/ipv4/inet_connection_sock.c:605:23: sparse: sparse: context imbalance in 'inet_csk_get_port' - unexpected unlock
   net/ipv4/inet_connection_sock.c: note: in included file (through include/net/inet_sock.h, include/net/inet_connection_sock.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv4/inet_connection_sock.c:1467:9: sparse: sparse: context imbalance in 'inet_csk_complete_hashdance' - unexpected unlock
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/route.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/ip_output.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/af_inet.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/tcp_ipv4.c:3415:41: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@
   net/ipv4/tcp_ipv4.c:3415:41: sparse:     expected void const *data
   net/ipv4/tcp_ipv4.c:3415:41: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3537:45: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control @@
   net/ipv4/tcp_ipv4.c:3537:45: sparse:     expected void const *data
   net/ipv4/tcp_ipv4.c:3537:45: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3541:50: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@     got struct tcp_congestion_ops * @@
   net/ipv4/tcp_ipv4.c:3541:50: sparse:     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3541:50: sparse:     got struct tcp_congestion_ops *
   net/ipv4/tcp_ipv4.c: note: in included file (through include/net/inet_sock.h, include/net/icmp.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv4/tcp_ipv4.c:1846:25: sparse: sparse: context imbalance in 'tcp_v4_syn_recv_sock' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2139:17: sparse: sparse: context imbalance in 'tcp_add_backlog' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2401:21: sparse: sparse: context imbalance in 'tcp_v4_rcv' - different lock contexts for basic block
   net/ipv4/tcp_ipv4.c:2612:13: sparse: sparse: context imbalance in 'listening_get_first' - wrong count at exit
   net/ipv4/tcp_ipv4.c:2660:29: sparse: sparse: context imbalance in 'listening_get_next' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2693:13: sparse: sparse: context imbalance in 'established_get_first' - wrong count at exit
   net/ipv4/tcp_ipv4.c:2738:40: sparse: sparse: context imbalance in 'established_get_next' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2870:36: sparse: sparse: context imbalance in 'tcp_seq_stop' - unexpected unlock
   net/ipv4/tcp_ipv4.c:3091:20: sparse: sparse: context imbalance in 'bpf_iter_tcp_listening_batch' - unexpected unlock
   net/ipv4/tcp_ipv4.c:3119:40: sparse: sparse: context imbalance in 'bpf_iter_tcp_established_batch' - unexpected unlock
   net/ipv4/tcp_ipv4.c:3416:41: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3416:41: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3538:45: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3538:45: sparse: sparse: dereference of noderef expression
--
   net/ipv4/ping.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
--
   net/ipv4/udp.c: note: in included file (through include/linux/bpf-cgroup.h):
>> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
   include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
   net/ipv4/udp.c:1668:28: sparse: sparse: context imbalance in 'udp_rmem_release' - unexpected unlock
   net/ipv4/udp.c:1700:19: sparse: sparse: context imbalance in 'busylock_acquire' - wrong count at exit
   net/ipv4/udp.c:1712:28: sparse: sparse: context imbalance in 'busylock_release' - unexpected unlock
   net/ipv4/udp.c:3305:9: sparse: sparse: context imbalance in 'udp_get_first' - wrong count at exit
   net/ipv4/udp.c:3322:39: sparse: sparse: context imbalance in 'udp_get_next' - unexpected unlock
   net/ipv4/udp.c:3370:31: sparse: sparse: context imbalance in 'udp_seq_stop' - unexpected unlock

vim +2100 include/net/sock.h

  2096	
  2097	static inline kuid_t sk_uid(const struct sock *sk)
  2098	{
  2099		/* Paired with WRITE_ONCE() in sockfs_setattr() */
> 2100		return READ_ONCE(sk->sk_uid);
  2101	}
  2102	

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-10 21:06 include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar kernel test robot
@ 2026-01-10 22:15 ` Al Viro
  2026-01-10 22:35   ` Al Viro
  2026-01-12  0:49   ` Philip Li
  0 siblings, 2 replies; 19+ messages in thread
From: Al Viro @ 2026-01-10 22:15 UTC (permalink / raw)
  To: kernel test robot
  Cc: Eric Dumazet, oe-kbuild-all, linux-kernel, Jakub Kicinski,
	Maciej Żenczykowski

On Sun, Jan 11, 2026 at 05:06:31AM +0800, kernel test robot wrote:

Folks, could your bot be taught to recognize that kind of situation?
It's very clear what's going on - an inline function that gets the
same warning with this config every time it is called.  Commit in
question has added several calls of that thing; the origin of warning
has nothing whatsoever to do with it, and that can be guessed without
even looking at the source - the quoted diff between the logs is quite
enough for that.

Looking at the function in question,

> sparse warnings: (new ones prefixed by >>)
>    net/ipv4/datagram.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> --
>    net/ipv4/raw.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> --
>    net/ipv4/inet_connection_sock.c:328:36: sparse: sparse: context imbalance in 'inet_csk_find_open_port' - wrong count at exit
>    net/ipv4/inet_connection_sock.c:605:23: sparse: sparse: context imbalance in 'inet_csk_get_port' - unexpected unlock
>    net/ipv4/inet_connection_sock.c: note: in included file (through include/net/inet_sock.h, include/net/inet_connection_sock.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>    net/ipv4/inet_connection_sock.c:1467:9: sparse: sparse: context imbalance in 'inet_csk_complete_hashdance' - unexpected unlock
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> --
>    net/ipv4/route.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> --
>    net/ipv4/ip_output.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> --
>    net/ipv4/af_inet.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> --
>    net/ipv4/tcp_ipv4.c:3415:41: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@
>    net/ipv4/tcp_ipv4.c:3415:41: sparse:     expected void const *data
>    net/ipv4/tcp_ipv4.c:3415:41: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
>    net/ipv4/tcp_ipv4.c:3537:45: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control @@
>    net/ipv4/tcp_ipv4.c:3537:45: sparse:     expected void const *data
>    net/ipv4/tcp_ipv4.c:3537:45: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control
>    net/ipv4/tcp_ipv4.c:3541:50: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@     got struct tcp_congestion_ops * @@
>    net/ipv4/tcp_ipv4.c:3541:50: sparse:     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
>    net/ipv4/tcp_ipv4.c:3541:50: sparse:     got struct tcp_congestion_ops *
>    net/ipv4/tcp_ipv4.c: note: in included file (through include/net/inet_sock.h, include/net/icmp.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>    net/ipv4/tcp_ipv4.c:1846:25: sparse: sparse: context imbalance in 'tcp_v4_syn_recv_sock' - unexpected unlock
>    net/ipv4/tcp_ipv4.c:2139:17: sparse: sparse: context imbalance in 'tcp_add_backlog' - unexpected unlock
>    net/ipv4/tcp_ipv4.c:2401:21: sparse: sparse: context imbalance in 'tcp_v4_rcv' - different lock contexts for basic block
>    net/ipv4/tcp_ipv4.c:2612:13: sparse: sparse: context imbalance in 'listening_get_first' - wrong count at exit
>    net/ipv4/tcp_ipv4.c:2660:29: sparse: sparse: context imbalance in 'listening_get_next' - unexpected unlock
>    net/ipv4/tcp_ipv4.c:2693:13: sparse: sparse: context imbalance in 'established_get_first' - wrong count at exit
>    net/ipv4/tcp_ipv4.c:2738:40: sparse: sparse: context imbalance in 'established_get_next' - unexpected unlock
>    net/ipv4/tcp_ipv4.c:2870:36: sparse: sparse: context imbalance in 'tcp_seq_stop' - unexpected unlock
>    net/ipv4/tcp_ipv4.c:3091:20: sparse: sparse: context imbalance in 'bpf_iter_tcp_listening_batch' - unexpected unlock
>    net/ipv4/tcp_ipv4.c:3119:40: sparse: sparse: context imbalance in 'bpf_iter_tcp_established_batch' - unexpected unlock
>    net/ipv4/tcp_ipv4.c:3416:41: sparse: sparse: dereference of noderef expression
>    net/ipv4/tcp_ipv4.c:3416:41: sparse: sparse: dereference of noderef expression
>    net/ipv4/tcp_ipv4.c:3538:45: sparse: sparse: dereference of noderef expression
>    net/ipv4/tcp_ipv4.c:3538:45: sparse: sparse: dereference of noderef expression
> --
>    net/ipv4/ping.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> --
>    net/ipv4/udp.c: note: in included file (through include/linux/bpf-cgroup.h):
> >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
>    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
>    net/ipv4/udp.c:1668:28: sparse: sparse: context imbalance in 'udp_rmem_release' - unexpected unlock
>    net/ipv4/udp.c:1700:19: sparse: sparse: context imbalance in 'busylock_acquire' - wrong count at exit
>    net/ipv4/udp.c:1712:28: sparse: sparse: context imbalance in 'busylock_release' - unexpected unlock
>    net/ipv4/udp.c:3305:9: sparse: sparse: context imbalance in 'udp_get_first' - wrong count at exit
>    net/ipv4/udp.c:3322:39: sparse: sparse: context imbalance in 'udp_get_next' - unexpected unlock
>    net/ipv4/udp.c:3370:31: sparse: sparse: context imbalance in 'udp_seq_stop' - unexpected unlock
> 
> vim +2100 include/net/sock.h
> 
>   2096	
>   2097	static inline kuid_t sk_uid(const struct sock *sk)
>   2098	{
>   2099		/* Paired with WRITE_ONCE() in sockfs_setattr() */
> > 2100		return READ_ONCE(sk->sk_uid);
>   2101	}
>   2102	
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-10 22:15 ` Al Viro
@ 2026-01-10 22:35   ` Al Viro
  2026-01-11 10:08     ` Eric Dumazet
                       ` (2 more replies)
  2026-01-12  0:49   ` Philip Li
  1 sibling, 3 replies; 19+ messages in thread
From: Al Viro @ 2026-01-10 22:35 UTC (permalink / raw)
  To: kernel test robot
  Cc: Eric Dumazet, oe-kbuild-all, linux-kernel, Jakub Kicinski,
	Maciej Żenczykowski, Will Deacon, Paul E. McKenney,
	Peter Zijlstra

On Sat, Jan 10, 2026 at 10:15:09PM +0000, Al Viro wrote:
> On Sun, Jan 11, 2026 at 05:06:31AM +0800, kernel test robot wrote:
> 
> Folks, could your bot be taught to recognize that kind of situation?
> It's very clear what's going on - an inline function that gets the
> same warning with this config every time it is called.  Commit in
> question has added several calls of that thing; the origin of warning
> has nothing whatsoever to do with it, and that can be guessed without
> even looking at the source - the quoted diff between the logs is quite
> enough for that.
> 
> Looking at the function in question,

[accidentally sent halfway through editing, sorry]

e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2097) static inline kuid_t sk_uid(const struct sock *sk)
e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2098) {
e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2099)       /* Paired with WRITE_ONCE() in sockfs_setattr() */
e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2100)       return READ_ONCE(sk->sk_uid);
e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2101) }

we see that warning in question almost certainly comes from
	READ_ONCE(some_kuid_t_object)
and looking at alpha we see this:
#define __READ_ONCE(x)                                                  \
({                                                                      \
        __unqual_scalar_typeof(x) __x =                                 \
		(*(volatile typeof(__x) *)(&(x)));                      \
	mb();                                                           \
	(typeof(x))__x;                                                 \
})
combined with
typedef struct {
        uid_t val;
} kuid_t;

IOW, it complains about a cast from structure to itself, which is fair
enough - C is pretty clear about not allowing any typecasts to or from
non-scalar types, tautological or not.

Why do we even need that cast?  Seeing that generic __READ_ONCE() is
#define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
the cast added on alpha seems to be pointless.

Folks involved in putting that cast in arch/alpha/include/asm/rwonce.h Cc'd...

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-10 22:35   ` Al Viro
@ 2026-01-11 10:08     ` Eric Dumazet
  2026-01-12 12:33       ` Peter Zijlstra
  2026-01-11 18:20     ` Al Viro
  2026-01-12 12:32     ` Peter Zijlstra
  2 siblings, 1 reply; 19+ messages in thread
From: Eric Dumazet @ 2026-01-11 10:08 UTC (permalink / raw)
  To: Al Viro
  Cc: kernel test robot, oe-kbuild-all, linux-kernel, Jakub Kicinski,
	Maciej Żenczykowski, Will Deacon, Paul E. McKenney,
	Peter Zijlstra

On Sat, Jan 10, 2026 at 11:34 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Sat, Jan 10, 2026 at 10:15:09PM +0000, Al Viro wrote:
> > On Sun, Jan 11, 2026 at 05:06:31AM +0800, kernel test robot wrote:
> >
> > Folks, could your bot be taught to recognize that kind of situation?
> > It's very clear what's going on - an inline function that gets the
> > same warning with this config every time it is called.  Commit in
> > question has added several calls of that thing; the origin of warning
> > has nothing whatsoever to do with it, and that can be guessed without
> > even looking at the source - the quoted diff between the logs is quite
> > enough for that.
> >
> > Looking at the function in question,
>
> [accidentally sent halfway through editing, sorry]
>
> e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2097) static inline kuid_t sk_uid(const struct sock *sk)
> e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2098) {
> e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2099)       /* Paired with WRITE_ONCE() in sockfs_setattr() */
> e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2100)       return READ_ONCE(sk->sk_uid);
> e84a4927a404f (Eric Dumazet               2025-06-20 13:30:00 +0000 2101) }
>
> we see that warning in question almost certainly comes from
>         READ_ONCE(some_kuid_t_object)
> and looking at alpha we see this:
> #define __READ_ONCE(x)                                                  \
> ({                                                                      \
>         __unqual_scalar_typeof(x) __x =                                 \
>                 (*(volatile typeof(__x) *)(&(x)));                      \
>         mb();                                                           \
>         (typeof(x))__x;                                                 \
> })
> combined with
> typedef struct {
>         uid_t val;
> } kuid_t;
>
> IOW, it complains about a cast from structure to itself, which is fair
> enough - C is pretty clear about not allowing any typecasts to or from
> non-scalar types, tautological or not.
>
> Why do we even need that cast?  Seeing that generic __READ_ONCE() is
> #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
> the cast added on alpha seems to be pointless.
>
> Folks involved in putting that cast in arch/alpha/include/asm/rwonce.h Cc'd...

I have sent a fix, but got no reply from any alpha users.

https://lists.openwall.net/linux-kernel/2025/11/03/350

My understanding is that this arch is no longer used.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-10 22:35   ` Al Viro
  2026-01-11 10:08     ` Eric Dumazet
@ 2026-01-11 18:20     ` Al Viro
  2026-01-11 18:51       ` Al Viro
  2026-01-12 12:37       ` Peter Zijlstra
  2026-01-12 12:32     ` Peter Zijlstra
  2 siblings, 2 replies; 19+ messages in thread
From: Al Viro @ 2026-01-11 18:20 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Eric Dumazet, oe-kbuild-all, linux-kernel, Jakub Kicinski,
	Maciej Żenczykowski, Will Deacon, Paul E. McKenney,
	Peter Zijlstra

On Sat, Jan 10, 2026 at 10:35:48PM +0000, Al Viro wrote:

> Folks involved in putting that cast in arch/alpha/include/asm/rwonce.h Cc'd...

FWIW, there's a way to strip qualifiers from *any* non-array type.
Look:

void f(void)
{
	const int x;
	x = 1;		// an error
	typeof(((typeof(x)(*)(void))0)()) y;
	y = 2;		// perfectly fine
}

The way it works is that qualifiers are stripped from return type when
deriving a function type.  That was spelled out only in C17; 6.7.6.3[5]
| If, in the declaration "T D1", D1 has the form
| D ( parameter-type-list )
|  or
| D ( identifier-list[opt] )
| and the type specified for ident in the declaration "T D" is
| "derived-declarator-type-list T", then the type specified for ident
| is "derived-declarator-type-list function returning the unqualified version
| of T".
but that "unqualified version of..." matched the common practice in
earlier variants of standard; they stopped issuing TCs by that point
(~2014), but both clang and gcc behave that way with any variant of
standard.

IOW, this

#define unqual_non_array(T) __typeof__(((T(*)(void))0)())

would do the right thing without that _Generic cascade and it'll work
just fine for e.g. kuid_t.  Using it for an array would trigger an error,
array-returning functions being forbidden...

Guys, do you have any problems with replacing __unqual_scalar_typeof()
uses with that thing?

As in,#ifndef __smp_load_acquire
#define __smp_load_acquire(p)                                           \
({                                                                      \
        unqual_non_array(__typeof__(*p)) ___p1 = READ_ONCE(*p);         \
...

Objections?  IMO it's more palatable than current __unqual_scalar_typeof()...

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-11 18:20     ` Al Viro
@ 2026-01-11 18:51       ` Al Viro
  2026-01-12 12:37       ` Peter Zijlstra
  1 sibling, 0 replies; 19+ messages in thread
From: Al Viro @ 2026-01-11 18:51 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Eric Dumazet, oe-kbuild-all, linux-kernel, Jakub Kicinski,
	Maciej Żenczykowski, Will Deacon, Paul E. McKenney,
	Peter Zijlstra

On Sun, Jan 11, 2026 at 06:20:10PM +0000, Al Viro wrote:

> Guys, do you have any problems with replacing __unqual_scalar_typeof()
> uses with that thing?
> 
> As in,#ifndef __smp_load_acquire
> #define __smp_load_acquire(p)                                           \
> ({                                                                      \
>         unqual_non_array(__typeof__(*p)) ___p1 = READ_ONCE(*p);         \
> ...
> 
> Objections?  IMO it's more palatable than current __unqual_scalar_typeof()...

Argh...  gcc prior to 8.4 fucks it up, and our minimum is 8.1 ;-/
Pity, that...  I still think it's worth keeping in mind for when
we bump the minimal gcc revision, though.

FWIW, with clang it works all way back at least to 3.1; icc - at least
to 13.0.1...

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-10 22:15 ` Al Viro
  2026-01-10 22:35   ` Al Viro
@ 2026-01-12  0:49   ` Philip Li
  1 sibling, 0 replies; 19+ messages in thread
From: Philip Li @ 2026-01-12  0:49 UTC (permalink / raw)
  To: Al Viro
  Cc: kernel test robot, Eric Dumazet, oe-kbuild-all, linux-kernel,
	Jakub Kicinski, Maciej Żenczykowski

On Sat, Jan 10, 2026 at 10:15:08PM +0000, Al Viro wrote:
> On Sun, Jan 11, 2026 at 05:06:31AM +0800, kernel test robot wrote:
> 
> Folks, could your bot be taught to recognize that kind of situation?

Got it, we will follow up to update the bot logic to ignore further
reports for this pattern.

> It's very clear what's going on - an inline function that gets the
> same warning with this config every time it is called.  Commit in
> question has added several calls of that thing; the origin of warning
> has nothing whatsoever to do with it, and that can be guessed without
> even looking at the source - the quoted diff between the logs is quite
> enough for that.
> 
> Looking at the function in question,
> 
> > sparse warnings: (new ones prefixed by >>)
> >    net/ipv4/datagram.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > --
> >    net/ipv4/raw.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > --
> >    net/ipv4/inet_connection_sock.c:328:36: sparse: sparse: context imbalance in 'inet_csk_find_open_port' - wrong count at exit
> >    net/ipv4/inet_connection_sock.c:605:23: sparse: sparse: context imbalance in 'inet_csk_get_port' - unexpected unlock
> >    net/ipv4/inet_connection_sock.c: note: in included file (through include/net/inet_sock.h, include/net/inet_connection_sock.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >    net/ipv4/inet_connection_sock.c:1467:9: sparse: sparse: context imbalance in 'inet_csk_complete_hashdance' - unexpected unlock
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > --
> >    net/ipv4/route.c: note: in included file (through include/linux/mroute_base.h, include/linux/mroute.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > --
> >    net/ipv4/ip_output.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > --
> >    net/ipv4/af_inet.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > --
> >    net/ipv4/tcp_ipv4.c:3415:41: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@
> >    net/ipv4/tcp_ipv4.c:3415:41: sparse:     expected void const *data
> >    net/ipv4/tcp_ipv4.c:3415:41: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
> >    net/ipv4/tcp_ipv4.c:3537:45: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control @@
> >    net/ipv4/tcp_ipv4.c:3537:45: sparse:     expected void const *data
> >    net/ipv4/tcp_ipv4.c:3537:45: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control
> >    net/ipv4/tcp_ipv4.c:3541:50: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@     got struct tcp_congestion_ops * @@
> >    net/ipv4/tcp_ipv4.c:3541:50: sparse:     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
> >    net/ipv4/tcp_ipv4.c:3541:50: sparse:     got struct tcp_congestion_ops *
> >    net/ipv4/tcp_ipv4.c: note: in included file (through include/net/inet_sock.h, include/net/icmp.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >    net/ipv4/tcp_ipv4.c:1846:25: sparse: sparse: context imbalance in 'tcp_v4_syn_recv_sock' - unexpected unlock
> >    net/ipv4/tcp_ipv4.c:2139:17: sparse: sparse: context imbalance in 'tcp_add_backlog' - unexpected unlock
> >    net/ipv4/tcp_ipv4.c:2401:21: sparse: sparse: context imbalance in 'tcp_v4_rcv' - different lock contexts for basic block
> >    net/ipv4/tcp_ipv4.c:2612:13: sparse: sparse: context imbalance in 'listening_get_first' - wrong count at exit
> >    net/ipv4/tcp_ipv4.c:2660:29: sparse: sparse: context imbalance in 'listening_get_next' - unexpected unlock
> >    net/ipv4/tcp_ipv4.c:2693:13: sparse: sparse: context imbalance in 'established_get_first' - wrong count at exit
> >    net/ipv4/tcp_ipv4.c:2738:40: sparse: sparse: context imbalance in 'established_get_next' - unexpected unlock
> >    net/ipv4/tcp_ipv4.c:2870:36: sparse: sparse: context imbalance in 'tcp_seq_stop' - unexpected unlock
> >    net/ipv4/tcp_ipv4.c:3091:20: sparse: sparse: context imbalance in 'bpf_iter_tcp_listening_batch' - unexpected unlock
> >    net/ipv4/tcp_ipv4.c:3119:40: sparse: sparse: context imbalance in 'bpf_iter_tcp_established_batch' - unexpected unlock
> >    net/ipv4/tcp_ipv4.c:3416:41: sparse: sparse: dereference of noderef expression
> >    net/ipv4/tcp_ipv4.c:3416:41: sparse: sparse: dereference of noderef expression
> >    net/ipv4/tcp_ipv4.c:3538:45: sparse: sparse: dereference of noderef expression
> >    net/ipv4/tcp_ipv4.c:3538:45: sparse: sparse: dereference of noderef expression
> > --
> >    net/ipv4/ping.c: note: in included file (through include/net/inet_sock.h, include/net/ip.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> > --
> >    net/ipv4/udp.c: note: in included file (through include/linux/bpf-cgroup.h):
> > >> include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
> >    include/net/sock.h:2100:16: sparse: sparse: cast from non-scalar
> >    net/ipv4/udp.c:1668:28: sparse: sparse: context imbalance in 'udp_rmem_release' - unexpected unlock
> >    net/ipv4/udp.c:1700:19: sparse: sparse: context imbalance in 'busylock_acquire' - wrong count at exit
> >    net/ipv4/udp.c:1712:28: sparse: sparse: context imbalance in 'busylock_release' - unexpected unlock
> >    net/ipv4/udp.c:3305:9: sparse: sparse: context imbalance in 'udp_get_first' - wrong count at exit
> >    net/ipv4/udp.c:3322:39: sparse: sparse: context imbalance in 'udp_get_next' - unexpected unlock
> >    net/ipv4/udp.c:3370:31: sparse: sparse: context imbalance in 'udp_seq_stop' - unexpected unlock
> > 
> > vim +2100 include/net/sock.h
> > 
> >   2096	
> >   2097	static inline kuid_t sk_uid(const struct sock *sk)
> >   2098	{
> >   2099		/* Paired with WRITE_ONCE() in sockfs_setattr() */
> > > 2100		return READ_ONCE(sk->sk_uid);
> >   2101	}
> >   2102	
> > 
> > -- 
> > 0-DAY CI Kernel Test Service
> > https://github.com/intel/lkp-tests/wiki
> > 
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-10 22:35   ` Al Viro
  2026-01-11 10:08     ` Eric Dumazet
  2026-01-11 18:20     ` Al Viro
@ 2026-01-12 12:32     ` Peter Zijlstra
  2026-01-12 19:30       ` Al Viro
  2 siblings, 1 reply; 19+ messages in thread
From: Peter Zijlstra @ 2026-01-12 12:32 UTC (permalink / raw)
  To: Al Viro
  Cc: kernel test robot, Eric Dumazet, oe-kbuild-all, linux-kernel,
	Jakub Kicinski, Maciej Żenczykowski, Will Deacon,
	Paul E. McKenney

On Sat, Jan 10, 2026 at 10:35:48PM +0000, Al Viro wrote:

> #define __READ_ONCE(x)                                                  \
> ({                                                                      \
>         __unqual_scalar_typeof(x) __x =                                 \
> 		(*(volatile typeof(__x) *)(&(x)));                      \
> 	mb();                                                           \
> 	(typeof(x))__x;                                                 \
> })
> combined with
> typedef struct {
>         uid_t val;
> } kuid_t;
> 
> IOW, it complains about a cast from structure to itself, which is fair
> enough - C is pretty clear about not allowing any typecasts to or from
> non-scalar types, tautological or not.
> 
> Why do we even need that cast?  Seeing that generic __READ_ONCE() is
> #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
> the cast added on alpha seems to be pointless.

The problem was things like test_bit() that take a volatile argument,
doing READ_ONCE() on them would instantiate a volatile temporary and GCC
would end up generating shit code.

The __unqual_scalar_typeof() was the result of trying to remove CV
qualifiers from a type.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-11 10:08     ` Eric Dumazet
@ 2026-01-12 12:33       ` Peter Zijlstra
  0 siblings, 0 replies; 19+ messages in thread
From: Peter Zijlstra @ 2026-01-12 12:33 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Al Viro, kernel test robot, oe-kbuild-all, linux-kernel,
	Jakub Kicinski, Maciej Żenczykowski, Will Deacon,
	Paul E. McKenney

On Sun, Jan 11, 2026 at 11:08:34AM +0100, Eric Dumazet wrote:

> I have sent a fix, but got no reply from any alpha users.
> 
> https://lists.openwall.net/linux-kernel/2025/11/03/350

That is not fix, it re-introduces original problem of volatile
temporary and bad code gen.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-11 18:20     ` Al Viro
  2026-01-11 18:51       ` Al Viro
@ 2026-01-12 12:37       ` Peter Zijlstra
  2026-01-12 15:02         ` Will Deacon
  2026-01-12 19:21         ` Al Viro
  1 sibling, 2 replies; 19+ messages in thread
From: Peter Zijlstra @ 2026-01-12 12:37 UTC (permalink / raw)
  To: Al Viro
  Cc: Linus Torvalds, Eric Dumazet, oe-kbuild-all, linux-kernel,
	Jakub Kicinski, Maciej Żenczykowski, Will Deacon,
	Paul E. McKenney

On Sun, Jan 11, 2026 at 06:20:10PM +0000, Al Viro wrote:
> On Sat, Jan 10, 2026 at 10:35:48PM +0000, Al Viro wrote:
> 
> > Folks involved in putting that cast in arch/alpha/include/asm/rwonce.h Cc'd...
> 
> FWIW, there's a way to strip qualifiers from *any* non-array type.
> Look:
> 
> void f(void)
> {
> 	const int x;
> 	x = 1;		// an error
> 	typeof(((typeof(x)(*)(void))0)()) y;
> 	y = 2;		// perfectly fine
> }
> 
> The way it works is that qualifiers are stripped from return type when
> deriving a function type.  That was spelled out only in C17; 6.7.6.3[5]
> | If, in the declaration "T D1", D1 has the form
> | D ( parameter-type-list )
> |  or
> | D ( identifier-list[opt] )
> | and the type specified for ident in the declaration "T D" is
> | "derived-declarator-type-list T", then the type specified for ident
> | is "derived-declarator-type-list function returning the unqualified version
> | of T".
> but that "unqualified version of..." matched the common practice in
> earlier variants of standard; they stopped issuing TCs by that point
> (~2014), but both clang and gcc behave that way with any variant of
> standard.
> 
> IOW, this
> 
> #define unqual_non_array(T) __typeof__(((T(*)(void))0)())
> 
> would do the right thing without that _Generic cascade and it'll work
> just fine for e.g. kuid_t.  Using it for an array would trigger an error,
> array-returning functions being forbidden...
> 
> Guys, do you have any problems with replacing __unqual_scalar_typeof()
> uses with that thing?

There is also __typeof_unqual__, but I do not know if that is now
supported by all compilers, if so that is the better option. If not,
your function return type thing is awesome.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-12 12:37       ` Peter Zijlstra
@ 2026-01-12 15:02         ` Will Deacon
  2026-01-12 19:21         ` Al Viro
  1 sibling, 0 replies; 19+ messages in thread
From: Will Deacon @ 2026-01-12 15:02 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Al Viro, Linus Torvalds, Eric Dumazet, oe-kbuild-all,
	linux-kernel, Jakub Kicinski, Maciej Żenczykowski,
	Paul E. McKenney

On Mon, Jan 12, 2026 at 01:37:22PM +0100, Peter Zijlstra wrote:
> On Sun, Jan 11, 2026 at 06:20:10PM +0000, Al Viro wrote:
> > On Sat, Jan 10, 2026 at 10:35:48PM +0000, Al Viro wrote:
> > 
> > > Folks involved in putting that cast in arch/alpha/include/asm/rwonce.h Cc'd...
> > 
> > FWIW, there's a way to strip qualifiers from *any* non-array type.
> > Look:
> > 
> > void f(void)
> > {
> > 	const int x;
> > 	x = 1;		// an error
> > 	typeof(((typeof(x)(*)(void))0)()) y;
> > 	y = 2;		// perfectly fine
> > }
> > 
> > The way it works is that qualifiers are stripped from return type when
> > deriving a function type.  That was spelled out only in C17; 6.7.6.3[5]
> > | If, in the declaration "T D1", D1 has the form
> > | D ( parameter-type-list )
> > |  or
> > | D ( identifier-list[opt] )
> > | and the type specified for ident in the declaration "T D" is
> > | "derived-declarator-type-list T", then the type specified for ident
> > | is "derived-declarator-type-list function returning the unqualified version
> > | of T".
> > but that "unqualified version of..." matched the common practice in
> > earlier variants of standard; they stopped issuing TCs by that point
> > (~2014), but both clang and gcc behave that way with any variant of
> > standard.
> > 
> > IOW, this
> > 
> > #define unqual_non_array(T) __typeof__(((T(*)(void))0)())
> > 
> > would do the right thing without that _Generic cascade and it'll work
> > just fine for e.g. kuid_t.  Using it for an array would trigger an error,
> > array-returning functions being forbidden...
> > 
> > Guys, do you have any problems with replacing __unqual_scalar_typeof()
> > uses with that thing?
> 
> There is also __typeof_unqual__, but I do not know if that is now
> supported by all compilers, if so that is the better option. If not,
> your function return type thing is awesome.

Agreed, that's a really neat trick. I wouldn't put it past somebody to
use READ_ONCE() on an array, but the build systems should shake any of
those out pretty quickly.

Will

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-12 12:37       ` Peter Zijlstra
  2026-01-12 15:02         ` Will Deacon
@ 2026-01-12 19:21         ` Al Viro
  2026-01-12 21:16           ` Al Viro
  1 sibling, 1 reply; 19+ messages in thread
From: Al Viro @ 2026-01-12 19:21 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Linus Torvalds, Eric Dumazet, oe-kbuild-all, linux-kernel,
	Jakub Kicinski, Maciej Żenczykowski, Will Deacon,
	Paul E. McKenney

On Mon, Jan 12, 2026 at 01:37:22PM +0100, Peter Zijlstra wrote:

> > #define unqual_non_array(T) __typeof__(((T(*)(void))0)())
> > 
> > would do the right thing without that _Generic cascade and it'll work
> > just fine for e.g. kuid_t.  Using it for an array would trigger an error,
> > array-returning functions being forbidden...
> > 
> > Guys, do you have any problems with replacing __unqual_scalar_typeof()
> > uses with that thing?
> 
> There is also __typeof_unqual__, but I do not know if that is now
> supported by all compilers, if so that is the better option. If not,
> your function return type thing is awesome.

From experimenting with godbolt.org:
			clang		gcc		icc
__typeof_unqual__	>= 19.0.1	>= 14.1		no
this trick		>= 3.0.0	>= 8.4		>= 13.0.1
our minima		15.0.0		8.1

So __typeof_unqual__ is well out of our range; this trick is slightly
out of range, but nowhere near as bad.  Prior to 8.4 gcc had a bug
in that area, unfortunately ;-/

Might make sense to reconsider it next time we bump gcc minimum...

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-12 12:32     ` Peter Zijlstra
@ 2026-01-12 19:30       ` Al Viro
  2026-01-13 15:27         ` Peter Zijlstra
  0 siblings, 1 reply; 19+ messages in thread
From: Al Viro @ 2026-01-12 19:30 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: kernel test robot, Eric Dumazet, oe-kbuild-all, linux-kernel,
	Jakub Kicinski, Maciej Żenczykowski, Will Deacon,
	Paul E. McKenney

On Mon, Jan 12, 2026 at 01:32:24PM +0100, Peter Zijlstra wrote:
> On Sat, Jan 10, 2026 at 10:35:48PM +0000, Al Viro wrote:
> 
> > #define __READ_ONCE(x)                                                  \
> > ({                                                                      \
> >         __unqual_scalar_typeof(x) __x =                                 \
> > 		(*(volatile typeof(__x) *)(&(x)));                      \
> > 	mb();                                                           \
> > 	(typeof(x))__x;                                                 \
> > })
> > combined with
> > typedef struct {
> >         uid_t val;
> > } kuid_t;
> > 
> > IOW, it complains about a cast from structure to itself, which is fair
> > enough - C is pretty clear about not allowing any typecasts to or from
> > non-scalar types, tautological or not.
> > 
> > Why do we even need that cast?  Seeing that generic __READ_ONCE() is
> > #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
> > the cast added on alpha seems to be pointless.
> 
> The problem was things like test_bit() that take a volatile argument,
> doing READ_ONCE() on them would instantiate a volatile temporary and GCC
> would end up generating shit code.
> 
> The __unqual_scalar_typeof() was the result of trying to remove CV
> qualifiers from a type.

Sure, but what does that have to do with the final cast in there?  Note
that generic __READ_ONCE() ends up with __unqual_scalar_typeof(x) for the
type of result and it seems to be working fine.

Why would the same type of result be a problem for alpha?  Sure, we need
a barrier there, so it can't be literal copy of generic __READ_ONCE(),
but what's the problem with using

#define __READ_ONCE(x)							\
({									\
	__unqual_scalar_typeof(x) __x =					\
 		(*(volatile typeof(__x) *)(&(x)));			\
	mb();								\
	__x;								\
})

there?  What could possibly need those qualifiers added back to the result?
It is, after all, an r-value, so...

IDGI...

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-12 19:21         ` Al Viro
@ 2026-01-12 21:16           ` Al Viro
  2026-01-12 22:39             ` David Laight
  0 siblings, 1 reply; 19+ messages in thread
From: Al Viro @ 2026-01-12 21:16 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Linus Torvalds, Eric Dumazet, oe-kbuild-all, linux-kernel,
	Jakub Kicinski, Maciej Żenczykowski, Will Deacon,
	Paul E. McKenney

On Mon, Jan 12, 2026 at 07:21:26PM +0000, Al Viro wrote:
> On Mon, Jan 12, 2026 at 01:37:22PM +0100, Peter Zijlstra wrote:
> 
> > > #define unqual_non_array(T) __typeof__(((T(*)(void))0)())
> > > 
> > > would do the right thing without that _Generic cascade and it'll work
> > > just fine for e.g. kuid_t.  Using it for an array would trigger an error,
> > > array-returning functions being forbidden...
> > > 
> > > Guys, do you have any problems with replacing __unqual_scalar_typeof()
> > > uses with that thing?
> > 
> > There is also __typeof_unqual__, but I do not know if that is now
> > supported by all compilers, if so that is the better option. If not,
> > your function return type thing is awesome.
> 
> >From experimenting with godbolt.org:
> 			clang		gcc		icc
> __typeof_unqual__	>= 19.0.1	>= 14.1		no
> this trick		>= 3.0.0	>= 8.4		>= 13.0.1
> our minima		15.0.0		8.1
> 
> So __typeof_unqual__ is well out of our range; this trick is slightly
> out of range, but nowhere near as bad.  Prior to 8.4 gcc had a bug
> in that area, unfortunately ;-/
> 
> Might make sense to reconsider it next time we bump gcc minimum...

Speaking of fun gcc bugs: prior to 11.1 gcc would not strip qualifiers
in conditional operator; I hadn't tried to RTFS, but it almost looks like
they took the union of qualifiers on the second and the third arguments
of ?:

That's a direct violation of standard, all way back to C90 - the type
of 0 ? x : x where x is an l-value of qualified type *is* explicitly
required to be the unqualified version of that type; C90#6.2.2.1 does
list the contexts where l-value is not converted to non-l-value and ?:
arguments are not among those, with clearly stated requirement to strip
qualifiers when converting to non-l-value.

Once upon a time gcc used to have a weird extension that made (a ? b : c)
an l-value if both b and c had been, which might explain the origin of
that bug, but that went further - even in cases like
	const int x;
	__typeof__(0 ? x : 1) y;
they ended with const leaking to y, which would be a bug even in C++,
where that extension for ?: originated (prvalue int as the third argument
ends up with lvalue-to-rvalue conversions applied to the second one,
stripping any qualifiers from it)...

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-12 21:16           ` Al Viro
@ 2026-01-12 22:39             ` David Laight
  2026-01-13  0:28               ` Al Viro
  0 siblings, 1 reply; 19+ messages in thread
From: David Laight @ 2026-01-12 22:39 UTC (permalink / raw)
  To: Al Viro
  Cc: Peter Zijlstra, Linus Torvalds, Eric Dumazet, oe-kbuild-all,
	linux-kernel, Jakub Kicinski, Maciej Żenczykowski,
	Will Deacon, Paul E. McKenney

On Mon, 12 Jan 2026 21:16:25 +0000
Al Viro <viro@zeniv.linux.org.uk> wrote:

> On Mon, Jan 12, 2026 at 07:21:26PM +0000, Al Viro wrote:
> > On Mon, Jan 12, 2026 at 01:37:22PM +0100, Peter Zijlstra wrote:
> >   
> > > > #define unqual_non_array(T) __typeof__(((T(*)(void))0)())
> > > > 
> > > > would do the right thing without that _Generic cascade and it'll work
> > > > just fine for e.g. kuid_t.  Using it for an array would trigger an error,
> > > > array-returning functions being forbidden...
> > > > 
> > > > Guys, do you have any problems with replacing __unqual_scalar_typeof()
> > > > uses with that thing?  
> > > 
> > > There is also __typeof_unqual__, but I do not know if that is now
> > > supported by all compilers, if so that is the better option. If not,
> > > your function return type thing is awesome.  
> >   
> > >From experimenting with godbolt.org:  
> > 			clang		gcc		icc
> > __typeof_unqual__	>= 19.0.1	>= 14.1		no
> > this trick		>= 3.0.0	>= 8.4		>= 13.0.1
> > our minima		15.0.0		8.1
> > 
> > So __typeof_unqual__ is well out of our range; this trick is slightly
> > out of range, but nowhere near as bad.  Prior to 8.4 gcc had a bug
> > in that area, unfortunately ;-/
> > 
> > Might make sense to reconsider it next time we bump gcc minimum...  
> 
> Speaking of fun gcc bugs: prior to 11.1 gcc would not strip qualifiers
> in conditional operator; I hadn't tried to RTFS, but it almost looks like
> they took the union of qualifiers on the second and the third arguments
> of ?:
> 
> That's a direct violation of standard, all way back to C90 - the type
> of 0 ? x : x where x is an l-value of qualified type *is* explicitly
> required to be the unqualified version of that type; C90#6.2.2.1 does
> list the contexts where l-value is not converted to non-l-value and ?:
> arguments are not among those, with clearly stated requirement to strip
> qualifiers when converting to non-l-value.
> 
> Once upon a time gcc used to have a weird extension that made (a ? b : c)
> an l-value if both b and c had been, which might explain the origin of
> that bug, but that went further - even in cases like
> 	const int x;
> 	__typeof__(0 ? x : 1) y;
> they ended with const leaking to y, which would be a bug even in C++,
> where that extension for ?: originated (prvalue int as the third argument
> ends up with lvalue-to-rvalue conversions applied to the second one,
> stripping any qualifiers from it)...
> 

I got a warning from gcc for your example (massaged a bit to compile):
<source>: In function 'f':
<source>:5:18: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
    5 |         typeof(((typeof(x)(*)(void))0)()) y;

Using __auto_type y = (1 ? 0 : 0+x) gives a non-const 'y' even with gcc 10.
The 0 seems to be needed, none of +x, -x or ~x 'lose' the constness.
Note that char/short get promoted to int - but that is hard to avoid,
and happens as soon as you use the value of a char/short variable,
?: should perform integer promotion.

I've a grep of __unqual_scalar_typeof() on my 'other monitor' (one of them)
from earlier. I'm sure most of them aren't needed at all.
arm64/..../barrier.h looks very strange - the actual accesses just depend on
the size of the item (even the union looks odd to me).

	David


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-12 22:39             ` David Laight
@ 2026-01-13  0:28               ` Al Viro
  0 siblings, 0 replies; 19+ messages in thread
From: Al Viro @ 2026-01-13  0:28 UTC (permalink / raw)
  To: David Laight
  Cc: Peter Zijlstra, Linus Torvalds, Eric Dumazet, oe-kbuild-all,
	linux-kernel, Jakub Kicinski, Maciej Żenczykowski,
	Will Deacon, Paul E. McKenney

On Mon, Jan 12, 2026 at 10:39:23PM +0000, David Laight wrote:

> Using __auto_type y = (1 ? 0 : 0+x) gives a non-const 'y' even with gcc 10.

... which does not work at all for the example that has started
that thread:

typedef struct {
        uid_t val;
} kuid_t;

Arithmetics is not an option for existing uses.  , and ?: would be OK, but
they are even worse than return type - at least that got fixed in 8.4.

As for the -Wignored-qualifiers...  Sure, that's included into -Wextra, along
with many other insanities - -Wunused-parameter, for example.  Grep for
-Wextra and you'll see...

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
  2026-01-12 19:30       ` Al Viro
@ 2026-01-13 15:27         ` Peter Zijlstra
  0 siblings, 0 replies; 19+ messages in thread
From: Peter Zijlstra @ 2026-01-13 15:27 UTC (permalink / raw)
  To: Al Viro
  Cc: kernel test robot, Eric Dumazet, oe-kbuild-all, linux-kernel,
	Jakub Kicinski, Maciej Żenczykowski, Will Deacon,
	Paul E. McKenney

On Mon, Jan 12, 2026 at 07:30:19PM +0000, Al Viro wrote:

> Sure, but what does that have to do with the final cast in there?  Note
> that generic __READ_ONCE() ends up with __unqual_scalar_typeof(x) for the
> type of result and it seems to be working fine.
> 
> Why would the same type of result be a problem for alpha?  Sure, we need
> a barrier there, so it can't be literal copy of generic __READ_ONCE(),
> but what's the problem with using
> 
> #define __READ_ONCE(x)							\
> ({									\
> 	__unqual_scalar_typeof(x) __x =					\
>  		(*(volatile typeof(__x) *)(&(x)));			\
> 	mb();								\
> 	__x;								\
> })
> 
> there?  What could possibly need those qualifiers added back to the result?
> It is, after all, an r-value, so...

Yeah, I'm not sure about the final cast, that was probably trying to add
'const' back.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-01-13 15:27 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-10 21:06 include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar kernel test robot
2026-01-10 22:15 ` Al Viro
2026-01-10 22:35   ` Al Viro
2026-01-11 10:08     ` Eric Dumazet
2026-01-12 12:33       ` Peter Zijlstra
2026-01-11 18:20     ` Al Viro
2026-01-11 18:51       ` Al Viro
2026-01-12 12:37       ` Peter Zijlstra
2026-01-12 15:02         ` Will Deacon
2026-01-12 19:21         ` Al Viro
2026-01-12 21:16           ` Al Viro
2026-01-12 22:39             ` David Laight
2026-01-13  0:28               ` Al Viro
2026-01-12 12:32     ` Peter Zijlstra
2026-01-12 19:30       ` Al Viro
2026-01-13 15:27         ` Peter Zijlstra
2026-01-12  0:49   ` Philip Li
  -- strict thread matches above, loose matches on Subject: below --
2025-12-06 10:09 kernel test robot
2025-08-25  4:45 kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox