virtio: improve virtiofs and VirtioProxy performance with per-device SWIOTLB pool#40654
Open
benhillis wants to merge 1 commit into
Open
virtio: improve virtiofs and VirtioProxy performance with per-device SWIOTLB pool#40654benhillis wants to merge 1 commit into
benhillis wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an end-to-end “guest-published SWIOTLB pool” handshake: the Linux guest (WSL kernel) publishes an hv_pci SWIOTLB pool (base/size), the Windows side reads and forwards it, and device creation paths pass a swiotlb=... token to wsldevicehost so it can program a matching per-device aperture (virtio-fs and virtio-net).
Changes:
- Add guest→host capability plumbing for hv_pci SWIOTLB pool (new init/WSLC messages, service/session forwarding, and telemetry logging).
- Thread a cached
swiotlb=0x{base:x},{size}token into virtio device creation (VirtioFS shares and VirtioProxy/virtio-net). - Add
.wslconfigparsing/validation and user-facing localization for SWIOTLB/virtio-related warnings, plus unit test coverage.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/UnitTests.cpp | Adds unit tests validating .wslconfig experimental.swiotlb parsing and rejection of malformed values. |
| src/windows/wslcsession/WSLCVirtualMachine.h | Adds per-VM guest capability fields and a ReadGuestCapabilities() step. |
| src/windows/wslcsession/WSLCVirtualMachine.cpp | Implements guest capability query over the init channel and forwards to the service via COM. |
| src/windows/service/inc/wslc.idl | Adds WSLCGuestCapabilities struct and a new ApplyGuestCapabilities method on IWSLCVirtualMachine. |
| src/windows/service/exe/WslCoreVm.h | Stores hv_pci SWIOTLB base/size and a cached SWIOTLB device-options token. |
| src/windows/service/exe/WslCoreVm.cpp | Reads hv_pci SWIOTLB info, caches formatted token, passes it to VirtioNetworking, and appends it to VirtioFS share options. |
| src/windows/service/exe/HcsVirtualMachine.h | Stores a cached SWIOTLB token for WSLC virtio device creation paths. |
| src/windows/service/exe/HcsVirtualMachine.cpp | Computes default SWIOTLB request size, passes it to kernel cmdline helper, threads token into VirtioNetworking/AddShare, and implements ApplyGuestCapabilities. |
| src/windows/common/WslCoreConfig.h | Adds experimental.swiotlb key constant and config field SwiotlbSizeBytes. |
| src/windows/common/WslCoreConfig.cpp | Parses experimental.swiotlb, validates virtio dependencies, and computes default SWIOTLB sizing only when relevant virtio paths are enabled. |
| src/windows/common/VirtioNetworking.h | Extends ctor to accept SWIOTLB token to pass into virtio-net device creation. |
| src/windows/common/VirtioNetworking.cpp | Passes SWIOTLB token into virtio-net/loopback device creation calls. |
| src/windows/common/helpers.hpp | Extends AppendCommonKernelCommandLine to accept SWIOTLB size and adds ComputeDefaultSwiotlbConfig. |
| src/windows/common/helpers.cpp | Appends swiotlb=force hv_pci_swiotlb=<bytes> when requested; implements default sizing helper. |
| src/windows/common/GuestDeviceManager.h | Adds m_vmIdOption member for device-host ownership tagging. |
| src/windows/common/GuestDeviceManager.cpp | Appends a vm_id= option to device share names and avoids adding an empty options delimiter. |
| src/shared/inc/lxinitshared.h | Adds WSLC message types for guest capability query and adds SWIOTLB fields to LX_INIT_GUEST_CAPABILITIES. |
| src/linux/init/WSLCInit.cpp | Handles WSLC guest capability query by reading hv_pci SWIOTLB sysfs and returning base/size. |
| src/linux/init/util.h | Introduces HvPciSwiotlbPool and declaration for reading the sysfs pool info. |
| src/linux/init/util.cpp | Implements sysfs reads for swiotlb_base/swiotlb_size with a safe fallback to zeros. |
| src/linux/init/main.cpp | Includes SWIOTLB base/size in LX_INIT_GUEST_CAPABILITIES sent to the service. |
| packages.config | Bumps Microsoft.WSL.DeviceHost and Microsoft.WSL.Kernel packages for SWIOTLB aperture/handshake support. |
| localization/strings/en-US/Resources.resw | Adds new localized messages for VirtioProxy fallback and missing-kernel-patch SWIOTLB warning. |
2 tasks
a8be2fb to
5041235
Compare
Comment on lines
+431
to
+435
| if (m_hvPciSwiotlbBase != 0 && m_hvPciSwiotlbSize != 0) | ||
| { | ||
| m_swiotlbOption = std::format(L"swiotlb=0x{:x},{}", m_hvPciSwiotlbBase, m_hvPciSwiotlbSize); | ||
| } | ||
| else if (m_vmConfig.SwiotlbSizeBytes != 0) |
5041235 to
2620337
Compare
asherkariv
previously approved these changes
May 27, 2026
2620337 to
82a476c
Compare
82a476c to
fe4406e
Compare
Comment on lines
+422
to
+423
| // swiotlb device-options token. Passing zero for both means the guest kernel does not | ||
| // support hv_pci swiotlb; the service then omits the token and emits a user warning. |
…SWIOTLB pool
Improves virtiofs and VirtioProxy performance by giving each virtio
device its own SWIOTLB aperture instead of sharing a single global
pool. The guest kernel reserves a contiguous physical range at boot,
publishes the (base, size), and the host programs a matching
per-device aperture in wsldevicehost.
1. The WSL kernel allocates a contiguous range at boot
(alloc_contig_pages with __GFP_DMA32 | __GFP_ZERO) and exposes
the chosen physical (base, size) under
/sys/bus/vmbus/drivers/hv_pci/swiotlb_{base,size}
2. mini_init (WSL2) and the WSLC init handler read those sysfs files
and return the values in LX_INIT_GUEST_CAPABILITIES and
WSLC_GET_GUEST_CAPABILITIES_RESULT respectively.
3. WslCoreVm::ReadGuestCapabilities and
WSLCVirtualMachine::ReadGuestCapabilities capture the values.
WSLC forwards them to wslservice via the new
HcsVirtualMachine::ApplyGuestCapabilities IDL method (with a
WSLCGuestCapabilities struct so future kernel-published values
can be added without bumping the interface IID).
4. Both VM owners format "swiotlb=0x{base:x},{size}" once into
m_swiotlbOption and pass it verbatim to AddGuestDevice /
AddSharePath for every virtiofs share and virtio-net adapter
(VirtioProxy networking). wsldevicehost consumes the token and
creates the per-device SWIOTLB aperture.
If the kernel does not publish the sysfs files (older kernel) both
values come back as zero, the host omits the device-options token,
and the WSL2 path emits a one-time user warning via
MessageSwiotlbKernelUnsupported so users understand why performance
is degraded. (The WSLC path always uses the bundled kernel, so the
warning does not apply there.)
Other changes:
* Bump Microsoft.WSL.Kernel to 6.18.26.3-1, which is the first
official kernel that publishes the hv_pci swiotlb_{base,size}
sysfs files this PR consumes.
* Bump Microsoft.WSL.DeviceHost to 1.2.29-0 for the device-side
SWIOTLB aperture support.
* Default pool sizing moves to helpers::ComputeDefaultSwiotlbConfig
and is only requested on the kernel command line when a virtio
device that needs bounce buffers (VirtioFs / Virtio9p /
VirtioProxy) is in use.
* Telemetry: emit GuestKernelInfo / WSLCReadGuestCapabilities /
WSLCApplyGuestCapabilities events with the kernel-chosen base
and size so we can validate the handshake in CI.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fe4406e to
1ee87b2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improves virtiofs and VirtioProxy performance by giving each virtio device its own SWIOTLB aperture instead of sharing a single global pool. The guest kernel reserves a contiguous physical range at boot, publishes the (base, size), and the host programs a matching per-device aperture in wsldevicehost.
Handshake:
alloc_contig_pages,__GFP_DMA32 | __GFP_ZERO) and exposes it under/sys/bus/vmbus/drivers/hv_pci/swiotlb_{base,size}.mini_init(WSL2) and the WSLC init handler read the sysfs files and return the values inLX_INIT_GUEST_CAPABILITIES/WSLC_GET_GUEST_CAPABILITIES_RESULT.WslCoreVm::ReadGuestCapabilitiesandWSLCVirtualMachine::ReadGuestCapabilitiescapture them. WSLC forwards them via the newHcsVirtualMachine::ApplyGuestCapabilitiesIDL method (taking aWSLCGuestCapabilitiesstruct).swiotlb=0x{base:x},{size}once intom_swiotlbOptionand pass it toAddGuestDevice/AddSharePathfor every virtiofs share and virtio-net adapter (VirtioProxy networking).Bumps
Microsoft.WSL.Kernelto 6.18.26.3-1 (first official kernel with the patch) andMicrosoft.WSL.DeviceHostto 1.2.29-0 (consumes the swiotlb device-options token).