Skip to contentSkip to conversation

Bonding: fix high prio not effect issue

PATCH In review Hangbin Liu 4 participants 12 messages Dec 9, 2022 – Dec 12, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Bonding: fix high prio not effect issue

When a high prio link up, if there has current link, it will not do failover as we missed the check in link up event. Fix it in this patchset and add a prio option test case.

Hangbin Liu (2):
bonding: access curr_active_slave with rtnl_dereference
bonding: do failover when high prio link up

Liang Li (1):
selftests: bonding: add bonding prio option test

 drivers/net/bonding/bond_main.c               |   6 +-
 .../selftests/drivers/net/bonding/Makefile    |   3 +-
 .../drivers/net/bonding/option_prio.sh        | 246 ++++++++++++++++++
 3 files changed, 252 insertions(+), 3 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/bonding/option_prio.sh
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/3 bonding: access curr_active_slave with rtnl_dereference

Looks commit 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave") missed rtnl_dereference for curr_active_slave in bond_miimon_commit().

Fixes 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave")
---
 drivers/net/bonding/bond_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_main.c +1 -1
index b9a882f182d2..2b6cc4dbb70e 100644
@@ -2689,7 +2689,7 @@ static void bond_miimon_commit(struct bonding *bond)
 
 			bond_miimon_link_change(bond, slave, BOND_LINK_UP);
 
-			if (!bond->curr_active_slave || slave == primary)
+			if (!rtnl_dereference(bond->curr_active_slave) || slave == primary)
 				goto do_failover;
 
 			continue;
Signature · 1 line
2.38.1
#7 lore raw

PATCH 2/3 bonding: do failover when high prio link up

In reply to Hangbin Liu

Currently, when a high prio link enslaved, or when current link down, the high prio port could be selected. But when high prio link up, the new active slave reselection is not triggered. Fix it by checking link's prio when getting up.

Fixes 0a2ff7cc8ad4 ("Bonding: add per-port priority for failover re-selection")
---
 drivers/net/bonding/bond_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +4 -2
index 2b6cc4dbb70e..dc6af790ff1e 100644
@@ -2689,7 +2689,8 @@ static void bond_miimon_commit(struct bonding *bond)
 
 			bond_miimon_link_change(bond, slave, BOND_LINK_UP);
 
-			if (!rtnl_dereference(bond->curr_active_slave) || slave == primary)
+			if (!rtnl_dereference(bond->curr_active_slave) || slave == primary ||
+			    slave->prio > rtnl_dereference(bond->curr_active_slave)->prio)
 				goto do_failover;
 
 			continue;
@@ -3550,7 +3551,8 @@ static void bond_ab_arp_commit(struct bonding *bond)
 				slave_info(bond->dev, slave->dev, "link status definitely up\n");
 
 				if (!rtnl_dereference(bond->curr_active_slave) ||
-				    slave == rtnl_dereference(bond->primary_slave))
+				    slave == rtnl_dereference(bond->primary_slave) ||
+				    slave->prio > rtnl_dereference(bond->curr_active_slave)->prio)
 					goto do_failover;
 
 			}
Signature · 1 line
2.38.1
#10 lore raw

PATCH 3/3 selftests: bonding: add bonding prio option test

In reply to Hangbin Liu

From: Liang Li <[email protected]>

Add a test for bonding prio option. Here is the test result:

]# ./option_prio.sh
TEST: prio_test (Test bonding option 'prio' with mode=1 monitor=arp_ip_target and primary_reselect=0) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=1 monitor=arp_ip_target and primary_reselect=1) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=1 monitor=arp_ip_target and primary_reselect=2) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=1 monitor=miimon and primary_reselect=0) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=1 monitor=miimon and primary_reselect=1) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=1 monitor=miimon and primary_reselect=2) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=5 monitor=miimon and primary_reselect=0) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=5 monitor=miimon and primary_reselect=1) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=5 monitor=miimon and primary_reselect=2) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=6 monitor=miimon and primary_reselect=0) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=6 monitor=miimon and primary_reselect=1) [ OK ]
TEST: prio_test (Test bonding option 'prio' with mode=6 monitor=miimon and primary_reselect=2) [ OK ]

