From nobody Tue Dec 2 02:41:09 2025 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 4117832862F for ; Wed, 19 Nov 2025 07:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538578; cv=none; b=j3VXIULpvUXo6pAtoV7xAv/gV51+pD0KZot9T7p6mkpbSwsCg36sDPe2ByfRvP4jvu6kh7goi/uJgMtJ/8U55K6CEF//BLKnwvTTxtpC/r3RasojB/IDB4C2pqnx9in5qWptKUjB0OJ6bHeoTWRPXSAtdko9SgbpThp66R1BMCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538578; c=relaxed/simple; bh=PJbVIE+FjlqZXAqh81T+nKN+VWQTjy5oRGltePRw6wo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WxtRNJ9n/5ODve67sqe5Y4LeJwcEqDxLbWhaBf/5SaDIJeE6fzUzmGmARTzuv18Asu9RKbdiJZesvESVaHualInmEiiYxRo8Pi8EiCK72i4GkWLEHuWY8S6yTmfPsw9tBbKNwPAPGPLGW4mSnlxuvME4+NCYnO30DIHYYxvggqQ= 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=MsqSWJYs; arc=none smtp.client-ip=209.85.221.43 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="MsqSWJYs" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-42b2e9ac45aso4090416f8f.0 for ; Tue, 18 Nov 2025 23:49:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763538574; x=1764143374; 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=3YO8hwlO2C7MvqjPC6EcWcIdUphHn/vVfWOEg+rLhE4=; b=MsqSWJYskP0psn59XxmZ7fbHIW18kVKs1jBUIh+Wglqztw0m9QzkjtBpd8N93QsYgx BCXkaoLOhjF9juCJIxnd515DCycvvSBitnDk6Ns2jhk5MwxjGDxQjmhQ4xWRHB82iNvf DdFtcfIOSfch8bTCNigj314SR/XuUXV4i7HA3cT25uiFWa92f/nqG7mpyXRtrBRQKlhO 3tA7QQRee04pfm38e4LseCuEZL7Dl24HR0b9yMZ05g6caqOEUnSBjySdlvaKUUhsf+C9 Ob6R1PZNK3eS+k5TptdZ+x5djKteG6tPnJVg/F+Gwq4lH7z+OUlheo6KCmW/1eOAa0d4 DtOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763538574; x=1764143374; 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=3YO8hwlO2C7MvqjPC6EcWcIdUphHn/vVfWOEg+rLhE4=; b=FLf5DnWUpeYsmRFsog/SH7VjFJdAd4e07FfwVXZ7ecAqFwkYqbdwhCsdwmhiQHhofa vPqWLTzjTolGaGuE/G2VKrbstort/XfdF8pLlF+G4HbStC3J5RXJ5xRX1TYq66rHxR++ dplP3H5Yr4gWQo7rc4RYNHs0jPYzomp+XP9hm/DhaXuvyrA8LyW/MJXBecBg5l9PFvkT ap4ChFKyUr37wctmEdK+NJYZAN85hHqKo32iR8gSHKAeVxr5bIA/yi5O7tdoD7ojiRtC HAVXrMxAzGGtisgV8YL5FkclEAk/aj2UaDY4eyk7AAK18P76d9LlUyGK2TPj8BLyMnHg SHaA== X-Forwarded-Encrypted: i=1; AJvYcCXIafbhUPg0dlfHCqip74SZM7mQa06oI8DvCpr8p7ssWcNRA6kmTpP7oaNtJdpXqq+ibfpMI1ZniQPo5hY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4K1G2SC8kPWS5dNgKIubZN8vI5lZPq4wEuY/eLznuz+4ckmEg +/oTiD5m2zOz+SAbyEAp8SI4sPgrERwAQ5fgB0dizIcwp0jDOWr6Uon/ X-Gm-Gg: ASbGnctnJYWZtKgC81B2x8fF5nraOxngttAYi49FI064/4DyRU2ammibmoUxXjM/QUS rbA9NJKbHwy//0+pSWRI9VhAszgQ6LQmaLI1xlcqJK7CKC2HzhCCJIK/+/Gmrp0sdguQ+mwqnPD UZTh7G6ov9f9R7dPzJu/4XLSLUqDS0D/N9sVUTWupAph9QiODteGK58klqLk3jeBGC9n1zQp/VH 9Hns3qCJQ5DiHqmdWO9bHXx4TDtnHvFAEoxksc7qiyctqFqXWBIrBsUENeBdlOsc6FjZbHHk+lr mA5ybqwvATJqlULwHBwD812GQFglFYoYIUfMXCXvDP8gofAWT0WP23IWmzm6UeP3uEKuvbTMpcm t5Pkkvq1enmM6jwuP6k4ert6ri1ug+//mvWYavrNnWRPg3qegp2cZpvW+aqNa4ul0B5p5ve09xq 5W/rdZIV5gwER6N/gSHBwHTdhELyhXVsJyQmS9 X-Google-Smtp-Source: AGHT+IGPDf3n7yw9tmvx3mRMsXmrPnlbEY7oesz8TUWhArbu2lVE770zOvsQLkEdWQLuDspCZ91xzQ== X-Received: by 2002:a5d:64e3:0:b0:42b:3592:1b92 with SMTP id ffacd0b85a97d-42b59398992mr19426502f8f.47.1763538574344; Tue, 18 Nov 2025 23:49:34 -0800 (PST) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e91f2dsm37461146f8f.19.2025.11.18.23.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 23:49:33 -0800 (PST) From: Andre Carvalho Date: Wed, 19 Nov 2025 07:49:23 +0000 Subject: [PATCH net-next v5 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: <20251119-netcons-retrigger-v5-5-2c7dda6055d6@gmail.com> References: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@gmail.com> In-Reply-To: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@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=1763538567; l=6488; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=PJbVIE+FjlqZXAqh81T+nKN+VWQTjy5oRGltePRw6wo=; b=3e3WCZ8bN9e7l+IkkBwVS0veQgRbSFvgvYDsAXZseHDhoWoDryCb6ea8Xq+nxulgDN1iEOtph 8lttF8bxPr8AEN3OkDmGiY36oKaAFTA97/R4KcvPMGszKou6zzbKryw 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. Signed-off-by: Andre Carvalho Reviewed-by: Breno Leitao --- 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 33f4816216ec..7dc9e5b23d5b 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -17,6 +17,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..b9f2d5a7dc59 --- /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 "${ksft_pass}" --=20 2.52.0