Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: net: dsa: add a stress test for unlocked FDB operations

This test is a bit strange in that it is perhaps more manual than
others: it does not transmit a clear OK/FAIL verdict, because user space
does not have synchronous feedback from the kernel. If a hardware access
fails, it is in deferred context.

Nonetheless, on sja1105 I have used it successfully to find and solve a
concurrency issue, so it can be used as a starting point for other
driver maintainers too.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vladimir Oltean and committed by
David S. Miller
eccd0a80 d70b51f2

+48
+1
MAINTAINERS
··· 13056 13056 F: include/linux/platform_data/dsa.h 13057 13057 F: include/net/dsa.h 13058 13058 F: net/dsa/ 13059 + F: tools/testing/selftests/drivers/net/dsa/ 13059 13060 13060 13061 NETWORKING [GENERAL] 13061 13062 M: "David S. Miller" <davem@davemloft.net>
+47
tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # Bridge FDB entries can be offloaded to DSA switches without holding the 5 + # rtnl_mutex. Traditionally this mutex has conferred drivers implicit 6 + # serialization, which means their code paths are not well tested in the 7 + # presence of concurrency. 8 + # This test creates a background task that stresses the FDB by adding and 9 + # deleting an entry many times in a row without the rtnl_mutex held. 10 + # It then tests the driver resistance to concurrency by calling .ndo_fdb_dump 11 + # (with rtnl_mutex held) from a foreground task. 12 + # Since either the FDB dump or the additions/removals can fail, but the 13 + # additions and removals are performed in deferred as opposed to process 14 + # context, we cannot simply check for user space error codes. 15 + 16 + WAIT_TIME=1 17 + NUM_NETIFS=1 18 + REQUIRE_JQ="no" 19 + REQUIRE_MZ="no" 20 + NETIF_CREATE="no" 21 + lib_dir=$(dirname $0)/../../../net/forwarding 22 + source $lib_dir/lib.sh 23 + 24 + cleanup() { 25 + echo "Cleaning up" 26 + kill $pid && wait $pid &> /dev/null 27 + ip link del br0 28 + echo "Please check kernel log for errors" 29 + } 30 + trap 'cleanup' EXIT 31 + 32 + eth=${NETIFS[p1]} 33 + 34 + ip link del br0 2&>1 >/dev/null || : 35 + ip link add br0 type bridge && ip link set $eth master br0 36 + 37 + (while :; do 38 + bridge fdb add 00:01:02:03:04:05 dev $eth master static 39 + bridge fdb del 00:01:02:03:04:05 dev $eth master static 40 + done) & 41 + pid=$! 42 + 43 + for i in $(seq 1 50); do 44 + bridge fdb show > /dev/null 45 + sleep 3 46 + echo "$((${i} * 2))% complete..." 47 + done