net: dsa: Setup dsa_netdev_ops
Subsystems (3)
v2 cover net: dsa: Setup dsa_netdev_ops
Hi David, Jakub,
This patch series addresses the overloading of a DSA CPU/management interface's netdev_ops for the purpose of providing useful information from the switch side.
Up until now we had duplicated the existing netdev_ops structure and added specific function pointers to return information of interest. Here we have a more controlled way of doing this by involving the specific netdev_ops function pointers that we want to be patched, which is easier for auditing code in the future. As a byproduct we can now maintain netdev_ops pointer comparisons which would be failing before (no known in tree problems because of that though).
Let me know if this approach looks reasonable to you and we might do the same with our ethtool_ops overloading as well.
Thanks!
Changes in v2:
- use static inline int vs. static int inline (Kbuild robot)
- fixed typos in patch 4 (Andrew)
- avoid using macros (Andrew)
Florian Fainelli (4):
net: Wrap ndo_do_ioctl() to prepare for DSA stacked ops
net: dsa: Add wrappers for overloaded ndo_ops
net: Call into DSA netdevice_ops wrappers
net: dsa: Setup dsa_netdev_ops
include/net/dsa.h | 71 +++++++++++++++++++++++++++++++++++++++++++- net/core/dev.c | 5 ++++ net/core/dev_ioctl.c | 29 +++++++++++++----- net/dsa/master.c | 52 ++++++++------------------------ 4 files changed, 110 insertions(+), 47 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/4 net: Wrap ndo_do_ioctl() to prepare for DSA stacked ops
In preparation for adding another layer of call into a DSA stacked ops singleton, wrap the ndo_do_ioctl() call into dev_do_ioctl().
--- net/core/dev_ioctl.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
net/core/dev_ioctl.c +17 -7
@@ -225,6 +225,22 @@ static int net_hwtstamp_validate(struct ifreq *ifr)return 0 ; } +static int dev_do_ioctl (struct net_device *dev, +struct ifreq *ifr,unsigned int cmd) +{ +const struct net_device_ops *ops = dev->netdev_ops; +int err = -EOPNOTSUPP ; + +if (ops->ndo_do_ioctl) { +if (netif_device_present (dev)) + err = ops->ndo_do_ioctl (dev, ifr, cmd); +else + err = -ENODEV ; + } + +return err; +} +/* * Perform the SIOCxIFxxx calls, inside rtnl_lock() */
@@ -323,13 +339,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) cmd == SIOCSHWTSTAMP || cmd == SIOCGHWTSTAMP || cmd == SIOCWANDEV) { - err = -EOPNOTSUPP ; -if (ops->ndo_do_ioctl) { -if (netif_device_present (dev)) - err = ops->ndo_do_ioctl (dev, ifr, cmd); -else - err = -ENODEV ; - } + err =dev_do_ioctl (dev, ifr, cmd); } else err = -EINVAL ;
Signature · 1 line
2.25.1
PATCH v2 2/4 net: dsa: Add wrappers for overloaded ndo_ops
In reply to Florian FainelliAdd definitions for the dsa_netdevice_ops structure which is a subset of the net_device_ops structure for the specific operations that we care about overlaying on top of the DSA CPU port net_device and provide inline stubs that take core managing whether DSA code is reachable.
--- include/net/dsa.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)
include/net/dsa.h +70 -0
@@ -86,6 +86,18 @@ struct dsa_device_ops {enum dsa_tag_protocol proto; }; +/* This structure defines the control interfaces that are overlayed by the +* DSA layer on top of the DSA CPU/management net_device instance. This is +* used by the core net_device layer while calling various net_device_ops +* function pointers. +*/ +struct dsa_netdevice_ops { +int (*ndo_do_ioctl)(struct net_device *dev,struct ifreq *ifr, +int cmd); +int (*ndo_get_phys_port_name)(struct net_device *dev,char *name, +size_t len); +}; +#define DSA_TAG_DRIVER_ALIAS "dsa_tag-"#define MODULE_ALIAS_DSA_TAG_DRIVER (__proto) \ MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE))
@@ -217,6 +229,7 @@ struct dsa_port {/* * Original copy of the master netdev net_device_ops */ +const struct dsa_netdevice_ops *netdev_ops;const struct net_device_ops *orig_ndo_ops;bool setup;
@@ -679,6 +692,63 @@ static inline bool dsa_can_decode(const struct sk_buff *skb,return false; } +#if IS_ENABLED (CONFIG_NET_DSA ) +static inline int __dsa_netdevice_ops_check (struct net_device *dev) +{ +int err = -EOPNOTSUPP ; + +if (!dev->dsa_ptr) +return err; + +if (!dev->dsa_ptr->netdev_ops) +return err; + +return 0 ; +} + +static inline int dsa_ndo_do_ioctl (struct net_device *dev,struct ifreq *ifr, +int cmd) +{ +const struct dsa_netdevice_ops *ops; +int err; + + err =__dsa_netdevice_ops_check (dev); +if (err) +return err; + + ops = dev->dsa_ptr->netdev_ops; + +return ops->ndo_do_ioctl (dev, ifr, cmd); +} + +static inline int dsa_ndo_get_phys_port_name (struct net_device *dev, +char *name,size_t len) +{ +const struct dsa_netdevice_ops *ops; +int err; + + err =__dsa_netdevice_ops_check (dev); +if (err) +return err; + + ops = dev->dsa_ptr->netdev_ops; + +return ops->ndo_get_phys_port_name (dev, name, len); +} +#else +static inline int dsa_ndo_do_ioctl (struct net_device *dev,struct ifreq *ifr, +int cmd) +{ +return -EOPNOTSUPP ; +} + +static inline int dsa_ndo_get_phys_port_name (struct net_device *dev, +char *name,size_t len) +{ +return -EOPNOTSUPP ; +} +#endif +void dsa_unregister_switch (struct dsa_switch *ds);int dsa_register_switch (struct dsa_switch *ds);struct dsa_switch *dsa_switch_find (int tree_index,int sw_index);
Signature · 1 line
2.25.1
PATCH v2 4/4 net: dsa: Setup dsa_netdev_ops
In reply to Florian FainelliNow that we have all the infrastructure in place for calling into the dsa_ptr->netdev_ops function pointers, install them when we configure the DSA CPU/management interface and tear them down. The flow is unchanged from before, but now we preserve equality of tests when network device drivers do tests like dev->netdev_ops == &foo_ops which was not the case before since we were allocating an entirely new structure.
--- include/net/dsa.h | 1 - net/dsa/master.c | 52 ++++++++++++----------------------------------- 2 files changed, 13 insertions(+), 40 deletions(-)
include/net/dsa.h +0 -1
@@ -230,7 +230,6 @@ struct dsa_port {* Original copy of the master netdev net_device_ops */ const struct dsa_netdevice_ops *netdev_ops; -const struct net_device_ops *orig_ndo_ops;bool setup; };
net/dsa/master.c +13 -39
87 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 3/4 net: Call into DSA netdevice_ops wrappers
In reply to Florian FainelliMake the core net_device code call into our ndo_do_ioctl() and ndo_get_phys_port_name() functions via the wrappers defined previously
--- net/core/dev.c | 5 +++++ net/core/dev_ioctl.c | 5 +++++ 2 files changed, 10 insertions(+)
net/core/dev.c +5 -0
@@ -98,6 +98,7 @@#include <net/busy_poll.h> #include <linux/rtnetlink.h> #include <linux/stat.h> +#include <net/dsa.h> #include <net/dst.h> #include <net/dst_metadata.h> #include <net/pkt_sched.h>
@@ -8602,6 +8603,10 @@ int dev_get_phys_port_name(struct net_device *dev,const struct net_device_ops *ops = dev->netdev_ops;int err; + err =dsa_ndo_get_phys_port_name (dev, name, len); +if (err ==0 || err != -EOPNOTSUPP ) +return err; +if (ops->ndo_get_phys_port_name) { err = ops->ndo_get_phys_port_name (dev, name, len);if (err != -EOPNOTSUPP )
net/core/dev_ioctl.c +5 -0
@@ -5,6 +5,7 @@#include <linux/rtnetlink.h> #include <linux/net_tstamp.h> #include <linux/wireless.h> +#include <net/dsa.h> #include <net/wext.h> /*
@@ -231,6 +232,10 @@ static int dev_do_ioctl(struct net_device *dev,const struct net_device_ops *ops = dev->netdev_ops;int err = -EOPNOTSUPP ; + err =dsa_ndo_do_ioctl (dev, ifr, cmd); +if (err ==0 || err != -EOPNOTSUPP ) +return err; +if (ops->ndo_do_ioctl) {if (netif_device_present (dev)) err = ops->ndo_do_ioctl (dev, ifr, cmd);
Signature · 1 line
2.25.1
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Sun, 19 Jul 2020 20:49:50 -0700
Quoted 12 lines
This patch series addresses the overloading of a DSA CPU/management interface's
netdev_opsfor the purpose of providing useful information from the switch side.Up until now we had duplicated the existing
netdev_opsstructure and added specific function pointers to return information of interest. Here we have a more controlled way of doing this by involving the specificnetdev_opsfunction pointers that we want to be patched, which is easier for auditing code in the future. As a byproduct we can now maintainnetdev_opspointer comparisons which would be failing before (no known in tree problems because of that though).
Quoted 2 lines
Let me know if this approach looks reasonable to you and we might do the same with our
ethtool_opsoverloading as well.
This looks good to me, series applied.
And yes, doing something similar for ethtool_ops is probably a good idea too.