i40e: additional safety check
Subsystems (3)
v2 cover i40e: additional safety check
From: Gregory Herrero <[email protected]>
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().
v2:
- make i40e_get_max_num_descriptors() 'pf' argument const.
- reword i40e_get_max_num_descriptors() description.
- modify commit description to explain potential behavior change.
Gregory Herrero (1):
i40e: validate ring_len parameter against hardware-specific values.
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(-)
Signature · 1 line
2.51.0
PATCH v2 1/1 i40e: validate ring_len parameter against hardware-specific values.
From: Gregory Herrero <[email protected]>
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.
--- 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(-)
drivers/net/ethernet/intel/i40e/i40e.h +17 -0
@@ -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_ */
drivers/net/ethernet/intel/i40e/i40e_ethtool.c +0 -12
@@ -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,
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -2
@@ -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; }
Signature · 1 line
2.51.0
RE: [PATCH v2 1/1] i40e: validate ring_len parameter against hardware-specific values.
Quoted 15 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, November 13, 2025 9:05 AM
To: Loktionov, Aleksandr <[email protected]>; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Gregory Herrero <[email protected]>
Subject: [PATCH v2 1/1] i40e: validatering_lenparameter against hardware-specific values.
Please drop the trailing period from the subject.
Quoted 12 lines
From: Gregory Herrero <[email protected]>
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 validring_lenparameter rather than using hardcoded value. Castinfo->ring_lento u32 ini40e_config_vsi_tx_queue()as it's u16 in structvirtchnl_txq_info.
Also cast it ini40e_config_vsi_rx_queue()even if it's u32 invirtchnl_rxq_infoto ease stable backport in case this changed.
Quoted 3 lines
By fixing an over-acceptance issue, behavior change could be seen where
ring_lenwould now be rejected whereas it was not before.
Please add a short “Tested:” explanation (what hw/flows, expected/actual before/after).
Quoted 79 lines
Fixes 55d225670def ("i40e: add validation for ring_len param")Signed-off-by Gregory Herrero <[email protected]>--- 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(-)drivers/net/ethernet/intel/i40e/i40e.h +2
-0@@ -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.
+ **/drivers/net/ethernet/intel/i40e/i40e.h +11
-0+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_ */ drivers/net/ethernet/intel/i40e/i40e_ethtool.c +0
-11@@ -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 --gita/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.cb/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.cindex081a4526a2f0..5e058159057b100644drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +1
-1@@ -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;drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0
-0}
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c static int i40e_config_vsi_rx_queue(struct i40e_vf · line 730
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +1
-1@@ -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.
With the best regards,
Alex
Quoted 5 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0
-0ret = -EINVAL ; goto error_param;}
--
2.51.0
Re: [PATCH v2 1/1] i40e: validate ring_len parameter against hardware-specific values.
Quoted 15 lines · Aleksandr
Quoted 15 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, November 13, 2025 9:05 AM
To: Loktionov, Aleksandr <[email protected]>; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Gregory Herrero <[email protected]>
Subject: [PATCH v2 1/1] i40e: validatering_lenparameter against hardware-specific values.
Quoted 2 lines
Please drop the trailing period from the subject.
Ok
Quoted 12 lines
Quoted 12 lines
From: Gregory Herrero <[email protected]>
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 validring_lenparameter rather than using hardcoded value. Castinfo->ring_lento u32 ini40e_config_vsi_tx_queue()as it's u16 in structvirtchnl_txq_info.
Also cast it ini40e_config_vsi_rx_queue()even if it's u32 invirtchnl_rxq_infoto ease stable backport in case this changed.
Quoted 5 lines
Quoted 3 lines
By fixing an over-acceptance issue, behavior change could be seen where
ring_lenwould 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.
Quoted 81 lines
Quoted 81 lines
Fixes 55d225670def ("i40e: add validation for ring_len param")Signed-off-by Gregory Herrero <[email protected]>--- 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(-)drivers/net/ethernet/intel/i40e/i40e.h +2
-0@@ -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.
+ **/drivers/net/ethernet/intel/i40e/i40e.h +11
-0+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_ */ drivers/net/ethernet/intel/i40e/i40e_ethtool.c +0
-11@@ -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 --gita/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.cb/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.cindex081a4526a2f0..5e058159057b100644drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +1
-1@@ -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;drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0
-0}@@ -726,7 +726,7 @@ static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
Quoted 8 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id, · line 729
Quoted 4 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +1
-1/* 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 oninfo->ring_lencan 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