Skip to content

hv: vmbus: prevent control-plane starvation and order-7 ring deadlocks under memory pressure

Emerson Busson linux-hyperv lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2hv: vmbus: prevent control-plane starvation and balloon thrash under memory pressuredrivers/hv/hv_balloon.c drivers/hv/hv_common.c+44 -00 replies
2/2hv: vmbus: add virtual memory fallback for ring buffer allocations under memory pressuredrivers/hv/channel.c drivers/hv/hyperv_vmbus.h drivers/hv/ring_buffer.c +1 more+57 -121 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] hv: vmbus: prevent control-plane starvation and order-7 ring deadlocks under memory pressure

Under Microsoft Hyper-V and WSL2 virtual machine environments, heavy memory pressure and memory tiering workloads (e.g. swap-heavy tasks, containerized compilation, in-memory databases) frequently expose guest kernels to starvation across two critical VMBus mechanisms:

1. Control-plane and heartbeat starvation:
During aggressive direct reclaim, available pages drop below safety watermarks. Atomic allocations (GFP_ATOMIC) required by synthetic VMBus packets, virtual network switches (netvsc), and balloon management fail. When the guest fails to service host heartbeats, the Windows Host Compute System (HCS) watchdog presumes a guest hard lock, triggering abrupt virtual switch teardowns (Hyper-V-VmSwitch Event 102/291) and ungracefully restarting the VM prior to any Linux OOM killer intervention. Concurrently, host balloon driver requests exacerbate exhaustion.

2. High-order contiguous allocation failures:
Dynamically instantiated VMBus sub-channels (e.g., synthetic SCSI, network, and vsock) invoke vmbus_alloc_ring(), requiring order-7 (512 KiB) contiguous physical pages via alloc_pages(GFP_KERNEL | __GFP_ZERO, order). Severe buddy allocator fragmentation causes alloc_pages() to fail with -ENOMEM even when ample virtual memory exists. On WSL2, this directly manifests as userspace communication failures (e.g. "accept4 failed 110: Connection timed out" on vsock control planes).

This series resolves both issues:

- Patch 1/2 dynamically establishes a memory headroom floor for vm.min_free_kbytes during late_initcall (clamped between 64 MiB and 512 MiB based on 3.125% of total guest RAM), safeguarding atomic allocations and VMBus heartbeats. It also defers balloon driver inflation when available memory drops below totalram_pages() / 32 to avoid competing with direct reclaim.

- Patch 2/2 introduces a fallback to vzalloc_node() / vzalloc() in vmbus_alloc_ring() when high-order physical allocation fails, adapts hv_ringbuffer_init() using vmalloc_to_page() for double-mapped ring wraparounds, and preserves Confidential VM (CoCo) guest memory re-encryption guarantees in vmbus_free_ring().

Verification & Testing:
Tested and validated against Microsoft WSL2 rolling-lts 6.18 kernel under multi-tier memory pressure (13.66 GB/s transfer bandwidth across ZRAM, VRAM, and SSD tiers), verifying zero kernel panics, zero HCS disconnects, and flawless vsock channel open resilience.

Related issue discussions:
- https://github.com/microsoft/WSL/issues/41634
- https://github.com/microsoft/WSL/issues/40795

Emerson Busson (2):
hv: vmbus: prevent control-plane starvation and balloon thrash under
memory pressure
hv: vmbus: add virtual memory fallback for ring buffer allocations
under memory pressure

 drivers/hv/channel.c      | 46 ++++++++++++++++++++++++++++++++++-----
 drivers/hv/hv_balloon.c   | 12 ++++++++++
 drivers/hv/hv_common.c    | 32 +++++++++++++++++++++++++++
 drivers/hv/hyperv_vmbus.h |  2 +-
 drivers/hv/ring_buffer.c  | 19 +++++++++++-----
 include/linux/hyperv.h    |  2 ++
 6 files changed, 101 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0