Article View: linux.kernel.netdev
Article #21802[PATCH net-next] bonding: check XDP support before enslaving changes state
From: Hangbin Liu
Date: Tue, 24 Nov 2026 13:41
Date: Tue, 24 Nov 2026 13:41
113 lines
12667 bytes
12667 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>
The XDP capability checks in bond_enslave() - ndo_bpf/ndo_xdp_xmit
presence and the slave XDP program count - run only after the slave
has been opened, linked and published to the datapath. On failure the
slave may already be bond->curr_active_slave or reachable through
bond->slave_cnt and the upper device list, so a lot of state has to be
undone, and bond_xdp_xmit() can observe the slave before its
capability was ever verified.
Move both checks to the validation section at the top of
bond_enslave(), before the first state change, so a rejected slave
returns directly with nothing mutated. The dev_xdp_propagate() setup
stays in place and still uses the err_dec_slave_cnt error path.
Moving the checks alone is not enough. Without a bond xdp_prog they
are skipped, and a slave without ndo_xdp_xmit can be enslaved while
the bond still advertises NETDEV_XDP_ACT_NDO_XMIT built from the
other slaves. __xdp_enqueue() then accepts frames and the bulk-queue
flush hands them to bond_xdp_xmit(), which may pick the new slave and
call a NULL ndo_xdp_xmit in softirq context.
Check the selected slave in bond_xdp_xmit() and fail the frame with
-ENXIO instead. The check happens at xmit time, so it also covers
frames enqueued before bond_xdp_set_features() clears the flag, and
the bulk-queue flush path that never rechecks xdp_features.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
Target this patch to net-next as it depends on f564749b3b26 ("net: record
XDP programs propagated to lower devices"). Please tell me if anyone
think it should be post to net.
For Sashiko: please ignore the bond's promiscuity/allmulti/ns maddrs
leak issue when xdp setup failed. It will be addressed in another patch.
---
drivers/net/bonding/bond_main.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 776afdb9df43..0149bd7764e7 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1951,6 +1951,20 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return -EPERM;
}
+ if (bond->xdp_prog) {
+ if (!slave_ops->ndo_bpf || !slave_ops->ndo_xdp_xmit) {
+ SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+ "Slave does not support XDP");
+ return -EOPNOTSUPP;
+ }
+
+ if (dev_xdp_has_own_prog(slave_dev)) {
+ SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+ "Slave has XDP program loaded, please unload before enslaving");
+ return -EOPNOTSUPP;
+ }
+ }
+
/* set bonding device ether type by slave - bonding netdevices are
* created with ether_setup, so when the slave type is not ARPHRD_ETHER
* there is a need to override some of the type dependent attribs/funcs.
@@ -2314,15 +2328,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
unblock_netpoll_tx();
}
- if (!slave_dev->netdev_ops->ndo_bpf ||
- !slave_dev->netdev_ops->ndo_xdp_xmit) {
- if (bond->xdp_prog) {
- SLAVE_NL_ERR(bond_dev, slave_dev, extack,
- "Slave does not support XDP");
- res = -EOPNOTSUPP;
- goto err_dec_slave_cnt;
- }
- } else if (bond->xdp_prog) {
+ if (bond->xdp_prog) {
struct netdev_bpf xdp = {
.command = XDP_SETUP_PROG,
.flags = 0,
@@ -2330,13 +2336,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
.extack = extack,
};
- if (dev_xdp_has_own_prog(slave_dev)) {
- SLAVE_NL_ERR(bond_dev, slave_dev, extack,
- "Slave has XDP program loaded, please unload before enslaving");
- res = -EOPNOTSUPP;
- goto err_dec_slave_cnt;
- }
-
res = dev_xdp_propagate(slave_dev, &xdp);
if (res < 0) {
/* ndo_bpf() sets extack error message */
@@ -5681,7 +5680,7 @@ static int bond_xdp_xmit(struct net_device *bond_dev,
xdp_convert_frame_to_buff(frame, &xdp);
slave_dev = bond_xdp_get_xmit_slave(bond_dev, &xdp);
- if (!slave_dev) {
+ if (!slave_dev || unlikely(!slave_dev->netdev_ops->ndo_xdp_xmit)) {
err = -ENXIO;
break;
}
---
base-commit: a4c450594f5d1dc0fc4daacfb95d40554d99dead
change-id: 20261124-bond_xdp_fix-3f5eb6533f50
Best regards,
--
Hangbin Liu <liuhangbin@kylinos.cn>
Technical Details
Message-ID:
<20261124-bond_xdp_fix-v1-1-e67983924324@kylinos.cn>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370388-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370388-linux-kernel-netdev=dewy.ru From: hangbin.liu@linux.dev (Hangbin Liu) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next] bonding: check XDP support before enslaving changes state Date: Tue, 24 Nov 2026 21:41:16 +0800 Organization: Usenet Network Message-ID: <20261124-bond_xdp_fix-v1-1-e67983924324@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="4146875"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:PaWOudeFQH4LH76ScIrT9ZTQ+gc= sha256:pDCNOdxiz2tUFu0alvZVEw0S5928gIIzOf8g2fQyduY= sha1:lLxK5G3G/DWNrF6aonDrc22Vahs= sha256:xuBlTQQh6wzPY/zqwBch3k1R+klVUqNObWfeohlu0TI= 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 DBBD2125E17; Tue, 24 Nov 2026 16:42:26 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 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, URIBL_BLOCKED=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 pQlHr-bsRdDD; Tue, 24 Nov 2026 16:42:19 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-370388-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 AF645125E15; Tue, 24 Nov 2026 16:42:09 +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 A5C0929503; Tue, 24 Nov 2026 13:42:05 +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=1795527709; b=V79h4poGBPEoF+JOgPvLHNKCKprbKB7R1fIjPy9PZSBwPbGfdBgSq12udGoLb80sahB7 2DIinwvj19yUza8HWnUA6IS57oOa6iX5XzIZWlQJ5q73urikrfpQ54uBwkWIX96WXMrlE mhRkVoTb/wuLsod1Y+zAqNvEsAGKeRIp7R5mB/IyUAsA9292fcHPeCM+3LJMYsiXJ70Za LU+wuuy6NKVAE3skphoH1BBn0vFRoKzKLguxYdgB9hIjJMXcm1e9aId7myx6QDvNItDBK 4DOuSpzUGyA1z0l2oZrdaVJLmzYfwivZ12vj950Lt5zTsbtmAHMrIfeLpA657Pnataw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795527709; 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=mATZzJIHu6yt8XD7wpZlPFJzWv/fQBeRjT0G1Txh/Qs=; b=wiAAGWuLP9cOOUcWJJaHwYdAD2F8U3QqfBE4ZuuX250S31ZedvZmM15epfma17ggOJ55 NP1lT8X3CCfTzjjJAHcwHlde3ugEiToIfujZ1pqP8PYyPXjrACFYBUlHMKUTvkCw+D+HE AQRsGDhdHpYcKPyD/2LX7qnoJvwif+zvEYL2BEBcqlnGKcxVTstx8/1rdkgauT7rNd5vi jrsyPJicC6QDgjTfmvpNR+/TdBA6Md3Qv3e+AXiT91xXlzfk/l+3WTs8zx3W9lGLH4jZd XFNVlWhX9TMkykT/YrGm83BOqgutkQnn1aPbrOjvb6GveKva284aYWqz7M/PkDSPYfA== 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=AWsjD24M; 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 DF0F360A2626; Tue, 24 Nov 2026 13:41:48 +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=AWsjD24M X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.130 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795527708; b=W7mmOJXucW/qP80EDAy/RyYEnCTlamF75Wzvu3Yt2kqlva9r0rwy5JYLQZ25J8Dcqzbj i9CSws1QethMcYStuUcRt7Pbbi1oE/QWwADNmHQpCzdSohMdjd9dHpivY9o2MDYrWBqRE 9YokV6H6QCMQ3gxzVFINZ1/miU7SmLpius8oBTzH+r5BjOmv6wirxfZ+dpX3ZBqPtqUpZ QwN7SAYLC1Ei6akcwE3eP4m9qHiHmbOEt8zDdw1MjJirwhTuYkLC3yKOcr0b9f7yk7rhk Lwh7QKr/YaNJsjlSA1UiPxDWMUdafATNH9zbdVg+FCeNJz/kLEEpM7AGLLSAHvv6muA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795527708; 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=mATZzJIHu6yt8XD7wpZlPFJzWv/fQBeRjT0G1Txh/Qs=; b=vZrrZoy9GWQjKTlEpAxWAL6G8HU8hms402Zv/ySXlhHDCfniO/rbPKFfa8QrEprzIG7X UvbDXIyQszK9KhHiLBEUgXSjyXhpr+kLejefW7b0BB+0b4JYOk9OQJOkBC986WqhRHfpM 4pBfE2ogA0xDGwQqTNTxkhguc2ng/Who/OkILIoFIoqMetwggTrL+W1dMVoSl7UNAoSZs 4bbut8NZ8wd4RfpaiRg4bZ31yUeBcE5lU1MSGdGCxA8P0uzSpKSXe4jmjvdtK1hquvqLe rT26YDyFLv7Yp1aDEMxIK3+3LlJg38cG0rmeQ95Kb87Le0Ukx41y1zZHt75lCn6NAzA== 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=AWsjD24M; arc=none smtp.remote-ip=95.215.58.130 X-Received: from mta1.migadu.com (out-130.mta1.migadu.com [95.215.58.130]) (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 49A9A606A6B6 for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 13:41:47 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 49A9A606A6B6 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=lG1NKyQUrSoB367kFlxf8SnY+K7LrS0Pb3rtvPqARQM=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795527705; v=1; x=1796132505; b=AWsjD24MFhVZQwtmonGr2eNU0yMPb10ZdSVh3cHHTN21ACFbskAESiVGvJYJ6Dddp7ReZ+wH jZ2vBXmuo3OYil3KcMaQZcSb+jHaWVPyxwBujNUeP+Sndu7MGL/tGREZcUraRtHWHM9rXUtUgTW iq3OqHWsOHSjxlX0+/UKLkVI= X-Envelope-To: netdev@vger.kernel.org X-Received: by mta10.migadu.com with ESMTPS id 3ad78350b41956a4; Tue, 24 Nov 2026 13:41:45 +0000 X-Mizu-Trace-ID: 3ad78350b41956a4 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/yWMwQqDMBBEf0XmbMDE6qG/UkSMWdvtYZUkSkD89 27b0/BmmHciUWRKuFcnIh2ceBUFW1eYX5M8yXBQhmtcb627Gb9KGEvYxoWLaZeOfN+1mg30skX S+qd7QCgboZIx/Je0+zfN+WvDdX0AiVNhw3oAAAA= X-Change-ID: 20261124-bond_xdp_fix-3f5eb6533f50 X-Cc: Hangbin Liu <hangbin.liu@linux.dev>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Hangbin Liu <hangbin.liu@linux.dev> X-Mailer: b4 0.16.0