From: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, Yipeng Wang <yipeng1.wang@intel.com>,
Sameh Gobriel <sameh.gobriel@intel.com>,
Bruce Richardson <bruce.richardson@intel.com>,
John McNamara <john.mcnamara@intel.com>
Subject: [PATCH] hash: fix thash lfsr initialization
Date: Fri, 6 Sep 2024 17:01:41 +0000 [thread overview]
Message-ID: <20240906170237.1324060-1-vladimir.medvedkin@intel.com> (raw)
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
next reply other threads:[~2024-09-06 17:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-06 17:01 Vladimir Medvedkin [this message]
2024-10-17 9:58 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240906170237.1324060-1-vladimir.medvedkin@intel.com \
--to=vladimir.medvedkin@intel.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=john.mcnamara@intel.com \
--cc=sameh.gobriel@intel.com \
--cc=stable@dpdk.org \
--cc=yipeng1.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).