---
 .../selftests/drivers/net/bonding/Makefile    |   3 +-
 .../drivers/net/bonding/option_prio.sh        | 246 ++++++++++++++++++
 2 files changed, 248 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/drivers/net/bonding/option_prio.sh
tools/testing/selftests/drivers/net/bonding/Makefile +2 -1
index 6b8d2e2f23c2..82250dd7a25d 100644
@@ -5,7 +5,8 @@ TEST_PROGS := \
 	bond-arp-interval-causes-panic.sh \
 	bond-break-lacpdu-tx.sh \
 	bond-lladdr-target.sh \
-	dev_addr_lists.sh
+	dev_addr_lists.sh \
+	option_prio.sh
 
 TEST_FILES := \
 	lag_lib.sh \
tools/testing/selftests/drivers/net/bonding/option_prio.sh new file +246 -0

246 lines not on this page · raw message

Signature · 1 line
2.38.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH net 1/3] bonding: access curr_active_slave with rtnl_dereference

In reply to Hangbin Liu
Quoted 6 lines · Hangbin Liu

Looks commit 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave") missed rtnl_dereference for curr_active_slave in bond_miimon_commit().

Fixes 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave")
#3 lore raw

Re: [PATCH net 1/3] bonding: access curr_active_slave with rtnl_dereference

In reply to Hangbin Liu
Quoted 18 lines · Hangbin Liu

Looks commit 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave") missed rtnl_dereference for curr_active_slave in bond_miimon_commit().

Fixes 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave")
---
 drivers/net/bonding/bond_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_main.c +0 -0
index b9a882f182d2..2b6cc4dbb70e 100644

drivers/net/bonding/bond_main.c static void bond_miimon_commit(struct bonding *bond) · line 2692

Quoted 5 lines
drivers/net/bonding/bond_main.c +1 -1
@@ -2689,7 +2689,7 @@ static void bond_miimon_commit(struct bonding *bond)
 
                        bond_miimon_link_change(bond, slave, BOND_LINK_UP);
 
-                       if (!bond->curr_active_slave || slave == primary)
+                       if (!rtnl_dereference(bond->curr_active_slave) || slave == primary)

We do not dereference the pointer here.

If this is fixing a sparse issue, then use the correct RCU helper for this.

( rcu_access_pointer())

Acked-by on the v1 series
#11 lore raw
In reply to Hangbin Liu
Quoted 10 lines · Hangbin Liu

When a high prio link up, if there has current link, it will not do failover as we missed the check in link up event. Fix it in this patchset and add a prio option test case.

Hangbin Liu (2):
bonding: access curr_active_slave with rtnl_dereference
bonding: do failover when high prio link up

Liang Li (1):
selftests: bonding: add bonding prio option test

For the series:

The only comment I have is that since prio is a signed value, it
would be nice if the selftest tested negative prio values.

	-J
Quoted 9 lines
drivers/net/bonding/bond_main.c               |   6 +-
.../selftests/drivers/net/bonding/Makefile    |   3 +-
.../drivers/net/bonding/option_prio.sh        | 246 ++++++++++++++++++
3 files changed, 252 insertions(+), 3 deletions(-)

create mode 100755 tools/testing/selftests/drivers/net/bonding/option_prio.sh

Signature · 1 line
2.38.1

---
-Jay Vosburgh, [email protected]

Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH net 2/3] bonding: do failover when high prio link up

In reply to Hangbin Liu
Quoted 17 lines · Hangbin Liu

Currently, when a high prio link enslaved, or when current link down, the high prio port could be selected. But when high prio link up, the new active slave reselection is not triggered. Fix it by checking link's prio when getting up.

Fixes 0a2ff7cc8ad4 ("Bonding: add per-port priority for failover re-selection")

---
drivers/net/bonding/bond_main.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +0 -0
index 2b6cc4dbb70e..dc6af790ff1e 100644

drivers/net/bonding/bond_main.c static void bond_miimon_commit(struct bonding *bond) · line 2694

Quoted 7 lines
drivers/net/bonding/bond_main.c +2 -1
@@ -2689,7 +2689,8 @@ static void bond_miimon_commit(struct bonding *bond)
 
 			bond_miimon_link_change(bond, slave, BOND_LINK_UP);
 
