Skip to content

Commit 6dd7291

Browse files
committed
i40e: fix vf may be used uninitialized in this function warning
jira LE-1907 cve CVE-2024-36020 Rebuild_History Non-Buildable kernel-5.14.0-427.31.1.el9_4 commit-author Aleksandr Loktionov <aleksandr.loktionov@intel.com> commit f37c4ea To fix the regression introduced by commit 52424f9, which causes servers hang in very hard to reproduce conditions with resets races. Using two sources for the information is the root cause. In this function before the fix bumping v didn't mean bumping vf pointer. But the code used this variables interchangeably, so stale vf could point to different/not intended vf. Remove redundant "v" variable and iterate via single VF pointer across whole function instead to guarantee VF pointer validity. Fixes: 52424f9 ("i40e: Fix VF hang when reset is triggered on another VF") Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Reviewed-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Tested-by: Rafal Romanowski <rafal.romanowski@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> (cherry picked from commit f37c4ea) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 442888d commit 6dd7291

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,8 +1628,8 @@ bool i40e_reset_all_vfs(struct i40e_pf *pf, bool flr)
16281628
{
16291629
struct i40e_hw *hw = &pf->hw;
16301630
struct i40e_vf *vf;
1631-
int i, v;
16321631
u32 reg;
1632+
int i;
16331633

16341634
/* If we don't have any VFs, then there is nothing to reset */
16351635
if (!pf->num_alloc_vfs)
@@ -1640,11 +1640,10 @@ bool i40e_reset_all_vfs(struct i40e_pf *pf, bool flr)
16401640
return false;
16411641

16421642
/* Begin reset on all VFs at once */
1643-
for (v = 0; v < pf->num_alloc_vfs; v++) {
1644-
vf = &pf->vf[v];
1643+
for (vf = &pf->vf[0]; vf < &pf->vf[pf->num_alloc_vfs]; ++vf) {
16451644
/* If VF is being reset no need to trigger reset again */
16461645
if (!test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
1647-
i40e_trigger_vf_reset(&pf->vf[v], flr);
1646+
i40e_trigger_vf_reset(vf, flr);
16481647
}
16491648

16501649
/* HW requires some time to make sure it can flush the FIFO for a VF
@@ -1653,14 +1652,13 @@ bool i40e_reset_all_vfs(struct i40e_pf *pf, bool flr)
16531652
* the VFs using a simple iterator that increments once that VF has
16541653
* finished resetting.
16551654
*/
1656-
for (i = 0, v = 0; i < 10 && v < pf->num_alloc_vfs; i++) {
1655+
for (i = 0, vf = &pf->vf[0]; i < 10 && vf < &pf->vf[pf->num_alloc_vfs]; ++i) {
16571656
usleep_range(10000, 20000);
16581657

16591658
/* Check each VF in sequence, beginning with the VF to fail
16601659
* the previous check.
16611660
*/
1662-
while (v < pf->num_alloc_vfs) {
1663-
vf = &pf->vf[v];
1661+
while (vf < &pf->vf[pf->num_alloc_vfs]) {
16641662
if (!test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states)) {
16651663
reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
16661664
if (!(reg & I40E_VPGEN_VFRSTAT_VFRD_MASK))
@@ -1670,7 +1668,7 @@ bool i40e_reset_all_vfs(struct i40e_pf *pf, bool flr)
16701668
/* If the current VF has finished resetting, move on
16711669
* to the next VF in sequence.
16721670
*/
1673-
v++;
1671+
++vf;
16741672
}
16751673
}
16761674

@@ -1680,39 +1678,39 @@ bool i40e_reset_all_vfs(struct i40e_pf *pf, bool flr)
16801678
/* Display a warning if at least one VF didn't manage to reset in
16811679
* time, but continue on with the operation.
16821680
*/
1683-
if (v < pf->num_alloc_vfs)
1681+
if (vf < &pf->vf[pf->num_alloc_vfs])
16841682
dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
1685-
pf->vf[v].vf_id);
1683+
vf->vf_id);
16861684
usleep_range(10000, 20000);
16871685

16881686
/* Begin disabling all the rings associated with VFs, but do not wait
16891687
* between each VF.
16901688
*/
1691-
for (v = 0; v < pf->num_alloc_vfs; v++) {
1689+
for (vf = &pf->vf[0]; vf < &pf->vf[pf->num_alloc_vfs]; ++vf) {
16921690
/* On initial reset, we don't have any queues to disable */
1693-
if (pf->vf[v].lan_vsi_idx == 0)
1691+
if (vf->lan_vsi_idx == 0)
16941692
continue;
16951693

16961694
/* If VF is reset in another thread just continue */
16971695
if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
16981696
continue;
16991697

1700-
i40e_vsi_stop_rings_no_wait(pf->vsi[pf->vf[v].lan_vsi_idx]);
1698+
i40e_vsi_stop_rings_no_wait(pf->vsi[vf->lan_vsi_idx]);
17011699
}
17021700

17031701
/* Now that we've notified HW to disable all of the VF rings, wait
17041702
* until they finish.
17051703
*/
1706-
for (v = 0; v < pf->num_alloc_vfs; v++) {
1704+
for (vf = &pf->vf[0]; vf < &pf->vf[pf->num_alloc_vfs]; ++vf) {
17071705
/* On initial reset, we don't have any queues to disable */
1708-
if (pf->vf[v].lan_vsi_idx == 0)
1706+
if (vf->lan_vsi_idx == 0)
17091707
continue;
17101708

17111709
/* If VF is reset in another thread just continue */
17121710
if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
17131711
continue;
17141712

1715-
i40e_vsi_wait_queues_disabled(pf->vsi[pf->vf[v].lan_vsi_idx]);
1713+
i40e_vsi_wait_queues_disabled(pf->vsi[vf->lan_vsi_idx]);
17161714
}
17171715

17181716
/* Hw may need up to 50ms to finish disabling the RX queues. We
@@ -1721,12 +1719,12 @@ bool i40e_reset_all_vfs(struct i40e_pf *pf, bool flr)
17211719
mdelay(50);
17221720

17231721
/* Finish the reset on each VF */
1724-
for (v = 0; v < pf->num_alloc_vfs; v++) {
1722+
for (vf = &pf->vf[0]; vf < &pf->vf[pf->num_alloc_vfs]; ++vf) {
17251723
/* If VF is reset in another thread just continue */
17261724
if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
17271725
continue;
17281726

1729-
i40e_cleanup_reset_vf(&pf->vf[v]);
1727+
i40e_cleanup_reset_vf(vf);
17301728
}
17311729

17321730
i40e_flush(hw);

0 commit comments

Comments
 (0)