[Git][ghc/ghc][wip/tsan/codegen] 45 commits: hadrian: Don't enable TSAN in stage0 build

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Wed Nov 16 22:44:55 UTC 2022



Ben Gamari pushed to branch wip/tsan/codegen at Glasgow Haskell Compiler / GHC


Commits:
e839abb6 by Ben Gamari at 2022-11-16T17:08:38-05:00
hadrian: Don't enable TSAN in stage0 build

- - - - -
3ca8bb7a by Ben Gamari at 2022-11-16T17:08:38-05:00
cmm: Introduce blockConcat

- - - - -
58d2d74c by Ben Gamari at 2022-11-16T17:08:38-05:00
cmm: Introduce MemoryOrderings

- - - - -
ef24ec56 by Ben Gamari at 2022-11-16T17:08:38-05:00
llvm: Respect memory specified orderings

- - - - -
089f0d86 by Ben Gamari at 2022-11-16T17:08:38-05:00
Codegen/x86: Eliminate barrier for relaxed accesses

- - - - -
ea01de8c by Ben Gamari at 2022-11-16T17:08:38-05:00
cmm/Parser: Reduce some repetition

- - - - -
72725c98 by Ben Gamari at 2022-11-16T17:08:38-05:00
cmm/Parser: Add syntax for ordered loads and stores

- - - - -
dbd94631 by Ben Gamari at 2022-11-16T17:08:38-05:00
cmm/Parser: Atomic load syntax

Originally I had thought I would just use the `prim` call syntax instead
of introducing new syntax for atomic loads. However, it turns out that
`prim` call syntax tends to make things quite unreadable. This new
syntax seems quite natural.

- - - - -
c6e6af3a by Ben Gamari at 2022-11-16T17:08:38-05:00
codeGen: Introduce ThreadSanitizer instrumentation

This introduces a new Cmm pass which instruments the program with
ThreadSanitizer annotations, allowing full tracking of mutator memory
accesses via TSAN.

- - - - -
2a6f0f02 by Ben Gamari at 2022-11-16T17:08:38-05:00
rts/Messages: Refactor

This doesn't change behavior but makes the code a bit easier to follow.

- - - - -
43ab8ba9 by Ben Gamari at 2022-11-16T17:08:38-05:00
rts/ThreadPaused: Ordering fixes

- - - - -
24418107 by Ben Gamari at 2022-11-16T17:08:38-05:00
eventlog: Silence spurious data race

- - - - -
ca5063ee by Ben Gamari at 2022-11-16T17:08:38-05:00
Introduce SET_INFO_RELEASE for Cmm

- - - - -
60dbb1bd by Ben Gamari at 2022-11-16T17:08:38-05:00
rts: Use fences instead of explicit barriers

- - - - -
5e65cf83 by Ben Gamari at 2022-11-16T17:39:37-05:00
rts/stm: Fix memory ordering in readTVarIO#

See #22421.

- - - - -
17e624d8 by Ben Gamari at 2022-11-16T17:39:37-05:00
Improve heap memory barrier Note

Also introduce MUT_FIELD marker in Closures.h to document mutable
fields.

- - - - -
fe7b6f7a by Ben Gamari at 2022-11-16T17:39:37-05:00
rts: Introduce getNumCapabilities

And ensure accesses to n_capabilities are atomic (although with relaxed
ordering). This is necessary as RTS API callers may concurrently call
into the RTS without holding a capability.

- - - - -
d3993ba8 by Ben Gamari at 2022-11-16T17:39:37-05:00
ghc: Fix data race in dump file handling

Previously the dump filename cache would use a non-atomic update which
could potentially result in lost dump contents. Note that this is still
a bit racy since the first writer may lag behind a later appending
writer.

- - - - -
dd908652 by Ben Gamari at 2022-11-16T17:39:37-05:00
rts: Always use atomics for context_switch and interrupt

Since these are modified by the timer handler.

- - - - -
dbc2e558 by Ben Gamari at 2022-11-16T17:39:37-05:00
rts/Timer: Always use atomic operations

As noted in #22447, the existence of the pthread-based ITimer
implementation means that we cannot assume that the program is
single-threaded.

- - - - -
cf42b09c by Ben Gamari at 2022-11-16T17:39:37-05:00
rts: Encapsulate recent_activity access

This makes it easier to ensure that it is accessed using the necessary
atomic operations.

- - - - -
39f4a61f by Ben Gamari at 2022-11-16T17:39:37-05:00
rts: Encapsulate access to capabilities array

- - - - -
87ba7497 by Ben Gamari at 2022-11-16T17:39:37-05:00
rts: Encapsulate sched_state

- - - - -
c0ac62ed by Ben Gamari at 2022-11-16T17:39:38-05:00
PrimOps: Fix benign MutVar race

