Skip to contentSkip to conversation

bonding: fix 802.3ad churn machine and port state issues

PATCH Superseded Hangbin Liu 3 participants 15 messages Jan 14 – Feb 26

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover bonding: fix 802.3ad churn machine and port state issues

This series fixes two issues in the bonding 802.3ad implementation related to port state management and churn detection:

1. When disabling a port, we need to set AD_RX_PORT_DISABLED to ensure proper state machine transitions, preventing ports from getting stuck in AD_RX_CURRENT state.

2. The ad_churn_machine implementation is restructured to follow IEEE 802.1AX-2014 specifications correctly. The current implementation has several issues: it doesn't transition to "none" state immediately when synchronization is achieved, and can get stuck in churned state in multi-aggregator scenarios.

3. Selftests are enhanced to validate both mux state machine and churn state logic under aggregator selection and failover scenarios.

These changes ensure proper LACP state machine behavior and fix issues where ports could remain in incorrect states during aggregator failover.

v2:
* The changes are large and not urgent. Post to net-next as Paolo suggested
* set AD_RX_PORT_DISABLED only in ad_agg_selection_logic to avoid side effect. (Paolo Abeni)
* remove actor_churn as it can only be true when the state is ACTOR_CHURN (Paolo Abeni)
* remove AD_PORT_CHURNED since we don't need it anywhere (Paolo Abeni)
* I didn't add new helper for ad_churn_machine() as it looks not help much.

v1: https://lore.kernel.org/netdev/[email protected]

Hangbin Liu (3):
bonding: set AD_RX_PORT_DISABLED when disabling a port
bonding: restructure ad_churn_machine
selftests: bonding: add mux and churn state testing

 drivers/net/bonding/bond_3ad.c                | 97 ++++++++++++++-----
 .../selftests/drivers/net/bonding/Makefile    |  2 +-
 ...nd_lacp_prio.sh => bond_lacp_ad_select.sh} | 73 ++++++++++++++
 3 files changed, 146 insertions(+), 26 deletions(-)
 rename tools/testing/selftests/drivers/net/bonding/{bond_lacp_prio.sh => bond_lacp_ad_select.sh} (64%)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/3 bonding: set AD_RX_PORT_DISABLED when disabling a port

When disabling a port’s collecting and distributing states, updating only rx_disabled is not sufficient. We also need to set AD_RX_PORT_DISABLED so that the rx_machine transitions into the AD_RX_EXPIRED state.

One example is in ad_agg_selection_logic(): when a new aggregator is selected and old active aggregator is disabled, if AD_RX_PORT_DISABLED is not set, the disabled port may remain stuck in AD_RX_CURRENT due to continuing to receive partner LACP messages.

The __disable_port() called by ad_disable_collecting_distributing() does not have this issue, since its caller also clears the collecting/distributing bits.

The __disable_port() called by bond_3ad_bind_slave() should also be fine, as the RX state machine is re-initialized to AD_RX_INITIALIZE.

