Skip to content

Commit 2a5dc09

Browse files
walking-machineanguy11
authored andcommitted
ice: move netif_queue_set_napi to rtnl-protected sections
Currently, netif_queue_set_napi() is called from ice_vsi_rebuild() that is not rtnl-locked when called from the reset. This creates the need to take the rtnl_lock just for a single function and complicates the synchronization with .ndo_bpf. At the same time, there no actual need to fill napi-to-queue information at this exact point. Fill napi-to-queue information when opening the VSI and clear it when the VSI is being closed. Those routines are already rtnl-locked. Also, rewrite napi-to-queue assignment in a way that prevents inclusion of XDP queues, as this leads to out-of-bounds writes, such as one below. [ +0.000004] BUG: KASAN: slab-out-of-bounds in netif_queue_set_napi+0x1c2/0x1e0 [ +0.000012] Write of size 8 at addr ffff889881727c80 by task bash/7047 [ +0.000006] CPU: 24 PID: 7047 Comm: bash Not tainted 6.10.0-rc2+ #2 [ +0.000004] Hardware name: Intel Corporation S2600WFT/S2600WFT, BIOS SE5C620.86B.02.01.0014.082620210524 08/26/2021 [ +0.000003] Call Trace: [ +0.000003] <TASK> [ +0.000002] dump_stack_lvl+0x60/0x80 [ +0.000007] print_report+0xce/0x630 [ +0.000007] ? __pfx__raw_spin_lock_irqsave+0x10/0x10 [ +0.000007] ? __virt_addr_valid+0x1c9/0x2c0 [ +0.000005] ? netif_queue_set_napi+0x1c2/0x1e0 [ +0.000003] kasan_report+0xe9/0x120 [ +0.000004] ? netif_queue_set_napi+0x1c2/0x1e0 [ +0.000004] netif_queue_set_napi+0x1c2/0x1e0 [ +0.000005] ice_vsi_close+0x161/0x670 [ice] [ +0.000114] ice_dis_vsi+0x22f/0x270 [ice] [ +0.000095] ice_pf_dis_all_vsi.constprop.0+0xae/0x1c0 [ice] [ +0.000086] ice_prepare_for_reset+0x299/0x750 [ice] [ +0.000087] pci_dev_save_and_disable+0x82/0xd0 [ +0.000006] pci_reset_function+0x12d/0x230 [ +0.000004] reset_store+0xa0/0x100 [ +0.000006] ? __pfx_reset_store+0x10/0x10 [ +0.000002] ? __pfx_mutex_lock+0x10/0x10 [ +0.000004] ? __check_object_size+0x4c1/0x640 [ +0.000007] kernfs_fop_write_iter+0x30b/0x4a0 [ +0.000006] vfs_write+0x5d6/0xdf0 [ +0.000005] ? fd_install+0x180/0x350 [ +0.000005] ? __pfx_vfs_write+0x10/0xA10 [ +0.000004] ? do_fcntl+0x52c/0xcd0 [ +0.000004] ? kasan_save_track+0x13/0x60 [ +0.000003] ? kasan_save_free_info+0x37/0x60 [ +0.000006] ksys_write+0xfa/0x1d0 [ +0.000003] ? __pfx_ksys_write+0x10/0x10 [ +0.000002] ? __x64_sys_fcntl+0x121/0x180 [ +0.000004] ? _raw_spin_lock+0x87/0xe0 [ +0.000005] do_syscall_64+0x80/0x170 [ +0.000007] ? _raw_spin_lock+0x87/0xe0 [ +0.000004] ? __pfx__raw_spin_lock+0x10/0x10 [ +0.000003] ? file_close_fd_locked+0x167/0x230 [ +0.000005] ? syscall_exit_to_user_mode+0x7d/0x220 [ +0.000005] ? do_syscall_64+0x8c/0x170 [ +0.000004] ? do_syscall_64+0x8c/0x170 [ +0.000003] ? do_syscall_64+0x8c/0x170 [ +0.000003] ? fput+0x1a/0x2c0 [ +0.000004] ? filp_close+0x19/0x30 [ +0.000004] ? do_dup2+0x25a/0x4c0 [ +0.000004] ? __x64_sys_dup2+0x6e/0x2e0 [ +0.000002] ? syscall_exit_to_user_mode+0x7d/0x220 [ +0.000004] ? do_syscall_64+0x8c/0x170 [ +0.000003] ? __count_memcg_events+0x113/0x380 [ +0.000005] ? handle_mm_fault+0x136/0x820 [ +0.000005] ? do_user_addr_fault+0x444/0xa80 [ +0.000004] ? clear_bhb_loop+0x25/0x80 [ +0.000004] ? clear_bhb_loop+0x25/0x80 [ +0.000002] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ +0.000005] RIP: 0033:0x7f2033593154 Fixes: 080b0c8 ("ice: Fix ASSERT_RTNL() warning during certain scenarios") Fixes: 91fdbce ("ice: Add support in the driver for associating queue with napi") Reviewed-by: Wojciech Drewek <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Reviewed-by: Amritha Nambiar <[email protected]> Signed-off-by: Larysa Zaremba <[email protected]> Reviewed-by: Maciej Fijalkowski <[email protected]> Tested-by: George Kuruvinakunnel <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent cfd433c commit 2a5dc09

