diff mbox series

[iwl-net,v1] ice: fix receive buffer size miscalculation

Message ID 20230810002313.421684-1-jesse.brandeburg@intel.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [iwl-net,v1] ice: fix receive buffer size miscalculation | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1328 this patch: 1328
netdev/cc_maintainers warning 5 maintainers not CCed: kuba@kernel.org davem@davemloft.net anthony.l.nguyen@intel.com pabeni@redhat.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 1351 this patch: 1351
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1351 this patch: 1351
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jesse Brandeburg Aug. 10, 2023, 12:23 a.m. UTC
The driver is misconfiguring the hardware for some values of MTU such that
it could use multiple descriptors to receive a packet when it could have
simply used one.

Change the driver to use a round-up instead of the result of a shift, as
the shift can truncate the lower bits of the size, and result in the
problem noted above. It also aligns this driver with similar code in i40e.

The insidiousness of this problem is that everything works with the wrong
size, it's just not working as well as it could, as some MTU sizes end up
using two or more descriptors, and there is no way to tell that is
happening without looking at ice_trace or a bus analyzer.

Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 drivers/net/ethernet/intel/ice/ice_base.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Przemek Kitszel Aug. 10, 2023, 11:02 a.m. UTC | #1
On 8/10/23 02:23, Jesse Brandeburg wrote:
> The driver is misconfiguring the hardware for some values of MTU such that
> it could use multiple descriptors to receive a packet when it could have
> simply used one.
> 
> Change the driver to use a round-up instead of the result of a shift, as
> the shift can truncate the lower bits of the size, and result in the
> problem noted above. It also aligns this driver with similar code in i40e.
> 
> The insidiousness of this problem is that everything works with the wrong
> size, it's just not working as well as it could, as some MTU sizes end up
> using two or more descriptors, and there is no way to tell that is
> happening without looking at ice_trace or a bus analyzer.
> 
> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>

Nice catch!

> ---
>   drivers/net/ethernet/intel/ice/ice_base.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_base.c b/drivers/net/ethernet/intel/ice/ice_base.c
> index b678bdf96f3a..074bf9403cd1 100644
> --- a/drivers/net/ethernet/intel/ice/ice_base.c
> +++ b/drivers/net/ethernet/intel/ice/ice_base.c
> @@ -435,7 +435,8 @@ static int ice_setup_rx_ctx(struct ice_rx_ring *ring)
>   	/* Receive Packet Data Buffer Size.
>   	 * The Packet Data Buffer Size is defined in 128 byte units.
>   	 */
> -	rlan_ctx.dbuf = ring->rx_buf_len >> ICE_RLAN_CTX_DBUF_S;
> +	rlan_ctx.dbuf = DIV_ROUND_UP(ring->rx_buf_len,
> +				     BIT_ULL(ICE_RLAN_CTX_DBUF_S));

looks like %ICE_RLAN_CTX_DBUF_S is only used once in whole codebase, here.

Perhaps you could rename it
(even considering that it is targeted for -net),
and have it as ICE_RLAN_CTX_DBUF_DIV or similar?

Then it will be BIT(7) or just 128. Also, I would keep it as 32bit value.

>   
>   	/* use 32 byte descriptors */
>   	rlan_ctx.dsize = 1;

(BTW: you have missed my review on e1000 ML)
anyway, it's good
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Tony Nguyen Aug. 10, 2023, 9:33 p.m. UTC | #2
On 8/9/2023 5:23 PM, Jesse Brandeburg wrote:
> The driver is misconfiguring the hardware for some values of MTU such that
> it could use multiple descriptors to receive a packet when it could have
> simply used one.
> 
> Change the driver to use a round-up instead of the result of a shift, as
> the shift can truncate the lower bits of the size, and result in the
> problem noted above. It also aligns this driver with similar code in i40e.
> 
> The insidiousness of this problem is that everything works with the wrong
> size, it's just not working as well as it could, as some MTU sizes end up
> using two or more descriptors, and there is no way to tell that is
> happening without looking at ice_trace or a bus analyzer.

This should have a Fixes: ?

> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
> ---
>   drivers/net/ethernet/intel/ice/ice_base.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_base.c b/drivers/net/ethernet/intel/ice/ice_base.c
> index b678bdf96f3a..074bf9403cd1 100644
> --- a/drivers/net/ethernet/intel/ice/ice_base.c
> +++ b/drivers/net/ethernet/intel/ice/ice_base.c
> @@ -435,7 +435,8 @@ static int ice_setup_rx_ctx(struct ice_rx_ring *ring)
>   	/* Receive Packet Data Buffer Size.
>   	 * The Packet Data Buffer Size is defined in 128 byte units.
>   	 */
> -	rlan_ctx.dbuf = ring->rx_buf_len >> ICE_RLAN_CTX_DBUF_S;
> +	rlan_ctx.dbuf = DIV_ROUND_UP(ring->rx_buf_len,
> +				     BIT_ULL(ICE_RLAN_CTX_DBUF_S));
>   
>   	/* use 32 byte descriptors */
>   	rlan_ctx.dsize = 1;
Jesse Brandeburg Aug. 10, 2023, 11:44 p.m. UTC | #3
On 8/10/2023 2:33 PM, Tony Nguyen wrote:
> 
> 
> On 8/9/2023 5:23 PM, Jesse Brandeburg wrote:
>> The driver is misconfiguring the hardware for some values of MTU such
>> that
>> it could use multiple descriptors to receive a packet when it could have
>> simply used one.
>>
>> Change the driver to use a round-up instead of the result of a shift, as
>> the shift can truncate the lower bits of the size, and result in the
>> problem noted above. It also aligns this driver with similar code in
>> i40e.
>>
>> The insidiousness of this problem is that everything works with the wrong
>> size, it's just not working as well as it could, as some MTU sizes end up
>> using two or more descriptors, and there is no way to tell that is
>> happening without looking at ice_trace or a bus analyzer.
> 
> This should have a Fixes: ?

Dang, you're correct. I'll send a v2.

Thanks,
Jesse
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/ice_base.c b/drivers/net/ethernet/intel/ice/ice_base.c
index b678bdf96f3a..074bf9403cd1 100644
--- a/drivers/net/ethernet/intel/ice/ice_base.c
+++ b/drivers/net/ethernet/intel/ice/ice_base.c
@@ -435,7 +435,8 @@  static int ice_setup_rx_ctx(struct ice_rx_ring *ring)
 	/* Receive Packet Data Buffer Size.
 	 * The Packet Data Buffer Size is defined in 128 byte units.
 	 */
-	rlan_ctx.dbuf = ring->rx_buf_len >> ICE_RLAN_CTX_DBUF_S;
+	rlan_ctx.dbuf = DIV_ROUND_UP(ring->rx_buf_len,
+				     BIT_ULL(ICE_RLAN_CTX_DBUF_S));
 
 	/* use 32 byte descriptors */
 	rlan_ctx.dsize = 1;