1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
import re
import time
import threading
from os import path
from lib.py import (
ksft_run,
ksft_exit,
ksft_eq,
ksft_in,
ksft_not_in,
ksft_raises,
)
from lib.py import (
NetDrvContEnv,
NetNSEnter,
EthtoolFamily,
NetdevFamily,
)
from lib.py import (
bkg,
cmd,
defer,
ethtool,
ip,
rand_port,
wait_port_listen,
)
from lib.py import KsftSkipEx, CmdExitFailure
def set_flow_rule(cfg):
output = ethtool(
f"-N {cfg.ifname} flow-type tcp6 dst-port {cfg.port} action {cfg.src_queue}"
).stdout
values = re.search(r"ID (\d+)", output).group(1)
return int(values)
def test_iou_zcrx(cfg) -> None:
cfg.require_ipver("6")
ethnl = EthtoolFamily()
rings = ethnl.rings_get({"header": {"dev-index": cfg.ifindex}})
rx_rings = rings["rx"]
hds_thresh = rings.get("hds-thresh", 0)
ethnl.rings_set(
{
"header": {"dev-index": cfg.ifindex},
"tcp-data-split": "enabled",
"hds-thresh": 0,
"rx": 64,
}
)
defer(
ethnl.rings_set,
{
"header": {"dev-index": cfg.ifindex},
"tcp-data-split": "unknown",
"hds-thresh": hds_thresh,
"rx": rx_rings,
},
)
ethtool(f"-X {cfg.ifname} equal {cfg.src_queue}")
defer(ethtool, f"-X {cfg.ifname} default")
flow_rule_id = set_flow_rule(cfg)
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
rx_cmd = f"ip netns exec {cfg.netns.name} {cfg.bin_local} -s -p {cfg.port} -i {cfg._nk_guest_ifname} -q {cfg.nk_queue}"
tx_cmd = f"{cfg.bin_remote} -c -h {cfg.nk_guest_ipv6} -p {cfg.port} -l 12840"
with bkg(rx_cmd, exit_wait=True):
wait_port_listen(cfg.port, proto="tcp", ns=cfg.netns)
cmd(tx_cmd, host=cfg.remote)
def test_attrs(cfg) -> None:
cfg.require_ipver("6")
netdevnl = NetdevFamily()
queue_info = netdevnl.queue_get(
{"ifindex": cfg.ifindex, "id": cfg.src_queue, "type": "rx"}
)
ksft_eq(queue_info["id"], cfg.src_queue)
ksft_eq(queue_info["type"], "rx")
ksft_eq(queue_info["ifindex"], cfg.ifindex)
ksft_in("lease", queue_info)
lease = queue_info["lease"]
ksft_eq(lease["ifindex"], cfg.nk_guest_ifindex)
ksft_eq(lease["queue"]["id"], cfg.nk_queue)
ksft_eq(lease["queue"]["type"], "rx")
ksft_in("netns-id", lease)
def test_attach_xdp_with_mp(cfg) -> None:
cfg.require_ipver("6")
ethnl = EthtoolFamily()
rings = ethnl.rings_get({"header": {"dev-index": cfg.ifindex}})
rx_rings = rings["rx"]
hds_thresh = rings.get("hds-thresh", 0)
ethnl.rings_set(
{
"header": {"dev-index": cfg.ifindex},
"tcp-data-split": "enabled",
"hds-thresh": 0,
"rx": 64,
}
)
defer(
ethnl.rings_set,
{
"header": {"dev-index": cfg.ifindex},
"tcp-data-split": "unknown",
"hds-thresh": hds_thresh,
"rx": rx_rings,
},
)
ethtool(f"-X {cfg.ifname} equal {cfg.src_queue}")
defer(ethtool, f"-X {cfg.ifname} default")
netdevnl = NetdevFamily()
rx_cmd = f"ip netns exec {cfg.netns.name} {cfg.bin_local} -s -p {cfg.port} -i {cfg._nk_guest_ifname} -q {cfg.nk_queue}"
with bkg(rx_cmd):
wait_port_listen(cfg.port, proto="tcp", ns=cfg.netns)
time.sleep(0.1)
queue_info = netdevnl.queue_get(
{"ifindex": cfg.ifindex, "id": cfg.src_queue, "type": "rx"}
)
ksft_in("io-uring", queue_info)
prog = cfg.net_lib_dir / "xdp_dummy.bpf.o"
with ksft_raises(CmdExitFailure):
ip(f"link set dev {cfg.ifname} xdp obj {prog} sec xdp.frags")
time.sleep(0.1)
queue_info = netdevnl.queue_get(
{"ifindex": cfg.ifindex, "id": cfg.src_queue, "type": "rx"}
)
ksft_not_in("io-uring", queue_info)
def test_destroy(cfg) -> None:
cfg.require_ipver("6")
ethnl = EthtoolFamily()
rings = ethnl.rings_get({"header": {"dev-index": cfg.ifindex}})
rx_rings = rings["rx"]
hds_thresh = rings.get("hds-thresh", 0)
ethnl.rings_set(
{
"header": {"dev-index": cfg.ifindex},
"tcp-data-split": "enabled",
"hds-thresh": 0,
"rx": 64,
}
)
defer(
ethnl.rings_set,
{
"header": {"dev-index": cfg.ifindex},
"tcp-data-split": "unknown",
"hds-thresh": hds_thresh,
"rx": rx_rings,
},
)
ethtool(f"-X {cfg.ifname} equal {cfg.src_queue}")
defer(ethtool, f"-X {cfg.ifname} default")
rx_cmd = f"ip netns exec {cfg.netns.name} {cfg.bin_local} -s -p {cfg.port} -i {cfg._nk_guest_ifname} -q {cfg.nk_queue}"
rx_proc = cmd(rx_cmd, background=True)
wait_port_listen(cfg.port, proto="tcp", ns=cfg.netns)
netdevnl = NetdevFamily()
queue_info = netdevnl.queue_get(
{"ifindex": cfg.ifindex, "id": cfg.src_queue, "type": "rx"}
)
ksft_in("io-uring", queue_info)
# ip link del will wait for all refs to drop first, but iou-zcrx is holding
# onto a ref. Terminate iou-zcrx async via a thread after a delay.
kill_timer = threading.Timer(1, rx_proc.proc.terminate)
kill_timer.start()
ip(f"link del dev {cfg._nk_host_ifname}")
kill_timer.join()
cfg._nk_host_ifname = None
cfg._nk_guest_ifname = None
queue_info = netdevnl.queue_get(
{"ifindex": cfg.ifindex, "id": cfg.src_queue, "type": "rx"}
)
ksft_not_in("io-uring", queue_info)
cmd(f"tc filter del dev {cfg.ifname} ingress pref {cfg._bpf_prog_pref}")
cfg._tc_attached = False
flow_rule_id = set_flow_rule(cfg)
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
rx_cmd = f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} -q {cfg.src_queue}"
tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {cfg.port} -l 12840"
with bkg(rx_cmd, exit_wait=True):
wait_port_listen(cfg.port, proto="tcp")
cmd(tx_cmd, host=cfg.remote)
# Short delay since iou cleanup is async and takes a bit of time.
time.sleep(0.1)
queue_info = netdevnl.queue_get(
{"ifindex": cfg.ifindex, "id": cfg.src_queue, "type": "rx"}
)
ksft_not_in("io-uring", queue_info)
def main() -> None:
with NetDrvContEnv(__file__, rxqueues=2) as cfg:
cfg.bin_local = path.abspath(
path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx"
)
cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
cfg.port = rand_port()
ethnl = EthtoolFamily()
channels = ethnl.channels_get({"header": {"dev-index": cfg.ifindex}})
channels = channels["combined-count"]
if channels < 2:
raise KsftSkipEx("Test requires NETIF with at least 2 combined channels")
cfg.src_queue = channels - 1
with NetNSEnter(str(cfg.netns)):
netdevnl = NetdevFamily()
bind_result = netdevnl.queue_create(
{
"ifindex": cfg.nk_guest_ifindex,
"type": "rx",
"lease": {
"ifindex": cfg.ifindex,
"queue": {"id": cfg.src_queue, "type": "rx"},
"netns-id": 0,
},
}
)
cfg.nk_queue = bind_result["id"]
# test_destroy must be last because it destroys the netkit devices
ksft_run(
[test_iou_zcrx, test_attrs, test_attach_xdp_with_mp, test_destroy],
args=(cfg,),
)
ksft_exit()
if __name__ == "__main__":
main()
|