DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org, Tyler Retzlaff <roretzla@linux.microsoft.com>
Cc: stable@dpdk.org
Subject: [PATCH v1 2/4] fbarray: fix incorrect lookbehind behavior
Date: Mon,  8 Jul 2024 17:07:33 +0100	[thread overview]
Message-ID: <bd7cdc5079a7eb1e3cbc173592a671c6b3f9fd89.1720454625.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <cover.1720454625.git.anatoly.burakov@intel.com>

Currently, whenever first bit of current index mask is set (meaning, there is
potentially a run starting at the start of the mask), lookbehind loop is
entered. In that loop, if the last bit of lookbehind mask is not set, the
lookbehind is stopped, and the current lookbehind mask index is assigned to
current index mask. However, because at that point we are inside a while-loop
that decrements current index mask after each iteration, this results in
erroneous mask index decrement.

Fix lookbehind to avoid erroneous decrement, and add corresponding unit test.

Fixes: e1ca5dc86226 ("fbarray: add reverse finding of chunk")
Cc: stable@dpdk.org

Signed-off-by: Vipin P R <vipinp@vmware.com>
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 app/test/test_fbarray.c             | 24 ++++++++++++++++++++++++
 lib/eal/common/eal_common_fbarray.c |  3 ++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/app/test/test_fbarray.c b/app/test/test_fbarray.c
index bf89b99e5b..147d6e2a07 100644
--- a/app/test/test_fbarray.c
+++ b/app/test/test_fbarray.c
@@ -111,6 +111,14 @@ static int lookahead_test_setup(void)
 	return init_array();
 }
 
+static int lookbehind_test_setup(void)
+{
+	/* set index 63 as used */
+	param.start = 63;
+	param.end = 63;
+	return init_array();
+}
+
 static int test_invalid(void)
 {
 	struct rte_fbarray dummy;
@@ -732,6 +740,21 @@ static int test_lookahead(void)
 	return TEST_SUCCESS;
 }
 
+static int test_lookbehind(void)
+{
+	int ret, free_len = 2;
+
+	/* run regular test first */
+	ret = test_find();
+	if (ret != TEST_SUCCESS)
+		return ret;
+
+	/* test if we can find free chunk while crossing mask boundary */
+	TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(&param.arr, param.start + 1, free_len),
+			param.start - free_len, "Free chunk index is wrong\n");
+	return TEST_SUCCESS;
+}
+
 static struct unit_test_suite fbarray_test_suite = {
 	.suite_name = "fbarray autotest",
 	.setup = autotest_setup,
@@ -746,6 +769,7 @@ static struct unit_test_suite fbarray_test_suite = {
 		TEST_CASE_ST(full_msk_test_setup, reset_array, test_find),
 		TEST_CASE_ST(empty_msk_test_setup, reset_array, test_empty),
 		TEST_CASE_ST(lookahead_test_setup, reset_array, test_lookahead),
+		TEST_CASE_ST(lookbehind_test_setup, reset_array, test_lookbehind),
 		TEST_CASES_END()
 	}
 };
diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c
index 2680b34823..b4f0b0b0c3 100644
--- a/lib/eal/common/eal_common_fbarray.c
+++ b/lib/eal/common/eal_common_fbarray.c
@@ -512,7 +512,8 @@ 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;
+				/* outer loop will decrement msk_idx so add 1 */
+				msk_idx = lookbehind_idx + 1;
 				break;
 			}
 
-- 
2.43.0


  parent reply	other threads:[~2024-07-08 16:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-08 16:07 [PATCH v1 0/4] fbarray lookahead/lookbehind fixes Anatoly Burakov
2024-07-08 16:07 ` [PATCH v1 1/4] fbarray: fix incorrect lookahead behavior Anatoly Burakov
2024-07-08 16:07 ` Anatoly Burakov [this message]
2024-07-08 16:07 ` [PATCH v1 3/4] fbarray: fix lookahead ignore mask handling Anatoly Burakov
2024-07-08 16:07 ` [PATCH v1 4/4] fbarray: fix lookbehind " Anatoly Burakov
2024-07-09  4:57 ` [PATCH v1 0/4] fbarray lookahead/lookbehind fixes David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bd7cdc5079a7eb1e3cbc173592a671c6b3f9fd89.1720454625.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=roretzla@linux.microsoft.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).