File tree

4 files changed

+49
-118
lines changed

4 files changed

+49
-118
lines changed

drivers/net/ethernet/intel/ice/ice_base.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,11 @@ static void ice_free_q_vector(struct ice_vsi *vsi, int v_idx)
190190
}
191191
q_vector = vsi->q_vectors[v_idx];
192192

193-
ice_for_each_tx_ring(tx_ring, q_vector->tx) {
194-
ice_queue_set_napi(vsi, tx_ring->q_index, NETDEV_QUEUE_TYPE_TX,
195-
NULL);
193+
ice_for_each_tx_ring(tx_ring, vsi->q_vectors[v_idx]->tx)
196194
tx_ring->q_vector = NULL;
197-
}
198-
ice_for_each_rx_ring(rx_ring, q_vector->rx) {
199-
ice_queue_set_napi(vsi, rx_ring->q_index, NETDEV_QUEUE_TYPE_RX,
200-
NULL);
195+
196+
ice_for_each_rx_ring(rx_ring, vsi->q_vectors[v_idx]->rx)
201197
rx_ring->q_vector = NULL;
202-
}
203198

204199
/* only VSI with an associated netdev is set up with NAPI */
205200
if (vsi->netdev)

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 31 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,9 +2286,6 @@ static int ice_vsi_cfg_def(struct ice_vsi *vsi)
22862286

22872287
ice_vsi_map_rings_to_vectors(vsi);
22882288

2289-
/* Associate q_vector rings to napi */
2290-
ice_vsi_set_napi_queues(vsi);
2291-
22922289
vsi->stat_offsets_loaded = false;
22932290

22942291
/* ICE_VSI_CTRL does not need RSS so skip RSS processing */
@@ -2628,6 +2625,7 @@ void ice_vsi_close(struct ice_vsi *vsi)
26282625
if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state))
26292626
ice_down(vsi);
26302627

2628+
ice_vsi_clear_napi_queues(vsi);
26312629
ice_vsi_free_irq(vsi);
26322630
ice_vsi_free_tx_rings(vsi);
26332631
ice_vsi_free_rx_rings(vsi);
@@ -2694,120 +2692,55 @@ void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
26942692
}
26952693

