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 2220FA00C2 for ; Thu, 3 Nov 2022 10:28:08 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1890740DF7; Thu, 3 Nov 2022 10:28:08 +0100 (CET) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by mails.dpdk.org (Postfix) with ESMTP id 8BDB740693 for ; Thu, 3 Nov 2022 10:28:06 +0100 (CET) Received: by mail-wr1-f41.google.com with SMTP id o4so1710768wrq.6 for ; Thu, 03 Nov 2022 02:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=dsNgE9oZGkq8nkUfOXyP8WPmFHzKyPiFcPssniA7jlM=; b=JGUXGUx3DOHknnOUtWzsjvvZUUtO23jPB04GRdAZP48/qooQK938nVGfNm9nWmfyDA 71NYV8xjCFsRr6vBuMKBxju+grjayNdiU1CBPCNp5ACZez2uZEJGZDD65PQ+j64O3E+9 qQNhr96365V/YipoRUWCnPRAkzLmiN9dEKQYZDlCF7Wk/Dqb+U3N2+xOZmSEu2ny3m8O auGb2+QImjO47di1McLS2gg6jE91I1QKziDhjRSV3jtLjbGDBNQ35klaXe7ZkuGz1q5n WE6xLOlyeDiC333njVDt+Q+BKPMhqiOw5B7YdfgOqXXBIsF6OB4dDuYSMF0to6QcHliq oh5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=dsNgE9oZGkq8nkUfOXyP8WPmFHzKyPiFcPssniA7jlM=; b=fqcL236GatvqUuFLr6FgvjwRkMgugYGsojlbDnMu/zZQGcZJMCck0H1jiBuqVKUNmC fVfsTBEBuB3yuY/UGFkvzBjOT8MKx07R/wvvBtso1TUc93FkCW4oAw2fulvbRM74AEG9 DNXo7/Ajp37M2vbqdMGTmq3WhDoctM/AfyJBBDK9alBR4yeerVOlH0I3LimQMvEAy2jT R3/m8cTohc1Y3K3l2y4MwkxBJf3OPkhXlELNAEcGSAVkLXHAdVpR00LbO4JqvaDpRtHG IiyPGgqvmGYEqIuDUmiJc5cYotNorDBv2GM3temCjqtHVqMFCtOVUpaVxgJHNralSvZ3 hu3g== X-Gm-Message-State: ACrzQf3QFsjVcAhJRCQJT5bgOC/nYDNxBMek+5k27elKls+dvry1hK+z I50czIlMxn7qz6HSorCkwsw= X-Google-Smtp-Source: AMsMyM7pPgJ2zqfDVEx6bK0nPhKHMcqtdv+YeZAraIzIe1cDz0ONSWPmOcnXzHfj9t1I1gy4uJ+HBg== X-Received: by 2002:adf:c582:0:b0:22b:3c72:6b81 with SMTP id m2-20020adfc582000000b0022b3c726b81mr18303035wrg.320.1667467686064; Thu, 03 Nov 2022 02:28:06 -0700 (PDT) Received: from localhost ([137.220.119.58]) by smtp.gmail.com with ESMTPSA id d8-20020adfa408000000b002345cb2723esm415495wra.17.2022.11.03.02.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 02:28:05 -0700 (PDT) From: luca.boccassi@gmail.com 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 20.11.7 Date: Thu, 3 Nov 2022 09:26:20 +0000 Message-Id: <20221103092758.1099402-2-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221103092758.1099402-1-luca.boccassi@gmail.com> References: <20221103092758.1099402-1-luca.boccassi@gmail.com> MIME-Version: 1.0 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 20.11.7 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/05/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/1aa7dc7481d5bbacc6c86dfb87a81ff6c0eeda12 Thanks. Luca Boccassi --- >From 1aa7dc7481d5bbacc6c86dfb87a81ff6c0eeda12 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 | 52 ++++++++++++++++++++--------- lib/librte_eal/include/rte_common.h | 4 +-- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/app/test/test_common.c b/app/test/test_common.c index 12bd1cad90..181c8be3be 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -25,27 +25,49 @@ test_macros(int __rte_unused unused_parm) #define SMALLER 0x1000U #define BIGGER 0x2000U #define PTR_DIFF BIGGER - SMALLER -#define FAIL_MACRO(x)\ - {printf(#x "() test failed!\n");\ - return -1;} uintptr_t unused = 0; + uint32_t arr[3]; RTE_SET_USED(unused); - 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_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/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h index 677b52a2f8..853adcb249 100644 --- a/lib/librte_eal/include/rte_common.h +++ b/lib/librte_eal/include/rte_common.h @@ -255,7 +255,7 @@ 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))) /** * get the difference between two pointer values, i.e. how far apart @@ -280,7 +280,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) * must be a power-of-two value. */ #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)) /** * Macro to align a value to a given power-of-two. The resultant value -- 2.34.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2022-11-03 09:27:25.658313581 +0000 +++ 0002-eal-fix-side-effect-in-some-pointer-arithmetic-macro.patch 2022-11-03 09:27:25.293420892 +0000 @@ -1 +1 @@ -From 1a7374c95678183aef6f40b64074752831a33d26 Mon Sep 17 00:00:00 2001 +From 1aa7dc7481d5bbacc6c86dfb87a81ff6c0eeda12 Mon Sep 17 00:00:00 2001 @@ -8,0 +9,2 @@ +[ upstream commit 1a7374c95678183aef6f40b64074752831a33d26 ] + @@ -26 +27,0 @@ -Cc: stable@dpdk.org @@ -33,3 +34,3 @@ - app/test/test_common.c | 56 +++++++++++++++++++++++++----------- - lib/eal/include/rte_common.h | 4 +-- - 2 files changed, 41 insertions(+), 19 deletions(-) + app/test/test_common.c | 52 ++++++++++++++++++++--------- + lib/librte_eal/include/rte_common.h | 4 +-- + 2 files changed, 39 insertions(+), 17 deletions(-) @@ -38 +39 @@ -index ef177cecb1..f89e1eb7ee 100644 +index 12bd1cad90..181c8be3be 100644 @@ -41 +42 @@ -@@ -25,31 +25,53 @@ test_macros(int __rte_unused unused_parm) +@@ -25,27 +25,49 @@ test_macros(int __rte_unused unused_parm) @@ -50 +50,0 @@ - unsigned int smaller = SMALLER, bigger = BIGGER; @@ -55,3 +54,0 @@ - RTE_SWAP(smaller, bigger); -- if (smaller != BIGGER && bigger != SMALLER) -- FAIL_MACRO(RTE_SWAP); @@ -68,2 +64,0 @@ -+ RTE_TEST_ASSERT(smaller == BIGGER && bigger == SMALLER, -+ "RTE_SWAP"); @@ -112,5 +107,5 @@ -diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h -index a96cc2a138..d517e9f75f 100644 ---- a/lib/eal/include/rte_common.h -+++ b/lib/eal/include/rte_common.h -@@ -295,7 +295,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) +diff --git a/lib/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h +index 677b52a2f8..853adcb249 100644 +--- a/lib/librte_eal/include/rte_common.h ++++ b/lib/librte_eal/include/rte_common.h +@@ -255,7 +255,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) @@ -125 +120 @@ -@@ -320,7 +320,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) +@@ -280,7 +280,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)