From nobody Fri Sep 25 16:02:51 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 584BC493D50; Thu, 10 Sep 2026 13:46:37 +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=1789048000; cv=none; b=FqLRPGNokTEy6eTZXRvztDVIg5BdQJSQIb5FtxMUKPTbaWopauOr7ZtdlBVgmHa1yH1P0ca1ZG/Gnss/Fb8BumoS7dZLKlmD5liJ2cRFJjuZiHqKlSvKxyl3zUWp9QbFawvajehKCi4KD3Y4FTTc55CFjWrINXWMpfFCaROCnFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789048000; c=relaxed/simple; bh=te3BGjv2ZkjpAtQL+NYq1q8u2tx56jSGzo6NvbWg650=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HmpFX7JBOEZTK00888uxp6eNpqzTlsAWGKCgo/tL4tDgyp5OeeHTFTKZTvPt44mKz+in4O2/ze9pndalyhfZWZ3uTss2eVMaaKII5gYBtGUa8KMmKhHD8EgI1R1At5g67qPDL+t0CFaLSwejrLkwWbmBo0Q1LuRN8uamoN6ULn8= 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=IVBMUMNf; 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="IVBMUMNf" 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=zhVYq7G9Exl1xvrXgONfvwSZx8+yAyxUVtkgjfCQr/U=; b=IVBMUMNfOCEh5gtOQcoEiFi0pl Al7+8KuZCUeUrSbVcf1JdjbIJO97rr76wEy1FW1wymYAiSj6YrdWkfLwJfZSSGd5B2u6SepE2131Q zwNm83YKwRSL7kfIwOSG7qDfFXVwXSNnDiOTn00Z/+J5lgoaR3wp3W2hoeV7YoQWwe+FGyHTV34eO TOzCtMyzoFQE4GmrzEvgM9X6aqWqbha88ORBkT9rIdrogv/y8cUtf8lv+VTMu5BVOLMWH03yJf2mx 8t0chOPDnJcV9QHHzmXrP28Vqz98mXeqVkb9hWsFYiRT5DuhIH5m+ED/pYjNv4GL4wRICzbjLwgrA bzGraNhA==; 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 1x4f6o-000YHl-1b; Thu, 10 Sep 2026 13:46:34 +0000 From: Breno Leitao Date: Thu, 10 Sep 2026 06:46:10 -0700 Subject: [PATCH net-next v2 1/4] 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: <20260910-netcons_ratelimit-v2-1-ebf0dd91e26e@debian.org> References: <20260910-netcons_ratelimit-v2-0-ebf0dd91e26e@debian.org> In-Reply-To: <20260910-netcons_ratelimit-v2-0-ebf0dd91e26e@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Shuah Khan Cc: Randy Dunlap , paulmck@kernel.org, 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, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-f8e9d X-Developer-Signature: v=1; a=openpgp-sha256; l=4007; i=leitao@debian.org; h=from:subject:message-id; bh=te3BGjv2ZkjpAtQL+NYq1q8u2tx56jSGzo6NvbWg650=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqorSvVw2Y1/q8d1jeRobTLospSYvh9UR+LXD8b tGeDwsY7N2JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaqK0rwAKCRA1o5Of/Hh3 bXv4D/47oB7YhUpBoxx2TLHcCdY+Q75AGJ2mgSQU6XI6UyyVyr/bBLGCzxFB04wQlXlBo9Et/kD PL+c+L1L92cU6ELWG+XJHLLO5qhpA5rHxInARpRwpHS3OYcqdrYnnUkXfp8Gh9hwUOTqDT95ijq ykGw0frlcZUKwYl7Moo6RKSFwm7S4d9AyuDePQJsyxhpyATPPk3MoWnlpakvzf67w3BGABZC+rR NlLf9LfA1nb/gfp2PLL+2x01JvLmrGnMYeU+K53D9qfOmurX4VDTXQiGxDdkh4MQRe2eMtlp1y6 aYgX0+6bfDYITHWPaXFCfq/wBcx+azkoxgMiwmM+yW8eOHxGrm5orOSutVrGJTOczHG0oWG/ejy z73LhEmvy8Prq4yhPFbPMFPEQ+z99AsXN6MtpTEx02F7DVhbjIxmOE65T6WTaq4dJSgQr+McdPb odlbqw/F7NdQsEAsi649fsOrfaDcbiAd6GzDyQBRUPVzJkCHtqRIaVo3YwMVAd8FfWeG6h07nSE Xrzvny9jKvMqBl4CUwmm/BJplpaD8hPLA6zA5zvMlzr/jg5KqxktXCRfp+1Q3VRsLuOX/ssX4JC jiV8pyGZD8S/a5H+Qq4Gt5THSMDA5KUvLLkX/7fQlF95I662/qdEWmj2G/WC2PugaHvfsxjXh74 tqlrDgEnOTwerXQ== 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. Set RATELIMIT_MSG_ON_RELEASE so it does not report the suppressed count itself, which would printk() from inside the console being serviced. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index b358e5c3673510..13292c3f818e9f 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: Token bucket used to rate limit 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,26 @@ 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); + /* The flag keeps ___ratelimit() from reporting the suppressed count + * itself, which would printk() from inside the console being + * serviced. Nothing calls ratelimit_state_exit(), so the count is + * never reported on release either. + */ + 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 +341,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 +718,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 +2515,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 Fri Sep 25 16:02:51 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 8823349BD75; Thu, 10 Sep 2026 13:46:42 +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=1789048004; cv=none; b=AxwrYncBCozH8uuS3xU9s9Vt2I/9AJeoZL+JiPFbLiKWW7JbsSe32v+xZO9s8Y9NzdFoECOH6o3OOI98MYuEW6RrqBH9GunatEQGoAmdtRENTmn3c+2K33W/U6ZlzHxS+2Qf4dWcyjRyLl2xurGp4AgJM3UK4o8PwMFlo1EE0VI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789048004; c=relaxed/simple; bh=GgvXD2xrB1iqUR8ST98lvwz4QfQlTRnHGFVX6aPoO0E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B/lHSsOtRCmhrW8qa3Nf4f8TkTHCd+JrYQIXOKLjF7bGX3hMhTR+/7hvNSeHKJ4jA6raHO9SrSE9SlCtHKkSIiyzHnd6t7T7YtQZWRfBRM0AI3s0p0dBNm20+6ZBlkNs7D1N5g8yW9yahsuLJyov9764/TP08UypdpKDYZtT/i8= 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=qbDXvACd; 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="qbDXvACd" 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=tMemiC/iqLpelYSBghG5uWB4ftBE/dbkc5Hnp9Rt9uk=; b=qbDXvACdJJZCDCafjHkjQ6MRnL ouv+pvJdleaeKANnxKt4LFnL7215Qhcn81yWRh5AVrbeHEIyinDt6IgD/o8ilIDheC9jeFf3K8GGL J0uh66b/HUnEteFd3lgfb+RbBuMyS6TFZ0rJyYWP4WPVhwY+DaJVOjCMpVcpaxdjsQwDxvxf8tu/7 RsoHfay/cy1/NmWP9kiw+PLjP8pNzsZEcZEyogu56uTlhBn+Bw2PnLtbikUN95EZnejXcpKMGTOif /r/s5u+EZNLdnY0xFgjuSmaxU44/STzCdk6UdVLnyxKxg91plX19WUTltP5z4lMMwDOJQvLTTBn1v w3gZjxIA==; 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 1x4f6t-000YI2-24; Thu, 10 Sep 2026 13:46:39 +0000 From: Breno Leitao Date: Thu, 10 Sep 2026 06:46:11 -0700 Subject: [PATCH net-next v2 2/4] 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: <20260910-netcons_ratelimit-v2-2-ebf0dd91e26e@debian.org> References: <20260910-netcons_ratelimit-v2-0-ebf0dd91e26e@debian.org> In-Reply-To: <20260910-netcons_ratelimit-v2-0-ebf0dd91e26e@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Shuah Khan Cc: Randy Dunlap , paulmck@kernel.org, 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, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-f8e9d X-Developer-Signature: v=1; a=openpgp-sha256; l=2389; i=leitao@debian.org; h=from:subject:message-id; bh=GgvXD2xrB1iqUR8ST98lvwz4QfQlTRnHGFVX6aPoO0E=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqorSvXNUJRgefIUH9DOrBZotYfAFBm2nDD+K/O vsLTDadkf+JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaqK0rwAKCRA1o5Of/Hh3 bWI2D/9cvJsYgFigQx1Iu2yY6vZmHIasUK8nyEC4/vwPgY1ihIFyp+WxYTX9GjQAXdkHZ8liVQQ lc58lGpG4E3Z6YWy0JWpLzzWgR82HzNU2w2GTkaXbwptliWtNfEyWf9QCI84vQpQF2rVmEb09QY a/DySYWGx8PqdiixK9ikdiPASE9PhwE9x34oyCikA0+HLClp2W3iVTNfcHa5X7aU6T/VKnLpQ7m 1cBy/hblMU5y/X2noyCZcwe2tyN/wpWGc4z6L2m1lBaO2frz4n0hk7g1Yf40aujQpr4CT/IMzmz SAWW+ZXB7v1qelTGBh3Z6q5bIx28AgMbhTnbFlQO7Hwqh//hZhXxZ6UMvhY0zocfhU2jcwCMxUC 3bRmiYrqQo0dA9VQGtUvPF1QPOJtHk8FfDkrghzpEcYr84A8W4NNZ5bjk4lAm8FHIOQ5NwR8Rlp lp30cU2nQGT3n2SbwVP/VeCdgCmkwGMXfIoE/RUTrlbCDOlkAPb03vZL+4nCmUqJccswoU6TaDc 5ULYSsabZIjN5sSUebrtRoyYzwZ7Uhta7DOAlJ+nhFsh1htb0EuBFWv8UwMlDM7a+svRfxpaKbG c8zbhQ3SP6egaqVHrZ+sNjo0ToQy0m/WcM35aKi1Ah4SZ1+PrMem5wwnyhAoXl35LoJn44kYP9X s/Q8nXfEXgNO9+Q== 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 13292c3f818e9f..faf8f9bbc6c0c2 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -945,6 +945,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) { @@ -1340,6 +1348,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]; @@ -1704,6 +1735,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, @@ -1717,6 +1749,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 Fri Sep 25 16:02:51 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 5B304494A0F; Thu, 10 Sep 2026 13:46:47 +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=1789048008; cv=none; b=nv8ZsGw+c0Sk3Sw92jtr/rC6sh37I+PhT0SS8mnzQ/oc3iuLlcRxkQ4qx/buBc/qt207wrHQqYsQIxpFvYr9yqqW5EIEZEBIgs3zcR8hCTzcn9Qasdbd5kIMoze5c+cLpnhMW7AKqctIYtwOnj6QEidaZZQPIujvhSKpTacbXi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789048008; c=relaxed/simple; bh=R7vwxfMtCdVEV0k2K5iBJN4LpKxwNZXOtaX277UogyE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HOvq+j7DaP2PvJt5cFcSbiGYkx6hm4+Oerc3UACACzVmXam2bJcWq6RkqrNHys6akZHKwUIFt2a6ZZJTro41x3vRb0tXgd2aaBaKplWZHkXqouBuu4BVSwY4+GPakefkc6Kzsino8Z0qYqzSksDlYEEYcrXMJ2X56ddJs41Da10= 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=RjrFD+23; 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="RjrFD+23" 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=ttP+erLBmJ2WI5yYL7mzHv/oynO9Da7pLbV1+ebVkF8=; b=RjrFD+23bRpniFtVQoPqTFgBCU cETEDVUFuL+qGFysmVLKfSBt5GvOsIAEjwEF/S4OLCufe2RoRiXkYfIkFmsnMnNb8PWMbCpAIIapZ R0mXTThQMGeIKLQtCQPTmyUxy/GAXplWGgLmCTsOq/Hic6q9OAsv003AomFqN0oWwRFoz8Y+UDmzu 0wJ4xDrIyEP+AQqAI38ESgyPn82mWDUXJC/73wcQlnscKAN1/EnfF3Q2ZIFZmDtW0K5U9/PAaeSbD FVjMeuUOAtMvsbgs7y+9Mdkn4Cbre+DvFT7butZovRebNjzpP8SGLzg/oIjgZXN+TfnsrH81pCMGP /jjnYIdQ==; 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 1x4f6y-000YIP-1w; Thu, 10 Sep 2026 13:46:44 +0000 From: Breno Leitao Date: Thu, 10 Sep 2026 06:46:12 -0700 Subject: [PATCH net-next v2 3/4] 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: <20260910-netcons_ratelimit-v2-3-ebf0dd91e26e@debian.org> References: <20260910-netcons_ratelimit-v2-0-ebf0dd91e26e@debian.org> In-Reply-To: <20260910-netcons_ratelimit-v2-0-ebf0dd91e26e@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Shuah Khan Cc: Randy Dunlap , paulmck@kernel.org, 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, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-f8e9d X-Developer-Signature: v=1; a=openpgp-sha256; l=2285; i=leitao@debian.org; h=from:subject:message-id; bh=R7vwxfMtCdVEV0k2K5iBJN4LpKxwNZXOtaX277UogyE=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqorSvLBvF21kvR3NEZrcjPyifJdniLOajaP87d +IwbKaRUGOJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaqK0rwAKCRA1o5Of/Hh3 bUJ/D/0ZKBLlrzeUmiqB3H9HU3QKePR677ssjeFv+vQN3PlgZpRJ4vVamimxhhnxjlwscxA+DsA q+MOMlgrsEc40FF+pZ5Gv2GCWv0WQOSnv/PAw0pqY2ncCD/pJDyV4CdUJ7wYV2FgL5P2zLZ2pwn nXKusx2GbzsyoF/FVZvIEwUVQzCU5++ojWcv7/K4tOVmHbTPMMiBiOp3DSeGKZKNUPs2i5NR1WD 7cLjrWCxD55bym665xxuRxf+iyDUuEuxrcMyf8gmHaGrL1ERLgXVAvzF6pJcQWwL4ZmjqwRicQm z4dUpo/4K3NFQ3iOlatcD6eWzoGMw9VaTS4SiCSoApkX6+p4SzUsEtZNE45OlWE6nj/V2Q9TP/U ndwL2FK0qinEPClO4OzHIGbG3VHn20O4rVRTFNXIXHQmbcZ4MqWYRE4D0NefXj1//jM92EwzoU4 sOa/pBoT2sWeNNTgnPJx7JwYBIOHRQoH9Y+2UH5uP/fSsMR78Nzj0frgUfQQkaoPilj+oQhw6rh LDIRPTL/1e2AjfJ1iuEmcSgEf9kOdjmGy7PGSsd0nwEiZJJGEJYyZuzVEJw0ge5KdRyCCc0shu7 ujvnGM70mEcYCUW9jScpuB+15E0X6DkgbizKG2DR3oXRVtS7Y6nFt6axdas9HPaNLMZ9gWKByhk x7nRCbKVFQViKxA== 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 faf8f9bbc6c0c2..10e02b7c3f9cbb 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -953,6 +953,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) { @@ -1371,6 +1378,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]; @@ -1736,6 +1764,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, @@ -1750,6 +1779,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 Fri Sep 25 16:02:51 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 93CEF4A014B; Thu, 10 Sep 2026 13:46:52 +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=1789048014; cv=none; b=cezWTbxhkH1k5IxZiYZut0Og8fMBaBeDbZnRM3e18G6a5YxnSMAazjy/U6PTNCG81fpNc2MxAKCelkqUkUfx2mtNaCicyXQ7u2VQpVjqqBm6Iv+M8aRpc7xEM4D+zIderY5lf+ahTPo4jWD6yEETo2zniovPS1y6L2YfgOYsZCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789048014; c=relaxed/simple; bh=YweghrEN35d/HrIQDZzlztjwvxtnA6T6pjRwWdD/VPs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nsepmUYcPN3wniAc5eRJ6dshPUm8Z8Mq4+6MOyTJy6K+d5ulDL+/Jfg1kez4pm0Ri1UTJUBUgaIZkIInWUV/TFt6DIHml5Siktu67ngXCcbWnmU3BGrZP+fX8P6O2paIOszI4WRAESbjBkE8XyfcDifVZQxCqwkXBLLnzrlZ8k8= 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=emUrnd93; 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="emUrnd93" 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=6lGdzSD4TWF0V5JshmLHmzYOBwaLk4uPT6kfJ83UM0I=; b=emUrnd93Yuv4NEnksdN6lxuBsA tVtnv5Q7g5R6zpN3PRmLr1Cqz5U7IcQ4Tc9f3nGmWu5RuhS98UGEKZJqoUmEUPj5G35WDn65HSI/8 4cn8mhLBgZcczZrDYuzaEfbb5833XmrYVDfGWOnFxgYeNkKHbcjFwkyVg2Ezzi8ls9i/9zCWxDZmx 6tgEyp6fffjV5rQiOV9AeKp+IbaMQI3wTcYL9mxN1wfXBXd1QibPLtsPTcYfm+QBHvM7q0tFt49sE oRlYZ8LBI40m8arU6D8FkVPDt6rS+EghqVQ+LJpikgQ9HCn0VuTLLpRmpnXLZEFJriiqGBmVvzx5B vyiMb9Gg==; 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 1x4f73-000YIn-2e; Thu, 10 Sep 2026 13:46:50 +0000 From: Breno Leitao Date: Thu, 10 Sep 2026 06:46:13 -0700 Subject: [PATCH net-next v2 4/4] 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: <20260910-netcons_ratelimit-v2-4-ebf0dd91e26e@debian.org> References: <20260910-netcons_ratelimit-v2-0-ebf0dd91e26e@debian.org> In-Reply-To: <20260910-netcons_ratelimit-v2-0-ebf0dd91e26e@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Shuah Khan Cc: Randy Dunlap , paulmck@kernel.org, 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, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-f8e9d X-Developer-Signature: v=1; a=openpgp-sha256; l=3209; i=leitao@debian.org; h=from:subject:message-id; bh=YweghrEN35d/HrIQDZzlztjwvxtnA6T6pjRwWdD/VPs=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqorSvOedOtB9UAZ59DRyvRo3o8+LhENkpQBRXW XSVIz9YvN6JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaqK0rwAKCRA1o5Of/Hh3 bS0TEAClh/SWx9vqpLBePxbdQOQOMmR4vb3mi6OcbDYi8vnA8taJTN4KRz6OIB+ngdCVPd9SvN7 UcNF3tEH8cKSnXEBCFtgzrnRa4ZN5nDHNuVJS2sFx0/qoecMfRLIcK2ePonCjtFT4axIes4XQEC I0brZpUw0zTfyBgREuuhfbxAYYPMVIKawnS0QLO80L4bWpyyTrp3ywW+XTdYr8HmKhoTzAZbZg8 0x2aVgGBFqo6+ndo+dFF7pfV+HfoYBi4uhowYU2gIti/g0vVIMmMgby/hor1C/Z5IQ8BFPffADk zsF8qiSkcszDon2L8lzqw42J5KJadPpa3g8/FhG3iJhdMybitTH+jktxTAOxNpM23OFVB4AV4G2 DUt3bpyxntRpAxsFgtDszjZ3jrJv7I8TyVBtCSHY18M3iuDgJMtNlwUGwm4SkiXte1FH5P1af2M BvIkaNtISRrXuJg7z2vvJdq1CLUV/N7bgRBWLM1HjhuxZ6UjjW5AuoUIHrfsp96BjbZcqmqhzuK NK5a8oYWZz0rukX5vKZ8vwPtUcTOdJa8pT0tJMdgJhdJ+4WJYccpTe+njlchS6JV+ZmQOB6Iu5Q jLQzcfD8XWxoWVm2xfFnon0f5XQZ+wKrqk2bdced8Rf+SL2zOo4f+oIDGADdMhg+c+wCHhYptqH LyQCerzAFZdSSsw== 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. Note in the message ID section that a message the bucket discards never reaches the counter, so those drops leave no gap in the IDs. Signed-off-by: Breno Leitao --- Documentation/networking/netconsole.rst | 38 +++++++++++++++++++++++++++++= ++++ 1 file changed, 38 insertions(+) diff --git a/Documentation/networking/netconsole.rst b/Documentation/networ= king/netconsole.rst index 4ab5d7b05cf102..a9ccf798346562 100644 --- a/Documentation/networking/netconsole.rst +++ b/Documentation/networking/netconsole.rst @@ -177,6 +177,41 @@ 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 once an + interval is set. + =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. On an extended target it shows up as a = gap +in the sequence number the header carries; a basic target has no such mark= er. + +Capping a target at 500 messages a minute:: + + echo 60000 > ratelimit_interval_ms + echo 500 > ratelimit_burst + Append User Data ---------------- =20 @@ -359,6 +394,9 @@ indicate that a message was dropped during transmission= , as it may never have been sent via netconsole. The message ID, on the other hand, is only assig= ned to messages that are actually transmitted via netconsole. =20 +A message the target's rate limit discards is dropped before the ID is +assigned, so those drops leave no gap in the sequence of IDs either. + Example:: =20 echo "This is message #1" > /dev/kmsg --=20 2.53.0-Meta