Article View: linux.kernel.netdev
Article #26162[PATCH net-next v2] bonding: roll back fail_over_mac if enslave fails
From: Hangbin Liu
Date: Thu, 03 Dec 2026 06:04
Date: Thu, 03 Dec 2026 06:04
82 lines
11952 bytes
11952 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>
bond_enslave() can change bond->params.fail_over_mac as a side
effect: when the first slave cannot set its own MAC address and the
bond is in active-backup mode, fail_over_mac is forced to "active" so
bonding never writes the slave MAC. If enslave fails later, the
forced value stays behind, silently changing a user-configured
option after a failed operation and affecting subsequent failover
behaviour.
Snapshot fail_over_mac on entry and restore it on the error path.
Annotate the stores with WRITE_ONCE() for lockless readers.
Also add the missing WRITE_ONCE() for the existing fail_over_mac
assignment in bond_enslave.
Fixes: 3915c1e8634a ("bonding: Add "follow" option to fail_over_mac")
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
The issue is discovered when I tried to restruct bond_enslave().
It could be reproduced via
bash-5.3# ip link add wg0 type wireguard
bash-5.3# ip link add bond0 type bond mode active-backup
bash-5.3# ip link set bond0 xdpdrv obj xdp_dummy.bpf.o sec xdp
bash-5.3# ip -d -j -p link show bond0 | grep fail_over_mac
"fail_over_mac": "none",
bash-5.3# ip link set wg0 master bond0
Error: Slave does not support XDP.
bash-5.3# ip -d -j -p link show bond0 | grep fail_over_mac
"fail_over_mac": "active",
After the patch, the fail_over_mac will not be changed by a failed enslave.
bash-5.3# ip -d -j -p link show bond0 | grep fail_over_mac
"fail_over_mac": "none",
---
Changes in v2:
- Annotate the stores with WRITE_ONCE() for lockless readers. (Willem de Bruijn)
- Link to v1: https://patch.msgid.link/20261124-bond_fail_over_mac-v1-1-9caee319331f@kylinos.cn
---
drivers/net/bonding/bond_main.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 754048ef4835..a1ee406a7d46 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1894,6 +1894,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
{
struct bonding *bond = netdev_priv(bond_dev);
const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
+ int orig_fail_over_mac = bond->params.fail_over_mac;
struct slave *new_slave = NULL, *prev_slave;
struct sockaddr_storage ss;
int res = 0, i;
@@ -2014,7 +2015,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
if (!bond_has_slaves(bond)) {
- bond->params.fail_over_mac = BOND_FOM_ACTIVE;
+ WRITE_ONCE(bond->params.fail_over_mac, BOND_FOM_ACTIVE);
slave_warn(bond_dev, slave_dev, "Setting fail_over_mac to active for active-backup mode\n");
} else {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
@@ -2420,6 +2421,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
kobject_put(&new_slave->kobj);
err_undo_flags:
+ if (bond->params.fail_over_mac != orig_fail_over_mac)
+ WRITE_ONCE(bond->params.fail_over_mac, orig_fail_over_mac);
/* Enslave of first slave has failed and we need to fix master's mac */
if (!bond_has_slaves(bond)) {
if (ether_addr_equal_64bits(bond_dev->dev_addr,
---
base-commit: c63b67b946fcd4efb24439f70ee081dfa485dc40
change-id: 20261124-bond_fail_over_mac-e7952797e80b
Best regards,
--
Hangbin Liu <liuhangbin@kylinos.cn>
Technical Details
Message-ID:
<20261203-bond_fail_over_mac-v2-1-6d6c32ca65e6@kylinos.cn>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376311-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376311-linux-kernel-netdev=dewy.ru From: hangbin.liu@linux.dev (Hangbin Liu) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v2] bonding: roll back fail_over_mac if enslave fails Date: Thu, 03 Dec 2026 14:04:04 +0800 Organization: Usenet Network Message-ID: <20261203-bond_fail_over_mac-v2-1-6d6c32ca65e6@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2176287"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:uwskC3J3YNWbYl/ddCJdE9LjrUU= sha256:xJzXJYEqB3LMI3VzXfrIbVyOoZMU6kL7oxRpsbvagMY= sha1:sROanImxjmuv0yAGmmmJdl9TW5E= sha256:FPXMRnwxqPWGZqrwpE5V9yvfPbRXUbceE4USwTJC6cI= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id D63F311782A; Thu, 3 Dec 2026 09:04:33 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fm-sNjW37t8u; Thu, 3 Dec 2026 09:04:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-376311-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 6784F117801; Thu, 3 Dec 2026 09:04:20 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id C282624080; Thu, 3 Dec 2026 06:04:17 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796277857; b=dQ9t4Y2YoxiV3PspppMqnJp+1zRU+G4SvYBRXWktmkNRLxrK3d+5kX4zFwo9EpeEhGmU 5KgjDDkrZylTGH/I49cb6KSfCAPU53MjEi6afTDMBRk6dT1n4TJfiuRZRjF4q1uLP0/hX VMldQ3StfdXURDDxk8nOpP5EhUg5rP4rgs4LBvJCeXYWUJc7JPG0bj5aateDbmw1bIsr7 yQAL+mOZSsREGW89KXNbZB6nRPw0Rc9lo/5L5CUjcUEpIGkcvdBU7sfj4xaHQJfTKf177 wkDMfKI4HoHrmFaUjQ0ZzeZ8R/vJksldMrN60oYpRqnxGFvGiWEX8cnbWl9SWgoBlkQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796277857; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc: X-Mailer; bh=wmqcCvLE0ImozxsR5FibttYYj/J62I/57LJsVq2W1kw=; b=0VqFSzNyPTVL3sYfOyWYvPZSckVgZUoVuENHCwjvZZ+9D08tv3A22Iifl9Y9YcEupMWr Ygj1VqWcI6LnTmBqgMuz6DiUpG82GXUtGENarbZmNiakXTBC+WdMmr3Lcd8gHGMQMLqNC a9hK5Oriz1JOvgTXa4xWi3buPbDeRrJWR+F99FWCCPYYfB18crYhvLPSbrur6+l46oY0r HqzqATnxNbAjfwTdglhP6zVuKwOTgh7g3jCrB5q+7Tvui8pvqT3U4ECvlcPxyg9rzC/1+ N8cUOnorjKY8YvzClacTnUseMyNgg+W586SqDPRTfoq6TEcEjmoNfndtkbUvAlo3+eQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Qi18SQhZ; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB6C0606A33D; Thu, 3 Dec 2026 06:04:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Qi18SQhZ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.235 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796277856; b=2aks2243DkpZ1xlVpR8l+OIvxznzfMClm0MNepHFhHx8KbYHWGbrzkB8s8SKf7nfIm3m WXav37uDc3LE8EZb5LPXob9VyBdoDVpIS6UIwUV3Viu2vQwGOnraDGeUpGGpFGnqJ4ekf i0JuhVQd3Djv9qwAOSdVmtDtzH5EuMBbwU0nBR3nbL9/TbNoMFiyhdNL54pUmz5nasX3K i9z2erqbnSrB3j1j4Yjljd1ybRdSYUP04N6Ku+W8Ci2A1HB4bEGkIszXA6JHH0pT6YaMs yfLqpEgrE7Sp5Vdx+HZxNARhwGgcGy0YszL6CYSJZ4tPR7VLRq1FmPqbyjD7yzXghjQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796277856; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:X-B4-Tracking: X-Change-ID:To:Cc:X-Mailer; bh=wmqcCvLE0ImozxsR5FibttYYj/J62I/57LJsVq2W1kw=; b=V2AWx6JENbl28O9GLY9v87hheIiZnpKMK9mK8skXn0RnJK+v8u/ri1gMvGYEbzSjNqUz GyYYfLL1g4WwDaLILU4UxTQseh2ZfObE+N7w3G0XpxjXeburaUauYdadcqTtmhEnKf1us H8i5nPEI0aoYcQdoSiNjjVo/3t9M1Hyb6q+wfA6eLeiGw3Cyt1RNNMg1X9tJgl0yjkeHq UOJ4y5/MzHdK4/oLCUNCN4uOOhfn+0TFFeczEKfi9XsnIvlv6/5GxEoTQyzctReZWkqIf nadNMtIXQOhAU1un3Qp3IcKSh2RkJK2dcQUGsg+eBtLoFPC98v0Ihx/0lR+5pzt99aw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Qi18SQhZ; arc=none smtp.remote-ip=91.218.175.235 X-Received: from mta0.migadu.com (out-235.mta0.migadu.com [91.218.175.235]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85DB2606A322 for <netdev@vger.kernel.org>; Thu, 3 Dec 2026 06:04:14 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 85DB2606A322 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=4yZWwiFx28vCdWLYHyUpbnXNNTFNAaA9uwVbv+Ei4BI=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796277852; v=1; x=1796882652; b=Qi18SQhZRds46PFug2wLPxr7GUBST+RJSu5m9T9HFRNc1xpxJaDCbsE3ZTI4uQytFYSmQe4K vHs/3KVKaH83CNf7uZxhXIRtSIK002LPIMAYhduIBq6EV2McRvYV5tFIxG288avCfY+runZHMfW ehfq6coFaxUjSpvHvS5I2OcE= X-Envelope-To: netdev@vger.kernel.org X-Received: by mta12.migadu.com with ESMTPS id d3bdb7bbcf5ba506; Thu, 03 Dec 2026 06:04:12 +0000 X-Mizu-Trace-ID: d3bdb7bbcf5ba506 X-Migadu-Flow: FLOW_OUT X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-B4-Tracking: v=1; b=H4sIAAAAAAAC/32NQQ6CMBREr0L+2hpaVKwr72EIactHvmJr2tpAC HcXcO/yZWbeTBDQEwa4ZBN4TBTI2QXELgPTKXtHRs3CIHJx4lwcmHa2qVtFfe0S+vqlDMNSHkU pSzznGpbh22NLwya9gcXILA4Rql8SPvqBJq7OtdtRiM6P23/i2+LfVeKMM2kUYsFlUfD2+hx7s i7sjYVqnucvUdkqPdEAAAA= X-Change-ID: 20261124-bond_fail_over_mac-e7952797e80b X-Cc: Hangbin Liu <hangbin.liu@linux.dev>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Hangbin Liu <hangbin.liu@linux.dev> X-Mailer: b4 0.16.0