linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] i40e: additional safety check
@ 2025-11-06 15:02 gregory.herrero
  2025-11-06 15:02 ` [PATCH] i40e: validate ring_len parameter against hardware specific values gregory.herrero
  0 siblings, 1 reply; 4+ messages in thread
From: gregory.herrero @ 2025-11-06 15:02 UTC (permalink / raw)
  To: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
	edumazet, kuba, pabeni
  Cc: intel-wired-lan, netdev, linux-kernel, Gregory Herrero

From: Gregory Herrero <gregory.herrero@oracle.com>

On code inspection, I realized we may want to check ring_len parameter
against hardware specific values in i40e_config_vsi_tx_queue() and
i40e_config_vsi_rx_queue().

Gregory Herrero (1):
  i40e: validate ring_len parameter against hardware specific values.

 drivers/net/ethernet/intel/i40e/i40e.h         | 18 ++++++++++++++++++
 drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 12 ------------
 .../net/ethernet/intel/i40e/i40e_virtchnl_pf.c |  4 ++--
 3 files changed, 20 insertions(+), 14 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] i40e: validate ring_len parameter against hardware specific values.
  2025-11-06 15:02 [PATCH 0/1] i40e: additional safety check gregory.herrero
@ 2025-11-06 15:02 ` gregory.herrero
  2025-11-07  6:39   ` [Intel-wired-lan] " Loktionov, Aleksandr
  0 siblings, 1 reply; 4+ messages in thread
From: gregory.herrero @ 2025-11-06 15:02 UTC (permalink / raw)
  To: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
	edumazet, kuba, pabeni
  Cc: intel-wired-lan, netdev, linux-kernel, Gregory Herrero

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.

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         | 18 ++++++++++++++++++
 drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 12 ------------
 .../net/ethernet/intel/i40e/i40e_virtchnl_pf.c |  4 ++--
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h
index 801a57a925da..0e697375fcaf 100644
--- a/drivers/net/ethernet/intel/i40e/i40e.h
+++ b/drivers/net/ethernet/intel/i40e/i40e.h
@@ -1418,4 +1418,22 @@ 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 descriptors number for this hardware.
+ * @pf: pointer to a PF
+ *
+ * Return: u32 value corresponding to maximum descriptors number.
+ **/
+static inline 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;
+	}
+}
+
 #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)) {
 		ret = -EINVAL;
 		goto error_param;
 	}
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [Intel-wired-lan] [PATCH] i40e: validate ring_len parameter against hardware specific values.
  2025-11-06 15:02 ` [PATCH] i40e: validate ring_len parameter against hardware specific values gregory.herrero
@ 2025-11-07  6:39   ` Loktionov, Aleksandr
  2025-11-07 10:18     ` Gregory Herrero
  0 siblings, 1 reply; 4+ messages in thread
From: Loktionov, Aleksandr @ 2025-11-07  6:39 UTC (permalink / raw)
  To: gregory.herrero@oracle.com, Nguyen, Anthony L,
	Kitszel, Przemyslaw, 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



> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf
> Of gregory.herrero@oracle.com
> Sent: Thursday, November 6, 2025 4:03 PM
> To: 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: [Intel-wired-lan] [PATCH] i40e: validate ring_len parameter
> against hardware specific values.
“hardware specific” → “hardware‑specific”

>
> 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.
> 
> 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         | 18
> ++++++++++++++++++
>  drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 12 ------------
> .../net/ethernet/intel/i40e/i40e_virtchnl_pf.c |  4 ++--
>  3 files changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/i40e/i40e.h
> b/drivers/net/ethernet/intel/i40e/i40e.h
> index 801a57a925da..0e697375fcaf 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e.h
> +++ b/drivers/net/ethernet/intel/i40e/i40e.h
> @@ -1418,4 +1418,22 @@ 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 descriptors number for
> this hardware.
> + * @pf: pointer to a PF
> + *
> + * Return: u32 value corresponding to maximum descriptors number.
> + **/
“maximum descriptors number” → “maximum number of descriptors”
" **/” → “ */


