[2/2] Memory Allocation: Fixes ms_idx jump (lookbehind) during find_prev_n() in fb_array library

Message ID 1673615325-20624-3-git-send-email-vipinp@vmware.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series *** Memory Allocation: Fixes ms_idx jump in fb_array library *** |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Performance fail Performance Testing issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Vipin P R Jan. 13, 2023, 1:08 p.m. UTC
  Cc: stable@dpdk.org

Signed-off-by: Vipin P R <vipinp@vmware.com>
Acked-by: Kumara Parameshwaran <kparameshwar@vmware.com>
---
 lib/eal/common/eal_common_fbarray.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Burakov, Anatoly May 16, 2023, 2:20 p.m. UTC | #1
Hi Vipin,

This commit should include a more detailed commit message, akin to one I 
suggested for the first patch.

For the patch itself:

Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com>


On 1/13/2023 1:08 PM, Vipin P R wrote:
> Cc: stable@dpdk.org
> 
> Signed-off-by: Vipin P R <vipinp@vmware.com>
> Acked-by: Kumara Parameshwaran <kparameshwar@vmware.com>
> ---
>   lib/eal/common/eal_common_fbarray.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c
> index 551bd87..90240e8 100644
> --- a/lib/eal/common/eal_common_fbarray.c
> +++ b/lib/eal/common/eal_common_fbarray.c
> @@ -511,7 +511,7 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
>   				 * as well, so skip that on next iteration.
>   				 */
>   				ignore_msk = UINT64_MAX << need;
> -				msk_idx = lookbehind_idx;
> +				msk_idx = lookbehind_idx + 1;
>   				break;
>   			}
>   

The unit test code you suggested does not cover this case. I've reduced 
this bug to a minimal test case:

1. Allocate fbarray with 256 entries
2. Set idx 63 as used
3. Call rte_fbarray_find_prev_n_free() starting with index 64 and length 
of 2

Returned value should be 61, but without the fix it returns -1.
  

Patch

diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c
index 551bd87..90240e8 100644
--- a/lib/eal/common/eal_common_fbarray.c
+++ b/lib/eal/common/eal_common_fbarray.c
@@ -511,7 +511,7 @@  find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
 				 * as well, so skip that on next iteration.
 				 */
 				ignore_msk = UINT64_MAX << need;
-				msk_idx = lookbehind_idx;
+				msk_idx = lookbehind_idx + 1;
 				break;
 			}