Package: pmdk / 1.10-2+deb11u1

0001-common-fix-missing-sfence-in-non-temporal-memcpy.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
From e67ca1ee3089d28e5945bc4a3e33ac525e313b5b Mon Sep 17 00:00:00 2001
From: Piotr Balcer <piotr.balcer@intel.com>
Date: Wed, 1 Sep 2021 14:12:49 +0200
Subject: [PATCH] common: fix missing sfence in non-temporal memcpy

The implementation of hardware fencing for non-temporal
memcpy variants is done using a function pointer. Some
of those pointers are called "barrier" which unfortunately
overlaps with a function-like macro that's used for compiler
barriers. This meant that a compiler barrier was being used
instead of a hardware store barrier.

This patch changes the compiler barrier to a static inline
function called "compiler_barrier" to avoid name conflicts.

Fixes #5292
Reported-by: @Transpeptidase
---
 src/core/util.h                                | 17 ++++++++++++++---
 src/libpmem2/x86_64/memcpy/memcpy_nt_avx.c     |  4 ++--
 src/libpmem2/x86_64/memcpy/memcpy_nt_avx512f.c |  4 ++--
 src/libpmem2/x86_64/memcpy/memcpy_nt_sse2.c    |  4 ++--
 src/libpmem2/x86_64/memset/memset_nt_avx.c     |  4 ++--
 src/libpmem2/x86_64/memset/memset_nt_avx512f.c |  4 ++--
 src/libpmem2/x86_64/memset/memset_nt_sse2.c    |  4 ++--
 7 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/src/core/util.h b/src/core/util.h
index 542047a17..1ce575dfa 100644
--- a/src/core/util.h
+++ b/src/core/util.h
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
-/* Copyright 2014-2020, Intel Corporation */
+/* Copyright 2014-2021, Intel Corporation */
 /*
  * Copyright (c) 2016-2020, Microsoft Corporation. All rights reserved.
  *
@@ -133,13 +133,24 @@ void util_set_alloc_funcs(
 #ifdef _MSC_VER
 #define force_inline inline __forceinline
 #define NORETURN __declspec(noreturn)
-#define barrier() _ReadWriteBarrier()
 #else
 #define force_inline __attribute__((always_inline)) inline
 #define NORETURN __attribute__((noreturn))
-#define barrier() asm volatile("" ::: "memory")
 #endif
 
+/*
+ * compiler_barrier -- issues a compiler barrier
+ */
+static force_inline void
+compiler_barrier(void)
+{
+#ifdef _MSC_VER
+	_ReadWriteBarrier();
+#else
+	asm volatile("" ::: "memory");
+#endif
+}
+
 #ifdef _MSC_VER
 typedef UNALIGNED uint64_t ua_uint64_t;
 typedef UNALIGNED uint32_t ua_uint32_t;
diff --git a/src/libpmem2/x86_64/memcpy/memcpy_nt_avx.c b/src/libpmem2/x86_64/memcpy/memcpy_nt_avx.c
index ff007fb3c..6311bed4f 100644
--- a/src/libpmem2/x86_64/memcpy/memcpy_nt_avx.c
+++ b/src/libpmem2/x86_64/memcpy/memcpy_nt_avx.c
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: BSD-3-Clause
-/* Copyright 2017-2020, Intel Corporation */
+/* Copyright 2017-2021, Intel Corporation */
 
 #include <immintrin.h>
 #include <stddef.h>
@@ -22,7 +22,7 @@ static force_inline void
 mm256_stream_si256(char *dest, unsigned idx, __m256i src)
 {
 	_mm256_stream_si256((__m256i *)dest + idx, src);
-	barrier();
+	compiler_barrier();
 }
 
 static force_inline void
diff --git a/src/libpmem2/x86_64/memcpy/memcpy_nt_avx512f.c b/src/libpmem2/x86_64/memcpy/memcpy_nt_avx512f.c
index fb19504e4..4a60b9cd0 100644
--- a/src/libpmem2/x86_64/memcpy/memcpy_nt_avx512f.c
+++ b/src/libpmem2/x86_64/memcpy/memcpy_nt_avx512f.c
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: BSD-3-Clause
-/* Copyright 2017-2020, Intel Corporation */
+/* Copyright 2017-2021, Intel Corporation */
 
 #include <immintrin.h>
 #include <stddef.h>
