contrib/vhost-user-gpu: segfault in get_edid_cb() when a virgl fence is signalled while a GET_EDID or GET_DISPLAY_INFO reply is pending

Environment: vhost-user-gpu from QEMU 11.0.3 (pve-qemu-kvm 11.0.3-3, /usr/lib/kvm/vhost-user-gpu) with virglrenderer 1.1.0; contrib/vhost-user-gpu is unchanged in master as of 2026-09-10.

Steps: a Linux guest compositing on virgl (KDE Plasma) and a display client that resizes the display, so the guest asks for display info and EDID while it renders with fences.

Result: after 15 h of uptime, during a console session:

vhost-user-gpu[...]: segfault at 28 ip ... in vhost-user-gpu[1d4e3,...]

The faulting instruction is cmd->cmd_hdr.type in get_edid_cb() with cmd == NULL. QEMU cannot reconnect afterwards; the guest loses its display until the VM is restarted.

Analysis: vg_get_edid() and vg_get_display_info() leave their command on fenceq in VG_CMD_STATE_PENDING with fence_id 0, and the reply callbacks take it back with QTAILQ_LAST(&vg->fenceq). virgl_write_fence() completes and frees every fenceq entry whose fence_id is not above the signalled fence, without looking at its state. A fence signalled during the round trip to the frontend therefore frees the pending command. The callback then finds an empty queue (NULL + 0x28) or a fenced command, whose type fails the assertion.

Reproduced on demand by reporting a fence between the request and the reply (an LD_PRELOAD test hook around the public virglrenderer callbacks): the stock binary crashed at the same address within 7 s. Holding fence notifications until the reply has been handled kept it running, and the guest got its EDID.

Expected: a fence completes only fenced commands; a command waiting for the frontend is completed by its reply.

Signed-off-by: Dmitry R rdmitry0911@gmail.com