[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT/LIBCXX PATCH] Fix crash due to atomics on bare-metal arm64



At the moment atomic operations are working on ARM64 for KVM; however,
they are not working on baremetal on ARM64 (i.e., on the Raspberry Pi
3B+).  This can be most likely be solved by enabling the caches and
setting up a compatible memory configuration.  In the meantime, these
patches allow us to have functionally-equivalent non-atomic
implementations of the gcc builtins working on baremetal on ARM64.
Once the issue is fixed this workaround can be removed.

Signed-off-by: Felipe Huici <felipe.huici@xxxxxxxxx>
---
 patches/0004-Fix-arm-atomics-memory.patch | 28 +++++++++++++++++++++++
 patches/0005-Fix-arm-atomics-header.patch | 19 +++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 patches/0004-Fix-arm-atomics-memory.patch
 create mode 100644 patches/0005-Fix-arm-atomics-header.patch

diff --git a/patches/0004-Fix-arm-atomics-memory.patch 
b/patches/0004-Fix-arm-atomics-memory.patch
new file mode 100644
index 0000000..852805e
--- /dev/null
+++ b/patches/0004-Fix-arm-atomics-memory.patch
@@ -0,0 +1,28 @@
+--- a/include/memory   2020-01-28 13:27:53.843204834 +0100
++++ b/include/memory   2020-01-28 13:29:45.109925361 +0100
+@@ -675,6 +675,7 @@
+ _LIBCPP_PUSH_MACROS
+ #include <__undef_macros>
+ 
++#include <uk/arch/atomic.h>
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
+@@ -3458,7 +3459,7 @@
+ __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
+ {
+ #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && 
!defined(_LIBCPP_HAS_NO_THREADS)
+-    return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
++    return ukarch_fetch_add(&__t, 1);
+ #else
+     return __t += 1;
+ #endif
+@@ -3469,7 +3470,7 @@
+ __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
+ {
+ #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && 
!defined(_LIBCPP_HAS_NO_THREADS)
+-    return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
++  return ukarch_dec(&__t);
+ #else
+     return __t -= 1;
+ #endif
diff --git a/patches/0005-Fix-arm-atomics-header.patch 
b/patches/0005-Fix-arm-atomics-header.patch
new file mode 100644
index 0000000..75e27d2
--- /dev/null
+++ b/patches/0005-Fix-arm-atomics-header.patch
@@ -0,0 +1,19 @@
+--- a/src/include/atomic_support.h     2020-01-28 13:33:44.139173682 +0100
++++ b/src/include/atomic_support.h     2020-01-28 13:34:43.986484257 +0100
+@@ -12,6 +12,7 @@
+ 
+ #include "__config"
+ #include "memory" // for __libcpp_relaxed_load
++#include <uk/arch/atomic.h>
+ 
+ #if defined(__clang__) && __has_builtin(__atomic_load_n)             \
+                        && __has_builtin(__atomic_store_n)            \
+@@ -80,7 +81,7 @@
+ _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
+                                int __order = _AO_Seq)
+ {
+-    return __atomic_add_fetch(__val, __a, __order);
++  return ukarch_fetch_add(__val, __a);
+ }
+ 
+ template <class _ValueType>
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.