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 CB7BDA034F for ; Wed, 10 Nov 2021 07:47:10 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C1E8F40683; Wed, 10 Nov 2021 07:47:10 +0100 (CET) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2040.outbound.protection.outlook.com [40.107.237.40]) by mails.dpdk.org (Postfix) with ESMTP id 1A49340142 for ; Wed, 10 Nov 2021 07:47:09 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R9qcNB1vql2a01e4kLqLzQcWgh1Kwt3xeA4zXmmWtibQhgR1K47yo7w9djX+VO3RI7tMBuBRITjs/kjLU/VmfMcs2EVmgGFCY02pKDJx2guLq3FrT0sTshV3CuG0z79BocJXSxCOe9bevHZu5zuxzTb5srPA0ONJYfhdBdrP5MmtunUZp9KojVlMRYNBDKznGKzjQ3h8mrCDiC3QzHctPJbqtnVuguFnel1qTU6dzwB5N4lN+9SD76wWDs37lIy1/MgBAo8zxlQdVYwvVRcqxDNQXCfMklaDEabAucTrI5YTSepBQyqQxj0/h0yj9thnYjkMr4LacQaw1Hkd53L9nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=N9Pd8GjFa78NytAY63wgdIorGd1X4Fbk/aj9qM16NFU=; b=cQlM7VjBbnug+/EFrk9oVVtGrHBpktZ0t/t5is7h/gZ0frVxPiGAbOuKQPnujv0YXHeNWlCZKf8xXQVR+b9xLV21XbljwtHkE1k3XGUZu2hW8HKMQA2jn2zLj/O/dIr7Xw0aoCm5qKPm9DfrxQJLQrJXsxBqPN5SFe6z2Ula6J+wkbwQqsfeHEOrM5MRVUZxcmk0tBSNvbDQoMxYfW0C32fU0aIaLppoa9sTvpcfD2zMz9j2KYEqh4wvbHAiQlkJbYZCZR7azMghPbMueMBJxr6M5lftVZiCZL0ErqGwA+A2BV1Bg4w7QxeKIkF61FuDTf2EmhtW25AQMkNEuQ0AIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N9Pd8GjFa78NytAY63wgdIorGd1X4Fbk/aj9qM16NFU=; b=WBjikqRLutu0pJ5bJT+4BnkB5OBrdvbN2wvGMKCMDs5PILrd2SU7KENz/VMwxyFvHPkWNc0oBvp16PWf0wh8DRE2D9KkXro3FDVfv4QclZ25N79SIs5Zz1+c7kAhZdafogfF8sYSN4dO/vuIGIu2NuxqDAkzK2fmoj9XKEw2+9pMgI65q3kSVze+UCpUt6afPkTeHRAnuWX5mL8KXHnZENcXiclDiNXS1MZKqk5s9NWgTVxj9TZLc6puiSQFGAa1SCdOYO451TVSK5CLhJW+cJr7tAR0SM9rTdNp7zVMjWNV2k6Ggxf1BNcBZWoAO6hleFHMEUclTNQT4qm4t7yfHQ== Received: from BN8PR07CA0009.namprd07.prod.outlook.com (2603:10b6:408:ac::22) by DM6PR12MB4266.namprd12.prod.outlook.com (2603:10b6:5:21a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Wed, 10 Nov 2021 06:47:07 +0000 Received: from BN8NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ac:cafe::1a) by BN8PR07CA0009.outlook.office365.com (2603:10b6:408:ac::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Wed, 10 Nov 2021 06:47:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT025.mail.protection.outlook.com (10.13.177.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4669.10 via Frontend Transport; Wed, 10 Nov 2021 06:47:07 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 10 Nov 2021 06:47:05 +0000 From: Xueming Li To: Konstantin Ananyev CC: Luca Boccassi , Stephen Hemminger , dpdk stable Date: Wed, 10 Nov 2021 14:30:15 +0800 Message-ID: <20211110063216.2744012-132-xuemingl@nvidia.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211110063216.2744012-1-xuemingl@nvidia.com> References: <20211110063216.2744012-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3ea22b0f-1d8f-438b-2611-08d9a415e9de X-MS-TrafficTypeDiagnostic: DM6PR12MB4266: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: diYnEFZDmg7kSpb5T91fHSoKImU8TpTc8BgLgAzf7DmmpljyQps/tHpGTUaDD5B3O1kvGwOiak93XOqhvWC8255cFf2GPOODzyG0AvsO0MvufReQ04cCb1DD4m0evgPaflyz4slAzAIecge0afVOLwSJDA2p97/30H4m++izuwahDfhztkYizDyCg/9ujCNpQ2wQr5CJOYOABgbZRJabNdGxBiVwkHdWp10TF7k6E63n4ZMKAFmnQYvV2nq9zXg4/xff1VjRCtSe8RWup0CltpbQLzBostjAbhC9qF25Cf4Pv+YTmjOAOfLq840YGrzT3L0aRDNYRHy/0vP8Jn7Yi8MLtomnyJjN8Z+R1boY338FpbTngc1uz8UxcqAmKhv0c0HOsQqD/aIDDenNWwEMGWzZqCuwRWIscLyzR6FJI/FSeD1lBKlZil3fXDs97Gmzsd3+0igO+3RyLjMgA4HskHWuZrzlV6d1jtptKJQy06w99nEL5GomgpcW18viWq8MSHOD8+2vV5GYAERX+E29lh5HTQTpKCQ0B/TefAKnvBog8nouAXnHTMFIZZ7K+LSHc5sGKD7+VU/k2zK1+3hAnk/0rdUrbr/EWjIvVSdafeSipXEhEnX98bUYRNmxB1QkGFTv2Vn6lRhB24J31xCTf8GmOUazdryu6a7co6vme6GUPq9eK7ymjPlfWTbp2RM9th3zo1sVWWSgsP+DBeaM/qgLBCZKMWggRFxMMRv6gy4AKw4MMGtgFt5azXiSlPC9UTxLbfBlI6UQibrEs6IESNgaYGFvBGlLUUEEEiePwv9w3Nzj/MeaEamybJPihwpY6WXhhE68Zr/LzM8Bu5SFPQ== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(316002)(36906005)(508600001)(55016002)(7696005)(36756003)(70586007)(5660300002)(54906003)(426003)(8676002)(82310400003)(4326008)(53546011)(36860700001)(70206006)(83380400001)(356005)(966005)(8936002)(6286002)(26005)(6916009)(86362001)(336012)(16526019)(2906002)(4001150100001)(186003)(2616005)(47076005)(6666004)(7636003)(1076003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 06:47:07.2875 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ea22b0f-1d8f-438b-2611-08d9a415e9de X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4266 Subject: [dpdk-stable] patch 'test/bpf: fix undefined behavior with clang' has been queued to stable release 20.11.4 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 Sender: "stable" Hi, FYI, your patch has been queued to stable release 20.11.4 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/12/21. 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/steevenlee/dpdk This queued commit can be viewed at: https://github.com/steevenlee/dpdk/commit/9f78abfa183b2b85f21d55d9684aed32b4f6ac54 Thanks. Xueming Li --- >From 9f78abfa183b2b85f21d55d9684aed32b4f6ac54 Mon Sep 17 00:00:00 2001 From: Konstantin Ananyev Date: Mon, 18 Oct 2021 14:40:52 +0100 Subject: [PATCH] test/bpf: fix undefined behavior with clang Cc: Xueming Li [ upstream commit 3ac2dffae88e8eb5c374b1fdd40d605014526510 ] test_shift1_check() function fails with clang build. The reason for that is that clang uses 64-bit shift instruction for what expected to be 32-bit operation. To be more specific, this C code: r2 = (uint32_t)r2 >> r4; With clang produces: 41a4eb: 48 d3 ef shr %cl,%rdi In that particular case it is an allowed choice, as from one side left-operand value is known to fit into 32 bits, from other side according to 'C' standard: "...if the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined." The problem is that on x86 behavior for 64-bit and 32-bit shift operation might differ. The fix avoids undefined behavior by making sure that right operand will not exceed width of the promoted left operand. Bugzilla ID: 811 Fixes: 9f8f9d91a701 ("test/bpf: introduce functional test") Reported-by: Stephen Hemminger Signed-off-by: Konstantin Ananyev Acked-by: Stephen Hemminger --- app/test/test_bpf.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/app/test/test_bpf.c b/app/test/test_bpf.c index 527c06b807..7002c6a734 100644 --- a/app/test/test_bpf.c +++ b/app/test/test_bpf.c @@ -59,6 +59,9 @@ struct dummy_mbuf { #define TEST_SHIFT_1 15 #define TEST_SHIFT_2 33 +#define TEST_SHIFT32_MASK (CHAR_BIT * sizeof(uint32_t) - 1) +#define TEST_SHIFT64_MASK (CHAR_BIT * sizeof(uint64_t) - 1) + #define TEST_JCC_1 0 #define TEST_JCC_2 -123 #define TEST_JCC_3 5678 @@ -548,15 +551,25 @@ static const struct ebpf_insn test_shift1_prog[] = { .off = offsetof(struct dummy_vect8, out[1].u64), }, { - .code = (BPF_ALU | BPF_RSH | BPF_X), - .dst_reg = EBPF_REG_2, - .src_reg = EBPF_REG_4, + .code = (BPF_ALU | BPF_AND | BPF_K), + .dst_reg = EBPF_REG_4, + .imm = TEST_SHIFT64_MASK, }, { .code = (EBPF_ALU64 | BPF_LSH | BPF_X), .dst_reg = EBPF_REG_3, .src_reg = EBPF_REG_4, }, + { + .code = (BPF_ALU | BPF_AND | BPF_K), + .dst_reg = EBPF_REG_4, + .imm = TEST_SHIFT32_MASK, + }, + { + .code = (BPF_ALU | BPF_RSH | BPF_X), + .dst_reg = EBPF_REG_2, + .src_reg = EBPF_REG_4, + }, { .code = (BPF_STX | BPF_MEM | EBPF_DW), .dst_reg = EBPF_REG_1, @@ -590,7 +603,7 @@ static const struct ebpf_insn test_shift1_prog[] = { { .code = (BPF_ALU | BPF_AND | BPF_K), .dst_reg = EBPF_REG_2, - .imm = sizeof(uint64_t) * CHAR_BIT - 1, + .imm = TEST_SHIFT64_MASK, }, { .code = (EBPF_ALU64 | EBPF_ARSH | BPF_X), @@ -600,7 +613,7 @@ static const struct ebpf_insn test_shift1_prog[] = { { .code = (BPF_ALU | BPF_AND | BPF_K), .dst_reg = EBPF_REG_2, - .imm = sizeof(uint32_t) * CHAR_BIT - 1, + .imm = TEST_SHIFT32_MASK, }, { .code = (BPF_ALU | BPF_LSH | BPF_X), @@ -666,8 +679,10 @@ test_shift1_check(uint64_t rc, const void *arg) dve.out[0].u64 = r2; dve.out[1].u64 = r3; - r2 = (uint32_t)r2 >> r4; + r4 &= TEST_SHIFT64_MASK; r3 <<= r4; + r4 &= TEST_SHIFT32_MASK; + r2 = (uint32_t)r2 >> r4; dve.out[2].u64 = r2; dve.out[3].u64 = r3; @@ -676,9 +691,9 @@ test_shift1_check(uint64_t rc, const void *arg) r3 = dvt->in[1].u64; r4 = dvt->in[2].u32; - r2 &= sizeof(uint64_t) * CHAR_BIT - 1; + r2 &= TEST_SHIFT64_MASK; r3 = (int64_t)r3 >> r2; - r2 &= sizeof(uint32_t) * CHAR_BIT - 1; + r2 &= TEST_SHIFT32_MASK; r4 = (uint32_t)r4 << r2; dve.out[4].u64 = r4; -- 2.33.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-11-10 14:17:07.765826756 +0800 +++ 0131-test-bpf-fix-undefined-behavior-with-clang.patch 2021-11-10 14:17:01.894079233 +0800 @@ -1 +1 @@ -From 3ac2dffae88e8eb5c374b1fdd40d605014526510 Mon Sep 17 00:00:00 2001 +From 9f78abfa183b2b85f21d55d9684aed32b4f6ac54 Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit 3ac2dffae88e8eb5c374b1fdd40d605014526510 ] @@ -26 +28,0 @@ -Cc: stable@dpdk.org @@ -36 +38 @@ -index 8118a1849b..7fcf92e716 100644 +index 527c06b807..7002c6a734 100644