All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing
  2025-11-25  8:44 [PATCH net-next v1 0/5] A series of minor optimizations of the bonding module Tonghao Zhang
@ 2025-11-25  8:44 ` Tonghao Zhang
  2025-11-25 23:56   ` kernel test robot
  2025-11-26  1:25   ` Jason Xing
  0 siblings, 2 replies; 5+ messages in thread
From: Tonghao Zhang @ 2025-11-25  8:44 UTC (permalink / raw)
  To: netdev
  Cc: Tonghao Zhang, Jay Vosburgh, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
	Andrew Lunn, Nikolay Aleksandrov, Hangbin Liu

Although operations on the variable send_peer_notif are already within
a lock-protected critical section, there are cases where it is accessed
outside the lock. Therefore, READ_ONCE() and WRITE_ONCE() should be
added to it.

Cc: Jay Vosburgh <jv@jvosburgh.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: Nikolay Aleksandrov <razor@blackwall.org>
Cc: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Tonghao Zhang <tonghao@bamaicloud.com>
---
 drivers/net/bonding/bond_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 025ca0a45615..5f04197e29f7 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1204,8 +1204,9 @@ void bond_peer_notify_work_rearm(struct bonding *bond, unsigned long delay)
 /* Peer notify update handler. Holds only RTNL */
 static void bond_peer_notify_reset(struct bonding *bond)
 {
-	bond->send_peer_notif = bond->params.num_peer_notif *
-		max(1, bond->params.peer_notif_delay);
+	WRITE_ONCE(bond->send_peer_notif,
+		   bond->params.num_peer_notif *
+		   max(1, bond->params.peer_notif_delay);
 }
 
 static void bond_peer_notify_handler(struct work_struct *work)
@@ -2825,7 +2826,7 @@ static void bond_mii_monitor(struct work_struct *work)
 
 	rcu_read_unlock();
 
-	if (commit || bond->send_peer_notif) {
+	if (commit || READ_ONCE(bond->send_peer_notif) {
 		/* Race avoidance with bond_close cancel of workqueue */
 		if (!rtnl_trylock()) {
 			delay = 1;
@@ -3784,7 +3785,7 @@ static void bond_activebackup_arp_mon(struct bonding *bond)
 	should_notify_rtnl = bond_ab_arp_probe(bond);
 	rcu_read_unlock();
 
-	if (bond->send_peer_notif || should_notify_rtnl) {
+	if (READ_ONCE(bond->send_peer_notif) || should_notify_rtnl) {
 		if (!rtnl_trylock()) {
 			delta_in_ticks = 1;
 			goto re_arm;
-- 
2.34.1


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

* Re: [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing
  2025-11-25  8:44 ` [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing Tonghao Zhang
@ 2025-11-25 23:56   ` kernel test robot
  2025-11-26  1:25   ` Jason Xing
  1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-11-25 23:56 UTC (permalink / raw)
  To: Tonghao Zhang, netdev
  Cc: llvm, oe-kbuild-all, Tonghao Zhang, Jay Vosburgh, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
	Andrew Lunn, Nikolay Aleksandrov, Hangbin Liu

Hi Tonghao,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Tonghao-Zhang/net-bonding-use-workqueue-to-make-sure-peer-notify-updated-in-lacp-mode/20251125-164825
base:   net-next/main
patch link:    https://lore.kernel.org/r/20251125084451.11632-5-tonghao%40bamaicloud.com
patch subject: [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing
config: loongarch-defconfig (https://download.01.org/0day-ci/archive/20251126/202511260755.PsI0heoq-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251126/202511260755.PsI0heoq-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/202511260755.PsI0heoq-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/net/bonding/bond_main.c:1207:2: error: unterminated function-like macro invocation
    1207 |         WRITE_ONCE(bond->send_peer_notif,
         |         ^
   include/asm-generic/rwonce.h:58:9: note: macro 'WRITE_ONCE' defined here
      58 | #define WRITE_ONCE(x, val)                                              \
         |         ^
>> drivers/net/bonding/bond_main.c:6585:37: error: expected '}'
    6585 | MODULE_IMPORT_NS("NETDEV_INTERNAL");
         |                                     ^
   drivers/net/bonding/bond_main.c:1206:1: note: to match this '{'
    1206 | {
         | ^
   2 errors generated.


vim +1207 drivers/net/bonding/bond_main.c

  1203	
  1204	/* Peer notify update handler. Holds only RTNL */
  1205	static void bond_peer_notify_reset(struct bonding *bond)
  1206	{
> 1207		WRITE_ONCE(bond->send_peer_notif,
  1208			   bond->params.num_peer_notif *
  1209			   max(1, bond->params.peer_notif_delay);
  1210	}
  1211	

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

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

* Re: [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing
@ 2025-11-26  0:50 kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-11-26  0:50 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "low confidence bisect report"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20251125084451.11632-5-tonghao@bamaicloud.com>
References: <20251125084451.11632-5-tonghao@bamaicloud.com>
TO: Tonghao Zhang <tonghao@bamaicloud.com>
TO: netdev@vger.kernel.org
CC: Tonghao Zhang <tonghao@bamaicloud.com>
CC: Jay Vosburgh <jv@jvosburgh.net>
CC: Eric Dumazet <edumazet@google.com>
CC: Jakub Kicinski <kuba@kernel.org>
CC: Paolo Abeni <pabeni@redhat.com>
CC: Simon Horman <horms@kernel.org>
CC: Jonathan Corbet <corbet@lwn.net>
CC: Andrew Lunn <andrew+netdev@lunn.ch>
CC: Nikolay Aleksandrov <razor@blackwall.org>
CC: Hangbin Liu <liuhangbin@gmail.com>

Hi Tonghao,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Tonghao-Zhang/net-bonding-use-workqueue-to-make-sure-peer-notify-updated-in-lacp-mode/20251125-164825
base:   net-next/main
patch link:    https://lore.kernel.org/r/20251125084451.11632-5-tonghao%40bamaicloud.com
patch subject: [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing
:::::: branch date: 16 hours ago
:::::: commit date: 16 hours ago
config: x86_64-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20251126/202511260730.QubKBTo6-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251126/202511260730.QubKBTo6-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/r/202511260730.QubKBTo6-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   drivers/net/bonding/bond_main.c: In function 'bond_peer_notify_reset':
>> drivers/net/bonding/bond_main.c:6585:37: error: unterminated argument list invoking macro "WRITE_ONCE"
    6585 | MODULE_IMPORT_NS("NETDEV_INTERNAL");
         |                                     ^
>> drivers/net/bonding/bond_main.c:1207:9: error: 'WRITE_ONCE' undeclared (first use in this function)
    1207 |         WRITE_ONCE(bond->send_peer_notif,
         |         ^~~~~~~~~~
   drivers/net/bonding/bond_main.c:1207:9: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/net/bonding/bond_main.c:1207:19: error: expected ';' at end of input
    1207 |         WRITE_ONCE(bond->send_peer_notif,
         |                   ^
         |                   ;
   ......
>> drivers/net/bonding/bond_main.c:1207:9: error: expected declaration or statement at end of input
    1207 |         WRITE_ONCE(bond->send_peer_notif,
         |         ^~~~~~~~~~
   drivers/net/bonding/bond_main.c: At top level:
>> drivers/net/bonding/bond_main.c:263:12: warning: 'bond_init' declared 'static' but never defined [-Wunused-function]
     263 | static int bond_init(struct net_device *bond_dev);
         |            ^~~~~~~~~
>> drivers/net/bonding/bond_main.c:264:13: warning: 'bond_uninit' declared 'static' but never defined [-Wunused-function]
     264 | static void bond_uninit(struct net_device *bond_dev);
         |             ^~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:265:13: warning: 'bond_get_stats' declared 'static' but never defined [-Wunused-function]
     265 | static void bond_get_stats(struct net_device *bond_dev,
         |             ^~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:267:13: warning: 'bond_slave_arr_handler' declared 'static' but never defined [-Wunused-function]
     267 | static void bond_slave_arr_handler(struct work_struct *work);
         |             ^~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:268:13: warning: 'bond_time_in_interval' declared 'static' but never defined [-Wunused-function]
     268 | static bool bond_time_in_interval(struct bonding *bond, unsigned long last_act,
         |             ^~~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:270:13: warning: 'bond_netdev_notify_work' declared 'static' but never defined [-Wunused-function]
     270 | static void bond_netdev_notify_work(struct work_struct *work);
         |             ^~~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:1205:13: warning: 'bond_peer_notify_reset' defined but not used [-Wunused-function]
    1205 | static void bond_peer_notify_reset(struct bonding *bond)
         |             ^~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:1166:13: warning: 'bond_should_notify_peers' defined but not used [-Wunused-function]
    1166 | static bool bond_should_notify_peers(struct bonding *bond)
         |             ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:1142:22: warning: 'bond_find_best_slave' defined but not used [-Wunused-function]
    1142 | static struct slave *bond_find_best_slave(struct bonding *bond)
         |                      ^~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:1004:13: warning: 'bond_do_fail_over_mac' defined but not used [-Wunused-function]
    1004 | static void bond_do_fail_over_mac(struct bonding *bond,
         |             ^~~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:922:13: warning: 'bond_hw_addr_swap' defined but not used [-Wunused-function]
     922 | static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
         |             ^~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:884:13: warning: 'bond_resend_igmp_join_requests_delayed' defined but not used [-Wunused-function]
     884 | static void bond_resend_igmp_join_requests_delayed(struct work_struct *work)
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:858:12: warning: 'bond_set_allmulti' defined but not used [-Wunused-function]
     858 | static int bond_set_allmulti(struct bonding *bond, int inc)
         |            ^~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:835:12: warning: 'bond_set_promiscuity' defined but not used [-Wunused-function]
     835 | static int bond_set_promiscuity(struct bonding *bond, int inc)
         |            ^~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:788:12: warning: 'bond_update_speed_duplex' defined but not used [-Wunused-function]
     788 | static int bond_update_speed_duplex(struct slave *slave)
         |            ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/bonding/bond_main.c:735:33: warning: 'bond_xfrmdev_ops' defined but not used [-Wunused-const-variable=]
     735 | static const struct xfrmdev_ops bond_xfrmdev_ops = {
         |                                 ^~~~~~~~~~~~~~~~
   drivers/net/bonding/bond_main.c:593:13: warning: 'bond_ipsec_del_sa_all' defined but not used [-Wunused-function]
     593 | static void bond_ipsec_del_sa_all(struct bonding *bond)
         |             ^~~~~~~~~~~~~~~~~~~~~
   drivers/net/bonding/bond_main.c:516:13: warning: 'bond_ipsec_add_sa_all' defined but not used [-Wunused-function]
     516 | static void bond_ipsec_add_sa_all(struct bonding *bond)
         |             ^~~~~~~~~~~~~~~~~~~~~
   drivers/net/bonding/bond_main.c:404:12: warning: 'bond_vlan_rx_kill_vid' defined but not used [-Wunused-function]
     404 | static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,
         |            ^~~~~~~~~~~~~~~~~~~~~
   drivers/net/bonding/bond_main.c:370:12: warning: 'bond_vlan_rx_add_vid' defined but not used [-Wunused-function]
     370 | static int bond_vlan_rx_add_vid(struct net_device *bond_dev,
         |            ^~~~~~~~~~~~~~~~~~~~
   drivers/net/bonding/bond_main.c:314:13: warning: 'bond_sk_check' defined but not used [-Wunused-function]
     314 | static bool bond_sk_check(struct bonding *bond)
         |             ^~~~~~~~~~~~~
   drivers/net/bonding/bond_main.c:259:30: warning: 'flow_keys_bonding' defined but not used [-Wunused-variable]
     259 | static struct flow_dissector flow_keys_bonding __read_mostly;
         |                              ^~~~~~~~~~~~~~~~~
   drivers/net/bonding/bond_main.c:216:40: warning: 'flow_keys_bonding_keys' defined but not used [-Wunused-const-variable=]
     216 | static const struct flow_dissector_key flow_keys_bonding_keys[] = {
         |                                        ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/bonding/bond_main.c:122:27: warning: 'bonding_defaults' defined but not used [-Wunused-variable]
     122 | static struct bond_params bonding_defaults;
         |                           ^~~~~~~~~~~~~~~~


vim +/WRITE_ONCE +6585 drivers/net/bonding/bond_main.c

^1da177e4c3f41 Linus Torvalds     2005-04-16  6579  
^1da177e4c3f41 Linus Torvalds     2005-04-16  6580  module_init(bonding_init);
^1da177e4c3f41 Linus Torvalds     2005-04-16  6581  module_exit(bonding_exit);
^1da177e4c3f41 Linus Torvalds     2005-04-16  6582  MODULE_LICENSE("GPL");
2b526b56e39628 Leon Romanovsky    2020-02-24  6583  MODULE_DESCRIPTION(DRV_DESCRIPTION);
^1da177e4c3f41 Linus Torvalds     2005-04-16  6584  MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");
0413a34ef678c3 Stanislav Fomichev 2025-07-17 @6585  MODULE_IMPORT_NS("NETDEV_INTERNAL");

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

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

* Re: [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing
  2025-11-25  8:44 ` [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing Tonghao Zhang
  2025-11-25 23:56   ` kernel test robot
@ 2025-11-26  1:25   ` Jason Xing
  2025-11-26  2:05     ` Tonghao Zhang
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Xing @ 2025-11-26  1:25 UTC (permalink / raw)
  To: Tonghao Zhang
  Cc: netdev, Jay Vosburgh, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
	Andrew Lunn, Nikolay Aleksandrov, Hangbin Liu

On Tue, Nov 25, 2025 at 4:45 PM Tonghao Zhang <tonghao@bamaicloud.com> wrote:
>
> Although operations on the variable send_peer_notif are already within
> a lock-protected critical section, there are cases where it is accessed
> outside the lock. Therefore, READ_ONCE() and WRITE_ONCE() should be
> added to it.
>
> Cc: Jay Vosburgh <jv@jvosburgh.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Simon Horman <horms@kernel.org>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Andrew Lunn <andrew+netdev@lunn.ch>
> Cc: Nikolay Aleksandrov <razor@blackwall.org>
> Cc: Hangbin Liu <liuhangbin@gmail.com>
> Signed-off-by: Tonghao Zhang <tonghao@bamaicloud.com>
> ---
>  drivers/net/bonding/bond_main.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 025ca0a45615..5f04197e29f7 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -1204,8 +1204,9 @@ void bond_peer_notify_work_rearm(struct bonding *bond, unsigned long delay)
>  /* Peer notify update handler. Holds only RTNL */
>  static void bond_peer_notify_reset(struct bonding *bond)
>  {
> -       bond->send_peer_notif = bond->params.num_peer_notif *
> -               max(1, bond->params.peer_notif_delay);
> +       WRITE_ONCE(bond->send_peer_notif,
> +                  bond->params.num_peer_notif *
> +                  max(1, bond->params.peer_notif_delay);
>  }
>
>  static void bond_peer_notify_handler(struct work_struct *work)
> @@ -2825,7 +2826,7 @@ static void bond_mii_monitor(struct work_struct *work)
>
>         rcu_read_unlock();
>
> -       if (commit || bond->send_peer_notif) {
> +       if (commit || READ_ONCE(bond->send_peer_notif) {

Also there is a lack of another bracket... It's not hard to spot this
error if you complete compilation.

Thanks,
Jason

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

* Re: [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing
  2025-11-26  1:25   ` Jason Xing
@ 2025-11-26  2:05     ` Tonghao Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Tonghao Zhang @ 2025-11-26  2:05 UTC (permalink / raw)
  To: Jason Xing
  Cc: netdev, Jay Vosburgh, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
	Andrew Lunn, Nikolay Aleksandrov, Hangbin Liu


> On Nov 26, 2025, at 09:25, Jason Xing <kerneljasonxing@gmail.com> wrote:
> 
> Also there is a lack of another bracket... It's not hard to spot this
I'm very sorry. Before sending the email, I adjusted the order of the patch files, 4/5 and 5/5.

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

end of thread, other threads:[~2025-11-26  2:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26  0:50 [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2025-11-25  8:44 [PATCH net-next v1 0/5] A series of minor optimizations of the bonding module Tonghao Zhang
2025-11-25  8:44 ` [PATCH net-next v1 4/5] net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing Tonghao Zhang
2025-11-25 23:56   ` kernel test robot
2025-11-26  1:25   ` Jason Xing
2025-11-26  2:05     ` Tonghao Zhang

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.