@@ -1968,6 +1968,7 @@ static int iavf_reinit_interrupt_scheme(struct iavf_adapter *adapter, bool runni
1968
1968
static void iavf_finish_config (struct work_struct * work )
1969
1969
{
1970
1970
struct iavf_adapter * adapter ;
1971
+ bool netdev_released = false;
1971
1972
int pairs , err ;
1972
1973
1973
1974
adapter = container_of (work , struct iavf_adapter , finish_config );
@@ -1988,7 +1989,16 @@ static void iavf_finish_config(struct work_struct *work)
1988
1989
1989
1990
switch (adapter -> state ) {
1990
1991
case __IAVF_DOWN :
1992
+ /* Set the real number of queues when reset occurs while
1993
+ * state == __IAVF_DOWN
1994
+ */
1995
+ pairs = adapter -> num_active_queues ;
1996
+ netif_set_real_num_rx_queues (adapter -> netdev , pairs );
1997
+ netif_set_real_num_tx_queues (adapter -> netdev , pairs );
1998
+
1991
1999
if (adapter -> netdev -> reg_state != NETREG_REGISTERED ) {
2000
+ mutex_unlock (& adapter -> netdev -> lock );
2001
+ netdev_released = true;
1992
2002
err = register_netdevice (adapter -> netdev );
1993
2003
if (err ) {
1994
2004
dev_err (& adapter -> pdev -> dev , "Unable to register netdev (%d)\n" ,
@@ -2003,11 +2013,7 @@ static void iavf_finish_config(struct work_struct *work)
2003
2013
goto out ;
2004
2014
}
2005
2015
}
2006
-
2007
- /* Set the real number of queues when reset occurs while
2008
- * state == __IAVF_DOWN
2009
- */
2010
- fallthrough ;
2016
+ break ;
2011
2017
case __IAVF_RUNNING :
2012
2018
pairs = adapter -> num_active_queues ;
2013
2019
netif_set_real_num_rx_queues (adapter -> netdev , pairs );
@@ -2020,7 +2026,8 @@ static void iavf_finish_config(struct work_struct *work)
2020
2026
2021
2027
out :
2022
2028
mutex_unlock (& adapter -> crit_lock );
2023
- mutex_unlock (& adapter -> netdev -> lock );
2029
+ if (!netdev_released )
2030
+ mutex_unlock (& adapter -> netdev -> lock );
2024
2031
rtnl_unlock ();
2025
2032
}
2026
2033
@@ -2713,12 +2720,16 @@ static void iavf_watchdog_task(struct work_struct *work)
2713
2720
struct iavf_adapter * adapter = container_of (work ,
2714
2721
struct iavf_adapter ,
2715
2722
watchdog_task .work );
2723
+ struct net_device * netdev = adapter -> netdev ;
2716
2724
struct iavf_hw * hw = & adapter -> hw ;
2717
2725
u32 reg_val ;
2718
2726
2727
+ mutex_lock (& netdev -> lock );
2719
2728
if (!mutex_trylock (& adapter -> crit_lock )) {
2720
- if (adapter -> state == __IAVF_REMOVE )
2729
+ if (adapter -> state == __IAVF_REMOVE ) {
2730
+ mutex_unlock (& netdev -> lock );
2721
2731
return ;
2732
+ }
2722
2733
2723
2734
goto restart_watchdog ;
2724
2735
}
@@ -2730,30 +2741,35 @@ static void iavf_watchdog_task(struct work_struct *work)
2730
2741
case __IAVF_STARTUP :
2731
2742
iavf_startup (adapter );
2732
2743
mutex_unlock (& adapter -> crit_lock );
2744
+ mutex_unlock (& netdev -> lock );
2733
2745
queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
2734
2746
msecs_to_jiffies (30 ));
2735
2747
return ;
2736
2748
case __IAVF_INIT_VERSION_CHECK :
2737
2749
iavf_init_version_check (adapter );
2738
2750
mutex_unlock (& adapter -> crit_lock );
2751
+ mutex_unlock (& netdev -> lock );
2739
2752
queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
2740
2753
msecs_to_jiffies (30 ));
2741
2754
return ;
2742
2755
case __IAVF_INIT_GET_RESOURCES :
2743
2756
iavf_init_get_resources (adapter );
2744
2757
mutex_unlock (& adapter -> crit_lock );
2758
+ mutex_unlock (& netdev -> lock );
2745
2759
queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
2746
2760
msecs_to_jiffies (1 ));
2747
2761
return ;
2748
2762
case __IAVF_INIT_EXTENDED_CAPS :
2749
2763
iavf_init_process_extended_caps (adapter );
2750
2764
mutex_unlock (& adapter -> crit_lock );
2765
+ mutex_unlock (& netdev -> lock );
2751
2766
queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
2752
2767
msecs_to_jiffies (1 ));
2753
2768
return ;
2754
2769
case __IAVF_INIT_CONFIG_ADAPTER :
2755
2770
iavf_init_config_adapter (adapter );
2756
2771
mutex_unlock (& adapter -> crit_lock );
2772
+ mutex_unlock (& netdev -> lock );
2757
2773
queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
2758
2774
msecs_to_jiffies (1 ));
2759
2775
return ;
@@ -2765,6 +2781,7 @@ static void iavf_watchdog_task(struct work_struct *work)
2765
2781
* as it can loop forever
2766
2782
*/
2767
2783
mutex_unlock (& adapter -> crit_lock );
2784
+ mutex_unlock (& netdev -> lock );
2768
2785
return ;
2769
2786
}
2770
2787
if (++ adapter -> aq_wait_count > IAVF_AQ_MAX_ERR ) {
@@ -2773,13 +2790,15 @@ static void iavf_watchdog_task(struct work_struct *work)
2773
2790
adapter -> flags |= IAVF_FLAG_PF_COMMS_FAILED ;
2774
2791
iavf_shutdown_adminq (hw );
2775
2792
mutex_unlock (& adapter -> crit_lock );
2793
+ mutex_unlock (& netdev -> lock );
2776
2794
queue_delayed_work (adapter -> wq ,
2777
2795
& adapter -> watchdog_task , (5 * HZ ));
2778
2796
return ;
2779
2797
}
2780
2798
/* Try again from failed step*/
2781
2799
iavf_change_state (adapter , adapter -> last_state );
2782
2800
mutex_unlock (& adapter -> crit_lock );
2801
+ mutex_unlock (& netdev -> lock );
2783
2802
queue_delayed_work (adapter -> wq , & adapter -> watchdog_task , HZ );
2784
2803
return ;
2785
2804
case __IAVF_COMM_FAILED :
@@ -2792,6 +2811,7 @@ static void iavf_watchdog_task(struct work_struct *work)
2792
2811
iavf_change_state (adapter , __IAVF_INIT_FAILED );
2793
2812
adapter -> flags &= ~IAVF_FLAG_PF_COMMS_FAILED ;
2794
2813
mutex_unlock (& adapter -> crit_lock );
2814
+ mutex_unlock (& netdev -> lock );
2795
2815
return ;
2796
2816
}
2797
2817
reg_val = rd32 (hw , IAVF_VFGEN_RSTAT ) &
@@ -2811,12 +2831,14 @@ static void iavf_watchdog_task(struct work_struct *work)
2811
2831
adapter -> aq_required = 0 ;
2812
2832
adapter -> current_op = VIRTCHNL_OP_UNKNOWN ;
2813
2833
mutex_unlock (& adapter -> crit_lock );
2834
+ mutex_unlock (& netdev -> lock );
2814
2835
queue_delayed_work (adapter -> wq ,
2815
2836
& adapter -> watchdog_task ,
2816
2837
msecs_to_jiffies (10 ));
2817
2838
return ;
2818
2839
case __IAVF_RESETTING :
2819
2840
mutex_unlock (& adapter -> crit_lock );
2841
+ mutex_unlock (& netdev -> lock );
2820
2842
queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
2821
2843
HZ * 2 );
2822
2844
return ;
@@ -2847,6 +2869,7 @@ static void iavf_watchdog_task(struct work_struct *work)
2847
2869
case __IAVF_REMOVE :
2848
2870
default :
2849
2871
mutex_unlock (& adapter -> crit_lock );
2872
+ mutex_unlock (& netdev -> lock );
2850
2873
return ;
2851
2874
}
2852
2875
@@ -2858,12 +2881,14 @@ static void iavf_watchdog_task(struct work_struct *work)
2858
2881
dev_err (& adapter -> pdev -> dev , "Hardware reset detected\n" );
2859
2882
iavf_schedule_reset (adapter , IAVF_FLAG_RESET_PENDING );
2860
2883
mutex_unlock (& adapter -> crit_lock );
2884
+ mutex_unlock (& netdev -> lock );
2861
2885
queue_delayed_work (adapter -> wq ,
2862
2886
& adapter -> watchdog_task , HZ * 2 );
2863
2887
return ;
2864
2888
}
2865
2889
2866
2890
mutex_unlock (& adapter -> crit_lock );
2891
+ mutex_unlock (& netdev -> lock );
2867
2892
restart_watchdog :
2868
2893
if (adapter -> state >= __IAVF_DOWN )
2869
2894
queue_work (adapter -> wq , & adapter -> adminq_task );
@@ -4340,14 +4365,17 @@ static int iavf_open(struct net_device *netdev)
4340
4365
return - EIO ;
4341
4366
}
4342
4367
4368
+ mutex_lock (& netdev -> lock );
4343
4369
while (!mutex_trylock (& adapter -> crit_lock )) {
4344
4370
/* If we are in __IAVF_INIT_CONFIG_ADAPTER state the crit_lock
4345
4371
* is already taken and iavf_open is called from an upper
4346
4372
* device's notifier reacting on NETDEV_REGISTER event.
4347
4373
* We have to leave here to avoid dead lock.
4348
4374
*/
4349
- if (adapter -> state == __IAVF_INIT_CONFIG_ADAPTER )
4375
+ if (adapter -> state == __IAVF_INIT_CONFIG_ADAPTER ) {
4376
+ mutex_unlock (& netdev -> lock );
4350
4377
return - EBUSY ;
4378
+ }
4351
4379
4352
4380
usleep_range (500 , 1000 );
4353
4381
}
@@ -4396,6 +4424,7 @@ static int iavf_open(struct net_device *netdev)
4396
4424
iavf_irq_enable (adapter , true);
4397
4425
4398
4426
mutex_unlock (& adapter -> crit_lock );
4427
+ mutex_unlock (& netdev -> lock );
4399
4428
4400
4429
return 0 ;
4401
4430
@@ -4408,6 +4437,7 @@ static int iavf_open(struct net_device *netdev)
4408
4437
iavf_free_all_tx_resources (adapter );
4409
4438
err_unlock :
4410
4439
mutex_unlock (& adapter -> crit_lock );
4440
+ mutex_unlock (& netdev -> lock );
4411
4441
4412
4442
return err ;
4413
4443
}
@@ -4429,10 +4459,12 @@ static int iavf_close(struct net_device *netdev)
4429
4459
u64 aq_to_restore ;
4430
4460
int status ;
4431
4461
4462
+ mutex_lock (& netdev -> lock );
4432
4463
mutex_lock (& adapter -> crit_lock );
4433
4464
4434
4465
if (adapter -> state <= __IAVF_DOWN_PENDING ) {
4435
4466
mutex_unlock (& adapter -> crit_lock );
4467
+ mutex_unlock (& netdev -> lock );
4436
4468
return 0 ;
4437
4469
}
4438
4470
@@ -4466,6 +4498,7 @@ static int iavf_close(struct net_device *netdev)
4466
4498
iavf_free_traffic_irqs (adapter );
4467
4499
4468
4500
mutex_unlock (& adapter -> crit_lock );
4501
+ mutex_unlock (& netdev -> lock );
4469
4502
4470
4503
/* We explicitly don't free resources here because the hardware is
4471
4504
* still active and can DMA into memory. Resources are cleared in
@@ -5342,6 +5375,7 @@ static int iavf_suspend(struct device *dev_d)
5342
5375
5343
5376
netif_device_detach (netdev );
5344
5377
5378
+ mutex_lock (& netdev -> lock );
5345
5379
mutex_lock (& adapter -> crit_lock );
5346
5380
5347
5381
if (netif_running (netdev )) {
@@ -5353,6 +5387,7 @@ static int iavf_suspend(struct device *dev_d)
5353
5387
iavf_reset_interrupt_capability (adapter );
5354
5388
5355
5389
mutex_unlock (& adapter -> crit_lock );
5390
+ mutex_unlock (& netdev -> lock );
5356
5391
5357
5392
return 0 ;
5358
5393
}
@@ -5451,6 +5486,7 @@ static void iavf_remove(struct pci_dev *pdev)
5451
5486
if (netdev -> reg_state == NETREG_REGISTERED )
5452
5487
unregister_netdev (netdev );
5453
5488
5489
+ mutex_lock (& netdev -> lock );
5454
5490
mutex_lock (& adapter -> crit_lock );
5455
5491
dev_info (& adapter -> pdev -> dev , "Removing device\n" );
5456
5492
iavf_change_state (adapter , __IAVF_REMOVE );
@@ -5487,6 +5523,7 @@ static void iavf_remove(struct pci_dev *pdev)
5487
5523
mutex_destroy (& hw -> aq .asq_mutex );
5488
5524
mutex_unlock (& adapter -> crit_lock );
5489
5525
mutex_destroy (& adapter -> crit_lock );
5526
+ mutex_unlock (& netdev -> lock );
5490
5527
5491
5528
iounmap (hw -> hw_addr );
5492
5529
pci_release_regions (pdev );
0 commit comments