[Bug 292570] [virtio] virtio-balloon does not balloon correctly
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Nov 2026 22:10:40 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292570
--- Comment #12 from Julian Y. Richard Corbet <admin@sys.corbet.ch> ---
Created attachment 277366
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277366&action=edit
virtio_balloon: re-enable the virtqueue interrupt before sleeping
To be open from the start: we found this with an AI coding assistant
(Anthropic's Claude). It traced the cause in the source, wrote the attached
patch and ran the tests below. We are saying so plainly so that you can weigh
it as you see fit.
We hit the same problem as in comment 0 on FreeBSD 15.1. The cause is a missing
interrupt re-enable in vtballoon_send_page_frames(). virtio_balloon.c is the
same in main, stable/15 and releng/15.1.
What happens
With MSI-X, the virtio_pci interrupt filter (vtpci_vq_shared_intr_filter() or
vtpci_vq_intr_filter()) calls virtqueue_intr_filter(). When a completion
arrives, that function disables the queue's interrupt. vtballoon enables its
interrupts once, in vtballoon_attach(), and never again. So only the first
completion wakes the balloon thread. After that, the thread sleeps in "vtbspf"
until a configuration-change interrupt arrives. vtballoon_config_change() then
calls wakeup_one(sc), and the thread collects the finished request, sends one
more batch of 256 pages, and sleeps again. With INTx, vtpci_intx_intr() calls
the handler without the filter, and ballooning works.
Versions
Guest: FreeBSD 15.1-RELEASE (releng/15.1-n283562-96841ea08dcf) and
15.1-RELEASE-p6 (releng/15.1-n283643-95719d8a895b), amd64, from the official
ufs qcow2 VM image.
Host: QEMU 11.1.0 with KVM on Linux 7.3, AMD Ryzen 9 5950X.
Steps to reproduce
1. Boot the official image:
qemu-system-x86_64 -machine q35,accel=kvm -cpu host -smp 4 -m 4096 \
-drive if=pflash,format=raw,readonly=on,file=edk2-x86_64-code.fd \
-drive if=pflash,format=raw,file=edk2-vars.fd \
-drive
file=FreeBSD-15.1-RELEASE-amd64-ufs.qcow2,if=none,id=d0,format=qcow2 \
-device virtio-blk-pci,drive=d0 \
-netdev user,id=n0 -device virtio-net-pci,netdev=n0 \
-device pcie-root-port,id=rp1,chassis=1,bus=pcie.0,addr=0x10 \
-device virtio-balloon-pci,bus=rp1 \
-display none -serial unix:console.sock,server=on,wait=off \
-monitor unix:mon.sock,server=on,wait=off
pciconf -lc shows MSI-X enabled for the balloon device (2 messages).
virtio_pci uses one for configuration changes and one shared by the two queues.
2. In the guest: sysctl dev.vtballoon.0 (current and desired are 0).
3. In the QEMU monitor: balloon 1024
4. Wait 30 seconds, then in the guest: sysctl dev.vtballoon.0.current
dev.vtballoon.0.desired
Expected
current reaches desired (786432 pages) within a few seconds, and "info balloon"
in the monitor shows actual=1024.
Actual
- current stops at 512, and "info balloon" shows actual=4095.
- In vmstat -ia, the queue vector has fired once.
- procstat -kk 0 shows the virtio_balloon thread in
vtballoon_send_page_frames().
- Each further "balloon" command adds 256 pages.
- Deflating ("balloon 4096") gets stuck in the same way.
Comment 0 shows the same behaviour with virsh setmem.
With hw.virtio.pci.disable_msix=1 in loader.conf (INTx), the same steps reach
786432 pages in about 5 seconds and go back to 0 in about 2 seconds. That
setting also works as a workaround.
The fix
The attached patch re-enables the queue interrupt before the thread sleeps. If
the host completed the request in the meantime, virtqueue_enable_intr() returns
non-zero, and the loop checks the queue again instead of sleeping.
Tested on 15.1-RELEASE-p6 with MSI-X: every target we tried, between 512 MiB
and 4 GiB, was reached within 3 seconds in both directions. That includes a
target set before the guest booted. Because the driver is compiled into
GENERIC, we built the patched file for the test as a module under another
driver name that wins the probe over the built-in one. The only functional
change is the attached diff. It applies to main, stable/15 and stable/14, but
we have only run it on 15.1.
PR 2116 already re-enables the interrupt in the same function, as part of its
larger stats and deflate-on-OOM work. This patch is not meant to replace it. It
is only the fix on its own, in case that is useful.
We are not asking for anything beyond a look when you have time. Thank you.
--
You are receiving this mail because:
You are the assignee for the bug.