From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 519B2455AD for ; Mon, 15 Jul 2024 17:28:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4993F40A71; Mon, 15 Jul 2024 17:28:39 +0200 (CEST) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by mails.dpdk.org (Postfix) with ESMTP id B697E402DD for ; Mon, 15 Jul 2024 17:28:37 +0200 (CEST) Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-52e9f788e7bso5246112e87.0 for ; Mon, 15 Jul 2024 08:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721057317; x=1721662117; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SK5ABGw9LmmGxuirJ6K5QSNc0e8SJCXe551/ARIDPyA=; b=X6KoV2iXn/MW79ZFWgiHM2Edr3uFep7327Y83YM04YabkWTciZ9Ogoeoo0+vwzvxVs mBJf8crv7oPSTuLRHI3HMQjVefGNpxAKp3yOqv8SIG57B8j7E5qKYHmacV7vNZjYvNA1 WksZRxd0+8V/Wh9V/rce3l0tHkInCgOn0lEXWObzn1AGIjomVXiEQdYPoUHj3O5P62EF lRK7yWdhOu6zwOCCtJk2OENHmN47YTzPaRrWtzvxGKpPAUlGSPeoW4VV3D57G336IwBV 1+FSDJsT3AhC7bkVvuV8FMCxTWPIq4CccaBB0462lna8UWvG6cyVmeM13DWEW3Hc3HHE ylFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721057317; x=1721662117; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SK5ABGw9LmmGxuirJ6K5QSNc0e8SJCXe551/ARIDPyA=; b=lKJtz9ZmPd2iRSGYUbpA4y8Rd3qGGCYXZaY4fW0sWxWwl/i/nuJzO2OaQ/g8GrAgR3 xpMhGe1tUu+vty9GkXsmp9rrBPmosRaib0AUUBgOE9k+U9CYlfn+GvKapbDruwUViuqE f2akLKvkTYi+Va56i5C1QD0HkhlNczyuiYzauLZ5XxS5qz0ICE6+XdtwMqvOLGCGhU0p BiusvZMYY7NMA1yDDuzpcmBmSmP493qCRD/SPjo/61lMba1Oh+SzznDBjpl8QkyaU+3g rCkeqnZEIvl6S6v7JnA5vxXtBsKejuAD0i11e9V1VslVJZZc14ksfH7MjOi/9GEhybgH 1xPw== X-Forwarded-Encrypted: i=1; AJvYcCUe7aCyhyG0iL3bqm4XjsKpYHmzgrAK/AKYraR1cEOec/f+hjakvTvYkvKMI0Lt9bP/S2RlnrBwlsbPXkZhU60= X-Gm-Message-State: AOJu0YxGp/zp4l1YJKXDtt1dU7/ulY86IhM8rH6gmn0Ap2CwaGX+mPUh 8lG99rvt5xYHN0C3CNm8XoCac5nVypGaMoQdI2Nyr/QmVJ1lse0eL1nEPtMo X-Google-Smtp-Source: AGHT+IGDr/t5QKOvE3sXtkGx7DmbQuZ3ialvQOiuk8D4dpKsO9HjgqzajVKcg7/vEc/4FNf5yDbuUA== X-Received: by 2002:a05:6512:3a88:b0:52e:9df2:7de0 with SMTP id 2adb3069b0e04-52eb999a844mr13670330e87.40.1721057317096; Mon, 15 Jul 2024 08:28:37 -0700 (PDT) Received: from localhost ([2a01:4b00:d036:ae00:7aef:1aaa:3dff:d546]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427a5e83273sm91592365e9.17.2024.07.15.08.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 08:28:36 -0700 (PDT) From: luca.boccassi@gmail.com To: Anatoly Burakov Cc: Vipin Padmam Ramesh , dpdk stable Subject: patch 'fbarray: fix lookbehind ignore mask handling' has been queued to stable release 22.11.6 Date: Mon, 15 Jul 2024 16:26:08 +0100 Message-Id: <20240715152704.2229503-30-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240715152704.2229503-1-luca.boccassi@gmail.com> References: <20240624235907.885628-81-luca.boccassi@gmail.com> <20240715152704.2229503-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 22.11.6 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 07/17/24. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/58dd24b4666b3254b8acce9b7ae113d69c38d3a0 Thanks. Luca Boccassi --- >From 58dd24b4666b3254b8acce9b7ae113d69c38d3a0 Mon Sep 17 00:00:00 2001 From: Anatoly Burakov Date: Mon, 8 Jul 2024 17:07:35 +0100 Subject: [PATCH] fbarray: fix lookbehind ignore mask handling [ upstream commit 0c6e2781578f37d0497c225acf68ce5ffe31bd8e ] When lookahead mask does not have its last bit set, we can infer that we've lost our run. However, currently, we set ignore mask to ignore first `need` bits, which is incorrect for two reasons: first, using `need` bits as ignore bit count means we might miss opportunities to start a new run within those bits, and more importantly when doing lookbehind, we start looking from the top, so we should be ignoring *last* N bits, not *first* N bits of the mask. This issue is fixed by counting how many shifts it took to lose the run, and this is the number of bits we should ignore from the top (+1 to skip one we stopped on). Also, add unit tests to reproduce the problem. Fixes: e1ca5dc86226 ("fbarray: add reverse finding of chunk") Signed-off-by: Vipin Padmam Ramesh Signed-off-by: Anatoly Burakov --- app/test/test_fbarray.c | 27 +++++++++++++++++++++++++++ lib/eal/common/eal_common_fbarray.c | 9 +++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/test/test_fbarray.c b/app/test/test_fbarray.c index 38a62cd456..3be9e19e78 100644 --- a/app/test/test_fbarray.c +++ b/app/test/test_fbarray.c @@ -781,6 +781,32 @@ static int test_lookahead_mask(void) return TEST_SUCCESS; } +static int test_lookbehind_mask(void) +{ + /* + * There is a certain type of lookbehind behavior we want to test here, + * namely masking of bits that were scanned with lookbehind but that we + * know do not match our criteria. This is achieved in two steps: + * + * 0. Look for a big enough chunk of free space (say, 62 elements) + * 1. Trigger lookbehind by breaking a run somewhere inside mask 2 + * (indices 128-191) + * 2. Fail lookbehind by breaking the run somewhere inside mask 1 + * (indices 64-127) + * 3. Ensure that we can still find free space in mask 1 afterwards + */ + + /* break run on mask 2 */ + rte_fbarray_set_used(¶m.arr, 130); + /* break run on mask 1 */ + rte_fbarray_set_used(¶m.arr, 70); + + /* start from 190, we expect to find free space at 8 */ + TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(¶m.arr, 190, 62), + 8, "Free chunk index is wrong\n"); + return TEST_SUCCESS; +} + static struct unit_test_suite fbarray_test_suite = { .suite_name = "fbarray autotest", .setup = autotest_setup, @@ -798,6 +824,7 @@ static struct unit_test_suite fbarray_test_suite = { TEST_CASE_ST(lookbehind_test_setup, reset_array, test_lookbehind), /* setup for these tests is more complex so do it in test func */ TEST_CASE_ST(NULL, reset_array, test_lookahead_mask), + TEST_CASE_ST(NULL, reset_array, test_lookbehind_mask), TEST_CASES_END() } }; diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c index 1909615187..34f51d8530 100644 --- a/lib/eal/common/eal_common_fbarray.c +++ b/lib/eal/common/eal_common_fbarray.c @@ -508,8 +508,13 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, /* figure out how many consecutive bits we need here */ need = RTE_MIN(left, MASK_ALIGN); - for (s_idx = 0; s_idx < need - 1; s_idx++) + /* count number of shifts we performed */ + for (s_idx = 0; s_idx < need - 1; s_idx++) { lookbehind_msk &= lookbehind_msk << 1ULL; + /* did we lose the run yet? */ + if ((lookbehind_msk & last_bit) == 0) + break; + } /* if last bit is not set, we've lost the run */ if ((lookbehind_msk & last_bit) == 0) { @@ -518,7 +523,7 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, * no runs in the space we've lookbehind-scanned * as well, so skip that on next iteration. */ - ignore_msk = UINT64_MAX << need; + ignore_msk = ~(UINT64_MAX << (MASK_ALIGN - s_idx - 1)); /* outer loop will decrement msk_idx so add 1 */ msk_idx = lookbehind_idx + 1; break; -- 2.39.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-07-15 16:19:36.233590416 +0100 +++ 0030-fbarray-fix-lookbehind-ignore-mask-handling.patch 2024-07-15 16:19:34.528205609 +0100 @@ -1 +1 @@ -From 0c6e2781578f37d0497c225acf68ce5ffe31bd8e Mon Sep 17 00:00:00 2001 +From 58dd24b4666b3254b8acce9b7ae113d69c38d3a0 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 0c6e2781578f37d0497c225acf68ce5ffe31bd8e ] + @@ -21 +22,0 @@ -Cc: stable@dpdk.org @@ -31 +32 @@ -index 4b17ef6be3..13c6691e50 100644 +index 38a62cd456..3be9e19e78 100644 @@ -76 +77 @@ -index 195f8394be..63d8b731f5 100644 +index 1909615187..34f51d8530 100644