[Git][ghc/ghc][master] compiler: Ensure that MutVar operations have necessary barriers

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Thu Dec 15 08:55:42 UTC 2022



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
552b7908 by Ben Gamari at 2022-12-15T03:55:15-05:00
compiler: Ensure that MutVar operations have necessary barriers

Here we add acquire and release barriers in readMutVar# and
writeMutVar#, which are necessary for soundness.

Fixes #22468.

- - - - -


1 changed file:

- compiler/GHC/StgToCmm/Prim.hs


Changes:

=====================================
compiler/GHC/StgToCmm/Prim.hs
=====================================
@@ -283,9 +283,10 @@ emitPrimOp cfg primop =
     emitAssign (CmmLocal res) currentTSOExpr
 
   ReadMutVarOp -> \[mutv] -> opIntoRegs $ \[res] ->
-    emitAssign (CmmLocal res) (cmmLoadIndexW platform mutv (fixedHdrSizeW profile) (gcWord platform))
+    emitPrimCall [res] (MO_AtomicRead (wordWidth platform) MemOrderAcquire)
+        [ cmmOffsetW platform mutv (fixedHdrSizeW profile) ]
 
-  WriteMutVarOp -> \[mutv, var] -> opIntoRegs $ \res@[] -> do
+  WriteMutVarOp -> \[mutv, var] -> opIntoRegs $ \[] -> do
     old_val <- CmmLocal <$> newTemp (cmmExprType platform var)
     emitAssign old_val (cmmLoadIndexW platform mutv (fixedHdrSizeW profile) (gcWord platform))
 
@@ -294,8 +295,8 @@ emitPrimOp cfg primop =
     -- Note that this also must come after we read the old value to ensure
     -- that the read of old_val comes before another core's write to the
     -- MutVar's value.
-    emitPrimCall res MO_WriteBarrier []
-    emitStore (cmmOffsetW platform mutv (fixedHdrSizeW profile)) var
+    emitPrimCall [] (MO_AtomicWrite (wordWidth platform) MemOrderRelease)
+        [ cmmOffsetW platform mutv (fixedHdrSizeW profile), var ]
 
     platform <- getPlatform
     mkdirtyMutVarCCall <- getCode $! emitCCall



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/552b7908d8703e9478cee418721b311e033391dc

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/552b7908d8703e9478cee418721b311e033391dc
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/20221215/040ec058/attachment-0001.html>


More information about the ghc-commits mailing list