Index | Thread | Search

From:
hshoexer <hshoexer@yerbouti.franken.de>
Subject:
Re: fix deadlock if pausing a vm with a busy-polling vcpu
To:
tech@openbsd.org
Date:
Mon, 16 Feb 2026 18:13:03 +0100

Download raw body.

Thread
Hi,

On Thu, Feb 12, 2026 at 10:02:17AM -0500, Dave Voutila wrote:
> If a vcpu isn't halted because it's busy polling (like at the
> bootloader prompt), issuing a pause via `vmctl pause <vm>` will
> effectively deadlock. This removes the condition that the vcpu needs
> to be in a halted state and aggressively pauses at the next vm exit.
> 
> If you want to see the current deadlock, boot an installer image and
> at the boot prompt just type a single character to stop the auto-boot
> from occurring. Now try to `vmctl pause`.
> 
> ok?

I can reproduce the issue and your change fixes it.  Not depending
on halt state make sense.

ok hshoexer

Note: for me the diff does not apply cleanly.  I think the range
information is wrong.  Should be more like 826,8 and not 826,2.

> diff refs/heads/master refs/heads/vmd-pause-deadlock
> commit - 012cf974ca6d25b889551a1e73afca0e5a6d0994
> commit + 35699612346148cad906319a3a64d4862bcd0f15
> blob - 6d571ce90fc27d700755eae58c2127ce874efd3f
> blob + 4b43735e16d2910a4ca843f425e32fa643016df4
> --- usr.sbin/vmd/vm.c
> +++ usr.sbin/vmd/vm.c
> @@ -826,2 +826,2 @@ vcpu_run_loop(void *arg)
>  		halted = vcpu_hlt[n];
>  		mutex_unlock(&vm_mtx);
> 
> -		/* If we are halted and need to pause, pause */
> -		if (halted && paused) {
> +		/* If we need to pause, wait on the barrier. */
> +		if (paused) {
>  			ret = pthread_barrier_wait(&vm_pause_barrier);
>  			if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
>  				log_warnx("%s: could not wait on pause barrier (%d)",
>