intel-wired-lan.osuosl.org archive mirror
 help / color / mirror / Atom feed
From: Gregory Herrero <gregory.herrero@oracle.com>
To: "Loktionov, Aleksandr" <aleksandr.loktionov@intel.com>
Cc: "Nguyen, Anthony L" <anthony.l.nguyen@intel.com>,
	"Kitszel, Przemyslaw" <przemyslaw.kitszel@intel.com>,
	"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"edumazet@google.com" <edumazet@google.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"intel-wired-lan@lists.osuosl.org"
	<intel-wired-lan@lists.osuosl.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [Intel-wired-lan] [PATCH v2 1/1] i40e: validate ring_len parameter against hardware-specific values.
Date: Thu, 13 Nov 2025 09:36:25 +0100	[thread overview]
Message-ID: <aRWYiafAr6qivBHm@oracle> (raw)
In-Reply-To: <IA3PR11MB8986755762618F3EE7AF309EE5CDA@IA3PR11MB8986.namprd11.prod.outlook.com>

On Thu, Nov 13, 2025 at 08:18:30AM +0000, Loktionov, Aleksandr wrote:
> 
> 
> > -----Original Message-----
> > From: gregory.herrero@oracle.com <gregory.herrero@oracle.com>
> > Sent: Thursday, November 13, 2025 9:05 AM
> > To: Loktionov, Aleksandr <aleksandr.loktionov@intel.com>; Nguyen,
> > Anthony L <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> > <przemyslaw.kitszel@intel.com>; andrew+netdev@lunn.ch;
> > davem@davemloft.net; edumazet@google.com; kuba@kernel.org;
> > pabeni@redhat.com
> > Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; linux-
> > kernel@vger.kernel.org; Gregory Herrero <gregory.herrero@oracle.com>
> > Subject: [PATCH v2 1/1] i40e: validate ring_len parameter against
> > hardware-specific values.
> > 
> Please drop the trailing period from the subject.
> 
Ok
> > From: Gregory Herrero <gregory.herrero@oracle.com>
> > 
> > The maximum number of descriptors supported by the hardware is
> > hardware dependent and can be retrieved using
> > i40e_get_max_num_descriptors().
> > Move this function to a shared header and use it when checking for
> > valid ring_len parameter rather than using hardcoded value.
> > Cast info->ring_len to u32 in i40e_config_vsi_tx_queue() as it's u16
> > in struct virtchnl_txq_info.
> > Also cast it in i40e_config_vsi_rx_queue() even if it's u32 in
> > virtchnl_rxq_info to ease stable backport in case this changed.
> > 
> > By fixing an over-acceptance issue, behavior change could be seen
> > where ring_len would now be rejected whereas it was not before.
> > 
> Please add a short “Tested:” explanation (what hw/flows, expected/actual before/after).
> 
No real test was done, it was found only by code inspection.
I could update the description though:
 By fixing an over-acceptance issue, behavior change could be seen where
 ring_len could now be rejected while configuring rx and tx queues if its
 size is larger than the hardware-specific maximum number of descriptors.

