[PATCH 1/2] Memory Allocation: Fixes ignore_msk during find_next_n() in fb_array library

Burakov, Anatoly anatoly.burakov at intel.com
Fri May 19 18:23:27 CEST 2023


Hi Vipin,

On 1/13/2023 1:14 PM, Vipin P R wrote:
> Ignore mask ignores essential bits WHICH could have been contiguous.
> This commit aims to rectify that

Suggested rewording:

fbarray: fix incorrect lookahead ignore mask

Currently, when lookahead reaches a point where we've lost the run, we 
set ignore mask to ignore N bits we were looking for for lookahead. The 
problem is, because we're only looking at first bit after collapsing 
next N bits into it, we end up ignoring bits that could've potentially 
started a new run not from the first bit.

To reproduce this issue, we need to do the following:

1) Look for N bits where 64 > N > 1 (to enable lookahead behavior)
2) Set last bit of mask M (to trigger lookahead)
3) Leave first bit of mask M+1 unset (to create incorrect ignore mask)
4) Have next N bits of mask M+1 set

For example:

1) Look for 3 bits
2) Set bit 63 (last bit of first mask)
3) Leave bit 64 unset (first bit of second mask)
4) Set bits 65-67

With current code, we will not find a run starting from bit 65, because 
we set ignore mask to ignore first 3 bits of second mask.

Fix this behavior by only setting the ignore mask when we know there 
were no bits in the mask at all, so there's no chance in skipping bits 
that could've been useful to us.

Fixes: c44d09811b40 ("eal: add shared indexed file-backed array")

> 
> Cc: stable at dpdk.org
> 
> Signed-off-by: Vipin P R <vipinp at vmware.com>
> Acked-by: Kumara Parameshwaran <kparameshwar at vmware.com>
> ---
> Depends-on: 0001-Memory-Allocation-Fixes-ms_idx-jump-lookahead-during.patch
> Depends-on: 0002-Memory-Allocation-Fixes-ms_idx-jump-lookbehind-durin.patch
> ---
>   lib/eal/common/eal_common_fbarray.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c
> index 90240e8..313681a 100644
> --- a/lib/eal/common/eal_common_fbarray.c
> +++ b/lib/eal/common/eal_common_fbarray.c
> @@ -235,7 +235,12 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
>   				 * no runs in the space we've lookahead-scanned
>   				 * as well, so skip that on next iteration.
>   				 */
> -				ignore_msk = ~((1ULL << need) - 1);
> +				if (!lookahead_msk) {
> +					/* There aren't "need" number of contiguous bits anywhere in the mask.
> +					 * Ignore these many number of bits from LSB for the next iteration.
> +					 */
> +					ignore_msk = ~((1ULL << need) - 1);
> +				}

Great find! Needs a unit test though. I've described in the commit 
message how to reproduce this behavior, should be trivial to implement 
it as a unit test.

With above changes,

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

-- 
Thanks,
Anatoly



More information about the stable mailing list