-			if (!rtnl_dereference(bond->curr_active_slave) || slave == primary)
+			if (!rtnl_dereference(bond->curr_active_slave) || slave == primary ||
+			    slave->prio > rtnl_dereference(bond->curr_active_slave)->prio)
 				goto do_failover;

I am not really familiar with this prio logic, seems to be new. Anyway, what if one of the next slaves has higher prio than this slave and the current active ? I see that the loop over all the slaves continues even after the failover,
but why would you do all these failovers until you settle on the highest
prio one ?

shouldn't you do something similar to bond_choose_primary_or_current() outside the loop, once you've updated all the slaves link states

Please let me know if I am wandering in the wrong directions Anyway, LGTM:

#9 lore raw

Re: [PATCH net 2/3] bonding: do failover when high prio link up

Quoted 21 lines · Saeed Mahameed
Quoted 20 lines · Hangbin Liu

Currently, when a high prio link enslaved, or when current link down, the high prio port could be selected. But when high prio link up, the new active slave reselection is not triggered. Fix it by checking link's prio when getting up.

Fixes 0a2ff7cc8ad4 ("Bonding: add per-port priority for failover re-selection")

---
drivers/net/bonding/bond_main.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +0 -0
index 2b6cc4dbb70e..dc6af790ff1e 100644
@@ -2689,7 +2689,8 @@ static void bond_miimon_commit(struct bonding *bond)
 
 			bond_miimon_link_change(bond, slave, BOND_LINK_UP);
 
Quoted 11 lines

drivers/net/bonding/bond_main.c static void bond_miimon_commit(struct bonding *bond) · line 2694

Quoted 4 lines
drivers/net/bonding/bond_main.c +2 -1
-			if (!rtnl_dereference(bond->curr_active_slave) || slave == primary)
+			if (!rtnl_dereference(bond->curr_active_slave) || slave == primary ||
+			    slave->prio > rtnl_dereference(bond->curr_active_slave)->prio)
 				goto do_failover;

I am not really familiar with this prio logic, seems to be new. Anyway, what if one of the next slaves has higher prio than this slave and the current active ? I see that the loop over all the slaves continues even after the failover,
but why would you do all these failovers until you settle on the highest prio one ?

Thanks, this makes sense to me. I will fix it.

Hangbin

Quoted 15 lines

shouldn't you do something similar to bond_choose_primary_or_current() outside the loop, once you've updated all the slaves link states

Please let me know if I am wandering in the wrong directions Anyway, LGTM:

#4 lore raw

Re: [PATCH net 1/3] bonding: access curr_active_slave with rtnl_dereference

In reply to Eric Dumazet
Quoted 22 lines · Eric Dumazet
Quoted 21 lines · Hangbin Liu

Looks commit 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave") missed rtnl_dereference for curr_active_slave in bond_miimon_commit().

Fixes 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave")
---
 drivers/net/bonding/bond_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_main.c +0 -0
index b9a882f182d2..2b6cc4dbb70e 100644
@@ -2689,7 +2689,7 @@ static void bond_miimon_commit(struct bonding *bond)
 
                        bond_miimon_link_change(bond, slave, BOND_LINK_UP);
 
Quoted 8 lines

drivers/net/bonding/bond_main.c static void bond_miimon_commit(struct bonding *bond) · line 2692

Quoted 2 lines
drivers/net/bonding/bond_main.c +1 -1
-                       if (!bond->curr_active_slave || slave == primary)
+                       if (!rtnl_dereference(bond->curr_active_slave) || slave == primary)

We do not dereference the pointer here.

If this is fixing a sparse issue, then use the correct RCU helper for this.

( rcu_access_pointer())

