From nobody Mon Sep 28 19:23:42 2026 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: 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: <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 =20 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); } =20 +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 */ =20 static int __init dynamic_netconsole_init(void) @@ -318,6 +336,15 @@ static void dynamic_netconsole_mutex_unlock(void) { } =20 +static void netconsole_ratelimit_init(struct netconsole_target *nt) +{ +} + +static bool netconsole_ratelimited(struct netconsole_target *nt) +{ + return false; +} + #endif /* CONFIG_NETCONSOLE_DYNAMIC */ =20 /* Check if the target was bound by mac address. */ @@ -686,6 +713,7 @@ static struct netconsole_target *alloc_and_init(void) nt->remote_port =3D 6666; eth_broadcast_addr(nt->remote_mac); nt->state =3D 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_conte= xt *wctxt, bool extended) !netif_running(nt->np.dev)) continue; =20 + 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. --=20 2.53.0-Meta From nobody Mon Sep 28 19:23:42 2026 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 D99013C65E0; Tue, 18 Aug 2026 10:29:54 +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=1787048998; cv=none; b=jFHqZOf9OfcZcZJoe/otvnb2DK2l1zwh7+yH5dt2HzKcauYM14udnZElfvIC88o+45XOjsSWgyTju4LAXlmGGZgZhmVqyI99UUg7j5abDg8w+DdhZx5XAMSl+rhRlBtvJJiQD6+p9s1KxqDffnHyxovzItr13WfnPDl/SWo1E38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787048998; c=relaxed/simple; bh=+PEINribgpDWpNHxXOZNeeb6KNomusmu0cKY3eK6Obs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hDWCbm9PB7mbppVum834jP8kRhgolAUW/t5YYoU6BMQC0g47WeBou7VFQyEXYD8tQMwOOB6elefd5hQiukgIo2flyZqByBHfPaMOgFExzWukEzCdqkXb1HiAoByqftJhShSfp1pMoyhXTeL5lOlr+vXL6fF8CMitn1icNJ/jzMA= 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=HgdIeAgw; 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="HgdIeAgw" 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=tUdFNSHtPF7z4z8dWRcTnirk4pd4hwL1PbeqJshlGOg=; b=HgdIeAgwIe5zPYVsy2QFETJZHU dahuMFVnIMRT0qYfbT778yxNn9IXcRga3WteAUu+2MyHE0d8xmicZQR3BufZW0GcBPWERxJwTUQgu YA1ErGcLPWS+Ey07SLWaiNrYGTXqQkInk59qykcbD5fzBU+Drc+S9dCWKXIVPSNx5ry+2hEsY8sIU 3IbR9KKwLbgz/rkHRhfbeFCLFnglc05Ws0+1fqwCoUiP5eZkVhO6GQNAYftCEi6iQGut/+3vtd7DX VywL9rGlmCRe4f6NwL7mjfFxg7CSHc406decnoQ5ETJ/rfmp05MwTrIgLT7wYYf2Fu02BTdsMonE4 v56OJUjQ==; 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 1wwH4p-008x63-2T; Tue, 18 Aug 2026 10:29:52 +0000 From: Breno Leitao Date: Tue, 18 Aug 2026 03:29:12 -0700 Subject: [PATCH net-next RFC 2/6] netconsole: allow configuring the rate limit interval through configfs 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: <20260818-netcons_ratelimit-v1-2-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=2387; i=leitao@debian.org; h=from:subject:message-id; bh=+PEINribgpDWpNHxXOZNeeb6KNomusmu0cKY3eK6Obs=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqhDQOF00k5m+HLNyG3w2xrJQq9qVi5ltmb/KwG L6Hc0BcdHuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaoQ0DgAKCRA1o5Of/Hh3 bYoTD/9nOI0f5ktqnNMRYwxxpQhLJX6YBuVvN3Je3ODL3Q9szQCW467wM4jbnIHiZ3czJWitxtg l+ZkOf1pUNw/yULe9eGbk+mGlj4BFryF16vmItco3Cc+E4KLOWJEI6o+vMWrPBIr0qwSED7FMiH TuAsKqdnopX+ovjjV5R3G2pn5x2LvVsiL6RnyrJ2JaNy8Ev9DXHX3A5p6ikcdXF8Unc/2RRk7O6 Uid5zdHnu3owcGcYbb4IBiPmSmrsOcQG6Kjy2eGJkjr77+LpguuITIW0xUo2PTOvlQDODlC8WJH WQtmsaW71Lex66DacHnAFV4Ki8X4QolmM/QkoQm6NDpVjFxkGmDaIKXeutGCwTJFkjhRl/3vi3A UTzd/m0tsL1xraRZWWNPn65u+3Pz9v/6ZgR0tqDq4/tModc2tG42bWVPW5vfFNnE/JdH5h4146b 3IVulqJTp7ZQX9mYmvjXnwxU95F3EOHdb/PPi2ZyqKEslEz4bwFG/bncpeqPhjgnoXjFrLVAZH3 mPvU9/cOZ/Ar15PGZ8D77v/xXxa+O6v9XwEDKl0i370E0odzm6RxfTjHN5sEAp5C4tj8CIZAJw+ wzTmqq+Sw5a0nqgUmzeBhZzk8Q3n8JAUwhHuvYZa/r0MOckOPSvboLxjGsra8JKiSf6sJcL7A2e +Sv6drdOoKMDAYw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao The per-target token bucket has no interface, so every target is still unlimited. Expose the interval as ratelimit_interval_ms through configfs. It defaults to zero, so a target stays unlimited until an administrator sets one. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 2ad514afa2b89..6f94495d0abc3 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -940,6 +940,14 @@ static ssize_t transmit_errors_show(struct config_item= *item, char *buf) return sysfs_emit(buf, "%llu\n", xmit_drop_count + enomem_count); } =20 +static ssize_t ratelimit_interval_ms_show(struct config_item *item, char *= buf) +{ + struct netconsole_target *nt =3D to_target(item); + + return sysfs_emit(buf, "%u\n", + jiffies_to_msecs(READ_ONCE(nt->ratelimit.interval))); +} + /* configfs helper to display if cpu_nr sysdata feature is enabled */ static ssize_t sysdata_cpu_nr_enabled_show(struct config_item *item, char = *buf) { @@ -1335,6 +1343,29 @@ static ssize_t remote_mac_store(struct config_item *= item, const char *buf, return ret; } =20 +static ssize_t ratelimit_interval_ms_store(struct config_item *item, + const char *buf, size_t count) +{ + struct netconsole_target *nt =3D to_target(item); + unsigned int interval; + unsigned long jifs; + ssize_t ret; + + ret =3D kstrtouint(buf, 10, &interval); + if (ret) + return ret; + + jifs =3D msecs_to_jiffies(interval); + if (jifs > INT_MAX) + return -ERANGE; + + dynamic_netconsole_mutex_lock(); + WRITE_ONCE(nt->ratelimit.interval, jifs); + dynamic_netconsole_mutex_unlock(); + + return count; +} + struct userdatum { struct config_item item; char value[MAX_EXTRADATA_VALUE_LEN]; @@ -1699,6 +1730,7 @@ CONFIGFS_ATTR_RO(, local_mac); CONFIGFS_ATTR(, remote_mac); CONFIGFS_ATTR(, release); CONFIGFS_ATTR_RO(, transmit_errors); +CONFIGFS_ATTR(, ratelimit_interval_ms); =20 static struct configfs_attribute *netconsole_target_attrs[] =3D { &attr_enabled, @@ -1712,6 +1744,7 @@ static struct configfs_attribute *netconsole_target_a= ttrs[] =3D { &attr_local_mac, &attr_remote_mac, &attr_transmit_errors, + &attr_ratelimit_interval_ms, NULL, }; =20 --=20 2.53.0-Meta From nobody Mon Sep 28 19:23:42 2026 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 106883E0255; Tue, 18 Aug 2026 10:29:59 +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=1787049005; cv=none; b=MKHgg4kNQVdXZE6RyOvBwV8qKS03NGbqVVHM33i52ou7TxJAyGRR2I5nTNetcQDWVPgFf70Q9pkvLMYvfXU2TP2iWc+m84kC3LyUm3G19V/B8LDQNAg9XyS6RugjNd3DiyBsbA6/I/qp8qnwDRwu7jzZAN+ji2pQrXV8jHyCCFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787049005; c=relaxed/simple; bh=R5iXd9olCf6Hc+oy9EHjUHxjp0R1Ga+f57pdI5oZ1H0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G0undrTN87R2AUyVytrIkyUvd8aSpD8uRzFVK2p7oSrgXaOe9t50myNGgRAyPd4R6TG8hxcK/QQNmQJBMecwmzWtxze6g1ojRE6yKeL+zmFl3JmZk6iWOUdLORHQAwztysicC7tX5kkbe36cFU7LaTVleDvboDPxQeT2rBTAqeA= 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=QupJKn5m; 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="QupJKn5m" 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=sxZtfqnwWWtAmKIrsR5oLgR+/1CWbp+LHmOJL0bB/lA=; b=QupJKn5mQiqxcm1XTPIme3LTwL K05HdkaoZkzP5GmDxyrSMph6G92qcD/q8zOVMBlVGXqutPJwaZKLkMQo6vO1mE0bJlRPqQ/E9Adt8 zJmtcdTDJ7xfo9oOuizJkvpsIhmz/irzP8wSbQAp6ytOtiQSc+KEfxALSfZWcSgZa7CyFLwl3pFAK 4nsMr9b3KDdJcRMuVrAEFIhi+u57qW18Z0mwGzZi0PKseWxKPcCRaVAFehP2MbqQ5OzCHE/7jkN3u V+i+E+h3UYzLBp7+gddBpN2T/vQ3/U+1HAuwT4wjgvi8JvcpwjcYRHdQYN3hvkaPoa29B56Sz80JA cJu2CASg==; 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 1wwH4v-008x6O-1A; Tue, 18 Aug 2026 10:29:57 +0000 From: Breno Leitao Date: Tue, 18 Aug 2026 03:29:13 -0700 Subject: [PATCH net-next RFC 3/6] netconsole: allow configuring the rate limit burst through configfs 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: <20260818-netcons_ratelimit-v1-3-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=2283; i=leitao@debian.org; h=from:subject:message-id; bh=R5iXd9olCf6Hc+oy9EHjUHxjp0R1Ga+f57pdI5oZ1H0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqhDQOdXIrnqoQGDGi6J1jK88hwtsE262RGDZbc djkUf+qkv6JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaoQ0DgAKCRA1o5Of/Hh3 bY6fD/4vUz5sKAVwFICoNyZyQEBHyzqRJRD0/q9sZdVn3gEN9E7ndgb0ldcxvvArnz4T/rkMDpx BUqpjvX6XM7k4E2R7fPDRxK/GPTaoHEaReZYkfG8UmvZty0t4NDh1SyOCOAH3H9AkehhEpxYnMM OW97ugy/bjMQQM+sLS43tIJ1ft1xrtyLNC3502iGUw47oEogo9BvffVVYuBLc8TwrTlNgjZBFbv XxrAPI5WAJJhDGtpDx9Kx6FG65C0SQaAkRsx4PBQPnZGaHUhCo+HruRvT0BmbXvlEj+U1R8p5jO ulCWHQgUJso3ohL1Uqc54IkN/zIXioo04KJsjdPGtoijECIubBGRHkSX4/NlksZey7t0Gp7VNJF Mr802ouEXY64AERQwk9yPrzXeDNsBFMKhl9GgIgGb0Ag8hTYNUyy68GlSZMK4WB5u1sCIcprY0P IMVgqa25T29OfKxLYp5cdeYFWE94S5XsTbLr0G7k7Sni3cka2z/mF67P1U0Nf3FPv4bGLIepavn vCkYq0dcF6A5BwjJRTFnyPx3BeZiC6Wj/WlQ6UedzHSXUA2R1axUSm5qtCFKV3GCJ6D130krYvB K47r5hwaTDvyq3n9GZOIJ9osE64a1l73Pz6UpdDkLWWxlo5QzPyQXcmO7T/qHBt2+apoAiqxNkF OGbATfFBxtFnEUA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao A target that sets ratelimit_interval_ms runs with the ratelimit default of 10 messages per interval, which is either too coarse or too generous depending on how chatty the target is. Expose it as ratelimit_burst through configfs. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 6f94495d0abc3..6d60a5188bf13 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -948,6 +948,13 @@ static ssize_t ratelimit_interval_ms_show(struct confi= g_item *item, char *buf) jiffies_to_msecs(READ_ONCE(nt->ratelimit.interval))); } =20 +static ssize_t ratelimit_burst_show(struct config_item *item, char *buf) +{ + struct netconsole_target *nt =3D to_target(item); + + return sysfs_emit(buf, "%d\n", READ_ONCE(nt->ratelimit.burst)); +} + /* configfs helper to display if cpu_nr sysdata feature is enabled */ static ssize_t sysdata_cpu_nr_enabled_show(struct config_item *item, char = *buf) { @@ -1366,6 +1373,27 @@ static ssize_t ratelimit_interval_ms_store(struct co= nfig_item *item, return count; } =20 +static ssize_t ratelimit_burst_store(struct config_item *item, const char = *buf, + size_t count) +{ + struct netconsole_target *nt =3D to_target(item); + unsigned int burst; + ssize_t ret; + + ret =3D kstrtouint(buf, 10, &burst); + if (ret) + return ret; + + if (burst > INT_MAX) + return -ERANGE; + + dynamic_netconsole_mutex_lock(); + WRITE_ONCE(nt->ratelimit.burst, burst); + dynamic_netconsole_mutex_unlock(); + + return count; +} + struct userdatum { struct config_item item; char value[MAX_EXTRADATA_VALUE_LEN]; @@ -1731,6 +1759,7 @@ CONFIGFS_ATTR(, remote_mac); CONFIGFS_ATTR(, release); CONFIGFS_ATTR_RO(, transmit_errors); CONFIGFS_ATTR(, ratelimit_interval_ms); +CONFIGFS_ATTR(, ratelimit_burst); =20 static struct configfs_attribute *netconsole_target_attrs[] =3D { &attr_enabled, @@ -1745,6 +1774,7 @@ static struct configfs_attribute *netconsole_target_a= ttrs[] =3D { &attr_remote_mac, &attr_transmit_errors, &attr_ratelimit_interval_ms, + &attr_ratelimit_burst, NULL, }; =20 --=20 2.53.0-Meta From nobody Mon Sep 28 19:23:42 2026 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 C6B1C3E1CE4; Tue, 18 Aug 2026 10:30:04 +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=1787049006; cv=none; b=PDK/E8E2aEujfZE00BhE7JyQpqATwgIqI2ybqFYAGYnyfUtyugvzgH1DFkRu87x9FAR4iI7gZXq8xTGGIpslsbig8wZFq/zEvX/RO2QMo9JgHMfb+1zfYPAIRYO2GCYMgjONqQiveK4bUAmPkHEzEGxmPg0EHD3DpiPDSJvTwNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787049006; c=relaxed/simple; bh=Q3qoIG28CpFJLddjjct+GSvPpQNH4vUDWBsW4OFZkcM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MKlkSLo054pYI0StDplSbwrJAPxeen5OATCDbVyX4/cslI/mia82fRkfUp7/jadSp9VRUm8zRRDaWACkw1lvSe/MhmaSGdqYPhy3rdikkQy4bFMW57jb77ocqJpZBCBbKbaRZsEbCnXVw++7H3eB6Alp4xE7YsJ5hHNB4DbUOrU= 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=ZfyIyuXI; 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="ZfyIyuXI" 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=Kz0Mz7z1sjUk0o6kQF/8M9atXJEj1KDEndjp7Pcq0Yc=; b=ZfyIyuXIwSZDs8kUqp8JduK1cP uJc1q47Da0sQ976khbi41JAgEyrPQvXVRKiUCdcPEi4FyqlTwuXFIz2ko5NQVZA7zvZJ4Vh4dzVxI iYVZj2KLZeZQ97UvokDGmlC0xeZw2hOoQKiZJVIkQCUMVJVI02UM75fEnf82ZFYsdF/oL4FzXPQKH D+ATUpRQ6fjbgL9lpj9z6xlmmr04Xt7KlWDigTq6YEnGHkQ6SCcO6CDmTOMdhiRW9h70kUEkBQLd7 oiSqsQPK8JyT7xz7Ot1K7iYlQFoBVjzgFrIRv4Ay4SIMmLJgrE+PDzoeLfCBrwk80N2/3WAtpOurd rdlRCGnQ==; 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 1wwH50-008x6e-1x; Tue, 18 Aug 2026 10:30:02 +0000 From: Breno Leitao Date: Tue, 18 Aug 2026 03:29:14 -0700 Subject: [PATCH net-next RFC 4/6] netconsole: tell the target when the rate limit drops messages 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: <20260818-netcons_ratelimit-v1-4-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=4145; i=leitao@debian.org; h=from:subject:message-id; bh=Q3qoIG28CpFJLddjjct+GSvPpQNH4vUDWBsW4OFZkcM=; b=owEBbAKT/ZANAwAIATWjk5/8eHdtAcsmYgBqhDQOlUKu6MPD3GsyVRno8F+Qe+xhRy+jNAFFu MyVOqPaOOWJAjIEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaoQ0DgAKCRA1o5Of/Hh3 bfTCD/ICSI7nWiauE3PkZgmF0FEPl5jR5YHMmGTxcpj3VFWIF3tztOqirA85zv3ZaphuUFF45vi QHRTE0Co0FYo2vwx4eIvCQQzeUOrIBCrfJnztQOrijhF+C1elOkiB6niouQggLXBrl3K7FLj8fK P1ygn/PXzkze06uQe73tVNqpXxF2gv3CGTM6ifXmDTUiTrWzI0IXuNKV8QZNpsOvu3qYgPxBRZ7 YFvwBzX7h0FHU3s9vD5Dx2cbJ16F16u/2hexUtvV0pXyCSZa6Hy7EGkQs3lEOLMoTgHOPPcxugB NEKjLBAal8jtVciYFhuF4sSD0UO0kJ/IxRT7QJxW1WDlGySclZXCMLJF1d4+pYHAkfIZVSe3e1c eZT2nGVxJFFJIWo1XMW5oDSctc5M0WqygCA+lhR2KzDazWmsfzziZFYF0srr+cNlm7Q2s59n7V1 eN2/zM7K6v0N27Yt/hpB54KBPUBYMU3SDfXV5C4EXEtS8nJqeOC1bLHmh7/i3tzp6Wl2gHtzw4N s29/Y3wTaCet2CesuDidmaErnc2e15tGQd+ZIcv6J3F0e8OQb1bg19UcQxszQd4wBXid8UVu7Jq RlMAyDXgk4fK5dYB1vY6eurBDQqMs4cIOXE3CRWbEDMnFxsbtcdccFlzUFi7DVebgRbg98uhJv9 xo77yalCAVGlE X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Keep the number of messages dropped since the last report on the target and send it to the receiver as soon as a message gets through again: netconsole: 45 messages dropped by rate limit netconsole formats that record itself rather than calling printk(), which would feed the console it is currently servicing. Nothing here has a printk sequence number, so the extended header carries a zero. The timestamp comes from local_clock(), the same clock printk stamps its records with, but it is taken when the notice goes out rather than when the message was logged. It can therefore read a few microseconds later than the message it precedes. The notice rides on the next message the bucket lets through, so a target that goes quiet right after a burst of drops only reports them once the host logs again, and a target with ratelimit_burst set to zero never reports at all. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 53 ++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 6d60a5188bf13..0af2e5b4335c0 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -50,6 +50,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Matt Mackall "); MODULE_DESCRIPTION("Console driver for network interfaces"); @@ -177,6 +178,7 @@ struct netcons_userdata { * @sysdata_fields: Sysdata features enabled. * @msgcounter: Message sent counter. * @ratelimit: Opaque structure to ratelimit messages + * @pending_drops: Messages dropped since the last notice was sent. * @stats: Packet send stats for the target. Used for debugging. * @state: State of the target. * Visible from userspace (read-write). @@ -221,6 +223,7 @@ struct netconsole_target { u32 sysdata_fields; /* protected by target_list_lock */ u32 msgcounter; + u32 pending_drops; struct ratelimit_state ratelimit; #endif struct netconsole_target_stats stats; @@ -297,7 +300,20 @@ static bool netconsole_ratelimited(struct netconsole_t= arget *nt) if (oops_in_progress) return false; =20 - return !__ratelimit(&nt->ratelimit); + if (__ratelimit(&nt->ratelimit)) + return false; + + nt->pending_drops++; + + return true; +} + +static u32 netconsole_take_drops(struct netconsole_target *nt) +{ + u32 drops =3D nt->pending_drops; + + nt->pending_drops =3D 0; + return drops; } =20 #else /* !CONFIG_NETCONSOLE_DYNAMIC */ @@ -345,6 +361,11 @@ static bool netconsole_ratelimited(struct netconsole_t= arget *nt) return false; } =20 +static u32 netconsole_take_drops(struct netconsole_target *nt) +{ + return 0; +} + #endif /* CONFIG_NETCONSOLE_DYNAMIC */ =20 /* Check if the target was bound by mac address. */ @@ -2554,6 +2575,34 @@ static void send_msg_udp(struct netconsole_target *n= t, const char *msg, } } =20 +static void send_ratelimit_notice(struct netconsole_target *nt, bool exten= ded) +{ + int len =3D 0; + u64 ts_usec; + u32 drops; + + drops =3D netconsole_take_drops(nt); + if (!drops) + return; + + if (extended) { + /* append the extended headers */ + if (nt->release) + len =3D scnprintf(nt->buf, sizeof(nt->buf), "%s,", + init_utsname()->release); + + ts_usec =3D div_u64(local_clock(), NSEC_PER_USEC); + len +=3D scnprintf(nt->buf + len, sizeof(nt->buf) - len, + "%u,0,%llu,-;", LOGLEVEL_WARNING, ts_usec); + } + + len +=3D scnprintf(nt->buf + len, sizeof(nt->buf) - len, + "netconsole: %u messages dropped by rate limit\n", + drops); + + send_udp(nt, nt->buf, len); +} + /** * netconsole_write - Generic function to send a msg to all targets * @wctxt: nbcon write context @@ -2583,6 +2632,8 @@ static void netconsole_write(struct nbcon_write_conte= xt *wctxt, bool extended) if (!nbcon_enter_unsafe(wctxt)) return; =20 + send_ratelimit_notice(nt, extended); + if (extended) send_ext_msg_udp(nt, wctxt); else --=20 2.53.0-Meta From nobody Mon Sep 28 19:23:42 2026 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 7E0183C10A3; Tue, 18 Aug 2026 10:30:12 +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=1787049014; cv=none; b=cXwMfVtVZ+B8BW8Dyt81HweiBwGqSdOJC1zuXHoE6rSTmE+oZYYkbY4ATr5VR9Vcj2gQjDCmy+V6qj28rpDrioVtgob8O3gU+R4VvWpGqCr4n/Gyah17V2RF1jjmpbGSQfA7auvhm7V+etT+xOdarxMP8jii3c35viCMa2x4oLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787049014; c=relaxed/simple; bh=/etAJJtrfw3F/NjXwyUYeknccqYgvo1SAqIH9/lrHcc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WobbeYeNnkaGeis5VvL1i7ZFeLeiqLWfNLzYrqEb6iktqeLYhEcmgD7UnSINo4U5minds69LDrjFClWDlPxbPnzcBBnRttK5xns9nblSipgWbBGzPdQwy60mkhWbaqzBO7Nq3NzK68EKnsE8oVpQTKpC6MO9P23BmwgI0czIuFM= 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=V4hzDR0K; 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="V4hzDR0K" 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=G+RMJyYuWASkHXXd+GnjSoR1L1cHAANJPPpOAclyXA0=; b=V4hzDR0K6XlhG3kMrg9pxaO/BT 8Le83uoNbm9KxRBnoMbJs0d1cFDCGnuRudvkS5tZcLOYGni5gHdbt3NMGP8RNn1fXZ8B5QWUwbmuq vj8zHvE6QP/qYByUujvNfgssu02/MnzlInQb22AN7w/3wEfE1hWzXfNiDkATU630dquh93phkp8Ew qc9UupWqKh5Jrlh80Eodqdw7NDCgEY2iSQTg2tCNrWsxpVB64eH5To+hf2XysoAJBYdKh8sRdDNfb SoobXuTLpGodDm8bK51pmWHzts0jnYYzJS/1GbOmNZ9nR0EKqFMFzBbxOxmusXXx9ZJQkFMXu6tyN a2ddhGjA==; 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 1wwH56-008x75-0d; Tue, 18 Aug 2026 10:30:08 +0000 From: Breno Leitao Date: Tue, 18 Aug 2026 03:29:15 -0700 Subject: [PATCH net-next RFC 5/6] docs: netconsole: document rate limit feature 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: <20260818-netcons_ratelimit-v1-5-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=2955; i=leitao@debian.org; h=from:subject:message-id; bh=/etAJJtrfw3F/NjXwyUYeknccqYgvo1SAqIH9/lrHcc=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqhDQOB/LYnnchrr2D2Nu3MfytO8/okSB6+3QG8 jdb4J7VOiGJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaoQ0DgAKCRA1o5Of/Hh3 bYLpD/9Xm4BSlqPsFt1cz+DDb/2M/AXMv5GADWUCsGrqhOuG2yLeitTCOXdwVXKpana/eVlLWfR WqOgIGT4sxznH5m1ef9F1HFDTnth45I/LZphmjJsXU+OKIC6qiLPn3eo2+pJctkM3jZ8NqHGBEs QHRRXn9q6G1nNUgT67SdjZT61DwYFLJz13uHs3bTUh0xumvd1ZailNTjcekDInoW9uNjZssONxR gFZVqLgbRCMqHpORHBm4ryZ3VONBu+2CjELHUQW4mOYDS0xIB2m7Ps+5q9Tbp8fcz271EysFzFM Y9EGAlXuMb0oVRSgxZDZZCxrhtZYWYWSHnaVElTTwD9BP5vXpTNGJZ3N8LdzFvzhTIIc0H0vrVc QqAO0RbptJ31EoABB2XKuX35m2eIuiJ6NVXm/Z4dkw3bpUz7qRHxmBXzFkJzK0kzC63MpuDC5g0 pj0L+99gHoLk9KkzKT2ck6Cl4VdcEEu+K4F4R3YC2ok/ID6BEG1y1o2TotnWFTUyoP/EhsNA0LR e+sgX5pmIBbXJ0Dtwmd/OVnMis1sy6b6lf905PYPn2Vo5b7UG943mDbu7nBR8cb/mMwNXE1gLHz 0arva3zR8WroRhqB8cMz2kLpB/C3G0v6RANfYS7L4unvxUL2FoEE/8Fw1OhPgCs8h4X+gzZcWk5 nLzEThFMrhDEpjg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Describe the per-target token bucket and the two configfs files that drive it: ratelimit_interval_ms and ratelimit_burst. Spell out the two properties that are not obvious from the file names. The limit is accounted per message rather than per packet, so a message split into several ncfrag packets is never truncated by the bucket running dry halfway through. Signed-off-by: Breno Leitao --- Documentation/networking/netconsole.rst | 43 +++++++++++++++++++++++++++++= ++++ 1 file changed, 43 insertions(+) diff --git a/Documentation/networking/netconsole.rst b/Documentation/networ= king/netconsole.rst index 4ab5d7b05cf10..7369cd89ae76c 100644 --- a/Documentation/networking/netconsole.rst +++ b/Documentation/networking/netconsole.rst @@ -177,6 +177,49 @@ You can modify these targets in runtime by creating th= e following targets:: cat cmdline1/remote_ip 10.0.0.3 =20 +Rate limiting +------------- + +Netconsole hands every console message to every enabled target, so a host = that +logs continuously can saturate the receiving agent. Each target carries a = token +bucket that drops messages once the configured rate is exceeded, controlle= d by +two files in the target directory: + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + ratelimit_interval_ms Length of the accounting interval, in + milliseconds. Zero, the default, sends + everything. + ratelimit_burst Messages allowed per interval. Defaults to + 10; zero drops every message. + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Unlike most target parameters, both knobs can be written while the target = is +enabled, which is when a flooding target most likely needs them. + +The limit is applied per message, not per packet, so a message big enough = to be +split into several `ncfrag` packets is either sent whole or not at all. + +Crash output bypasses the bucket. While an oops, BUG() or panic() is in +progress every message is sent, whatever the limit says, so a small burst +cannot cost you part of a crash dump. + +A drop leaves nothing on the wire, so the receiver is told what it missed = as +soon as a message gets through again:: + + netconsole: 45 messages dropped by rate limit + +The notice only travels with the next message the bucket allows. A host th= at +goes quiet right after being limited reports the drops later, when it logs +again, and a target with a `ratelimit_burst` of zero never reports them. + +netconsole generates the notice itself instead of logging it, so on an +extended target the record carries a sequence number of zero. + +Capping a target at 500 messages a minute:: + + echo 60000 > ratelimit_interval_ms + echo 500 > ratelimit_burst + Append User Data ---------------- =20 --=20 2.53.0-Meta From nobody Mon Sep 28 19:23:42 2026 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 64DED3E5A0E; Tue, 18 Aug 2026 10:30:16 +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=1787049018; cv=none; b=TsraC/WV8P26Q/zNbrwpRx+WDSZxSBpfkRFVgOo++auIlRCk5T7gW+BhwQxVH/8QwAQIDvz1WC8/pZALJ1k9YDAcG6qeRLhF6C3g17SuePfKz00wrys+QTTn41e0Wdi9N1mwObUxwUOpJGaPdmw+aoWd0RO+A/skc2ZAhgMEF/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787049018; c=relaxed/simple; bh=+9MOoBeACdx26BYEWPAq/ZHeh7mKiNyWJP1qhkqZhJ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZPZyX1y2/0QjFSKwXTqSWqwsQOI0HNL6TPmK/MntDwDdBy0+gKP/sfxK34VlwNUxMtmZwVX6EwGngOSm0s+dUHRQU+VoFir0YA+P3pBTJIDE3x48lSfqDyDGfyVCbcain674FamhJ99pF+KE8gq5U2mjyqNmKVCqvKbGXbQFmv8= 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=iTDCAimJ; 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="iTDCAimJ" 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=Z0bBxF8VnIEwXxGroB2RBoES/eXA6hsdail7v/CV2Po=; b=iTDCAimJieGfQs+Mu/oTarJg+T /jR0jW2ga1i8IVipTHn9JPFt+gfTSSUN0sk4X26GoH2dFlvHtWVkNppH7+xPYVEiheZej+Qqe6mCZ 6KZpacCzc1N8XclcLHCUTjrkBgTEdPC1ZQvFPzEeh84aOzKyQDZPtPR4PoPIaWzaHBlaGK/N29f1P POhkVs3HIz5SqDRgT9Oj7WqLjkbl5YYerr1sCYdFz3CZ6dtEOliXO6YwE1A4Txx5RMNl+nyjJMnXV WX2C5sq24reVWThP7V4cnOMU/6/xS+vobclqp1TrVHfKcscU+ulZYZ54NBTMqaMY5vdQET4o2UPRw j7VEjBzA==; 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 1wwH5B-008x7a-1x; Tue, 18 Aug 2026 10:30:14 +0000 From: Breno Leitao Date: Tue, 18 Aug 2026 03:29:16 -0700 Subject: [PATCH net-next RFC 6/6] selftests: netcons: test the per-target rate limit 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: <20260818-netcons_ratelimit-v1-6-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=6255; i=leitao@debian.org; h=from:subject:message-id; bh=+9MOoBeACdx26BYEWPAq/ZHeh7mKiNyWJP1qhkqZhJ0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqhDQOky3Hoa0R4sv9+HXwWMjKOARiDoGcitDLA O1B1TLK2fGJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaoQ0DgAKCRA1o5Of/Hh3 bW1fD/wOkp0X2FsVMsxo0Tg425Tqnxwu/bKLAaeK+7l9QOVFu210kxx/Y0PdLrb85Sqw8h27bve J0cWap08ObcUzHW2vYLmzZ3E/oeOOOf8iwmE3ji58htVhf2MfeKeeS+ApXkJMd+Hz5IU7BdGnBi F2RDqfXsarbtUUpu6mpQX5RLbky3IG7lSeL5gmqXzIQs+4bnb44oWmcLsCCikhpBQC4yy/YOe1g B534BNmdO//9gBdxW98KEC3yExHygFiFZEKt//l5GqiSRK36oP0D63766ZoxgUV6aOri+weUxXp JK2JHcoqe3MN9ZMdJB47/3gr1SE/bMaB1e5dUV/47BXq6+rrCauZme4UUi7m3WIYa8nVUwf2AZH 2riULcTjivisZ34tRVHdOVbXBLtjAhvgkFLNdxe2xt3gVJ9PvnsVVsx8AxcBTvbqRixMfd279cW 82F26c0W62MfnTb5SCWMNfRJgY8dro+qo6x4yJO4/++4J5sL6bcuhcmH0suNfCPTHi9G31y3k9T Dlgeas5LR3m4G+BVldTtlVk3aDIbaqx9Y10bdl8C6z3sa11mobmHYLKTTRwneU/jvpfp/w0yQAN DevKhEsyfWghMwO1lJfq3SziP+8ldJ/pqe1SO8p4LG3YiTOIu6dtXFStmQ77rTso80RfXep0Thx iIqhuIjNHa2n2RQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Check that a new target starts unlimited and that a configured burst caps what the target transmits. Dropping the interval back to zero has to restore unlimited delivery and report what was lost to the receiver. Only an upper bound is checked on the number of messages received. netconsole is best-effort UDP and unrelated kernel messages draw from the same bucket, so what arrives is not an exact count, while the cap is. Signed-off-by: Breno Leitao --- .../selftests/drivers/net/netconsole/Makefile | 1 + .../drivers/net/netconsole/netcons_ratelimit.sh | 160 +++++++++++++++++= ++++ 2 files changed, 161 insertions(+) diff --git a/tools/testing/selftests/drivers/net/netconsole/Makefile b/tool= s/testing/selftests/drivers/net/netconsole/Makefile index f0674c0017fc4..04cce40f162e9 100644 --- a/tools/testing/selftests/drivers/net/netconsole/Makefile +++ b/tools/testing/selftests/drivers/net/netconsole/Makefile @@ -10,6 +10,7 @@ TEST_PROGS :=3D \ netcons_cmdline.sh \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ + netcons_ratelimit.sh \ netcons_resume.sh \ netcons_sysdata.sh \ netcons_torture.sh \ diff --git a/tools/testing/selftests/drivers/net/netconsole/netcons_ratelim= it.sh b/tools/testing/selftests/drivers/net/netconsole/netcons_ratelimit.sh new file mode 100755 index 0000000000000..38dd1599fe57d --- /dev/null +++ b/tools/testing/selftests/drivers/net/netconsole/netcons_ratelimit.sh @@ -0,0 +1,160 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# This test exercises the per-target rate limit. It configures a small bur= st +# over an interval long enough that the bucket is never refilled, sends ma= ny +# more messages than the burst allows, and checks that the target stops +# transmitting once the bucket is empty. +# +# Clearing the interval has to restore unlimited delivery and tell the +# receiver how many messages it missed, which is verified last. +# +# Author: Breno Leitao + +set -euo pipefail + +SCRIPTDIR=3D$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/../lib/sh/lib_netcons.sh + +# Messages sent while the limit is in place, comfortably above BURST so th= at +# the bucket is drained +MSG_COUNT=3D50 +BURST=3D5 +# Long enough that the bucket is not refilled while the test runs +INTERVAL_MS=3D60000 +# Default the target starts with, as documented in netconsole.rst +DEFAULT_BURST=3D10 +# What the target sends once it can transmit again +DROP_NOTICE=3D"messages dropped by rate limit" + +# The content of kmsg will be saved to the following file +OUTPUT_FILE=3D"/tmp/${TARGET}" + +function count_msgs() { + local FILE=3D"${1}" + + if [ ! -f "${FILE}" ] + then + echo 0 + return + fi + + # grep exits 1 on no match, which is a valid result here + grep -c "${MSG}" "${FILE}" || true +} + +function send_msgs() { + local COUNT=3D"${1}" + local I + + for I in $(seq "${COUNT}") + do + echo "${MSG}: ${TARGET} ${I}" > /dev/kmsg + done +} + +# A freshly created target has to be unlimited, otherwise every existing +# netconsole user would start dropping messages after an upgrade +function check_defaults() { + local INTERVAL BURST_DEFAULT + + INTERVAL=3D$(cat "${NETCONS_PATH}"/ratelimit_interval_ms) + BURST_DEFAULT=3D$(cat "${NETCONS_PATH}"/ratelimit_burst) + + if [ "${INTERVAL}" -ne 0 ] || + [ "${BURST_DEFAULT}" -ne "${DEFAULT_BURST}" ] + then + echo "FAIL: unexpected rate limit defaults:" \ + "interval=3D${INTERVAL} burst=3D${BURST_DEFAULT}" >&2 + exit "${ksft_fail}" + fi +} + +function check_limited() { + local RECEIVED + + RECEIVED=3D$(count_msgs "${OUTPUT_FILE}") + + # Unrelated kernel messages share the bucket, so fewer than BURST of + # ours can get through, but never more + if [ "${RECEIVED}" -gt "${BURST}" ] + then + echo "FAIL: received ${RECEIVED} messages with ratelimit_burst=3D${BURST= }" >&2 + cat "${OUTPUT_FILE}" >&2 + exit "${ksft_fail}" + fi +} + +# The notice below travels ahead of the message that reopened the bucket, = so +# waiting for the file to appear is not enough +function msg_received() { + grep -q "${MSG}" "${OUTPUT_FILE}" 2> /dev/null +} + +# The messages lost above have to be reported to the receiver +function check_drops_reported() { + if ! grep -q "${DROP_NOTICE}" "${OUTPUT_FILE}" + then + echo "FAIL: no rate limit notice in ${OUTPUT_FILE}" >&2 + cat "${OUTPUT_FILE}" >&2 + exit "${ksft_fail}" + fi +} + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # +# Start here # +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # + +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 +# Remove the namespace, interfaces and netconsole target on exit +trap cleanup EXIT + +# 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 a dynamic target for netconsole +create_dynamic_target + +check_defaults + +# Set the burst before the interval, so that no message escapes while the +# target still carries the default burst +echo "${BURST}" > "${NETCONS_PATH}"/ratelimit_burst +echo "${INTERVAL_MS}" > "${NETCONS_PATH}"/ratelimit_interval_ms + +listen_port_and_save_to "${OUTPUT_FILE}" & +wait_for_port "${NAMESPACE}" "${PORT}" "ipv4" +send_msgs "${MSG_COUNT}" +# This half of the test is about messages that never arrive, so there is +# nothing to busywait on +sleep 1 +pkill_socat +check_limited +rm -f "${OUTPUT_FILE}" + +# Dropping the interval back to zero has to make the target unlimited again +echo 0 > "${NETCONS_PATH}"/ratelimit_interval_ms + +listen_port_and_save_to "${OUTPUT_FILE}" & +wait_for_port "${NAMESPACE}" "${PORT}" "ipv4" +send_msgs 1 +if ! busywait "${BUSYWAIT_TIMEOUT}" msg_received +then + echo "FAIL: Timed out waiting (${BUSYWAIT_TIMEOUT} ms) for netconsole" \ + "message in ${OUTPUT_FILE} after clearing the rate limit" >&2 + exit "${ksft_fail}" +fi +validate_msg "${OUTPUT_FILE}" +check_drops_reported +pkill_socat +rm -f "${OUTPUT_FILE}" + +trap - EXIT +cleanup +exit "${ksft_pass}" --=20 2.53.0-Meta