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 4849F45920 for ; Fri, 6 Sep 2024 19:02:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 411D442F7A; Fri, 6 Sep 2024 19:02:55 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by mails.dpdk.org (Postfix) with ESMTP id ECF1942E82; Fri, 6 Sep 2024 19:02:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725642174; x=1757178174; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5vzsJ/npVPWGQvWRYEb5rPIBMm2LrrJFUEG0+yH42bM=; b=MxgY4YZCpS2o18JZTLiwJIlffuEDqqXwcnPbW1qAyMtCYKr4l5mjY5KT uPeh5DP4SDONXDG9CfKwhI7jaPCFRV6FWAqG+9nfa0d0Y/ZuRmtnToL4Z pu5dP1Gxk2weWRWR3/AvWYNxJm+umkwz3YZnssV/nAPFRTuBJRX3kVZxh cP2nZNJQe2r2XmPPHDiT9/3XxO7ersb9lFlSCguZ0vGVRV5TGcpmv6VdE chK7HhK1RG95IWQnAvbm3+wQ6J7Dbs5BN2dePa0akfkC0m7D0aa+NLW6W iydFtelfFSeyGa0AJ2EuSDzNifO0PlR/aXvpI7uH1J2BPHzud2lmjFf6c A==; X-CSE-ConnectionGUID: B8IMTJCzT8+QHPQucU2Mpw== X-CSE-MsgGUID: RRfEdrVkT9+FCnEQwPUNbw== X-IronPort-AV: E=McAfee;i="6700,10204,11187"; a="46935709" X-IronPort-AV: E=Sophos;i="6.10,208,1719903600"; d="scan'208";a="46935709" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2024 10:02:40 -0700 X-CSE-ConnectionGUID: l8GlX1FzQJyCFGGcbiZ0cQ== X-CSE-MsgGUID: Mf5POy0aTF2Jv5kNoNSRKg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,208,1719903600"; d="scan'208";a="96793406" Received: from silpixa00401176.ir.intel.com ([10.243.22.170]) by fmviesa001.fm.intel.com with ESMTP; 06 Sep 2024 10:02:37 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: stable@dpdk.org, Yipeng Wang , Sameh Gobriel , Bruce Richardson , John McNamara Subject: [PATCH] hash: fix thash lfsr initialization Date: Fri, 6 Sep 2024 17:01:41 +0000 Message-Id: <20240906170237.1324060-1-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 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 Reverse polynomial for an LFSR was initialized improperly which could generate improper bit sequence in some situations. This patch implements proper polynomial reversing function. Fixes: 28ebff11c2dc ("hash: add predictable RSS") Cc: stable@dpdk.org Signed-off-by: Vladimir Medvedkin --- lib/hash/rte_thash.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c index 10721effe6..99a685f0c8 100644 --- a/lib/hash/rte_thash.c +++ b/lib/hash/rte_thash.c @@ -166,6 +166,30 @@ thash_get_rand_poly(uint32_t poly_degree) RTE_DIM(irreducible_poly_table[poly_degree])]; } +static inline uint32_t +get_rev_poly(uint32_t poly, int degree) +{ + int i; + /* + * The implicit highest coefficient of the polynomial + * becomes the lowest after reversal. + */ + uint32_t rev_poly = 1; + uint32_t mask = (1 << degree) - 1; + + /* + * Here we assume "poly" argument is an irreducible polynomial, + * thus the lowest coefficient of the "poly" must always be equal to "1". + * After the reversal, this the lowest coefficient becomes the highest and + * it is omitted since the highest coefficient is implicitly determined by + * degree of the polynomial. + */ + for (i = 1; i < degree; i++) + rev_poly |= ((poly >> i) & 0x1) << (degree - i); + + return rev_poly & mask; +} + static struct thash_lfsr * alloc_lfsr(struct rte_thash_ctx *ctx) { @@ -185,7 +209,7 @@ alloc_lfsr(struct rte_thash_ctx *ctx) lfsr->state = rte_rand() & ((1 << lfsr->deg) - 1); } while (lfsr->state == 0); /* init reverse order polynomial */ - lfsr->rev_poly = (lfsr->poly >> 1) | (1 << (lfsr->deg - 1)); + lfsr->rev_poly = get_rev_poly(lfsr->poly, lfsr->deg); /* init proper rev_state*/ lfsr->rev_state = lfsr->state; for (i = 0; i <= lfsr->deg; i++) -- 2.34.1