From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4083A3C65E0; Tue, 18 Aug 2026 10:29:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787048990; cv=none; b=KhNlCamODPoDFKXL+TiZM68642BFis+HZYoVUXyTWaiNomWFYFUpEJkJwF9mmXTAPM/X4Rne3iNLg4RU1ZgSEnK0cV9GXzXVtiGxacjnTiKfAGGynlOaIpkGRB2uKSlRJFG73ny1TjQzRhm4QiJaSGI2jn78kyvIAi0/y340oRU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787048990; c=relaxed/simple; bh=lFur1xwu0bq93OPnU1P6L/N2ZodSNHeRwhx5g4/WIv0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Wgu33lmsr8m/WSsdXFwwqLq1F04NxbvlDcWD9Hom8xj06PpG87y9xQzTpX5+ecjMdC46/7U61x2KmJdI7MMQyQsK8BViWQVIFSfDMa/JCaD9b9Ht/zqLfMh3/U25BB7IP3w3KGKnIGtVe/ND4rGNCkLqesjp6LJ1lQ7yzj+UYJY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=TaSOB0Ti; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="TaSOB0Ti" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=K3h4DTnkmd6MDd9gcOyc0AOSipMCo7CbeHAKFL3Cbf8=; b=TaSOB0TinomqWXohQLjoMIVaAT XfFoC/h5/onNC3KfpAlFvS9oO3MH/7ggoSHqMvyW/P2y+wJDLl0attjmc7kfURZ3w80TQW6Mrl5fJ FwlyZ3DqGDnrZDFuah+6h7n4CRNilmHM587diiOlYJrdOriSAoFGpQCJ8EiRx9T5g2SbcAhaYHlBr uJpEXd97VKi58q7UpbrwDZP0k992RvNzeEUVaCRIvYd+erRU7MvIzys4V9rIykHNLhUMp7dDKAgut LCmXkyIvdN3WR8E7VH6ACTor2H3RruFmx8E7qyE8XT7FvRc5jn3EA2X1ca+657CoOhHJ9UV1/VK9l mMl69oHw==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wwH4k-008x5p-0D; Tue, 18 Aug 2026 10:29:46 +0000 From: Breno Leitao Date: Tue, 18 Aug 2026 03:29:11 -0700 Subject: [PATCH net-next RFC 1/6] netconsole: add a per-target message rate limit 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: <20260818-netcons_ratelimit-v1-1-8c5d2d17789c@debian.org> References: <20260818-netcons_ratelimit-v1-0-8c5d2d17789c@debian.org> In-Reply-To: <20260818-netcons_ratelimit-v1-0-8c5d2d17789c@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Shuah Khan Cc: paulmck@kernel.org, davej@codemonkey.org.uk, riel@surriel.com, gustavold@gmail.com, asantostc@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, samuelcrossley@gmail.com, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-f8e9d X-Developer-Signature: v=1; a=openpgp-sha256; l=3601; i=leitao@debian.org; h=from:subject:message-id; bh=lFur1xwu0bq93OPnU1P6L/N2ZodSNHeRwhx5g4/WIv0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqhDQOk7lqInJ6/SEdpk07JgvNyAtu2HDHc6CJY RtG26IUZ8mJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaoQ0DgAKCRA1o5Of/Hh3 beQDEACfT3t9G29wKGOAcu11M44gubUpf0yPHvIHrClcGBOc/+Uj6AhejCQ3ZWML7zGtTsd+4jk O8UJ27eCfDKs/0mkwONYbcBtpx0pg9IOm5ir+fdRduSTMhrItVTcIoW94FOSD1hjU5fme5hizsf JYjYGaDeg/OlxMt18L+mxYhK5E72RCEUNuSxAOxJiAUxmmxq5dDt/pGOKx0L6lyLBYoS3tAnx6f yOr4Bv5uN88vGEs2M5kf2yIPQ3AE5zYzSAWNt1CYtrPdjK0yLZ6lzXHy8kh1u95wYN4h462qTiV jAyyJje6fb1h+5RsLIekLwsF340j42eorLSzAS8rxCWizrdrMB87BKLn8OO4o0wEmt03avgWFku 1YRTlzSsRj1VNPGrr4ZgH71ukqXxmxCkBepC3wViTOPGbwInxoYDN7Y3rYo/QuJ1K5d9hKegwmY Ib7WTn52oPJO+D+jxmpxcYJRrMFwrM7QX+satn0P6ZFrFqWVf4CqLa4ejD14E7+7ZTtyTKAh3gq mFZ6bcoBbU2lmIU/HrD4vJ6brQ6xzrts42R9rxlR+7gM0MknXJwbg6AecQxB9wApB/slUPo0mzz euwkoU25drxS1LMGo4ZaYH7i1tMZ3ttaWJ+avfMBiwkMYUqEAM0bsVR8y+ZD6WEGkgkAuINdCoO vpZudD9F4p6rR+g== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Give each target a token bucket and consult it once per message in netconsole_write(). The bucket is created with a zero interval, which struct ratelimit_state treats as unlimited, and nothing can set a nonzero one yet, so no target changes behaviour. Skip the bucket while oops_in_progress is set, so a limit configured for steady-state logging never truncates an oops, BUG() or panic(). The configfs files that expose it come next. ___ratelimit() only trylocks its own raw spinlock, so it is safe with target_list_lock held and interrupts disabled, and safe from NMI. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index b358e5c367351..2ad514afa2b89 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -49,6 +49,7 @@ #include #include #include +#include MODULE_AUTHOR("Matt Mackall "); MODULE_DESCRIPTION("Console driver for network interfaces"); @@ -175,6 +176,7 @@ struct netcons_userdata { * @sysdata: Cached, formatted string of append * @sysdata_fields: Sysdata features enabled. * @msgcounter: Message sent counter. + * @ratelimit: Opaque structure to ratelimit messages * @stats: Packet send stats for the target. Used for debugging. * @state: State of the target. * Visible from userspace (read-write). @@ -219,6 +221,7 @@ struct netconsole_target { u32 sysdata_fields; /* protected by target_list_lock */ u32 msgcounter; + struct ratelimit_state ratelimit; #endif struct netconsole_target_stats stats; enum target_state state; @@ -282,6 +285,21 @@ static void dynamic_netconsole_mutex_unlock(void) mutex_unlock(&dynamic_netconsole_mutex); } +static void netconsole_ratelimit_init(struct netconsole_target *nt) +{ + ratelimit_state_init(&nt->ratelimit, 0, DEFAULT_RATELIMIT_BURST); + ratelimit_set_flags(&nt->ratelimit, RATELIMIT_MSG_ON_RELEASE); +} + +static bool netconsole_ratelimited(struct netconsole_target *nt) +{ + /* A limit meant for steady-state logging must not eat a crash dump. */ + if (oops_in_progress) + return false; + + return !__ratelimit(&nt->ratelimit); +} + #else /* !CONFIG_NETCONSOLE_DYNAMIC */ static int __init dynamic_netconsole_init(void) @@ -318,6 +336,15 @@ static void dynamic_netconsole_mutex_unlock(void) { } +static void netconsole_ratelimit_init(struct netconsole_target *nt) +{ +} + +static bool netconsole_ratelimited(struct netconsole_target *nt) +{ + return false; +} + #endif /* CONFIG_NETCONSOLE_DYNAMIC */ /* Check if the target was bound by mac address. */ @@ -686,6 +713,7 @@ static struct netconsole_target *alloc_and_init(void) nt->remote_port = 6666; eth_broadcast_addr(nt->remote_mac); nt->state = STATE_DISABLED; + netconsole_ratelimit_init(nt); INIT_WORK(&nt->resume_wq, process_resume_target); /* Set up the skb pool primitives once; enabling only refills it. */ skb_queue_head_init(&nt->skb_pool); @@ -2482,6 +2510,9 @@ static void netconsole_write(struct nbcon_write_context *wctxt, bool extended) !netif_running(nt->np.dev)) continue; + if (netconsole_ratelimited(nt)) + continue; + /* If nbcon_enter_unsafe() fails, just return given netconsole * lost the ownership, and iterating over the targets will not * be able to re-acquire. -- 2.53.0-Meta