Let's fix this only in ad_agg_selection_logic() to reduce the chances of unintended side effects.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/net/bonding/bond_3ad.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/bonding/bond_3ad.c +1 -0
index 1a8de2bf8655..bcf9833e5436 100644
@@ -1926,6 +1926,7 @@ static void ad_agg_selection_logic(struct aggregator *agg,
 		if (active) {
 			for (port = active->lag_ports; port;
 			     port = port->next_port_in_aggregator) {
+				port->sm_rx_state = AD_RX_PORT_DISABLED;
 				__disable_port(port);
 			}
 		}
Signature · 1 line
2.50.1
#2 lore raw

PATCH v2 2/3 bonding: restructure ad_churn_machine

In reply to Hangbin Liu

The current ad_churn_machine implementation only transitions the actor/partner churn state to churned or none after the churn timer expires. However, IEEE 802.1AX-2014 specifies that a port should enter the none state immediately once the actor’s port state enters synchronization.

Another issue is that if the churn timer expires while the churn machine is not in the monitor state (e.g. already in churn), the state may remain stuck indefinitely with no further transitions. This becomes visible in multi-aggregator scenarios. For example:

Ports 1 and 2 are in aggregator 1 (active)
Ports 3 and 4 are in aggregator 2 (backup)

Ports 1 and 2 should be in none
Ports 3 and 4 should be in churned

If a failover occurs due to port 2 link down/up, aggregator 2 becomes active. Under the current implementation, the resulting states may look like:

agg 1 (backup): port 1 -> none, port 2 -> churned
agg 2 (active): ports 3,4 keep in churned.

The root cause is that ad_churn_machine() only clears the AD_PORT_CHURNED flag and starts a timer. When a churned port becomes active, its RX state becomes AD_RX_CURRENT, preventing the churn flag from being set again, leaving no way to retrigger the timer. Fixing this solely in ad_rx_machine() is insufficient.

This patch rewrites ad_churn_machine according to IEEE 802.1AX-2014 (Figures 6-23 and 6-24), ensuring correct churn detection, state transitions, and timer behavior. With new implementation, there is no need to set AD_PORT_CHURNED in ad_rx_machine().

Fixes 14c9551a32eb ("bonding: Implement port churn-machine (AD standard 43.4.17).")
---
 drivers/net/bonding/bond_3ad.c | 96 +++++++++++++++++++++++++---------
 1 file changed, 71 insertions(+), 25 deletions(-)
drivers/net/bonding/bond_3ad.c +71 -25
index bcf9833e5436..154e06e345ad 100644
@@ -44,7 +44,6 @@
 #define AD_PORT_STANDBY         0x80
 #define AD_PORT_SELECTED        0x100
 #define AD_PORT_MOVED           0x200
-#define AD_PORT_CHURNED         (AD_PORT_ACTOR_CHURN | AD_PORT_PARTNER_CHURN)
 
 /* Port Key definitions
  * key is determined according to the link speed, duplex and
@@ -1248,7 +1247,6 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
 	/* first, check if port was reinitialized */
 	if (port->sm_vars & AD_PORT_BEGIN) {
 		port->sm_rx_state = AD_RX_INITIALIZE;
-		port->sm_vars |= AD_PORT_CHURNED;
 	/* check if port is not enabled */
 	} else if (!(port->sm_vars & AD_PORT_BEGIN) && !port->is_enabled)
 		port->sm_rx_state = AD_RX_PORT_DISABLED;
@@ -1256,8 +1254,6 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
 	else if (lacpdu && ((port->sm_rx_state == AD_RX_EXPIRED) ||
 		 (port->sm_rx_state == AD_RX_DEFAULTED) ||
 		 (port->sm_rx_state == AD_RX_CURRENT))) {
-		if (port->sm_rx_state != AD_RX_CURRENT)
-			port->sm_vars |= AD_PORT_CHURNED;
 		port->sm_rx_timer_counter = 0;
 		port->sm_rx_state = AD_RX_CURRENT;
 	} else {
@@ -1341,7 +1337,6 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
 			port->partner_oper.port_state |= LACP_STATE_LACP_TIMEOUT;
 			port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(AD_SHORT_TIMEOUT));
 			port->actor_oper_port_state |= LACP_STATE_EXPIRED;
-			port->sm_vars |= AD_PORT_CHURNED;
 			break;
 		case AD_RX_DEFAULTED:
 			__update_default_selected(port);
@@ -1373,11 +1368,41 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
  * ad_churn_machine - handle port churn's state machine
  * @port: the port we're looking at
  *
+ * IEEE 802.1AX-2014 Figure 6-23 - Actor Churn Detection machine state diagram
+ *
+ *                                                     BEGIN || (! port_enabled)
+ *                                                               |
+ *                                      (3)                (1)   v
+ *   +----------------------+     ActorPort.Sync     +-------------------------+
+ *   |    NO_ACTOR_CHURN    | <--------------------- |   ACTOR_CHURN_MONITOR   |
+ *   |======================|                        |=========================|
+ *   | actor_churn = FALSE; |    ! ActorPort.Sync    | actor_churn = FALSE;    |
+ *   |                      | ---------------------> | Start actor_churn_timer |
+ *   +----------------------+           (4)          +-------------------------+
+ *             ^                                                 |
+ *             |                                                 |
+ *             |                                      actor_churn_timer expired
+ *             |                                                 |
+ *       ActorPort.Sync                                          |  (2)
+ *             |              +--------------------+             |
+ *        (3)  |              |   ACTOR_CHURN      |             |
+ *             |              |====================|             |
+ *             +------------- | actor_churn = True | <-----------+
+ *                            |                    |
+ *                            +--------------------+
+ *
+ * Similar for the Figure 6-24 - Partner Churn Detection machine state diagram
+ *
+ * We don’t need to check actor_churn, because it can only be true when the
+ * state is ACTOR_CHURN.
  */
 static void ad_churn_machine(struct port *port)
 {
-	if (port->sm_vars & AD_PORT_CHURNED) {
-		port->sm_vars &= ~AD_PORT_CHURNED;
+	bool partner_synced = port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION;
+	bool actor_synced = port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION;
+
+	/* ---- 1. begin or port not enabled ---- */
+	if ((port->sm_vars & AD_PORT_BEGIN) || !port->is_enabled) {
 		port->sm_churn_actor_state = AD_CHURN_MONITOR;
 		port->sm_churn_partner_state = AD_CHURN_MONITOR;
 		port->sm_churn_actor_timer_counter =
@@ -1386,25 +1411,46 @@ static void ad_churn_machine(struct port *port)
 			 __ad_timer_to_ticks(AD_PARTNER_CHURN_TIMER, 0);
 		return;
 	}
-	if (port->sm_churn_actor_timer_counter &&
-	    !(--port->sm_churn_actor_timer_counter) &&
-	    port->sm_churn_actor_state == AD_CHURN_MONITOR) {
-		if (port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION) {
-			port->sm_churn_actor_state = AD_NO_CHURN;
-		} else {
-			port->churn_actor_count++;
-			port->sm_churn_actor_state = AD_CHURN;
-		}
+
+	if (port->sm_churn_actor_timer_counter)
+		port->sm_churn_actor_timer_counter--;
+
+	if (port->sm_churn_partner_timer_counter)
+		port->sm_churn_partner_timer_counter--;
+
+	/* ---- 2. timer expired, enter CHURN ---- */
+	if (port->sm_churn_actor_state == AD_CHURN_MONITOR &&
+	    !port->sm_churn_actor_timer_counter) {
+		port->sm_churn_actor_state = AD_CHURN;
+		port->churn_actor_count++;
 	}
-	if (port->sm_churn_partner_timer_counter &&
-	    !(--port->sm_churn_partner_timer_counter) &&
-	    port->sm_churn_partner_state == AD_CHURN_MONITOR) {
-		if (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) {
-			port->sm_churn_partner_state = AD_NO_CHURN;
-		} else {
-			port->churn_partner_count++;
-			port->sm_churn_partner_state = AD_CHURN;
-		}
+
+	if (port->sm_churn_partner_state == AD_CHURN_MONITOR &&
+	    !port->sm_churn_partner_timer_counter) {
+		port->sm_churn_partner_state = AD_CHURN;
+		port->churn_partner_count++;
+	}
+
+	/* ---- 3. CHURN_MONITOR/CHURN + sync -> NO_CHURN ---- */
+	if ((port->sm_churn_actor_state == AD_CHURN_MONITOR ||
+	     port->sm_churn_actor_state == AD_CHURN) && actor_synced)
+		port->sm_churn_actor_state = AD_NO_CHURN;
+
+	if ((port->sm_churn_partner_state == AD_CHURN_MONITOR ||
+	     port->sm_churn_partner_state == AD_CHURN) && partner_synced)
+		port->sm_churn_partner_state = AD_NO_CHURN;
+
+	/* ---- 4. NO_CHURN + !sync -> MONITOR ---- */
+	if (port->sm_churn_actor_state == AD_NO_CHURN && !actor_synced) {
+		port->sm_churn_actor_state = AD_CHURN_MONITOR;
+		port->sm_churn_actor_timer_counter =
+			__ad_timer_to_ticks(AD_ACTOR_CHURN_TIMER, 0);
+	}
+
+	if (port->sm_churn_partner_state == AD_NO_CHURN && !partner_synced) {
+		port->sm_churn_partner_state = AD_CHURN_MONITOR;
+		port->sm_churn_partner_timer_counter =
+			__ad_timer_to_ticks(AD_PARTNER_CHURN_TIMER, 0);
 	}
 }
 
Signature · 1 line
2.50.1
maintainer
#3 lore raw

Re: [PATCHv2 net-next 2/3] bonding: restructure ad_churn_machine

Quoted 4 lines · On Wed, 14 Jan 2026 06:49:20 +0000 Hangbin Liu wrote:

The current ad_churn_machine implementation only transitions the actor/partner churn state to churned or none after the churn timer expires. However, IEEE 802.1AX-2014 specifies that a port should enter the none state immediately once the actor’s port state enters synchronization.

Paolo, how do you feel about his patch with 2+ weeks until final? The first patch is definitely suitable for net. If this one is not it should not have a Fixes tag. I'd lean towards getting them all into -rc7 if we can.

BTW please make sure to CC Nik (based on the Fixes tag I think). Always run get_maintainers on the patches.

Signature · 1 line
pw-bot: cr
#4 lore raw

Re: [PATCHv2 net-next 2/3] bonding: restructure ad_churn_machine

Quoted 2 lines · Jakub Kicinski

BTW please make sure to CC Nik (based on the Fixes tag I think). Always run get_maintainers on the patches.

Thanks, I will keep this in mind.

Hangbin

maintainer
#5 lore raw

Re: [PATCHv2 net-next 2/3] bonding: restructure ad_churn_machine

In reply to Jakub Kicinski
Quoted 10 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 14 Jan 2026 06:49:20 +0000 Hangbin Liu wrote:

The current ad_churn_machine implementation only transitions the actor/partner churn state to churned or none after the churn timer expires. However, IEEE 802.1AX-2014 specifies that a port should enter the none state immediately once the actor’s port state enters synchronization.

Paolo, how do you feel about his patch with 2+ weeks until final? The first patch is definitely suitable for net. If this one is not it should not have a Fixes tag. I'd lean towards getting them all into -rc7 if we can.

My personal preference would be for 2/3 landing into net-next: the code looks correct to me, but refactor has IMHO still to much potential for regressions do land directly into net and the blamed commit is quite old.

I suggested targeting net-next while retaining the Fixes tag as we already had complex fixes landing into net-next in the past.

/P

maintainer
#6 lore raw

Re: [PATCHv2 net-next 2/3] bonding: restructure ad_churn_machine

Quoted 12 lines · On Tue, 20 Jan 2026 09:29:14 +0100 Paolo Abeni wrote:
Quoted 10 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 14 Jan 2026 06:49:20 +0000 Hangbin Liu wrote:

The current ad_churn_machine implementation only transitions the actor/partner churn state to churned or none after the churn timer expires. However, IEEE 802.1AX-2014 specifies that a port should enter the none state immediately once the actor’s port state enters synchronization.

Paolo, how do you feel about his patch with 2+ weeks until final? The first patch is definitely suitable for net. If this one is not it should not have a Fixes tag. I'd lean towards getting them all into -rc7 if we can.

Quoted 6 lines

My personal preference would be for 2/3 landing into net-next: the code looks correct to me, but refactor has IMHO still to much potential for regressions do land directly into net and the blamed commit is quite old.

I suggested targeting net-next while retaining the Fixes tag as we already had complex fixes landing into net-next in the past.

The appropriate way to delay propagation of the fix to add:

Cc <[email protected]> # after 4 weeks

not to merge things into -next.

maintainer
#7 lore raw

Re: [PATCHv2 net-next 2/3] bonding: restructure ad_churn_machine

Quoted 17 lines · Jakub Kicinski
Quoted 16 lines · On Tue, 20 Jan 2026 09:29:14 +0100 Paolo Abeni wrote:
Quoted 10 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 14 Jan 2026 06:49:20 +0000 Hangbin Liu wrote:

The current ad_churn_machine implementation only transitions the actor/partner churn state to churned or none after the churn timer expires. However, IEEE 802.1AX-2014 specifies that a port should enter the none state immediately once the actor’s port state enters synchronization.

Paolo, how do you feel about his patch with 2+ weeks until final? The first patch is definitely suitable for net. If this one is not it should not have a Fixes tag. I'd lean towards getting them all into -rc7 if we can.

My personal preference would be for 2/3 landing into net-next: the code looks correct to me, but refactor has IMHO still to much potential for regressions do land directly into net and the blamed commit is quite old.

Quoted 8 lines
Quoted 2 lines

I suggested targeting net-next while retaining the Fixes tag as we already had complex fixes landing into net-next in the past.

The appropriate way to delay propagation of the fix to add:

Cc <[email protected]> # after 4 weeks

not to merge things into -next.

I went over the code as carefully as I could and I don't see any obvious problem, so I don't have a so strong opinion vs net, but to hopefully
clarify: my thinking is that this is net-next material because it's an invasive refactor with behavior change. My preference would be let the code be tested in next/net-next for a while before landing into mainline.

/P

maintainer
#8 lore raw

Re: [PATCHv2 net-next 2/3] bonding: restructure ad_churn_machine

Quoted 11 lines · On Wed, 21 Jan 2026 08:58:13 +0100 Paolo Abeni wrote:
Quoted 11 lines
Quoted 6 lines

My personal preference would be for 2/3 landing into net-next: the code looks correct to me, but refactor has IMHO still to much potential for regressions do land directly into net and the blamed commit is quite old.

I suggested targeting net-next while retaining the Fixes tag as we already had complex fixes landing into net-next in the past.

The appropriate way to delay propagation of the fix to add:

Cc <[email protected]> # after 4 weeks
Quoted 7 lines
Quoted 1 line

not to merge things into -next.

I went over the code as carefully as I could and I don't see any obvious problem, so I don't have a so strong opinion vs net, but to hopefully
clarify: my thinking is that this is net-next material because it's an invasive refactor with behavior change. My preference would be let the code be tested in next/net-next for a while before landing into mainline.

From the patch description it look like user-trigger-able hang of the FSM. But if this is more of a resiliency improvement than a fix then I'm perfectly fine with net-next. But then no Fixes tag and no stable at all, please.

#9 lore raw

PATCH v2 3/3 selftests: bonding: add mux and churn state testing

In reply to Hangbin Liu

Rename the current LACP priority test to LACP ad_select testing, and extend it to include validation of the actor state machine and churn state logic. The updated tests verify that both the mux state machine and the churn state machine behave correctly under aggregator selection and failover scenarios.

---
 .../selftests/drivers/net/bonding/Makefile    |  2 +-
 ...nd_lacp_prio.sh => bond_lacp_ad_select.sh} | 73 +++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)
 rename tools/testing/selftests/drivers/net/bonding/{bond_lacp_prio.sh => bond_lacp_ad_select.sh} (64%)
tools/testing/selftests/drivers/net/bonding/Makefile +1 -1
index 6c5c60adb5e8..e7bddfbf0f7a 100644
@@ -7,7 +7,7 @@ TEST_PROGS := \
 	bond-eth-type-change.sh \
 	bond-lladdr-target.sh \
 	bond_ipsec_offload.sh \
-	bond_lacp_prio.sh \
+	bond_lacp_ad_select.sh \
 	bond_macvlan_ipvlan.sh \
 	bond_options.sh \
 	bond_passive_lacp.sh \
tools/testing/selftests/drivers/net/bonding/bond_lacp_ad_select.sh renamed from tools/testing/selftests/drivers/net/bonding/bond_lacp_prio.sh +73 -0

90 lines not on this page · raw message

Signature · 1 line
2.50.1
#10 lore raw
In reply to Hangbin Liu

Hi Jakub, Paolo,

Is there anything I should do for this patchset ?

Thanks
Hangbin

Quoted 43 lines · Hangbin Liu

This series fixes two issues in the bonding 802.3ad implementation related to port state management and churn detection:

1. When disabling a port, we need to set AD_RX_PORT_DISABLED to ensure proper state machine transitions, preventing ports from getting stuck in AD_RX_CURRENT state.

2. The ad_churn_machine implementation is restructured to follow IEEE 802.1AX-2014 specifications correctly. The current implementation has several issues: it doesn't transition to "none" state immediately when synchronization is achieved, and can get stuck in churned state in multi-aggregator scenarios.

3. Selftests are enhanced to validate both mux state machine and churn state logic under aggregator selection and failover scenarios.

These changes ensure proper LACP state machine behavior and fix issues where ports could remain in incorrect states during aggregator failover.

v2:
* The changes are large and not urgent. Post to net-next as Paolo suggested
* set AD_RX_PORT_DISABLED only in ad_agg_selection_logic to avoid side effect. (Paolo Abeni)
* remove actor_churn as it can only be true when the state is ACTOR_CHURN (Paolo Abeni)
* remove AD_PORT_CHURNED since we don't need it anywhere (Paolo Abeni)
* I didn't add new helper for ad_churn_machine() as it looks not help much.

v1: https://lore.kernel.org/netdev/[email protected]

Hangbin Liu (3):
bonding: set AD_RX_PORT_DISABLED when disabling a port
bonding: restructure ad_churn_machine
selftests: bonding: add mux and churn state testing

 drivers/net/bonding/bond_3ad.c                | 97 ++++++++++++++-----
 .../selftests/drivers/net/bonding/Makefile    |  2 +-
 ...nd_lacp_prio.sh => bond_lacp_ad_select.sh} | 73 ++++++++++++++
 3 files changed, 146 insertions(+), 26 deletions(-)
 rename tools/testing/selftests/drivers/net/bonding/{bond_lacp_prio.sh => bond_lacp_ad_select.sh} (64%)
Signature · 1 line
2.50.1
maintainer
#11 lore raw
Quoted 3 lines · Hangbin Liu

Hi Jakub, Paolo,

Is there anything I should do for this patchset ?

My take is that given we are now much more near to 6.19 final, this should go via net-next.

Beware: it looks like Jakub and me are not 110% aligned on this topic, so please wait a bit more for his feedback, thanks.

Paolo

#12 lore raw

Hi Paolo, Jakub,

I'm not sure what I should do for this patch set. Should I re-post to net-next or net?

Thanks
Hangbin

Quoted 13 lines · Paolo Abeni
Quoted 3 lines · Hangbin Liu

Hi Jakub, Paolo,

Is there anything I should do for this patchset ?

My take is that given we are now much more near to 6.19 final, this should go via net-next.

Beware: it looks like Jakub and me are not 110% aligned on this topic, so please wait a bit more for his feedback, thanks.

Paolo

maintainer
#13 lore raw
Quoted 1 line · Hangbin Liu

I'm not sure what I should do for this patch set. Should I re-post to net-next or net?

Jakub and me discussed the topic off-list and the current agreement is repost for 'net', with fixes tag.

Thanks for your patience.

/P

#14 lore raw
Quoted 5 lines · Paolo Abeni
Quoted 1 line · Hangbin Liu

I'm not sure what I should do for this patch set. Should I re-post to net-next or net?

Jakub and me discussed the topic off-list and the current agreement is repost for 'net', with fixes tag.

Thanks, I will repost to net.

Regards
Hangbin