From: Kevin Traynor <ktraynor@redhat.com>
To: Luc Pelletier <lucp.at.work@gmail.com>
Cc: Konstantin Ananyev <konstantin.ananyev@intel.com>,
dpdk stable <stable@dpdk.org>
Subject: patch 'eal/x86: fix unaligned access for small memcpy' has been queued to stable release 21.11.2
Date: Wed, 25 May 2022 17:28:46 +0100 [thread overview]
Message-ID: <20220525162847.711753-54-ktraynor@redhat.com> (raw)
In-Reply-To: <20220525162847.711753-1-ktraynor@redhat.com>
Hi,
FYI, your patch has been queued to stable release 21.11.2
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 05/30/22. So please
shout if anyone has objections.
Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.
Queued patches are on a temporary branch at:
https://github.com/kevintraynor/dpdk-stable
This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable/commit/29fa5a6eaff312cc1163fff17ac4455c1cf63361
Thanks.
Kevin
---
From 29fa5a6eaff312cc1163fff17ac4455c1cf63361 Mon Sep 17 00:00:00 2001
From: Luc Pelletier <lucp.at.work@gmail.com>
Date: Fri, 25 Feb 2022 11:38:05 -0500
Subject: [PATCH] eal/x86: fix unaligned access for small memcpy
[ upstream commit 00901e4d1a9ee7c7b43d0a3592683f0a420a331d ]
Calls to rte_memcpy for 1 < n < 16 could result in unaligned
loads/stores, which is undefined behaviour according to the C
standard, and strict aliasing violations.
The code was changed to use a packed structure that allows aliasing
(using the __may_alias__ attribute) to perform the load/store
operations. This results in code that has the same performance as the
original code and that is also C standards-compliant.
Fixes: af75078fece3 ("first public release")
Signed-off-by: Luc Pelletier <lucp.at.work@gmail.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Tested-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
lib/eal/include/rte_common.h | 5 ++
lib/eal/x86/include/rte_memcpy.h | 133 ++++++++++++-------------------
2 files changed, 56 insertions(+), 82 deletions(-)
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index eee1ada379..6f004f6cb3 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -86,4 +86,9 @@ typedef uint16_t unaligned_uint16_t;
#define __rte_packed __attribute__((__packed__))
+/**
+ * Macro to mark a type that is not subject to type-based aliasing rules
+ */
+#define __rte_may_alias __attribute__((__may_alias__))
+
/******* Macro to mark functions and fields scheduled for removal *****/
#define __rte_deprecated __attribute__((__deprecated__))
diff --git a/lib/eal/x86/include/rte_memcpy.h b/lib/eal/x86/include/rte_memcpy.h
index 1b6c6e585f..18aa4e43a7 100644
--- a/lib/eal/x86/include/rte_memcpy.h
+++ b/lib/eal/x86/include/rte_memcpy.h
@@ -46,4 +46,50 @@ static __rte_always_inline void *
rte_memcpy(void *dst, const void *src, size_t n);
+/**
+ * Copy bytes from one location to another,
+ * locations should not overlap.
+ * Use with n <= 15.
+ */
+static __rte_always_inline void *
+rte_mov15_or_less(void *dst, const void *src, size_t n)
+{
+ /**
+ * Use the following structs to avoid violating C standard
+ * alignment requirements and to avoid strict aliasing bugs
+ */
+ struct rte_uint64_alias {
+ uint64_t val;
+ } __rte_packed __rte_may_alias;
+ struct rte_uint32_alias {
+ uint32_t val;
+ } __rte_packed __rte_may_alias;
+ struct rte_uint16_alias {
+ uint16_t val;
+ } __rte_packed __rte_may_alias;
+
+ void *ret = dst;
+ if (n & 8) {
+ ((struct rte_uint64_alias *)dst)->val =
+ ((const struct rte_uint64_alias *)src)->val;
+ src = (const uint64_t *)src + 1;
+ dst = (uint64_t *)dst + 1;
+ }
+ if (n & 4) {
+ ((struct rte_uint32_alias *)dst)->val =
+ ((const struct rte_uint32_alias *)src)->val;
+ src = (const uint32_t *)src + 1;
+ dst = (uint32_t *)dst + 1;
+ }
+ if (n & 2) {
+ ((struct rte_uint16_alias *)dst)->val =
+ ((const struct rte_uint16_alias *)src)->val;
+ src = (const uint16_t *)src + 1;
+ dst = (uint16_t *)dst + 1;
+ }
+ if (n & 1)
+ *(uint8_t *)dst = *(const uint8_t *)src;
+ return ret;
+}
+
#if defined __AVX512F__ && defined RTE_MEMCPY_AVX512
@@ -172,6 +218,4 @@ static __rte_always_inline void *
rte_memcpy_generic(void *dst, const void *src, size_t n)
{
- uintptr_t dstu = (uintptr_t)dst;
- uintptr_t srcu = (uintptr_t)src;
void *ret = dst;
size_t dstofss;
@@ -182,22 +226,5 @@ rte_memcpy_generic(void *dst, const void *src, size_t n)
*/
if (n < 16) {
- if (n & 0x01) {
- *(uint8_t *)dstu = *(const uint8_t *)srcu;
- srcu = (uintptr_t)((const uint8_t *)srcu + 1);
- dstu = (uintptr_t)((uint8_t *)dstu + 1);
- }
- if (n & 0x02) {
- *(uint16_t *)dstu = *(const uint16_t *)srcu;
- srcu = (uintptr_t)((const uint16_t *)srcu + 1);
- dstu = (uintptr_t)((uint16_t *)dstu + 1);
- }
- if (n & 0x04) {
- *(uint32_t *)dstu = *(const uint32_t *)srcu;
- srcu = (uintptr_t)((const uint32_t *)srcu + 1);
- dstu = (uintptr_t)((uint32_t *)dstu + 1);
- }
- if (n & 0x08)
- *(uint64_t *)dstu = *(const uint64_t *)srcu;
- return ret;
+ return rte_mov15_or_less(dst, src, n);
}
@@ -380,6 +407,4 @@ static __rte_always_inline void *
rte_memcpy_generic(void *dst, const void *src, size_t n)
{
- uintptr_t dstu = (uintptr_t)dst;
- uintptr_t srcu = (uintptr_t)src;
void *ret = dst;
size_t dstofss;
@@ -390,23 +415,5 @@ rte_memcpy_generic(void *dst, const void *src, size_t n)
*/
if (n < 16) {
- if (n & 0x01) {
- *(uint8_t *)dstu = *(const uint8_t *)srcu;
- srcu = (uintptr_t)((const uint8_t *)srcu + 1);
- dstu = (uintptr_t)((uint8_t *)dstu + 1);
- }
- if (n & 0x02) {
- *(uint16_t *)dstu = *(const uint16_t *)srcu;
- srcu = (uintptr_t)((const uint16_t *)srcu + 1);
- dstu = (uintptr_t)((uint16_t *)dstu + 1);
- }
- if (n & 0x04) {
- *(uint32_t *)dstu = *(const uint32_t *)srcu;
- srcu = (uintptr_t)((const uint32_t *)srcu + 1);
- dstu = (uintptr_t)((uint32_t *)dstu + 1);
- }
- if (n & 0x08) {
- *(uint64_t *)dstu = *(const uint64_t *)srcu;
- }
- return ret;
+ return rte_mov15_or_less(dst, src, n);
}
@@ -673,6 +680,4 @@ rte_memcpy_generic(void *dst, const void *src, size_t n)
{
__m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8;
- uintptr_t dstu = (uintptr_t)dst;
- uintptr_t srcu = (uintptr_t)src;
void *ret = dst;
size_t dstofss;
@@ -683,23 +688,5 @@ rte_memcpy_generic(void *dst, const void *src, size_t n)
*/
if (n < 16) {
- if (n & 0x01) {
- *(uint8_t *)dstu = *(const uint8_t *)srcu;
- srcu = (uintptr_t)((const uint8_t *)srcu + 1);
- dstu = (uintptr_t)((uint8_t *)dstu + 1);
- }
- if (n & 0x02) {
- *(uint16_t *)dstu = *(const uint16_t *)srcu;
- srcu = (uintptr_t)((const uint16_t *)srcu + 1);
- dstu = (uintptr_t)((uint16_t *)dstu + 1);
- }
- if (n & 0x04) {
- *(uint32_t *)dstu = *(const uint32_t *)srcu;
- srcu = (uintptr_t)((const uint32_t *)srcu + 1);
- dstu = (uintptr_t)((uint32_t *)dstu + 1);
- }
- if (n & 0x08) {
- *(uint64_t *)dstu = *(const uint64_t *)srcu;
- }
- return ret;
+ return rte_mov15_or_less(dst, src, n);
}
@@ -819,25 +806,7 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
void *ret = dst;
- /* Copy size <= 16 bytes */
+ /* Copy size < 16 bytes */
if (n < 16) {
- if (n & 0x01) {
- *(uint8_t *)dst = *(const uint8_t *)src;
- src = (const uint8_t *)src + 1;
- dst = (uint8_t *)dst + 1;
- }
- if (n & 0x02) {
- *(uint16_t *)dst = *(const uint16_t *)src;
- src = (const uint16_t *)src + 1;
- dst = (uint16_t *)dst + 1;
- }
- if (n & 0x04) {
- *(uint32_t *)dst = *(const uint32_t *)src;
- src = (const uint32_t *)src + 1;
- dst = (uint32_t *)dst + 1;
- }
- if (n & 0x08)
- *(uint64_t *)dst = *(const uint64_t *)src;
-
- return ret;
+ return rte_mov15_or_less(dst, src, n);
}
--
2.34.3
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2022-05-25 17:26:59.829475423 +0100
+++ 0054-eal-x86-fix-unaligned-access-for-small-memcpy.patch 2022-05-25 17:26:58.665828475 +0100
@@ -1 +1 @@
-From 00901e4d1a9ee7c7b43d0a3592683f0a420a331d Mon Sep 17 00:00:00 2001
+From 29fa5a6eaff312cc1163fff17ac4455c1cf63361 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 00901e4d1a9ee7c7b43d0a3592683f0a420a331d ]
+
@@ -16 +17,0 @@
-Cc: stable@dpdk.org
@@ -27 +28 @@
-index d56a7570c0..a96cc2a138 100644
+index eee1ada379..6f004f6cb3 100644
next prev parent reply other threads:[~2022-05-25 16:30 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-25 16:27 patch 'test/mem: disable ASan when accessing unallocated memory' " Kevin Traynor
2022-05-25 16:27 ` patch 'net/netvsc: fix hot adding multiple VF PCI devices' " Kevin Traynor
2022-05-25 16:27 ` patch 'net/nfp: remove unneeded header inclusion' " Kevin Traynor
2022-05-25 16:27 ` patch 'net/bonding: fix RSS key config with extended key length' " Kevin Traynor
2022-05-25 16:27 ` patch 'net/cxgbe: fix port ID in Rx mbuf' " Kevin Traynor
2022-05-25 16:27 ` patch 'net/cxgbe: fix Tx queue stuck with mbuf chain coalescing' " Kevin Traynor
2022-05-25 16:27 ` patch 'net/vhost: fix access to freed memory' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/virtio: restore some optimisations with AVX512' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/vhost: fix TSO feature default disablement' " Kevin Traynor
2022-05-25 16:28 ` patch 'vhost: fix missing virtqueue lock protection' " Kevin Traynor
2022-05-25 16:28 ` patch 'vdpa/mlx5: fix interrupt trash that leads to crash' " Kevin Traynor
2022-05-25 16:28 ` patch 'vdpa/mlx5: fix dead loop when process interrupted' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/dpaa: fix event queue detach' " Kevin Traynor
2022-05-25 16:28 ` patch 'doc: update matching versions in ice guide' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bonding: fix stopping non-active slaves' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bonding: fix slave stop and remove on port close' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/tap: fix interrupt handler freeing' " Kevin Traynor
2022-05-25 16:28 ` patch 'ethdev: fix build with vtune option' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/hns3: fix order of clearing imissed register in PF' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/hns3: fix MAC and queues HW statistics overflow' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/hns3: fix pseudo-sharing between threads' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/hns3: fix mbuf free on Tx done cleanup' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/hns3: fix RSS disable' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/hns3: fix rollback on RSS hash update' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/hns3: remove redundant RSS tuple field' " Kevin Traynor
2022-05-25 16:28 ` patch 'ethdev: fix RSS update when RSS is disabled' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/hns3: remove unnecessary RSS switch' " Kevin Traynor
2022-05-25 16:28 ` patch 'app/testpmd: check statistics query before printing' " Kevin Traynor
2022-05-25 16:28 ` patch 'app/testpmd: fix MTU verification' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/cnxk: add message on flow parsing failure' " Kevin Traynor
2022-05-25 16:28 ` patch 'common/cnxk: fix unaligned access to device memory' " Kevin Traynor
2022-05-25 16:28 ` patch 'common/cnxk: fix null pointer dereference' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/cnxk: fix uninitialized variables' " Kevin Traynor
2022-05-25 16:28 ` patch 'common/cnxk: fix SQ flush sequence' " Kevin Traynor
2022-05-25 16:35 ` Kevin Traynor
2022-05-25 16:28 ` patch 'net/cnxk: add barrier after meta batch free in scalar' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: fix reordering in NEON Rx' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: fix device capability reporting' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: remove unused macro' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: fix Rx configuration' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: fix RSS action' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: fix ring group on Rx restart' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: check duplicate queue IDs' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: handle queue stop during RSS flow create' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: avoid unnecessary endianness conversion' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: fix speed autonegotiation' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: force PHY update on certain configurations' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: fix link status when port is stopped' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: recheck FW readiness if in reset process' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/bnxt: fix freeing VNIC filters' " Kevin Traynor
2022-05-25 16:28 ` patch 'net/mlx5: fix no-green metering with RSS' " Kevin Traynor
2022-05-25 16:28 ` patch 'doc: fix build with sphinx 4.5' " Kevin Traynor
2022-05-25 16:28 ` patch 'eventdev/eth_rx: fix telemetry Rx stats reset' " Kevin Traynor
2022-05-25 16:28 ` patch 'event/cnxk: fix out of bounds access in test' " Kevin Traynor
2022-05-25 16:28 ` Kevin Traynor [this message]
2022-05-25 16:28 ` patch 'devargs: fix leak on hotplug failure' " Kevin Traynor
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=20220525162847.711753-54-ktraynor@redhat.com \
--to=ktraynor@redhat.com \
--cc=konstantin.ananyev@intel.com \
--cc=lucp.at.work@gmail.com \
--cc=stable@dpdk.org \
/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;
as well as URLs for NNTP newsgroup(s).