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 8E32EA034C; Fri, 25 Feb 2022 17:21:07 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EAC9141157; Fri, 25 Feb 2022 17:21:06 +0100 (CET) Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mails.dpdk.org (Postfix) with ESMTP id 5E4894068B; Fri, 25 Feb 2022 17:21:05 +0100 (CET) Received: by mail-pj1-f46.google.com with SMTP id ev16-20020a17090aead000b001bc3835fea8so5274230pjb.0; Fri, 25 Feb 2022 08:21:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=2QUEkhx04f2qqop+FqoTNFpYiyILdLGX+DTFhMD0/oE=; b=XBrtSmKp4P6g453+BNKgFjli+5XnCEV/oopBvx/iL5IR2lg1FpsRX6nV0dJp4hwUJy 3Z5crgZlOlBcktj1RBZNRUbR7yA3QWdo7X7sFitf4P7Va7h0p2wcWm8pMmIYH91dJsiN yFkQ5frD3flTPqFU8HTxzspoRy9Ddshl4TdgWJs4nqyJPc9SafkcliKFnF+d9r5P52Jl 8meSRY6Asv6y0X3Kl29idHi4TyBphtrGD4WI5FFXxts+1EhHBVAas/koXht5r12of5w5 Xs8K9VfYdacogxzfTyVG7wq5TruAD8Scx3gH6GFznJ4tgqsivy2Zr2siRvZCNlU2wHgB tbsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=2QUEkhx04f2qqop+FqoTNFpYiyILdLGX+DTFhMD0/oE=; b=dUvtc4dEpJZsWxzOwvpaVsOTOWqKlE8UQhvSXH/nRJ+GQacxnclIMFFN4KUfYo9C9+ YTdXmMxIFMEW9rI5QnDJbmil76MuaYzjGGGvLnL6R36uSRUAypM3J2rsG7OXJCQtuxQk BqASu2EaYc7oPaclDyIXhv02vMXvcldMRoZaUXIhrJtkVPnneEQ7tm+98h1H0DZTj6WS /siR7XljST1Fmx7JRnz11kYS4vLp9PIVXbz80Ya6iK+sjew8LsMqJSmb0WIaYaiWI0c/ VECRSOsxLwlT0eICttzgqFTM1QUMWW4HgDvfat4W/GEhjSwMo++A85kiCCq0K8WN8lp2 eXDA== X-Gm-Message-State: AOAM530l3VTy9qRM+h6daFg5C3pZ/FHCr4ml9A0DaZi0FCd1b1YpyWgA IvOMCLpJVZJH7iw4w6vLUCiPBAst4of7dokIojU= X-Google-Smtp-Source: ABdhPJynsB4yhoN8FmuQLSM8nfnW+HOYyxbzO3r2MsvgtmqbnKlshUooOvvV0g/FOqoI6cPXkRRyqzsfR+oCpNlZS0I= X-Received: by 2002:a17:90a:f30b:b0:1bc:3884:350f with SMTP id ca11-20020a17090af30b00b001bc3884350fmr3840843pjb.217.1645806064422; Fri, 25 Feb 2022 08:21:04 -0800 (PST) MIME-Version: 1.0 References: <20220115193836.442209-1-lucp.at.work@gmail.com> In-Reply-To: <20220115193836.442209-1-lucp.at.work@gmail.com> From: Luc Pelletier Date: Fri, 25 Feb 2022 11:20:53 -0500 Message-ID: Subject: Re: [PATCH] eal: fix unaligned loads/stores in rte_memcpy_aligned To: "Richardson, Bruce" , "Ananyev, Konstantin" Cc: dev , Xiaoyun Li , dpdk stable Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Hi, This patch can be abandoned. As indicated in another thread (http://mails.dpdk.org/archives/dev/2022-February/234889.html), there is no requirement/desire to make this change. Thanks. Le sam. 15 janv. 2022 =C3=A0 14:39, Luc Pelletier = a =C3=A9crit : > > Calls to rte_memcpy_aligned could result in unaligned loads/stores for > 1 < n < 16. This is undefined behavior according to the C standard, > and it gets flagged by the clang undefined behavior sanitizer. > > rte_memcpy_aligned is called with aligned src and dst addresses. When > n is odd, the code would copy a single byte first, increment src/dst, > then, depending on the value of n, would cast src/dst to a qword, dword > or word pointer. This results in an unaligned load/store. Reversing the > order of the casts & copies (ie. copying a qword first, dword second, > etc.) fixes the issue. > > Fixes: d35cc1fe6a7a ("eal/x86: revert select optimized memcpy at run-time= ") > Cc: Xiaoyun Li > Cc: stable@dpdk.org > > Signed-off-by: Luc Pelletier > --- > lib/eal/x86/include/rte_memcpy.h | 24 ++++++++++++------------ > 1 file changed, 12 insertions(+), 12 deletions(-) > > diff --git a/lib/eal/x86/include/rte_memcpy.h b/lib/eal/x86/include/rte_m= emcpy.h > index 1b6c6e585f..a4eb1316b6 100644 > --- a/lib/eal/x86/include/rte_memcpy.h > +++ b/lib/eal/x86/include/rte_memcpy.h > @@ -818,25 +818,25 @@ rte_memcpy_aligned(void *dst, const void *src, size= _t n) > { > void *ret =3D dst; > > - /* Copy size <=3D 16 bytes */ > + /* Copy size < 16 bytes */ > if (n < 16) { > - if (n & 0x01) { > - *(uint8_t *)dst =3D *(const uint8_t *)src; > - src =3D (const uint8_t *)src + 1; > - dst =3D (uint8_t *)dst + 1; > - } > - if (n & 0x02) { > - *(uint16_t *)dst =3D *(const uint16_t *)src; > - src =3D (const uint16_t *)src + 1; > - dst =3D (uint16_t *)dst + 1; > + if (n & 0x08) { > + *(uint64_t *)dst =3D *(const uint64_t *)src; > + src =3D (const uint64_t *)src + 1; > + dst =3D (uint64_t *)dst + 1; > } > if (n & 0x04) { > *(uint32_t *)dst =3D *(const uint32_t *)src; > src =3D (const uint32_t *)src + 1; > dst =3D (uint32_t *)dst + 1; > } > - if (n & 0x08) > - *(uint64_t *)dst =3D *(const uint64_t *)src; > + if (n & 0x02) { > + *(uint16_t *)dst =3D *(const uint16_t *)src; > + src =3D (const uint16_t *)src + 1; > + dst =3D (uint16_t *)dst + 1; > + } > + if (n & 0x01) > + *(uint8_t *)dst =3D *(const uint8_t *)src; > > return ret; > } > -- > 2.25.1 >