net: bonding: move bond_should_notify_peers, e.g. into rtnl lock block
Subsystems (3)
PATCH 1/1 net: bonding: move bond_should_notify_peers, e.g. into rtnl lock block
In bond_mii_monitor()/bond_activebackup_arp_mon(), when we hold the rtnl lock:
- check send_peer_notif again to avoid unconditionally reducing this value.
- send_peer_notif may have been reset. Therefore, it is necessary to check whether to send peer notify via bond_should_notify_peers() to avoid the loss of notification events.
--- drivers/net/bonding/bond_main.c | 35 ++++++++++++++------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
drivers/net/bonding/bond_main.c +15 -20
@@ -2810,11 +2810,10 @@ static void bond_mii_monitor(struct work_struct *work) { struct bonding *bond = container_of(work, struct bonding, mii_work.work); -bool should_notify_peers; -bool commit; -unsigned long delay; -struct slave *slave;struct list_head *iter; +struct slave *slave; +unsigned long delay; +bool commit; delay =msecs_to_jiffies (bond->params.miimon);
@@ -2823,7 +2822,6 @@ static void bond_mii_monitor(struct work_struct *work)rcu_read_lock (); - should_notify_peers =bond_should_notify_peers (bond); commit = !!bond_miimon_inspect (bond);rcu_read_unlock ();
@@ -2844,10 +2842,10 @@ static void bond_mii_monitor(struct work_struct *work) }if (bond->send_peer_notif) { - bond->send_peer_notif--; -if (should_notify_peers) +if (bond_should_notify_peers (bond))call_netdevice_notifiers (NETDEV_NOTIFY_PEERS , bond->dev); + bond->send_peer_notif--; }rtnl_unlock ();/* might sleep, hold no other locks */
@@ -3759,8 +3757,7 @@ static bool bond_ab_arp_probe(struct bonding *bond)static void bond_activebackup_arp_mon (struct bonding *bond) { -bool should_notify_peers = false; -bool should_notify_rtnl = false; +bool should_notify_rtnl;int delta_in_ticks; delta_in_ticks =msecs_to_jiffies (bond->params.arp_interval);
@@ -3770,15 +3767,12 @@ static void bond_activebackup_arp_mon(struct bonding *bond)rcu_read_lock (); - should_notify_peers =bond_should_notify_peers (bond); -if (bond_ab_arp_inspect (bond)) {rcu_read_unlock ();/* Race avoidance with bond_close flush of workqueue */ if (!rtnl_trylock ()) { delta_in_ticks =1 ; - should_notify_peers = false; goto re_arm; }
@@ -3791,18 +3785,15 @@ static void bond_activebackup_arp_mon(struct bonding *bond) should_notify_rtnl =bond_ab_arp_probe (bond);rcu_read_unlock (); -re_arm: -if (bond->params.arp_interval) -queue_delayed_work (bond->wq, &bond->arp_work, delta_in_ticks); - -if (should_notify_peers || should_notify_rtnl) { +if (bond->send_peer_notif || should_notify_rtnl) {if (!rtnl_trylock ())return ; -if (should_notify_peers) { +if (bond->send_peer_notif) { +if (bond_should_notify_peers (bond)) +call_netdevice_notifiers (NETDEV_NOTIFY_PEERS , + bond->dev); bond->send_peer_notif--; -call_netdevice_notifiers (NETDEV_NOTIFY_PEERS , - bond->dev); }if (should_notify_rtnl) {bond_slave_state_notify (bond);
@@ -3811,6 +3802,10 @@ static void bond_activebackup_arp_mon(struct bonding *bond)rtnl_unlock (); } + +re_arm: +if (bond->params.arp_interval) +queue_delayed_work (bond->wq, &bond->arp_work, delta_in_ticks); }static void bond_arp_monitor (struct work_struct *work)
Signature · 1 line
2.34.1
Paolo Abeni
maintainerQuoted 6 lines · Tonghao Zhang
In bond_mii_monitor()/bond_activebackup_arp_mon(), when we hold the rtnl lock:
- check
send_peer_notifagain to avoid unconditionally reducing this value.
-send_peer_notifmay have been reset. Therefore, it is necessary to check whether to send peer notify viabond_should_notify_peers()to avoid the loss of notification events.
This looks strictly related to:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
you probably should bundle both in a series.
Quoted 28 lines
drivers/net/bonding/bond_main.c +3
-5@@ -2810,11 +2810,10 @@ static void bond_mii_monitor(struct work_struct *work) { struct bonding *bond = container_of(work, struct bonding, mii_work.work); -bool should_notify_peers; -bool commit; -unsigned long delay; -struct slave *slave;struct list_head *iter; +struct slave *slave; +unsigned long delay; +bool commit; delay =msecs_to_jiffies (bond->params.miimon);@@ -2823,7 +2822,6 @@ static void bond_mii_monitor(struct work_struct *work)rcu_read_lock (); - should_notify_peers =bond_should_notify_peers (bond); commit = !!bond_miimon_inspect (bond);rcu_read_unlock ();
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct work_struct *work) · line 2844
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0@@ -2844,10 +2842,10 @@ static void bond_mii_monitor(struct work_struct *work) }if (bond->send_peer_notif) {
The first bond->send_peer_notif access is outside the lock. I think the compiler could do funny things and read the field only outside the
lock: I guess you need additional ONCE annotation, and that could be a separate patch.
Quoted 37 lines
drivers/net/bonding/bond_main.c +3
-7- bond->send_peer_notif--; -if (should_notify_peers) +if (bond_should_notify_peers (bond))call_netdevice_notifiers (NETDEV_NOTIFY_PEERS , bond->dev); + bond->send_peer_notif--; }rtnl_unlock ();/* might sleep, hold no other locks */ @@ -3759,8 +3757,7 @@ static bool bond_ab_arp_probe(struct bonding *bond)static void bond_activebackup_arp_mon (struct bonding *bond) { -bool should_notify_peers = false; -bool should_notify_rtnl = false; +bool should_notify_rtnl;int delta_in_ticks; delta_in_ticks =msecs_to_jiffies (bond->params.arp_interval);@@ -3770,15 +3767,12 @@ static void bond_activebackup_arp_mon(struct bonding *bond)rcu_read_lock (); - should_notify_peers =bond_should_notify_peers (bond); -if (bond_ab_arp_inspect (bond)) {rcu_read_unlock ();/* Race avoidance with bond_close flush of workqueue */ if (!rtnl_trylock ()) { delta_in_ticks =1 ; - should_notify_peers = false; goto re_arm; }@@ -3791,18 +3785,15 @@ static void bond_activebackup_arp_mon(struct bonding *bond) should_notify_rtnl =bond_ab_arp_probe (bond);
drivers/net/bonding/bond_main.c static void bond_activebackup_arp_mon(struct bonding *bond) · line 3790
Quoted 10 lines
drivers/net/bonding/bond_main.c +1
-5rcu_read_unlock (); -re_arm: -if (bond->params.arp_interval) -queue_delayed_work (bond->wq, &bond->arp_work, delta_in_ticks); - -if (should_notify_peers || should_notify_rtnl) { +if (bond->send_peer_notif || should_notify_rtnl) {if (!rtnl_trylock ())return ;
The above skips the 2nd trylock attempt when the first one fail, which IMHO makes sense, but its unrelated from the rest of the change here. I think this specific bits should go in a separate patch.
/P
Quoted 12 lines · Paolo Abeni
Quoted 6 lines · Tonghao Zhang
In bond_mii_monitor()/bond_activebackup_arp_mon(), when we hold the rtnl lock:
- check
send_peer_notifagain to avoid unconditionally reducing this value.
-send_peer_notifmay have been reset. Therefore, it is necessary to check whether to send peer notify viabond_should_notify_peers()to avoid the loss of notification events.
Quoted 5 lines
This looks strictly related to:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
you probably should bundle both in a series.
Ok
Quoted 31 lines
Quoted 31 lines
drivers/net/bonding/bond_main.c +3
-5@@ -2810,11 +2810,10 @@ static void bond_mii_monitor(struct work_struct *work) { struct bonding *bond = container_of(work, struct bonding, mii_work.work); -bool should_notify_peers; -bool commit; -unsigned long delay; -struct slave *slave;struct list_head *iter; +struct slave *slave; +unsigned long delay; +bool commit; delay =msecs_to_jiffies (bond->params.miimon);@@ -2823,7 +2822,6 @@ static void bond_mii_monitor(struct work_struct *work)rcu_read_lock (); - should_notify_peers =bond_should_notify_peers (bond); commit = !!bond_miimon_inspect (bond);rcu_read_unlock ();@@ -2844,10 +2842,10 @@ static void bond_mii_monitor(struct work_struct *work) }
Quoted 6 lines
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct work_struct *work) · line 2844
Quoted 1 line
drivers/net/bonding/bond_main.c +0
-0if (bond->send_peer_notif) {The first
bond->send_peer_notifaccess is outside the lock. I think the compiler could do funny things and read the field only outside the
lock: I guess you need additional ONCE annotation, and that could be a separate patch.
Ok
Quoted 40 lines
Quoted 40 lines
drivers/net/bonding/bond_main.c +2
-2- bond->send_peer_notif--; -if (should_notify_peers) +if (bond_should_notify_peers (bond))call_netdevice_notifiers (NETDEV_NOTIFY_PEERS , bond->dev); + bond->send_peer_notif--; }
rtnl_unlock(); /* might sleep, hold no other locks */drivers/net/bonding/bond_main.c +1
-5@@ -3759,8 +3757,7 @@ static bool bond_ab_arp_probe(struct bonding *bond)static void bond_activebackup_arp_mon (struct bonding *bond) { -bool should_notify_peers = false; -bool should_notify_rtnl = false; +bool should_notify_rtnl;int delta_in_ticks; delta_in_ticks =msecs_to_jiffies (bond->params.arp_interval);@@ -3770,15 +3767,12 @@ static void bond_activebackup_arp_mon(struct bonding *bond)rcu_read_lock (); - should_notify_peers =bond_should_notify_peers (bond); -if (bond_ab_arp_inspect (bond)) {rcu_read_unlock ();/* Race avoidance with bond_close flush of workqueue */ if (!rtnl_trylock ()) { delta_in_ticks =1 ; - should_notify_peers = false; goto re_arm; }@@ -3791,18 +3785,15 @@ static void bond_activebackup_arp_mon(struct bonding *bond) should_notify_rtnl =bond_ab_arp_probe (bond);rcu_read_unlock ();
Quoted 12 lines
drivers/net/bonding/bond_main.c static void bond_activebackup_arp_mon(struct bonding *bond) · line 3790
Quoted 8 lines
drivers/net/bonding/bond_main.c +1
-5-re_arm: -if (bond->params.arp_interval) -queue_delayed_work (bond->wq, &bond->arp_work, delta_in_ticks); - -if (should_notify_peers || should_notify_rtnl) { +if (bond->send_peer_notif || should_notify_rtnl) {if (!rtnl_trylock ())return ;The above skips the 2nd trylock attempt when the first one fail, which IMHO makes sense, but its unrelated from the rest of the change here. I think this specific bits should go in a separate patch.
Ok, thanks.
Quoted 5 lines
/P