Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d248953a authored by Martin Habets's avatar Martin Habets Committed by David S. Miller
Browse files

sfc: Take mac_lock before calling efx_ef10_filter_table_probe



When trying to enslave an SFC interface to a bond the following BUG_ON was
hit:

 kernel BUG [in ef10.c]!
 CPU: 0 PID: 4383 Comm: ifenslave Tainted: G
...
 Call Trace:
  efx_ef10_filter_add_vlan+0x121/0x180 [sfc]
  efx_ef10_filter_table_probe+0x2a2/0x4f0 [sfc]
  efx_ef10_set_mac_address+0x370/0x6d0 [sfc]
  efx_set_mac_address+0x7d/0x120 [sfc]
  dev_set_mac_address+0x43/0xa0
  bond_enslave+0x337/0xea0 [bonding]
This comes from function efx_ef10_filter_vlan_sync_rx_mode.

To solve the bug we ensure the mac_lock is taken before calling
efx_ef10_filter_add_vlan. But to avoid a priority inversion mac_lock must
be taken before filter_sem.
To satisfy these requirements we end up taking mac_lock in
efx_ef10_vport_set_mac_address, efx_ef10_set_mac_address,
efx_ef10_sriov_set_vf_vlan and efx_probe_filters.

Signed-off-by: default avatarEdward Cree <ecree@solarflare.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4a53ea8a
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -4666,6 +4666,8 @@ static int efx_ef10_set_mac_address(struct efx_nic *efx)


	efx_device_detach_sync(efx);
	efx_device_detach_sync(efx);
	efx_net_stop(efx->net_dev);
	efx_net_stop(efx->net_dev);

	mutex_lock(&efx->mac_lock);
	down_write(&efx->filter_sem);
	down_write(&efx->filter_sem);
	efx_ef10_filter_table_remove(efx);
	efx_ef10_filter_table_remove(efx);


@@ -4678,6 +4680,8 @@ static int efx_ef10_set_mac_address(struct efx_nic *efx)


	efx_ef10_filter_table_probe(efx);
	efx_ef10_filter_table_probe(efx);
	up_write(&efx->filter_sem);
	up_write(&efx->filter_sem);
	mutex_unlock(&efx->mac_lock);

	if (was_enabled)
	if (was_enabled)
		efx_net_open(efx->net_dev);
		efx_net_open(efx->net_dev);
	netif_device_attach(efx->net_dev);
	netif_device_attach(efx->net_dev);
+5 −2
Original line number Original line Diff line number Diff line
@@ -554,6 +554,7 @@ int efx_ef10_sriov_set_vf_vlan(struct efx_nic *efx, int vf_i, u16 vlan,
		efx_device_detach_sync(vf->efx);
		efx_device_detach_sync(vf->efx);
		efx_net_stop(vf->efx->net_dev);
		efx_net_stop(vf->efx->net_dev);


		mutex_lock(&vf->efx->mac_lock);
		down_write(&vf->efx->filter_sem);
		down_write(&vf->efx->filter_sem);
		vf->efx->type->filter_table_remove(vf->efx);
		vf->efx->type->filter_table_remove(vf->efx);


@@ -630,6 +631,7 @@ int efx_ef10_sriov_set_vf_vlan(struct efx_nic *efx, int vf_i, u16 vlan,
			goto reset_nic_up_write;
			goto reset_nic_up_write;


		up_write(&vf->efx->filter_sem);
		up_write(&vf->efx->filter_sem);
		mutex_unlock(&vf->efx->mac_lock);


		up_write(&vf->efx->filter_sem);
		up_write(&vf->efx->filter_sem);


@@ -642,9 +644,10 @@ int efx_ef10_sriov_set_vf_vlan(struct efx_nic *efx, int vf_i, u16 vlan,
	return rc;
	return rc;


reset_nic_up_write:
reset_nic_up_write:
	if (vf->efx)
	if (vf->efx) {
		up_write(&vf->efx->filter_sem);
		up_write(&vf->efx->filter_sem);

		mutex_unlock(&vf->efx->mac_lock);
	}
reset_nic:
reset_nic:
	if (vf->efx) {
	if (vf->efx) {
		netif_err(efx, drv, efx->net_dev,
		netif_err(efx, drv, efx->net_dev,
+2 −0
Original line number Original line Diff line number Diff line
@@ -1729,6 +1729,7 @@ static int efx_probe_filters(struct efx_nic *efx)


	spin_lock_init(&efx->filter_lock);
	spin_lock_init(&efx->filter_lock);
	init_rwsem(&efx->filter_sem);
	init_rwsem(&efx->filter_sem);
	mutex_lock(&efx->mac_lock);
	down_write(&efx->filter_sem);
	down_write(&efx->filter_sem);
	rc = efx->type->filter_table_probe(efx);
	rc = efx->type->filter_table_probe(efx);
	if (rc)
	if (rc)
@@ -1767,6 +1768,7 @@ static int efx_probe_filters(struct efx_nic *efx)
#endif
#endif
out_unlock:
out_unlock:
	up_write(&efx->filter_sem);
	up_write(&efx->filter_sem);
	mutex_unlock(&efx->mac_lock);
	return rc;
	return rc;
}
}