Bug 289930 - Booting FreeBSD 16-CURRENT on riscv64 with QEMU hangs indefinitely
Summary: Booting FreeBSD 16-CURRENT on riscv64 with QEMU hangs indefinitely
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: riscv (show other bugs)
Version: 16.0-CURRENT
Hardware: riscv Any
: --- Affects Only Me
Assignee: Mark Johnston
URL:
Keywords: crash, regression
Depends on:
Blocks:
 
Reported: 2025-09-30 22:30 UTC by Siva Mahadevan
Modified: 2025-11-07 23:42 UTC (History)
4 users (show)

See Also:


Attachments
boot log (2.97 KB, text/plain)
2025-09-30 22:30 UTC, Siva Mahadevan
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Siva Mahadevan freebsd_committer freebsd_triage 2025-09-30 22:30:03 UTC
Created attachment 264179 [details]
boot log

Booting FreeBSD 16-CURRENT on riscv64 with QEMU causes an indefinite hang here:


---<<BOOT>>---
[...]
vtblk0: 32772MB (67117123 512 byte sectors)
virtio_pci2: <VirtIO PCI (legacy) Block adapter> port 0x1100-0x117f mem 0x40010000-0x40010fff,0x40014000-0x40017fff irq 22 at device 3.0 on pci0
vtblk1: <VirtIO Block Adapter> on virtio_pci2 <---- HANGS HERE


To reproduce this, I used Bricoler with qemu-system-riscv64 10.1.0 and attached the boot log in this bug:

bricoler run freebsd-src-regression-suite \
  --param freebsd-src:url=/usr/src \
  --param freebsd-src:branch= \
  --param freebsd-src-build:machine=riscv/riscv64 \
  --param freebsd-src-regression-suite:hypervisor=qemu \
  --param freebsd-src-regression-suite:memory=4096 \
  --param freebsd-src-regression-suite:ncpus=2 \
  --param freebsd-src-regression-suite:parallelism=1 \
  --param freebsd-src-regression-suite:tests='bin/ls' \
  --param freebsd-src-regression-suite-vm-image:packages=


@andrew I've bisected this to your commit https://cgit.freebsd.org/src/commit/?id=ad17789a8569c6712c6d789232df2703a21088a4 (virtio: Remove the unused poll method). It boots successfully on this commit's parent, and hangs at this commit and current HEAD at the time of writing. Please triage as necessary.
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2025-10-03 16:07:55 UTC
I believe I've seen this with 32-bit ARM as well.  Seems quite odd for that commit to be implicated though, perhaps there's a race condition somewhere?
Comment 2 commit-hook freebsd_committer freebsd_triage 2025-11-04 14:36:44 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f999ffdce3813eb946f10999ccffb8275c324469

commit f999ffdce3813eb946f10999ccffb8275c324469
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-11-04 14:27:33 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-11-04 14:35:31 +0000

    virtio: Fix polling in virtqueue_dequeue()

    The access of vq->vq_ring.used->idx needs to be volatile-qualified,
    otherwise the compiler may optimize virtqueue_poll() into an infinite
    loop if there is no data available upon the first poll.

    Prior to commit ad17789a8569 this wasn't a problem since an external
    function call after each poll inhibited the optimization.

    PR:             289930
    MFC after:      3 days
    Sponsored by:   Klara, Inc.
    Fixes:          ad17789a8569 ("virtio: Remove the unused poll method")

 sys/dev/virtio/virtqueue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2025-11-07 15:00:14 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=72c76047541ab6cc0e989a74e8de4d6e6a1a94b6

commit 72c76047541ab6cc0e989a74e8de4d6e6a1a94b6
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-11-04 14:27:33 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-11-07 14:10:04 +0000

    virtio: Fix polling in virtqueue_dequeue()

    The access of vq->vq_ring.used->idx needs to be volatile-qualified,
    otherwise the compiler may optimize virtqueue_poll() into an infinite
    loop if there is no data available upon the first poll.

    Prior to commit ad17789a8569 this wasn't a problem since an external
    function call after each poll inhibited the optimization.

    PR:             289930
    MFC after:      3 days
    Sponsored by:   Klara, Inc.
    Fixes:          ad17789a8569 ("virtio: Remove the unused poll method")

    (cherry picked from commit f999ffdce3813eb946f10999ccffb8275c324469)

 sys/dev/virtio/virtqueue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2025-11-07 23:12:49 UTC
A commit in branch releng/15.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=69c726c150772c36854d38e51b6fd921a04caea5

commit 69c726c150772c36854d38e51b6fd921a04caea5
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-11-04 14:27:33 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-11-07 23:12:02 +0000

    virtio: Fix polling in virtqueue_dequeue()

    The access of vq->vq_ring.used->idx needs to be volatile-qualified,
    otherwise the compiler may optimize virtqueue_poll() into an infinite
    loop if there is no data available upon the first poll.

    Prior to commit ad17789a8569 this wasn't a problem since an external
    function call after each poll inhibited the optimization.

    Approved by:    re (cperciva)
    PR:             289930
    MFC after:      3 days
    Sponsored by:   Klara, Inc.
    Fixes:          ad17789a8569 ("virtio: Remove the unused poll method")

    (cherry picked from commit f999ffdce3813eb946f10999ccffb8275c324469)
    (cherry picked from commit 72c76047541ab6cc0e989a74e8de4d6e6a1a94b6)

 sys/dev/virtio/virtqueue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)