From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A9D5E43BF4; Sun, 3 Mar 2024 07:47:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 994F1435AE; Sun, 3 Mar 2024 07:47:45 +0100 (CET) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id B7E3142E2F for ; Sun, 3 Mar 2024 07:47:43 +0100 (CET) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 6CEA44141 for ; Sun, 3 Mar 2024 07:47:43 +0100 (CET) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 60FAA41AF; Sun, 3 Mar 2024 07:47:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED,AWL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=4.0.0 X-Spam-Score: -1.4 Received: from [192.168.1.59] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 0E2C74140; Sun, 3 Mar 2024 07:47:42 +0100 (CET) Message-ID: <5a3e4cfb-cf24-49eb-8af3-b28dc263e6b0@lysator.liu.se> Date: Sun, 3 Mar 2024 07:47:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] rte_memcpy: fix off by one for size 16 and 32 Content-Language: en-US To: Stephen Hemminger , dev@dpdk.org Cc: =?UTF-8?Q?Morten_Br=C3=B8rup?= , Bruce Richardson , Konstantin Ananyev , Zhihong Wang , Yuanhan Liu , Xiaoyun Li References: <20240302204923.227105-1-stephen@networkplumber.org> From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: <20240302204923.227105-1-stephen@networkplumber.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 > Signed-off-by: Stephen Hemminger > --- > 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; > }