@@ -132,21 +132,18 @@ enum iavf_status iavf_free_virt_mem_d(struct iavf_hw *hw,
132
132
}
133
133
134
134
/**
135
- * iavf_lock_timeout - try to set bit but give up after timeout
136
- * @adapter: board private structure
137
- * @bit: bit to set
135
+ * iavf_lock_timeout - try to lock mutex but give up after timeout
136
+ * @lock: mutex that should be locked
138
137
* @msecs: timeout in msecs
139
138
*
140
139
* Returns 0 on success, negative on failure
141
140
**/
142
- static int iavf_lock_timeout (struct iavf_adapter * adapter ,
143
- enum iavf_critical_section_t bit ,
144
- unsigned int msecs )
141
+ static int iavf_lock_timeout (struct mutex * lock , unsigned int msecs )
145
142
{
146
143
unsigned int wait , delay = 10 ;
147
144
148
145
for (wait = 0 ; wait < msecs ; wait += delay ) {
149
- if (! test_and_set_bit ( bit , & adapter -> crit_section ))
146
+ if (mutex_trylock ( lock ))
150
147
return 0 ;
151
148
152
149
msleep (delay );
@@ -1939,7 +1936,7 @@ static void iavf_watchdog_task(struct work_struct *work)
1939
1936
struct iavf_hw * hw = & adapter -> hw ;
1940
1937
u32 reg_val ;
1941
1938
1942
- if (test_and_set_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section ))
1939
+ if (! mutex_trylock ( & adapter -> crit_lock ))
1943
1940
goto restart_watchdog ;
1944
1941
1945
1942
if (adapter -> flags & IAVF_FLAG_PF_COMMS_FAILED )
@@ -1957,8 +1954,7 @@ static void iavf_watchdog_task(struct work_struct *work)
1957
1954
adapter -> state = __IAVF_STARTUP ;
1958
1955
adapter -> flags &= ~IAVF_FLAG_PF_COMMS_FAILED ;
1959
1956
queue_delayed_work (iavf_wq , & adapter -> init_task , 10 );
1960
- clear_bit (__IAVF_IN_CRITICAL_TASK ,
1961
- & adapter -> crit_section );
1957
+ mutex_unlock (& adapter -> crit_lock );
1962
1958
/* Don't reschedule the watchdog, since we've restarted
1963
1959
* the init task. When init_task contacts the PF and
1964
1960
* gets everything set up again, it'll restart the
@@ -1968,14 +1964,13 @@ static void iavf_watchdog_task(struct work_struct *work)
1968
1964
}
1969
1965
adapter -> aq_required = 0 ;
1970
1966
adapter -> current_op = VIRTCHNL_OP_UNKNOWN ;
1971
- clear_bit (__IAVF_IN_CRITICAL_TASK ,
1972
- & adapter -> crit_section );
1967
+ mutex_unlock (& adapter -> crit_lock );
1973
1968
queue_delayed_work (iavf_wq ,
1974
1969
& adapter -> watchdog_task ,
1975
1970
msecs_to_jiffies (10 ));
1976
1971
goto watchdog_done ;
1977
1972
case __IAVF_RESETTING :
1978
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
1973
+ mutex_unlock ( & adapter -> crit_lock );
1979
1974
queue_delayed_work (iavf_wq , & adapter -> watchdog_task , HZ * 2 );
1980
1975
return ;
1981
1976
case __IAVF_DOWN :
@@ -1998,7 +1993,7 @@ static void iavf_watchdog_task(struct work_struct *work)
1998
1993
}
1999
1994
break ;
2000
1995
case __IAVF_REMOVE :
2001
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
1996
+ mutex_unlock ( & adapter -> crit_lock );
2002
1997
return ;
2003
1998
default :
2004
1999
goto restart_watchdog ;
@@ -2020,7 +2015,7 @@ static void iavf_watchdog_task(struct work_struct *work)
2020
2015
if (adapter -> state == __IAVF_RUNNING ||
2021
2016
adapter -> state == __IAVF_COMM_FAILED )
2022
2017
iavf_detect_recover_hung (& adapter -> vsi );
2023
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
2018
+ mutex_unlock ( & adapter -> crit_lock );
2024
2019
restart_watchdog :
2025
2020
if (adapter -> aq_required )
2026
2021
queue_delayed_work (iavf_wq , & adapter -> watchdog_task ,
@@ -2084,7 +2079,7 @@ static void iavf_disable_vf(struct iavf_adapter *adapter)
2084
2079
memset (adapter -> vf_res , 0 , IAVF_VIRTCHNL_VF_RESOURCE_SIZE );
2085
2080
iavf_shutdown_adminq (& adapter -> hw );
2086
2081
adapter -> netdev -> flags &= ~IFF_UP ;
2087
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
2082
+ mutex_unlock ( & adapter -> crit_lock );
2088
2083
adapter -> flags &= ~IAVF_FLAG_RESET_PENDING ;
2089
2084
adapter -> state = __IAVF_DOWN ;
2090
2085
wake_up (& adapter -> down_waitqueue );
@@ -2117,15 +2112,14 @@ static void iavf_reset_task(struct work_struct *work)
2117
2112
/* When device is being removed it doesn't make sense to run the reset
2118
2113
* task, just return in such a case.
2119
2114
*/
2120
- if (test_bit ( __IAVF_IN_REMOVE_TASK , & adapter -> crit_section ))
2115
+ if (mutex_is_locked ( & adapter -> remove_lock ))
2121
2116
return ;
2122
2117
2123
- if (iavf_lock_timeout (adapter , __IAVF_IN_CRITICAL_TASK , 200 )) {
2118
+ if (iavf_lock_timeout (& adapter -> crit_lock , 200 )) {
2124
2119
schedule_work (& adapter -> reset_task );
2125
2120
return ;
2126
2121
}
2127
- while (test_and_set_bit (__IAVF_IN_CLIENT_TASK ,
2128
- & adapter -> crit_section ))
2122
+ while (!mutex_trylock (& adapter -> client_lock ))
2129
2123
usleep_range (500 , 1000 );
2130
2124
if (CLIENT_ENABLED (adapter )) {
2131
2125
adapter -> flags &= ~(IAVF_FLAG_CLIENT_NEEDS_OPEN |
@@ -2177,7 +2171,7 @@ static void iavf_reset_task(struct work_struct *work)
2177
2171
dev_err (& adapter -> pdev -> dev , "Reset never finished (%x)\n" ,
2178
2172
reg_val );
2179
2173
iavf_disable_vf (adapter );
2180
- clear_bit ( __IAVF_IN_CLIENT_TASK , & adapter -> crit_section );
2174
+ mutex_unlock ( & adapter -> client_lock );
2181
2175
return ; /* Do not attempt to reinit. It's dead, Jim. */
2182
2176
}
2183
2177
@@ -2304,13 +2298,13 @@ static void iavf_reset_task(struct work_struct *work)
2304
2298
adapter -> state = __IAVF_DOWN ;
2305
2299
wake_up (& adapter -> down_waitqueue );
2306
2300
}
2307
- clear_bit ( __IAVF_IN_CLIENT_TASK , & adapter -> crit_section );
2308
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
2301
+ mutex_unlock ( & adapter -> client_lock );
2302
+ mutex_unlock ( & adapter -> crit_lock );
2309
2303
2310
2304
return ;
2311
2305
reset_err :
2312
- clear_bit ( __IAVF_IN_CLIENT_TASK , & adapter -> crit_section );
2313
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
2306
+ mutex_unlock ( & adapter -> client_lock );
2307
+ mutex_unlock ( & adapter -> crit_lock );
2314
2308
dev_err (& adapter -> pdev -> dev , "failed to allocate resources during reinit\n" );
2315
2309
iavf_close (netdev );
2316
2310
}
@@ -2338,7 +2332,7 @@ static void iavf_adminq_task(struct work_struct *work)
2338
2332
if (!event .msg_buf )
2339
2333
goto out ;
2340
2334
2341
- if (iavf_lock_timeout (adapter , __IAVF_IN_CRITICAL_TASK , 200 ))
2335
+ if (iavf_lock_timeout (& adapter -> crit_lock , 200 ))
2342
2336
goto freedom ;
2343
2337
do {
2344
2338
ret = iavf_clean_arq_element (hw , & event , & pending );
@@ -2353,7 +2347,7 @@ static void iavf_adminq_task(struct work_struct *work)
2353
2347
if (pending != 0 )
2354
2348
memset (event .msg_buf , 0 , IAVF_MAX_AQ_BUF_SIZE );
2355
2349
} while (pending );
2356
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
2350
+ mutex_unlock ( & adapter -> crit_lock );
2357
2351
2358
2352
if ((adapter -> flags &
2359
2353
(IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED )) ||
@@ -2420,7 +2414,7 @@ static void iavf_client_task(struct work_struct *work)
2420
2414
* later.
2421
2415
*/
2422
2416
2423
- if (test_and_set_bit ( __IAVF_IN_CLIENT_TASK , & adapter -> crit_section ))
2417
+ if (! mutex_trylock ( & adapter -> client_lock ))
2424
2418
return ;
2425
2419
2426
2420
if (adapter -> flags & IAVF_FLAG_SERVICE_CLIENT_REQUESTED ) {
@@ -2443,7 +2437,7 @@ static void iavf_client_task(struct work_struct *work)
2443
2437
adapter -> flags &= ~IAVF_FLAG_CLIENT_NEEDS_OPEN ;
2444
2438
}
2445
2439
out :
2446
- clear_bit ( __IAVF_IN_CLIENT_TASK , & adapter -> crit_section );
2440
+ mutex_unlock ( & adapter -> client_lock );
2447
2441
}
2448
2442
2449
2443
/**
@@ -3046,8 +3040,7 @@ static int iavf_configure_clsflower(struct iavf_adapter *adapter,
3046
3040
if (!filter )
3047
3041
return - ENOMEM ;
3048
3042
3049
- while (test_and_set_bit (__IAVF_IN_CRITICAL_TASK ,
3050
- & adapter -> crit_section )) {
3043
+ while (!mutex_trylock (& adapter -> crit_lock )) {
3051
3044
if (-- count == 0 )
3052
3045
goto err ;
3053
3046
udelay (1 );
@@ -3078,7 +3071,7 @@ static int iavf_configure_clsflower(struct iavf_adapter *adapter,
3078
3071
if (err )
3079
3072
kfree (filter );
3080
3073
3081
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
3074
+ mutex_unlock ( & adapter -> crit_lock );
3082
3075
return err ;
3083
3076
}
3084
3077
@@ -3225,8 +3218,7 @@ static int iavf_open(struct net_device *netdev)
3225
3218
return - EIO ;
3226
3219
}
3227
3220
3228
- while (test_and_set_bit (__IAVF_IN_CRITICAL_TASK ,
3229
- & adapter -> crit_section ))
3221
+ while (!mutex_trylock (& adapter -> crit_lock ))
3230
3222
usleep_range (500 , 1000 );
3231
3223
3232
3224
if (adapter -> state != __IAVF_DOWN ) {
@@ -3261,7 +3253,7 @@ static int iavf_open(struct net_device *netdev)
3261
3253
3262
3254
iavf_irq_enable (adapter , true);
3263
3255
3264
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
3256
+ mutex_unlock ( & adapter -> crit_lock );
3265
3257
3266
3258
return 0 ;
3267
3259
@@ -3273,7 +3265,7 @@ static int iavf_open(struct net_device *netdev)
3273
3265
err_setup_tx :
3274
3266
iavf_free_all_tx_resources (adapter );
3275
3267
err_unlock :
3276
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
3268
+ mutex_unlock ( & adapter -> crit_lock );
3277
3269
3278
3270
return err ;
3279
3271
}
@@ -3297,8 +3289,7 @@ static int iavf_close(struct net_device *netdev)
3297
3289
if (adapter -> state <= __IAVF_DOWN_PENDING )
3298
3290
return 0 ;
3299
3291
3300
- while (test_and_set_bit (__IAVF_IN_CRITICAL_TASK ,
3301
- & adapter -> crit_section ))
3292
+ while (!mutex_trylock (& adapter -> crit_lock ))
3302
3293
usleep_range (500 , 1000 );
3303
3294
3304
3295
set_bit (__IAVF_VSI_DOWN , adapter -> vsi .state );
@@ -3309,7 +3300,7 @@ static int iavf_close(struct net_device *netdev)
3309
3300
adapter -> state = __IAVF_DOWN_PENDING ;
3310
3301
iavf_free_traffic_irqs (adapter );
3311
3302
3312
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
3303
+ mutex_unlock ( & adapter -> crit_lock );
3313
3304
3314
3305
/* We explicitly don't free resources here because the hardware is
3315
3306
* still active and can DMA into memory. Resources are cleared in
@@ -3658,8 +3649,8 @@ static void iavf_init_task(struct work_struct *work)
3658
3649
init_task .work );
3659
3650
struct iavf_hw * hw = & adapter -> hw ;
3660
3651
3661
- if (iavf_lock_timeout (adapter , __IAVF_IN_CRITICAL_TASK , 5000 )) {
3662
- dev_warn (& adapter -> pdev -> dev , "failed to set __IAVF_IN_CRITICAL_TASK in %s\n" , __FUNCTION__ );
3652
+ if (iavf_lock_timeout (& adapter -> crit_lock , 5000 )) {
3653
+ dev_warn (& adapter -> pdev -> dev , "failed to acquire crit_lock in %s\n" , __FUNCTION__ );
3663
3654
return ;
3664
3655
}
3665
3656
switch (adapter -> state ) {
@@ -3694,7 +3685,7 @@ static void iavf_init_task(struct work_struct *work)
3694
3685
}
3695
3686
queue_delayed_work (iavf_wq , & adapter -> init_task , HZ );
3696
3687
out :
3697
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
3688
+ mutex_unlock ( & adapter -> crit_lock );
3698
3689
}
3699
3690
3700
3691
/**
@@ -3711,12 +3702,12 @@ static void iavf_shutdown(struct pci_dev *pdev)
3711
3702
if (netif_running (netdev ))
3712
3703
iavf_close (netdev );
3713
3704
3714
- if (iavf_lock_timeout (adapter , __IAVF_IN_CRITICAL_TASK , 5000 ))
3715
- dev_warn (& adapter -> pdev -> dev , "failed to set __IAVF_IN_CRITICAL_TASK in %s\n" , __FUNCTION__ );
3705
+ if (iavf_lock_timeout (& adapter -> crit_lock , 5000 ))
3706
+ dev_warn (& adapter -> pdev -> dev , "failed to acquire crit_lock in %s\n" , __FUNCTION__ );
3716
3707
/* Prevent the watchdog from running. */
3717
3708
adapter -> state = __IAVF_REMOVE ;
3718
3709
adapter -> aq_required = 0 ;
3719
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
3710
+ mutex_unlock ( & adapter -> crit_lock );
3720
3711
3721
3712
#ifdef CONFIG_PM
3722
3713
pci_save_state (pdev );
@@ -3810,6 +3801,9 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3810
3801
/* set up the locks for the AQ, do this only once in probe
3811
3802
* and destroy them only once in remove
3812
3803
*/
3804
+ mutex_init (& adapter -> crit_lock );
3805
+ mutex_init (& adapter -> client_lock );
3806
+ mutex_init (& adapter -> remove_lock );
3813
3807
mutex_init (& hw -> aq .asq_mutex );
3814
3808
mutex_init (& hw -> aq .arq_mutex );
3815
3809
@@ -3861,8 +3855,7 @@ static int __maybe_unused iavf_suspend(struct device *dev_d)
3861
3855
3862
3856
netif_device_detach (netdev );
3863
3857
3864
- while (test_and_set_bit (__IAVF_IN_CRITICAL_TASK ,
3865
- & adapter -> crit_section ))
3858
+ while (!mutex_trylock (& adapter -> crit_lock ))
3866
3859
usleep_range (500 , 1000 );
3867
3860
3868
3861
if (netif_running (netdev )) {
@@ -3873,7 +3866,7 @@ static int __maybe_unused iavf_suspend(struct device *dev_d)
3873
3866
iavf_free_misc_irq (adapter );
3874
3867
iavf_reset_interrupt_capability (adapter );
3875
3868
3876
- clear_bit ( __IAVF_IN_CRITICAL_TASK , & adapter -> crit_section );
3869
+ mutex_unlock ( & adapter -> crit_lock );
3877
3870
3878
3871
return 0 ;
3879
3872
}
@@ -3935,7 +3928,7 @@ static void iavf_remove(struct pci_dev *pdev)
3935
3928
struct iavf_hw * hw = & adapter -> hw ;
3936
3929
int err ;
3937
3930
/* Indicate we are in remove and not to run reset_task */
3938
- set_bit ( __IAVF_IN_REMOVE_TASK , & adapter -> crit_section );
3931
+ mutex_lock ( & adapter -> remove_lock );
3939
3932
cancel_delayed_work_sync (& adapter -> init_task );
3940
3933
cancel_work_sync (& adapter -> reset_task );
3941
3934
cancel_delayed_work_sync (& adapter -> client_task );
@@ -3957,8 +3950,8 @@ static void iavf_remove(struct pci_dev *pdev)
3957
3950
iavf_request_reset (adapter );
3958
3951
msleep (50 );
3959
3952
}
3960
- if (iavf_lock_timeout (adapter , __IAVF_IN_CRITICAL_TASK , 5000 ))
3961
- dev_warn (& adapter -> pdev -> dev , "failed to set __IAVF_IN_CRITICAL_TASK in %s\n" , __FUNCTION__ );
3953
+ if (iavf_lock_timeout (& adapter -> crit_lock , 5000 ))
3954
+ dev_warn (& adapter -> pdev -> dev , "failed to acquire crit_lock in %s\n" , __FUNCTION__ );
3962
3955
3963
3956
/* Shut down all the garbage mashers on the detention level */
3964
3957
adapter -> state = __IAVF_REMOVE ;
@@ -3983,6 +3976,11 @@ static void iavf_remove(struct pci_dev *pdev)
3983
3976
/* destroy the locks only once, here */
3984
3977
mutex_destroy (& hw -> aq .arq_mutex );
3985
3978
mutex_destroy (& hw -> aq .asq_mutex );
3979
+ mutex_destroy (& adapter -> client_lock );
3980
+ mutex_unlock (& adapter -> crit_lock );
3981
+ mutex_destroy (& adapter -> crit_lock );
3982
+ mutex_unlock (& adapter -> remove_lock );
3983
+ mutex_destroy (& adapter -> remove_lock );
3986
3984
3987
3985
iounmap (hw -> hw_addr );
3988
3986
pci_release_regions (pdev );
0 commit comments