All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: lkp@intel.com, davem@davemloft.net, edumazet@google.com,
	kbuild-all@lists.01.org, kuba@kernel.org, llvm@lists.linux.dev,
	netdev@vger.kernel.org, pabeni@redhat.com
Subject: Re: [PATCH v2 net 13/17] net: Fix data-races around sysctl_fb_tunnels_only_for_init_net.
Date: Thu, 18 Aug 2022 09:23:19 -0700	[thread overview]
Message-ID: <Yv5nd3cVX2ZKysC/@dev-arch.thelio-3990X> (raw)
In-Reply-To: <20220818150154.29112-1-kuniyu@amazon.com>

On Thu, Aug 18, 2022 at 08:01:54AM -0700, Kuniyuki Iwashima wrote:
> From:   kernel test robot <lkp@intel.com>
> Date:   Thu, 18 Aug 2022 16:51:37 +0800
> > Hi Kuniyuki,
> > 
> > Thank you for the patch! Yet something to improve:
> > 
> > [auto build test ERROR on net/master]
> > 
> > url:    https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/net-sysctl-Fix-data-races-around-net-core-XXX/20220818-115941
> > base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git fc4aaf9fb3c99bcb326d52f9d320ed5680bd1cee
> > config: riscv-randconfig-r032-20220818 (https://download.01.org/0day-ci/archive/20220818/202208181615.Lu9xjiEv-lkp@intel.com/config)
> > compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project aed5e3bea138ce581d682158eb61c27b3cfdd6ec)
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # install riscv cross compiling tool for clang build
> >         # apt-get install binutils-riscv64-linux-gnu
> >         # https://github.com/intel-lab-lkp/linux/commit/6bc3dfb3dc4862f4e00ba93c45cd5c0251b85d5b
> >         git remote add linux-review https://github.com/intel-lab-lkp/linux
> >         git fetch --no-tags linux-review Kuniyuki-Iwashima/net-sysctl-Fix-data-races-around-net-core-XXX/20220818-115941
> >         git checkout 6bc3dfb3dc4862f4e00ba93c45cd5c0251b85d5b
> >         # save the config file
> >         mkdir build_dir && cp config build_dir/.config
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
> > 
> > If you fix the issue, kindly add following tag where applicable
> > Reported-by: kernel test robot <lkp@intel.com>
> > 
> > All errors (new ones prefixed by >>):
> > 
> > >> ld.lld: error: undefined symbol: sysctl_fb_tunnels_only_for_init_net
> >    >>> referenced by ip_tunnel.c
> >    >>>               ipv4/ip_tunnel.o:(ip_tunnel_init_net) in archive net/built-in.a
> >    >>> referenced by ip_tunnel.c
> >    >>>               ipv4/ip_tunnel.o:(ip_tunnel_init_net) in archive net/built-in.a
> 
> Hmm... I tested allmodconfig with x86_64 but it seems not enough...
> 
> I don't think just using READ_ONCE() causes regression.
> Is this really regression or always-broken stuff in some arch,
> or ... clang 16?
> 
> Anyway, I'll take a look.

You'll see the same error with the same configuration and GCC:

riscv64-linux-gnu-ld: net/ipv4/ip_tunnel.o: in function `.L536':
ip_tunnel.c:(.text+0x1d4a): undefined reference to `sysctl_fb_tunnels_only_for_init_net'
riscv64-linux-gnu-ld: ip_tunnel.c:(.text+0x1d4e): undefined reference to `sysctl_fb_tunnels_only_for_init_net'

$ scripts/config --file build/riscv/.config -s SYSCTL
undef

Prior to your change, the '!IS_ENABLED(CONFIG_SYSCTL)' would cause
net_has_fallback_tunnels() to unconditionally 'return 1' in the
CONFIG_SYSCTL=n case, meaning 'fb_tunnels_only_for_init_net' was never
emitted in the final assembly so the linker would not complain about it
never being defined (the kernel relies on this trick a lot, which is why
you cannot build the kernel with -O0).

After your change, sysctl_fb_tunnels_only_for_init_net is
unconditionally used but it is only defined in sysctl_net_core.c, which
is only built when CONFIG_SYSCTL=y, hence the link error.

I suspect hoisting '!IS_ENABLED(CONFIG_SYSCTL)' out of the return into
its own conditional would fix the error:

  static inline bool net_has_fallback_tunnels(const struct net *net)
  {
      int fb_tunnels_only_for_init_net;

      if (!IS_ENABLED(CONFIG_SYSCTL))
          return true;

      fb_tunnels_only_for_init_net = READ_ONCE(sysctl_fb_tunnels_only_for_init_net);

      return !fb_tunnels_only_for_init_net ||
             (net == &init_net && fb_tunnels_only_for_init_net == 1)
  }

Cheers,
Nathan

WARNING: multiple messages have this Message-ID (diff)
From: Nathan Chancellor <nathan@kernel.org>
To: kbuild-all@lists.01.org
Subject: Re: [PATCH v2 net 13/17] net: Fix data-races around sysctl_fb_tunnels_only_for_init_net.
Date: Thu, 18 Aug 2022 09:23:19 -0700	[thread overview]
Message-ID: <Yv5nd3cVX2ZKysC/@dev-arch.thelio-3990X> (raw)
In-Reply-To: <20220818150154.29112-1-kuniyu@amazon.com>

[-- Attachment #1: Type: text/plain, Size: 3988 bytes --]

On Thu, Aug 18, 2022 at 08:01:54AM -0700, Kuniyuki Iwashima wrote:
> From:   kernel test robot <lkp@intel.com>
> Date:   Thu, 18 Aug 2022 16:51:37 +0800
> > Hi Kuniyuki,
> > 
> > Thank you for the patch! Yet something to improve:
> > 
> > [auto build test ERROR on net/master]
> > 
> > url:    https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/net-sysctl-Fix-data-races-around-net-core-XXX/20220818-115941
> > base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git fc4aaf9fb3c99bcb326d52f9d320ed5680bd1cee
> > config: riscv-randconfig-r032-20220818 (https://download.01.org/0day-ci/archive/20220818/202208181615.Lu9xjiEv-lkp(a)intel.com/config)
> > compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project aed5e3bea138ce581d682158eb61c27b3cfdd6ec)
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # install riscv cross compiling tool for clang build
> >         # apt-get install binutils-riscv64-linux-gnu
> >         # https://github.com/intel-lab-lkp/linux/commit/6bc3dfb3dc4862f4e00ba93c45cd5c0251b85d5b
> >         git remote add linux-review https://github.com/intel-lab-lkp/linux
> >         git fetch --no-tags linux-review Kuniyuki-Iwashima/net-sysctl-Fix-data-races-around-net-core-XXX/20220818-115941
> >         git checkout 6bc3dfb3dc4862f4e00ba93c45cd5c0251b85d5b
> >         # save the config file
> >         mkdir build_dir && cp config build_dir/.config
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
> > 
> > If you fix the issue, kindly add following tag where applicable
> > Reported-by: kernel test robot <lkp@intel.com>
> > 
> > All errors (new ones prefixed by >>):
> > 
> > >> ld.lld: error: undefined symbol: sysctl_fb_tunnels_only_for_init_net
> >    >>> referenced by ip_tunnel.c
> >    >>>               ipv4/ip_tunnel.o:(ip_tunnel_init_net) in archive net/built-in.a
> >    >>> referenced by ip_tunnel.c
> >    >>>               ipv4/ip_tunnel.o:(ip_tunnel_init_net) in archive net/built-in.a
> 
> Hmm... I tested allmodconfig with x86_64 but it seems not enough...
> 
> I don't think just using READ_ONCE() causes regression.
> Is this really regression or always-broken stuff in some arch,
> or ... clang 16?
> 
> Anyway, I'll take a look.

You'll see the same error with the same configuration and GCC:

riscv64-linux-gnu-ld: net/ipv4/ip_tunnel.o: in function `.L536':
ip_tunnel.c:(.text+0x1d4a): undefined reference to `sysctl_fb_tunnels_only_for_init_net'
riscv64-linux-gnu-ld: ip_tunnel.c:(.text+0x1d4e): undefined reference to `sysctl_fb_tunnels_only_for_init_net'

