[PATCH] rte_memcpy: fix off by one for size 16 and 32
Mattias Rönnblom
hofors at lysator.liu.se
Sun Mar 3 07:47:42 CET 2024
On 2024-03-02 21:49, Stephen Hemminger wrote:
> The rte_memcpy code would do extra instructions for size 16
> and 32 which potentially could reference past end of data.
>
> For size of 16, only single mov16 is needed.
> same for size of 32, only single mov32.
>
> Fixes: f5472703c0bd ("eal: optimize aligned memcpy on x86")
> Fixes: d35cc1fe6a7a ("eal/x86: revert select optimized memcpy at run-time")
>
> Suggested-by: Morten Brørup <mb at smartsharesystems.com>
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---
> lib/eal/x86/include/rte_memcpy.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/eal/x86/include/rte_memcpy.h b/lib/eal/x86/include/rte_memcpy.h
> index 72a92290e05d..00479a4bfbe6 100644
> --- a/lib/eal/x86/include/rte_memcpy.h
> +++ b/lib/eal/x86/include/rte_memcpy.h
> @@ -233,13 +233,15 @@ rte_memcpy_generic(void *dst, const void *src, size_t n)
> */
> if (n <= 32) {
> rte_mov16((uint8_t *)dst, (const uint8_t *)src);
> - rte_mov16((uint8_t *)dst - 16 + n,
> + if (n > 16)
> + rte_mov16((uint8_t *)dst - 16 + n,
> (const uint8_t *)src - 16 + n);
> return ret;
> }
> if (n <= 64) {
> rte_mov32((uint8_t *)dst, (const uint8_t *)src);
> - rte_mov32((uint8_t *)dst - 32 + n,
> + if (n > 32)
n is always > 32 here.
> + rte_mov32((uint8_t *)dst - 32 + n,
> (const uint8_t *)src - 32 + n);
> return ret;
> }
More information about the dev
mailing list