lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu,  9 Dec 2021 00:32:27 +0200
From:   Vladimir Oltean <vladimir.oltean@....com>
To:     netdev@...r.kernel.org
Cc:     "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>, Andrew Lunn <andrew@...n.ch>,
        Vivien Didelot <vivien.didelot@...il.com>,
        Florian Fainelli <f.fainelli@...il.com>,
        Ansuel Smith <ansuelsmth@...il.com>
Subject: [RFC PATCH net-next 4/7] net: dsa: provide switch operations for tracking the master state

Certain drivers may need to send management traffic to the switch for
things like register access, FDB dump, etc, to accelerate what their
slow bus (SPI, I2C, MDIO) can already do.

Ethernet is faster (especially in bulk transactions) but is also more
unreliable, since the user may decide to bring the DSA master down (or
not bring it up), therefore severing the link between the host and the
attached switch.

Drivers needing Ethernet-based register access already should have
fallback logic to the slow bus if the Ethernet method fails, but that
fallback may be based on a timeout, and the I/O to the switch may slow
down to a halt if the master is down, because every Ethernet packet will
have to time out. The driver also doesn't have the option to turn off
Ethernet-based I/O momentarily, because it wouldn't know when to turn it
back on.

Which is where this change comes in. By tracking NETDEV_UP and
NETDEV_GOING_DOWN events on the DSA master, we should know when this
interface becomes available for traffic. Provide this information to
switches so they can use it as they wish.

Signed-off-by: Vladimir Oltean <vladimir.oltean@....com>
---
 include/net/dsa.h  |  8 ++++++++
 net/dsa/dsa2.c     | 14 ++++++++++++++
 net/dsa/dsa_priv.h |  9 +++++++++
 net/dsa/slave.c    | 12 ++++++++++++
 net/dsa/switch.c   | 29 +++++++++++++++++++++++++++++
 5 files changed, 72 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index bdf308a5c55e..65aef079b156 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -1011,6 +1011,14 @@ struct dsa_switch_ops {
 	int	(*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid,
 				      u16 flags);
 	int	(*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid);
+
+	/*
+	 * DSA master tracking operations
+	 */
+	void	(*master_up)(struct dsa_switch *ds,
+			     const struct net_device *master);
+	void	(*master_going_down)(struct dsa_switch *ds,
+				     const struct net_device *master);
 };
 
 #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes)		\
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 9c490a326e6f..fe3a3d05ee24 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -1187,12 +1187,26 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
 	return err;
 }
 
+void dsa_tree_master_up(struct dsa_switch_tree *dst, struct net_device *master)
+{
+	struct dsa_notifier_master_state_info info = {
+		.master = master,
+	};
+
+	dsa_tree_notify(dst, DSA_NOTIFIER_MASTER_UP, &info);
+}
+
 void dsa_tree_master_going_down(struct dsa_switch_tree *dst,
 				struct net_device *master)
 {
 	struct dsa_port *dp, *cpu_dp = master->dsa_ptr;
+	struct dsa_notifier_master_state_info info = {
+		.master = master,
+	};
 	LIST_HEAD(close_list);
 
+	dsa_tree_notify(dst, DSA_NOTIFIER_MASTER_GOING_DOWN, &info);
+
 	dsa_tree_for_each_user_port(dp, dst) {
 		if (dp->cpu_dp != cpu_dp)
 			continue;
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 21bd11b9d706..107f934ca592 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -43,6 +43,8 @@ enum {
 	DSA_NOTIFIER_MRP_DEL_RING_ROLE,
 	DSA_NOTIFIER_TAG_8021Q_VLAN_ADD,
 	DSA_NOTIFIER_TAG_8021Q_VLAN_DEL,
+	DSA_NOTIFIER_MASTER_UP,
+	DSA_NOTIFIER_MASTER_GOING_DOWN,
 };
 
 /* DSA_NOTIFIER_AGEING_TIME */
@@ -126,6 +128,12 @@ struct dsa_notifier_tag_8021q_vlan_info {
 	u16 vid;
 };
 
+/* DSA_NOTIFIER_MASTER_* */
+struct dsa_notifier_master_state_info {
+	const struct net_device *master;
+	struct netlink_ext_ack *extack;
+};
+
 struct dsa_switchdev_event_work {
 	struct dsa_switch *ds;
 	int port;
@@ -506,6 +514,7 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
 			      struct net_device *master,
 			      const struct dsa_device_ops *tag_ops,
 			      const struct dsa_device_ops *old_tag_ops);
+void dsa_tree_master_up(struct dsa_switch_tree *dst, struct net_device *master);
 void dsa_tree_master_going_down(struct dsa_switch_tree *dst,
 				struct net_device *master);
 unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 4b91157790bb..ff0e8a173996 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -2349,6 +2349,18 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb,
 		err = dsa_port_lag_change(dp, info->lower_state_info);
 		return notifier_from_errno(err);
 	}
+	case NETDEV_UP: {
+		if (netdev_uses_dsa(dev)) {
+			struct dsa_port *cpu_dp = dev->dsa_ptr;
+			struct dsa_switch_tree *dst = cpu_dp->ds->dst;
+
+			dsa_tree_master_up(dst, dev);
+
+			return NOTIFY_OK;
+		}
+
+		return NOTIFY_OK;
+	}
 	case NETDEV_GOING_DOWN: {
 		if (netdev_uses_dsa(dev)) {
 			struct dsa_port *cpu_dp = dev->dsa_ptr;
diff --git a/net/dsa/switch.c b/net/dsa/switch.c
index 9c92edd96961..553b67478428 100644
--- a/net/dsa/switch.c
+++ b/net/dsa/switch.c
@@ -699,6 +699,29 @@ dsa_switch_mrp_del_ring_role(struct dsa_switch *ds,
 	return 0;
 }
 
+static int dsa_switch_master_up(struct dsa_switch *ds,
+				struct dsa_notifier_master_state_info *info)
+{
+	if (!ds->ops->master_up)
+		return 0;
+
+	ds->ops->master_up(ds, info->master);
+
+	return 0;
+}
+
+static int
+dsa_switch_master_going_down(struct dsa_switch *ds,
+			     struct dsa_notifier_master_state_info *info)
+{
+	if (!ds->ops->master_going_down)
+		return 0;
+
+	ds->ops->master_going_down(ds, info->master);
+
+	return 0;
+}
+
 static int dsa_switch_event(struct notifier_block *nb,
 			    unsigned long event, void *info)
 {
@@ -784,6 +807,12 @@ static int dsa_switch_event(struct notifier_block *nb,
 	case DSA_NOTIFIER_TAG_8021Q_VLAN_DEL:
 		err = dsa_switch_tag_8021q_vlan_del(ds, info);
 		break;
+	case DSA_NOTIFIER_MASTER_UP:
+		err = dsa_switch_master_up(ds, info);
+		break;
+	case DSA_NOTIFIER_MASTER_GOING_DOWN:
+		err = dsa_switch_master_going_down(ds, info);
+		break;
 	default:
 		err = -EOPNOTSUPP;
 		break;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