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 0F9ABA0C41 for ; Tue, 30 Nov 2021 17:39:44 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0895241190; Tue, 30 Nov 2021 17:39:44 +0100 (CET) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by mails.dpdk.org (Postfix) with ESMTP id 04E5241186 for ; Tue, 30 Nov 2021 17:39:43 +0100 (CET) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 984A33F1ED for ; Tue, 30 Nov 2021 16:39:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1638290382; bh=+MuxIbhr0euWATWXFAm39FfstJ5b2g25Cd9o6PzPfNE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AzA18WNcqKbBGIxSy8neK60fUcEpEp0/VeQ37+Bp6p+lQOlCVf/M8yCd03msz9nPh pXT7VrL94n1CpVgG3xegeXqab5/WV70cdtqMHU6jjF1bXNIvlqkMyAA0sbsEKVAIME 3AXujOchbaWEuiwHUeIyBpuasew+51Q3IKwMRgMTH7AfaxnF96TD6MBqFPwQM1gt4W XvxTLOP3QivX9lUIMBrsTaE3vWC+9n0nwDm07fXQJSBU3Km7Gi7ztxUAuc0ngmkibN xDWxaodCUVZ4Ljg0NbmNsaw30I0TTqUheVJhfoexAT1tW2a5fzmoic8fDKFaD7fRYZ 291yoALW3xSdw== Received: by mail-ed1-f69.google.com with SMTP id p4-20020aa7d304000000b003e7ef120a37so17401439edq.16 for ; Tue, 30 Nov 2021 08:39:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+MuxIbhr0euWATWXFAm39FfstJ5b2g25Cd9o6PzPfNE=; b=YyCDWXoYi22Rx1FEBIyTwGDZCPZ/NFgZBq4QRZHkDT+xU3Px2bifBrSIit4s2ceh1I ww/znjyLISXrYMmQ4IzfYjxqxC2PQYZ90bJvWy46dsvfT89cueC7tqNY0l3qFB5AjTEU y+eIiHgCLIE52TsKpfgU2GpurUd6HLTDoK7y7UzM5BGZB+wmQniRsj0AWbeF9xfX1DMX HWQ5Xi82B+9aaZDfRu+v4SU1aQ+v9ez74Kc0FItd+ogF6T6RwWBaCvupaBwryTRjN9h+ 8sbI/U69T1xM0z7/5wkj+4gI5ezF1KEmK/8MnaesAVvw9Wjfo+H3Zwp0la3GFzUSh86c 5FSg== X-Gm-Message-State: AOAM530McZUcmfwXr56F3lRYu7zXtJKRWEnThTs1RVXZj6tBuerPDsuv XDEQsGND1SKIFU64Aq4UjGs4JgzSz10fH6PvTJH1eqVZ9tQzy+QfRvmdVj8+ob7IpDQFvxzpPTb Rci08O90Z3xa0uR6lMqY/6/Gj X-Received: by 2002:a17:906:5d0b:: with SMTP id g11mr272980ejt.110.1638290381096; Tue, 30 Nov 2021 08:39:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/G8C/mNbpwnf4SdRMOl4tuyON7gKLqBRv3rKyudQnBb2nwBnwX7MqfuDwCj3n7b0oQgSBCA== X-Received: by 2002:a17:906:5d0b:: with SMTP id g11mr272960ejt.110.1638290380937; Tue, 30 Nov 2021 08:39:40 -0800 (PST) Received: from localhost.localdomain ([2001:67c:1560:8007::aac:c4ad]) by smtp.gmail.com with ESMTPSA id cs12sm9456701ejc.15.2021.11.30.08.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 08:39:40 -0800 (PST) From: christian.ehrhardt@canonical.com To: Konstantin Ananyev Cc: Stephen Hemminger , dpdk stable Subject: patch 'test/bpf: fix undefined behavior with clang' has been queued to stable release 19.11.11 Date: Tue, 30 Nov 2021 17:34:34 +0100 Message-Id: <20211130163605.2460997-70-christian.ehrhardt@canonical.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211130163605.2460997-1-christian.ehrhardt@canonical.com> References: <20211130163605.2460997-1-christian.ehrhardt@canonical.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 19.11.11 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before December 10th 2021. 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/cpaelzer/dpdk-stable-queue This queued commit can be viewed at: https://github.com/cpaelzer/dpdk-stable-queue/commit/0f30d115c5cdec4b1dbdda29fedf07a77d3565fd Thanks. Christian Ehrhardt --- >From 0f30d115c5cdec4b1dbdda29fedf07a77d3565fd 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 [ 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 88048b4644..533d8ba878 100644 --- a/app/test/test_bpf.c +++ b/app/test/test_bpf.c @@ -51,6 +51,9 @@ struct dummy_net { #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 @@ -540,15 +543,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, @@ -582,7 +595,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), @@ -592,7 +605,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), @@ -658,8 +671,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; @@ -668,9 +683,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.34.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-11-30 16:50:10.003580557 +0100 +++ 0070-test-bpf-fix-undefined-behavior-with-clang.patch 2021-11-30 16:50:05.746873207 +0100 @@ -1 +1 @@ -From 3ac2dffae88e8eb5c374b1fdd40d605014526510 Mon Sep 17 00:00:00 2001 +From 0f30d115c5cdec4b1dbdda29fedf07a77d3565fd Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 3ac2dffae88e8eb5c374b1fdd40d605014526510 ] + @@ -26 +27,0 @@ -Cc: stable@dpdk.org @@ -36 +37 @@ -index 8118a1849b..7fcf92e716 100644 +index 88048b4644..533d8ba878 100644 @@ -39 +40 @@ -@@ -59,6 +59,9 @@ struct dummy_mbuf { +@@ -51,6 +51,9 @@ struct dummy_net { @@ -49 +50 @@ -@@ -548,15 +551,25 @@ static const struct ebpf_insn test_shift1_prog[] = { +@@ -540,15 +543,25 @@ static const struct ebpf_insn test_shift1_prog[] = { @@ -78 +79 @@ -@@ -590,7 +603,7 @@ static const struct ebpf_insn test_shift1_prog[] = { +@@ -582,7 +595,7 @@ static const struct ebpf_insn test_shift1_prog[] = { @@ -87 +88 @@ -@@ -600,7 +613,7 @@ static const struct ebpf_insn test_shift1_prog[] = { +@@ -592,7 +605,7 @@ static const struct ebpf_insn test_shift1_prog[] = { @@ -96 +97 @@ -@@ -666,8 +679,10 @@ test_shift1_check(uint64_t rc, const void *arg) +@@ -658,8 +671,10 @@ test_shift1_check(uint64_t rc, const void *arg) @@ -108 +109 @@ -@@ -676,9 +691,9 @@ test_shift1_check(uint64_t rc, const void *arg) +@@ -668,9 +683,9 @@ test_shift1_check(uint64_t rc, const void *arg)