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 9E2F8455AD for ; Mon, 15 Jul 2024 17:29:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9931C40BA6; Mon, 15 Jul 2024 17:29:23 +0200 (CEST) Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by mails.dpdk.org (Postfix) with ESMTP id 01FBB402DD for ; Mon, 15 Jul 2024 17:29:22 +0200 (CEST) Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4267300145eso34541135e9.3 for ; Mon, 15 Jul 2024 08:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721057361; x=1721662161; 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=HUtLJPKuFmrz5WTMzetDAm2pA/7sRT7DUVCkJEi+roQ=; b=TWq+JBlDGGAJ0vvlmrrpwYtHCJA/K8Gs34m95N07byRpYS6LGAUjNXpz575gYnQEs0 1d+RyZp21vvHwW3hScuUcTHesL1XUfi3oAABwNaJATu2uMvdov6S3IIywTDvWUX1IcG0 667u3TlWFffkp+hmFGYDV3Pn5ars8KfHbxf9V/7dnokE5oTJaD9CDcUIAqUl7S4hWnqz 3kllRqcTyv9ZEKquYooYALj4N4/sdRJPQ1vb+qUaXawnEXZlbToh0FuIp79S+PMH4fTR ow8UKrREFVm0KOQZbhfLwnP/xsqv6fueZ0SWuGlAWSBvefMSFVusFAjZTVk3XMxyWID2 8tvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721057361; x=1721662161; 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=HUtLJPKuFmrz5WTMzetDAm2pA/7sRT7DUVCkJEi+roQ=; b=uz4VVcbWtSnCHKo0cPaRDvy1CXRjIjnKUs+sW1H/c9z4cvdZi1Ma3ppdQOSLN18TT4 WK9mxImneREfNOHZUGwGGxDG57BmcuKBResK1PMHfmf8yPprfyHrY4qD6HEUSAViyAj/ tvfHvS+KVyTQgSNkbfdVGpS2HAW+nyLN8UrcMXR8CAPdnNsSnfWo1OHdHmNJATGIaNnH tGooQl1gHVGyGFg+DyRfNa+vkIS1asnvZWv4NzFOgMaOV9MjgVQyt3G8fNTskBcJxdpw deYrfT6ECXwvlmIA6zzh7a8CcWLJDjd6rOS4Rmsk5qfyI8F8Kx3FKRhB0nUhnsRE4Sbw SJrg== X-Gm-Message-State: AOJu0YzBNzlOehD0zEyZwUABOvn1NczV9rG4gxUSocLb2eiWeMaobzrR GlzE7t5W/Y+o81xF43PQ1IeqyLiVCDcI540x8bbX9+530pELIEji4qwDmL6s X-Google-Smtp-Source: AGHT+IFgqk05T8+15niXYL7ARbIFw+r1f++gtxw/V9xxUGSv+/Lxd6KnNK3PVO36cLR3LtsJhC57gA== X-Received: by 2002:a05:600c:2d48:b0:426:55a3:71b5 with SMTP id 5b1f17b1804b1-426707ce9c0mr142097025e9.9.1721057361500; Mon, 15 Jul 2024 08:29:21 -0700 (PDT) Received: from localhost ([137.220.120.171]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279f27a265sm124781265e9.28.2024.07.15.08.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 08:29:21 -0700 (PDT) From: luca.boccassi@gmail.com To: Anatoly Burakov Cc: dpdk stable Subject: patch 'fbarray: fix finding for unaligned length' has been queued to stable release 22.11.6 Date: Mon, 15 Jul 2024 16:26:20 +0100 Message-Id: <20240715152704.2229503-42-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/73a8315608a79ab9b721d5155e407cb4f6a0499a Thanks. Luca Boccassi --- >From 73a8315608a79ab9b721d5155e407cb4f6a0499a 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 @@ -21,23 +21,41 @@ 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; } 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; for (i = param.start; i <= param.end; i++) { @@ -47,11 +65,35 @@ static int init_array(void) return 0; } -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; + } static int first_msk_test_setup(void) @@ -59,7 +101,7 @@ static int first_msk_test_setup(void) /* put all within first mask */ param.start = 3; param.end = 10; - return init_array(); + return init_aligned(); } static int cross_msk_test_setup(void) @@ -67,7 +109,7 @@ static int cross_msk_test_setup(void) /* put all within second and third mask */ param.start = 70; param.end = 160; - return init_array(); + return init_aligned(); } static int multi_msk_test_setup(void) @@ -75,7 +117,7 @@ static int multi_msk_test_setup(void) /* put all within first and last mask */ param.start = 3; param.end = FBARRAY_TEST_LEN - 20; - return init_array(); + return init_aligned(); } static int last_msk_test_setup(void) @@ -83,7 +125,7 @@ static int last_msk_test_setup(void) /* put all within last mask */ param.start = FBARRAY_TEST_LEN - 20; param.end = FBARRAY_TEST_LEN - 1; - return init_array(); + return init_aligned(); } static int full_msk_test_setup(void) @@ -91,16 +133,7 @@ static int full_msk_test_setup(void) /* fill entire mask */ 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(); } static int lookahead_test_setup(void) @@ -108,7 +141,7 @@ static int lookahead_test_setup(void) /* set index 64 as used */ param.start = 64; param.end = 64; - return init_array(); + return init_aligned(); } static int lookbehind_test_setup(void) @@ -116,7 +149,15 @@ static int lookbehind_test_setup(void) /* set index 63 as used */ 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(); } static int test_invalid(void) @@ -470,7 +511,7 @@ static int test_basic(void) if (check_free()) return TEST_FAILED; - reset_array(); + reset_aligned(); return TEST_SUCCESS; } @@ -713,6 +754,26 @@ static int test_find(void) return TEST_SUCCESS; } +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) { TEST_ASSERT_EQUAL((int)param.arr.count, 0, "Wrong element count\n"); @@ -814,17 +875,19 @@ static struct unit_test_suite fbarray_test_suite = { .unit_test_cases = { 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 34f51d8530..4b3b3904c7 100644 --- a/lib/eal/common/eal_common_fbarray.c +++ b/lib/eal/common/eal_common_fbarray.c @@ -173,7 +173,7 @@ 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 */ if (ignore_msk) { -- 2.39.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-07-15 16:19:36.791681237 +0100 +++ 0042-fbarray-fix-finding-for-unaligned-length.patch 2024-07-15 16:19:34.564206378 +0100 @@ -1 +1 @@ -From a744665d2149ba8707621c1214c798f807ec398e Mon Sep 17 00:00:00 2001 +From 73a8315608a79ab9b721d5155e407cb4f6a0499a 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 @@ -259 +260 @@ -index 63d8b731f5..22b43073c6 100644 +index 34f51d8530..4b3b3904c7 100644