26962694
/**
2697-
* __ice_queue_set_napi - Set the napi instance for the queue
2698-
* @dev: device to which NAPI and queue belong
2699-
* @queue_index: Index of queue
2700-
* @type: queue type as RX or TX
2701-
* @napi: NAPI context
2702-
* @locked: is the rtnl_lock already held
2703-
*
2704-
* Set the napi instance for the queue. Caller indicates the lock status.
2705-
*/
2706-
static void
2707-
__ice_queue_set_napi(struct net_device *dev, unsigned int queue_index,
2708-
enum netdev_queue_type type, struct napi_struct *napi,
2709-
bool locked)
2710-
{
2711-
if (!locked)
2712-
rtnl_lock();
2713-
netif_queue_set_napi(dev, queue_index, type, napi);
2714-
if (!locked)
2715-
rtnl_unlock();
2716-
}
2717-
2718-
/**
2719-
* ice_queue_set_napi - Set the napi instance for the queue
2720-
* @vsi: VSI being configured
2721-
* @queue_index: Index of queue
2722-
* @type: queue type as RX or TX
2723-
* @napi: NAPI context
2695+
* ice_vsi_set_napi_queues - associate netdev queues with napi
2696+
* @vsi: VSI pointer
27242697
*
2725-
* Set the napi instance for the queue. The rtnl lock state is derived from the
2726-
* execution path.
2698+
* Associate queue[s] with napi for all vectors.
2699+
* The caller must hold rtnl_lock.
27272700
*/
2728-
void
2729-
ice_queue_set_napi(struct ice_vsi *vsi, unsigned int queue_index,
2730-
enum netdev_queue_type type, struct napi_struct *napi)
2701+
void ice_vsi_set_napi_queues(struct ice_vsi *vsi)
27312702
{
2732-
struct ice_pf *pf = vsi->back;
2703+
struct net_device *netdev = vsi->netdev;
2704+
int q_idx, v_idx;
27332705

2734-
if (!vsi->netdev)
2706+
if (!netdev)
27352707
return;
27362708

2737-
if (current_work() == &pf->serv_task ||
2738-
test_bit(ICE_PREPARED_FOR_RESET, pf->state) ||
2739-
test_bit(ICE_DOWN, pf->state) ||
2740-
test_bit(ICE_SUSPENDED, pf->state))
2741-
__ice_queue_set_napi(vsi->netdev, queue_index, type, napi,
2742-
false);
2743-
else
2744-
__ice_queue_set_napi(vsi->netdev, queue_index, type, napi,
2745-
true);
2746-
}
2709+
ice_for_each_rxq(vsi, q_idx)
2710+
netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_RX,
2711+
&vsi->rx_rings[q_idx]->q_vector->napi);
27472712

2748-
/**
2749-
* __ice_q_vector_set_napi_queues - Map queue[s] associated with the napi
2750-
* @q_vector: q_vector pointer
2751-
* @locked: is the rtnl_lock already held
2752-
*
2753-
* Associate the q_vector napi with all the queue[s] on the vector.
2754-
* Caller indicates the lock status.
2755-
*/
2756-
void __ice_q_vector_set_napi_queues(struct ice_q_vector *q_vector, bool locked)
2757-
{
2758-
struct ice_rx_ring *rx_ring;
2759-
struct ice_tx_ring *tx_ring;
2760-
2761-
ice_for_each_rx_ring(rx_ring, q_vector->rx)
2762-
__ice_queue_set_napi(q_vector->vsi->netdev, rx_ring->q_index,
2763-
NETDEV_QUEUE_TYPE_RX, &q_vector->napi,
2764-
locked);
2765-
2766-
ice_for_each_tx_ring(tx_ring, q_vector->tx)
2767-
__ice_queue_set_napi(q_vector->vsi->netdev, tx_ring->q_index,
2768-
NETDEV_QUEUE_TYPE_TX, &q_vector->napi,
2769-
locked);
2713+
ice_for_each_txq(vsi, q_idx)
2714+
netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_TX,
2715+
&vsi->tx_rings[q_idx]->q_vector->napi);
27702716
/* Also set the interrupt number for the NAPI */
2771-
netif_napi_set_irq(&q_vector->napi, q_vector->irq.virq);
2772-
}
2717+
ice_for_each_q_vector(vsi, v_idx) {
2718+
struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
27732719

2774-
/**
2775-
* ice_q_vector_set_napi_queues - Map queue[s] associated with the napi
2776-
* @q_vector: q_vector pointer
2777-
*
2778-
* Associate the q_vector napi with all the queue[s] on the vector
2779-
*/
2780-
void ice_q_vector_set_napi_queues(struct ice_q_vector *q_vector)
2781-
{
2782-
struct ice_rx_ring *rx_ring;
2783-
struct ice_tx_ring *tx_ring;
2784-
2785-
ice_for_each_rx_ring(rx_ring, q_vector->rx)
2786-
ice_queue_set_napi(q_vector->vsi, rx_ring->q_index,
2787-
NETDEV_QUEUE_TYPE_RX, &q_vector->napi);
2788-
2789-
ice_for_each_tx_ring(tx_ring, q_vector->tx)
2790-
ice_queue_set_napi(q_vector->vsi, tx_ring->q_index,
2791-
NETDEV_QUEUE_TYPE_TX, &q_vector->napi);
2792-
/* Also set the interrupt number for the NAPI */
2793-
netif_napi_set_irq(&q_vector->napi, q_vector->irq.virq);
2720+
netif_napi_set_irq(&q_vector->napi, q_vector->irq.virq);
2721+
}
27942722
}
27952723

