[GHC] #8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Operating System: Linux Architecture: x86_64 (amd64) | Type of failure: Runtime crash Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ----------------------------------+---------------------------------- Save the following module as {{{throwto.hs}}} {{{ import Control.Concurrent import Control.Exception import Control.Monad main = do tid <- mask_ $ forkIO $ void $ (try $ threadDelay 100000 :: IO (Either SomeException ())) killThread tid }}} Then compile it with HEAD and run it: {{{ ghc-stage2 throwto.hs -prof -threaded -fforce-recomp ./throwto +RTS -N2 # segfaults }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Comment (by akio): I see many different stack traces from this program, here is one of them: {{{ Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff56fe700 (LWP 14605)] 0x00000000008382d4 in overwritingClosure (p=0x7ffff6007a38) at includes/rts/storage/ClosureMacros.h:500 500 ((StgThunk *)(p))->payload[i] = 0; (gdb) bt #0 0x00000000008382d4 in overwritingClosure (p=0x7ffff6007a38) at includes/rts/storage/ClosureMacros.h:500 #1 0x0000000000830eb4 in doneWithMsgThrowTo (m=0x7ffff6007a38) at rts/Messages.h:25 #2 0x0000000000831a52 in maybePerformBlockedException (cap=0xbbc0c0, tso=0x7ffff60079b0) at rts/RaiseAsync.c:539 #3 0x000000000083aa9f in threadPaused (cap=0xbbc0c0, tso=0x7ffff60079b0) at rts/ThreadPaused.c:209 #4 0x0000000000852dc5 in stg_returnToSchedButFirst () #5 0x0000000000000000 in ?? () }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Changes (by akio): * status: new => patch Comment: The attached patch seems to fix this. I haven't figured out how I should validate it, since a normal validate run doesn't run many tests with profiling, so I just did {{{make}}} in {{{testsuite/tests/profiling/should_run}}}. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Changes (by akio): * component: Compiler => Profiling -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Changes (by simonmar): * cc: ezyang (added) * priority: normal => highest * milestone: => 7.8.1 Comment: Just to be clear for those watching this ticket: this just affects profiling with `+RTS -N`. Here are the rules, documented next to `overwritingClosure`: * We cannot zero slop when THREADED_RTS && +RTS -N * LDV profiling requires slop-zeroing, so we cannot do LDV profiling with +RTS -N If THREADED_RTS is on, then we only get into `overwritingClosure` if `PROFILING` is on. Originally we returned immediately if (PROFILING && !LDV), but Edward removed this, basically making it so that slop is always overwritten when PROFILING is on, which breaks the first rule above. I'd like to understand more about what Edward was fixing with his patch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2
----------------------------------+----------------------------------
Reporter: akio | Owner:
Type: bug | Status: patch
Priority: highest | Milestone: 7.8.1
Component: Profiling | Version: 7.7
Resolution: | Keywords:
Operating System: Linux | Architecture: x86_64 (amd64)
Type of failure: Runtime crash | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
----------------------------------+----------------------------------
Comment (by ezyang):
Thanks for bringing this to my attention. The relevant commit was for
#7747:
{{{
commit 1ce57ec9d544beaee79aed50c4e12de144e4482f
Author: Edward Z. Yang

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Comment (by ezyang): OK, I understand what is going on here. It useful to think of the various cases that the RTS can be compiled. When the RTS is compiled as profiling and debugging, some of the sanity check code expects closures to be zeroed (specifically checkFullHeap, which explicitly looks for slop like things): {{{ /* skip over slop */ while (p < bd->free && (*p < 0x1000 || !LOOKS_LIKE_INFO_PTR(*p))) { p++; } }}} So we must zero out the slop in that case. However, when RTS is compiled as profiling and multithreaded, as Simon points out (and I didn't realize when making my patch), it's not OK to zero slop when threaded. So Akio's patch prevents the slop from zeroed in this case. Serendipitously, we already had disabled full heap checks when compiling with the threaded RTS. So I think the proper conditional here is: {{{ // It is never valid to overwrite slop when multithreaded #if defined(THREADED_RTS) return; // We need to overwrite slop when: // - We are LDV profiling // - We have a debug RTS which will do full heap checks #elif defined(PROFILING) && !DEBUG if (era <= 0) return; #endif }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Comment (by akio): Should it be allowed to use LDV profiling with {{{-threaded}}} and {{{-N1}}}? I assumed the answer was "yes", because the CPP condition that controls the definition of {{{OVERWRITING_CLOSURE}}} was {{{ #if defined(PROFILING) || (!defined(THREADED_RTS) && defined(DEBUG)) }}} which evaluates to true in {{{thr_p}}}. The only case this is useful seemed when you are doing LDV profiling with {{{-threaded}}} but with {{{-N1}}}. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Comment (by ezyang): If that's the case, then checkGeneration in rts/sm/Sanity.c should be adjusted, because it means that we can do a full heap check on all GCs when `-N1`. I don't know if LDV is supposed to work with the threaded runtime. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Changes (by kazu-yamamoto): * cc: kazu@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Comment (by kazu-yamamoto): I'm trying to profile my web server with GHC head (+RTS -Nx -p). Without ezyang's patch, it causes a segfault when I type C-c to stop the server. With GHC 7.6.3, C-c stops the server and generates a profile file. With ezyang's patch, this segfault disappeared. However, all counters are displayed 0: {{{ individual inherited COST CENTRE MODULE no. entries %time %alloc %time %alloc MAIN MAIN 347 0 100.0 100.0 100.0 100.0 CAF Main 693 0 0.0 0.0 0.0 0.0 CAF Server 692 0 0.0 0.0 0.0 0.0 CAF WaiApp 690 0 0.0 0.0 0.0 0.0 CAF Program.Mighty.Config 688 0 0.0 0.0 0.0 0.0 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Comment (by kazu-yamamoto): This "0 report" is created even with -N1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Comment (by kazu-yamamoto): Never mind. I forgot to specify --ghc-options="-fprof-auto -fprof-cafs" to cabal. I can get a proper profiling file if I specify it. So, I hope that ezyang's patch will be merged quickly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: simonmar Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Changes (by simonmar): * owner: => simonmar Comment: ezyang: I think the case that you were originally trying to fix by removing the test was PROFILING && DEBUG, right? We need to restore the original check to fix this bug, and additionally enable slop-zeroing when PROFILING && DEBUG. I'll commit a fix. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ----------------------------------+---------------------------------- Changes (by akio): * owner: simonmar => * status: closed => new * resolution: fixed => Comment: I think the current condition is wrong because it zeros slop when {{{THREADED && PROFILING && DEBUG}}}. This causes the test case for #8453 to segfault. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: 8453 | Related Tickets: ----------------------------------+---------------------------------- Changes (by simonpj): * cc: simonmar (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: 8453 | Related Tickets: ----------------------------------+---------------------------------- Comment (by simonmar): You're right. I think the code should be: {{{ #if defined(PROFILING) && (!defined(DEBUG) || defined(THREADED_RTS)) // see Note [zeroing slop] if (era <= 0) return; #endif }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: simonmar Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: 8453 | Related Tickets: ----------------------------------+---------------------------------- Changes (by simonmar): * owner: => simonmar -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8402: throwTo segfaults under -prof -threaded -with-rtsopts=N2 ----------------------------------+---------------------------------- Reporter: akio | Owner: simonmar Type: bug | Status: closed Priority: highest | Milestone: 7.8.1 Component: Profiling | Version: 7.7 Resolution: fixed | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: 8453 | Related Tickets: ----------------------------------+---------------------------------- Changes (by simonmar): * status: new => closed * resolution: => fixed Comment: hopefully fixed in 45eaeee3d7f5ef2efbc72769ebe6b988a867692a/ghc -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8402#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC