Re: drivers/net/ethernet/intel/i40e/i40e_main.c:7089:35-37: ERROR: invalid reference to the index variable of the iterator on line 7056 (fwd)

From: Jeff Kirsher
Date: Thu Aug 08 2019 - 17:55:55 EST


On Thu, 2019-08-08 at 18:08 +0200, Julia Lawall wrote:
> Hello,
>
> Is it guaranteed that the loop starting on line 7056 will eventually
> take
> the break? If not, line 7089 will be performing an invalid
> dereference of
> ch.

Good catch Julia, I have talked with Harshitha and if after checking
the list of channels and not finding an available channel, we should
exit the function instead of proceeding on to add the MACVLAN filter.

Harshitha said she would put together a patch to fix the issue in the
next day or two, unless you or someone else gets to it first.

>
> ---------- Forwarded message ----------
> Date: Thu, 8 Aug 2019 21:31:53 +0800
> From: kbuild test robot <lkp@xxxxxxxxx>
> To: kbuild@xxxxxx
> Cc: Julia Lawall <julia.lawall@xxxxxxx>
> Subject: drivers/net/ethernet/intel/i40e/i40e_main.c:7089:35-37:
> ERROR: invalid
> reference to the index variable of the iterator on line 7056
>
> CC: kbuild-all@xxxxxx
> CC: linux-kernel@xxxxxxxxxxxxxxx
> TO: Harshitha Ramamurthy <harshitha.ramamurthy@xxxxxxxxx>
> CC: Jeff Kirsher <jeffrey.t.kirsher@xxxxxxxxx>
>
> tree:
> https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux.git
> master
> head: ecb095bff5d4b8711a81968625b3b4a235d3e477
> commit: 1d8d80b4e4ff641eefa5250cba324dfa5861a9f1 i40e: Add macvlan
> support on i40e
> date: 6 weeks ago
> :::::: branch date: 15 hours ago
> :::::: commit date: 6 weeks ago
>
> If you fix the issue, kindly add following tag
> Reported-by: kbuild test robot <lkp@xxxxxxxxx>
> Reported-by: Julia Lawall <julia.lawall@xxxxxxx>
>
> > > drivers/net/ethernet/intel/i40e/i40e_main.c:7089:35-37: ERROR:
> > > invalid reference to the index variable of the iterator on line
> > > 7056
>
> git remote add linus
> https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux.git
> git remote update linus
> git checkout 1d8d80b4e4ff641eefa5250cba324dfa5861a9f1
> vim +7089 drivers/net/ethernet/intel/i40e/i40e_main.c
>
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7037
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7038 /**
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7039 *
> i40e_fwd_ring_up - bring the macvlan device up
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7040 * @vsi: the
> VSI we want to access
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7041 * @vdev:
> macvlan netdevice
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7042 * @fwd: the
> private fwd structure
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7043 */
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7044 static int
> i40e_fwd_ring_up(struct i40e_vsi *vsi, struct net_device *vdev,
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7045
> struct i40e_fwd_adapter *fwd)
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7046 {
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7047 int ret
> = 0, num_tc = 1, i, aq_err;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7048 struct
> i40e_channel *ch, *ch_tmp;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7049 struct
> i40e_pf *pf = vsi->back;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7050 struct
> i40e_hw *hw = &pf->hw;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7051
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7052 if
> (list_empty(&vsi->macvlan_list))
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7053
> return -EINVAL;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7054
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7055 /* Go
> through the list and find an available channel */
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 @7056 list_fo
> r_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7057
> if (!i40e_is_channel_macvlan(ch)) {
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7058
> ch->fwd = fwd;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7059
> /* record configuration for macvlan interface in vdev */
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7060
> for (i = 0; i < num_tc; i++)
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7061
> netdev_bind_sb_channel_queue(vsi->netdev, vdev,
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7062
> i,
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7063
> ch->num_queue_pairs,
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7064
> ch->base_queue);
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7065
> for (i = 0; i < ch->num_queue_pairs; i++) {
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7066
> struct i40e_ring *tx_ring, *rx_ring;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7067
> u16 pf_q;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7068
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7069
> pf_q = ch->base_queue + i;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7070
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7071
> /* Get to TX ring ptr */
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7072
> tx_ring = vsi->tx_rings[pf_q];
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7073
> tx_ring->ch = ch;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7074
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7075
> /* Get the RX ring ptr */
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7076
> rx_ring = vsi->rx_rings[pf_q];
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7077
> rx_ring->ch = ch;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7078
> }
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7079
> break;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7080
> }
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7081 }
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7082
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7083 /*
> Guarantee all rings are updated before we update the
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7084 * MAC
> address filter.
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7085 */
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7086 wmb();
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7087
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7088 /* Add
> a mac filter */
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 @7089 ret =
> i40e_add_macvlan_filter(hw, ch->seid, vdev->dev_addr, &aq_err);
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7090 if
> (ret) {
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7091
> /* if we cannot add the MAC rule then disable the offload */
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7092
> macvlan_release_l2fw_offload(vdev);
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7093
> for (i = 0; i < ch->num_queue_pairs; i++) {
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7094
> struct i40e_ring *rx_ring;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7095
> u16 pf_q;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7096
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7097
> pf_q = ch->base_queue + i;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7098
> rx_ring = vsi->rx_rings[pf_q];
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7099
> rx_ring->netdev = NULL;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7100
> }
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7101
> dev_info(&pf->pdev->dev,
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7102
> "Error adding mac filter on macvlan err %s, aq_err %s\n",
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7103
> i40e_stat_str(hw, ret),
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7104
> i40e_aq_str(hw, aq_err));
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7105
> netdev_err(vdev, "L2fwd offload disabled to L2 filter error\n");
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7106 }
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7107
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7108 return
> ret;
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7109 }
> 1d8d80b4e4ff64 Harshitha Ramamurthy 2019-06-19 7110
>
> ---
> 0-DAY kernel test infrastructure Open Source
> Technology Center
> https://lists.01.org/pipermail/kbuild-all Intel
> Corporation

Attachment: signature.asc
Description: This is a digitally signed message part