From patchwork Thu Aug 1 16:11:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13750703 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 900A61B372C; Thu, 1 Aug 2024 16:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528835; cv=none; b=ix5dwsQWtouYddg1wPKQuJFWocoyuMgjLpA1r6VoQnm/Osi5krZ082uiXudXm3MKocZborqrHBCT+xWN9ge8CXmNSzyt4NrjCjch1FJZA+mQYJHassAndiVDyp/PVMXHGQsCNy79LU9XlAy3/fY8C5uVMqTdsAa2SSKgiWV7QVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528835; c=relaxed/simple; bh=zS9pPlHOmO0BZ7xmcFWzDSiTDOZYmnzfdggcHye1Fn4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GluhVOYcbwSktBzmsiFu97kWmviX3M9iOVWPgB7eA/xTsavYN0qDysEdmRlSY3hJBKwwMs4pZ74m2UTAO+/rA2QrYrA3d6jzii1hc1ge3Io9qxca81bvyDGyEGDSIN42JLKJcQiIW+S1gsS9+qCMjqHJDWO5i2tRnK7ATwxRV30= 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.45 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-f45.google.com with SMTP id a640c23a62f3a-a7ab5fc975dso651863266b.1; Thu, 01 Aug 2024 09:13:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722528832; x=1723133632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5/RdmcqVIP5R/Ggm/1sHWuedrazo6kwvVFmS0MKY894=; b=De0rtEmbDYvER43Ki+HOQJbPU6Bm1tvYUGJbZI/n6fXwyg9+I4EY01gdhHZ/tKc5Xl wECfRysMdWzBy0VbGgxicdZ5FFX0+NEulxa9syzQvbXd1rtcx+64FMy+A5BIGWAnTRPy tDAlwGF5fJkDwHrRJFyumSe9KV8wnt50iMg6siBqesZ3q89qk2lYOI+LHj9qHcrLbMpP VAjP8GFyFevUQakfpKiZ5t6wTEO23X3DiVOOwikk1Sk2ZHztbOS9eqOu5kKB/IQ7b4Ym IUHlVmhJaVWKwNmO/ttAPUS8lCufs7bE3EKATn9hZTIuVuU/Fp8/0UIKrnSFHjA2x12K N8lA== X-Forwarded-Encrypted: i=1; AJvYcCXZj4d/ZYswejlLIdt7k4wYIJJ9Fjfea47ukSZPNLs61UWEcBVSXJAkiIuLUzgV522X09QTWIzAPIY7CCcC73PsYWaovJdciYeFWk6oerf1NTQyTG8rIaUM+NwmPDjIRjeTSehKrEvReSul2FrAsKzMoFMVTqX+kTO/6wiHQUgWszl8Ix1f X-Gm-Message-State: AOJu0Yz/zw4oh1sdAoHNRwujC2Ir3oB23xwd3X7ohecRkt0rHkRuJy0I oGgXCG41ewPgfMZiivsoxi03Abg6OuOyfzew0WgEoSpdOHUxTRhw X-Google-Smtp-Source: AGHT+IG/AFrPnvzzN/amAsAUv4ipt+ECA8EtiB7HwaDCZ+4l9+dJ1jQQevf/LknK3BxjRYbQ7q3D+A== X-Received: by 2002:a17:907:934a:b0:a7a:a5ed:43d0 with SMTP id a640c23a62f3a-a7dc5071046mr55940666b.47.1722528831525; Thu, 01 Aug 2024 09:13:51 -0700 (PDT) Received: from localhost (fwdproxy-lla-005.fbsv.net. [2a03:2880:30ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acac61218sm923403266b.94.2024.08.01.09.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 09:13:51 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, Shuah Khan Cc: thevlad@fb.com, thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk, linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK) Subject: [PATCH net-next 1/6] net: netconsole: selftests: Create a new netconsole selftest Date: Thu, 1 Aug 2024 09:11:58 -0700 Message-ID: <20240801161213.2707132-2-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801161213.2707132-1-leitao@debian.org> References: <20240801161213.2707132-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Adds a selftest that creates two virtual interfaces, assigns one to a new namespace, and assigns IP addresses to both. It listens on the destination interface using netcat and configures a dynamic target on netconsole, pointing to the destination IP address. The test then checks if the message was received properly on the destination interface. Signed-off-by: Breno Leitao --- MAINTAINERS | 1 + .../net/netconsole/basic_integration_test.sh | 153 ++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100755 tools/testing/selftests/net/netconsole/basic_integration_test.sh diff --git a/MAINTAINERS b/MAINTAINERS index c0a3d9e93689..59207365c9f5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15768,6 +15768,7 @@ M: Breno Leitao S: Maintained F: Documentation/networking/netconsole.rst F: drivers/net/netconsole.c +F: tools/testing/selftests/net/netconsole/ NETDEVSIM M: Jakub Kicinski diff --git a/tools/testing/selftests/net/netconsole/basic_integration_test.sh b/tools/testing/selftests/net/netconsole/basic_integration_test.sh new file mode 100755 index 000000000000..fbabbc633451 --- /dev/null +++ b/tools/testing/selftests/net/netconsole/basic_integration_test.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# This test creates two virtual interfaces, assigns one of them (the "destination +# interface") to a new namespace, and assigns IP addresses to both interfaces. +# +# It listens on the destination interface using netcat (nc) and configures a +# dynamic target on netconsole, pointing to the destination IP address. +# +# Finally, it checks whether the message was received properly on the +# destination interface. Note that this test may pollute the kernel log buffer +# (dmesg) and relies on dynamic configuration and namespaces being configured." +# +# Author: Breno Leitao + +SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +# Simple script to test dynamic targets in netconsole +SRCIF="veth0" +SRCIP=192.168.1.1 + +DSTIF="veth1" +DSTIP=192.168.1.2 + +PORT="6666" +MSG="netconsole selftest" +TARGET=$(mktemp -u netcons_XXXXX) +NETCONS_CONFIGFS="/sys/kernel/config/netconsole" +FULLPATH="${NETCONS_CONFIGFS}"/"${TARGET}" +# This will be have some tmp values appened to it in set_network() +NAMESPACE="netconsns" + +# Used to create and delete namespaces +source "${SCRIPTDIR}"/../lib.sh + +function set_network() { + # this is coming from lib.sh + setup_ns "${NAMESPACE}" + NAMESPACE=${NS_LIST[0]} + ip link add "${SRCIF}" type veth peer name "${DSTIF}" + + # "${DSTIF}" + ip link set "${DSTIF}" netns "${NAMESPACE}" + ip netns exec "${NAMESPACE}" ip addr add "${DSTIP}"/24 dev "${DSTIF}" + ip netns exec "${NAMESPACE}" ip link set "${DSTIF}" up + + # later, configure "${SRCIF}" + ip addr add "${SRCIP}"/24 dev "${SRCIF}" + ip link set "${SRCIF}" up +} + +function create_dynamic_target() { + DSTMAC=$(ip netns exec "${NAMESPACE}" ip link show "${DSTIF}" | awk '/ether/ {print $2}') + + # Create a dynamic target + mkdir ${FULLPATH} + + echo ${DSTIP} > ${FULLPATH}/remote_ip + echo ${SRCIP} > ${FULLPATH}/local_ip + echo ${DSTMAC} > ${FULLPATH}/remote_mac + echo "${SRCIF}" > ${FULLPATH}/dev_name + + echo 1 > ${FULLPATH}/enabled +} + +function cleanup() { + echo 0 > "${FULLPATH}"/enabled + rmdir "${FULLPATH}" + # This will delete DSTIF also + ip link del "${SRCIF}" + # this is coming from lib.sh + cleanup_all_ns +} + +function listen_port() { + OUTPUT=${1} + echo "Saving content in ${OUTPUT}" + timeout 2 ip netns exec "${NAMESPACE}" nc -u -l "${PORT}" | sed '/^$/q' > ${OUTPUT} +} + +function validate_result() { + TMPFILENAME=/tmp/"${TARGET}" + + # sleep until the file isc reated + sleep 1 + # Check if the file exists + if [ ! -f "$TMPFILENAME" ]; then + echo "FAIL: File was not generate." >&2 + return ${ksft_fail} + fi + + if ! grep -q "${MSG}" "${TMPFILENAME}"; then + echo "FAIL: ${MSG} not found in ${TMPFILENAME}" >&2 + cat ${TMPFILENAME} >&2 + return ${ksft_fail} + fi + + rm ${TMPFILENAME} + return ${ksft_pass} +} + +function check_for_dependencies() { + if [ "$(id -u)" -ne 0 ]; then + echo "This script must be run as root" >&2 + exit 1 + fi + + if ! which nc > /dev/null ; then + echo "SKIP: nc(1) is not available" >&2 + exit ${ksft_skip} + fi + + if ! which ip > /dev/null ; then + echo "SKIP: ip(1) is not available" >&2 + exit ${ksft_skip} + fi + + if [ ! -d "${NETCONS_CONFIGFS}" ]; then + echo "SKIP: directory ${NETCONS_CONFIGFS} does not exist. Check if NETCONSOLE_DYNAMIC is enabled" >&2 + exit ${ksft_skip} + fi + + if ip link show veth0 2> /dev/null; then + echo "SKIP: interface veth0 exists in the system. Not overwriting it." + exit ${ksft_skip} + fi +} + +# ========== # +# Start here # +# ========== # + +# Check for basic system dependency and exit if not found +check_for_dependencies +# Create one namespace and two interfaces +set_network +# Create a dynamic target for netconsole +create_dynamic_target +# Listed for netconsole port inside the namespace and destination interface +listen_port /tmp/"${TARGET}" & +# Wait for nc to start and listen to the port. +sleep 1 + +# Send the message +echo "${MSG}: ${TARGET}" > /dev/kmsg + +# Make sure the message was received in the dst part +validate_result +ret=$? +# Remove the namespace, interfaces and netconsole target +cleanup + +exit ${ret} From patchwork Thu Aug 1 16:11:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13750704 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 231E01B4C23; Thu, 1 Aug 2024 16:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528842; cv=none; b=bUNGektzgYYmAdhQ3uJ1kb2CJAltVnYmS7cUo0pPG0TdlnVl3ZdeA7lnhAM6y42OecHIYz8rbGZiOcrMIUyWTYHGKdv0PakBiRfjV/WlcAbYpcZ/PmzT3Xh4WMCfrgOFEThlGmcaX9jBdRs/VtvKOG4D+5auoRhtj1rU9NxT17Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528842; c=relaxed/simple; bh=uC2BmUxRWsf0KsVLb+yZ2Q6rogj5W1+emqWqRBzGCbI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pPcilvnnWCkm0dX4Z5hgIMjqZlgoXiVZjDZSyQ6IDP6S9H3Cib09Zn1bo3t1KC1tdEIKUTI1hpS7le/Cg4+P3XUwnSXoHPBr3H5A7nNChf7/Elh4PtGThx55YcCHAM7PAVhHktcb9rKiWga+nznroXQkcfmKVYKt53rbtZ5mcgk= 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.50 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-f50.google.com with SMTP id a640c23a62f3a-a7ad02501c3so24674366b.2; Thu, 01 Aug 2024 09:13:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722528837; x=1723133637; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HjhvO/EBhB/Q0GYaqqTWtDrqTWX0pPfpEEQqm+7VbP8=; b=sTsl/yFS3Qo0gI7uSEAdjnD8IV9rqcrIlX2mkG2bavTD61SJA+1OLYqqZZrAzKbuwm +jwB+A6Tjv+ZDiMU839nJJBT3IpSoKzLQnLQ8s5zDx6PtSMw84HpqHpkc+y5Y2LPJKua ekENzlXawJwoosSGTU4QAFT2vgpcKHwM4rubutkN8FcRZF0OyC5oxotWwLGER3zbwAUG EFNFt9Mwts8jmjuSwYn7S0MEONPY/d7q+kuqrlk+6T9/lFOGe+nr3ZphQ78Nigv5hSGQ AHRCByLuRbK8b0QNKq7nUn004wAgDNcYoDy5O+SxgBgon05Lvr9DPnShVJcAy4XcWBgQ UmQQ== X-Forwarded-Encrypted: i=1; AJvYcCWGm2v8J5XZD/MQd2ZYN5yhc1JUl3DPRDJUH+H2+QevKz8p5NwJqHqlvzDUoECaTccKwIVAFyFvjWppdLf/euNADvNbEJYTIg60DFSdcl121MH6agZhuZADzaB6CGsrLu81+NOc X-Gm-Message-State: AOJu0Yy6ZHG3Rmik8pDOkFJDJ+qiifNzDgE0b539WFPsAo2+lz+09dKm fPhLhFcnrvd68k2a9QlZ0fb87oJCy2lOGSdjJWu93OEClbnvFqCv X-Google-Smtp-Source: AGHT+IHayzcwog/gmPGLzBe0jVWIZGeY2SV8QM4SSOAok68Ua4v9QWwxo6FmbcadS72hKK5/M8z6ig== X-Received: by 2002:a17:907:9689:b0:a7a:b839:8583 with SMTP id a640c23a62f3a-a7dc51c26e5mr45068366b.66.1722528836923; Thu, 01 Aug 2024 09:13:56 -0700 (PDT) Received: from localhost (fwdproxy-lla-003.fbsv.net. [2a03:2880:30ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acab4de90sm913734866b.62.2024.08.01.09.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 09:13:56 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next 2/6] net: netpoll: extract core of netpoll_cleanup Date: Thu, 1 Aug 2024 09:11:59 -0700 Message-ID: <20240801161213.2707132-3-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801161213.2707132-1-leitao@debian.org> References: <20240801161213.2707132-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Extract the core part of netpoll_cleanup(), so, it could be called from a caller that has the rtnl lock already. Netconsole uses this in a weird way right now: __netpoll_cleanup(&nt->np); spin_lock_irqsave(&target_list_lock, flags); netdev_put(nt->np.dev, &nt->np.dev_tracker); nt->np.dev = NULL; nt->enabled = false; This will be replaced by do_netpoll_cleanup() as the locking situation is overhauled. Signed-off-by: Breno Leitao Reviewed-by: Rik van Riel --- include/linux/netpoll.h | 1 + net/core/netpoll.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index bd19c4b91e31..cd4e28db0cbd 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -64,6 +64,7 @@ int netpoll_setup(struct netpoll *np); void __netpoll_cleanup(struct netpoll *np); void __netpoll_free(struct netpoll *np); void netpoll_cleanup(struct netpoll *np); +void do_netpoll_cleanup(struct netpoll *np); netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb); #ifdef CONFIG_NETPOLL diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 55bcacf67df3..a58ea724790c 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -853,14 +853,20 @@ void __netpoll_free(struct netpoll *np) } EXPORT_SYMBOL_GPL(__netpoll_free); +void do_netpoll_cleanup(struct netpoll *np) +{ + __netpoll_cleanup(np); + netdev_put(np->dev, &np->dev_tracker); + np->dev = NULL; +} +EXPORT_SYMBOL(do_netpoll_cleanup); + void netpoll_cleanup(struct netpoll *np) { rtnl_lock(); if (!np->dev) goto out; - __netpoll_cleanup(np); - netdev_put(np->dev, &np->dev_tracker); - np->dev = NULL; + do_netpoll_cleanup(np); out: rtnl_unlock(); } From patchwork Thu Aug 1 16:12:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13750705 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 F2CEC13B79F; Thu, 1 Aug 2024 16:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528842; cv=none; b=pkDQXnt3bsqa12MKw6Wdi6Hc/832FtbPRnD0yRzeBqs7pyOhIRJ6BNVBoUmefriecgdYVcqNlJGwEnMpsG7yVndmPQhdrF8bT3ZaIHwH1vqmTcD1MIg9pxQN2YuB2v4do9G9gbn9d7OI2bp1iQ3ENdxni3gq/1t5pvABDKCgn2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528842; c=relaxed/simple; bh=mMQmVObRVBuWpAB2ikI7wWAApPb3vfqPeQMvLpJnzME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bAFKRF7not90wGlj63y7GhoAPtdJxSJdT7pBuWsxK0n2+ZfkjLuoPRdE6KH+Fe2a51MpagaMLlkOU4O+/cfOSxctZczBUcpXxrZcdmodRKOFX7sPNVukZYa7+/P2o51NcdTErUvT6aLO/KpOHXXIGJ9Tp1PjEcbCfdyFieR4ZHY= 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.167.44 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-lf1-f44.google.com with SMTP id 2adb3069b0e04-52efd855adbso10304044e87.2; Thu, 01 Aug 2024 09:14:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722528839; x=1723133639; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zWWsP5Srxsq1NtqWc5nLvTQoERQAcCDYt/rgvLjpdoU=; b=EMuby2MHBU9FfykT/XnE6mTJn/sPxb+LTHxBckWxld5yDrrPBRde1JWIzM91NA1kDr 78syiDVzm3gvW95R2P9wrExje5bvc/tl5l5pHLxN/7LJIoKldwxp4evPTF2xgZ2x3V3o WdUtjvB2WjUisAPns3c0pTesFnzWtEccvEsuhqTXUeEt3/MjziLC3wb3QjxxaKfRpLNO CTvqrBjr+DeV/JVD8f2s1X8SoLz3uzuic/z01i6aaf68a6F/x4qBJhwtmKUjNQ3FBXJ/ +A8/VbdsEML5k1h8JxeQ4QFoYn1UUs06hVF4dc1pjEhe+3FKj67gHtySaAXsRiAqw2CR vgbA== X-Forwarded-Encrypted: i=1; AJvYcCUPswcZKYV+SQIw6KYx1JYSZcUpU9nM/R9CpYGjSMD0h2WyPmQtt9o+huRxShjZfVGFT7BtWE0Ka3lH7HX0TJbm47puOmVTNxjHHMDTn6s7xrpzvqzL4L2gtHmEfCYoTXtrbtRo X-Gm-Message-State: AOJu0YwGeP8Ii9fUdo5skWaJIzpLU4z8kSIOBR9hqckq9jGIbx3w6H+0 z3iYz3iu4cr0MEqjYWjPSplsdeLyxeL8qfgKbIr4S58NB7gL3+gr X-Google-Smtp-Source: AGHT+IHQ/aEe586XoVR7BG8EBKnNuvXVAIXWefDS4eDr0W1uHCxZ0ZiGCnuuUF3kX0aKcKj7FY3kBA== X-Received: by 2002:a05:6512:3c82:b0:52f:d090:6da6 with SMTP id 2adb3069b0e04-530bb3b47b0mr306256e87.55.1722528838631; Thu, 01 Aug 2024 09:13:58 -0700 (PDT) Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acab535a6sm912583966b.88.2024.08.01.09.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 09:13:58 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next 3/6] net: netconsole: Correct mismatched return types Date: Thu, 1 Aug 2024 09:12:00 -0700 Message-ID: <20240801161213.2707132-4-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801161213.2707132-1-leitao@debian.org> References: <20240801161213.2707132-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org netconsole incorrectly mixes int and ssize_t types by using int for return variables in functions that should return ssize_t. This is fixed by updating the return variables to the appropriate ssize_t type, ensuring consistency across the function definitions. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 9c09293b5258..c0ad4df7252f 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -336,7 +336,7 @@ static ssize_t enabled_store(struct config_item *item, struct netconsole_target *nt = to_target(item); unsigned long flags; bool enabled; - int err; + ssize_t err; mutex_lock(&dynamic_netconsole_mutex); err = kstrtobool(buf, &enabled); @@ -394,7 +394,7 @@ static ssize_t release_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); bool release; - int err; + ssize_t err; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -422,7 +422,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); bool extended; - int err; + ssize_t err; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -469,7 +469,7 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - int rv = -EINVAL; + ssize_t rv = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -492,7 +492,7 @@ static ssize_t remote_port_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - int rv = -EINVAL; + ssize_t rv = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -685,7 +685,7 @@ static ssize_t userdatum_value_store(struct config_item *item, const char *buf, struct userdatum *udm = to_userdatum(item); struct netconsole_target *nt; struct userdata *ud; - int ret; + ssize_t ret; if (count > MAX_USERDATA_VALUE_LENGTH) return -EMSGSIZE; From patchwork Thu Aug 1 16:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13750706 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 3C8D21B372C; Thu, 1 Aug 2024 16:14:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528844; cv=none; b=DLIfTsMKEIIY9pyW6BlCNZSPyfeyLDC/IRa+DIQ9WqXu4J5hPCnxhLwVZjpCp6qnvIH3NddxwN0wUgh272ifwUmSTi9jdEwvDVaNzTNU1V8G8L+PqeK0jMknbuOrKYRgN9h5WaGZAo45C3o6UGHUXZdauVR5VO/Ad1gNcMj3wfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528844; c=relaxed/simple; bh=84aBcW6YN3OxvL2Ztisz9NzO1eT9ywLCh52C6F9Glzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iGikwbxu1AugRTNtp22XH0ESh3QiwOqhx7GtBSM3RZA2g9lUr6I/bCkOvwZCYqLLNV8NG2FFl0gmaFteKuQOGnJM8Ciw+NMnheGZrK6R7Khf/KuYh5bc+DZ4k0ihDz9EPGZ6o9m0TaavqbYJ+tnvxYxkiwrhznXQHelnbZaTWhY= 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.208.47 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-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5a156557029so11376362a12.2; Thu, 01 Aug 2024 09:14:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722528840; x=1723133640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0WTGjpF8ofP7Y59hp4oDRQu/iNhPQ69qU6RnSz0WlhE=; b=hW6E6E6iUaRMi8DtGFZZ6+nL4yJNlDxmD8XyuxtBSzh0OzGsiCI9mmxRrTsTDDWY4+ 0u4PO6SfkHSKZWVHt6ftKnU3w28hIB1StWidP+08+G5T+wxBEdAwSxpTl+oweryBFwb7 Bqvtf6+Uw2DmeQ+Eti60/GRT1sG/H1Gycw4WickowRUyuANGtKTsQurPLys7u1rkJL7q 27/aPb5kn9dFMVpheTlLPwIQUTHVsnZI5a68IvdofE9Oey89PDy0+EJzaA8MmARoYcmp T7EMzGQcBW6hAQDiw7kStHXHWCh12NiR3joYL0Q7+472qD87UI3q/l4vQZnhFApjBR+i JbIw== X-Forwarded-Encrypted: i=1; AJvYcCXc5j1ib4DAJX3gUdqFINun21zz+0iLoL2qKq5y7kJYdp7X5wHW/bxoEsCiiqp8gN3ZsJJYzjpJCpnZRk/iZVZpV/m4rCT30wmrfbsqMomVFfGDzUXQ/YaT1vISXsSjjVMPd7lm X-Gm-Message-State: AOJu0Yz0DENAWGT4som7OBYfxdc39Glc+eF34EbjYyAgAfp6P6IelDx0 Ml+d6B206aCd4LkvoPu4arhsdEsEYKUJEo8icUySd1YJTWhYtd8/ X-Google-Smtp-Source: AGHT+IHU91OsjH2erTD293Q7SRKJBwpK0junrFqS8LnZVGUawYDxdO4xK+cBfMHsQOUkwR/6Y8SYwA== X-Received: by 2002:a17:907:1c0f:b0:a72:8a62:65e7 with SMTP id a640c23a62f3a-a7dc51042c1mr64835866b.57.1722528840433; Thu, 01 Aug 2024 09:14:00 -0700 (PDT) Received: from localhost (fwdproxy-lla-002.fbsv.net. [2a03:2880:30ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb8356sm911164666b.206.2024.08.01.09.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 09:14:00 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next 4/6] net: netconsole: Standardize variable naming Date: Thu, 1 Aug 2024 09:12:01 -0700 Message-ID: <20240801161213.2707132-5-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801161213.2707132-1-leitao@debian.org> References: <20240801161213.2707132-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Update variable names from err to ret in cases where the variable may return non-error values. This change facilitates a forthcoming patch that relies on ret being used consistently to handle return values, regardless of whether they indicate an error or not. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index c0ad4df7252f..0980a61f8775 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -336,14 +336,14 @@ static ssize_t enabled_store(struct config_item *item, struct netconsole_target *nt = to_target(item); unsigned long flags; bool enabled; - ssize_t err; + ssize_t ret; mutex_lock(&dynamic_netconsole_mutex); - err = kstrtobool(buf, &enabled); - if (err) + ret = kstrtobool(buf, &enabled); + if (ret) goto out_unlock; - err = -EINVAL; + ret = -EINVAL; if (enabled == nt->enabled) { pr_info("network logging has already %s\n", nt->enabled ? "started" : "stopped"); @@ -365,8 +365,8 @@ static ssize_t enabled_store(struct config_item *item, */ netpoll_print_options(&nt->np); - err = netpoll_setup(&nt->np); - if (err) + ret = netpoll_setup(&nt->np); + if (ret) goto out_unlock; nt->enabled = true; @@ -386,7 +386,7 @@ static ssize_t enabled_store(struct config_item *item, return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return err; + return ret; } static ssize_t release_store(struct config_item *item, const char *buf, @@ -394,18 +394,18 @@ static ssize_t release_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); bool release; - ssize_t err; + ssize_t ret; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); - err = -EINVAL; + ret = -EINVAL; goto out_unlock; } - err = kstrtobool(buf, &release); - if (err) + ret = kstrtobool(buf, &release); + if (ret) goto out_unlock; nt->release = release; @@ -414,7 +414,7 @@ static ssize_t release_store(struct config_item *item, const char *buf, return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return err; + return ret; } static ssize_t extended_store(struct config_item *item, const char *buf, @@ -422,18 +422,18 @@ static ssize_t extended_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); bool extended; - ssize_t err; + ssize_t ret; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); - err = -EINVAL; + ret = -EINVAL; goto out_unlock; } - err = kstrtobool(buf, &extended); - if (err) + ret = kstrtobool(buf, &extended); + if (ret) goto out_unlock; nt->extended = extended; @@ -442,7 +442,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf, return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return err; + return ret; } static ssize_t dev_name_store(struct config_item *item, const char *buf, @@ -469,7 +469,7 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - ssize_t rv = -EINVAL; + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -478,21 +478,21 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, goto out_unlock; } - rv = kstrtou16(buf, 10, &nt->np.local_port); - if (rv < 0) + ret = kstrtou16(buf, 10, &nt->np.local_port); + if (ret < 0) goto out_unlock; mutex_unlock(&dynamic_netconsole_mutex); return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return rv; + return ret; } static ssize_t remote_port_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - ssize_t rv = -EINVAL; + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -501,14 +501,14 @@ static ssize_t remote_port_store(struct config_item *item, goto out_unlock; } - rv = kstrtou16(buf, 10, &nt->np.remote_port); - if (rv < 0) + ret = kstrtou16(buf, 10, &nt->np.remote_port); + if (ret < 0) goto out_unlock; mutex_unlock(&dynamic_netconsole_mutex); return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return rv; + return ret; } static ssize_t local_ip_store(struct config_item *item, const char *buf, From patchwork Thu Aug 1 16:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13750707 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 178F61BA86A; Thu, 1 Aug 2024 16:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528845; cv=none; b=WWlseJ2LU0Tg+s+Yqkyy4aUuiM9w2KovDzIEDL27i8B1MPJEAz5YbZtPowF73MzwPoqXhtocbnawhFoBIGnAmwz7c3jnokdep2Zdv9c8YvfBgX5uLcUsj+lPNEMu115cmphiVMWnHchC5WOz7B9vqvvuOa1OSmrIrEtnmfKf9u4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528845; c=relaxed/simple; bh=aH1yEwSC01qNb2na4yUR3FpstcU83pdCY8kuWMCDHhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mILODu2Bje0Lz2dIwu0HY+W/Rk92AAKnhUu64paqZgYOoS32/s/FovvG/1vk+xr8wB6KSJQJ6am/6uG8CvxplIGFHPC40cCWBo73ufKANY4zhbb+5UpbtWJS678kXXiHyhIedkNmjIBHqUpOEHnG8lDYFDSWaSiY5+xbTRhqfV0= 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.208.44 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-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5a15692b6f6so10833230a12.0; Thu, 01 Aug 2024 09:14:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722528842; x=1723133642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mW/DNu7o3BWO/l2Alah7sarSMSV5UbORK3y1TxW0QAs=; b=LYNIl2LdjIq1g20jWJOcc+RvG5RObZMkFlOiCO3DTJ5O+QYQ6f2P918OpQugrDK7LU iF6+/08WkJxBf4+GSsnJMxpjQiYx1pGFBXWyJMpvqmp6Eq/wCTbKCfIaGcqZZO8TIMj6 dFb+7K5V7yB6zp1MSrg6jvkxw8WCtIoJS8GjYEkjHkHNOIpzn3TdRp7byfRKY+r/8JSM KkU7nk/U7XbHGjsmdgQRQ0khKKqy/EpR/7plqmk+VdnQMUY8/CVvQu+sDAy8YARaRA0q /9LIWBY0rm5xDioav+XtGfgOrwUHyv8a1kmuH7S9a5NRiWe1ZmemqdUwJB/Q9WLnFUtc czAQ== X-Forwarded-Encrypted: i=1; AJvYcCXFwCRo9OK4yiNJ0VvNnGVTlDcNkEaGKCEp372Z8aL28oV98qEdIgrkG6FYD3Wtabip9dzJLLiq+kfBWWwigSOxKK8aPC0NAmWFz6lMjMScR2ZCVfcR37PP1XB2Nf2K49TFmiNa X-Gm-Message-State: AOJu0YxJy+PiC38m63dvZrVb0h/2ILxEbg5Yt3Vrq48CXR3SEmPlmWzI eLwy/EmtD2d/drzVaRfiEehfP4De9l44WS4ALU4cOhwu+MwO8p0g X-Google-Smtp-Source: AGHT+IFmvS5csQdGU6mRHJKFsi6PI0N5TyaCieoOJxkkJIMlgbz2xRxKaOLoRY804k4r/7USdh7i+g== X-Received: by 2002:aa7:c994:0:b0:5a2:69f9:1fe7 with SMTP id 4fb4d7f45d1cf-5b7f5dc1552mr613392a12.35.1722528842155; Thu, 01 Aug 2024 09:14:02 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac64eb318dsm10410138a12.68.2024.08.01.09.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 09:14:01 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next 5/6] net: netconsole: Unify Function Return Paths Date: Thu, 1 Aug 2024 09:12:02 -0700 Message-ID: <20240801161213.2707132-6-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801161213.2707132-1-leitao@debian.org> References: <20240801161213.2707132-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The return flow in netconsole's dynamic functions is currently inconsistent. This patch aims to streamline and standardize the process by ensuring that the mutex is unlocked before returning the ret value. Additionally, this update includes a minor functional change where certain strnlen() operations are performed with the dynamic_netconsole_mutex locked. This adjustment is not anticipated to cause any issues, however, it is crucial to document this change for clarity. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 0980a61f8775..eb9799edb95b 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -382,8 +382,7 @@ static ssize_t enabled_store(struct config_item *item, netpoll_cleanup(&nt->np); } - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -410,8 +409,7 @@ static ssize_t release_store(struct config_item *item, const char *buf, nt->release = release; - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -437,9 +435,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf, goto out_unlock; nt->extended = extended; - - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -481,8 +477,7 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, ret = kstrtou16(buf, 10, &nt->np.local_port); if (ret < 0) goto out_unlock; - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -504,8 +499,7 @@ static ssize_t remote_port_store(struct config_item *item, ret = kstrtou16(buf, 10, &nt->np.remote_port); if (ret < 0) goto out_unlock; - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -515,6 +509,7 @@ static ssize_t local_ip_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -541,17 +536,17 @@ static ssize_t local_ip_store(struct config_item *item, const char *buf, goto out_unlock; } - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return -EINVAL; + return ret; } static ssize_t remote_ip_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -578,11 +573,10 @@ static ssize_t remote_ip_store(struct config_item *item, const char *buf, goto out_unlock; } - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return -EINVAL; + return ret; } static ssize_t remote_mac_store(struct config_item *item, const char *buf, @@ -590,6 +584,7 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); u8 remote_mac[ETH_ALEN]; + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -604,11 +599,10 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf, goto out_unlock; memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN); - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return -EINVAL; + return ret; } struct userdatum { @@ -700,9 +694,7 @@ static ssize_t userdatum_value_store(struct config_item *item, const char *buf, ud = to_userdata(item->ci_parent); nt = userdata_to_target(ud); update_userdata(nt); - - mutex_unlock(&dynamic_netconsole_mutex); - return count; + ret = count; out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; From patchwork Thu Aug 1 16:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13750708 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 D86D51BA89F; Thu, 1 Aug 2024 16:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528851; cv=none; b=ELcA2ifPWUhpY27B5SlrhHnnXshVzEgfcjQ0+5kD69vDdUQnkPgZVMcTgiyB5AoQScnsisb0NMNr78SP6m1ZY0dJhKlMJlgeK6ktbA/l+wcs319n/XyImUlMR5xngvJs9jlXhonsOwe6z8uoWhNfoJRTr0xxHMB9OFNlQPDnBpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722528851; c=relaxed/simple; bh=7e3efhcv9TBwyQynz9QMmq8QAaAjHIGnXvuyE+brDnw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TM1xgYNCX5H8FT5wgzxzXKOPLWe1EEcFuvc/occaeFAPya/QwGn+uSaMKfURwm8Ml8fjNXMkbX4RxmMvC825aorkgjEK3aBo05neKLpy+8xI32jKATmDZHquGm1EdYqiU8AdnHN8tDlnrc0Bsz5BiKGo6io21LwN6Bm7TYKdP7M= 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.208.42 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-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-595856e2336so3807186a12.1; Thu, 01 Aug 2024 09:14:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722528844; x=1723133644; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0fwJ9sjtEm+K2Uygni9ol7IUWm5RqiSMgqK4WJO8Gac=; b=UuwDzSxR9llqTx84X9BGJ70J0PlC3geXJC3gM452fWtxJcmQF/J3YKi3MoCMAuoCYh y2IKrZPeTylxteZKFAWetRKXvX3FYzgJSOjtkYhnZjjVlLuROqLW1wAZAu3HEfChIc8Y DYcLEgam0eOJrMpy5M63LTnA4yu7nVwdu3c0R+XNwt5FKleADNZ1Hm6/kcjda/6tDM01 i4C6ziOw/FIrA3FtgKqsXaGBYbz/t4KVESfOQ+6VLvvmKwQCBQpA/fEJWVHhQ3+8sRez +uxt4snid+qFJs4n9iV4n/+bJW1Y91PAKi+pMs1kHC3GV+L+psCMErJWy3w4TD32sbKB xuFQ== X-Forwarded-Encrypted: i=1; AJvYcCXNTp+m0+anPCHzkjVAJ1HTkHF2z+ct5SqZmfXRbdseY42no11jLTL0Omo7osISYy6HKPfWvfhASzBTH78uATD5qZTtApLq8liu/dq8lDEgQZf0AL4s7RPkhWWh1QE64r/UfV35 X-Gm-Message-State: AOJu0YyDs3SpkEfKwzhBD0mjW+bSLqNKFQvrQvuu0O6AAjirJZdxgxnR SXlMqC6Jl31sCCLOkoJe7PJLLphnNm2cJOpPJ601euU8HsQ8DF0A X-Google-Smtp-Source: AGHT+IF7er/XmpWbI0le/WS2rWWF6sCS6psERpQnYNgAPU5ZQUrM+3Dj4MSYUnTmN6FyQp5+PkeJ4A== X-Received: by 2002:a05:6402:1a42:b0:5a1:5c0c:cbd6 with SMTP id 4fb4d7f45d1cf-5b80acb9ba2mr479182a12.8.1722528843964; Thu, 01 Aug 2024 09:14:03 -0700 (PDT) Received: from localhost (fwdproxy-lla-003.fbsv.net. [2a03:2880:30ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590d81sm10482172a12.23.2024.08.01.09.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 09:14:03 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next 6/6] net: netconsole: Defer netpoll cleanup to avoid lock release during list traversal Date: Thu, 1 Aug 2024 09:12:03 -0700 Message-ID: <20240801161213.2707132-7-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801161213.2707132-1-leitao@debian.org> References: <20240801161213.2707132-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Current issue: - The `target_list_lock` spinlock is held while iterating over target_list() entries. - Mid-loop, the lock is released to call __netpoll_cleanup(), then reacquired. - This practice compromises the protection provided by `target_list_lock`. Reason for current design: 1. __netpoll_cleanup() may sleep, incompatible with holding a spinlock. 2. target_list_lock must be a spinlock because write_msg() cannot sleep. (See commit b5427c27173e ("[NET] netconsole: Support multiple logging targets")) Defer the cleanup of the netpoll structure to outside the target_list_lock() protected area. Create another list (target_cleanup_list) to hold the entries that need to be cleaned up, and clean them using a mutex (target_cleanup_list_lock). Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 83 ++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index eb9799edb95b..dd984ee4a564 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -37,6 +37,7 @@ #include #include #include +#include MODULE_AUTHOR("Maintainer: Matt Mackall "); MODULE_DESCRIPTION("Console driver for network interfaces"); @@ -72,9 +73,16 @@ __setup("netconsole=", option_setup); /* Linked list of all configured targets */ static LIST_HEAD(target_list); +/* target_cleanup_list is used to track targets that need to be cleaned outside + * of target_list_lock. It should be cleaned in the same function it is + * populated. + */ +static LIST_HEAD(target_cleanup_list); /* This needs to be a spinlock because write_msg() cannot sleep */ static DEFINE_SPINLOCK(target_list_lock); +/* This needs to be a mutex because netpoll_cleanup might sleep */ +static DEFINE_MUTEX(target_cleanup_list_lock); /* * Console driver for extended netconsoles. Registered on the first use to @@ -210,6 +218,46 @@ static struct netconsole_target *alloc_and_init(void) return nt; } +/* Clean up every target in the cleanup_list and move the clean targets back to + * the main target_list. + */ +static void netconsole_process_cleanups_core(void) +{ + struct netconsole_target *nt, *tmp; + unsigned long flags; + + /* The cleanup needs RTNL locked */ + ASSERT_RTNL(); + + mutex_lock(&target_cleanup_list_lock); + list_for_each_entry_safe(nt, tmp, &target_cleanup_list, list) { + /* all entries in the cleanup_list needs to be disabled */ + WARN_ON_ONCE(nt->enabled); + do_netpoll_cleanup(&nt->np); + /* moved the cleaned target to target_list. Need to hold both + * locks + */ + spin_lock_irqsave(&target_list_lock, flags); + list_move(&nt->list, &target_list); + spin_unlock_irqrestore(&target_list_lock, flags); + } + WARN_ON_ONCE(!list_empty(&target_cleanup_list)); + mutex_unlock(&target_cleanup_list_lock); +} + +/* Do the list cleanup with the rtnl lock hold. rtnl lock is necessary because + * netdev might be cleaned-up by calling __netpoll_cleanup(), + */ +static void netconsole_process_cleanups(void) +{ + /* rtnl lock is called here, because it has precedence over + * target_cleanup_list_lock mutex and target_cleanup_list + */ + rtnl_lock(); + netconsole_process_cleanups_core(); + rtnl_unlock(); +} + #ifdef CONFIG_NETCONSOLE_DYNAMIC /* @@ -376,13 +424,20 @@ static ssize_t enabled_store(struct config_item *item, * otherwise we might end up in write_msg() with * nt->np.dev == NULL and nt->enabled == true */ + mutex_lock(&target_cleanup_list_lock); spin_lock_irqsave(&target_list_lock, flags); nt->enabled = false; + /* Remove the target from the list, while holding + * target_list_lock + */ + list_move(&nt->list, &target_cleanup_list); spin_unlock_irqrestore(&target_list_lock, flags); - netpoll_cleanup(&nt->np); + mutex_unlock(&target_cleanup_list_lock); } ret = strnlen(buf, count); + /* Deferred cleanup */ + netconsole_process_cleanups(); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -942,7 +997,7 @@ static int netconsole_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { unsigned long flags; - struct netconsole_target *nt; + struct netconsole_target *nt, *tmp; struct net_device *dev = netdev_notifier_info_to_dev(ptr); bool stopped = false; @@ -950,9 +1005,9 @@ static int netconsole_netdev_event(struct notifier_block *this, event == NETDEV_RELEASE || event == NETDEV_JOIN)) goto done; + mutex_lock(&target_cleanup_list_lock); spin_lock_irqsave(&target_list_lock, flags); -restart: - list_for_each_entry(nt, &target_list, list) { + list_for_each_entry_safe(nt, tmp, &target_list, list) { netconsole_target_get(nt); if (nt->np.dev == dev) { switch (event) { @@ -962,25 +1017,16 @@ static int netconsole_netdev_event(struct notifier_block *this, case NETDEV_RELEASE: case NETDEV_JOIN: case NETDEV_UNREGISTER: - /* rtnl_lock already held - * we might sleep in __netpoll_cleanup() - */ nt->enabled = false; - spin_unlock_irqrestore(&target_list_lock, flags); - - __netpoll_cleanup(&nt->np); - - spin_lock_irqsave(&target_list_lock, flags); - netdev_put(nt->np.dev, &nt->np.dev_tracker); - nt->np.dev = NULL; + list_move(&nt->list, &target_cleanup_list); stopped = true; - netconsole_target_put(nt); - goto restart; } } netconsole_target_put(nt); } spin_unlock_irqrestore(&target_list_lock, flags); + mutex_unlock(&target_cleanup_list_lock); + if (stopped) { const char *msg = "had an event"; @@ -999,6 +1045,11 @@ static int netconsole_netdev_event(struct notifier_block *this, dev->name, msg); } + /* Process target_cleanup_list entries. By the end, target_cleanup_list + * should be empty + */ + netconsole_process_cleanups_core(); + done: return NOTIFY_DONE; }