Skip to content

Commit 29b036b

Browse files
committed
selftests: drv-net: test XDP, HDS auto and the ioctl path
Test XDP and HDS interaction. While at it add a test for using the IOCTL, as that turned out to be the real culprit. Testing bnxt: # NETIF=eth0 ./ksft-net-drv/drivers/net/hds.py KTAP version 1 1..12 ok 1 hds.get_hds ok 2 hds.get_hds_thresh ok 3 hds.set_hds_disable # SKIP disabling of HDS not supported by the device ok 4 hds.set_hds_enable ok 5 hds.set_hds_thresh_zero ok 6 hds.set_hds_thresh_max ok 7 hds.set_hds_thresh_gt ok 8 hds.set_xdp ok 9 hds.enabled_set_xdp ok 10 hds.ioctl ok 11 hds.ioctl_set_xdp ok 12 hds.ioctl_enabled_set_xdp # Totals: pass:11 fail:0 xfail:0 xpass:0 skip:1 error:0 and netdevsim: # ./ksft-net-drv/drivers/net/hds.py KTAP version 1 1..12 ok 1 hds.get_hds ok 2 hds.get_hds_thresh ok 3 hds.set_hds_disable ok 4 hds.set_hds_enable ok 5 hds.set_hds_thresh_zero ok 6 hds.set_hds_thresh_max ok 7 hds.set_hds_thresh_gt ok 8 hds.set_xdp ok 9 hds.enabled_set_xdp ok 10 hds.ioctl ok 11 hds.ioctl_set_xdp ok 12 hds.ioctl_enabled_set_xdp # Totals: pass:12 fail:0 xfail:0 xpass:0 skip:0 error:0 Netdevsim needs a sane default for tx/rx ring size. ethtool 6.11 is needed for the --disable-netlink option. Acked-by: Stanislav Fomichev <[email protected]> Tested-by: Taehee Yoo <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent db10fde commit 29b036b

File tree

4 files changed

+160
-3
lines changed

4 files changed

+160
-3
lines changed