> +static inline u32 i40e_get_max_num_descriptors(struct i40e_pf *pf) {
Nit: kernel coding style
Please follow standard kernel style for function definitions:

 - The opening brace must be on its own line, not after the prototype.
 - static inline is fine here, but keep spacing consistent.
 - Also consider marking the argument const if the function does not modify pf.

So instead of:
static inline u32 i40e_get_max_num_descriptors(struct i40e_pf *pf) {
use:
static inline u32 i40e_get_max_num_descriptors(const struct i40e_pf *pf)
{

See: https://docs.kernel.org/process/coding-style.html section on function definitions.

> +	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)) {
>  		ret = -EINVAL;
>  		goto error_param;
>  	}
> --
> 2.51.0

Behavior change / potential regression:
This switches validation from a hard‑coded XL710 maximum to the per‑MAC maximum.
That will tighten the limit on non‑XL710 controllers and can reject ring_len values that previously passed validation.
Please call this out in the commit message so users understand the change (it fixes an over‑acceptance issue).

Return codes / logging:
-EINVAL is fine for invalid virtchnl parameters; please keep it silent (no dmesg) to avoid log spam from misconfigured VFs.

With the best regards
Alex

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Intel-wired-lan] [PATCH] i40e: validate ring_len parameter against hardware specific values.
  2025-11-07  6:39   ` [Intel-wired-lan] " Loktionov, Aleksandr
@ 2025-11-07 10:18     ` Gregory Herrero
  0 siblings, 0 replies; 4+ messages in thread
From: Gregory Herrero @ 2025-11-07 10:18 UTC (permalink / raw)
  To: Loktionov, Aleksandr
  Cc: Nguyen, Anthony L, Kitszel, Przemyslaw, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, intel-wired-lan@lists.osuosl.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org

On Fri, Nov 07, 2025 at 06:39:16AM +0000, Loktionov, Aleksandr wrote:
> 
> 
> > -----Original Message-----
> > From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf
> > Of gregory.herrero@oracle.com
> > Sent: Thursday, November 6, 2025 4:03 PM
> > To: 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: [Intel-wired-lan] [PATCH] i40e: validate ring_len parameter
> > against hardware specific values.
> “hardware specific” → “hardware‑specific”
> 
I will fix it in v2.
> >
> > 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.
> > 
> > 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         | 18
> > ++++++++++++++++++
> >  drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 12 ------------
> > .../net/ethernet/intel/i40e/i40e_virtchnl_pf.c |  4 ++--
> >  3 files changed, 20 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/intel/i40e/i40e.h
> > b/drivers/net/ethernet/intel/i40e/i40e.h
> > index 801a57a925da..0e697375fcaf 100644
> > --- a/drivers/net/ethernet/intel/i40e/i40e.h
> > +++ b/drivers/net/ethernet/intel/i40e/i40e.h
> > @@ -1418,4 +1418,22 @@ 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 descriptors number for
> > this hardware.
> > + * @pf: pointer to a PF
> > + *
> > + * Return: u32 value corresponding to maximum descriptors number.
> > + **/
> “maximum descriptors number” → “maximum number of descriptors”
I will fix it in v2.

> " **/” → “ */
I followed coding style of the file. If I change from **/ to */, should
I change the whole file in a separate commit? Or should I keep as it is ?
> 
> 
> > +static inline u32 i40e_get_max_num_descriptors(struct i40e_pf *pf) {
> Nit: kernel coding style
> Please follow standard kernel style for function definitions:
> 
>  - The opening brace must be on its own line, not after the prototype.
It should already be the case. I double checked in the patch and on the mailing
list. Am I missing something?
>  - static inline is fine here, but keep spacing consistent.
Ah I missed that, which spacing is not consistent?
>  - Also consider marking the argument const if the function does not modify pf.
> 
> So instead of:
> static inline u32 i40e_get_max_num_descriptors(struct i40e_pf *pf) {
> use:
> static inline u32 i40e_get_max_num_descriptors(const struct i40e_pf *pf)
> {
> 
> See: https://docs.kernel.org/process/coding-style.html  section on function definitions.
Ok, I will fix it in v2.
> 
> > +	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)) {
> >  		ret = -EINVAL;
> >  		goto error_param;
> >  	}
> > --
> > 2.51.0
> 
> Behavior change / potential regression:
> This switches validation from a hard‑coded XL710 maximum to the per‑MAC maximum.
> That will tighten the limit on non‑XL710 controllers and can reject ring_len values that previously passed validation.
> Please call this out in the commit message so users understand the change (it fixes an over‑acceptance issue).
> 
I will add below comment in v2:
  By fixing an over-acceptance issue, behavior change could be seen where
  ring_len would now be rejected whereas it was not before.

> Return codes / logging:
> -EINVAL is fine for invalid virtchnl parameters; please keep it silent (no dmesg) to avoid log spam from misconfigured VFs.
> 
I didn't add any extra log and I don't see any which would be printed
when this error happen. (I checked the callers)
I could be missing something though.

Thanks for the review!
I will wait for your answers before sending v2.

Gregory

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-07 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-06 15:02 [PATCH 0/1] i40e: additional safety check gregory.herrero
2025-11-06 15:02 ` [PATCH] i40e: validate ring_len parameter against hardware specific values gregory.herrero
2025-11-07  6:39   ` [Intel-wired-lan] " Loktionov, Aleksandr
2025-11-07 10:18     ` Gregory Herrero

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).