Commit 5ac49f3c authored by Stefan Assmann's avatar Stefan Assmann Committed by Tony Nguyen

iavf: use mutexes for locking of critical sections

As follow-up to the discussion with Jakub Kicinski about iavf locking
being insufficient [1] convert iavf to use mutexes instead of bitops.
The locking logic is kept as is, just a drop-in replacement of
enum iavf_critical_section_t with separate mutexes.
The only difference is that the mutexes will be destroyed before the
module is unloaded.

[1] https://lwn.net/ml/netdev/20210316150210.00007249%40intel.com/Signed-off-by: default avatarStefan Assmann <sassmann@kpanic.de>
Tested-by: default avatarMarek Szlosek <marek.szlosek@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent 752be297
...@@ -185,12 +185,6 @@ enum iavf_state_t { ...@@ -185,12 +185,6 @@ enum iavf_state_t {
__IAVF_RUNNING, /* opened, working */ __IAVF_RUNNING, /* opened, working */
}; };
enum iavf_critical_section_t {
__IAVF_IN_CRITICAL_TASK, /* cannot be interrupted */
__IAVF_IN_CLIENT_TASK,
__IAVF_IN_REMOVE_TASK, /* device being removed */
};
#define IAVF_CLOUD_FIELD_OMAC 0x01 #define IAVF_CLOUD_FIELD_OMAC 0x01
#define IAVF_CLOUD_FIELD_IMAC 0x02 #define IAVF_CLOUD_FIELD_IMAC 0x02
#define IAVF_CLOUD_FIELD_IVLAN 0x04 #define IAVF_CLOUD_FIELD_IVLAN 0x04
...@@ -235,6 +229,9 @@ struct iavf_adapter { ...@@ -235,6 +229,9 @@ struct iavf_adapter {
struct iavf_q_vector *q_vectors; struct iavf_q_vector *q_vectors;
struct list_head vlan_filter_list; struct list_head vlan_filter_list;
struct list_head mac_filter_list; struct list_head mac_filter_list;
struct mutex crit_lock;
struct mutex client_lock;
struct mutex remove_lock;
/* Lock to protect accesses to MAC and VLAN lists */ /* Lock to protect accesses to MAC and VLAN lists */
spinlock_t mac_vlan_list_lock; spinlock_t mac_vlan_list_lock;
char misc_vector_name[IFNAMSIZ + 9]; char misc_vector_name[IFNAMSIZ + 9];
......
...@@ -1352,8 +1352,7 @@ static int iavf_add_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rx ...@@ -1352,8 +1352,7 @@ static int iavf_add_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rx
if (!fltr) if (!fltr)
return -ENOMEM; return -ENOMEM;
while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, while (!mutex_trylock(&adapter->crit_lock)) {
&adapter->crit_section)) {
if (--count == 0) { if (--count == 0) {
kfree(fltr); kfree(fltr);
return -EINVAL; return -EINVAL;
...@@ -1378,7 +1377,7 @@ static int iavf_add_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rx ...@@ -1378,7 +1377,7 @@ static int iavf_add_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rx
if (err && fltr) if (err && fltr)
kfree(fltr); kfree(fltr);
clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); mutex_unlock(&adapter->crit_lock);
return err; return err;
} }
...@@ -1563,8 +1562,7 @@ iavf_set_adv_rss_hash_opt(struct iavf_adapter *adapter, ...@@ -1563,8 +1562,7 @@ iavf_set_adv_rss_hash_opt(struct iavf_adapter *adapter,
return -EINVAL; return -EINVAL;
} }
while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, while (!mutex_trylock(&adapter->crit_lock)) {
&adapter->crit_section)) {
if (--count == 0) { if (--count == 0) {
kfree(rss_new); kfree(rss_new);
return -EINVAL; return -EINVAL;
...@@ -1600,7 +1598,7 @@ iavf_set_adv_rss_hash_opt(struct iavf_adapter *adapter, ...@@ -1600,7 +1598,7 @@ iavf_set_adv_rss_hash_opt(struct iavf_adapter *adapter,
if (!err) if (!err)
mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0); mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0);
clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); mutex_unlock(&adapter->crit_lock);
if (!rss_new_add) if (!rss_new_add)
kfree(rss_new); kfree(rss_new);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment