From: Hangbin Liu <liuhangbin@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Jiri Pirko <jiri@resnulli.us>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Andrii Nakryiko <andriin@fb.com>, Jussi Maki <joamaki@gmail.com>,
Jay Vosburgh <jv@jvosburgh.net>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
Hangbin Liu <liuhangbin@gmail.com>, Liang Li <liali@redhat.com>
Subject: [PATCH net] bpf: xdp: fallback to SKB mode if DRV flag is absent.
Date: Tue, 15 Oct 2024 03:36:32 +0000 [thread overview]
Message-ID: <20241015033632.12120-1-liuhangbin@gmail.com> (raw)
After commit c8a36f1945b2 ("bpf: xdp: Fix XDP mode when no mode flags
specified"), the mode is automatically set to XDP_MODE_DRV if the driver
implements the .ndo_bpf function. However, for drivers like bonding, which
only support native XDP for specific modes, this may result in an
"unsupported" response.
In such cases, let's fall back to SKB mode if the user did not explicitly
request DRV mode.
Fixes: c8a36f1945b2 ("bpf: xdp: Fix XDP mode when no mode flags specified")
Reported-by: Liang Li <liali@redhat.com>
Closes: https://issues.redhat.com/browse/RHEL-62339
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
net/core/dev.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index ea5fbcd133ae..e32069d81cd7 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9579,6 +9579,7 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack
/* don't call drivers if the effective program didn't change */
if (new_prog != cur_prog) {
+reinstall:
bpf_op = dev_xdp_bpf_op(dev, mode);
if (!bpf_op) {
NL_SET_ERR_MSG(extack, "Underlying driver does not support XDP in native mode");
@@ -9586,8 +9587,17 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack
}
err = dev_xdp_install(dev, mode, bpf_op, extack, flags, new_prog);
- if (err)
+ if (err) {
+ /* The driver returns not supported even .ndo_bpf
+ * implemented, fall back to SKB mode.
+ */
+ if (err == -EOPNOTSUPP && mode == XDP_MODE_DRV &&
+ !(flags & XDP_FLAGS_DRV_MODE)) {
+ mode = XDP_MODE_SKB;
+ goto reinstall;
+ }
return err;
+ }
}
if (link)
--
2.46.0
next reply other threads:[~2024-10-15 3:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 3:36 Hangbin Liu [this message]
2024-10-15 8:17 ` [PATCH net] bpf: xdp: fallback to SKB mode if DRV flag is absent Daniel Borkmann
2024-10-15 9:53 ` Nikolay Aleksandrov
2024-10-15 10:38 ` Hangbin Liu
2024-10-15 10:46 ` Nikolay Aleksandrov
2024-10-15 10:55 ` Nikolay Aleksandrov
2024-10-15 11:31 ` Hangbin Liu
2024-10-15 15:51 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241015033632.12120-1-liuhangbin@gmail.com \
--to=liuhangbin@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=jiri@resnulli.us \
--cc=joamaki@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jv@jvosburgh.net \
--cc=kuba@kernel.org \
--cc=liali@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).