From: Simon Horman <horms@kernel.org>
To: Ivan Vecera <ivecera@redhat.com>
Cc: intel-wired-lan@lists.osuosl.org,
Jesse Brandeburg <jesse.brandeburg@intel.com>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org,
Jacob Keller <jacob.e.keller@intel.com>,
Wojciech Drewek <wojciech.drewek@intel.com>,
mschmidt@redhat.com, netdev@vger.kernel.org
Subject: Re: [PATCH iwl-next v3 3/5] i40e: Add helpers to find VSI and VEB by SEID and use them
Date: Tue, 21 Nov 2023 19:45:04 +0000 [thread overview]
Message-ID: <20231121194504.GB16629@kernel.org> (raw)
In-Reply-To: <26b17c32-c9ad-4b4c-8193-3a9757e587db@redhat.com>
On Mon, Nov 20, 2023 at 06:55:42PM +0100, Ivan Vecera wrote:
>
> On 20. 11. 23 12:42, Simon Horman wrote:
> > On Thu, Nov 16, 2023 at 04:21:12PM +0100, Ivan Vecera wrote:
> > > Add two helpers i40e_(veb|vsi)_get_by_seid() to find corresponding
> > > VEB or VSI by their SEID value and use these helpers to replace
> > > existing open-coded loops.
> > >
> > > Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>
> > > Signed-off-by: Ivan Vecera <ivecera@redhat.com>
> >
> > Hi Ivan,
> >
> > some minor feedback from my side.
> >
> > ...
> >
> > > diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h
> > > index 1e9266de270b..ca8997d29c02 100644
> > > --- a/drivers/net/ethernet/intel/i40e/i40e.h
> > > +++ b/drivers/net/ethernet/intel/i40e/i40e.h
> > > @@ -1360,4 +1360,38 @@ static inline struct i40e_pf *i40e_hw_to_pf(struct i40e_hw *hw)
> > > struct device *i40e_hw_to_dev(struct i40e_hw *hw);
> > > +/**
> > > + * i40e_pf_get_vsi_by_seid - find VSI by SEID
> > > + * @pf: pointer to a PF
> >
> > nit: @seid is missing here
> >
> > > + **/
> > > +static inline struct i40e_vsi *
> > > +i40e_pf_get_vsi_by_seid(struct i40e_pf *pf, u16 seid)
> > > +{
> > > + struct i40e_vsi *vsi;
> > > + int i;
> > > +
> > > + i40e_pf_for_each_vsi(pf, i, vsi)
> > > + if (vsi->seid == seid)
> > > + return vsi;
> > > +
> > > + return NULL;
> > > +}
> > > +
> > > +/**
> > > + * i40e_pf_get_veb_by_seid - find VEB by SEID
> > > + * @pf: pointer to a PF
> >
> > Ditto
> >
> > ...
> >
> > > diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
> >
> > ...
> >
> > > @@ -14848,23 +14831,16 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
> > > }
> > > /* make sure there is such a vsi and uplink */
> > > - i40e_pf_for_each_vsi(pf, vsi_idx, vsi)
> > > - if (vsi->seid == vsi_seid)
> > > - break;
> > > -
> > > - if (vsi_idx == pf->num_alloc_vsi && vsi_seid != 0) {
> > > - dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
> > > - vsi_seid);
> > > - return NULL;
> > > + if (vsi_seid) {
> > > + vsi = i40e_pf_get_vsi_by_seid(pf, vsi_seid);
> > > + if (!vsi) {
> > > + dev_err(&pf->pdev->dev, "vsi seid %d not found\n",
> > > + vsi_seid);
> > > + return NULL;
> > > + }
> > > }
> > > -
> > > if (uplink_seid && uplink_seid != pf->mac_seid) {
> > > - i40e_pf_for_each_veb(pf, veb_idx, veb) {
> > > - if (veb->seid == uplink_seid) {
> > > - uplink_veb = veb;
> > > - break;
> > > - }
> > > - }
> > > + uplink_veb = i40e_pf_get_veb_by_seid(pf, uplink_seid);
> > > if (!uplink_veb) {
> > > dev_info(&pf->pdev->dev,
> > > "uplink seid %d not found\n", uplink_seid);
> >
> > The next part of this function looks like this:
> >
> > if (!uplink_veb) {
> > dev_info(&pf->pdev->dev,
> > "uplink seid %d not found\n", uplink_seid);
> > return NULL;
> > }
> > }
> > /* get veb sw struct */
> > veb_idx = i40e_veb_mem_alloc(pf);
> > if (veb_idx < 0)
> > goto err_alloc;
> > veb = pf->veb[veb_idx];
> > veb->flags = flags;
> > veb->uplink_seid = uplink_seid;
> > veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
> > veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
> >
> > /* create the VEB in the switch */
> > ret = i40e_add_veb(veb, vsi);
> >
> > Smatch complains that vsi may be used uninitialised here.
> > Which does seem possible to me if vsi_seid is 0.
>
> Yes, the support for floating VEBs is and WAS broken prior this patch and it
> is fixed by the following patch.
>
> Prior this patch... Let's vsi_seid == 0:
>
> /* make sure there is such a vsi and uplink */
> i40e_pf_for_each_vsi(pf, vsi_idx, vsi)
> if (vsi->seid == vsi_seid)
> break;
> -> here vsi_idx == pf->num_alloc_vsi because there cannot be VSI with SEID
> == 0... and VSI points after the pf->vsi[] array.
>
> if (vsi_idx == pf->num_alloc_vsi && vsi_seid != 0) {
> dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
> vsi_seid);
> return NULL;
> }
>
> This condition is not met, although vsi_idx == pf->num_alloc_vsi but
> vsi_seid == 0 so the rest of code ended by:
>
> ret = i40e_add_veb(veb, vsi);
>
> and vsi pointer points to invalid area (item after the last one from
> pf->vsi).
>
> As I mentioned the broken floating VEB functionality (where vsi_seid == 0
> and uplink_seid == 0) is fixed by the following patch.
Thanks Ivan,
I see that I flagged a false positive, sorry about that.
I understand things quite a bit better after reading your explanation
above.
next prev parent reply other threads:[~2023-11-21 19:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-16 15:21 [PATCH iwl-next v3 0/5] i40e: Simplify VSI and VEB handling Ivan Vecera
2023-11-16 15:21 ` [PATCH iwl-next v3 1/5] i40e: Use existing helper to find flow director VSI Ivan Vecera
2023-11-16 15:21 ` [PATCH iwl-next v3 2/5] i40e: Introduce and use macros for iterating VSIs and VEBs Ivan Vecera
2023-11-16 15:21 ` [PATCH iwl-next v3 3/5] i40e: Add helpers to find VSI and VEB by SEID and use them Ivan Vecera
2023-11-20 11:42 ` Simon Horman
2023-11-20 17:55 ` Ivan Vecera
2023-11-21 19:45 ` Simon Horman [this message]
2023-11-21 23:05 ` Tony Nguyen
2023-11-22 9:58 ` Ivan Vecera
2023-11-16 15:21 ` [PATCH iwl-next v3 4/5] i40e: Fix broken support for floating VEBs Ivan Vecera
2023-11-16 15:21 ` [PATCH iwl-next v3 5/5] i40e: Remove VEB recursion Ivan Vecera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231121194504.GB16629@kernel.org \
--to=horms@kernel.org \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=ivecera@redhat.com \
--cc=jacob.e.keller@intel.com \
--cc=jesse.brandeburg@intel.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mschmidt@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=wojciech.drewek@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox