DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] hash: fix thash lfsr initialization
@ 2024-09-06 17:01 Vladimir Medvedkin
  2024-10-17  9:58 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Medvedkin @ 2024-09-06 17:01 UTC (permalink / raw)
  To: dev; +Cc: stable, Yipeng Wang, Sameh Gobriel, Bruce Richardson, John McNamara

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 <vladimir.medvedkin@intel.com>
---
 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] hash: fix thash lfsr initialization
  2024-09-06 17:01 [PATCH] hash: fix thash lfsr initialization Vladimir Medvedkin
@ 2024-10-17  9:58 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2024-10-17  9:58 UTC (permalink / raw)
  To: Vladimir Medvedkin
  Cc: dev, stable, Yipeng Wang, Sameh Gobriel, Bruce Richardson, John McNamara

06/09/2024 19:01, Vladimir Medvedkin:
> 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 <vladimir.medvedkin@intel.com>

There was no review but I assume it will be fine.

Applied, thanks.




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-17  9:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-06 17:01 [PATCH] hash: fix thash lfsr initialization Vladimir Medvedkin
2024-10-17  9:58 ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).