From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E98C9328610 for ; Fri, 7 Nov 2025 14:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524252; cv=none; b=FgunnvWB4EtpJ2NCBteN4bT/jTlI3knYrtSr8ww9ckB+FoSB+/lTmZtiWwQ41lYAn7vAiMmA13hqq0mkQYU9oD1o3wC1iEBHdonC79cjaDQ6ugv+jtKgRIhAlPyM+z8Nngao7IJ8xaUBV60ASsM4ElFk6laqCWqfLVFU4Bqg1gI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524252; c=relaxed/simple; bh=XQp4YoJOgWYJBS+lAreScEfDBZBcema28xQn9VyrhM8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TSBoxhX0gUtUWWfJGrmU0UMJHp7a1SX64r7+vOTzQlv0Jjgp25WAJw1cAY6H+56CO5Q7aa0qR7qMefnuBkT7DJxokrMiiVV5PrjfBLxBUPYyBtKQd79DFTmwRqsbpeWbyNLsNfbj4hk6MEDCzcuyoiXx+70EImSCmEulKjhD/MU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-afcb7ae6ed0so129883366b.3 for ; Fri, 07 Nov 2025 06:04:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762524248; x=1763129048; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=48WWGgV3/OQmNtRAgDmereIyjTW6e2ku3y8EB8DFBcI=; b=mNW38ge89O0Lk1m5pZy4JcEGR/ZnHwzU5eGEOv4PyEYXow7O4xG7NTRGQ4edf2oGDH Jlj5q8RgcdXAiAsNwBlgZcIr/ss/K0BrdVsIiD6y/28TM5Bmz0o5x9GUVby6WwpzIXvk Jecr4L4Ctl8txu9k4Cscxp8amHcMzOg1qjcMHwWd9syH5q7fAdqlIXG1jCz+C+LEcQkG kmDhXobc7UxUeNgUrJIDPssLr098YEe4MEU8bOBR/P4jHC7n1HlTU38/vJZuv+WVbQXA r3ClaRZC5Wig6lvnLNQEuo/JjA9frECN3WwYL2O/jgoE1g+vOgo5C+lNQYAYzflOckSb 9bYg== X-Forwarded-Encrypted: i=1; AJvYcCVVYqytbGnhLWC3EiW4OW0aHXTFctHO1jqqyVS72lYkjPa4b17rb1A4PJi8p4oQvcIsuLMYsLY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5/+TJlQ5SkBWjq6/OlZoN2ULXWTdahAXVwfE2OZCp1zjBZsQ7 eZRpEdHZ6IZ9ZJedv6VEeZ2dwmFD3xq8NxashyKqiTU6zLwzybfk09i7 X-Gm-Gg: ASbGncudyQJ3Jkl4bRxNVxnfZkuMTxCyx+zaOWHWmvE7mOwIghk5FHXEWQ7CNc2Usi/ lsEFRDe8D1DoHdl9JWvXiBx34foM0oz+A7RdgidNx4G4/YZKBuIP2tMq9Bz3jCJGTpuTkyO5cq7 LG9ouaihistFgT6hcG1E/a1kBo1Viij1wVo6cznJAzPElTaH9Zc2mOCyQbLxrb+lm3OK2k4/Z4n Y2YpigblgF/KxEBWZd8MxuXbDTZMIInCaJZZQxvJOt6X18Rdo7DzJf5CCELu6gwiz6BbtU2y0Ro XjthCqwZN0Qt+Nf+9S7fp5FVrT9IMG9/L8UuKn8FiHy140wDKzhXsM1hsJ65bDNuk+5BpbeQ0Ws FRALLGjdxvzR9hRkiiksNCflD8Ah+TaipcEydOlHoRAjXp3qlIofhrICYtfJxydE3xA== X-Google-Smtp-Source: AGHT+IHsxl2XPAlFemI24OJUBp3fWjsJgLD0KhUvnrbrT+u5Rl9gEHfRv/SUFSF97pVI+pc2Kd8NmQ== X-Received: by 2002:a17:907:7f8b:b0:b6d:67b0:ca0b with SMTP id a640c23a62f3a-b72c0dcb646mr312514066b.61.1762524247809; Fri, 07 Nov 2025 06:04:07 -0800 (PST) Received: from localhost ([2a03:2880:30ff:8::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6411f862bd0sm4354131a12.26.2025.11.07.06.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:04:07 -0800 (PST) From: Breno Leitao Date: Fri, 07 Nov 2025 06:03:39 -0800 Subject: [PATCH net v10 3/4] selftest: netcons: create a torture test Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251107-netconsole_torture-v10-3-749227b55f63@debian.org> References: <20251107-netconsole_torture-v10-0-749227b55f63@debian.org> In-Reply-To: <20251107-netconsole_torture-v10-0-749227b55f63@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman , david decotigny Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, calvin@wbinvd.org, kernel-team@meta.com, calvin@wbinvd.org, jv@jvosburgh.net, Breno Leitao X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=5328; i=leitao@debian.org; h=from:subject:message-id; bh=XQp4YoJOgWYJBS+lAreScEfDBZBcema28xQn9VyrhM8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpDfxRs0hwlyPprZCy7+HJz29rlUnUJTxAFFQNi /Z8x94vzfaJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaQ38UQAKCRA1o5Of/Hh3 beFwD/93H/5JZ90OGK7FAb7LO8jQ5l5TjjZmj91h748Q+8zPGszefi/KlWCesQ4vSBGJ0YP6Xbe z/AXyk4N6z3LUM6kxXuWUgEZ8gnsb5VuVAK+qMnBzhTjKdTZ3IuRSd4vIZNhDf99pmOAY+dv8/s KHump/2qH/HsFgDFtsH+xGwUDYrOHJ/2Zk04MBnuSXZpl8HbDJd2mBiasrjfZ1fU6eHdD+OZhk+ ypykIZRZgJvLSE8nHJMLC2Abxvq3eZHCoqg7wEDWcX2c8J6s+GiEgF1Y/ob6KmEk0QRkZVXvOjH 2BbtvdK142leANniiHxHCPtxFS5NMJa2Tg7lLR716S5WLaUy5eAzvoFXZ0GZ0I9CfVXROzTbyP5 evCXNHFGimHDDVJnYJsS5n9lNqN92Gnc11IEjJXQ8faVGn/rd94hqb70TQCKn3GvXw+US4m3Wm4 ZWTN4Fale4u4FEgno56YX6FjONuC1x1dDcN43bcz1XGnnIw++NWcEnIOWhU4drRCCQgvllBC4Mw LJdAAAd0VvhjAIWUkYu72WLtZnlzgMMBAgzzGJRYOI0BsdV4HORBeGUFheISB5ZWmHZqOEBc994 /u6sZi36kt1eWcqEbpxU7ctyDIA3dCowVYukU6bt5skEHCJrBMJw7PoQ/yd+AdUtzdYNfd79Upn TM3XfaLkgWTnU1Q== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Create a netconsole test that puts a lot of pressure on the netconsole list manipulation. Do it by creating dynamic targets and deleting targets while messages are being sent. Also put interface down while the messages are being sent, as creating parallel targets. The code launches three background jobs on distinct schedules: * Toggle netcons target every 30 iterations * create and delete random_target every 50 iterations * toggle iface every 70 iterations This creates multiple concurrency sources that interact with netconsole states. This is good practice to simulate stress, and exercise netpoll and netconsole locks. This test already found an issue as reported in [1] Link: https://lore.kernel.org/all/20250901-netpoll_memleak-v1-1-34a181977dfc@debian.org/ [1] Signed-off-by: Breno Leitao Reviewed-by: Andre Carvalho Reviewed-by: Simon Horman --- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/netcons_torture.sh | 130 +++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index 6e41635bd55a4..71ee69e524d77 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -18,6 +18,7 @@ TEST_PROGS := \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ netcons_sysdata.sh \ + netcons_torture.sh \ netpoll_basic.py \ ping.py \ psp.py \ diff --git a/tools/testing/selftests/drivers/net/netcons_torture.sh b/tools/testing/selftests/drivers/net/netcons_torture.sh new file mode 100755 index 0000000000000..2ce9ee3719d1a --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_torture.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# Repeatedly send kernel messages, toggles netconsole targets on and off, +# creates and deletes targets in parallel, and toggles the source interface to +# simulate stress conditions. +# +# This test aims to verify the robustness of netconsole under dynamic +# configurations and concurrent operations. +# +# The major goal is to run this test with LOCKDEP, Kmemleak and KASAN to make +# sure no issues is reported. +# +# Author: Breno Leitao + +set -euo pipefail + +SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh + +# Number of times the main loop run +ITERATIONS=${1:-150} + +# Only test extended format +FORMAT="extended" +# And ipv6 only +IP_VERSION="ipv6" + +# Create, enable and delete some targets. +create_and_delete_random_target() { + COUNT=2 + RND_PREFIX=$(mktemp -u netcons_rnd_XXXX_) + + if [ -d "${NETCONS_CONFIGFS}/${RND_PREFIX}${COUNT}" ] || \ + [ -d "${NETCONS_CONFIGFS}/${RND_PREFIX}0" ]; then + echo "Function didn't finish yet, skipping it." >&2 + return + fi + + # enable COUNT targets + for i in $(seq ${COUNT}) + do + RND_TARGET="${RND_PREFIX}"${i} + RND_TARGET_PATH="${NETCONS_CONFIGFS}"/"${RND_TARGET}" + + # Basic population so the target can come up + _create_dynamic_target "${FORMAT}" "${RND_TARGET_PATH}" + done + + echo "netconsole selftest: ${COUNT} additional targets were created" > /dev/kmsg + # disable them all + for i in $(seq ${COUNT}) + do + RND_TARGET="${RND_PREFIX}"${i} + RND_TARGET_PATH="${NETCONS_CONFIGFS}"/"${RND_TARGET}" + if [[ $(cat "${RND_TARGET_PATH}/enabled") -eq 1 ]] + then + echo 0 > "${RND_TARGET_PATH}"/enabled + fi + rmdir "${RND_TARGET_PATH}" + done +} + +# Disable and enable the target mid-air, while messages +# are being transmitted. +toggle_netcons_target() { + for i in $(seq 2) + do + if [ ! -d "${NETCONS_PATH}" ] + then + break + fi + echo 0 > "${NETCONS_PATH}"/enabled 2> /dev/null || true + # Try to enable a bit harder, given it might fail to enable + # Write to `enabled` might fail depending on the lock, which is + # highly contentious here + for _ in $(seq 5) + do + echo 1 > "${NETCONS_PATH}"/enabled 2> /dev/null || true + done + done +} + +toggle_iface(){ + ip link set "${SRCIF}" down + ip link set "${SRCIF}" up +} + +# Start here + +modprobe netdevsim 2> /dev/null || true +modprobe netconsole 2> /dev/null || true + +# Check for basic system dependency and exit if not found +check_for_dependencies +# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5) +echo "6 5" > /proc/sys/kernel/printk +# Remove the namespace, interfaces and netconsole target on exit +trap cleanup EXIT +# Create one namespace and two interfaces +set_network "${IP_VERSION}" +# Create a dynamic target for netconsole +create_dynamic_target "${FORMAT}" + +for i in $(seq "$ITERATIONS") +do + for _ in $(seq 10) + do + echo "${MSG}: ${TARGET} ${i}" > /dev/kmsg + done + wait + + if (( i % 30 == 0 )); then + toggle_netcons_target & + fi + + if (( i % 50 == 0 )); then + # create some targets, enable them, send msg and disable + # all in a parallel thread + create_and_delete_random_target & + fi + + if (( i % 70 == 0 )); then + toggle_iface & + fi +done +wait + +exit "${EXIT_STATUS}" -- 2.47.3