[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251103194631.3393020-2-florian.fainelli@broadcom.com>
Date: Mon, 3 Nov 2025 11:46:30 -0800
From: Florian Fainelli <florian.fainelli@...adcom.com>
To: netdev@...r.kernel.org
Cc: bcm-kernel-feedback-list@...adcom.com,
Florian Fainelli <florian.fainelli@...adcom.com>,
Doug Berger <opendmb@...il.com>,
Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>,
Antoine Tenart <atenart@...nel.org>,
Kuniyuki Iwashima <kuniyu@...gle.com>,
Yajun Deng <yajun.deng@...ux.dev>,
linux-kernel@...r.kernel.org (open list)
Subject: [PATCH net-next 1/2] net: ethernet: Allow disabling pause on panic
Development devices on a lab network might be subject to kernel panics
and if they have pause frame generation enabled, once the kernel panics,
the Ethernet controller stops being serviced. This can create a flood of
pause frames that certain switches are unable to handle resulting a
completle paralysis of the network.
To accomodate for such situation introduce a
/sys/class/net/<device>/disable_pause_on_panic knob which will disable
Ethernet pause frame generation upon kernel panic.
Note that device driver wishing to make use of that feature need to be
mindful of the fact that ethtool_ops::set_pauseparam may now be called
from atomic context.
Signed-off-by: Florian Fainelli <florian.fainelli@...adcom.com>
---
Documentation/ABI/testing/sysfs-class-net | 16 ++++
include/linux/netdevice.h | 1 +
net/core/net-sysfs.c | 34 ++++++++
net/ethernet/Makefile | 3 +-
net/ethernet/pause_panic.c | 95 +++++++++++++++++++++++
5 files changed, 148 insertions(+), 1 deletion(-)
create mode 100644 net/ethernet/pause_panic.c
diff --git a/Documentation/ABI/testing/sysfs-class-net b/Documentation/ABI/testing/sysfs-class-net
index ebf21beba846..f762ce439203 100644
--- a/Documentation/ABI/testing/sysfs-class-net
+++ b/Documentation/ABI/testing/sysfs-class-net
@@ -352,3 +352,19 @@ Description:
0 threaded mode disabled for this dev
1 threaded mode enabled for this dev
== ==================================
+
+What: /sys/class/net/<iface>/disable_pause_on_panic
+Date: Nov 2025
+KernelVersion: 6.20
+Contact: netdev@...r.kernel.org
+Description:
+ Boolean value to control whether to disable pause frame
+ generation on panic. This is helpful in environments where
+ the link partner may incorrect respond to pause frames (e.g.:
+ improperly configured Ethernet switches)
+
+ Possible values:
+ == ==================================
+ 0 threaded mode disabled for this dev
+ 1 threaded mode enabled for this dev
+ == ==================================
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 9c1e5042c5e7..7af0944aada2 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2439,6 +2439,7 @@ struct net_device {
bool proto_down;
bool irq_affinity_auto;
bool rx_cpu_rmap_auto;
+ bool disable_pause_on_panic;
/* priv_flags_slow, ungrouped to save space */
unsigned long see_all_hwtstamp_requests:1;
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index ca878525ad7c..c01dc3e200d8 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -770,6 +770,39 @@ static ssize_t threaded_store(struct device *dev,
}
static DEVICE_ATTR_RW(threaded);
+static ssize_t disable_pause_on_panic_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct net_device *ndev = to_net_dev(dev);
+ ssize_t ret = -EINVAL;
+
+ rcu_read_lock();
+ if (dev_isalive(ndev))
+ ret = sysfs_emit(buf, fmt_dec, READ_ONCE(ndev->disable_pause_on_panic));
+ rcu_read_unlock();
+
+ return ret;
+}
+
+static int modify_disable_pause_on_panic(struct net_device *dev, unsigned long val)
+{
+ if (val != 0 && val != 1)
+ return -EINVAL;
+
+ WRITE_ONCE(dev->disable_pause_on_panic, val);
+
+ return 0;
+}
+
+static ssize_t disable_pause_on_panic_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ return netdev_store(dev, attr, buf, len, modify_disable_pause_on_panic);
+}
+static DEVICE_ATTR_RW(disable_pause_on_panic);
+
static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_netdev_group.attr,
&dev_attr_type.attr,
@@ -800,6 +833,7 @@ static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_carrier_up_count.attr,
&dev_attr_carrier_down_count.attr,
&dev_attr_threaded.attr,
+ &dev_attr_disable_pause_on_panic.attr,
NULL,
};
ATTRIBUTE_GROUPS(net_class);
diff --git a/net/ethernet/Makefile b/net/ethernet/Makefile
index e03eff94e0db..9b1f3ff8695a 100644
--- a/net/ethernet/Makefile
+++ b/net/ethernet/Makefile
@@ -3,4 +3,5 @@
# Makefile for the Linux Ethernet layer.
#
-obj-y += eth.o
+obj-y += eth.o \
+ pause_panic.o
diff --git a/net/ethernet/pause_panic.c b/net/ethernet/pause_panic.c
new file mode 100644
index 000000000000..ed859b443b00
--- /dev/null
+++ b/net/ethernet/pause_panic.c
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Ethernet pause disable on panic handler
+ *
+ * This module provides per-device control via sysfs to disable Ethernet flow
+ * control (pause frames) on individual Ethernet devices when the kernel panics.
+ * Each device can be configured via /sys/class/net/<device>/disable_pause_on_panic.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/panic_notifier.h>
+#include <linux/netdevice.h>
+#include <linux/ethtool.h>
+#include <linux/notifier.h>
+#include <linux/if_ether.h>
+#include <net/net_namespace.h>
+
+/*
+ * Disable pause/flow control on a single Ethernet device.
+ * This is called from panic context, so we cannot sleep.
+ * We try to call set_pauseparam, but if it would require sleeping,
+ * we skip the device rather than risk deadlock.
+ */
+static void disable_pause_on_device(struct net_device *dev)
+{
+ struct ethtool_pauseparam pause = { };
+ const struct ethtool_ops *ops;
+
+ /* Only proceed if this device has the flag enabled */
+ if (!READ_ONCE(dev->disable_pause_on_panic))
+ return;
+
+ ops = dev->ethtool_ops;
+ if (!ops || !ops->set_pauseparam)
+ return;
+
+ /* Prepare pause parameters to disable flow control */
+ pause.autoneg = 0;
+ pause.rx_pause = 0;
+ pause.tx_pause = 0;
+
+ /*
+ * In panic context, we're in atomic context and cannot sleep.
+ * We try to call set_pauseparam directly. If it would sleep,
+ * that's a driver bug, but we proceed anyway since we're panicking.
+ * The driver's set_pauseparam implementation should ideally handle
+ * atomic context, but if it doesn't, we can't do much about it
+ * during a panic.
+ */
+ ops->set_pauseparam(dev, &pause);
+}
+
+/*
+ * Panic notifier to disable pause frames on all Ethernet devices.
+ * Called in atomic context during kernel panic.
+ */
+static int eth_pause_panic_handler(struct notifier_block *this,
+ unsigned long event, void *ptr)
+{
+ struct net_device *dev;
+
+ /*
+ * Iterate over all network devices in the init namespace.
+ * In panic context, we cannot acquire locks that might sleep,
+ * so we use RCU iteration.
+ * Each device will check its own disable_pause_on_panic flag.
+ */
+ rcu_read_lock();
+ for_each_netdev_rcu(&init_net, dev) {
+ /* Reference count might not be available in panic */
+ if (!dev)
+ continue;
+
+ disable_pause_on_device(dev);
+ }
+ rcu_read_unlock();
+
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block eth_pause_panic_notifier = {
+ .notifier_call = eth_pause_panic_handler,
+ .priority = INT_MAX, /* Run as late as possible */
+};
+
+static int __init eth_pause_panic_init(void)
+{
+ /* Register panic notifier */
+ atomic_notifier_chain_register(&panic_notifier_list,
+ ð_pause_panic_notifier);
+
+ return 0;
+}
+device_initcall(eth_pause_panic_init);
--
2.34.1
Powered by blists - more mailing lists