[Git][ghc/ghc][wip/T22468] compiler: Ensure that MutVar operations have necessary barriers
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Mon Dec 5 23:37:49 UTC 2022
Ben Gamari pushed to branch wip/T22468 at Glasgow Haskell Compiler / GHC
Commits:
f8e8fe64 by Ben Gamari at 2022-12-05T18:37:04-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/f8e8fe6413621c5e1be7cc8de6dc58d67f6e720d
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f8e8fe6413621c5e1be7cc8de6dc58d67f6e720d
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/20221205/7331319a/attachment-0001.html>
More information about the ghc-commits
mailing list