Skip to content

Commit

Permalink
Merge branch 'geneve-vxlan-deps'
Browse files Browse the repository at this point in the history
Hannes Frederic Sowa says:

====================
net: network drivers should not depend on geneve/vxlan

This patchset removes the dependency of network drivers on vxlan or
geneve, so those don't get autoloaded when the nic driver is loaded.

Also audited the code such that vxlan_get_rx_port and geneve_get_rx_port
are not called without rtnl lock.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Apr 21, 2016
2 parents 7f348a6 + 681e683 commit 22d37b6
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 22 deletions.
10 changes: 6 additions & 4 deletions drivers/net/ethernet/emulex/benet/be_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4890,11 +4890,13 @@ static int be_resume(struct be_adapter *adapter)
if (status)
return status;

if (netif_running(netdev)) {
rtnl_lock();
if (netif_running(netdev))
status = be_open(netdev);
if (status)
return status;
}
rtnl_unlock();

if (status)
return status;

netif_device_attach(netdev);

Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ethernet/intel/fm10k/fm10k_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -2287,8 +2287,10 @@ static void fm10k_io_resume(struct pci_dev *pdev)
/* reassociate interrupts */
fm10k_mbx_request_irq(interface);

rtnl_lock();
if (netif_running(netdev))
err = fm10k_open(netdev);
rtnl_unlock();

/* final check of hardware state before registering the interface */
err = err ? : fm10k_hw_ready(interface);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7192,10 +7192,12 @@ static void ixgbe_service_task(struct work_struct *work)
return;
}
#ifdef CONFIG_IXGBE_VXLAN
rtnl_lock();
if (adapter->flags2 & IXGBE_FLAG2_VXLAN_REREG_NEEDED) {
adapter->flags2 &= ~IXGBE_FLAG2_VXLAN_REREG_NEEDED;
vxlan_get_rx_port(adapter->netdev);
}
rtnl_unlock();
#endif /* CONFIG_IXGBE_VXLAN */
ixgbe_reset_subtask(adapter);
ixgbe_phy_interrupt_subtask(adapter);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ethernet/mellanox/mlx4/en_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1856,13 +1856,15 @@ static void mlx4_en_restart(struct work_struct *work)

en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);

rtnl_lock();
mutex_lock(&mdev->state_lock);
if (priv->port_up) {
mlx4_en_stop_port(dev, 1);
if (mlx4_en_start_port(dev))
en_err(priv, "Failed restarting port %d\n", priv->port);
}
mutex_unlock(&mdev->state_lock);
rtnl_unlock();
}

static void mlx4_en_clear_stats(struct net_device *dev)
Expand Down
10 changes: 8 additions & 2 deletions drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3952,8 +3952,14 @@ static pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *pdev,

static pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *pdev)
{
return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
PCI_ERS_RESULT_RECOVERED;
pci_ers_result_t res;

rtnl_lock();
res = qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
PCI_ERS_RESULT_RECOVERED;
rtnl_unlock();

return res;
}

static void qlcnic_82xx_io_resume(struct pci_dev *pdev)
Expand Down
31 changes: 28 additions & 3 deletions drivers/net/geneve.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ static struct device_type geneve_type = {
* supply the listening GENEVE udp ports. Callers are expected
* to implement the ndo_add_geneve_port.
*/
void geneve_get_rx_port(struct net_device *dev)
static void geneve_push_rx_ports(struct net_device *dev)
{
struct net *net = dev_net(dev);
struct geneve_net *gn = net_generic(net, geneve_net_id);
Expand All @@ -1181,6 +1181,9 @@ void geneve_get_rx_port(struct net_device *dev)
struct sock *sk;
__be16 port;

if (!dev->netdev_ops->ndo_add_geneve_port)
return;

rcu_read_lock();
list_for_each_entry_rcu(gs, &gn->sock_list, list) {
sk = gs->sock->sk;
Expand All @@ -1190,7 +1193,6 @@ void geneve_get_rx_port(struct net_device *dev)
}
rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(geneve_get_rx_port);

/* Initialize the device structure. */
static void geneve_setup(struct net_device *dev)
Expand Down Expand Up @@ -1538,6 +1540,21 @@ struct net_device *geneve_dev_create_fb(struct net *net, const char *name,
}
EXPORT_SYMBOL_GPL(geneve_dev_create_fb);

static int geneve_netdevice_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);

if (event == NETDEV_OFFLOAD_PUSH_GENEVE)
geneve_push_rx_ports(dev);

return NOTIFY_DONE;
}

static struct notifier_block geneve_notifier_block __read_mostly = {
.notifier_call = geneve_netdevice_event,
};

