Revert "Improve spinlock implementation for ARMv8.0"

This reverts commit 713580c1e2a4a5b479bbe5095d8930326e6ba3d3.

Reason for revert: Frequent timeouts on QEMU.

Bug: 141087046
Change-Id: Ib1cc9b95dc77a23a1e5730024e96b73e3d63a446
diff --git a/inc/hf/spinlock.h b/inc/hf/spinlock.h
index 80d1cfc..dbd7890 100644
--- a/inc/hf/spinlock.h
+++ b/inc/hf/spinlock.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The Hafnium Authors.
+ * Copyright 2018 The Hafnium Authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,18 +16,27 @@
 
 #pragma once
 
-/*
- * Includes the arch-specific definition of 'struct spinlock' and
- * implementations of:
- *  - SPINLOCK_INIT
- *  - sl_lock()
- *  - sl_unlock()
- */
-#include "hf/arch/spinlock.h"
+#include <stdatomic.h>
+
+struct spinlock {
+	atomic_flag v;
+};
+
+#define SPINLOCK_INIT                 \
+	{                             \
+		.v = ATOMIC_FLAG_INIT \
+	}
 
 static inline void sl_init(struct spinlock *l)
 {
-	*l = SPINLOCK_INIT;
+	*l = (struct spinlock)SPINLOCK_INIT;
+}
+
+static inline void sl_lock(struct spinlock *l)
+{
+	while (atomic_flag_test_and_set_explicit(&l->v, memory_order_acquire)) {
+		/* do nothing */
+	}
 }
 
 /**
@@ -44,3 +53,8 @@
 		sl_lock(a);
 	}
 }
+
+static inline void sl_unlock(struct spinlock *l)
+{
+	atomic_flag_clear_explicit(&l->v, memory_order_release);
+}
diff --git a/src/arch/aarch64/inc/hf/arch/spinlock.h b/src/arch/aarch64/inc/hf/arch/spinlock.h
deleted file mode 100644
index 96b01c8..0000000
--- a/src/arch/aarch64/inc/hf/arch/spinlock.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2019 The Hafnium Authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-/**
- * Spinlock implementation using ARMv8.0 LDXR/STXR pair and a WFE pause.
- *
- * Implementation using C11 atomics also generates a LDXR/STXR pair but no WFE.
- * Without it we observe that Cortex A72 can easily livelock and not make
- * forward progress.
- *
- * TODO(b/141087046): Forward progress is still not guaranteed as even with WFE
- * we see that A72 can livelock for extremely tight loops. We should investigate
- * the guarantees provided by atomic instructions introduced in ARMv8.1 LSE.
- */
-
-#include <stdint.h>
-
-#include "hf/arch/types.h"
-
-struct spinlock {
-	volatile uint32_t v;
-};
-
-#define SPINLOCK_INIT ((struct spinlock){.v = 0})
-
-static inline void sl_lock(struct spinlock *l)
-{
-	register uintreg_t tmp1;
-	register uintreg_t tmp2;
-
-	/*
-	 * Acquire the lock with a LDAXR/STXR pair (acquire semantics on the
-	 * load instruction). Pause using WFE if the lock is currently taken.
-	 * This is NOT guaranteed to make progress.
-	 */
-	__asm__ volatile(
-		"	mov	%w2, #1\n"
-		"	sevl\n" /* set event bit */
-		"1:	wfe\n"  /* wait for event, clear event bit */
-		"2:	ldaxr	%w1, [%0]\n"      /* load lock value */
-		"	cbnz	%w1, 1b\n"	/* if lock taken, goto WFE */
-		"	stxr	%w1, %w2, [%0]\n" /* try to take lock */
-		"	cbnz	%w1, 2b\n"	/* loop if unsuccessful */
-		: "+r"(l), "=&r"(tmp1), "=&r"(tmp2)
-		:
-		: "cc");
-}
-
-static inline void sl_unlock(struct spinlock *l)
-{
-	/*
-	 * Store zero to lock's value with release semantics. This triggers an
-	 * event which wakes up other threads waiting on a lock (no SEV needed).
-	 */
-	__asm__ volatile("stlr wzr, [%0]" : "+r"(l)::"cc");
-}
diff --git a/src/arch/fake/inc/hf/arch/spinlock.h b/src/arch/fake/inc/hf/arch/spinlock.h
deleted file mode 100644
index db3b45c..0000000
--- a/src/arch/fake/inc/hf/arch/spinlock.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2018 The Hafnium Authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-/**
- * Generic implementation of a spinlock using C11 atomics.
- * Does not work very well under contention.
- */
-
-#include <stdatomic.h>
-
-struct spinlock {
-	atomic_flag v;
-};
-
-#define SPINLOCK_INIT ((struct spinlock){.v = ATOMIC_FLAG_INIT})
-
-static inline void sl_lock(struct spinlock *l)
-{
-	while (atomic_flag_test_and_set_explicit(&l->v, memory_order_acquire)) {
-		/* do nothing */
-	}
-}
-
-static inline void sl_unlock(struct spinlock *l)
-{
-	atomic_flag_clear_explicit(&l->v, memory_order_release);
-}