public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
* [PATCH] hash: fix pointer alignment
@ 2026-02-26 14:22 Radu Nicolau
  2026-02-26 16:22 ` Marat Khalili
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Radu Nicolau @ 2026-02-26 14:22 UTC (permalink / raw)
  To: dev
  Cc: Radu Nicolau, stable, stephen, Yipeng Wang, Sameh Gobriel,
	Bruce Richardson, Vladimir Medvedkin, Pablo de Lara,
	Yerden Zhumabekov

rte_hash_crc assumes input pointer address is 8 byte aligned
which may not be always the case.
This fix aligns the input pointer before proceeding to process it
in 8 byte chunks.

Fixes: 504a29af13a7 ("hash: fix strict-aliasing for CRC")
Cc: stable@dpdk.org
Cc: stephen@networkplumber.org

Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
---
 lib/hash/rte_hash_crc.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/hash/rte_hash_crc.h b/lib/hash/rte_hash_crc.h
index fa07c97685..66f11fafcd 100644
--- a/lib/hash/rte_hash_crc.h
+++ b/lib/hash/rte_hash_crc.h
@@ -127,6 +127,24 @@ rte_hash_crc(const void *data, uint32_t data_len, uint32_t init_val)
 	unsigned i;
 	uintptr_t pd = (uintptr_t) data;
 
+	/* align input to 8 byte boundary if needed */
+	if ((pd & 0x7) && data_len >= 8) {
+		uintptr_t unaligned_bytes = 8 - (pd & 0x7);
+		data_len -= unaligned_bytes;
+		if (unaligned_bytes & 0x4) {
+			init_val = rte_hash_crc_4byte(*(const uint32_t *)pd, init_val);
+			pd += 4;
+		}
+		if (unaligned_bytes & 0x2) {
+			init_val = rte_hash_crc_2byte(*(const uint16_t *)pd, init_val);
+			pd += 2;
+		}
+		if (unaligned_bytes & 0x1) {
+			init_val = rte_hash_crc_1byte(*(const uint8_t *)pd, init_val);
+			pd += 1;
+		}
+	}
+
 	for (i = 0; i < data_len / 8; i++) {
 		init_val = rte_hash_crc_8byte(*(const uint64_t *)pd, init_val);
 		pd += 8;
-- 
2.52.0


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

end of thread, other threads:[~2026-03-05 12:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26 14:22 [PATCH] hash: fix pointer alignment Radu Nicolau
2026-02-26 16:22 ` Marat Khalili
2026-02-26 16:43   ` Radu Nicolau
2026-02-26 19:47     ` Bruce Richardson
2026-02-27  9:44       ` Radu Nicolau
2026-02-27  9:48 ` [PATCH v2] " Radu Nicolau
2026-02-27 12:37   ` Marat Khalili
2026-02-27 13:00     ` Radu Nicolau
2026-02-27 13:59 ` [PATCH v3] " Radu Nicolau
2026-02-27 15:55   ` Marat Khalili
2026-03-05 12:18   ` David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox