[Git][ghc/ghc][wip/T22965-9.2] 2 commits: rts: Statically assert alignment of Capability
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Mon Feb 13 19:32:01 UTC 2023
Ben Gamari pushed to branch wip/T22965-9.2 at Glasgow Haskell Compiler / GHC
Commits:
8e6ac03c by Ben Gamari at 2023-02-13T14:31:52-05:00
rts: Statically assert alignment of Capability
In #22965 we noticed that changes in the size of `Capability` can result
in unsound behavior due to the `align` pragma claiming an alignment
which we don't in practice observe. Avoid this by statically asserting
that the size is a multiple of the alignment.
(cherry picked from commit d5f765ce080f5f6877a32665a7b0a7c443805a84)
- - - - -
918e4d67 by Ben Gamari at 2023-02-13T14:31:54-05:00
rts: Fix alignment of Capability
- - - - -
1 changed file:
- rts/Capability.h
Changes:
=====================================
rts/Capability.h
=====================================
@@ -27,6 +27,14 @@
#include "BeginPrivate.h"
+// We never want a Capability to overlap a cache line with
+// anything else, so round it up to a cache line size:
+#if defined(s390x_HOST_ARCH)
+#define CAPABILITY_ALIGNMENT 256
+#elif !defined(mingw32_HOST_OS)
+#define CAPABILITY_ALIGNMENT 64
+#endif
+
/* N.B. This must be consistent with CapabilityPublic in RtsAPI.h */
struct Capability_ {
// State required by the STG virtual machine when running Haskell
@@ -171,15 +179,20 @@ struct Capability_ {
StgTRecChunk *free_trec_chunks;
StgTRecHeader *free_trec_headers;
uint32_t transaction_tokens;
+
+ // To ensure that size is multiple of CAPABILITY_ALIGNMENT.
+ StgWord _padding[0];
} // typedef Capability is defined in RtsAPI.h
- // We never want a Capability to overlap a cache line with anything
- // else, so round it up to a cache line size:
-#if defined(s390x_HOST_ARCH)
- ATTRIBUTE_ALIGNED(256)
-#elif !defined(mingw32_HOST_OS)
- ATTRIBUTE_ALIGNED(64)
+#if defined(CAPABILITY_ALIGNMENT)
+ ATTRIBUTE_ALIGNED(CAPABILITY_ALIGNMENT)
+#endif
+;
+
+// We allocate arrays of Capabilities therefore we must ensure that the size is
+// a multiple of the claimed alignment
+#if defined(CAPABILITY_ALIGNMENT)
+GHC_STATIC_ASSERT(sizeof(struct Capability_) % CAPABILITY_ALIGNMENT == 0, "Capability size does not match cache size");
#endif
- ;
#if defined(THREADED_RTS)
#define ASSERT_TASK_ID(task) ASSERT(task->id == osThreadId())
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c3081e42748b44441f7f888e379cd0264d82a963...918e4d672bca4db6986e9a394f2cfa787cb3c8e9
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c3081e42748b44441f7f888e379cd0264d82a963...918e4d672bca4db6986e9a394f2cfa787cb3c8e9
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230213/51e09f9c/attachment-0001.html>
More information about the ghc-commits
mailing list