From nobody Mon Dec 1 23:09:23 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 766F3345CA8 for ; Wed, 26 Nov 2025 20:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764188621; cv=none; b=YFxesNANJeksPLeKBO6ibaukzognO8FWvNglxDWY6TqcFYs9HgYO2dkL8/sW8NWe2wHUfPcLML0EFvhwS8nhZX1ZTqPomK1dB5CMrK+iJJ4fRaFFiNPkCFbQBnJod7nzxh6l5ctT8EJp5HoSbJDrhOu7R8oQj8lEMeYioW+MgOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764188621; c=relaxed/simple; bh=hn/kxg8v9iI6fPhbZcD8Tj+G//s0QmgoWLVA/hu8hV4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BgG8G4s7W5fDb2M3oatYgpF2xEjsdoPXfTmhmB38PcpWvv3uzkCgkWU8MHWScgUSsEUNtQRRHWHudrabtHJ4YYUiOark1y5BTvyC0Lm3a4AFQGiTeFGMxmwmnR8HH23KvxeOMWcGwfC8zdKgSeL7nBok3Z5m2zqKI3Ale/zXHXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZKFzQj2D; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZKFzQj2D" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-295548467c7so1841245ad.2 for ; Wed, 26 Nov 2025 12:23:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764188619; x=1764793419; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3/fAPe5zn1MJUzjr0NdBaLTd5ohKsQq+JKoQHPiFo9E=; b=ZKFzQj2Digx3P0D2Z7pBMXWp/dNP2V2Z6OTlQrNWtxCu/Z/KXT+f/Ak11S/DyxRFti Mkyf7wlbwXBZThFRG43mcDnvqWbcAIWguMqRtYaaaf0qdSSAZLnthzscgwkVFwTWfSW0 bME+nvfw8KAJQ6N6Qw+VBQ4bsAiXFZWpHL2f+0x+5UBsPEyOY1QRkiBM7t3R6teRwmN9 kSgoIK41KzfFSl2HKt287WF64O+uGWU1JcrmI2mpM/MuKdnHAb0ZmSaTgOLHRZM2Rq8k B8ej8g42RUfWvShHNhTDIgKcERsYU/fZEW47xf/AawM2B/Od/KimisAW1QY9zTyFzepf +KZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764188619; x=1764793419; 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=3/fAPe5zn1MJUzjr0NdBaLTd5ohKsQq+JKoQHPiFo9E=; b=u4EZoQJB+Lt5auLabvwyj+gO7G4oLmYVK2zegp7ocjf0B9sH81DMnClL/b7puYwk2L qWtj/NXIYXO+dJRc0D6AotacLEhQwB+29p7aNbCiJjKyBXfVouuI2wGLuGzDSoaw44B9 BJ+//15W7Typ+VSeoqZDtm1TaclEUimASwbQaJ/TM6H/JdX34GiUnEPFHvE+d8X9tezE chGDO6xqGZXE9Fzc4AR4HHyh2RHgAsZzNQL8ydAcFyM11HvjDLmGJmkuNSJykMQ8Eq13 fVLI2hKObYnFA50z3jWCDm/daKyIOAcyN2n9aNH/xr/nXbGK4y4dU0ULZYWcokuAyXj0 QTpg== X-Forwarded-Encrypted: i=1; AJvYcCWQvIMTB381MPlUooxpBYo2/xWCuDe2HeFx7vl6EAIOZ3RX1Z761BTMrVgy9VTBvaIRGAMSTtlZ/l6ow34=@vger.kernel.org X-Gm-Message-State: AOJu0YxKXFwKMsW3Y5HPaFFGyXXdcYCPbswSvPlOeisyGRJf0ut9gXz5 e85Oav5W1vJW1AnA6OD/+tciyIXPq7mTDuqcW483022qgh/8ynQIHzkM X-Gm-Gg: ASbGncsvAYne+gvrgtXoyzDjqMGIcNe2v/xKGP2BsE2dM/Q+QDs1KZ5Un/oEOWmD1mW 5zuPqgYNfOp4HkqqiqQXsTFCbmISbTQ3OaJ+aBAFqt8iAWAzGu/HJTuBeTUzSn6p++i56xbDxBV lHbS5gBV4TQiE9wQ/45dgbgpUhH2NC6Y3oMiQxcxsvPWs5wj89EMHmq4ttJIAyZdv0mFuv4IrU7 PQplINqkMOBzQclxP6vbUlbqKaB9jb+No8vcv6sHoXUtwyNWzeX2F2i8VhUqovqsbDhgDisPJiG fJa8BjKzKV9POlisyJgQh8VRaQocME+hRd8yAc5sU0n2Obl3SypmXluoWE10l+SaDvD6lYerltD K/vDrwuRpT8vYSIGedDCBGF/DZVjz1R0Dk/UJY9O3iogQH8/EcU84aT3BlYBvsy3sw1/bMkpwqW te4nruaXpuA+SJkjLbAw== X-Google-Smtp-Source: AGHT+IFlWVMX3M1sh8LmYCCM96cdfdCDdGHZ43sVYm0HSHzwk5bsC7hG9uCm6tFdUOBtcUGMxFtFNA== X-Received: by 2002:a17:902:ccc9:b0:295:596f:84ef with SMTP id d9443c01a7336-29b6bf3b5dfmr273525865ad.31.1764188618591; Wed, 26 Nov 2025 12:23:38 -0800 (PST) Received: from [192.168.15.94] ([2804:7f1:ebc3:752f:12e1:8eff:fe46:88b8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b13a80csm207100475ad.35.2025.11.26.12.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 12:23:37 -0800 (PST) From: Andre Carvalho Date: Wed, 26 Nov 2025 20:22:57 +0000 Subject: [PATCH net-next v7 5/5] selftests: netconsole: validate target resume Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251126-netcons-retrigger-v7-5-1d86dba83b1c@gmail.com> References: <20251126-netcons-retrigger-v7-0-1d86dba83b1c@gmail.com> In-Reply-To: <20251126-netcons-retrigger-v7-0-1d86dba83b1c@gmail.com> To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andre Carvalho X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1764188576; l=6537; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=hn/kxg8v9iI6fPhbZcD8Tj+G//s0QmgoWLVA/hu8hV4=; b=Gc3qQzJVfojty4M0sdLaLerlkNhNULg2fnhRj1y77ELw6y2fb0ILQ+09aIEBjf8I7ZIWElEQx 5eOQj2mprGFBHxjLaoA+n/SVCCKN3YRHvhFzWwqac6aJMa6RVdlusEM X-Developer-Key: i=asantostc@gmail.com; a=ed25519; pk=eWre+RwFHCxkiaQrZLsjC67mZ/pZnzSM/f7/+yFXY4Q= Introduce a new netconsole selftest to validate that netconsole is able to resume a deactivated target when the low level interface comes back. The test setups the network using netdevsim, creates a netconsole target and then remove/add netdevsim in order to bring the same interfaces back. Afterwards, the test validates that the target works as expected. Targets are created via cmdline parameters to the module to ensure that we are able to resume targets that were bound by mac and interface name. Reviewed-by: Breno Leitao Signed-off-by: Andre Carvalho --- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 35 ++++++-- .../selftests/drivers/net/netcons_resume.sh | 97 ++++++++++++++++++= ++++ 3 files changed, 128 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/s= elftests/drivers/net/Makefile index f5c71d993750..3eba569b3366 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -19,6 +19,7 @@ TEST_PROGS :=3D \ netcons_cmdline.sh \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ + netcons_resume.sh \ netcons_sysdata.sh \ netcons_torture.sh \ netpoll_basic.py \ diff --git a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh b/to= ols/testing/selftests/drivers/net/lib/sh/lib_netcons.sh index 87f89fd92f8c..239f44d4a45d 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -203,19 +203,21 @@ function do_cleanup() { function cleanup_netcons() { # delete netconsole dynamic reconfiguration # do not fail if the target is already disabled - if [[ ! -d "${NETCONS_PATH}" ]] + local TARGET_PATH=3D${1:-${NETCONS_PATH}} + + if [[ ! -d "${TARGET_PATH}" ]] then # in some cases this is called before netcons path is created return fi - if [[ $(cat "${NETCONS_PATH}"/enabled) !=3D 0 ]] + if [[ $(cat "${TARGET_PATH}"/enabled) !=3D 0 ]] then - echo 0 > "${NETCONS_PATH}"/enabled || true + echo 0 > "${TARGET_PATH}"/enabled || true fi # Remove all the keys that got created during the selftest - find "${NETCONS_PATH}/userdata/" -mindepth 1 -type d -delete + find "${TARGET_PATH}/userdata/" -mindepth 1 -type d -delete # Remove the configfs entry - rmdir "${NETCONS_PATH}" + rmdir "${TARGET_PATH}" } =20 function cleanup() { @@ -377,6 +379,29 @@ function check_netconsole_module() { fi } =20 +function wait_target_state() { + local TARGET=3D${1} + local STATE=3D${2} + local TARGET_PATH=3D"${NETCONS_CONFIGFS}"/"${TARGET}" + local ENABLED=3D0 + + if [ "${STATE}" =3D=3D "enabled" ] + then + ENABLED=3D1 + fi + + if [ ! -d "$TARGET_PATH" ]; then + echo "FAIL: Target does not exist." >&2 + exit "${ksft_fail}" + fi + + local CHECK_CMD=3D"grep \"$ENABLED\" \"$TARGET_PATH/enabled\"" + slowwait 2 sh -c "test -n \"\$($CHECK_CMD)\"" || { + echo "FAIL: ${TARGET} is not ${STATE}." >&2 + exit "${ksft_fail}" + } +} + # A wrapper to translate protocol version to udp version function wait_for_port() { local NAMESPACE=3D${1} diff --git a/tools/testing/selftests/drivers/net/netcons_resume.sh b/tools/= testing/selftests/drivers/net/netcons_resume.sh new file mode 100755 index 000000000000..383ad1149271 --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_resume.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# This test validates that netconsole is able to resume a target that was +# deactivated when its interface was removed when the interface is brought +# back up. +# +# The test configures a netconsole target and then removes netdevsim modul= e to +# cause the interface to disappear. Targets are configured via cmdline to = ensure +# targets bound by interface name and mac address can be resumed. +# The test verifies that the target moved to disabled state before adding +# netdevsim and the interface back. +# +# Finally, the test verifies that the target is re-enabled automatically a= nd +# the message is received on the destination interface. +# +# Author: Andre Carvalho + +set -euo pipefail + +SCRIPTDIR=3D$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh + +modprobe netdevsim 2> /dev/null || true +rmmod netconsole 2> /dev/null || true + +check_netconsole_module + +function cleanup() { + cleanup_netcons "${NETCONS_CONFIGFS}/cmdline0" + do_cleanup + rmmod netconsole +} + +trap cleanup EXIT + +# Run the test twice, with different cmdline parameters +for BINDMODE in "ifname" "mac" +do + echo "Running with bind mode: ${BINDMODE}" >&2 + # Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5) + echo "6 5" > /proc/sys/kernel/printk + + # Create one namespace and two interfaces + set_network + + # Create the command line for netconsole, with the configuration from + # the function above + CMDLINE=3D$(create_cmdline_str "${BINDMODE}") + + # The content of kmsg will be save to the following file + OUTPUT_FILE=3D"/tmp/${TARGET}-${BINDMODE}" + + # Load the module, with the cmdline set + modprobe netconsole "${CMDLINE}" + # Expose cmdline target in configfs + mkdir "${NETCONS_CONFIGFS}/cmdline0" + + # Target should be enabled + wait_target_state "cmdline0" "enabled" + + # Remove low level module + rmmod netdevsim + # Target should be disabled + wait_target_state "cmdline0" "disabled" + + # Add back low level module + modprobe netdevsim + # Recreate namespace and two interfaces + set_network + # Target should be enabled again + wait_target_state "cmdline0" "enabled" + + # Listen for netconsole port inside the namespace and destination + # interface + listen_port_and_save_to "${OUTPUT_FILE}" & + # Wait for socat to start and listen to the port. + wait_local_port_listen "${NAMESPACE}" "${PORT}" udp + # Send the message + echo "${MSG}: ${TARGET}" > /dev/kmsg + # Wait until socat saves the file to disk + busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" + # Make sure the message was received in the dst part + # and exit + validate_msg "${OUTPUT_FILE}" + + # kill socat in case it is still running + pkill_socat + # Cleanup & unload the module + cleanup + + echo "${BINDMODE} : Test passed" >&2 +done + +trap - EXIT +exit "${EXIT_STATUS}" --=20 2.52.0