@@ -22,7 +22,7 @@ static force_inline void
 mm512_stream_si512(char *dest, unsigned idx, __m512i src)
 {
 	_mm512_stream_si512((__m512i *)dest + idx, src);
-	barrier();
+	compiler_barrier();
 }
 
 static force_inline void
diff --git a/src/libpmem2/x86_64/memcpy/memcpy_nt_sse2.c b/src/libpmem2/x86_64/memcpy/memcpy_nt_sse2.c
index b633be9da..05c5cf9bf 100644
--- a/src/libpmem2/x86_64/memcpy/memcpy_nt_sse2.c
+++ b/src/libpmem2/x86_64/memcpy/memcpy_nt_sse2.c
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: BSD-3-Clause
-/* Copyright 2017-2020, Intel Corporation */
+/* Copyright 2017-2021, Intel Corporation */
 
 #include <immintrin.h>
 #include <stddef.h>
@@ -21,7 +21,7 @@ static force_inline void
 mm_stream_si128(char *dest, unsigned idx, __m128i src)
 {
 	_mm_stream_si128((__m128i *)dest + idx, src);
-	barrier();
+	compiler_barrier();
 }
 
 static force_inline void
diff --git a/src/libpmem2/x86_64/memset/memset_nt_avx.c b/src/libpmem2/x86_64/memset/memset_nt_avx.c
index 4a4d5f6a2..4882b3c58 100644
--- a/src/libpmem2/x86_64/memset/memset_nt_avx.c
+++ b/src/libpmem2/x86_64/memset/memset_nt_avx.c
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: BSD-3-Clause
-/* Copyright 2017-2020, Intel Corporation */
+/* Copyright 2017-2021, Intel Corporation */
 
 #include <immintrin.h>
 #include <stddef.h>
@@ -17,7 +17,7 @@ static force_inline void
 mm256_stream_si256(char *dest, unsigned idx, __m256i src)
 {
 	_mm256_stream_si256((__m256i *)dest + idx, src);
-	barrier();
+	compiler_barrier();
 }
 
 static force_inline void
diff --git a/src/libpmem2/x86_64/memset/memset_nt_avx512f.c b/src/libpmem2/x86_64/memset/memset_nt_avx512f.c
index b29402a93..5db88c5aa 100644
--- a/src/libpmem2/x86_64/memset/memset_nt_avx512f.c
+++ b/src/libpmem2/x86_64/memset/memset_nt_avx512f.c
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: BSD-3-Clause
-/* Copyright 2017-2020, Intel Corporation */
+/* Copyright 2017-2021, Intel Corporation */
 
 #include <immintrin.h>
 #include <stddef.h>
@@ -18,7 +18,7 @@ static force_inline void
 mm512_stream_si512(char *dest, unsigned idx, __m512i src)
 {
 	_mm512_stream_si512((__m512i *)dest + idx, src);
-	barrier();
+	compiler_barrier();
 }
 
 static force_inline void
diff --git a/src/libpmem2/x86_64/memset/memset_nt_sse2.c b/src/libpmem2/x86_64/memset/memset_nt_sse2.c
index 5590a65f8..0793ff5be 100644
--- a/src/libpmem2/x86_64/memset/memset_nt_sse2.c
+++ b/src/libpmem2/x86_64/memset/memset_nt_sse2.c
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: BSD-3-Clause
-/* Copyright 2017-2020, Intel Corporation */
+/* Copyright 2017-2021, Intel Corporation */
 
 #include <immintrin.h>
 #include <stddef.h>
@@ -16,7 +16,7 @@ static force_inline void
 mm_stream_si128(char *dest, unsigned idx, __m128i src)
 {
 	_mm_stream_si128((__m128i *)dest + idx, src);
-	barrier();
+	compiler_barrier();
 }
 
 static force_inline void
-- 
2.33.0