Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Nov 2019 14:50:21 +0400
From:      Gleb Popov <arrowd@freebsd.org>
To:        freebsd-hackers <freebsd-hackers@freebsd.org>
Subject:   My code causes "ata0: already running" error and hang in VirtualBox VM
Message-ID:  <CALH631kMNi6xyKaCa6LcWhTU2i7rXqto-MHaD3ZEdLHxQ8Q5oA@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hello, hackers@

I'm facing an issue that I'm unable to debug, so decided to ask for an
advice here.

The project I'm working on is bsdisks - an implementation of UDisks2 daemon
for FreeBSD. Amongst other things it tries to find out if a gived disk
(from a list reported by geom disk list) has "removable" property. For
that, it run the same code that `camcontrol identify && camcontrol inquiry`
runs [1].

However, I got reports that this code causes the following error message
when bsdisks is run on a FreeBSD system virtualized under VirtualBox:

ata0: already running!
ata0: timeout waiting for ATAPI ready
ata0: error issuing ATA PACKET command

Right after this message the system goes into a strange state, when It
can't run any new processes. After a while, the system hangs completely
with additional message, something like "out of memory", but I can't
reproduce it now.

The strangest thing is that this error can be reproduced **once per host
reboot**. That is, restarting a VM causes the problem to go away. To
reproduce the hang again, I have to reboot host machine (even
unloading/loading vbox kernel modules doesn't work).

I tried to create a minimal reproducing program, but failed. Just calling
cam_is_removable() from empty main() doesn't trigger the hang. I also tried
simulating race conditions by calling cam_is_removalbe from different
threads, as well as using mutex in bsdisks - still no luck.

I'm completely lost there, so hoping someone can shed some light on this
heisenbug.

Reproduction steps are as simple as

# pkg install bsdisks
# bsdisks

on both FreeBSD 11 and 12 in a VirtualBox VM.

Thanks in advance.

[1]
https://bitbucket.org/arrowd/bsdisks/src/3e6fcb56763c14afb55c69cad3703543de41373f/camcontrol.c#lines-179



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CALH631kMNi6xyKaCa6LcWhTU2i7rXqto-MHaD3ZEdLHxQ8Q5oA>