Hmm... I saw in 4740d6382790 ("bonding: add proper __rcu annotation for
curr_active_slave") there are also some dereference like that. Should I also
fix them at the same time? e.g.

@@ -2607,8 +2612,8 @@ static void bond_ab_arp_commit(struct bonding *bond)

                case BOND_LINK_UP:
                        trans_start = dev_trans_start(slave->dev);

- if (bond->curr_active_slave != slave ||
- (!bond->curr_active_slave &&
+ if (rtnl_dereference(bond->curr_active_slave) != slave ||
+ (!rtnl_dereference(bond->curr_active_slave) &&

Thanks
Hangbin

#5 lore raw

Re: [PATCH net 1/3] bonding: access curr_active_slave with rtnl_dereference

Quoted 29 lines · Hangbin Liu
Quoted 27 lines · Eric Dumazet
Quoted 18 lines · Hangbin Liu

Looks commit 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave") missed rtnl_dereference for curr_active_slave in bond_miimon_commit().

Fixes 4740d6382790 ("bonding: add proper __rcu annotation for curr_active_slave")
---
 drivers/net/bonding/bond_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_main.c +0 -0
index b9a882f182d2..2b6cc4dbb70e 100644

drivers/net/bonding/bond_main.c static void bond_miimon_commit(struct bonding *bond) · line 2692

Quoted 5 lines
drivers/net/bonding/bond_main.c +1 -1
@@ -2689,7 +2689,7 @@ static void bond_miimon_commit(struct bonding *bond)
 
                        bond_miimon_link_change(bond, slave, BOND_LINK_UP);
 
-                       if (!bond->curr_active_slave || slave == primary)
+                       if (!rtnl_dereference(bond->curr_active_slave) || slave == primary)

We do not dereference the pointer here.

Quoted 7 lines
Quoted 3 lines

If this is fixing a sparse issue, then use the correct RCU helper for this.

( rcu_access_pointer())

Hmm... I saw in 4740d6382790 ("bonding: add proper __rcu annotation for
curr_active_slave") there are also some dereference like that. Should I also
fix them at the same time? e.g.

There is no 'fix' really. I do not see any reason to change this part.

It is merely a matter of repeating or not the fact that RTNL (or another lock) is held.

Review static void bond_ab_arp_commit(struct bonding *bond) · line 2617

Quoted 10 lines
(quoted diff) +2 -2
@@ -2607,8 +2612,8 @@ static void bond_ab_arp_commit(struct bonding *bond)
 
                case BOND_LINK_UP:
                        trans_start = dev_trans_start(slave->dev);
-                       if (bond->curr_active_slave != slave ||
-                           (!bond->curr_active_slave &&
+                       if (rtnl_dereference(bond->curr_active_slave) != slave ||
+                           (!rtnl_dereference(bond->curr_active_slave) &&
 

At the time of commit 4740d6382790 we wanted to make sure the bond->curr_slave_lock
was taken, because it was the assertion at that time.

Then later, bond_deref_active_protected() has been removed, because curr_slave_lock has been removed.

$ git log --oneline --reverse
b25bd2515ea32cf5ddd5fd5a2a93b8c9dd875e4f..8c0bc550288d81e9ad8a2ed9136a72140b9ef507
86e749866d7c6b0ee1f9377cf7142f2690596a05 bonding: 3ad: clean up
curr_slave_lock usage
62c5f5185397f4bd8e5defe6fcb86420deeb2b38 bonding: alb: remove curr_slave_lock
1c72cfdc96e63bf975cab514c4ca4d8a661ba0e6 bonding: clean curr_slave_lock use
b743562819bd97cc7c282e870896bae8016b64b5 bonding: convert
curr_slave_lock to a spinlock and rename it
4bab16d7c97498e91564231b922d49f52efaf7d4 bonding: alb: convert to
bond->mode_lock
e470259fa1bd7ce5a375b16c5ec97cc0e83b058d bonding: 3ad: convert to
bond->mode_lock
8c0bc550288d81e9ad8a2ed9136a72140b9ef507 bonding: adjust locking comments

Now, you post a patch for bond_miimon_commit() which already has :

if (slave == rcu_access_pointer(bond->curr_active_slave))

      goto do_failover;

So really it is a matter of consistency in _this_ function, which is run under RTNL for sure.

It is also a patch for net-next tree, because it fixes no bug.

I would not add a Fixes: tag to avoid dealing with useless backports.

#6 lore raw

Re: [PATCH net 1/3] bonding: access curr_active_slave with rtnl_dereference

Quoted 7 lines · Eric Dumazet

Now, you post a patch for bond_miimon_commit() which already has :

if (slave == rcu_access_pointer(bond->curr_active_slave))

      goto do_failover;

So really it is a matter of consistency in _this_ function, which is run under RTNL for sure.

Ah, thanks for the explanation.

Quoted 3 lines

It is also a patch for net-next tree, because it fixes no bug.

I would not add a Fixes: tag to avoid dealing with useless backports.

OK, I will do as your suggest.

Cheers
Hangbin