[PATCH v3] hash: fix pointer alignment

Marat Khalili marat.khalili at huawei.com
Fri Feb 27 16:55:30 CET 2026


> -----Original Message-----
> From: Radu Nicolau <radu.nicolau at intel.com>
> Sent: Friday 27 February 2026 14:00
> To: dev at dpdk.org
> Cc: Marat Khalili <marat.khalili at huawei.com>; Radu Nicolau <radu.nicolau at intel.com>; stable at dpdk.org;
> stephen at networkplumber.org; Yipeng Wang <yipeng1.wang at intel.com>; Sameh Gobriel
> <sameh.gobriel at intel.com>; Bruce Richardson <bruce.richardson at intel.com>; Vladimir Medvedkin
> <vladimir.medvedkin at intel.com>; Yerden Zhumabekov <e_zhumabekov at sts.kz>; Pablo de Lara
> <pablo.de.lara.guarch at intel.com>
> Subject: [PATCH v3] hash: fix pointer alignment
> 
> 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.
> 
> Bugzilla ID: 1892
> Fixes: 504a29af13a7 ("hash: fix strict-aliasing for CRC")
> Cc: stable at dpdk.org
> Cc: stephen at networkplumber.org
> 
> Signed-off-by: Radu Nicolau <radu.nicolau at intel.com>
> Acked-by: Marat Khalili <marat.khalili at huawei.com>
> ---
> v3: revert alignment code to simple loop, it was getting too complex for a corner case
> 
> 
>  lib/hash/rte_hash_crc.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/lib/hash/rte_hash_crc.h b/lib/hash/rte_hash_crc.h
> index fa07c97685..f60f4598d8 100644
> --- a/lib/hash/rte_hash_crc.h
> +++ b/lib/hash/rte_hash_crc.h
> @@ -127,6 +127,16 @@ 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) {
> +		unsigned int unaligned_bytes = RTE_MIN(8 - (pd & 0x7), data_len);
> +		for (i = 0; i < unaligned_bytes; i++) {
> +			init_val = rte_hash_crc_1byte(*(const uint8_t *)pd, init_val);
> +			pd++;
> +			data_len--;
> +		}
> +	}
> +
>  	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
> 

My custom checks now pass even for small inputs.

(I also support the idea to simplify it to a single loop, until we have actual
benchmarks showing that some alternative is better. Same for many possible ways
to simplify if and/or for condition.)

Acked-by: Marat Khalili <marat.khalili at huawei.com>
Tested-by: Marat Khalili <marat.khalili at huawei.com>


More information about the stable mailing list