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 39B80455C2; Mon, 8 Jul 2024 18:07:54 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4E2A042794; Mon, 8 Jul 2024 18:07:45 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by mails.dpdk.org (Postfix) with ESMTP id A61564029E; Mon, 8 Jul 2024 18:07:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720454862; x=1751990862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5hS4KqDK+7kIBoPImh/vCX5QRQbVDsMty5aH7UTcNpQ=; b=AY06IZIo0ed3et1a8N+tNjvICFlXP2vtDXQGqBN2/Z75x/8warA7QEOP buB/7UZSBN3ESuHmBlDamgFqnKEDDVoISy4L/sqyk+p7PpjJEhkpLT6Cu KKwZU8UrNVrOPvpnZautwtn7fjL7SyeU3a4WhGTC/IdUDSyHpCJkk8QJx ZarGvZxbDDesLz+WsdpsvGkVKaZp43HjW2XvrdbLcpCW+uXA4Up0PoRop MBgA/oHHpczawNZ+EjVE3bsWpI9pDJmP7o1qc9m6gd8ocFG8We+bbU3Af K+k/x0e+x4rwPr/9H5arn7l+84YjN7BoutqJemjLxFLkl3/Dxd09Xee3x w==; X-CSE-ConnectionGUID: AVuabdnvSyidsut75x4EgQ== X-CSE-MsgGUID: APbKA6gPQKanpp8Qlhw1EQ== X-IronPort-AV: E=McAfee;i="6700,10204,11127"; a="28827524" X-IronPort-AV: E=Sophos;i="6.09,192,1716274800"; d="scan'208";a="28827524" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2024 09:07:41 -0700 X-CSE-ConnectionGUID: ecuRvVpUTiyCnetKwlb74g== X-CSE-MsgGUID: T2dI1ItgSb62Q6NPio71PQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,192,1716274800"; d="scan'208";a="51965481" Received: from silpixa00401119.ir.intel.com ([10.55.129.167]) by fmviesa005.fm.intel.com with ESMTP; 08 Jul 2024 09:07:40 -0700 From: Anatoly Burakov To: dev@dpdk.org, Tyler Retzlaff Cc: stable@dpdk.org Subject: [PATCH v1 2/4] fbarray: fix incorrect lookbehind behavior Date: Mon, 8 Jul 2024 17:07:33 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Signed-off-by: Anatoly Burakov --- 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(¶m.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