gve_xdp() runs gve_verify_xdp_configuration() before it looks at the
command, so the check also applies when a program is removed or an
AF_XDP zero-copy pool is disabled. gve has no ndo_change_mtu, so the
MTU can be raised past the XDP limit while a program is attached. From
then on every removal fails with -EOPNOTSUPP.
The core does not expect a removal to fail. With a netlink attach the
program cannot be removed until the MTU is lowered again:
# ethtool -L eth0 rx 1 tx 1
# ip link set dev eth0 mtu 1460
# ip link set dev eth0 xdp obj xdp_pass.o sec xdp
# ip link set dev eth0 mtu 4000
# ip link set dev eth0 xdp off
Error: gve: XDP is not supported for mtu 4000.
With a bpf_link the release path ignores the error. The core warns and
drops its reference while the driver keeps running the program:
WARNING: net/core/dev.c:10824 at bpf_xdp_link_release+0x194/0x1a0, CPU#0: xdp-hold/1293
After that no program is listed on the device, but the driver still
runs it on received packets and it stays loaded.
Only run the check when a program is installed or a pool is enabled.
Installing at an unsupported MTU is still refused.
Reproduced on gVNIC in GQI-QPL mode (GCE n2-standard-4) on net at
commit ef3e21c61baa ("net/tcp-ao: fix reset key lookup for IPv4
segments on IPv6 listeners") with reproduce.sh at the Link below, on an
unmodified kernel and without error injection; the output above is from
that kernel. The script runs the equivalent of the commands above with
its own XDP program, and the bpf_link case with a small loader. On the
patched kernel both removals succeed, there is no warning, the program
stops processing packets, and a new attach at MTU 4000 is still refused.
gve_xdp() and the check are shared by the two queue formats that support
XDP. On DQO-RDA (c3-standard-4, HW-GRO off, 2K RX buffers) the
unmodified kernel fails in the same way and the patched kernel does not.
Unloading gve there with the program attached at MTU 4000 hits the
WARN_ON() in dev_xdp_uninstall() on the unmodified kernel and gives no
warning on the patched kernel.
drivers/net/queues.py passes on the patched kernel; drivers/net/xdp.py
was not run, it needs a second host.
The AF_XDP pool disable path was tested on a second n2-standard-4 VM
(GQI-QPL, network MTU 3000), because gve only enables a zero-copy
pool when one UMEM frame holds the device's maximum MTU. A zero-copy
socket was bound at MTU 1460 with no program attached, the MTU raised
to 3000 and the socket closed. The unmodified kernel logs:
Failed to disable zero-copy!
WARNING: net/xdp/xsk_buff_pool.c:160 at xp_disable_drv_zc+0xa7/0xd0, CPU#3: kworker/3:1/64
After the warning the core frees the pool anyway, while gve still has
it DMA-mapped and, if a program is attached, its queues still point at
it. That last case was found by reading the code and not reproduced.
On the patched kernel the pool is disabled and there is no warning.
The same warning appears at an unchanged MTU when the queue counts are
raised while the pool is bound, which gve allows when no program is
attached; on the patched kernel it does not.
This bug was found and fixed with the help of an AI coding assistant
over an interactive session; it read the driver and the XDP core, and
ran the tests above.
Link: https://github.com/AmaanC/sticky-xdp
Fixes: 75eaae158b1b ("gve: Add XDP DROP and TX support for GQI-QPL format")
Fixes: fd8e40321a12 ("gve: Add AF_XDP zero-copy support for GQI-QPL format")
Cc: stab…@vger.kernel.org
Signed-off-by: Amaan Cheval <amaa…@gmail.com>
---
drivers/net/ethernet/google/gve/gve_main.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c
index 35cf0f06a0f2..5156259232b2 100644
--- a/drivers/net/ethernet/google/gve/gve_main.c
+++ b/drivers/net/ethernet/google/gve/gve_main.c
@@ -1852,17 +1852,27 @@ static int gve_xdp(struct net_device *dev, struct netdev_bpf *xdp)
struct gve_priv *priv = netdev_priv(dev);
int err;
- err = gve_verify_xdp_configuration(dev, xdp->extack);
- if (err)
- return err;
switch (xdp->command) {
case XDP_SETUP_PROG:
+ /* Removing a program must not depend on the configuration
+ * still being valid for XDP: the core does not expect an
+ * uninstall to fail.
+ */
+ if (xdp->prog) {
+ err = gve_verify_xdp_configuration(dev, xdp->extack);
+ if (err)
+ return err;
+ }
return gve_set_xdp(priv, xdp->prog, xdp->extack);
case XDP_SETUP_XSK_POOL:
- if (xdp->xsk.pool)
- return gve_xsk_pool_enable(dev, xdp->xsk.pool, xdp->xsk.queue_id);
- else
+ if (!xdp->xsk.pool)
return gve_xsk_pool_disable(dev, xdp->xsk.queue_id);
+
+ err = gve_verify_xdp_configuration(dev, xdp->extack);
+ if (err)
+ return err;
+ return gve_xsk_pool_enable(dev, xdp->xsk.pool,
+ xdp->xsk.queue_id);
default:
return -EINVAL;
}
--
2.47.3