-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: dsa: replace NETDEV_PRE_CHANGE_HWTSTAMP notifier with a stub
There was a sort of rush surrounding commit 88c0a6b ("net: create a netdev notifier for DSA to reject PTP on DSA master"), due to a desire to convert DSA's attempt to deny TX timestamping on a DSA master to something that doesn't block the kernel-wide API conversion from ndo_eth_ioctl() to ndo_hwtstamp_set(). What was required was a mechanism that did not depend on ndo_eth_ioctl(), and what was provided was a mechanism that did not depend on ndo_eth_ioctl(), while at the same time introducing something that wasn't absolutely necessary - a new netdev notifier. There have been objections from Jakub Kicinski that using notifiers in general when they are not absolutely necessary creates complications to the control flow and difficulties to maintainers who look at the code. So there is a desire to not use notifiers. In addition to that, the notifier chain gets called even if there is no DSA in the system and no one is interested in applying any restriction. Take the model of udp_tunnel_nic_ops and introduce a stub mechanism, through which net/core/dev_ioctl.c can call into DSA even when CONFIG_NET_DSA=m. Compared to the code that existed prior to the notifier conversion, aka what was added in commits: - 4cfab35 ("net: dsa: Add wrappers for overloaded ndo_ops") - 3369afb ("net: Call into DSA netdevice_ops wrappers") this is different because we are not overloading any struct net_device_ops of the DSA master anymore, but rather, we are exposing a rather specific functionality which is orthogonal to which API is used to enable it - ndo_eth_ioctl() or ndo_hwtstamp_set(). Also, what is similar is that both approaches use function pointers to get from built-in code to DSA. There is no point in replicating the function pointers towards __dsa_master_hwtstamp_validate() once for every CPU port (dev->dsa_ptr). Instead, it is sufficient to introduce a singleton struct dsa_stubs, built into the kernel, which contains a single function pointer to __dsa_master_hwtstamp_validate(). I find this approach preferable to what we had originally, because dev->dsa_ptr->netdev_ops->ndo_do_ioctl() used to require going through struct dsa_port (dev->dsa_ptr), and so, this was incompatible with any attempts to add any data encapsulation and hide DSA data structures from the outside world. Link: https://lore.kernel.org/netdev/20230403083019.120b72fd@kernel.org/ Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Vladimir Oltean
authored and
David S. Miller
committed
Apr 9, 2023
1 parent
48b7ea1
commit 5a17818
Showing
11 changed files
with
89 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* include/net/dsa_stubs.h - Stubs for the Distributed Switch Architecture framework | ||
*/ | ||
|
||
#include <linux/mutex.h> | ||
#include <linux/netdevice.h> | ||
#include <linux/net_tstamp.h> | ||
#include <net/dsa.h> | ||
|
||
#if IS_ENABLED(CONFIG_NET_DSA) | ||
|
||
extern const struct dsa_stubs *dsa_stubs; | ||
|
||
struct dsa_stubs { | ||
int (*master_hwtstamp_validate)(struct net_device *dev, | ||
const struct kernel_hwtstamp_config *config, | ||
struct netlink_ext_ack *extack); | ||
}; | ||
|
||
static inline int dsa_master_hwtstamp_validate(struct net_device *dev, | ||
const struct kernel_hwtstamp_config *config, | ||
struct netlink_ext_ack *extack) | ||
{ | ||
if (!netdev_uses_dsa(dev)) | ||
return 0; | ||
|
||
/* rtnl_lock() is a sufficient guarantee, because as long as | ||
* netdev_uses_dsa() returns true, the dsa_core module is still | ||
* registered, and so, dsa_unregister_stubs() couldn't have run. | ||
* For netdev_uses_dsa() to start returning false, it would imply that | ||
* dsa_master_teardown() has executed, which requires rtnl_lock(). | ||
*/ | ||
ASSERT_RTNL(); | ||
|
||
return dsa_stubs->master_hwtstamp_validate(dev, config, extack); | ||
} | ||
|
||
#else | ||
|
||
static inline int dsa_master_hwtstamp_validate(struct net_device *dev, | ||
const struct kernel_hwtstamp_config *config, | ||
struct netlink_ext_ack *extack) | ||
{ | ||
return 0; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Stubs for DSA functionality called by the core network stack. | ||
* These are necessary because CONFIG_NET_DSA can be a module, and built-in | ||
* code cannot directly call symbols exported by modules. | ||
*/ | ||
#include <net/dsa_stubs.h> | ||
|
||
const struct dsa_stubs *dsa_stubs; | ||
EXPORT_SYMBOL_GPL(dsa_stubs); |