Relaxed ordering is fine here since the later CAS implies a release.

- - - - -
918e3daf by Ben Gamari at 2022-11-16T17:39:38-05:00
rts: Style fix

- - - - -
5584fad7 by Ben Gamari at 2022-11-16T17:39:38-05:00
compiler: Use release store in eager blackholing

- - - - -
ddd872b2 by Ben Gamari at 2022-11-16T17:39:38-05:00
rts: Fix ordering of makeStableName

- - - - -
5731870f by Ben Gamari at 2022-11-16T17:39:38-05:00
rts: Use ordered accesses instead of explicit barriers

- - - - -
b957cd5f by Ben Gamari at 2022-11-16T17:39:38-05:00
rts: Statically allocate capabilities

This is a rather simplistic way of solving #17289.

- - - - -
67705eec by Ben Gamari at 2022-11-16T17:39:38-05:00
rts: Ensure that all accesses to pending_sync are atomic

- - - - -
50bdeadb by Ben Gamari at 2022-11-16T17:39:38-05:00
compiler: Ensure that MutVar operations have necessary barriers

- - - - -
ec56105d by Ben Gamari at 2022-11-16T17:39:38-05:00
rts: Note race with wakeBlockingQueue

- - - - -
87e74342 by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Fix race in marking of blackholes

We must use an acquire-fence when marking to ensure that the indirectee
is visible.

- - - - -
681af9fc by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Fix segment list races

- - - - -
b2b13e9d by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Use atomic when looking at bd->gen

Since it may have been mutated by a moving GC.

- - - - -
3b433a7b by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Eliminate race in bump_static_flag

To ensure that we don't race with a mutator entering a new CAF we take
the SM mutex before touching static_flag. The other option here would be
to instead modify newCAF to use a CAS but the present approach is a bit
safer.

- - - - -
cb386ac6 by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Ensure that mutable fields have acquire barrier

- - - - -
9abeb112 by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Fix races in collector status tracking

Mark a number of accesses to do with tracking of the status of the
concurrent collection thread as atomic. No interesting races here,
merely necessary to satisfy TSAN.

- - - - -
9cd94164 by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Make segment state updates atomic

- - - - -
60083bbf by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Refactor update remembered set initialization

This avoids a lock inversion between the storage manager mutex and
the stable pointer table mutex by not dropping the SM_MUTEX in
nonmovingCollect. This requires quite a bit of rejiggering but it
does seem like a better strategy.

- - - - -
58ac86fc by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Ensure that we aren't holding locks when closing them

TSAN complains about this sort of thing.

- - - - -
da29b015 by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Make bitmap accesses atomic

This is a benign race on any sensible hard since these are byte
accesses. Nevertheless, atomic accesses are necessary to satisfy
TSAN.

- - - - -
0afcbd34 by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Fix benign race in update remembered set check

Relaxed load is fine here since we will take the lock before looking at
the list.

- - - - -
047ef945 by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Fix race in shortcutting

We must use an acquire load to read the info table pointer since if we
find an indirection we must be certain that we see the indirectee.

- - - - -
7bca0b3f by Ben Gamari at 2022-11-16T17:39:38-05:00
nonmoving: Make free list counter accesses atomic

Since these may race with the allocator(s).

- - - - -


30 changed files:

- compiler/GHC/Cmm/Config.hs
- compiler/GHC/Cmm/ContFlowOpt.hs
- compiler/GHC/Cmm/Dataflow/Block.hs
- compiler/GHC/Cmm/Lexer.x
- compiler/GHC/Cmm/MachOp.hs
- compiler/GHC/Cmm/Parser.y
- compiler/GHC/Cmm/Pipeline.hs
- + compiler/GHC/Cmm/ThreadSanitizer.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/PPC/CodeGen.hs
- compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToC.hs
- compiler/GHC/CmmToLlvm/CodeGen.hs
- compiler/GHC/Driver/Config/Cmm.hs
- compiler/GHC/Driver/Flags.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/StgToCmm/Bind.hs
- compiler/GHC/StgToCmm/ExtCode.hs
- compiler/GHC/StgToCmm/Prim.hs
- compiler/GHC/Utils/Logger.hs
- compiler/ghc.cabal.in
- docs/users_guide/debugging.rst
- hadrian/src/Flavour.hs
- rts/Apply.cmm
- rts/Capability.c
- rts/Capability.h
- rts/HeapStackCheck.cmm
- rts/IOManager.c
- rts/Messages.c


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fce117dc80369a6f7d4155c290cb764064ebb040...7bca0b3f9911ffdd5a349887b00f553451b9cd73

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fce117dc80369a6f7d4155c290cb764064ebb040...7bca0b3f9911ffdd5a349887b00f553451b9cd73
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/20221116/971c155f/attachment-0001.html>


More information about the ghc-commits mailing list