mirror of
https://github.com/torvalds/linux.git
synced 2026-10-28 09:35:02 +01:00
An offline self test that brings the interface down and back up with
netif_close() / netif_open() requires rtnl_lock for both. Since the
ethtool IOCTL path became rtnl-optional for ops-locked drivers, the
ETHTOOL_TEST ioctl runs holding only the netdev instance lock, so on an
ops-locked driver the self test now tears the device down without
rtnl_lock.
With lockdep this reproduces deterministically on every offline self
test on such a driver; note the sole lock held is the instance lock, not
rtnl:
WARNING: suspicious RCU usage
net/core/netpoll.c:207 suspicious rcu_dereference_protected() usage!
1 lock held by ethtool/107:
#0: (&dev->lock){+.+.}, at: dev_ethtool
Call Trace:
netpoll_poll_disable
__dev_close_many
netif_close_many
netif_close
fbnic_self_test
dev_ethtool_locked
dev_ethtool
dev_ioctl
sock_ioctl
__x64_sys_ioctl
Without lockdep the same condition trips ASSERT_RTNL() in
__dev_close_many() / __dev_open(); that check only samples the global
rtnl state, so it can be masked by a concurrent rtnl holder, but the
device is still being reconfigured without the lock it requires.
The ethtool self_test is a legacy ioctl-only command, so an ETHTOOL_TEST
case is only needed on the ioctl path. Add an opt-in bit for drivers whose
self test needs rtnl_lock and set it on the ops-locked drivers whose
offline self test tears the interface down and up:
- fbnic (ops-locked via queue_mgmt_ops): fbnic_self_test() offline path
uses netif_close() / netif_open().
- bnxt (ops-locked via queue_mgmt_ops): bnxt_self_test() offline path
goes through bnxt_close_nic() / bnxt_half_open_nic() /
bnxt_half_close_nic() / bnxt_open_nic(), which close and reopen the
device.
Fixes: f994752b11 ("net: ethtool: optionally skip rtnl_lock on IOCTL path")
Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/178942019771.7700.338431553546884773.stgit@ahduyck-xeon-server.home.arpa
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
182 lines
6.4 KiB
C
182 lines
6.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
#ifndef _ETHTOOL_COMMON_H
|
|
#define _ETHTOOL_COMMON_H
|
|
|
|
#include <linux/netdevice.h>
|
|
#include <linux/ethtool.h>
|
|
|
|
#define ETHTOOL_DEV_FEATURE_WORDS DIV_ROUND_UP(NETDEV_FEATURE_COUNT, 32)
|
|
|
|
/* compose link mode index from speed, type and duplex */
|
|
#define ETHTOOL_LINK_MODE(speed, type, duplex) \
|
|
ETHTOOL_LINK_MODE_ ## speed ## base ## type ## _ ## duplex ## _BIT
|
|
|
|
#define __SOF_TIMESTAMPING_CNT (const_ilog2(SOF_TIMESTAMPING_LAST) + 1)
|
|
#define __HWTSTAMP_FLAG_CNT (const_ilog2(HWTSTAMP_FLAG_LAST) + 1)
|
|
|
|
struct genl_info;
|
|
struct hwtstamp_provider_desc;
|
|
|
|
extern const char
|
|
netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN];
|
|
extern const char
|
|
rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN];
|
|
extern const char
|
|
tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN];
|
|
extern const char
|
|
phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
|
|
extern const char link_mode_names[][ETH_GSTRING_LEN];
|
|
extern const char netif_msg_class_names[][ETH_GSTRING_LEN];
|
|
extern const char wol_mode_names[][ETH_GSTRING_LEN];
|
|
extern const char sof_timestamping_names[][ETH_GSTRING_LEN];
|
|
extern const char ts_tx_type_names[][ETH_GSTRING_LEN];
|
|
extern const char ts_rx_filter_names[][ETH_GSTRING_LEN];
|
|
extern const char ts_flags_names[][ETH_GSTRING_LEN];
|
|
extern const char udp_tunnel_type_names[][ETH_GSTRING_LEN];
|
|
|
|
int __ethtool_get_link(struct net_device *dev);
|
|
|
|
bool convert_legacy_settings_to_link_ksettings(
|
|
struct ethtool_link_ksettings *link_ksettings,
|
|
const struct ethtool_cmd *legacy_settings);
|
|
int ethtool_check_max_channel(struct net_device *dev,
|
|
struct ethtool_channels channels,
|
|
struct genl_info *info);
|
|
struct ethtool_rxfh_context *
|
|
ethtool_rxfh_ctx_alloc(const struct ethtool_ops *ops,
|
|
u32 indir_size, u32 key_size);
|
|
int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context);
|
|
int ethtool_rxfh_config_is_sym(u64 rxfh);
|
|
|
|
void ethtool_ringparam_get_cfg(struct net_device *dev,
|
|
struct ethtool_ringparam *param,
|
|
struct kernel_ethtool_ringparam *kparam,
|
|
struct netlink_ext_ack *extack);
|
|
|
|
int ethtool_get_rx_ring_count(struct net_device *dev);
|
|
|
|
int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info);
|
|
int ethtool_get_ts_info_by_phc(struct net_device *dev,
|
|
struct kernel_ethtool_ts_info *info,
|
|
struct hwtstamp_provider_desc *hwprov_desc);
|
|
int ethtool_net_get_ts_info_by_phc(struct net_device *dev,
|
|
struct kernel_ethtool_ts_info *info,
|
|
struct hwtstamp_provider_desc *hwprov_desc);
|
|
struct phy_device *
|
|
ethtool_phy_get_ts_info_by_phc(struct net_device *dev,
|
|
struct kernel_ethtool_ts_info *info,
|
|
struct hwtstamp_provider_desc *hwprov_desc);
|
|
bool net_support_hwtstamp_qualifier(struct net_device *dev,
|
|
enum hwtstamp_provider_qualifier qualifier);
|
|
|
|
extern const struct ethtool_phy_ops *ethtool_phy_ops;
|
|
extern const struct ethtool_pse_ops *ethtool_pse_ops;
|
|
|
|
int ethtool_get_module_info_call(struct net_device *dev,
|
|
struct ethtool_modinfo *modinfo);
|
|
int ethtool_get_module_eeprom_call(struct net_device *dev,
|
|
struct ethtool_eeprom *ee, u8 *data);
|
|
|
|
bool __ethtool_dev_mm_supported(struct net_device *dev);
|
|
|
|
/**
|
|
* ethtool_nl_msg_needs_rtnl() - does this Netlink cmd need rtnl_lock?
|
|
* @dev: target device
|
|
* @cmd: ETHTOOL_MSG_* Netlink command value
|
|
*
|
|
* Return: true if @cmd is a command for which @dev has opted-in to
|
|
* keeping rtnl_lock held across the call (via op_needs_rtnl).
|
|
*/
|
|
static inline bool
|
|
ethtool_nl_msg_needs_rtnl(const struct net_device *dev, u8 cmd)
|
|
{
|
|
const struct ethtool_ops *ops = dev->ethtool_ops;
|
|
|
|
switch (cmd) {
|
|
case ETHTOOL_MSG_LINKINFO_GET:
|
|
case ETHTOOL_MSG_LINKINFO_SET:
|
|
case ETHTOOL_MSG_LINKMODES_GET:
|
|
case ETHTOOL_MSG_LINKMODES_SET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_LINKSETTINGS;
|
|
case ETHTOOL_MSG_PRIVFLAGS_SET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SPFLAGS;
|
|
case ETHTOOL_MSG_RINGS_SET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SRINGPARAM;
|
|
case ETHTOOL_MSG_CHANNELS_SET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SCHANNELS;
|
|
case ETHTOOL_MSG_COALESCE_SET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SCOALESCE;
|
|
case ETHTOOL_MSG_PAUSE_GET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_GPAUSEPARAM;
|
|
case ETHTOOL_MSG_PAUSE_SET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SPAUSEPARAM;
|
|
case ETHTOOL_MSG_RSS_SET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_RSS;
|
|
case ETHTOOL_MSG_LINKSTATE_GET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_GLINK;
|
|
case ETHTOOL_MSG_TSCONFIG_GET:
|
|
case ETHTOOL_MSG_TSCONFIG_SET:
|
|
/* tsconfig calls ndos (ndo_hwtstamp_set/get), not ethtool ops.
|
|
* Also, there is no corresponding ethtool ioctl, therefore
|
|
* these cases are Netlink-only.
|
|
*/
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* ethtool_ioctl_needs_rtnl() - does this legacy ioctl cmd need rtnl_lock?
|
|
* @dev: target device
|
|
* @ethcmd: ETHTOOL_* ioctl command value
|
|
*
|
|
* Return: true if @ethcmd is a command for which @dev has opted-in to
|
|
* keeping rtnl_lock held across the call (via op_needs_rtnl).
|
|
*/
|
|
static inline bool
|
|
ethtool_ioctl_needs_rtnl(const struct net_device *dev, u32 ethcmd)
|
|
{
|
|
const struct ethtool_ops *ops = dev->ethtool_ops;
|
|
|
|
switch (ethcmd) {
|
|
case ETHTOOL_GLINKSETTINGS:
|
|
case ETHTOOL_GSET:
|
|
case ETHTOOL_SLINKSETTINGS:
|
|
case ETHTOOL_SSET:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_LINKSETTINGS;
|
|
case ETHTOOL_SPFLAGS:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SPFLAGS;
|
|
case ETHTOOL_SRINGPARAM:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SRINGPARAM;
|
|
case ETHTOOL_SCHANNELS:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SCHANNELS;
|
|
case ETHTOOL_SCOALESCE:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SCOALESCE;
|
|
case ETHTOOL_GPAUSEPARAM:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_GPAUSEPARAM;
|
|
case ETHTOOL_SPAUSEPARAM:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_SPAUSEPARAM;
|
|
case ETHTOOL_SRSSH:
|
|
case ETHTOOL_SRXFH:
|
|
case ETHTOOL_SRXFHINDIR:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_RSS;
|
|
case ETHTOOL_GLINK:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_GLINK;
|
|
case ETHTOOL_TEST:
|
|
return ops->op_needs_rtnl & ETHTOOL_OP_NEEDS_RTNL_TEST;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
#if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)
|
|
void ethtool_rss_notify(struct net_device *dev, u32 type, u32 rss_context);
|
|
#else
|
|
static inline void
|
|
ethtool_rss_notify(struct net_device *dev, u32 type, u32 rss_context)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
#endif /* _ETHTOOL_COMMON_H */
|