Jiri Slaby b11903
From: Jay Vosburgh <jay.vosburgh@canonical.com>
Jiri Slaby b11903
Date: Tue, 7 Nov 2017 19:50:07 +0900
Jiri Slaby b11903
Subject: bonding: fix slave stuck in BOND_LINK_FAIL state
Jiri Slaby b11903
Git-commit: 055db6957e4735b16cd2fa94a5bbfb754c9b8023
Jiri Slaby b11903
Patch-mainline: 4.14
Jiri Slaby b11903
References: networking-stable-19_11_10
Jiri Slaby b11903
Jiri Slaby b11903
The bonding miimon logic has a flaw, in that a failure of the
Jiri Slaby b11903
rtnl_trylock can cause a slave to become permanently stuck in
Jiri Slaby b11903
BOND_LINK_FAIL state.
Jiri Slaby b11903
Jiri Slaby b11903
	The sequence of events to cause this is as follows:
Jiri Slaby b11903
Jiri Slaby b11903
	1) bond_miimon_inspect finds that a slave's link is down, and so
Jiri Slaby b11903
calls bond_propose_link_state, setting slave->new_link_state to
Jiri Slaby b11903
BOND_LINK_FAIL, then sets slave->new_link to BOND_LINK_DOWN and returns
Jiri Slaby b11903
non-zero.
Jiri Slaby b11903
Jiri Slaby b11903
	2) In bond_mii_monitor, the rtnl_trylock fails, and the timer is
Jiri Slaby b11903
rescheduled.  No change is committed.
Jiri Slaby b11903
Jiri Slaby b11903
	3) bond_miimon_inspect is called again, but this time the slave
Jiri Slaby b11903
from step 1 has recovered.  slave->new_link is reset to NOCHANGE, and, as
Jiri Slaby b11903
slave->link was never changed, the switch enters the BOND_LINK_UP case,
Jiri Slaby b11903
and does nothing.  The pending BOND_LINK_FAIL state from step 1 remains
Jiri Slaby b11903
pending, as new_link_state is not reset.
Jiri Slaby b11903
Jiri Slaby b11903
	4) The state from step 3 persists until another slave changes link
Jiri Slaby b11903
state and causes bond_miimon_inspect to return non-zero.  At this point,
Jiri Slaby b11903
the BOND_LINK_FAIL state change on the slave from steps 1-3 is committed,
Jiri Slaby b11903
and the slave will remain stuck in BOND_LINK_FAIL state even though it
Jiri Slaby b11903
is actually link up.
Jiri Slaby b11903
Jiri Slaby b11903
	The remedy for this is to initialize new_link_state on each entry
Jiri Slaby b11903
to bond_miimon_inspect, as is already done with new_link.
Jiri Slaby b11903
Jiri Slaby b11903
Fixes: fb9eb899a6dc ("bonding: handle link transition from FAIL to UP correctly")
Jiri Slaby b11903
Reported-by: Alex Sidorenko <alexandre.sidorenko@hpe.com>
Jiri Slaby b11903
Reviewed-by: Jarod Wilson <jarod@redhat.com>
Jiri Slaby b11903
Signed-off-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Jiri Slaby b11903
Acked-by: Mahesh Bandewar <maheshb@google.com>
Jiri Slaby b11903
Signed-off-by: David S. Miller <davem@davemloft.net>
Jiri Slaby b11903
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Jiri Slaby b11903
---
Jiri Slaby b11903
 drivers/net/bonding/bond_main.c |    1 +
Jiri Slaby b11903
 1 file changed, 1 insertion(+)
Jiri Slaby b11903
Jiri Slaby b11903
--- a/drivers/net/bonding/bond_main.c
Jiri Slaby b11903
+++ b/drivers/net/bonding/bond_main.c
Jiri Slaby b11903
@@ -2039,6 +2039,7 @@ static int bond_miimon_inspect(struct bo
Jiri Slaby b11903
 
Jiri Slaby b11903
 	bond_for_each_slave_rcu(bond, slave, iter) {
Jiri Slaby b11903
 		slave->new_link = BOND_LINK_NOCHANGE;
Jiri Slaby b11903
+		slave->link_new_state = slave->link;
Jiri Slaby b11903
 
Jiri Slaby b11903
 		link_state = bond_check_dev_link(bond, slave->dev, 0);
Jiri Slaby b11903