From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 62484A10DA for ; Wed, 31 Jul 2019 15:06:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5D3E01C199; Wed, 31 Jul 2019 15:06:30 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 140BC1C192 for ; Wed, 31 Jul 2019 15:06:27 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D0B33091753; Wed, 31 Jul 2019 13:06:24 +0000 (UTC) Received: from dhcp-25.97.bos.redhat.com (unknown [10.18.25.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E56DD60BF7; Wed, 31 Jul 2019 13:06:23 +0000 (UTC) From: Aaron Conole To: "Ananyev\, Konstantin" Cc: "dev\@dpdk.org" , "De Lara Guarch\, Pablo" References: <20190730213920.17225-1-aconole@redhat.com> <2601191342CEEE43887BDE71AB9772580168A5FE40@irsmsx105.ger.corp.intel.com> Date: Wed, 31 Jul 2019 09:06:23 -0400 In-Reply-To: <2601191342CEEE43887BDE71AB9772580168A5FE40@irsmsx105.ger.corp.intel.com> (Konstantin Ananyev's message of "Wed, 31 Jul 2019 08:16:38 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 31 Jul 2019 13:06:24 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH] librte_acl: fix undefined behavior X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" "Ananyev, Konstantin" writes: > Hi Aaron, > >> >> Left-shift of an integer constant is represented as 'int' type, but a left >> shift of 1 by 31 bits in 'int' is undefined. Use the U suffix to force >> a representation as unsigned. >> >> Caught while running with ubsan under gcc. >> >> Fixes: dc276b5780c2 ("acl: new library") >> Cc: Konstantin Ananyev >> Signed-off-by: Aaron Conole >> --- >> I could have changed the sizeof(bits_t) * 8 in the bitset.bits as well during >> the cleanup, but chose not to to keep the change minimal. > > But it seems that you did change it in some places: > >> - 1 << (n % (sizeof(bits_t) * 8)); >> + 1U << (n % (sizeof(bits_t) * CHAR_BIT)); > > While in others kept unchanged: >> - (1 << (n % (sizeof(bits_t) * 8)))) { >> + (1U << (n % (sizeof(bits_t) * 8)))) { > > Was that intended? Oops - nope. I'll respin. > Konstantin > >> >> lib/librte_acl/acl_bld.c | 6 +++--- >> lib/librte_acl/acl_gen.c | 4 ++-- >> 2 files changed, 5 insertions(+), 5 deletions(-) >> >> diff --git a/lib/librte_acl/acl_bld.c b/lib/librte_acl/acl_bld.c >> index b82191f42..9d27c0a5a 100644 >> --- a/lib/librte_acl/acl_bld.c >> +++ b/lib/librte_acl/acl_bld.c >> @@ -320,7 +320,7 @@ acl_add_ptr_range(struct acl_build_context *context, >> for (n = 0; n < UINT8_MAX + 1; n++) >> if (n >= low && n <= high) >> bitset.bits[n / (sizeof(bits_t) * 8)] |= >> - 1 << (n % (sizeof(bits_t) * 8)); >> + 1U << (n % (sizeof(bits_t) * CHAR_BIT)); >> >> return acl_add_ptr(context, root, node, &bitset); >> } >> @@ -343,7 +343,7 @@ acl_gen_mask(struct rte_acl_bitset *bitset, uint32_t value, uint32_t mask) >> if ((n & mask) == value) { >> range++; >> bitset->bits[n / (sizeof(bits_t) * 8)] |= >> - 1 << (n % (sizeof(bits_t) * 8)); >> + 1U << (n % (sizeof(bits_t) * CHAR_BIT)); >> } >> } >> return range; >> @@ -972,7 +972,7 @@ build_trie(struct acl_build_context *context, struct rte_acl_build_rule *head, >> sizeof(*end->mrt)); >> >> for (m = context->cfg.num_categories; 0 != m--; ) { >> - if (rule->f->data.category_mask & (1 << m)) { >> + if (rule->f->data.category_mask & (1U << m)) { >> end->mrt->results[m] = rule->f->data.userdata; >> end->mrt->priority[m] = rule->f->data.priority; >> } else { >> diff --git a/lib/librte_acl/acl_gen.c b/lib/librte_acl/acl_gen.c >> index 35a0140b4..81dec3aa6 100644 >> --- a/lib/librte_acl/acl_gen.c >> +++ b/lib/librte_acl/acl_gen.c >> @@ -133,7 +133,7 @@ acl_node_fill_dfa(const struct rte_acl_node *node, >> for (n = 0; n < RTE_ACL_DFA_SIZE; n++) { >> >> if (bits->bits[n / (sizeof(bits_t) * CHAR_BIT)] & >> - (1 << (n % (sizeof(bits_t) * CHAR_BIT)))) { >> + (1U << (n % (sizeof(bits_t) * CHAR_BIT)))) { >> >> dfa[n] = resolved ? child->node_index : x; >> ranges += (last_bit == 0); >> @@ -175,7 +175,7 @@ acl_count_sequential_groups(struct rte_acl_bitset *bits, int zero_one) >> } >> for (n = 0; n < QRANGE_MIN; n++) { >> if (bits->bits[n / (sizeof(bits_t) * 8)] & >> - (1 << (n % (sizeof(bits_t) * 8)))) { >> + (1U << (n % (sizeof(bits_t) * 8)))) { >> if (zero_one == 1 && last_bit != 1) >> ranges++; >> last_bit = 1; >> -- > > > >> 2.21.0