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 9EA4645804 for ; Fri, 23 Aug 2024 18:22:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 995DC4336F; Fri, 23 Aug 2024 18:22:35 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 59247402BE for ; Fri, 23 Aug 2024 18:22:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724430153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CJDIE11U+EhOzZ3/1sw/B13Z1JRat0y8Jvp4/X2a3x8=; b=FEnLoS/ydukMuAg0Z4T6qjF9SBWafgBvY2eScGibj/H6p0pmmNQmid8e8oUnO0gEGWR8+A FSmA/B+nVQL/62XacCQ3ZHQHIAgkdzj9nLBHEi6W0AXJIZ6m7xsJvmRR8+04Y4dIyXiCvi qs7tY44aQkqJWI3/wN4vf3yPAtkINUs= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-C5LCwqg2OIC91nr-w1nG_A-1; Fri, 23 Aug 2024 12:22:30 -0400 X-MC-Unique: C5LCwqg2OIC91nr-w1nG_A-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D35DD1955D4C; Fri, 23 Aug 2024 16:22:29 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.193.224]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 898761956053; Fri, 23 Aug 2024 16:22:28 +0000 (UTC) From: Kevin Traynor To: Anatoly Burakov Cc: dpdk stable Subject: patch 'fbarray: fix finding for unaligned length' has been queued to stable release 21.11.8 Date: Fri, 23 Aug 2024 17:18:29 +0100 Message-ID: <20240823161929.1004778-81-ktraynor@redhat.com> In-Reply-To: <20240823161929.1004778-1-ktraynor@redhat.com> References: <20240823161929.1004778-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 21.11.8 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 08/28/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/kevintraynor/dpdk-stable This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable/commit/3a72f98ab15e44228cb77a0dcd9573d9a9195c4e Thanks. Kevin --- >From 3a72f98ab15e44228cb77a0dcd9573d9a9195c4e Mon Sep 17 00:00:00 2001 From: Anatoly Burakov Date: Wed, 10 Jul 2024 12:49:26 +0100 Subject: [PATCH] fbarray: fix finding for unaligned length [ upstream commit a744665d2149ba8707621c1214c798f807ec398e ] When array length is not aligned on a power of 2, we need to mask out the unaligned bits from the mask whenever we reach the last mask. However, when both ignore mask (e.g. due to starting at unaligned bit) and last index ignore mask are specified, we combine them with an OR, which is incorrect. Fix it to combine them with AND instead, and add a unit test covering this case. The reverse function does not suffer from this issue because it does not have to deal with array end, and array beginning is always aligned. Fixes: c44d09811b40 ("eal: add shared indexed file-backed array") Signed-off-by: Anatoly Burakov --- app/test/test_fbarray.c | 123 +++++++++++++++++++++------- lib/eal/common/eal_common_fbarray.c | 2 +- 2 files changed, 94 insertions(+), 31 deletions(-) diff --git a/app/test/test_fbarray.c b/app/test/test_fbarray.c index 3be9e19e78..8a3a3d77ab 100644 --- a/app/test/test_fbarray.c +++ b/app/test/test_fbarray.c @@ -22,13 +22,30 @@ struct fbarray_testsuite_params { static struct fbarray_testsuite_params param; +static struct fbarray_testsuite_params unaligned; #define FBARRAY_TEST_ARR_NAME "fbarray_autotest" #define FBARRAY_TEST_LEN 256 +#define FBARRAY_UNALIGNED_TEST_ARR_NAME "fbarray_unaligned_autotest" +#define FBARRAY_UNALIGNED_TEST_LEN 60 #define FBARRAY_TEST_ELT_SZ (sizeof(int)) static int autotest_setup(void) { - return rte_fbarray_init(¶m.arr, FBARRAY_TEST_ARR_NAME, + int ret; + + ret = rte_fbarray_init(¶m.arr, FBARRAY_TEST_ARR_NAME, FBARRAY_TEST_LEN, FBARRAY_TEST_ELT_SZ); + if (ret) { + printf("Failed to initialize test array\n"); + return -1; + } + ret = rte_fbarray_init(&unaligned.arr, FBARRAY_UNALIGNED_TEST_ARR_NAME, + FBARRAY_UNALIGNED_TEST_LEN, FBARRAY_TEST_ELT_SZ); + if (ret) { + printf("Failed to initialize unaligned test array\n"); + rte_fbarray_destroy(¶m.arr); + return -1; + } + return 0; } @@ -36,7 +53,8 @@ static void autotest_teardown(void) { rte_fbarray_destroy(¶m.arr); + rte_fbarray_destroy(&unaligned.arr); } -static int init_array(void) +static int init_aligned(void) { int i; @@ -48,9 +66,33 @@ static int init_array(void) } -static void reset_array(void) +static int init_unaligned(void) +{ + int i; + for (i = unaligned.start; i <= unaligned.end; i++) { + if (rte_fbarray_set_used(&unaligned.arr, i)) + return -1; + } + return 0; +} + +static void reset_aligned(void) { int i; for (i = 0; i < FBARRAY_TEST_LEN; i++) rte_fbarray_set_free(¶m.arr, i); + /* reset param as well */ + param.start = -1; + param.end = -1; +} + +static void reset_unaligned(void) +{ + int i; + for (i = 0; i < FBARRAY_UNALIGNED_TEST_LEN; i++) + rte_fbarray_set_free(&unaligned.arr, i); + /* reset param as well */ + unaligned.start = -1; + unaligned.end = -1; + } @@ -60,5 +102,5 @@ static int first_msk_test_setup(void) param.start = 3; param.end = 10; - return init_array(); + return init_aligned(); } @@ -68,5 +110,5 @@ static int cross_msk_test_setup(void) param.start = 70; param.end = 160; - return init_array(); + return init_aligned(); } @@ -76,5 +118,5 @@ static int multi_msk_test_setup(void) param.start = 3; param.end = FBARRAY_TEST_LEN - 20; - return init_array(); + return init_aligned(); } @@ -84,5 +126,5 @@ static int last_msk_test_setup(void) param.start = FBARRAY_TEST_LEN - 20; param.end = FBARRAY_TEST_LEN - 1; - return init_array(); + return init_aligned(); } @@ -92,14 +134,5 @@ static int full_msk_test_setup(void) param.start = 0; param.end = FBARRAY_TEST_LEN - 1; - return init_array(); -} - -static int empty_msk_test_setup(void) -{ - /* do not fill anything in */ - reset_array(); - param.start = -1; - param.end = -1; - return 0; + return init_aligned(); } @@ -109,5 +142,5 @@ static int lookahead_test_setup(void) param.start = 64; param.end = 64; - return init_array(); + return init_aligned(); } @@ -117,5 +150,13 @@ static int lookbehind_test_setup(void) param.start = 63; param.end = 63; - return init_array(); + return init_aligned(); +} + +static int unaligned_test_setup(void) +{ + unaligned.start = 0; + /* leave one free bit at the end */ + unaligned.end = FBARRAY_UNALIGNED_TEST_LEN - 2; + return init_unaligned(); } @@ -471,5 +512,5 @@ static int test_basic(void) return TEST_FAILED; - reset_array(); + reset_aligned(); return TEST_SUCCESS; @@ -714,4 +755,24 @@ static int test_find(void) } +static int test_find_unaligned(void) +{ + TEST_ASSERT_EQUAL((int)unaligned.arr.count, unaligned.end - unaligned.start + 1, + "Wrong element count\n"); + /* ensure space is free before start */ + if (ensure_correct(&unaligned.arr, 0, unaligned.start - 1, false)) + return TEST_FAILED; + /* ensure space is occupied where it's supposed to be */ + if (ensure_correct(&unaligned.arr, unaligned.start, unaligned.end, true)) + return TEST_FAILED; + /* ensure space after end is free as well */ + if (ensure_correct(&unaligned.arr, unaligned.end + 1, FBARRAY_UNALIGNED_TEST_LEN - 1, + false)) + return TEST_FAILED; + /* test if find_biggest API's work correctly */ + if (test_biggest(&unaligned.arr, unaligned.start, unaligned.end)) + return TEST_FAILED; + return TEST_SUCCESS; +} + static int test_empty(void) { @@ -815,15 +876,17 @@ static struct unit_test_suite fbarray_test_suite = { TEST_CASE(test_invalid), TEST_CASE(test_basic), - TEST_CASE_ST(first_msk_test_setup, reset_array, test_find), - TEST_CASE_ST(cross_msk_test_setup, reset_array, test_find), - TEST_CASE_ST(multi_msk_test_setup, reset_array, test_find), - TEST_CASE_ST(last_msk_test_setup, reset_array, test_find), - 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_CASE_ST(first_msk_test_setup, reset_aligned, test_find), + TEST_CASE_ST(cross_msk_test_setup, reset_aligned, test_find), + TEST_CASE_ST(multi_msk_test_setup, reset_aligned, test_find), + TEST_CASE_ST(last_msk_test_setup, reset_aligned, test_find), + TEST_CASE_ST(full_msk_test_setup, reset_aligned, test_find), + /* empty test does not need setup */ + TEST_CASE_ST(NULL, reset_aligned, test_empty), + TEST_CASE_ST(lookahead_test_setup, reset_aligned, test_lookahead), + TEST_CASE_ST(lookbehind_test_setup, reset_aligned, 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_CASE_ST(NULL, reset_aligned, test_lookahead_mask), + TEST_CASE_ST(NULL, reset_aligned, test_lookbehind_mask), + TEST_CASE_ST(unaligned_test_setup, reset_unaligned, test_find_unaligned), TEST_CASES_END() } diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c index 6dcbff0ba6..ad40b6d9f9 100644 --- a/lib/eal/common/eal_common_fbarray.c +++ b/lib/eal/common/eal_common_fbarray.c @@ -177,5 +177,5 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, /* combine current ignore mask with last index ignore mask */ if (msk_idx == last) - ignore_msk |= last_msk; + ignore_msk &= last_msk; /* if we have an ignore mask, ignore once */ -- 2.46.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-08-23 17:18:12.151078273 +0100 +++ 0081-fbarray-fix-finding-for-unaligned-length.patch 2024-08-23 17:18:09.756430231 +0100 @@ -1 +1 @@ -From a744665d2149ba8707621c1214c798f807ec398e Mon Sep 17 00:00:00 2001 +From 3a72f98ab15e44228cb77a0dcd9573d9a9195c4e Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit a744665d2149ba8707621c1214c798f807ec398e ] + @@ -19 +20,0 @@ -Cc: stable@dpdk.org @@ -28 +29 @@ -index 13c6691e50..09f6907fb1 100644 +index 3be9e19e78..8a3a3d77ab 100644 @@ -235 +236 @@ -index 63d8b731f5..22b43073c6 100644 +index 6dcbff0ba6..ad40b6d9f9 100644 @@ -238 +239 @@ -@@ -174,5 +174,5 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, +@@ -177,5 +177,5 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,