Add missing barriers to Bakery Locks
With the current implementation, it's possible for a contender to
observe accesses in the Critical Section before acquiring or releasing
the lock. Insert fencing in the locking and release codes to prevent any
reorder.
Fixes ARM-software/tf-issues#609
Change-Id: I773b82aa41dd544a2d3dbacb9a4b42c9eb767bbb
Signed-off-by: Jeenu Viswambharan <jeenu.viswambharan@arm.com>
diff --git a/lib/locks/bakery/bakery_lock_normal.c b/lib/locks/bakery/bakery_lock_normal.c
index 630226a..b947da9 100644
--- a/lib/locks/bakery/bakery_lock_normal.c
+++ b/lib/locks/bakery/bakery_lock_normal.c
@@ -204,7 +204,12 @@
== bakery_ticket_number(their_bakery_info->lock_data));
}
}
- /* Lock acquired */
+
+ /*
+ * Lock acquired. Ensure that any reads from a shared resource in the
+ * critical section read values after the lock is acquired.
+ */
+ dmbld();
}
void bakery_lock_release(bakery_lock_t *lock)
@@ -220,6 +225,12 @@
assert(is_lock_acquired(my_bakery_info, is_cached));
+ /*
+ * Ensure that other observers see any stores in the critical section
+ * before releasing the lock. Release the lock by resetting ticket.
+ * Then signal other waiting contenders.
+ */
+ dmbst();
my_bakery_info->lock_data = 0;
write_cache_op(my_bakery_info, is_cached);
sev();