Re: [PATCH v1 1/5] riscv/cmpxchg: Deduplicate xchg() asm functions

Leonardo Bras
2024-01-16T19:27:22Z

On Sat, Jan 13, 2024 at 02:54:17PM +0800, kernel test robot wrote:
> Hi Leonardo,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on 610a9b8f49fbcf1100716370d3b5f6f884a2835a]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Leonardo-Bras/riscv-cmpxchg-Deduplicate-xchg-asm-functions/20240104-003501

Cloned this repo

> base: 610a9b8f49fbcf1100716370d3b5f6f884a2835a
> patch link: https://lore.kernel.org/r/20240103163203.72768-3-leobras%40redhat.com
> patch subject: [PATCH v1 1/5] riscv/cmpxchg: Deduplicate xchg() asm functions
> config: riscv-randconfig-r111-20240112 (https://download.01.org/0day-ci/archive/20240113/202401131438.f8SELM0W-lkp@intel.com/config)
> compiler: clang version 18.0.0git (https://github.com/llvm/llvm-project 9bde5becb44ea071f5e1fa1f5d4071dc8788b18c)
> reproduce: (https://download.01.org/0day-ci/archive/20240113/202401131438.f8SELM0W-lkp@intel.com/reproduce)

And followed those instructions, while using sparse v0.6.4-52-g1cf3d98c.

>
> 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/202401131438.f8SELM0W-lkp@intel.com/
>
> sparse warnings: (new ones prefixed by >>)
> >> net/ipv4/tcp_cong.c:300:24: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct tcp_congestion_ops const [noderef] __rcu *__new @@ got struct tcp_congestion_ops *[assigned] ca @@
> net/ipv4/tcp_cong.c:300:24: sparse: expected struct tcp_congestion_ops const [noderef] __rcu *__new
> net/ipv4/tcp_cong.c:300:24: sparse: got struct tcp_congestion_ops *[assigned] ca
> net/ipv4/tcp_cong.c:300:22: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct tcp_congestion_ops const *prev @@ got struct tcp_congestion_ops const [noderef] __rcu * @@
> net/ipv4/tcp_cong.c:300:22: sparse: expected struct tcp_congestion_ops const *prev
> net/ipv4/tcp_cong.c:300:22: sparse: got struct tcp_congestion_ops const [noderef] __rcu *
> net/ipv4/tcp_cong.c: note: in included file (through include/linux/module.h):
> include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true
> include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true
>
> vim +300 net/ipv4/tcp_cong.c
>
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 281
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 282 /* Used by sysctl to change default congestion control */
> 6670e152447732 Stephen Hemminger 2017-11-14 283 int tcp_set_default_congestion_control(struct net *net, const char *name)
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 284 {
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 285 struct tcp_congestion_ops *ca;
> 6670e152447732 Stephen Hemminger 2017-11-14 286 const struct tcp_congestion_ops *prev;
> 6670e152447732 Stephen Hemminger 2017-11-14 287 int ret;
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 288
> 6670e152447732 Stephen Hemminger 2017-11-14 289 rcu_read_lock();
> 6670e152447732 Stephen Hemminger 2017-11-14 290 ca = tcp_ca_find_autoload(net, name);
> 6670e152447732 Stephen Hemminger 2017-11-14 291 if (!ca) {
> 6670e152447732 Stephen Hemminger 2017-11-14 292 ret = -ENOENT;
> 0baf26b0fcd74b Martin KaFai Lau 2020-01-08 293 } else if (!bpf_try_module_get(ca, ca->owner)) {
> 6670e152447732 Stephen Hemminger 2017-11-14 294 ret = -EBUSY;
> 8d432592f30fcc Jonathon Reinhart 2021-05-01 295 } else if (!net_eq(net, &init_net) &&
> 8d432592f30fcc Jonathon Reinhart 2021-05-01 296 !(ca->flags & TCP_CONG_NON_RESTRICTED)) {
> 8d432592f30fcc Jonathon Reinhart 2021-05-01 297 /* Only init netns can set default to a restricted algorithm */
> 8d432592f30fcc Jonathon Reinhart 2021-05-01 298 ret = -EPERM;
> 6670e152447732 Stephen Hemminger 2017-11-14 299 } else {
> 6670e152447732 Stephen Hemminger 2017-11-14 @300 prev = xchg(&net->ipv4.tcp_congestion_control, ca);
> 6670e152447732 Stephen Hemminger 2017-11-14 301 if (prev)
> 0baf26b0fcd74b Martin KaFai Lau 2020-01-08 302 bpf_module_put(prev, prev->owner);
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 303
> 6670e152447732 Stephen Hemminger 2017-11-14 304 ca->flags |= TCP_CONG_NON_RESTRICTED;
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 305 ret = 0;
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 306 }
> 6670e152447732 Stephen Hemminger 2017-11-14 307 rcu_read_unlock();
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 308
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 309 return ret;
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 310 }
> 317a76f9a44b43 Stephen Hemminger 2005-06-23 311
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
>

I did some testing using the instructions above on above file, and patch
1/5 haven't introduced anything new.

Command for gathering sparse warnings:
COMPILER_INSTALL_PATH=$HOME/0day ~/lkp-tests/kbuild/make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__ -fmax-errors=unlimited -fmax-warnings=unlimited' O=build_dir ARCH=riscv SHELL=/bin/bash net/ipv4/tcp_cong.o 2> sparse

I ran this for the commit mentioned in the reproduction instructions
(7931dc023 : riscv/cmpxchg: Deduplicate xchg() asm functions ) and for it's
parent (610a9b8f49 : Linux 6.7-rc8). The diff -u on the output was:

# diff -u sparse_vanilla sparse_p1_5
--- sparse_vanilla 2024-01-16 14:16:36.217965076 -0500
+++ sparse_p1_5 2024-01-16 14:15:29.942712160 -0500
@@ -1,5 +1,5 @@
../net/ipv4/tcp_cong.c:300:24: sparse: warning: incorrect type in initializer (different address spaces)
-../net/ipv4/tcp_cong.c:300:24: sparse: expected struct tcp_congestion_ops const [noderef] __rcu *_x_
+../net/ipv4/tcp_cong.c:300:24: sparse: expected struct tcp_congestion_ops const [noderef] __rcu *__new
../net/ipv4/tcp_cong.c:300:24: sparse: got struct tcp_congestion_ops *[assigned] ca
../net/ipv4/tcp_cong.c:300:22: sparse: warning: incorrect type in assignment (different address spaces)
../net/ipv4/tcp_cong.c:300:22: sparse: expected struct tcp_congestion_ops const *prev

So I did not introduce anything new, as per sparse v0.6.4-52-g1cf3d98c .

I noticed the output is slightly different, and that in the reproduction
steps this used:
# sparse version: v0.6.4-52-g1cf3d98c-dirty

Since there is no indicator on what the -dirty stands for, it's hard for me
to get the same reproduction, but as far as I could test there is not
any new error.

Thanks!
Leo