>Submitter-Id: net
>Originator: Scott Blomenkamp <[email protected]>
>Organization: (none)
>Synopsis: xbf(4) never answers its backend's Closing, so detach waits out
the toolstack timeout and can free a ring the backend still maps
>Severity: serious
>Priority: medium
>Category: kernel
>Class: sw-bug
>Release: 8.0
>Environment:
System : OpenBSD 8.0
https://www.google.com/url?q=http://GENERIC.MP&source=gmail&ust=1795678552272000&sa=E,
with local workarounds
(the PVH ones from my report "amd64: OpenBSD 8.0
cannot boot as a Xen PVH guest (seven separate
faults)", sent to bugs@ the same day); the code
on this path is 8.0's unchanged
Architecture: OpenBSD.amd64
Machine : Qubes OS host, Xen 4.19.6, dom0 Linux 6.18.64;
PVH and HVM guests, 2 vCPUs
>Description:
xbf(4) does not watch its backend's state after it connects.
At a disk detach the backend moves to Closing (5) and waits for
the frontend to answer Closed (6); xbf stays at Connected (4),
so the toolstack waits out its timeout (about 10 s) and removes
both xenstore directories. xen_hotplug() then runs
xbf_detach(), which frees the ring while blkback may still have
it mapped, and xen_grant_table_remove() panics:

panic: grant table reference 9765 is held by domain 0:
frame 0x6f00d flags 0x19
xen_grant_table_remove() at xen_grant_table_remove+0x16f
xen_bus_dmamap_unload() at xen_bus_dmamap_unload+0x73
xbf_dma_free() at xbf_dma_free+0x67
xbf_ring_destroy() at xbf_ring_destroy+0x10f
xbf_detach() at xbf_detach+0x81
config_detach() at config_detach+0x166
xen_hotplug() at xen_hotplug+0x1a5
taskq_thread() at taskq_thread+0x129

Seen with qvm-block detach of a loop-backed disk, with no
deliberate hold by dom0. As a PVH guest it panicked at the
first detach (2 of 2 runs). As an HVM guest it survived 12 of
12, but every detach took the 10 s timeout path (10.35-10.41 s).
A Linux guest on the same host detaches in 0.35-0.65 s. The
code on this path is 8.0's unchanged: xbf.c rev 1.54, and
xen_hotplug(), xen_bus_dmamap_unload() and
xen_grant_table_remove().

The panic itself is the class of my report "xen(4): a backend
that keeps a grant mapped panics the guest at device detach",
sent the same day; here it comes from a routine detach.
>How-To-Repeat:
1. Attach a disk to a running guest (xl block-attach, or on
Qubes OS: qvm-block attach <guest> dom0:loopN) and read
from it.
2. Detach it (xl block-detach / qvm-block detach) and watch
/local/domain/0/backend/vbd/<domid>/<dev>/state go to 5
while /local/domain/<domid>/device/vbd/<dev>/state stays 4.
3. The detach returns after about 10 s. Repeated under PVH,
the guest panics as above (here at the first cycle).
The panic and trace are attached.
>Fix:
None attached. Locally, watching the backend's state after
connect, and on Closing answering Closed without freeing the
ring (freeing it only at the detach that follows, once blkback
has unmapped), made every detach finish in 0.28-0.36 s with no
panic (10 of 10, PVH). The deferral asked for in the other
report is still needed for a backend that keeps a mapping on
purpose.

Disclosure: I found and analysed this with the help of an AI
assistant (Anthropic's Claude), on a Qubes OS host (Xen 4.19.6).
The panic and trace above are from real runs. No AI-written code
is attached.
panic: grant table reference 9765 is held by domain 0: frame 0x6f00d flags 0x19

Stopped at      db_enter+0x14:  popq    %rbp
    TID    PID    UID     PRFLAGS     PFLAGS  CPU  COMMAND
*431835  99636      0     0x14000      0x200    1K xenwatch
db_enter() at db_enter+0x14
panic(ffffffff8267600f) at panic+0xd5
xen_grant_table_remove(ffff8000000822f8,25) at xen_grant_table_remove+0x16f
xen_bus_dmamap_unload(ffffffff82af07f0,ffff800000bec980) at xen_bus_dmamap_unlo
ad+0x73
xbf_dma_free(ffffffff82af07f0,ffff800000b18d78) at xbf_dma_free+0x67
xbf_ring_destroy(ffff800000b18c00) at xbf_ring_destroy+0x10f
xbf_detach(ffff800000b18c00,0) at xbf_detach+0x81
config_detach(ffff800000b18c00,0) at config_detach+0x166
xen_hotplug(ffff80000002f600) at xen_hotplug+0x1a5
taskq_thread(ffff80000007f400) at taskq_thread+0x129
end trace frame: 0x0, count: 5
https://www.openbsd.org/ddb.html describes the minimum info required in bug
reports.  Insufficient info makes it difficult to find and fix bugs.

Reply via email to