On 9/30/2024 2:40 PM, Niall Meade wrote: > Addressed a specific overflow issue in the eth_dev_adjust_nb_desc() > function where the uint16_t variable nb_desc would overflow when its > value was greater than (2^16 - nb_align). This overflow caused nb_desc > to incorrectly wrap around between 0 and nb_align-1, leading to the > function setting nb_desc to nb_min instead of the expected nb_max. > > To give an example, let nb_desc=UINT16_MAX, nb_align=32, nb_max=4096 and > nb_min=64. RTE_ALIGN_CEIL(nb_desc, nb_align) calls > RTE_ALIGN_FLOOR(nb_desc + nb_align - 1, nb_align). This results in an > overflow of nb_desc, leading to nb_desc being set to 30 and then 0 when > the macros return. As a result of this, nb_desc is then set to nb_min > later on. > > The resolution involves upcasting nb_desc to a uint32_t before the > RTE_ALIGN_CEIL macro is applied. This change ensures that the subsequent > call to RTE_ALIGN_FLOOR(nb_desc + (nb_align - 1), nb_align) does not > result in an overflow, as it would when nb_desc is a uint16_t. By using > a uint32_t for these operations, the correct behavior is maintained > without the risk of overflow. > > Fixes: 0f67fc3baeb9 ("ethdev: add function to adjust number of descriptors") > > Signed-off-by: Niall Meade <niall.me...@intel.com> >
Reviewed-by: Ferruh Yigit <ferruh.yi...@amd.com> Applied to dpdk-next-net/main, thanks.