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 8ADB342D99 for ; Fri, 30 Jun 2023 19:09:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 83AC542BAC; Fri, 30 Jun 2023 19:09:39 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 8B90240EDB; Fri, 30 Jun 2023 19:09:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688144976; x=1719680976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GsYjua5r7ri6HlIuw35cI82xdCZM+acSIyPBen5XEIk=; b=ahHbfV2jQ2FosHiTnU4IKl4pY0Oe1rSwsfVSh+GPheVzkW4Utb4oXYSc psQ1+02+Hbzqf2jbj4BryrnPfpUmSZjXs2o5gPnEab13lO58vC7YZn31w h5QP+UqLlX+O53g34ss3nXavhBqRSV9ksYDHsEKerTKX+/lReFZNoiJSR 7jhTeNB9rDN0tqoGuJMRYavPrrLp4bFzju259CVa68M/cMGKraWso51MI KV6bHjcZWR33OJR2GWFb/GPjqvvUFAWF30g5vuW6+eitmbrCDAIH4uVtu 4vcluNhbiK+hcCVvGvoCHtYJWQJodub57/1S8FGhfw+olrnWhGdQzNfIW A==; X-IronPort-AV: E=McAfee;i="6600,9927,10757"; a="393168800" X-IronPort-AV: E=Sophos;i="6.01,171,1684825200"; d="scan'208";a="393168800" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2023 10:09:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10757"; a="783151842" X-IronPort-AV: E=Sophos;i="6.01,171,1684825200"; d="scan'208";a="783151842" Received: from silpixa00401176.ir.intel.com (HELO silpixa00401176.ger.corp.intel.com) ([10.237.222.204]) by fmsmga008.fm.intel.com with ESMTP; 30 Jun 2023 10:09:29 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.v.ananyev@yandex.ru, stable@dpdk.org Subject: [PATCH v2 1/2] hash: fix reading unaligned bits implementation Date: Fri, 30 Jun 2023 17:09:26 +0000 Message-Id: <20230630170927.32829-1-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230628191219.78753-1-vladimir.medvedkin@intel.com> References: <20230628191219.78753-1-vladimir.medvedkin@intel.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 Fixes: 28ebff11c2dc ("hash: add predictable RSS") Cc: stable@dpdk.org Acked-by: Konstantin Ananyev Tested-by: Konstantin Ananyev 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 */ -- 2.25.1