i40e: keep q_vectors array in sync with channel count changes
Subsystems (3)
PATCH v2 1/1 i40e: keep q_vectors array in sync with channel count changes
For the main VSI, i40e_set_num_rings_in_vsi() always derives num_q_vectors from pf->num_lan_msix. At the same time, ethtool -L stores the user requested channel count in vsi->req_queue_pairs and the queue setup path uses that value for the effective number of queue pairs.
This leaves queue and vector counts out of sync after shrinking channel count via ethtool -L. The active queue configuration is reduced, but the VSI still keeps the full PF-sized q_vector topology.
That mismatch breaks reconfiguration flows which rely on vector/NAPI state matching the effective channel configuration. In particular, toggling /sys/class/net/<dev>/threaded after reducing the channel count can hang, and later channel-count changes can fail because VSI reinit does not rebuild q_vectors to match the new vector count.
Fix this by making the main VSI num_q_vectors follow the effective requested channel count, capped by the available MSI-X vectors. Update i40e_vsi_reinit_setup() to rebuild q_vectors during VSI reinit so the vector topology is refreshed together with the ring arrays when channel count changes.
Keep alloc_queue_pairs unchanged and based on pf->num_lan_qps so the VSI retains its full queue capacity.
Selftest napi_threaded.py was originally used when Jakub reported hang on /sys/class/net/<dev>/threaded toggle. In order to make it pass on i40e, use persistent NAPI configuration for q_vector NAPIs so NAPI identity and threaded settings survive q_vector reallocation across channel-count changes. This is achieved by using netif_napi_add_config() when configuring q_vectors.
$ export NETIF=ens259f1np1 $ sudo -E env PATH="$PATH" ./tools/testing/selftests/drivers/net/napi_threaded.py TAP version 13 1..3 ok 1 napi_threaded.napi_init ok 2 napi_threaded.change_num_queues ok 3 napi_threaded.enable_dev_threaded_disable_napi_threaded Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
---
v2:
- NULL vsi->tx_rings in i40e_vsi_alloc_arrays() (Sashiko)
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 35 +++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +29 -6
@@ -11403,10 +11403,14 @@ static void i40e_service_timer(struct timer_list *t)static int i40e_set_num_rings_in_vsi (struct i40e_vsi *vsi) {struct i40e_pf *pf = vsi->back; +u16 qps;switch (vsi->type) {case I40E_VSI_MAIN : vsi->alloc_queue_pairs = pf->num_lan_qps; + qps = vsi->req_queue_pairs ? +min_t (u16, vsi->req_queue_pairs, pf->num_lan_qps) : + pf->num_lan_qps;if (!vsi->num_tx_desc) vsi->num_tx_desc =ALIGN (I40E_DEFAULT_NUM_DESCRIPTORS ,I40E_REQ_DESCRIPTOR_MULTIPLE );
@@ -11414,7 +11418,8 @@ static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) vsi->num_rx_desc =ALIGN (I40E_DEFAULT_NUM_DESCRIPTORS ,I40E_REQ_DESCRIPTOR_MULTIPLE );if (test_bit (I40E_FLAG_MSIX_ENA , pf->flags)) - vsi->num_q_vectors = pf->num_lan_msix; + vsi->num_q_vectors =max_t (int,1 , +min_t (int, qps, pf->num_lan_msix));else vsi->num_q_vectors =1 ;
@@ -11503,6 +11508,7 @@ static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors) err_vectors:kfree (vsi->tx_rings); + vsi->tx_rings =NULL ;return ret; }
@@ -12043,7 +12049,8 @@ static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)cpumask_copy (&q_vector->affinity_mask, cpu_possible_mask);if (vsi->netdev) -netif_napi_add (vsi->netdev, &q_vector->napi, i40e_napi_poll); +netif_napi_add_config (vsi->netdev, &q_vector->napi, + i40e_napi_poll, v_idx);/* tie q_vector and vsi together */ vsi->q_vectors[v_idx] = q_vector;
@@ -14265,12 +14272,27 @@ static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) pf = vsi->back; +if (test_bit (I40E_FLAG_MSIX_ENA , pf->flags)) { +i40e_put_lump (pf->irq_pile, vsi->base_vector, vsi->idx); + vsi->base_vector =0 ; + } +i40e_put_lump (pf->qp_pile, vsi->base_queue, vsi->idx);i40e_vsi_clear_rings (vsi); -i40e_vsi_free_arrays (vsi, false); +i40e_vsi_free_q_vectors (vsi); +i40e_vsi_free_arrays (vsi, true);i40e_set_num_rings_in_vsi (vsi); - ret =i40e_vsi_alloc_arrays (vsi, false); + + ret =i40e_vsi_alloc_arrays (vsi, true); +if (ret) + goto err_vsi; + +/* Rebuild q_vectors during VSI reinit because the effective channel +* count may change num_q_vectors. Keep vector topology aligned with the +* queue configuration after ethtool's .set_channels() callback. +*/ + ret =i40e_vsi_setup_vectors (vsi);if (ret) goto err_vsi;
@@ -14282,7 +14304,7 @@ static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)dev_info (&pf->pdev->dev,"failed to get tracking for %d queues for VSI %d err %d\n" , alloc_queue_pairs, vsi->seid, ret); - goto err_vsi; + goto err_lump; } vsi->base_queue = ret;
@@ -14306,7 +14328,6 @@ static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)return vsi; err_rings: -i40e_vsi_free_q_vectors (vsi);if (vsi->netdev_registered) { vsi->netdev_registered = false;unregister_netdev (vsi->netdev);
@@ -14316,6 +14337,8 @@ static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)if (vsi->type ==I40E_VSI_MAIN )i40e_devlink_destroy_port (pf);i40e_aq_delete_element (&pf->hw, vsi->seid,NULL ); +err_lump: +i40e_vsi_free_q_vectors (vsi); err_vsi:i40e_vsi_clear (vsi);return NULL ;
Signature · 1 line
2.43.0
Quoted 40 lines · Maciej Fijalkowski
For the main VSI,
i40e_set_num_rings_in_vsi()always derivesnum_q_vectorsfrompf->num_lan_msix. At the same time, ethtool -L stores the user requested channel count invsi->req_queue_pairsand the queue setup path uses that value for the effective number of queue pairs.This leaves queue and vector counts out of sync after shrinking channel count via ethtool -L. The active queue configuration is reduced, but the VSI still keeps the full PF-sized
q_vectortopology.That mismatch breaks reconfiguration flows which rely on vector/NAPI state matching the effective channel configuration. In particular, toggling /sys/class/net/<dev>/threaded after reducing the channel count can hang, and later channel-count changes can fail because VSI reinit does not rebuild
q_vectorsto match the new vector count.Fix this by making the main VSI
num_q_vectorsfollow the effective requested channel count, capped by the available MSI-X vectors. Updatei40e_vsi_reinit_setup()to rebuildq_vectorsduring VSI reinit so the vector topology is refreshed together with the ring arrays when channel count changes.Keep
alloc_queue_pairsunchanged and based onpf->num_lan_qpsso the VSI retains its full queue capacity.Selftest
napi_threaded.pywas originally used when Jakub reported hang on /sys/class/net/<dev>/threaded toggle. In order to make it pass on i40e, use persistent NAPI configuration forq_vectorNAPIs so NAPI identity and threaded settings surviveq_vectorreallocation across channel-count changes. This is achieved by usingnetif_napi_add_config()when configuringq_vectors.$ export NETIF=ens259f1np1 $ sudo -E env PATH="$PATH" ./tools/testing/selftests/drivers/net/napi_threaded.py TAP version 13 1..3 ok 1 napi_threaded.napi_init ok 2 napi_threaded.change_num_queues ok 3 napi_threaded.enable_dev_threaded_disable_napi_threaded Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
Quoted 8 lines
Reported-by Jakub Kicinski <[email protected]>Fixes d2a69fefd756 ("i40e: Fix changing previously set num_queue_pairs for PFs")Signed-off-by Maciej Fijalkowski <[email protected]>---
v2:
- NULLvsi->tx_ringsini40e_vsi_alloc_arrays()(Sashiko)
---
Thanks Maciej,
I'll go ahead and replace the older version of the fix on dev-queue today. Apologies for missing the exchange related to this and the previous fix :(
Thanks,
Jake
Quoted 40 lines · Maciej Fijalkowski
For the main VSI,
i40e_set_num_rings_in_vsi()always derivesnum_q_vectorsfrompf->num_lan_msix. At the same time, ethtool -L stores the user requested channel count invsi->req_queue_pairsand the queue setup path uses that value for the effective number of queue pairs.This leaves queue and vector counts out of sync after shrinking channel count via ethtool -L. The active queue configuration is reduced, but the VSI still keeps the full PF-sized
q_vectortopology.That mismatch breaks reconfiguration flows which rely on vector/NAPI state matching the effective channel configuration. In particular, toggling /sys/class/net/<dev>/threaded after reducing the channel count can hang, and later channel-count changes can fail because VSI reinit does not rebuild
q_vectorsto match the new vector count.Fix this by making the main VSI
num_q_vectorsfollow the effective requested channel count, capped by the available MSI-X vectors. Updatei40e_vsi_reinit_setup()to rebuildq_vectorsduring VSI reinit so the vector topology is refreshed together with the ring arrays when channel count changes.Keep
alloc_queue_pairsunchanged and based onpf->num_lan_qpsso the VSI retains its full queue capacity.Selftest
napi_threaded.pywas originally used when Jakub reported hang on /sys/class/net/<dev>/threaded toggle. In order to make it pass on i40e, use persistent NAPI configuration forq_vectorNAPIs so NAPI identity and threaded settings surviveq_vectorreallocation across channel-count changes. This is achieved by usingnetif_napi_add_config()when configuringq_vectors.$ export NETIF=ens259f1np1 $ sudo -E env PATH="$PATH" ./tools/testing/selftests/drivers/net/napi_threaded.py TAP version 13 1..3 ok 1 napi_threaded.napi_init ok 2 napi_threaded.change_num_queues ok 3 napi_threaded.enable_dev_threaded_disable_napi_threaded Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
Quoted 7 lines
Reported-by Jakub Kicinski <[email protected]>Fixes d2a69fefd756 ("i40e: Fix changing previously set num_queue_pairs for PFs")Signed-off-by Maciej Fijalkowski <[email protected]>---
v2:
- NULLvsi->tx_ringsini40e_vsi_alloc_arrays()(Sashiko)
Quoted 9 lines
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 35 +++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-)drivers/net/ethernet/intel/i40e/i40e_main.c +0
-0
drivers/net/ethernet/intel/i40e/i40e_main.c static void i40e_service_timer(struct timer_list *t) · line 11412
Quoted 10 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +3
-0@@ -11403,10 +11403,14 @@ static void i40e_service_timer(struct timer_list *t)static int i40e_set_num_rings_in_vsi (struct i40e_vsi *vsi) {struct i40e_pf *pf = vsi->back; +u16 qps;switch (vsi->type) {case I40E_VSI_MAIN : vsi->alloc_queue_pairs = pf->num_lan_qps; + qps = vsi->req_queue_pairs ? + min_t(u16, vsi->req_queue_pairs, pf->num_lan_qps) :
nit: It looks all the variables involved here u16.
So min() can be used instead of min_t().
drivers/net/ethernet/intel/i40e/i40e_main.c static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) · line 11422
Quoted 11 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +3
-1+ pf->num_lan_qps;if (!vsi->num_tx_desc) vsi->num_tx_desc =ALIGN (I40E_DEFAULT_NUM_DESCRIPTORS ,I40E_REQ_DESCRIPTOR_MULTIPLE );@@ -11414,7 +11418,8 @@ static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) vsi->num_rx_desc =ALIGN (I40E_DEFAULT_NUM_DESCRIPTORS ,I40E_REQ_DESCRIPTOR_MULTIPLE );if (test_bit (I40E_FLAG_MSIX_ENA , pf->flags)) - vsi->num_q_vectors = pf->num_lan_msix; + vsi->num_q_vectors =max_t (int,1 , +min_t (int, qps, pf->num_lan_msix));
nit: On the left side, all values seem to be either constants or u16.
So I think you can use clamp() here, and simply assign the resulting value to num_q_vectors, which is an int.
Quoted 3 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +0
-0else vsi->num_q_vectors =1 ;
...
Quoted 5 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +1
-0@@ -14265,12 +14272,27 @@ static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) pf = vsi->back; +if (test_bit (I40E_FLAG_MSIX_ENA , pf->flags)) {
drivers/net/ethernet/intel/i40e/i40e_main.c static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) · line 14284
Quoted 10 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +6
-1+i40e_put_lump (pf->irq_pile, vsi->base_vector, vsi->idx); + vsi->base_vector =0 ; + } +i40e_put_lump (pf->qp_pile, vsi->base_queue, vsi->idx);i40e_vsi_clear_rings (vsi); -i40e_vsi_free_arrays (vsi, false); +i40e_vsi_free_q_vectors (vsi); +i40e_vsi_free_arrays (vsi, true);
nit: with this patch applied the free_vectors argument (the 2nd parameter)
of i40e_vsi_free_arrays is always passed as true by callers. So I think that, as a follow-up, it can be removed.
Similarly for i40e_vsi_alloc_arrays.
Quoted 15 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +10
-1i40e_set_num_rings_in_vsi (vsi); - ret =i40e_vsi_alloc_arrays (vsi, false); + + ret =i40e_vsi_alloc_arrays (vsi, true); +if (ret) + goto err_vsi; + +/* Rebuild q_vectors during VSI reinit because the effective channel +* count may change num_q_vectors. Keep vector topology aligned with the +* queue configuration after ethtool's .set_channels() callback. +*/ + ret =i40e_vsi_setup_vectors (vsi);if (ret) goto err_vsi;
...
Quoted 51 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Maciej Fijalkowski
Sent: Thursday, April 16, 2026 4:41 AM
To: [email protected]
Cc: [email protected]; Karlsson, Magnus <[email protected]>; [email protected]; [email protected]; [email protected]; Kitszel, Przemyslaw <[email protected]>; Keller, > Jacob E <[email protected]>; Fijalkowski, Maciej <[email protected]>
Subject: [Intel-wired-lan] [PATCH v2 iwl-net] i40e: keepq_vectorsarray in sync with channel count changesFor the main VSI,
i40e_set_num_rings_in_vsi()always derivesnum_q_vectorsfrompf->num_lan_msix. At the same time, ethtool -L stores the user requested channel count invsi->req_queue_pairsand the queue setup path uses that value for the effective number of queue pairs.This leaves queue and vector counts out of sync after shrinking channel count via ethtool -L. The active queue configuration is reduced, but the VSI still keeps the full PF-sized
q_vectortopology.That mismatch breaks reconfiguration flows which rely on vector/NAPI state matching the effective channel configuration. In particular, toggling /sys/class/net/<dev>/threaded after reducing the channel count can hang, and later channel-count changes can fail because VSI reinit does not rebuild
q_vectorsto match the new vector count.Fix this by making the main VSI
num_q_vectorsfollow the effective requested channel count, capped by the available MSI-X vectors. Updatei40e_vsi_reinit_setup()to rebuildq_vectorsduring VSI reinit so the vector topology is refreshed together with the ring arrays when channel count changes.Keep
alloc_queue_pairsunchanged and based onpf->num_lan_qpsso the VSI retains its full queue capacity.Selftest
napi_threaded.pywas originally used when Jakub reported hang on /sys/class/net/<dev>/threaded toggle. In order to make it pass on i40e, use persistent NAPI configuration forq_vectorNAPIs so NAPI identity and threaded settings surviveq_vectorreallocation across channel-count changes. This is achieved by usingnetif_napi_add_config()when configuringq_vectors.$ export NETIF=ens259f1np1 $ sudo -E env PATH="$PATH" ./tools/testing/selftests/drivers/net/napi_threaded.py TAP version 13 1..3 ok 1 napi_threaded.napi_init ok 2 napi_threaded.change_num_queues ok 3 napi_threaded.enable_dev_threaded_disable_napi_threaded Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0Reported-by Jakub Kicinski <[email protected]>Fixes d2a69fefd756 ("i40e: Fix changing previously set num_queue_pairs for PFs")Signed-off-by Maciej Fijalkowski <[email protected]>
Quoted 6 lines
---
v2:
- NULLvsi->tx_ringsini40e_vsi_alloc_arrays()(Sashiko)--- drivers/net/ethernet/intel/i40e/i40e_main.c | 35 +++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-)