Add checks that each RX queue is linked to a NAPI instance of the device while NAPI is enabled, and is not linked otherwise. chk_queue_napi() reads queue-get and napi-get with the ynl CLI, as the ndo-xmit checks do. It checks with jq that the napi-ids of the RX queues are the IDs of the NAPI instances, and that the expected number of queues is linked. The checks run with GRO on and with XDP attached, and across RX channel changes and link down/up. They are skipped if the ynl CLI or jq is not found. Signed-off-by: Tianyi Gao --- tools/testing/selftests/net/veth.sh | 79 ++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/veth.sh b/tools/testing/selftests/net/veth.sh index 64c2a5a59821..685209995485 100755 --- a/tools/testing/selftests/net/veth.sh +++ b/tools/testing/selftests/net/veth.sh @@ -110,6 +110,44 @@ chk_xdp_feature() { fi } +chk_queue_napi() { + local msg="$1" + local target=$2 + local expected=$3 + local ns=$BASE$target + local ifindex + local queues + local napis + local st + local linked + + ifindex=`ip netns exec $ns cat /sys/class/net/veth$target/ifindex` + queues=`ip netns exec $ns "$YNL" --family netdev --dump queue-get \ + --output-json --json "{\"ifindex\": $ifindex}" 2>&1` + st=$? + napis=`ip netns exec $ns "$YNL" --family netdev --dump napi-get \ + --output-json --json "{\"ifindex\": $ifindex}" 2>&1` || st=$? + + printf "%-60s" "$msg" + if [ $st -ne 0 ]; then + echo " fail - ynl cli error: $queues $napis" + ret=1 + return + fi + + queues=`echo "$queues" | \ + jq -c 'map(select(.type == "rx") | ."napi-id" // empty) | sort'` + napis=`echo "$napis" | jq -c 'map(.id) | sort'` + linked=`echo "$queues" | jq length` + + if [ "$queues" = "$napis" ] && [ "$linked" = "$expected" ]; then + echo " ok " + else + echo " fail - expected $expected found $queues napis $napis" + ret=1 + fi +} + chk_channels() { local msg="$1" local target=$2 @@ -330,7 +368,8 @@ fi [ $CPUS -lt 2 ] && echo "Only one CPU available, some tests will be skipped" [ $STRESS -gt 0 -a $CPUS -lt 3 ] && echo " stress test will be skipped, too" -[ ! -f "$YNL" ] && echo "ynl cli not found, ndo-xmit tests will be skipped" +[ ! -f "$YNL" ] && echo "ynl cli not found, ndo-xmit/napi tests will be skipped" +[ ! -x "$(command -v jq)" ] && echo "jq not found, napi tests will be skipped" chk_channels_carrier up up || ret=1 chk_channels_carrier up down || ret=1 @@ -443,6 +482,44 @@ else fi cleanup +if [ -f "$YNL" ] && [ -x "$(command -v jq)" ]; then + create_ns + RXQ=1 + if [ $CPUS -gt 1 ]; then + ip netns exec $NS_DST ethtool -L veth$DST rx 2 + RXQ=2 + fi + chk_queue_napi "queue napi - default" $DST 0 + ip netns exec $NS_DST ethtool -K veth$DST gro on + chk_queue_napi " - with gro on" $DST $RXQ + if [ $CPUS -gt 1 ]; then + ip netns exec $NS_DST ethtool -L veth$DST rx 1 + chk_queue_napi " - fewer rx channels with gro" $DST 1 + ip netns exec $NS_DST ethtool -L veth$DST rx 2 + chk_queue_napi " - more rx channels with gro" $DST 2 + fi + ip -n $NS_DST link set dev veth$DST xdp object ${BPF_FILE} section xdp + chk_queue_napi " - with gro and xdp on" $DST $RXQ + ip -n $NS_DST link set dev veth$DST xdp off + chk_queue_napi " - after xdp off with gro on" $DST $RXQ + ip netns exec $NS_DST ethtool -K veth$DST gro off + chk_queue_napi " - after gro off" $DST 0 + ip -n $NS_DST link set dev veth$DST xdp object ${BPF_FILE} section xdp + chk_queue_napi " - with xdp on" $DST $RXQ + if [ $CPUS -gt 1 ]; then + ip netns exec $NS_DST ethtool -L veth$DST rx 1 + chk_queue_napi " - fewer rx channels with xdp" $DST 1 + ip netns exec $NS_DST ethtool -L veth$DST rx 2 + chk_queue_napi " - more rx channels with xdp" $DST 2 + fi + ip -n $NS_DST link set dev veth$DST down + ip -n $NS_DST link set dev veth$DST up + chk_queue_napi " - after down and up" $DST $RXQ + ip -n $NS_DST link set dev veth$DST xdp off + chk_queue_napi " - after xdp off" $DST 0 + cleanup +fi + create_ns CUR_TX=1 -- 2.56.0