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 8F1C942D8C for ; Thu, 29 Jun 2023 13:38:26 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 81CA542B8B; Thu, 29 Jun 2023 13:38:26 +0200 (CEST) Received: from forward500c.mail.yandex.net (forward500c.mail.yandex.net [178.154.239.208]) by mails.dpdk.org (Postfix) with ESMTP id 65C5B40EDB; Thu, 29 Jun 2023 13:38:24 +0200 (CEST) Received: from mail-nwsmtp-smtp-production-main-10.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-10.sas.yp-c.yandex.net [IPv6:2a02:6b8:c14:2481:0:640:e0:0]) by forward500c.mail.yandex.net (Yandex) with ESMTP id BB2AE5EFD0; Thu, 29 Jun 2023 14:38:23 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-10.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id LcLUvs2DRW20-hbktoxTk; Thu, 29 Jun 2023 14:38:23 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1688038703; bh=X/0amWLyXBVqw7MbuWirovo56h48jHWK3taKvWkxk7g=; h=From:In-Reply-To:Cc:Date:References:To:Subject:Message-ID; b=CGH+U/anZsZV5pcZrciIXrIcMI1m53H1B9ByUgv1yI13/3RdlClHRdXdG97swWgoW Z4aoZ9AHXCHPrC9RQ+9RgezEqBF0tWUasyooMTpLSWL4DMSj4UaSvmnQKFx59eQvHp GIcYRkd/YxyMryuLKNQhqn6yM0Po9x8tJ4xNvn68= Authentication-Results: mail-nwsmtp-smtp-production-main-10.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: Date: Thu, 29 Jun 2023 12:38:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] hash: fix reading unaligned bits implementation Content-Language: en-US To: Vladimir Medvedkin , dev@dpdk.org Cc: stable@dpdk.org References: <20230628191208.78701-1-vladimir.medvedkin@intel.com> From: Konstantin Ananyev In-Reply-To: <20230628191208.78701-1-vladimir.medvedkin@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 > Fixes: 28ebff11c2dc ("hash: add predictable RSS") > Cc: stable@dpdk.org > > Signed-off-by: Vladimir Medvedkin > --- > lib/hash/rte_thash.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c > index 0249883b8d..2228af576b 100644 > --- a/lib/hash/rte_thash.c > +++ b/lib/hash/rte_thash.c > @@ -670,7 +670,7 @@ rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx) > } > > static inline uint8_t > -read_unaligned_byte(uint8_t *ptr, unsigned int len, unsigned int offset) > +read_unaligned_byte(uint8_t *ptr, unsigned int offset) > { > uint8_t ret = 0; > > @@ -681,13 +681,14 @@ read_unaligned_byte(uint8_t *ptr, unsigned int len, unsigned int offset) > (CHAR_BIT - (offset % CHAR_BIT)); > } > > - return ret >> (CHAR_BIT - len); > + return ret; > } > > static inline uint32_t > read_unaligned_bits(uint8_t *ptr, int len, int offset) > { > uint32_t ret = 0; > + int shift; > > len = RTE_MAX(len, 0); > len = RTE_MIN(len, (int)(sizeof(uint32_t) * CHAR_BIT)); > @@ -695,13 +696,14 @@ read_unaligned_bits(uint8_t *ptr, int len, int offset) > while (len > 0) { > ret <<= CHAR_BIT; > > - ret |= read_unaligned_byte(ptr, RTE_MIN(len, CHAR_BIT), > - offset); > + ret |= read_unaligned_byte(ptr, offset); > offset += CHAR_BIT; > len -= CHAR_BIT; > } > > - return ret; > + shift = (len == 0) ? 0 : > + (CHAR_BIT - ((len + CHAR_BIT) % CHAR_BIT)); > + return ret >> shift; > } > > /* returns mask for len bits with given offset inside byte */ Acked-by: Konstantin Ananyev Tested-by: Konstantin Ananyev