public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
From: Marat Khalili <marat.khalili@huawei.com>
To: Radu Nicolau <radu.nicolau@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: "stable@dpdk.org" <stable@dpdk.org>,
	"stephen@networkplumber.org" <stephen@networkplumber.org>,
	Yipeng Wang <yipeng1.wang@intel.com>,
	"Sameh Gobriel" <sameh.gobriel@intel.com>,
	Bruce Richardson <bruce.richardson@intel.com>,
	Vladimir Medvedkin <vladimir.medvedkin@intel.com>,
	Yerden Zhumabekov <e_zhumabekov@sts.kz>,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>
Subject: RE: [PATCH v3] hash: fix pointer alignment
Date: Fri, 27 Feb 2026 15:55:30 +0000	[thread overview]
Message-ID: <ea247161a37544bdab12060c4fe1180c@huawei.com> (raw)
In-Reply-To: <20260227140128.1083814-1-radu.nicolau@intel.com>

> -----Original Message-----
> From: Radu Nicolau <radu.nicolau@intel.com>
> Sent: Friday 27 February 2026 14:00
> To: dev@dpdk.org
> Cc: Marat Khalili <marat.khalili@huawei.com>; Radu Nicolau <radu.nicolau@intel.com>; stable@dpdk.org;
> stephen@networkplumber.org; Yipeng Wang <yipeng1.wang@intel.com>; Sameh Gobriel
> <sameh.gobriel@intel.com>; Bruce Richardson <bruce.richardson@intel.com>; Vladimir Medvedkin
> <vladimir.medvedkin@intel.com>; Yerden Zhumabekov <e_zhumabekov@sts.kz>; Pablo de Lara
> <pablo.de.lara.guarch@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@dpdk.org
> Cc: stephen@networkplumber.org
> 
> Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
> Acked-by: Marat Khalili <marat.khalili@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@huawei.com>
Tested-by: Marat Khalili <marat.khalili@huawei.com>

  reply	other threads:[~2026-02-27 15:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-03-05 12:18   ` David Marchand

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=ea247161a37544bdab12060c4fe1180c@huawei.com \
    --to=marat.khalili@huawei.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=e_zhumabekov@sts.kz \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=radu.nicolau@intel.com \
    --cc=sameh.gobriel@intel.com \
    --cc=stable@dpdk.org \
    --cc=stephen@networkplumber.org \
    --cc=vladimir.medvedkin@intel.com \
    --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