From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796176533; b=gDvIgH+0BXTv5QW44vKrFFwkQ6QsHsCV8mg8OQly0PhdJyXEHH0popdtZAkurJ/XvJu8 WbsRUYXHVx1TSrGvDALasNsqw4T4b1jUyiSD5JVhOWIONM0sk138WlOluLm5p8EyGezs5 YWPHozpS3VHhzhFDrnq/67RKWCsZsHNnnvfznA52bhaYeAHToRY9KUqynLOSl9zSvkA7N 7JL092fKEBDK/m6kLLIOaD3TXMaOShdHshfKA/92HXhiX4VHBQcVefOlD5d/WUg07OHRR XBMA0bgYF5BcsYXCnCTeUx7Vpd34WOTcPx8HsoEfZCUStkJXdJcNYRtBt+1PoAaYuig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796176533; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=i1BkfU/yMQNWkvwH0ZwzERApvQWrYRiARr123Nagp28=; b=WUd0bKf9AzXEtAAysUjEQdSpZ4Aku/G+72g/4Gf5cKfiuw61XBD12IPZ9hhEUAUYZW7H xdoY7YXvjJ9aezkVg6WANTtHlwUEcBnpWeM39P1jFeYHY8RA3vFhRVmR2wpq050EsehHz fA6EdjHdOSUEPeZlYK+uhhyLGPJiEkOuJ2TXTCl+TPsaEXNFMbrIgB2oYIXft/dvdOqmM TrFT2kyV3O0C98BJHPk9Y8cevXm9E08JoF2TQT64bhAvFyAwteHBtyt40t/hAT5D5rF48 JFow+m5JgBbTXHgJ9gqUYUNpSjn+2STATHDmlO1iJxnZrxqJ21cxfb/Pv7OtZyQJExw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LO8w1dY6; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3922606A330 for ; Wed, 2 Dec 2026 01:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LO8w1dY6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F1741F00893; Wed, 2 Dec 2026 01:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796176533; bh=i1BkfU/yMQNWkvwH0ZwzERApvQWrYRiARr123Nagp28=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LO8w1dY6BXPipR0c4UqrLCRMLsBrv+S019rC33tIiIyxQ4ovdqM6Irxwr47SSSacu V8GVaGx6+GvWS66HqKQycjRDU0tWf/gEswEuCfsJySDj2oL4ckkRHK2KqXDyTR6hjq xtRJiZZIcITxPO7KbiEwsx76shOW5A3HbUREm+2flPydDBlApyg82Puj8YxpxRKJEZ mPBMIlNo5zjZp/PARHWwRGF81uTeQLrII2DMi8Fcmx8HA2xe1mTn6+QwMsZ+YG/DZL 0Dj1jr9tdxZW+pPvQSo9qvDzm7oUnnRhZorF8NRNL+Yy8vXQsU6tyYfEnwFkf4Wqyh xaqvwwGUQQcDw== From: David Ahern To: netdev@vger.kernel.org Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, David Ahern Subject: [PATCH net-next 2/2] selftests: Add stress test for dst_entries Date: Tue, 1 Dec 2026 18:55:23 -0700 Message-ID: <20261202015529.7846-3-dsahern@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261202015529.7846-1-dsahern@kernel.org> References: <20261202015529.7846-1-dsahern@kernel.org> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Ahern Signed-off-by: David Ahern --- tools/testing/selftests/net/fib_tests.sh | 178 ++++++++++++++++++++++- 1 file changed, 177 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index d7ac3c727f70..d1686dff7a77 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -14,7 +14,8 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \ ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \ ipv4_mpath_balance_preferred ipv4_mpath_oif ipv4_mpath_oif_nh \ ipv4_mpath_oif_vrf ipv6_mpath_oif ipv6_mpath_oif_nh ipv6_mpath_oif_vrf \ - fib6_ra_to_static fib6_temp_addr_renewal" + fib6_ra_to_static fib6_temp_addr_renewal \ + ipv4_dst_entries_stress ipv6_dst_entries_stress" VERBOSE=0 PAUSE_ON_FAIL=no @@ -3228,6 +3229,179 @@ ipv6_mpath_oif_vrf_test() cleanup } +# Number of dst entries the netns' dst_ops accounts for. DST_NOCOUNT dsts +# (pcpu routes) are not in it, but exceptions, clones and uncached dsts are. +# The IPv4 counter belongs to the global ipv4_dst_ops, so it also sees other +# netns. +dst_entries() +{ + local family=$1 hex + + if [ "$family" = "6" ]; then + hex=$($NS_EXEC awk '{print $6}' /proc/net/rt6_stats) + else + hex=$($NS_EXEC awk 'NR == 2 {print $1}' /proc/net/stat/rt_cache) + fi + + echo $((16#$hex)) +} + +# wait up to $3 seconds for the dst entry count to drop to $2 or below +wait_dst_entries_le() +{ + local family=$1 + local limit=$2 + local secs=$3 + local i + + for ((i = 0; i < secs * 10; i++)); do + [ $(dst_entries $family) -le $limit ] && return 0 + sleep 0.1 + done + + return 1 +} + +# Create more PMTU exceptions than the exception tables allow and churn the +# routes while every cpu keeps building pcpu dsts. The dst count must stay +# within the table limits, must not grow because of the churn, and must go +# back to where it started once the routes and nexthops are gone. +# +# DST_STRESS_EXC is the number of destinations to send a too big packet to +# per route, DST_STRESS_ITERS the number of churn iterations. +dst_entries_stress() +{ + local family=$1 + local exc=${DST_STRESS_EXC:-1000} + local iters=${DST_STRESS_ITERS:-200} + local ncpus=$(nproc) + local base after_exc after_churn cap slack i cpu dst1 dst2 ip6="" + local gw1 pfx1 pfx2 + + [ $ncpus -gt 4 ] && ncpus=4 + + if [ ! -x "$(command -v taskset)" ]; then + echo "SKIP: taskset not installed" + return $ksft_skip + fi + + setup + + set -e + setup_ns ns2 + $IP link add veth1 type veth peer name veth2 netns $ns2 + $IP link set veth1 up + ip -netns $ns2 link set veth2 up + ip -netns $ns2 link add dummy0 type dummy + ip -netns $ns2 link set dummy0 mtu 1280 up + # the too big messages must not be rate limited + ip netns exec $ns2 sysctl -qw net.ipv4.ip_forward=1 + ip netns exec $ns2 sysctl -qw net.ipv4.icmp_ratelimit=0 + ip netns exec $ns2 sysctl -qw net.ipv4.icmp_msgs_per_sec=100000 + ip netns exec $ns2 sysctl -qw net.ipv4.icmp_msgs_burst=100000 + ip netns exec $ns2 sysctl -qw net.ipv6.conf.all.forwarding=1 + ip netns exec $ns2 sysctl -qw net.ipv6.icmp.ratelimit=0 + + if [ "$family" = "6" ]; then + ip6="-6" + gw1=2001:db8:10::2 + pfx1=2001:db8:12::/64 + pfx2=2001:db8:13::/64 + cap=$((2 * 1024 * 6)) # 2 fib6_nh * buckets * (depth + 1) + slack=16 + $IP -6 address add 2001:db8:10::1/64 dev veth1 nodad + ip -netns $ns2 -6 address add 2001:db8:10::2/64 dev veth2 nodad + ip -netns $ns2 -6 route add $pfx1 dev dummy0 + ip -netns $ns2 -6 route add $pfx2 dev dummy0 + else + gw1=10.10.0.2 + pfx1=10.20.0.0/16 + pfx2=10.30.0.0/16 + cap=$((2 * 2048 * 6)) + slack=64 # the counter is global + $IP address add 10.10.0.1/24 dev veth1 + ip -netns $ns2 address add 10.10.0.2/24 dev veth2 + ip -netns $ns2 route add $pfx1 dev dummy0 + ip -netns $ns2 route add $pfx2 dev dummy0 + fi + + # one route with its own nexthop, one using a nexthop object + $IP $ip6 nexthop add id 100 via $gw1 dev veth1 + $IP $ip6 route add $pfx1 via $gw1 dev veth1 + $IP $ip6 route add $pfx2 nhid 100 + set +e + + base=$(dst_entries $family) + + for ((i = 1; i <= exc; i++)); do + if [ "$family" = "6" ]; then + dst1=2001:db8:12::$(printf %x $i) + dst2=2001:db8:13::$(printf %x $i) + $NS_EXEC $ping6 -c1 -W1 -s1400 $dst1 &> /dev/null + $NS_EXEC $ping6 -c1 -W1 -s1400 $dst2 &> /dev/null + else + dst1=10.20.$((i / 250)).$((i % 250 + 1)) + dst2=10.30.$((i / 250)).$((i % 250 + 1)) + $NS_EXEC ping -c1 -W1 -s1400 -M do $dst1 &> /dev/null + $NS_EXEC ping -c1 -W1 -s1400 -M do $dst2 &> /dev/null + fi + done + + after_exc=$(dst_entries $family) + [ $after_exc -gt $((base + exc / 2)) ] + log_test $? 0 "PMTU exceptions created ($base -> $after_exc dst entries)" + + [ $after_exc -le $((base + cap)) ] + log_test $? 0 "dst entries within the exception table limits ($after_exc <= $((base + cap)))" + + # churn: every cpu builds pcpu dsts, then the routes and the nexthop + # change, which invalidates them + for ((i = 0; i < iters; i++)); do + for ((cpu = 0; cpu < ncpus; cpu++)); do + if [ "$family" = "6" ]; then + taskset -a -c $cpu $IP -6 route get 2001:db8:12::1 &> /dev/null + taskset -a -c $cpu $IP -6 route get 2001:db8:13::1 &> /dev/null + else + taskset -a -c $cpu $IP route get 10.20.0.1 &> /dev/null + taskset -a -c $cpu $IP route get 10.30.0.1 &> /dev/null + fi + done + $IP $ip6 route replace $pfx1 via $gw1 dev veth1 + $IP $ip6 nexthop replace id 100 via $gw1 dev veth1 + $IP $ip6 route replace $pfx2 nhid 100 + done + + # let the deferred releases run + sleep 2 + after_churn=$(dst_entries $family) + [ $after_churn -le $((after_exc + slack)) ] + log_test $? 0 "dst entries do not grow with route churn ($after_exc -> $after_churn)" + + $IP $ip6 route del $pfx1 + $IP $ip6 route del $pfx2 + $IP $ip6 nexthop del id 100 + wait_dst_entries_le $family $((base + slack)) 10 + log_test $? 0 "dst entries released with routes and nexthop (base $base, now $(dst_entries $family))" + + cleanup +} + +ipv4_dst_entries_stress_test() +{ + echo + echo "IPv4 dst entries stress test" + + dst_entries_stress 4 +} + +ipv6_dst_entries_stress_test() +{ + echo + echo "IPv6 dst entries stress test" + + dst_entries_stress 6 +} + ################################################################################ # usage @@ -3322,6 +3496,8 @@ do ipv6_mpath_oif_vrf) ipv6_mpath_oif_vrf_test;; fib6_ra_to_static) fib6_ra_to_static;; fib6_temp_addr_renewal) fib6_temp_addr_renewal;; + ipv4_dst_entries_stress) ipv4_dst_entries_stress_test;; + ipv6_dst_entries_stress) ipv6_dst_entries_stress_test;; help) echo "Test names: $TESTS"; exit 0;; esac -- 2.54.0 (Apple Git-157)