drivers/net/netdevsim/ethtool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,11 @@ static const struct ethtool_ops nsim_ethtool_ops = {
184184

185185
static void nsim_ethtool_ring_init(struct netdevsim *ns)
186186
{
187+
ns->ethtool.ring.rx_pending = 512;
187188
ns->ethtool.ring.rx_max_pending = 4096;
188189
ns->ethtool.ring.rx_jumbo_max_pending = 4096;
189190
ns->ethtool.ring.rx_mini_max_pending = 4096;
191+
ns->ethtool.ring.tx_pending = 512;
190192
ns->ethtool.ring.tx_max_pending = 4096;
191193
}
192194

tools/testing/selftests/drivers/net/hds.py

Lines changed: 142 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,54 @@
22
# SPDX-License-Identifier: GPL-2.0
33

44
import errno
5+
import os
56
from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises, KsftSkipEx
6-
from lib.py import EthtoolFamily, NlError
7+
from lib.py import CmdExitFailure, EthtoolFamily, NlError
78
from lib.py import NetDrvEnv
9+
from lib.py import defer, ethtool, ip
810

9-
def get_hds(cfg, netnl) -> None:
11+
12+
def _get_hds_mode(cfg, netnl) -> str:
1013
try:
1114
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
1215
except NlError as e:
1316
raise KsftSkipEx('ring-get not supported by device')
1417
if 'tcp-data-split' not in rings:
1518
raise KsftSkipEx('tcp-data-split not supported by device')
19+
return rings['tcp-data-split']
20+
21+
22+
def _xdp_onoff(cfg):
23+
test_dir = os.path.dirname(os.path.realpath(__file__))
24+
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
25+
ip("link set dev %s xdp obj %s sec xdp" %
26+
(cfg.ifname, prog))
27+
ip("link set dev %s xdp off" % cfg.ifname)
28+
29+
30+
def _ioctl_ringparam_modify(cfg, netnl) -> None:
31+
"""
32+
Helper for performing a hopefully unimportant IOCTL SET.
33+
IOCTL does not support HDS, so it should not affect the HDS config.
34+
"""
35+
try:
36+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
37+
except NlError as e:
38+
raise KsftSkipEx('ring-get not supported by device')
39+
40+
if 'tx' not in rings:
41+
raise KsftSkipEx('setting Tx ring size not supported')
42+
43+
try:
44+
ethtool(f"--disable-netlink -G {cfg.ifname} tx {rings['tx'] // 2}")
45+
except CmdExitFailure as e:
46+
ethtool(f"--disable-netlink -G {cfg.ifname} tx {rings['tx'] * 2}")
47+
defer(ethtool, f"-G {cfg.ifname} tx {rings['tx']}")
48+
49+
50+
def get_hds(cfg, netnl) -> None:
51+
_get_hds_mode(cfg, netnl)
52+
1653

1754
def get_hds_thresh(cfg, netnl) -> None:
1855
try:
@@ -104,6 +141,103 @@ def set_hds_thresh_gt(cfg, netnl) -> None:
104141
netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': hds_gt})
105142
ksft_eq(e.exception.nl_msg.error, -errno.EINVAL)
106143

144+
145+
def set_xdp(cfg, netnl) -> None:
146+
"""
147+
Enable single-buffer XDP on the device.
148+
When HDS is in "auto" / UNKNOWN mode, XDP installation should work.
149+
"""
150+
mode = _get_hds_mode(cfg, netnl)
151+
if mode == 'enabled':
152+
netnl.rings_set({'header': {'dev-index': cfg.ifindex},
153+
'tcp-data-split': 'unknown'})
154+
155+
_xdp_onoff(cfg)
156+
157+
158+
def enabled_set_xdp(cfg, netnl) -> None:
159+
"""
160+
Enable single-buffer XDP on the device.
161+
When HDS is in "enabled" mode, XDP installation should not work.
162+
"""
163+
_get_hds_mode(cfg, netnl)
164+
netnl.rings_set({'header': {'dev-index': cfg.ifindex},
165+
'tcp-data-split': 'enabled'})
166+
167+
defer(netnl.rings_set, {'header': {'dev-index': cfg.ifindex},
168+
'tcp-data-split': 'unknown'})
169+
170+
with ksft_raises(CmdExitFailure) as e:
171+
_xdp_onoff(cfg)
172+
173+
174+
def set_xdp(cfg, netnl) -> None:
175+
"""
176+
Enable single-buffer XDP on the device.
177+
When HDS is in "auto" / UNKNOWN mode, XDP installation should work.
178+
"""
179+
mode = _get_hds_mode(cfg, netnl)
180+
if mode == 'enabled':
181+
netnl.rings_set({'header': {'dev-index': cfg.ifindex},
182+
'tcp-data-split': 'unknown'})
183+
184+
_xdp_onoff(cfg)
185+
186+
187+
def enabled_set_xdp(cfg, netnl) -> None:
188+
"""
189+
Enable single-buffer XDP on the device.
190+
When HDS is in "enabled" mode, XDP installation should not work.
191+
"""
192+
_get_hds_mode(cfg, netnl) # Trigger skip if not supported
193+
194+
netnl.rings_set({'header': {'dev-index': cfg.ifindex},
195+
'tcp-data-split': 'enabled'})
196+
defer(netnl.rings_set, {'header': {'dev-index': cfg.ifindex},
197+
'tcp-data-split': 'unknown'})
198+
199+
with ksft_raises(CmdExitFailure) as e:
200+
_xdp_onoff(cfg)
201+
202+
203+
def ioctl(cfg, netnl) -> None:
204+
mode1 = _get_hds_mode(cfg, netnl)
205+
_ioctl_ringparam_modify(cfg, netnl)
206+
mode2 = _get_hds_mode(cfg, netnl)
207+
208+
ksft_eq(mode1, mode2)
209+
210+
211+
def ioctl_set_xdp(cfg, netnl) -> None:
212+
"""
213+
Like set_xdp(), but we perturb the settings via the legacy ioctl.
214+
"""
215+
mode = _get_hds_mode(cfg, netnl)
216+
if mode == 'enabled':
217+
netnl.rings_set({'header': {'dev-index': cfg.ifindex},
218+
'tcp-data-split': 'unknown'})
219+
220+
_ioctl_ringparam_modify(cfg, netnl)
221+
222+
_xdp_onoff(cfg)
223+
224+
225+
def ioctl_enabled_set_xdp(cfg, netnl) -> None:
226+
"""
227+
Enable single-buffer XDP on the device.
228+
When HDS is in "enabled" mode, XDP installation should not work.
229+
"""
230+
_get_hds_mode(cfg, netnl) # Trigger skip if not supported
231+
232+
netnl.rings_set({'header': {'dev-index': cfg.ifindex},
233+
'tcp-data-split': 'enabled'})
234+
defer(netnl.rings_set, {'header': {'dev-index': cfg.ifindex},
235+
'tcp-data-split': 'unknown'})
236+
237+
with ksft_raises(CmdExitFailure) as e:
238+
_xdp_onoff(cfg)
239+
240+
107241
def main() -> None:
108242
with NetDrvEnv(__file__, queue_count=3) as cfg:
109243
ksft_run([get_hds,
@@ -112,7 +246,12 @@ def main() -> None:
112246
set_hds_enable,
113247
set_hds_thresh_zero,
114248
set_hds_thresh_max,
115-
set_hds_thresh_gt],
249+
set_hds_thresh_gt,
250+
set_xdp,
251+
enabled_set_xdp,
252+
ioctl,
253+
ioctl_set_xdp,
254+
ioctl_enabled_set_xdp],
116255
args=(cfg, EthtoolFamily()))
117256
ksft_exit()
118257

tools/testing/selftests/net/lib/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ TEST_FILES := ../../../../../Documentation/netlink/specs
99
TEST_FILES += ../../../../net/ynl
1010

1111
TEST_GEN_FILES += csum
12+
TEST_GEN_FILES += $(patsubst %.c,%.o,$(wildcard *.bpf.c))
1213

1314
TEST_INCLUDES := $(wildcard py/*.py sh/*.sh)
1415

1516
include ../../lib.mk
17+
18+
include ../bpf.mk
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#define KBUILD_MODNAME "xdp_dummy"
4+
#include <linux/bpf.h>
5+
#include <bpf/bpf_helpers.h>
6+
7+
SEC("xdp")
8+
int xdp_dummy_prog(struct xdp_md *ctx)
9+
{
10+
return XDP_PASS;
11+
}
12+
13+
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)