From c421bbbbf2a353858dda8f998d4997cce5977c03 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Tue, 7 Mar 2023 18:33:33 -0500 Subject: rts: Fix barriers of IND and IND_STATIC Previously IND and IND_STATIC lacked the acquire barriers enjoyed by BLACKHOLE. As noted in the (now updated) Note [Heap memory barriers], this barrier is critical to ensure that the indirectee is visible to the entering core. Fixes #22872. --- rts/StgMiscClosures.cmm | 3 +++ rts/include/stg/SMP.h | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'rts') diff --git a/rts/StgMiscClosures.cmm b/rts/StgMiscClosures.cmm index 625bfd472a..222a12e9c6 100644 --- a/rts/StgMiscClosures.cmm +++ b/rts/StgMiscClosures.cmm @@ -521,6 +521,7 @@ INFO_TABLE(stg_IND,1,0,IND,"IND","IND") (P_ node) { TICK_ENT_DYN_IND(); /* tick */ + ACQUIRE_FENCE; node = UNTAG(StgInd_indirectee(node)); TICK_ENT_VIA_NODE(); jump %GET_ENTRY(node) (node); @@ -529,6 +530,7 @@ INFO_TABLE(stg_IND,1,0,IND,"IND","IND") /* explicit stack */ { TICK_ENT_DYN_IND(); /* tick */ + ACQUIRE_FENCE; R1 = UNTAG(StgInd_indirectee(R1)); TICK_ENT_VIA_NODE(); jump %GET_ENTRY(R1) [R1]; @@ -539,6 +541,7 @@ INFO_TABLE(stg_IND_STATIC,1,0,IND_STATIC,"IND_STATIC","IND_STATIC") /* explicit stack */ { TICK_ENT_STATIC_IND(); /* tick */ + ACQUIRE_FENCE; R1 = UNTAG(StgInd_indirectee(R1)); TICK_ENT_VIA_NODE(); jump %GET_ENTRY(R1) [R1]; diff --git a/rts/include/stg/SMP.h b/rts/include/stg/SMP.h index bb30935aed..6cdbb15d14 100644 --- a/rts/include/stg/SMP.h +++ b/rts/include/stg/SMP.h @@ -214,23 +214,22 @@ EXTERN_INLINE void load_load_barrier(void); * examining a thunk being updated can see the indirectee. Consequently, a * thunk update (see rts/Updates.h) does the following: * - * 1. Use a release-fence to ensure that the indirectee is visible - * 2. Use a relaxed-store to place the new indirectee into the thunk's + * 1. Use a relaxed-store to place the new indirectee into the thunk's * indirectee field - * 3. use a release-store to set the info table to stg_BLACKHOLE (which + * 2. use a release-store to set the info table to stg_BLACKHOLE (which * represents an indirection) * * Blackholing a thunk (either eagerly, by GHC.StgToCmm.Bind.emitBlackHoleCode, * or lazily, by ThreadPaused.c:threadPaused) is done similarly. * - * Conversely, thunk entry (see the entry code of stg_BLACKHOLE in - * rts/StgMiscClosure) does the following: + * Conversely, indirection entry (see the entry code of stg_BLACKHOLE, stg_IND, + * and stg_IND_STATIC in rts/StgMiscClosure.cmm) does the following: * - * 1. We jump into the entry code for stg_BLACKHOLE; this of course implies - * that we have already read the thunk's info table pointer, which is done - * with a relaxed load. + * 1. We jump into the entry code for, e.g., stg_BLACKHOLE; this of course + * implies that we have already read the thunk's info table pointer, which + * is done with a relaxed load. * 2. use an acquire-fence to ensure that our view on the thunk is - * up-to-date. This synchronizes with step (3) in the update + * up-to-date. This synchronizes with step (2) in the update * procedure. * 3. relaxed-load the indirectee. Since thunks are updated at most * once we know that the fence in the last step has given us -- cgit v1.2.1