Skip to contentSkip to conversation

linux-user emulation hangs during fork

DISCUSSION Andreas Schwab 2 participants 5 messages Jun 5, 2024 – Jun 6, 2024

lore
Share & tools
lore
#0 lore raw
$ qemu-x86_64 --version
qemu-x86_64 version 9.0.50 (v9.0.0-1211-gd16cab541a)
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
$ cat fork.rb 
begin
  r, w = IO.pipe
  if pid1 = fork
    w.close
    r.read 1
    Process.kill "USR1", pid1
    Process.wait2 pid1
  else
    print "child\n"
    r.close
    if pid2 = fork
      trap("USR1") { print "child: kill\n"; Process.kill "USR2", pid2 }
      w.close
      print "child: wait\n"
      Process.wait2 pid2
    else
      print "grandchild\n"
      w.close
      sleep 0.2
    end
  end
end
$ ruby fork.rb
child
child: wait
grandchild
child: kill
$ qemu-x86_64 /usr/bin/ruby fork.rb
child
child: wait
^Z
[1]+  Stopped                 qemu-x86_64 /usr/bin/ruby fork.rb
$ grep SigB $(for p in $(pidof qemu-x86_64); do echo /proc/$p/status; done | sort)
/proc/3221/status:SigBlk:       0000000000000000
/proc/3224/status:SigBlk:       0000000000000000
/proc/3228/status:SigBlk:       fffffff27ffbfa9f
Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
author Reviewed-by Laurent Vivier
#1 lore raw

6490d9aa62ef3cbbac2bf584fb0f3e737ab05e44 is the first bad commit commit 6490d9aa62ef3cbbac2bf584fb0f3e737ab05e44

Author: Richard Henderson <[email protected]>
Date:   Tue Jan 24 10:10:19 2023 -1000

linux-user: un-parent OBJECT(cpu) when closing thread

This reinstates commit 52f0c1607671293afcdb2acc2f83e9bccbfa74bb:

While forcing the CPU to unrealize by hand does trigger the clean-up code we never fully free resources because refcount never reaches zero. This is because QOM automatically added objects without an explicit parent to /unattached/, incrementing the refcount.

Instead of manually triggering unrealization just unparent the object and let the device machinery deal with that for us.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/866

Message-Id: <[email protected]>

The original patch tickled a problem in target/arm, and was reverted. But that problem is fixed as of commit 3b07a936d3bf.

Message-Id: <[email protected]>

 linux-user/syscall.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
#2 lore raw
In reply to Andreas Schwab
Quoted 32 lines · Andreas Schwab
$ qemu-x86_64 --version
qemu-x86_64 version 9.0.50 (v9.0.0-1211-gd16cab541a)
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
$ cat fork.rb
begin
   r, w = IO.pipe
   if pid1 = fork
     w.close
     r.read 1
     Process.kill "USR1", pid1
     Process.wait2 pid1
   else
     print "child\n"
     r.close
     if pid2 = fork
       trap("USR1") { print "child: kill\n"; Process.kill "USR2", pid2 }
       w.close
       print "child: wait\n"
       Process.wait2 pid2
     else
       print "grandchild\n"
       w.close
       sleep 0.2
     end
   end
end
$ ruby fork.rb
child
child: wait
grandchild
child: kill
$ qemu-x86_64 /usr/bin/ruby fork.rb
Quoted 9 lines
child
child: wait
^Z
[1]+  Stopped                 qemu-x86_64 /usr/bin/ruby fork.rb
$ grep SigB $(for p in $(pidof qemu-x86_64); do echo /proc/$p/status; done | sort)
/proc/3221/status:SigBlk:       0000000000000000
/proc/3224/status:SigBlk:       0000000000000000
/proc/3228/status:SigBlk:       fffffff27ffbfa9f

Works for me:

rth@stoup:~/zz$ ~/qemu/bld/qemu-x86_64 `which ruby` fork.rb
child
grandchild
child: wait
child: kill
rth@stoup:~/zz$ ~/qemu/bld/qemu-x86_64 `which ruby` fork.rb
child
grandchild
child: wait
child: kill
rth@stoup:~/zz$ ~/qemu/bld/qemu-x86_64 `which ruby` fork.rb
child
grandchild
child: wait
child: kill
rth@stoup:~/zz$ ~/qemu/bld/qemu-x86_64 `which ruby` fork.rb
child
grandchild
child: wait
child: kill

r~

#3 lore raw

Which ruby?

$ ruby --version
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux-gnu]
Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
#4 lore raw
Quoted 5 lines · Andreas Schwab

Which ruby?

$ ruby --version
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux-gnu]

ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu]

That might have been handy to have with your original report.

r~