Subject: [PATCH 03/12] powerpc: qspinlock: Enforce qnode writes prior to publishing to queue

From: Rohan McLure <[email-masked]>
Date: Mon, 8 May 2023 12:01:11 +1000

Use a compiler barrier to enforce that all fields of a new struct qnode
be written to (especially the lock value) before publishing the qnode to
the waitqueue.

Signed-off-by: Rohan McLure <[email-masked]>
---
 arch/powerpc/lib/qspinlock.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/lib/qspinlock.c b/arch/powerpc/lib/qspinlock.c
index 579290d55abf..d548001a86be 100644
--- a/arch/powerpc/lib/qspinlock.c
+++ b/arch/powerpc/lib/qspinlock.c
@@ -567,6 +567,10 @@ static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, b
 	node->cpu = smp_processor_id();
 	node->yield_cpu = -1;
 	node->locked = 1;
+	/*
+	 * Assign all attributes of a node before it can be published.
+	 */
+	barrier();
 
 	tail = encode_tail_cpu(node->cpu);
 
-- 
2.37.2