Skip to content

Commit 86e19b2

Browse files
Yangzheng BaiYangzheng Bai
authored andcommitted
Fixed dangerous return stack variable pointer bug
clh_unlock() now returns node->prev directly. Also disable wfe() for all non-aarch64 systems by default.
1 parent 8d8ed90 commit 86e19b2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

benchmarks/lockhammer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TEST_TARGETS=lh_swap_mutex \
3434
lh_jvm_objectmonitor \
3535
lh_tbb_spin_rw_mutex \
3636
lh_osq_lock \
37-
lh_clh_spinlock
37+
lh_clh_spinlock
3838

3939
ifeq ($(TARGET_ARCH),aarch64)
4040
TEST_TARGETS+=lh_hybrid_spinlock \

ext/sms/clh_spinlock.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ static __thread struct clh_node thread_clh_node;
120120
/* additional parameter to enable WFE(default) or disable WFE */
121121
static void clh_parse_args(test_args unused, int argc, char** argv) {
122122
int i = 0;
123+
#if defined(__aarch64__)
123124
without_wfe = false;
125+
#else
126+
/* only aarch64 supports WFE */
127+
without_wfe = true;
128+
#endif
124129

125130
/* extended options retrieved after '--' operator */
126131
while ((i = getopt(argc, argv, "w")) != -1)
@@ -134,7 +139,7 @@ static void clh_parse_args(test_args unused, int argc, char** argv) {
134139
fprintf(stderr,
135140
"clh_spinlock additional options after --:\n"
136141
"\t[-h print this msg]\n"
137-
"\t[-w without_wfe, default is false]\n");
142+
"\t[-w without_wfe, aarch64 default is false, non-aarch64 default is true]\n");
138143
exit(2);
139144
}
140145
}
@@ -147,7 +152,8 @@ static inline void clh_lock_init(uint64_t *u64_lock, unsigned long num_cores)
147152
global_clh_lock.node.wait = 0;
148153
global_clh_lock.tail = &global_clh_lock.node;
149154
/* save clh_lock pointer to global u64int_t */
150-
*u64_lock = (uint64_t)&global_clh_lock;
155+
*u64_lock = (uint64_t)&global_clh_lock; // unused
156+
151157
#ifdef DDEBUG
152158
printf("global_clh_lock: %llx\n", (long long unsigned int) &global_clh_lock);
153159
#endif
@@ -198,7 +204,6 @@ static inline void clh_lock(struct clh_lock *lock, struct clh_node *node, bool u
198204
/* return the previous node as reused node for the next clh_lock() */
199205
static inline struct clh_node* clh_unlock(struct clh_node *node)
200206
{
201-
struct clh_node *prev = node->prev;
202207
/* CLH spinlock: release current node by resetting wait status */
203208
#ifdef USE_DMB
204209
__atomic_thread_fence(__ATOMIC_RELEASE);
@@ -209,7 +214,7 @@ static inline struct clh_node* clh_unlock(struct clh_node *node)
209214
#ifdef DDEBUG
210215
printf("unlock/node/wait: %llx:%lu\n", (long long unsigned int)node, node->wait);
211216
#endif
212-
return prev;
217+
return node->prev;
213218
}
214219

215220
/* standard lockhammer lock_acquire and lock_release interfaces */

0 commit comments

Comments
 (0)