Commit 034ebd3c authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'virtio-net-disable-delayed-refill-when-pausing-rx'

Bui Quang Minh says:

====================
virtio-net: disable delayed refill when pausing rx

Hi everyone,

This only includes the selftest for virtio-net deadlock bug. The fix
commit has been applied already.

Link: https://lore.kernel.org/virtualization/174537302875.2111809.8543884098526067319.git-patchwork-notify@kernel.org/T/
====================

Link: https://patch.msgid.link/20250425071018.36078-1-minhquangbui99@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents c0b0a360 c347fb0f
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only
napi_id_helper
xdp_helper
+0 −1
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \

TEST_GEN_FILES := \
	napi_id_helper \
	xdp_helper \
# end of TEST_GEN_FILES

TEST_PROGS := \
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ TEST_PROGS = \
	rss_ctx.py \
	rss_input_xfrm.py \
	tso.py \
	xsk_reconfig.py \
	#

TEST_FILES := \
+60 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0

# This is intended to be run on a virtio-net guest interface.
# The test binds the XDP socket to the interface without setting
# the fill ring to trigger delayed refill_work. This helps to
# make it easier to reproduce the deadlock when XDP program,
# XDP socket bind/unbind, rx ring resize race with refill_work on
# the buggy kernel.
#
# The Qemu command to setup virtio-net
# -netdev tap,id=hostnet1,vhost=on,script=no,downscript=no
# -device virtio-net-pci,netdev=hostnet1,iommu_platform=on,disable-legacy=on

from lib.py import ksft_exit, ksft_run
from lib.py import KsftSkipEx, KsftFailEx
from lib.py import NetDrvEnv
from lib.py import bkg, ip, cmd, ethtool
import time

def _get_rx_ring_entries(cfg):
    output = ethtool(f"-g {cfg.ifname}", json=True)
    return output[0]["rx"]

def setup_xsk(cfg, xdp_queue_id = 0) -> bkg:
    # Probe for support
    xdp = cmd(f'{cfg.net_lib_dir / "xdp_helper"} - -', fail=False)
    if xdp.ret == 255:
        raise KsftSkipEx('AF_XDP unsupported')
    elif xdp.ret > 0:
        raise KsftFailEx('unable to create AF_XDP socket')

    try:
        return bkg(f'{cfg.net_lib_dir / "xdp_helper"} {cfg.ifindex} ' \
                   '{xdp_queue_id} -z', ksft_wait=3)
    except:
        raise KsftSkipEx('Failed to bind XDP socket in zerocopy.\n' \
                         'Please consider adding iommu_platform=on ' \
                         'when setting up virtio-net-pci')

def check_xdp_bind(cfg):
    with setup_xsk(cfg):
        ip(f"link set dev %s xdp obj %s sec xdp" %
           (cfg.ifname, cfg.net_lib_dir / "xdp_dummy.bpf.o"))
        ip(f"link set dev %s xdp off" % cfg.ifname)

def check_rx_resize(cfg):
    with setup_xsk(cfg):
        rx_ring = _get_rx_ring_entries(cfg)
        ethtool(f"-G %s rx %d" % (cfg.ifname, rx_ring // 2))
        ethtool(f"-G %s rx %d" % (cfg.ifname, rx_ring))

def main():
    with NetDrvEnv(__file__, nsim_test=False) as cfg:
        ksft_run([check_xdp_bind, check_rx_resize],
                 args=(cfg, ))
    ksft_exit()

if __name__ == "__main__":
    main()
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
#include <arpa/inet.h>
#include <sys/socket.h>

#include "ksft.h"
#include "../../net/lib/ksft.h"

int main(int argc, char *argv[])
{
Loading