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 541A145804 for ; Fri, 23 Aug 2024 18:22:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4D18C4338F; Fri, 23 Aug 2024 18:22:18 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id BFEF14336F for ; Fri, 23 Aug 2024 18:22:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724430136; 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=g7OvggHN5npgRgncu4X4LC7atDz2UwVgWift5NksE3o=; b=iPOmn63ykjaux+kC8IU+lhrcPbPLaoKkjFyZJOymJAPCVyDKPfirQhXpCeRZvLW8/4t3wg c///Jh7PLmZ94zr/m2sqICfGS/NZwwqycmwPEM02+x558SZAWI6NttG0DovK+t53Ck6Ef9 vE2H9W2V1r1N/kNXxDQOqrXU8xWdrVw= Received: from mx-prod-mc-05.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-414-V4Dqu1aJNMWlqsbg8Ih2pg-1; Fri, 23 Aug 2024 12:22:15 -0400 X-MC-Unique: V4Dqu1aJNMWlqsbg8Ih2pg-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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ED4731955F4A; Fri, 23 Aug 2024 16:22:13 +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 44ED71955F45; Fri, 23 Aug 2024 16:22:11 +0000 (UTC) From: Kevin Traynor To: Anatoly Burakov Cc: Vipin Padmam Ramesh , dpdk stable Subject: patch 'fbarray: fix lookbehind ignore mask handling' has been queued to stable release 21.11.8 Date: Fri, 23 Aug 2024 17:18:21 +0100 Message-ID: <20240823161929.1004778-73-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/8203dd48edd837f382e921be2558190ca0ee4e01 Thanks. Kevin --- >From 8203dd48edd837f382e921be2558190ca0ee4e01 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 @@ -782,4 +782,30 @@ static int test_lookahead_mask(void) } +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", @@ -799,4 +825,5 @@ static struct unit_test_suite fbarray_test_suite = { /* 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 def47ceef0..6dcbff0ba6 100644 --- a/lib/eal/common/eal_common_fbarray.c +++ b/lib/eal/common/eal_common_fbarray.c @@ -512,6 +512,11 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, 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 */ @@ -522,5 +527,5 @@ 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; + ignore_msk = ~(UINT64_MAX << (MASK_ALIGN - s_idx - 1)); /* outer loop will decrement msk_idx so add 1 */ msk_idx = lookbehind_idx + 1; -- 2.46.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-08-23 17:18:11.968551157 +0100 +++ 0073-fbarray-fix-lookbehind-ignore-mask-handling.patch 2024-08-23 17:18:09.752430217 +0100 @@ -1 +1 @@ -From 0c6e2781578f37d0497c225acf68ce5ffe31bd8e Mon Sep 17 00:00:00 2001 +From 8203dd48edd837f382e921be2558190ca0ee4e01 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 @@ -72 +73 @@ -index 195f8394be..63d8b731f5 100644 +index def47ceef0..6dcbff0ba6 100644 @@ -75 +76 @@ -@@ -509,6 +509,11 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, +@@ -512,6 +512,11 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, @@ -88 +89 @@ -@@ -519,5 +524,5 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, +@@ -522,5 +527,5 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,