27962724
/**
2797-
* ice_vsi_set_napi_queues
2725+
* ice_vsi_clear_napi_queues - dissociate netdev queues from napi
27982726
* @vsi: VSI pointer
27992727
*
2800-
* Associate queue[s] with napi for all vectors
2728+
* Clear the association between all VSI queues queue[s] and napi.
2729+
* The caller must hold rtnl_lock.
28012730
*/
2802-
void ice_vsi_set_napi_queues(struct ice_vsi *vsi)
2731+
void ice_vsi_clear_napi_queues(struct ice_vsi *vsi)
28032732
{
2804-
int i;
2733+
struct net_device *netdev = vsi->netdev;
2734+
int q_idx;
28052735

2806-
if (!vsi->netdev)
2736+
if (!netdev)
28072737
return;
28082738

2809-
ice_for_each_q_vector(vsi, i)
2810-
ice_q_vector_set_napi_queues(vsi->q_vectors[i]);
2739+
ice_for_each_txq(vsi, q_idx)
2740+
netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_TX, NULL);
2741+
2742+
ice_for_each_rxq(vsi, q_idx)
2743+
netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_RX, NULL);
28112744
}
28122745

28132746
/**

drivers/net/ethernet/intel/ice/ice_lib.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,10 @@ void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc);
4444
struct ice_vsi *
4545
ice_vsi_setup(struct ice_pf *pf, struct ice_vsi_cfg_params *params);
4646

47-
void
48-
ice_queue_set_napi(struct ice_vsi *vsi, unsigned int queue_index,
49-
enum netdev_queue_type type, struct napi_struct *napi);
50-
51-
void __ice_q_vector_set_napi_queues(struct ice_q_vector *q_vector, bool locked);
52-
53-
void ice_q_vector_set_napi_queues(struct ice_q_vector *q_vector);
54-
5547
void ice_vsi_set_napi_queues(struct ice_vsi *vsi);
5648

49+
void ice_vsi_clear_napi_queues(struct ice_vsi *vsi);
50+
5751
int ice_vsi_release(struct ice_vsi *vsi);
5852

5953
void ice_vsi_close(struct ice_vsi *vsi);

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,11 +3558,9 @@ static void ice_napi_add(struct ice_vsi *vsi)
35583558
if (!vsi->netdev)
35593559
return;
35603560

3561-
ice_for_each_q_vector(vsi, v_idx) {
3561+
ice_for_each_q_vector(vsi, v_idx)
35623562
netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
35633563
ice_napi_poll);
3564-
__ice_q_vector_set_napi_queues(vsi->q_vectors[v_idx], false);
3565-
}
35663564
}
35673565

35683566
/**
@@ -5540,7 +5538,9 @@ static int ice_reinit_interrupt_scheme(struct ice_pf *pf)
55405538
if (ret)
55415539
goto err_reinit;
55425540
ice_vsi_map_rings_to_vectors(pf->vsi[v]);
5541+
rtnl_lock();
55435542
ice_vsi_set_napi_queues(pf->vsi[v]);
5543+
rtnl_unlock();
55445544
}
55455545

55465546
ret = ice_req_irq_msix_misc(pf);
@@ -5554,8 +5554,12 @@ static int ice_reinit_interrupt_scheme(struct ice_pf *pf)
55545554

55555555
err_reinit:
55565556
while (v--)
5557-
if (pf->vsi[v])
5557+
if (pf->vsi[v]) {
5558+
rtnl_lock();
5559+
ice_vsi_clear_napi_queues(pf->vsi[v]);
5560+
rtnl_unlock();
55585561
ice_vsi_free_q_vectors(pf->vsi[v]);
5562+
}
55595563

55605564
return ret;
55615565
}
@@ -5620,6 +5624,9 @@ static int ice_suspend(struct device *dev)
56205624
ice_for_each_vsi(pf, v) {
56215625
if (!pf->vsi[v])
56225626
continue;
5627+
rtnl_lock();
5628+
ice_vsi_clear_napi_queues(pf->vsi[v]);
5629+
rtnl_unlock();
56235630
ice_vsi_free_q_vectors(pf->vsi[v]);
56245631
}
56255632
ice_clear_interrupt_scheme(pf);
@@ -7455,6 +7462,8 @@ int ice_vsi_open(struct ice_vsi *vsi)
74557462
err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
74567463
if (err)
74577464
goto err_set_qs;
7465+
7466+
ice_vsi_set_napi_queues(vsi);
74587467
}
74597468

74607469
err = ice_up_complete(vsi);

0 commit comments

Comments
 (0)