$ scripts/config --file build/riscv/.config -s SYSCTL
undef

Prior to your change, the '!IS_ENABLED(CONFIG_SYSCTL)' would cause
net_has_fallback_tunnels() to unconditionally 'return 1' in the
CONFIG_SYSCTL=n case, meaning 'fb_tunnels_only_for_init_net' was never
emitted in the final assembly so the linker would not complain about it
never being defined (the kernel relies on this trick a lot, which is why
you cannot build the kernel with -O0).

After your change, sysctl_fb_tunnels_only_for_init_net is
unconditionally used but it is only defined in sysctl_net_core.c, which
is only built when CONFIG_SYSCTL=y, hence the link error.

I suspect hoisting '!IS_ENABLED(CONFIG_SYSCTL)' out of the return into
its own conditional would fix the error:

  static inline bool net_has_fallback_tunnels(const struct net *net)
  {
      int fb_tunnels_only_for_init_net;

      if (!IS_ENABLED(CONFIG_SYSCTL))
          return true;

      fb_tunnels_only_for_init_net = READ_ONCE(sysctl_fb_tunnels_only_for_init_net);

      return !fb_tunnels_only_for_init_net ||
             (net == &init_net && fb_tunnels_only_for_init_net == 1)
  }

Cheers,
Nathan

  reply	other threads:[~2022-08-18 16:23 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18  3:52 [PATCH v2 net 00/17] net: sysctl: Fix data-races around net.core.XXX Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 01/17] net: Fix data-races around sysctl_[rw]mem_(max|default) Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 02/17] net: Fix data-races around weight_p and dev_weight_[rt]x_bias Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 03/17] net: Fix data-races around netdev_max_backlog Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 04/17] net: Fix data-races around netdev_tstamp_prequeue Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 05/17] ratelimit: Fix data-races in ___ratelimit() Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 06/17] net: Fix data-races around sysctl_optmem_max Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 07/17] net: Fix a data-race around sysctl_tstamp_allow_data Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 08/17] net: Fix a data-race around sysctl_net_busy_poll Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 09/17] net: Fix a data-race around sysctl_net_busy_read Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 10/17] net: Fix a data-race around netdev_budget Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 11/17] net: Fix data-races around sysctl_max_skb_frags Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 12/17] net: Fix a data-race around netdev_budget_usecs Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 13/17] net: Fix data-races around sysctl_fb_tunnels_only_for_init_net Kuniyuki Iwashima
2022-08-18  7:58   ` kernel test robot
2022-08-18  8:51   ` kernel test robot
2022-08-18 15:01     ` Kuniyuki Iwashima
2022-08-18 15:01       ` Kuniyuki Iwashima
2022-08-18 16:23       ` Nathan Chancellor [this message]
2022-08-18 16:23         ` Nathan Chancellor
2022-08-18 16:41         ` Kuniyuki Iwashima
2022-08-18 16:41           ` Kuniyuki Iwashima
2022-08-18 16:17   ` Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 14/17] net: Fix data-races around sysctl_devconf_inherit_init_net Kuniyuki Iwashima
2022-08-18  3:52 ` [PATCH v2 net 15/17] net: Fix a data-race around gro_normal_batch Kuniyuki Iwashima
2022-08-18 13:22   ` Edward Cree
2022-08-18  3:52 ` [PATCH v2 net 16/17] net: Fix a data-race around netdev_unregister_timeout_secs Kuniyuki Iwashima
2022-08-18  6:53   ` Dmitry Vyukov
2022-08-18  3:52 ` [PATCH v2 net 17/17] net: Fix a data-race around sysctl_somaxconn Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yv5nd3cVX2ZKysC/@dev-arch.thelio-3990X \
    --to=nathan@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kbuild-all@lists.01.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.