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 105F5A054A for ; Tue, 25 Oct 2022 17:08:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 090E042C41; Tue, 25 Oct 2022 17:08:11 +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 89AD942C34 for ; Tue, 25 Oct 2022 17:08:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666710489; 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=Y1hW9IB7E3dcyc22Zt5c6e0yt6Kgf8ZToy0XERiZb4Q=; b=S9mZVeAxE51OXsOm6CjmndAKuSB0fkavDyZWvVMC2R4wFd/NYRCSjUYWP2NVzvM2019/PR Btf0JrnGXuH9BOr2B9k2TRSCiU7xTLc0Zu03/teBwHMH/EcKk9cgHr/amHSkPzvyKMzJmY GLxXwpwzEgNvFejV/rleftQSzbsa/UY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-365-rOvw4dbpPayHwRc0jMM44w-1; Tue, 25 Oct 2022 11:08:07 -0400 X-MC-Unique: rOvw4dbpPayHwRc0jMM44w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31A8F8582B9; Tue, 25 Oct 2022 15:08:02 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.192.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8684C4A9254; Tue, 25 Oct 2022 15:08:00 +0000 (UTC) From: Kevin Traynor To: Dmitry Kozlyuk Cc: =?UTF-8?q?Morten=20Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng , dpdk stable Subject: patch 'eal: fix side effect in some pointer arithmetic macros' has been queued to stable release 21.11.3 Date: Tue, 25 Oct 2022 16:05:58 +0100 Message-Id: <20221025150734.142189-3-ktraynor@redhat.com> In-Reply-To: <20221025150734.142189-1-ktraynor@redhat.com> References: <20221025150734.142189-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 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 21.11.3 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/01/22. 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/48240d704e634336b5de4e9a0bcad40fb7089bdc Thanks. Kevin --- >From 48240d704e634336b5de4e9a0bcad40fb7089bdc Mon Sep 17 00:00:00 2001 From: Dmitry Kozlyuk Date: Sat, 27 Aug 2022 14:32:19 +0300 Subject: [PATCH] eal: fix side effect in some pointer arithmetic macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ upstream commit 1a7374c95678183aef6f40b64074752831a33d26 ] RTE_PTR_SUB(ptr, x) and RTE_PTR_ALIGN_FLOOR() worked incorrectly if "ptr" was an expression: uint32_t arr[3]; RTE_PTR_SUB(arr + 1, sizeof(arr[0])); // expected: (uint32_t *)((uintptr_t)(arr + 1) - 4) == arr // actual: (uint32_t *)((uintptr_t) arr + 1 - 4) != arr RTE_PTR_ALIGN_FLOOR(arr + 2, sizeof(arr[0])); // expected: RTE_ALIGN_FLOOR((uintptr_t)(arr + 2), 4) == &arr[2] // actual: RTE_ALIGN_FLOOR((uintptr_t) arr + 2, 4) == &arr[0] Fix the macros and extend the relevant unit test. Convert uses of a custom test failure macro to RTE_TEST_ASSERT*(). Fixes: af75078fece3 ("first public release") Signed-off-by: Dmitry Kozlyuk Reviewed-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- app/test/test_common.c | 56 +++++++++++++++++++++++++----------- lib/eal/include/rte_common.h | 4 +-- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/app/test/test_common.c b/app/test/test_common.c index ef177cecb1..f89e1eb7ee 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -26,29 +26,51 @@ test_macros(int __rte_unused unused_parm) #define BIGGER 0x2000U #define PTR_DIFF BIGGER - SMALLER -#define FAIL_MACRO(x)\ - {printf(#x "() test failed!\n");\ - return -1;} uintptr_t unused = 0; unsigned int smaller = SMALLER, bigger = BIGGER; + uint32_t arr[3]; RTE_SET_USED(unused); RTE_SWAP(smaller, bigger); - if (smaller != BIGGER && bigger != SMALLER) - FAIL_MACRO(RTE_SWAP); - if ((uintptr_t)RTE_PTR_ADD(SMALLER, PTR_DIFF) != BIGGER) - FAIL_MACRO(RTE_PTR_ADD); - if ((uintptr_t)RTE_PTR_SUB(BIGGER, PTR_DIFF) != SMALLER) - FAIL_MACRO(RTE_PTR_SUB); - if (RTE_PTR_DIFF(BIGGER, SMALLER) != PTR_DIFF) - FAIL_MACRO(RTE_PTR_DIFF); - if (RTE_MAX(SMALLER, BIGGER) != BIGGER) - FAIL_MACRO(RTE_MAX); - if (RTE_MIN(SMALLER, BIGGER) != SMALLER) - FAIL_MACRO(RTE_MIN); + RTE_TEST_ASSERT(smaller == BIGGER && bigger == SMALLER, + "RTE_SWAP"); + RTE_TEST_ASSERT_EQUAL((uintptr_t)RTE_PTR_ADD(SMALLER, PTR_DIFF), BIGGER, + "RTE_PTR_ADD"); + RTE_TEST_ASSERT_EQUAL((uintptr_t)RTE_PTR_SUB(BIGGER, PTR_DIFF), SMALLER, + "RTE_PTR_SUB"); + RTE_TEST_ASSERT_EQUAL(RTE_PTR_DIFF(BIGGER, SMALLER), PTR_DIFF, + "RTE_PTR_DIFF"); + RTE_TEST_ASSERT_EQUAL(RTE_MAX(SMALLER, BIGGER), BIGGER, + "RTE_MAX"); + RTE_TEST_ASSERT_EQUAL(RTE_MIN(SMALLER, BIGGER), SMALLER, + "RTE_MIN"); - if (strncmp(RTE_STR(test), "test", sizeof("test"))) - FAIL_MACRO(RTE_STR); + RTE_TEST_ASSERT_EQUAL(RTE_PTR_ADD(arr + 1, sizeof(arr[0])), &arr[2], + "RTE_PTR_ADD(expr, x)"); + RTE_TEST_ASSERT_EQUAL(RTE_PTR_SUB(arr + 1, sizeof(arr[0])), &arr[0], + "RTE_PTR_SUB(expr, x)"); + RTE_TEST_ASSERT_EQUAL(RTE_PTR_ALIGN_FLOOR(arr + 2, 4), &arr[2], + "RTE_PTR_ALIGN_FLOOR(expr, x)"); + RTE_TEST_ASSERT_EQUAL(RTE_PTR_ALIGN_CEIL(arr + 2, 4), &arr[2], + "RTE_PTR_ALIGN_CEIL(expr, x)"); + RTE_TEST_ASSERT_EQUAL(RTE_PTR_ALIGN(arr + 2, 4), &arr[2], + "RTE_PTR_ALIGN(expr, x)"); + + RTE_TEST_ASSERT_EQUAL( + RTE_PTR_ALIGN_FLOOR(RTE_PTR_ADD(&arr[1], 1), 4), &arr[1], + "RTE_PTR_ALIGN_FLOOR(x < y/2, y)"); + RTE_TEST_ASSERT_EQUAL( + RTE_PTR_ALIGN_FLOOR(RTE_PTR_ADD(&arr[1], 3), 4), &arr[1], + "RTE_PTR_ALIGN_FLOOR(x > y/2, y)"); + RTE_TEST_ASSERT_EQUAL( + RTE_PTR_ALIGN_CEIL(RTE_PTR_ADD(&arr[1], 3), 4), &arr[2], + "RTE_PTR_ALIGN_CEIL(x < y/2, y)"); + RTE_TEST_ASSERT_EQUAL( + RTE_PTR_ALIGN_CEIL(RTE_PTR_ADD(&arr[1], 1), 4), &arr[2], + "RTE_PTR_ALIGN_CEIL(x > y/2, y)"); + + RTE_TEST_ASSERT(strncmp(RTE_STR(test), "test", sizeof("test")) == 0, + "RTE_STR"); return 0; diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index 6f004f6cb3..5122ea8925 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -271,5 +271,5 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) * subtract a byte-value offset from a pointer */ -#define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x))) +#define RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x))) /** @@ -296,5 +296,5 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) */ #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ - ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align)) + ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align)) /** -- 2.37.3 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2022-10-25 14:18:58.661639051 +0100 +++ 0003-eal-fix-side-effect-in-some-pointer-arithmetic-macro.patch 2022-10-25 14:18:58.350797873 +0100 @@ -1 +1 @@ -From 1a7374c95678183aef6f40b64074752831a33d26 Mon Sep 17 00:00:00 2001 +From 48240d704e634336b5de4e9a0bcad40fb7089bdc Mon Sep 17 00:00:00 2001 @@ -8,0 +9,2 @@ +[ upstream commit 1a7374c95678183aef6f40b64074752831a33d26 ] + @@ -26 +27,0 @@ -Cc: stable@dpdk.org @@ -111 +112 @@ -index a96cc2a138..d517e9f75f 100644 +index 6f004f6cb3..5122ea8925 100644 @@ -114 +115 @@ -@@ -296,5 +296,5 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) +@@ -271,5 +271,5 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) @@ -121 +122 @@ -@@ -321,5 +321,5 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) +@@ -296,5 +296,5 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)