> > Fixes: 55d225670def ("i40e: add validation for ring_len param")
> > Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
> > ---
> >  drivers/net/ethernet/intel/i40e/i40e.h          | 17
> > +++++++++++++++++
> >  drivers/net/ethernet/intel/i40e/i40e_ethtool.c  | 12 ------------
> > .../net/ethernet/intel/i40e/i40e_virtchnl_pf.c  |  4 ++--
> >  3 files changed, 19 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/intel/i40e/i40e.h
> > b/drivers/net/ethernet/intel/i40e/i40e.h
> > index 801a57a925da..a953cce008f4 100644
> > --- a/drivers/net/ethernet/intel/i40e/i40e.h
> > +++ b/drivers/net/ethernet/intel/i40e/i40e.h
> > @@ -1418,4 +1418,21 @@ static inline struct i40e_veb
> > *i40e_pf_get_main_veb(struct i40e_pf *pf)
> >  	return (pf->lan_veb != I40E_NO_VEB) ? pf->veb[pf->lan_veb] :
> > NULL;  }
> > 
> > +/**
> > + * i40e_get_max_num_descriptors - get maximum number of descriptors
> > for this hardware.
> > + * @pf: pointer to a PF
> > + *
> > + * Return: u32 value corresponding to the maximum number of
> > descriptors.
> > + **/
> > +static inline u32 i40e_get_max_num_descriptors(const struct i40e_pf
> > +*pf) {
> > +	const struct i40e_hw *hw = &pf->hw;
> > +
> > +	switch (hw->mac.type) {
> > +	case I40E_MAC_XL710:
> > +		return I40E_MAX_NUM_DESCRIPTORS_XL710;
> > +	default:
> > +		return I40E_MAX_NUM_DESCRIPTORS;
> > +	}
> > +}
> >  #endif /* _I40E_H_ */
> > diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> > b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> > index 86c72596617a..61c39e881b00 100644
> > --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> > +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> > @@ -2013,18 +2013,6 @@ static void i40e_get_drvinfo(struct net_device
> > *netdev,
> >  		drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;  }
> > 
> > -static u32 i40e_get_max_num_descriptors(struct i40e_pf *pf) -{
> > -	struct i40e_hw *hw = &pf->hw;
> > -
> > -	switch (hw->mac.type) {
> > -	case I40E_MAC_XL710:
> > -		return I40E_MAX_NUM_DESCRIPTORS_XL710;
> > -	default:
> > -		return I40E_MAX_NUM_DESCRIPTORS;
> > -	}
> > -}
> > -
> >  static void i40e_get_ringparam(struct net_device *netdev,
> >  			       struct ethtool_ringparam *ring,
> >  			       struct kernel_ethtool_ringparam
> > *kernel_ring, diff --git
> > a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
> > b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
> > index 081a4526a2f0..5e058159057b 100644
> > --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
> > +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
> > @@ -656,7 +656,7 @@ static int i40e_config_vsi_tx_queue(struct i40e_vf
> > *vf, u16 vsi_id,
> > 
> >  	/* ring_len has to be multiple of 8 */
> >  	if (!IS_ALIGNED(info->ring_len, 8) ||
> > -	    info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) {
> > +	    (u32)info->ring_len > i40e_get_max_num_descriptors(pf)) {
> >  		ret = -EINVAL;
> >  		goto error_context;
> >  	}
> > @@ -726,7 +726,7 @@ static int i40e_config_vsi_rx_queue(struct i40e_vf
> > *vf, u16 vsi_id,
> > 
> >  	/* ring_len has to be multiple of 32 */
> >  	if (!IS_ALIGNED(info->ring_len, 32) ||
> > -	    info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) {
> > +	    (u32)info->ring_len > i40e_get_max_num_descriptors(pf)) {
> virtchnl_rxq_info.ring_len is already u32 (as noted in the commit message).
> Casting it to u32 before comparison is redundant and adds churn without value in mainline.
> The (u32) cast on info->ring_len can be dropped in mainline; if you need it only for a stable backport, consider keeping the mainline patch minimal and adding the backport‑only hunk when submitting to stable.
> 
I've dropped this cast and removed the comment about it from the commit
description.

Thanks for the review,
Greg

      reply	other threads:[~2025-11-13  8:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13  8:04 [Intel-wired-lan] [PATCH v2 0/1] i40e: additional safety check gregory.herrero
2025-11-13  8:04 ` [Intel-wired-lan] [PATCH v2 1/1] i40e: validate ring_len parameter against hardware-specific values gregory.herrero
2025-11-13  8:18   ` Loktionov, Aleksandr
2025-11-13  8:36     ` Gregory Herrero [this message]

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=aRWYiafAr6qivBHm@oracle \
    --to=gregory.herrero@oracle.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@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;
as well as URLs for NNTP newsgroup(s).