static __net_init int geneve_init_net(struct net *net)
{
struct geneve_net *gn = net_generic(net, geneve_net_id);
Expand Down Expand Up @@ -1590,11 +1607,18 @@ static int __init geneve_init_module(void)
if (rc)
goto out1;

rc = rtnl_link_register(&geneve_link_ops);
rc = register_netdevice_notifier(&geneve_notifier_block);
if (rc)
goto out2;

rc = rtnl_link_register(&geneve_link_ops);
if (rc)
goto out3;

return 0;

out3:
unregister_netdevice_notifier(&geneve_notifier_block);
out2:
unregister_pernet_subsys(&geneve_net_ops);
out1:
Expand All @@ -1605,6 +1629,7 @@ late_initcall(geneve_init_module);
static void __exit geneve_cleanup_module(void)
{
rtnl_link_unregister(&geneve_link_ops);
unregister_netdevice_notifier(&geneve_notifier_block);
unregister_pernet_subsys(&geneve_net_ops);
}
module_exit(geneve_cleanup_module);
Expand Down
14 changes: 9 additions & 5 deletions drivers/net/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ static struct device_type vxlan_type = {
* supply the listening VXLAN udp ports. Callers are expected
* to implement the ndo_add_vxlan_port.
*/
void vxlan_get_rx_port(struct net_device *dev)
static void vxlan_push_rx_ports(struct net_device *dev)
{
struct vxlan_sock *vs;
struct net *net = dev_net(dev);
Expand All @@ -2536,6 +2536,9 @@ void vxlan_get_rx_port(struct net_device *dev)
__be16 port;
unsigned int i;

if (!dev->netdev_ops->ndo_add_vxlan_port)
return;

spin_lock(&vn->sock_lock);
for (i = 0; i < PORT_HASH_SIZE; ++i) {
hlist_for_each_entry_rcu(vs, &vn->sock_list[i], hlist) {
Expand All @@ -2547,7 +2550,6 @@ void vxlan_get_rx_port(struct net_device *dev)
}
spin_unlock(&vn->sock_lock);
}
EXPORT_SYMBOL_GPL(vxlan_get_rx_port);

/* Initialize the device structure. */
static void vxlan_setup(struct net_device *dev)
Expand Down Expand Up @@ -3283,20 +3285,22 @@ static void vxlan_handle_lowerdev_unregister(struct vxlan_net *vn,
unregister_netdevice_many(&list_kill);
}

static int vxlan_lowerdev_event(struct notifier_block *unused,
unsigned long event, void *ptr)
static int vxlan_netdevice_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);

if (event == NETDEV_UNREGISTER)
vxlan_handle_lowerdev_unregister(vn, dev);
else if (event == NETDEV_OFFLOAD_PUSH_VXLAN)
vxlan_push_rx_ports(dev);

return NOTIFY_DONE;
}

static struct notifier_block vxlan_notifier_block __read_mostly = {
.notifier_call = vxlan_lowerdev_event,
.notifier_call = vxlan_netdevice_event,
};

static __net_init int vxlan_init_net(struct net *net)
Expand Down
2 changes: 2 additions & 0 deletions include/linux/netdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,8 @@ struct netdev_lag_lower_state_info {
#define NETDEV_BONDING_INFO 0x0019
#define NETDEV_PRECHANGEUPPER 0x001A
#define NETDEV_CHANGELOWERSTATE 0x001B
#define NETDEV_OFFLOAD_PUSH_VXLAN 0x001C
#define NETDEV_OFFLOAD_PUSH_GENEVE 0x001D

int register_netdevice_notifier(struct notifier_block *nb);
int unregister_netdevice_notifier(struct notifier_block *nb);
Expand Down
6 changes: 2 additions & 4 deletions include/net/geneve.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ struct genevehdr {
struct geneve_opt options[];
};

#if IS_ENABLED(CONFIG_GENEVE)
void geneve_get_rx_port(struct net_device *netdev);
#else
static inline void geneve_get_rx_port(struct net_device *netdev)
{
ASSERT_RTNL();
call_netdevice_notifiers(NETDEV_OFFLOAD_PUSH_GENEVE, netdev);
}
#endif

#ifdef CONFIG_INET
struct net_device *geneve_dev_create_fb(struct net *net, const char *name,
Expand Down
6 changes: 2 additions & 4 deletions include/net/vxlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,11 @@ static inline __be32 vxlan_compute_rco(unsigned int start, unsigned int offset)
return vni_field;
}

#if IS_ENABLED(CONFIG_VXLAN)
void vxlan_get_rx_port(struct net_device *netdev);
#else
static inline void vxlan_get_rx_port(struct net_device *netdev)
{
ASSERT_RTNL();
call_netdevice_notifiers(NETDEV_OFFLOAD_PUSH_VXLAN, netdev);
}
#endif

static inline unsigned short vxlan_get_sk_family(struct vxlan_sock *vs)
{
Expand Down

0 comments on commit 22d37b6

Please sign in to comment.